Skip to content

Commit

Permalink
Fix wrong/missing OpenAPI ApiResponse content
Browse files Browse the repository at this point in the history
This fixes some issues where the response content is missing or wrong in the generated OpenAPI spec.

Signed-off-by: Wouter Born <[email protected]>
  • Loading branch information
wborn committed Mar 26, 2021
1 parent 6961db7 commit f2dd82b
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public Response getByUID(@PathParam("ruleUID") @Parameter(description = "ruleUID
@Path("/{ruleUID}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(operationId = "deleteRule", summary = "Removes an existing rule corresponding to the given UID.", responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Rule corresponding to the given UID does not found.") })
public Response remove(@PathParam("ruleUID") @Parameter(description = "ruleUID") String ruleUID) {
Rule removedRule = ruleRegistry.remove(ruleUID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.slf4j.LoggerFactory;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand Down Expand Up @@ -115,7 +116,7 @@ public TokenResource(final @Reference UserRegistry userRegistry, final @Referenc
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_FORM_URLENCODED })
@Operation(operationId = "getOAuthToken", summary = "Get access and refresh tokens.", responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = TokenResponseDTO.class))),
@ApiResponse(responseCode = "400", description = "Invalid request parameters") })
public Response getToken(@FormParam("grant_type") String grantType, @FormParam("code") String code,
@FormParam("redirect_uri") String redirectUri, @FormParam("client_id") String clientId,
Expand Down Expand Up @@ -145,7 +146,7 @@ public Response getToken(@FormParam("grant_type") String grantType, @FormParam("
@GET
@Path("/sessions")
@Operation(operationId = "getSessionsForCurrentUser", summary = "List the sessions associated to the authenticated user.", responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = UserSessionDTO.class))),
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = UserSessionDTO.class)))),
@ApiResponse(responseCode = "401", description = "User is not authenticated"),
@ApiResponse(responseCode = "404", description = "User not found") })
@Produces({ MediaType.APPLICATION_JSON })
Expand Down Expand Up @@ -244,9 +245,8 @@ public Response deleteSession(@Nullable @FormParam("refresh_token") String refre
ResponseBuilder response = Response.ok();

if (sessionCookie != null && sessionCookie.getValue().equals(session.get().getSessionId())) {
URI domainUri;
try {
domainUri = new URI(session.get().getRedirectUri());
URI domainUri = new URI(session.get().getRedirectUri());
NewCookie newCookie = new NewCookie(SESSIONID_COOKIE_NAME, null, "/", domainUri.getHost(), null, 0,
false, true);
response.cookie(newCookie);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
* @author Yannick Schaus - initial contribution
*/
public class UserApiTokenDTO {
String name;
Date createdTime;
String scope;
public String name;
public Date createdTime;
public String scope;

public UserApiTokenDTO(String name, Date createdTime, String scope) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* @author Yannick Schaus - initial contribution
*/
public class UserDTO {
String name;
Collection<String> roles;
public String name;
public Collection<String> roles;

public UserDTO(User user) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
* @author Yannick Schaus - initial contribution
*/
public class UserSessionDTO {
String sessionId;
Date createdTime;
Date lastRefreshTime;
String clientId;
String scope;
public String sessionId;
public Date createdTime;
public Date lastRefreshTime;
public String clientId;
public String scope;

public UserSessionDTO(String sessionId, Date createdTime, Date lastRefreshTime, String clientId, String scope) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected void removeAddonService(AddonService featureService) {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Operation(operationId = "getAddons", summary = "Get all add-ons.", responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class))) })
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = Addon.class))) })
public Response getAddon(
@HeaderParam("Accept-Language") @Parameter(description = "language") @Nullable String language) {
logger.debug("Received HTTP GET request at '{}'", uriInfo.getPath());
Expand All @@ -132,7 +132,7 @@ public Response getAddon(
@Path("/types")
@Produces(MediaType.APPLICATION_JSON)
@Operation(operationId = "getAddonTypes", summary = "Get all add-on types.", responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class))) })
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AddonType.class))) })
public Response getTypes(
@HeaderParam("Accept-Language") @Parameter(description = "language") @Nullable String language) {
logger.debug("Received HTTP GET request at '{}'", uriInfo.getPath());
Expand All @@ -145,7 +145,7 @@ public Response getTypes(
@Path("/{addonId: [a-zA-Z_0-9-:]+}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(operationId = "getAddonById", summary = "Get add-on with given ID.", responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = Addon.class))),
@ApiResponse(responseCode = "404", description = "Not found") })
public Response getById(
@HeaderParam("Accept-Language") @Parameter(description = "language") @Nullable String language,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ public Response removeMetadata(@PathParam("itemname") @Parameter(description = "
@Consumes(MediaType.APPLICATION_JSON)
@Operation(operationId = "addOrUpdateItemInRegistry", summary = "Adds a new item to the registry or updates the existing item.", security = {
@SecurityRequirement(name = "oauth2", scopes = { "admin" }) }, responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = EnrichedItemDTO.class))),
@ApiResponse(responseCode = "201", description = "Item created."),
@ApiResponse(responseCode = "400", description = "Payload invalid."),
@ApiResponse(responseCode = "404", description = "Item not found or name in path invalid."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public Response getAll(
@GET
@Path("/{itemName}/{channelUID}")
@Operation(operationId = "getItemLink", summary = "Retrieves an individual link.", responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ItemChannelLinkDTO.class))),
@ApiResponse(responseCode = "404", description = "Content does not match the path") })
public Response getLink(@PathParam("itemName") @Parameter(description = "itemName") String itemName,
@PathParam("channelUID") @Parameter(description = "channelUID") String channelUid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.openhab.core.persistence.FilterCriteria.Ordering;
import org.openhab.core.persistence.HistoricItem;
import org.openhab.core.persistence.ModifiablePersistenceService;
import org.openhab.core.persistence.PersistenceItemInfo;
import org.openhab.core.persistence.PersistenceService;
import org.openhab.core.persistence.PersistenceServiceRegistry;
import org.openhab.core.persistence.QueryablePersistenceService;
Expand Down Expand Up @@ -133,7 +134,7 @@ public PersistenceResource( //
@Produces({ MediaType.APPLICATION_JSON })
@Operation(operationId = "getPersistenceServices", summary = "Gets a list of persistence services.", security = {
@SecurityRequirement(name = "oauth2", scopes = { "admin" }) }, responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))) })
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = PersistenceServiceDTO.class)))) })
public Response httpGetPersistenceServices(@Context HttpHeaders headers,
@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language) {
Locale locale = localeService.getLocale(language);
Expand All @@ -148,7 +149,7 @@ public Response httpGetPersistenceServices(@Context HttpHeaders headers,
@Produces({ MediaType.APPLICATION_JSON })
@Operation(operationId = "getItemsForPersistenceService", summary = "Gets a list of items available via a specific persistence service.", security = {
@SecurityRequirement(name = "oauth2", scopes = { "admin" }) }, responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))) })
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = PersistenceItemInfo.class), uniqueItems = true))) })
public Response httpGetPersistenceServiceItems(@Context HttpHeaders headers,
@Parameter(description = "Id of the persistence service. If not provided the default service will be used") @QueryParam("serviceId") @Nullable String serviceId) {
return getServiceItemList(serviceId);
Expand Down Expand Up @@ -199,7 +200,7 @@ public Response httpDeletePersistenceServiceItem(@Context HttpHeaders headers,
@Path("/items/{itemname: [a-zA-Z_0-9]+}")
@Produces({ MediaType.APPLICATION_JSON })
@Operation(operationId = "storeItemDataInPersistenceService", summary = "Stores item persistence data into the persistence service.", responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ItemHistoryDTO.class))),
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Unknown Item or persistence service") })
public Response httpPutPersistenceItemData(@Context HttpHeaders headers,
@Parameter(description = "Id of the persistence service. If not provided the default service will be used") @QueryParam("serviceId") @Nullable String serviceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ public ConfigurableServiceResource( //
@Operation(operationId = "getServices", summary = "Get all configurable services.", responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ConfigurableServiceDTO.class)))) })
public List<ConfigurableServiceDTO> getAll() {
List<ConfigurableServiceDTO> services = getConfigurableServices();
return services;
return getConfigurableServices();
}

