From 3e6f1cecf3b9dd7910ec54a82317be41d104d629 Mon Sep 17 00:00:00 2001 From: Claudio Mezzasalma Date: Fri, 4 Jun 2021 14:39:02 +0200 Subject: [PATCH] Update Endpoint REST API to support CORS endpoints Signed-off-by: Claudio Mezzasalma --- .../resources/v1/resources/EndpointInfos.java | 9 ++++++--- .../endpointInfo-scopeId-_count.yaml | 1 + .../endpointInfo-scopeId-_query.yaml | 1 + .../endpointInfo/endpointInfo-scopeId.yaml | 1 + .../openapi/endpointInfo/endpointInfo.yaml | 19 +++++++++++++++++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/EndpointInfos.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/EndpointInfos.java index 3732e6d4dd9..5076a3cf4aa 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/EndpointInfos.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/EndpointInfos.java @@ -67,6 +67,7 @@ public class EndpointInfos extends AbstractKapuaResource { public EndpointInfoListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @QueryParam("usage") String usage, + @QueryParam("endpointType") @DefaultValue(EndpointInfo.ENDPOINT_TYPE_RESOURCE) String endpointType, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { EndpointInfoQuery query = endpointInfoFactory.newQuery(scopeId); @@ -80,7 +81,7 @@ public EndpointInfoListResult simpleQuery( query.setOffset(offset); query.setLimit(limit); - return query(scopeId, query); + return query(scopeId, endpointType, query); } /** @@ -99,10 +100,11 @@ public EndpointInfoListResult simpleQuery( @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public EndpointInfoListResult query( @PathParam("scopeId") ScopeId scopeId, + @QueryParam("endpointType") @DefaultValue(EndpointInfo.ENDPOINT_TYPE_RESOURCE) String endpointType, EndpointInfoQuery query) throws KapuaException { query.setScopeId(scopeId); - return endpointInfoService.query(query); + return endpointInfoService.query(query, endpointType); } /** @@ -121,10 +123,11 @@ public EndpointInfoListResult query( @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public CountResult count( @PathParam("scopeId") ScopeId scopeId, + @QueryParam("endpointType") @DefaultValue(EndpointInfo.ENDPOINT_TYPE_RESOURCE) String endpointType, EndpointInfoQuery query) throws KapuaException { query.setScopeId(scopeId); - return new CountResult(endpointInfoService.count(query)); + return new CountResult(endpointInfoService.count(query, endpointType)); } /** diff --git a/rest-api/resources/src/main/resources/openapi/endpointInfo/endpointInfo-scopeId-_count.yaml b/rest-api/resources/src/main/resources/openapi/endpointInfo/endpointInfo-scopeId-_count.yaml index 1b202563dd1..b1952d9bb39 100644 --- a/rest-api/resources/src/main/resources/openapi/endpointInfo/endpointInfo-scopeId-_count.yaml +++ b/rest-api/resources/src/main/resources/openapi/endpointInfo/endpointInfo-scopeId-_count.yaml @@ -20,6 +20,7 @@ paths: operationId: endpointInfoCount parameters: - $ref: '../openapi.yaml#/components/parameters/scopeId' + - $ref: './endpointInfo.yaml#/components/parameters/endpointType' requestBody: $ref: '../openapi.yaml#/components/requestBodies/kapuaQuery' responses: diff --git a/rest-api/resources/src/main/resources/openapi/endpointInfo/endpointInfo-scopeId-_query.yaml b/rest-api/resources/src/main/resources/openapi/endpointInfo/endpointInfo-scopeId-_query.yaml index 5bc5a65f2c8..ebe30a4d239 100644 --- a/rest-api/resources/src/main/resources/openapi/endpointInfo/endpointInfo-scopeId-_query.yaml +++ b/rest-api/resources/src/main/resources/openapi/endpointInfo/endpointInfo-scopeId-_query.yaml @@ -20,6 +20,7 @@ paths: operationId: endpointInfoQuery parameters: - $ref: '../openapi.yaml#/components/parameters/scopeId' + - $ref: './endpointInfo.yaml#/components/parameters/endpointType' requestBody: $ref: '../openapi.yaml#/components/requestBodies/kapuaQuery' responses: diff --git a/rest-api/resources/src/main/resources/openapi/endpointInfo/endpointInfo-scopeId.yaml b/rest-api/resources/src/main/resources/openapi/endpointInfo/endpointInfo-scopeId.yaml index 8a44232f282..084498fbc49 100644 --- a/rest-api/resources/src/main/resources/openapi/endpointInfo/endpointInfo-scopeId.yaml +++ b/rest-api/resources/src/main/resources/openapi/endpointInfo/endpointInfo-scopeId.yaml @@ -25,6 +25,7 @@ paths: description: The endpointInfo usage to filter results schema: type: string + - $ref: './endpointInfo.yaml#/components/parameters/endpointType' - $ref: '../openapi.yaml#/components/parameters/limit' - $ref: '../openapi.yaml#/components/parameters/offset' responses: diff --git a/rest-api/resources/src/main/resources/openapi/endpointInfo/endpointInfo.yaml b/rest-api/resources/src/main/resources/openapi/endpointInfo/endpointInfo.yaml index 569d1498d86..b4947dfe326 100644 --- a/rest-api/resources/src/main/resources/openapi/endpointInfo/endpointInfo.yaml +++ b/rest-api/resources/src/main/resources/openapi/endpointInfo/endpointInfo.yaml @@ -22,6 +22,15 @@ components: schema: $ref: '../openapi.yaml#/components/schemas/kapuaId' required: true + endpointType: + name: endpointType + in: query + description: The type of the Endpoints to query for + schema: + allOf: + - $ref: '#/components/schemas/endpointType' + - default: resource + required: false schemas: endpointInfo: allOf: @@ -44,6 +53,7 @@ components: usages: - name: MESSAGE_BROKER - name: PROVISION + endpointType: resource endpointInfoCreator: allOf: - $ref: '../openapi.yaml#/components/schemas/kapuaUpdatableEntityCreator' @@ -61,6 +71,8 @@ components: type: array items: $ref: '#/components/schemas/usage' + endpointType: + $ref: '#/components/schemas/endpointType' example: schema: mqtt dns: 10.200.12.148 @@ -69,6 +81,7 @@ components: usages: - name: MESSAGE_BROKER - name: PROVISION + endpointType: resource endpointInfoListResult: allOf: - $ref: '../openapi.yaml#/components/schemas/kapuaListResult' @@ -98,8 +111,14 @@ components: usages: - name: MESSAGE_BROKER - name: PROVISION + endpointType: resource usage: type: object properties: name: type: string + endpointType: + type: string + enum: + - resource + - cors