[rest] Corrections in the annotations for several REST api calls (#5404)

* Fix expected post body
* Fixes to openapi spec

Signed-off-by: Jeff James <jeff@james-online.com>
This commit is contained in:
Jeff James
2026-03-15 20:09:47 +01:00
committed by GitHub
parent 1341eda39e
commit eebf1173c5
5 changed files with 25 additions and 13 deletions
@@ -70,6 +70,7 @@ import org.openhab.core.persistence.PersistenceServiceProblem;
import org.openhab.core.persistence.PersistenceServiceRegistry; import org.openhab.core.persistence.PersistenceServiceRegistry;
import org.openhab.core.persistence.QueryablePersistenceService; import org.openhab.core.persistence.QueryablePersistenceService;
import org.openhab.core.persistence.dto.ItemHistoryDTO; import org.openhab.core.persistence.dto.ItemHistoryDTO;
import org.openhab.core.persistence.dto.PersistenceCronStrategyDTO;
import org.openhab.core.persistence.dto.PersistenceServiceConfigurationDTO; import org.openhab.core.persistence.dto.PersistenceServiceConfigurationDTO;
import org.openhab.core.persistence.dto.PersistenceServiceDTO; import org.openhab.core.persistence.dto.PersistenceServiceDTO;
import org.openhab.core.persistence.dto.PersistenceStrategyDTO; import org.openhab.core.persistence.dto.PersistenceStrategyDTO;
@@ -349,7 +350,8 @@ public class PersistenceResource implements RESTResource {
@Path("strategysuggestions") @Path("strategysuggestions")
@Operation(operationId = "getPersistenceServiceStrategySuggestions", summary = "Gets a persistence service suggested strategies.", security = { @Operation(operationId = "getPersistenceServiceStrategySuggestions", summary = "Gets a persistence service suggested strategies.", security = {
@SecurityRequirement(name = "oauth2", scopes = { "admin" }) }, responses = { @SecurityRequirement(name = "oauth2", scopes = { "admin" }) }, responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = PersistenceStrategyDTO.class), uniqueItems = true))), @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(oneOf = {
PersistenceStrategyDTO.class, PersistenceCronStrategyDTO.class }), uniqueItems = true))),
@ApiResponse(responseCode = "404", description = "Suggested strategies not found.") }) @ApiResponse(responseCode = "404", description = "Suggested strategies not found.") })
public Response httpGetPersistenceServiceStrategySuggestions(@Context HttpHeaders headers, public Response httpGetPersistenceServiceStrategySuggestions(@Context HttpHeaders headers,
@Parameter(description = "Id of the persistence service.") @QueryParam("serviceId") String serviceId) { @Parameter(description = "Id of the persistence service.") @QueryParam("serviceId") String serviceId) {
@@ -75,6 +75,7 @@ import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
@@ -200,7 +201,7 @@ public class ConfigurableServiceResource implements RESTResource {
@Path("/{serviceId}/config") @Path("/{serviceId}/config")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
@Operation(operationId = "getServiceConfig", summary = "Get service configuration for given service ID.", responses = { @Operation(operationId = "getServiceConfig", summary = "Get service configuration for given service ID.", responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(type = "object"))),
@ApiResponse(responseCode = "500", description = "Configuration can not be read due to internal error") }) @ApiResponse(responseCode = "500", description = "Configuration can not be read due to internal error") })
public Response getConfiguration(@PathParam("serviceId") @Parameter(description = "service ID") String serviceId) { public Response getConfiguration(@PathParam("serviceId") @Parameter(description = "service ID") String serviceId) {
try { try {
@@ -217,8 +218,8 @@ public class ConfigurableServiceResource implements RESTResource {
@Path("/{serviceId}/config") @Path("/{serviceId}/config")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
@Operation(operationId = "updateServiceConfig", summary = "Updates a service configuration for given service ID and returns the old configuration.", responses = { @Operation(operationId = "updateServiceConfig", summary = "Updates a service configuration for given service ID and returns the old configuration.", requestBody = @RequestBody(required = false, content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(type = "object"))), responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(type = "object"))),
@ApiResponse(responseCode = "204", description = "No old configuration"), @ApiResponse(responseCode = "204", description = "No old configuration"),
@ApiResponse(responseCode = "500", description = "Configuration can not be updated due to internal error") }) @ApiResponse(responseCode = "500", description = "Configuration can not be updated due to internal error") })
public Response updateConfiguration( public Response updateConfiguration(
@@ -269,7 +270,7 @@ public class ConfigurableServiceResource implements RESTResource {
@Path("/{serviceId}/config") @Path("/{serviceId}/config")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
@Operation(operationId = "deleteServiceConfig", summary = "Deletes a service configuration for given service ID and returns the old configuration.", responses = { @Operation(operationId = "deleteServiceConfig", summary = "Deletes a service configuration for given service ID and returns the old configuration.", responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(type = "object"))),
@ApiResponse(responseCode = "204", description = "No old configuration"), @ApiResponse(responseCode = "204", description = "No old configuration"),
@ApiResponse(responseCode = "500", description = "Configuration can not be deleted due to internal error") }) @ApiResponse(responseCode = "500", description = "Configuration can not be deleted due to internal error") })
public Response deleteConfiguration( public Response deleteConfiguration(
@@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.security.RolesAllowed; import javax.annotation.security.RolesAllowed;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
@@ -222,6 +223,7 @@ public class SseResource implements RESTResource, SsePublisher {
*/ */
@POST @POST
@Path("/states/{connectionId}") @Path("/states/{connectionId}")
@Consumes(MediaType.APPLICATION_JSON)
@Operation(operationId = "updateItemListForStateUpdates", summary = "Changes the list of items a SSE connection will receive state updates to.", responses = { @Operation(operationId = "updateItemListForStateUpdates", summary = "Changes the list of items a SSE connection will receive state updates to.", responses = {
@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Unknown connectionId") }) @ApiResponse(responseCode = "404", description = "Unknown connectionId") })
@@ -24,7 +24,16 @@ import io.swagger.v3.oas.annotations.media.Schema;
*/ */
@Schema(name = "PersistenceCronStrategy") @Schema(name = "PersistenceCronStrategy")
@NonNullByDefault @NonNullByDefault
public class PersistenceCronStrategyDTO { public class PersistenceCronStrategyDTO extends PersistenceStrategyDTO {
public String name = "";
public String cronExpression = ""; public String cronExpression = "";
// do not remove - needed by GSON
public PersistenceCronStrategyDTO() {
this("", "");
}
public PersistenceCronStrategyDTO(String name, String cronExpression) {
super(name);
this.cronExpression = cronExpression;
}
} }
@@ -24,16 +24,14 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(name = "PersistenceStrategy") @Schema(name = "PersistenceStrategy")
@NonNullByDefault @NonNullByDefault
public class PersistenceStrategyDTO { public class PersistenceStrategyDTO {
public String type; public String name;
public String configuration;
// do not remove - needed by GSON // do not remove - needed by GSON
PersistenceStrategyDTO() { PersistenceStrategyDTO() {
this("", ""); this("");
} }
public PersistenceStrategyDTO(String type, String configuration) { public PersistenceStrategyDTO(String name) {
this.type = type; this.name = name;
this.configuration = configuration;
} }
} }