@GET
Expand Down Expand Up @@ -172,8 +171,7 @@ public Response getById(@PathParam("serviceId") @Parameter(description = "servic
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ConfigurableServiceDTO.class)))) })
public List<ConfigurableServiceDTO> getMultiConfigServicesByFactoryPid(
@PathParam("serviceId") @Parameter(description = "service ID") String serviceId) {
List<ConfigurableServiceDTO> services = collectServicesById(serviceId);
return services;
return collectServicesById(serviceId);
}

private List<ConfigurableServiceDTO> collectServicesById(String serviceId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.openhab.core.config.core.ConfigUtil;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.config.core.status.ConfigStatusInfo;
import org.openhab.core.config.core.status.ConfigStatusMessage;
import org.openhab.core.config.core.status.ConfigStatusService;
import org.openhab.core.config.core.validation.ConfigValidationException;
import org.openhab.core.io.rest.DTOMapper;
Expand Down Expand Up @@ -217,7 +218,7 @@ public ThingResource( //
@Consumes(MediaType.APPLICATION_JSON)
@Operation(operationId = "createThingInRegistry", summary = "Creates a new thing and adds it to the registry.", security = {
@SecurityRequirement(name = "oauth2", scopes = { "admin" }) }, responses = {
@ApiResponse(responseCode = "201", description = "Created", content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "201", description = "Created", content = @Content(schema = @Schema(implementation = EnrichedThingDTO.class))),
@ApiResponse(responseCode = "400", description = "Thing uid does not match bridge uid."),
@ApiResponse(responseCode = "400", description = "A uid must be provided, if no binding can create a thing of this type."),
@ApiResponse(responseCode = "409", description = "A thing with the same uid already exists.") })
Expand Down Expand Up @@ -316,7 +317,7 @@ public Response getAll(
@Produces(MediaType.APPLICATION_JSON)
@Operation(operationId = "getThingById", summary = "Gets thing by UID.", security = {
@SecurityRequirement(name = "oauth2", scopes = { "admin" }) }, responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ThingDTO.class))),
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = EnrichedThingDTO.class))),
@ApiResponse(responseCode = "404", description = "Thing not found.") })
public Response getByUID(
@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language,
Expand Down Expand Up @@ -406,7 +407,7 @@ public Response remove(
@Consumes(MediaType.APPLICATION_JSON)
@Operation(operationId = "updateThing", summary = "Updates a thing.", security = {
@SecurityRequirement(name = "oauth2", scopes = { "admin" }) }, responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ThingDTO.class))),
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = EnrichedThingDTO.class))),
@ApiResponse(responseCode = "404", description = "Thing not found."),
@ApiResponse(responseCode = "409", description = "Thing could not be updated as it is not editable.") })
public Response update(
Expand Down Expand Up @@ -466,7 +467,7 @@ public Response update(
@Consumes(MediaType.APPLICATION_JSON)
@Operation(operationId = "updateThingConfig", summary = "Updates thing's configuration.", security = {
@SecurityRequirement(name = "oauth2", scopes = { "admin" }) }, responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ThingDTO.class))),
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = EnrichedThingDTO.class))),
@ApiResponse(responseCode = "400", description = "Configuration of the thing is not valid."),
@ApiResponse(responseCode = "404", description = "Thing not found"),
@ApiResponse(responseCode = "409", description = "Thing could not be updated as it is not editable.") })
Expand Down Expand Up @@ -523,7 +524,7 @@ public Response updateConfiguration(
@Produces(MediaType.APPLICATION_JSON)
@Operation(operationId = "getThingStatus", summary = "Gets thing status.", security = {
@SecurityRequirement(name = "oauth2", scopes = { "admin" }) }, responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ThingStatusInfo.class))),
@ApiResponse(responseCode = "404", description = "Thing not found.") })
public Response getStatus(
@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language,
Expand All @@ -548,7 +549,7 @@ public Response getStatus(
@Path("/{thingUID}/enable")
@Operation(operationId = "enableThing", summary = "Sets the thing enabled status.", security = {
@SecurityRequirement(name = "oauth2", scopes = { "admin" }) }, responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = EnrichedThingDTO.class))),
@ApiResponse(responseCode = "404", description = "Thing not found.") })
public Response setEnabled(
@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language,
Expand Down Expand Up @@ -578,7 +579,7 @@ public Response setEnabled(
@Produces(MediaType.APPLICATION_JSON)
@Operation(operationId = "getThingConfigStatus", summary = "Gets thing config status.", security = {
@SecurityRequirement(name = "oauth2", scopes = { "admin" }) }, responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ConfigStatusMessage.class)))),
@ApiResponse(responseCode = "404", description = "Thing not found.") })
public Response getConfigStatus(
@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") String language,
Expand Down Expand Up @@ -643,7 +644,7 @@ public Response updateFirmware(
@Path("/{thingUID}/firmware/status")
@Operation(operationId = "getThingFirmwareStatus", summary = "Gets thing's firmware status.", security = {
@SecurityRequirement(name = "oauth2", scopes = { "admin" }) }, responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = FirmwareStatusDTO.class))),
@ApiResponse(responseCode = "204", description = "No firmware status provided by this Thing.") })
public Response getFirmwareStatus(
@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language,
Expand Down
Loading

0 comments on commit f2dd82b

Please sign in to comment.