Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong/missing OpenAPI ApiResponse content #2258

Merged
merged 1 commit into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -165,8 +166,8 @@ public Response getSessions(@Context SecurityContext securityContext) {

@GET
@Path("/apitokens")
@Operation(operationId = "getApiToken", summary = "List the API tokens associated to the authenticated user.", responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = UserApiTokenDTO.class))),
@Operation(operationId = "getApiTokens", summary = "List the API tokens associated to the authenticated user.", responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = UserApiTokenDTO.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 @@ -65,6 +65,7 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
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 @@ -120,7 +121,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(array = @ArraySchema(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 +133,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(array = @ArraySchema(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 +146,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
Loading