aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2022-12-12 16:42:24 +0000
committerliamfallon <liam.fallon@est.tech>2022-12-12 17:28:14 +0000
commit7ed786054f394c9ea745cb41061d81c370435736 (patch)
tree735d72dca53d2dedb0180942859968fc766f536f /main/src
parent555445562f24224ac5333b32345adff62f2c0c4c (diff)
Use generated API interface for Swagger
This commit removes the Swagger V2 annotations on the NodeTemplateController in policy-api. The OpeApi annotations (Swagger v3 annotations) are on a generated Java Interface. The code is changed so that the controller implements that interface. There are no code changes tot he controller except that the order of the parameters is switched in some cases. Issue-ID: POLICY-4404 Change-Id: Iab49c7f3f197a85d3314a879d39fe2c95be041b8 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/NodeTemplateController.java221
-rw-r--r--main/src/main/resources/openapi/openapi.yaml41
2 files changed, 37 insertions, 225 deletions
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/NodeTemplateController.java b/main/src/main/java/org/onap/policy/api/main/rest/NodeTemplateController.java
index 6010f8e1..ecad0e59 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/NodeTemplateController.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/NodeTemplateController.java
@@ -22,24 +22,11 @@
package org.onap.policy.api.main.rest;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
-import io.swagger.annotations.Authorization;
-import io.swagger.annotations.BasicAuthDefinition;
-import io.swagger.annotations.Extension;
-import io.swagger.annotations.ExtensionProperty;
-import io.swagger.annotations.Info;
-import io.swagger.annotations.ResponseHeader;
-import io.swagger.annotations.SecurityDefinition;
-import io.swagger.annotations.SwaggerDefinition;
-import java.net.HttpURLConnection;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.onap.policy.api.main.exception.PolicyApiRuntimeException;
+import org.onap.policy.api.main.rest.genapi.ToscaNodeTemplateDesignApi;
import org.onap.policy.api.main.service.ToscaServiceTemplateService;
import org.onap.policy.common.endpoints.event.comm.Topic;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
@@ -48,36 +35,14 @@ import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestHeader;
-import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Class to provide REST API services for Tosca Node templates.
*/
@RestController
-@RequestMapping(path = "/policy/api/v1", produces = { "application/json", "application/yaml" })
-@Api(value = "Tosca Node template Design API")
-@SwaggerDefinition(
- info = @Info(
- description = "Tosca Node template Design API is publicly exposed for clients to Create/Read/Update/Delete"
- + " node templates which can be recognized"
- + " and executable by incorporated policy engines. It is an"
- + " independent component running rest service that takes all node templates design API calls"
- + " from clients and then assign them to different API working functions.",
- version = "1.0.0", title = "Tosca Node template Design",
- extensions = {@Extension(properties = {@ExtensionProperty(name = "planned-retirement-date", value = "tbd"),
- @ExtensionProperty(name = "component", value = "Policy Framework")})}),
- schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
- securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
@RequiredArgsConstructor
-public class NodeTemplateController extends CommonRestController {
+public class NodeTemplateController extends CommonRestController implements ToscaNodeTemplateDesignApi {
private final ToscaServiceTemplateService toscaServiceTemplateService;
@@ -88,37 +53,8 @@ public class NodeTemplateController extends CommonRestController {
*
* @return the Response object containing the results of the API operation
*/
- @PostMapping("/nodetemplates")
- @ApiOperation(value = "Create one or more new node templates",
- notes = "Client should provide TOSCA body of the new node templates",
- authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"nodeTemplate", },
- response = ToscaServiceTemplate.class,
- responseHeaders = {
- @ResponseHeader(name = VERSION_MINOR_NAME,
- description = VERSION_MINOR_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_PATCH_NAME,
- description = VERSION_PATCH_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = REQUEST_ID_NAME,
- description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
- extensions = {
- @Extension(name = EXTENSION_NAME, properties = {
- @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
- @ExtensionProperty(name = LAST_MOD_NAME, value = "Jakarta")})})
- @ApiResponses(value = {
- @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = INVALID_BODY_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
- public ResponseEntity<ToscaServiceTemplate> createToscaNodeTemplates(
- @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @RequestBody @ApiParam(value = "Entity body of tosca node templates", required = true)
- ToscaServiceTemplate body) {
+ @Override
+ public ResponseEntity<ToscaServiceTemplate> createToscaNodeTemplates(ToscaServiceTemplate body, UUID requestId) {
if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
NetLoggerUtil.log(NetLoggerUtil.EventType.IN, Topic.CommInfrastructure.REST, "/nodetemplates",
@@ -133,7 +69,6 @@ public class NodeTemplateController extends CommonRestController {
}
}
-
/**
* Updates one or more node templates in one call.
*
@@ -141,37 +76,8 @@ public class NodeTemplateController extends CommonRestController {
*
* @return the Response object containing the results of the API operation
*/
- @PutMapping("/nodetemplates")
- @ApiOperation(value = "Updates one or more new node templates",
- notes = "Client should provide TOSCA body of the updated node templates",
- authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"nodeTemplate", },
- response = ToscaServiceTemplate.class,
- responseHeaders = {
- @ResponseHeader(name = VERSION_MINOR_NAME,
- description = VERSION_MINOR_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_PATCH_NAME,
- description = VERSION_PATCH_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = REQUEST_ID_NAME,
- description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
- extensions = {
- @Extension(name = EXTENSION_NAME, properties = {
- @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
- @ExtensionProperty(name = LAST_MOD_NAME, value = "Jakarta")})})
- @ApiResponses(value = {
- @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = INVALID_BODY_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
- public ResponseEntity<ToscaServiceTemplate> updateToscaNodeTemplates(
- @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @RequestBody @ApiParam(value = "Entity body of tosca node templates", required = true)
- ToscaServiceTemplate body) {
+ @Override
+ public ResponseEntity<ToscaServiceTemplate> updateToscaNodeTemplates(ToscaServiceTemplate body, UUID requestId) {
if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
NetLoggerUtil.log(NetLoggerUtil.EventType.IN, Topic.CommInfrastructure.REST, "/nodetemplates",
@@ -186,47 +92,15 @@ public class NodeTemplateController extends CommonRestController {
}
}
-
/**
* Deletes a node template with specific name and version.
*
- * @param name the name of node template
+ * @param name the name of node template
* @param version the version of node template
* @return the Response object containing the results of the API operation
*/
- @DeleteMapping("/nodetemplates/{name}/versions/{version}")
- @ApiOperation(value = "Updates one or more new node templates",
- notes = "Client should provide TOSCA body of the updated node templates",
- authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"nodeTemplate", },
- response = ToscaServiceTemplate.class,
- responseHeaders = {
- @ResponseHeader(name = VERSION_MINOR_NAME,
- description = VERSION_MINOR_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_PATCH_NAME,
- description = VERSION_PATCH_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = REQUEST_ID_NAME,
- description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
- extensions = {
- @Extension(name = EXTENSION_NAME, properties = {
- @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
- @ExtensionProperty(name = LAST_MOD_NAME, value = "Jakarta")})})
- @ApiResponses(value = {
- @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = INVALID_BODY_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
- public ResponseEntity<ToscaServiceTemplate> deleteToscaNodeTemplates(
- @PathVariable("name") @ApiParam(value = "Name of the node template", required = true) String name,
- @PathVariable("version") @ApiParam(value = "Version of the node template",
- required = true) String version,
- @RequestHeader(name = REQUEST_ID_NAME, required = false)
- @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
+ @Override
+ public ResponseEntity<ToscaServiceTemplate> deleteToscaNodeTemplates(String name, String version, UUID requestId) {
try {
ToscaServiceTemplate nodeTemplates = toscaServiceTemplateService.deleteToscaNodeTemplate(name, version);
return makeOkResponse(requestId, nodeTemplates);
@@ -236,7 +110,6 @@ public class NodeTemplateController extends CommonRestController {
}
}
-
/**
* Retrieves the specified version of a node template.
*
@@ -245,42 +118,9 @@ public class NodeTemplateController extends CommonRestController {
*
* @return the Response object containing the results of the API operation
*/
- @GetMapping("/nodetemplates/{name}/versions/{version}")
- @ApiOperation(value = "Retrieve one version of a tosca node template",
- notes = "Returns a particular version of a node template",
- response = ToscaNodeTemplate.class,
- responseContainer = "List",
- responseHeaders = {
- @ResponseHeader(name = VERSION_MINOR_NAME,
- description = VERSION_MINOR_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_PATCH_NAME,
- description = VERSION_PATCH_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = REQUEST_ID_NAME,
- description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
- authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"nodeTemplates", },
- extensions = {
- @Extension(name = EXTENSION_NAME, properties = {
- @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
- @ExtensionProperty(name = LAST_MOD_NAME, value = "Jakarta")
- })
- }
- )
- @ApiResponses(value = {
- @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
- })
- public ResponseEntity<List<ToscaNodeTemplate>> getSpecificVersionOfNodeTemplate(
- @PathVariable("name") @ApiParam(value = "Name of the node template", required = true) String name,
- @PathVariable("version") @ApiParam(value = "Version of the node template",
- required = true) String version,
- @RequestHeader(name = REQUEST_ID_NAME, required = false)
- @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
+ @Override
+ public ResponseEntity<List<ToscaNodeTemplate>> getSpecificVersionOfNodeTemplate(String name, String version,
+ UUID requestId) {
try {
List<ToscaNodeTemplate> nodeTemplates = toscaServiceTemplateService.fetchToscaNodeTemplates(name, version);
return makeOkResponse(requestId, nodeTemplates);
@@ -290,45 +130,13 @@ public class NodeTemplateController extends CommonRestController {
}
}
-
/**
* Retrieves all the node templates from the tosca service template.
*
* @return the Response object containing the results of the API operation
*/
- @GetMapping("/nodetemplates")
- @ApiOperation(value = "Retrieve all the available tosca node templates",
- notes = "Returns all the node templates from the service template",
- response = ToscaNodeTemplate.class,
- responseContainer = "List",
- responseHeaders = {
- @ResponseHeader(name = VERSION_MINOR_NAME,
- description = VERSION_MINOR_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_PATCH_NAME,
- description = VERSION_PATCH_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = REQUEST_ID_NAME,
- description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
- authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"nodeTemplates", },
- extensions = {
- @Extension(name = EXTENSION_NAME, properties = {
- @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
- @ExtensionProperty(name = LAST_MOD_NAME, value = "Jakarta")
- })
- }
- )
- @ApiResponses(value = {
- @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
- @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
- })
- public ResponseEntity<List<ToscaNodeTemplate>> getAllNodeTemplates(
- @RequestHeader(name = REQUEST_ID_NAME, required = false)
- @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
+ @Override
+ public ResponseEntity<List<ToscaNodeTemplate>> getAllNodeTemplates(UUID requestId) {
try {
List<ToscaNodeTemplate> nodeTemplates = toscaServiceTemplateService.fetchToscaNodeTemplates(null, null);
return makeOkResponse(requestId, nodeTemplates);
@@ -337,5 +145,4 @@ public class NodeTemplateController extends CommonRestController {
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
}
}
-
}
diff --git a/main/src/main/resources/openapi/openapi.yaml b/main/src/main/resources/openapi/openapi.yaml
index 22e256f8..105019af 100644
--- a/main/src/main/resources/openapi/openapi.yaml
+++ b/main/src/main/resources/openapi/openapi.yaml
@@ -1,18 +1,27 @@
openapi: 3.0.1
info:
- title: Api Documentation
- description: Api Documentation
- termsOfService: urn:tos
- contact: {}
+ title: Policy Framework Lifecycle API
+ description: The Policy Fraemwork API allows the lifecycle of policy types and policyes to be managed
+ contact:
+ name: ONAP Support
+ url: https://lists.onap.org/g/onap-discuss
+ email: onap-discuss@lists.onap.org
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0
- version: "1.0"
+ version: '1.0'
+externalDocs:
+ description: Policy Framework Documentation
+ url: https://docs.onap.org/projects/onap-policy-parent/en/latest
servers:
- url: //localhost:30440/
tags:
-- name: policy-api-rest-controller
- description: Api Rest Controller
+- name: "Tosca Node Template Design"
+ description:
+ Tosca Node template Design API is publicly exposed for clients to Create/Read/Update/Delete
+ node templates which can be recognized and executable by incorporated policy engines. It is an
+ independent component running rest service that takes all node templates design API calls
+ from clients and then assign them to different API working functions.
paths:
/policy/api/v1/healthcheck:
get:
@@ -129,7 +138,7 @@ paths:
/policy/api/v1/nodetemplates:
get:
tags:
- - NodeTemplates
+ - "Tosca Node Template Design"
summary: Retrieve all the available tosca node templates
description: Returns all the node templates from the service template
operationId: getAllNodeTemplates
@@ -245,7 +254,7 @@ paths:
last-mod-release: Jakarta
put:
tags:
- - NodeTemplates
+ - "Tosca Node Template Design"
summary: Updates one or more new node templates
description: Client should provide TOSCA body of the updated node templates in an instance of
[ToscaServiceTemplate](https://github.com/onap/policy-models/blob/master/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplate.java)
@@ -262,14 +271,10 @@ paths:
content:
application/json:
schema:
- type: array
- items:
- $ref: '#/components/schemas/ToscaNodeTemplate'
+ $ref: '#/components/schemas/ToscaServiceTemplate'
application/yaml:
schema:
- type: array
- items:
- $ref: '#/components/schemas/ToscaNodeTemplate'
+ $ref: '#/components/schemas/ToscaServiceTemplate'
required: true
responses:
200:
@@ -430,7 +435,7 @@ paths:
x-codegen-request-body-name: body
post:
tags:
- - NodeTemplates
+ - "Tosca Node Template Design"
summary: Create one or more new node templates
description: Client should provide TOSCA body of the new node templates
operationId: createToscaNodeTemplates
@@ -612,7 +617,7 @@ paths:
/policy/api/v1/nodetemplates/{name}/versions/{version}:
get:
tags:
- - NodeTemplates
+ - "Tosca Node Template Design"
summary: Retrieve one version of a tosca node template
description: Returns a particular version of a node template
operationId: getSpecificVersionOfNodeTemplate
@@ -739,7 +744,7 @@ paths:
last-mod-release: Jakarta
delete:
tags:
- - NodeTemplates
+ - "Tosca Node Template Design"
summary: Updates one or more new node templates
description: Client should provide TOSCA body of the updated node templates
operationId: deleteToscaNodeTemplates