diff options
author | JakobKrieg <jakob.krieg@bcmsolutions.de> | 2020-12-08 19:04:52 +0100 |
---|---|---|
committer | JakobKrieg <jakob.krieg@bcmsolutions.de> | 2020-12-08 19:04:57 +0100 |
commit | a4b721c3e9c4aa7c5342304a061dc5634935acd0 (patch) | |
tree | 74cd05438a98f4fdf73b487026a5908f7e9317b1 /ms/blueprintsprocessor/modules/inbounds/designer-api/src | |
parent | 0ac5e3da98031d71388328ae519ee5ce4db8269c (diff) |
CDS add Swagger annotations for BP Model API
Issue-ID: CCSDK-3014
Change-Id: Ibca7cbaa2c70f04acf818e2b554664e13b116c5e
Signed-off-by: JakobKrieg <jakob.krieg@bcmsolutions.de>
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/designer-api/src')
2 files changed, 195 insertions, 34 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt index 0fadec30c..167e4358d 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt @@ -19,7 +19,10 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api import io.swagger.annotations.ApiOperation +import io.swagger.annotations.Api import io.swagger.annotations.ApiParam +import io.swagger.annotations.ApiResponse +import io.swagger.annotations.ApiResponses import org.jetbrains.annotations.NotNull import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.BluePrintModelHandler @@ -55,28 +58,64 @@ import org.springframework.web.bind.annotation.RestController */ @RestController @RequestMapping("/api/v1/blueprint-model") +@Api( + value = "Blueprint Model Catalog API", + description = "Manages all blueprint models which are available in CDS" +) open class BlueprintModelController(private val bluePrintModelHandler: BluePrintModelHandler) { @PostMapping( path = arrayOf("/bootstrap"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE), consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE) ) + @ApiOperation( + value = "Bootstrap CDS", + notes = "Loads all Model Types, Resource Dictionaries and Blueprint Models which are included in CDS by default. " + + "Before starting to work with CDS, bootstrap should be called to load all the basic models that each orginization might support. " + + "Parameter values can be set as `false` to skip loading e.g. the Resource Dictionaries but this is not recommended." + ) + @ApiResponses( + ApiResponse(code = 200, message = "OK"), + ApiResponse(code = 500, message = "Internal Server Error") + ) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") - suspend fun bootstrap(@RequestBody bootstrapRequest: BootstrapRequest): Unit = mdcWebCoroutineScope { + suspend fun bootstrap( + @ApiParam(required = true, value = "Specifies which elements to load") + @RequestBody bootstrapRequest: BootstrapRequest + ): Unit = mdcWebCoroutineScope { bluePrintModelHandler.bootstrapBlueprint(bootstrapRequest) } - @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) + @PostMapping(produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) + @ApiOperation( + value = "Save a Blueprint Model", + notes = "Saves a blueprint model by the given CBA zip file input. There is no validation of the attached CBA happening when this API is called." + ) + @ApiResponses( + ApiResponse(code = 200, message = "OK"), + ApiResponse(code = 500, message = "Internal Server Error") + ) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") - suspend fun saveBlueprint(@RequestPart("file") filePart: FilePart): BlueprintModelSearch = mdcWebCoroutineScope { + suspend fun saveBlueprint( + @ApiParam(name = "file", value = "CBA file to be uploaded (example: cba.zip)", required = true) + @RequestPart("file") filePart: FilePart + ): BlueprintModelSearch = mdcWebCoroutineScope { bluePrintModelHandler.saveBlueprintModel(filePart) } - @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE]) + @GetMapping(produces = [MediaType.APPLICATION_JSON_VALUE]) + @ApiOperation( + value = "List all Blueprint Models", + notes = "Lists all meta-data of blueprint models which are saved in CDS." + ) + @ApiResponses( + ApiResponse(code = 200, message = "OK"), + ApiResponse(code = 500, message = "Internal Server Error") + ) @ResponseBody @PreAuthorize("hasRole('USER')") fun allBlueprintModel(): List<BlueprintModelSearch> { @@ -84,13 +123,18 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint } @GetMapping("/paged", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ApiOperation( + value = "Get Blueprints ordered", + notes = "Lists all blueprint models which are saved in CDS in an ordered mode.", + nickname = "BlueprintModelController_allBlueprintModelPaged_GET.org.onap.ccsdk.cds.blueprintsprocessor.designer.api" + ) @ResponseBody @PreAuthorize("hasRole('USER')") fun allBlueprintModel( - @RequestParam(defaultValue = "20") limit: Int, - @RequestParam(defaultValue = "0") offset: Int, - @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption, - @RequestParam(defaultValue = "ASC") sortType: String + @ApiParam(value = "Maximum number of returned blueprint models") @RequestParam(defaultValue = "20") limit: Int, + @ApiParam(value = "Offset") @RequestParam(defaultValue = "0") offset: Int, + @ApiParam(value = "Order of returned blueprint models") @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption, + @ApiParam(value = "Ascend or descend ordering") @RequestParam(defaultValue = "ASC") sortType: String ): Page<BlueprintModelSearch> { val pageRequest = PageRequest.of( offset, limit, @@ -100,22 +144,39 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint } @GetMapping("meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ApiOperation( + value = "Search for Blueprints by a Keyword", + notes = "Lists all blueprint models by a matching keyword in any of the meta-data of the blueprint models. " + + "Blueprint models are just returned if a whole keyword is matching, not just parts of it. Not case-sensitive. " + + "Used by CDS UI." + ) @ResponseBody @PreAuthorize("hasRole('USER')") - suspend fun allBlueprintModelMetaData(@NotNull @PathVariable(value = "keyword") keyWord: String): List<BlueprintModelSearch> = + suspend fun allBlueprintModelMetaData( + @NotNull + @ApiParam(value = "Keyword to search for in blueprint model meta-data", required = true, example = "pnf_netconf") + @PathVariable(value = "keyword") keyWord: String + ): List<BlueprintModelSearch> = mdcWebCoroutineScope { bluePrintModelHandler.searchBluePrintModelsByKeyWord(keyWord) } @GetMapping("/paged/meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ApiOperation( + value = "Search for Blueprints by a Keyword in an ordered mode", + notes = "Lists all blueprint models by a matching keyword in any of the meta-data of the blueprint models in an ordered mode. " + + "Blueprint models are just returned if a whole keyword is matching, not just parts of it. Not case-sensitive. " + + "Used by CDS UI." + ) @ResponseBody @PreAuthorize("hasRole('USER')") fun allBlueprintModelMetaDataPaged( + @ApiParam(value = "Keyword to search for in blueprint model meta-data", required = true, example = "pnf_netconf") @NotNull @PathVariable(value = "keyword") keyWord: String, - @RequestParam(defaultValue = "20") limit: Int, - @RequestParam(defaultValue = "0") offset: Int, - @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption, - @RequestParam(defaultValue = "ASC") sortType: String + @ApiParam(value = "Maximum number of returned blueprint models") @RequestParam(defaultValue = "20") limit: Int, + @ApiParam(value = "Offset") @RequestParam(defaultValue = "0") offset: Int, + @ApiParam(value = "Order of returned blueprint models") @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption, + @ApiParam(value = "Ascend or descend ordering") @RequestParam(defaultValue = "ASC") sortType: String ): Page<BlueprintModelSearch> { val pageRequest = PageRequest.of( offset, limit, @@ -125,19 +186,38 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint } @DeleteMapping("/{id}") + @ApiOperation( + value = "Delete a Blueprint Model by ID", + notes = "Delete a blueprint model by its ID. ID is the internally created ID of blueprint, not the name of blueprint." + ) + @ApiResponses( + ApiResponse(code = 200, message = "OK"), + ApiResponse(code = 404, message = "RESOURCE_NOT_FOUND") + ) @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") - suspend fun deleteBlueprint(@PathVariable(value = "id") id: String) = mdcWebCoroutineScope { + suspend fun deleteBlueprint( + @ApiParam(value = "ID of the blueprint model to delete", required = true, example = "67ec1f96-ab55-4b81-aff9-23ee0ed1d7a4") + @PathVariable(value = "id") id: String + ) = mdcWebCoroutineScope { bluePrintModelHandler.deleteBlueprintModel(id) } @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ApiOperation( + value = "Get a Blueprint Model by Name and Version", + notes = "Get Meta-Data of a Blueprint Model by its name and version." + ) + @ApiResponses( + ApiResponse(code = 200, message = "OK"), + ApiResponse(code = 404, message = "Not Found") + ) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") suspend fun getBlueprintByNameAndVersion( - @PathVariable(value = "name") name: String, - @PathVariable(value = "version") version: String + @ApiParam(value = "Name of the blueprint model", required = true, example = "pnf_netconf") @PathVariable(value = "name") name: String, + @ApiParam(value = "Version of the blueprint model", required = true, example = "1.0.0") @PathVariable(value = "version") version: String ): ResponseEntity<BlueprintModelSearch> = mdcWebCoroutineScope { val bluePrintModel: BlueprintModelSearch? = bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version) @@ -148,29 +228,59 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint } @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ApiOperation( + value = "Download a Blueprint Model", + notes = "Gets the CBA of a blueprint model by its name and version. Response can be saved to a file to download the CBA." + ) + @ApiResponses( + ApiResponse(code = 200, message = "OK"), + ApiResponse(code = 404, message = "Not Found") + ) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") suspend fun downloadBlueprintByNameAndVersion( - @PathVariable(value = "name") name: String, - @PathVariable(value = "version") version: String + @ApiParam(value = "Name of the blueprint model", required = true, example = "pnf_netconf") @PathVariable(value = "name") name: String, + @ApiParam(value = "Version of the blueprint model", required = true, example = "1.0.0") @PathVariable(value = "version") version: String ): ResponseEntity<Resource> = mdcWebCoroutineScope { bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version) } @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ApiOperation( + value = "Get a Blueprint Model by ID", + notes = "Get meta-data of a blueprint model by its internally created ID." + ) + @ApiResponses( + ApiResponse(code = 200, message = "OK"), + ApiResponse(code = 404, message = "Not Found") + ) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") - suspend fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch = mdcWebCoroutineScope { + suspend fun getBlueprintModel( + @ApiParam(value = "ID of the blueprint model to search for", required = true, example = "67ec1f96-ab55-4b81-aff9-23ee0ed1d7a4") + @PathVariable(value = "id") id: String + ): BlueprintModelSearch = mdcWebCoroutineScope { bluePrintModelHandler.getBlueprintModelSearch(id) } @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ApiOperation( + value = "Download a Blueprint Model by ID", + notes = "Gets the CBA of a blueprint model by its ID. Response can be saved to a file to download the CBA." + ) + @ApiResponses( + ApiResponse(code = 200, message = "OK"), + ApiResponse(code = 404, message = "Not Found") + ) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") - suspend fun downloadBluePrint(@PathVariable(value = "id") id: String): ResponseEntity<Resource> = + suspend fun downloadBluePrint( + @ApiParam(value = "ID of the blueprint model to download", required = true, example = "67ec1f96-ab55-4b81-aff9-23ee0ed1d7a4") + @PathVariable(value = "id") id: String + ): ResponseEntity<Resource> = mdcWebCoroutineScope { bluePrintModelHandler.downloadBlueprintModelFile(id) } @@ -182,10 +292,18 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint .MULTIPART_FORM_DATA_VALUE ] ) + @ApiOperation( + value = "Enrich a Blueprint Model", + notes = "Enriches the attached CBA and returns the enriched CBA zip file in the response. " + + "The enrichment process will complete the package by providing all the definition of types used." + ) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") - suspend fun enrichBlueprint(@RequestPart("file") file: FilePart): ResponseEntity<Resource> = mdcWebCoroutineScope { + suspend fun enrichBlueprint( + @ApiParam(name = "file", value = "CBA zip file to be uploaded (example: cba_unenriched.zip)", required = true) + @RequestPart("file") file: FilePart + ): ResponseEntity<Resource> = mdcWebCoroutineScope { bluePrintModelHandler.enrichBlueprint(file) } @@ -196,41 +314,68 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint .MULTIPART_FORM_DATA_VALUE ] ) + @ApiOperation( + value = "Enrich and publish a Blueprint Model", + notes = "Enriches the attached CBA, validates it and saves it in CDS if validation was successful." + ) + @ApiResponses( + ApiResponse(code = 200, message = "OK"), + ApiResponse(code = 503, message = "Service Unavailable") + ) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") - suspend fun enrichAndPubishlueprint(@RequestPart("file") file: FilePart): BlueprintModelSearch = mdcWebCoroutineScope { + suspend fun enrichAndPubishlueprint( + @ApiParam(name = "file", value = "Unenriched CBA zip file to be uploaded (example: cba_unenriched.zip)", required = true) + @RequestPart("file") file: FilePart + ): BlueprintModelSearch = mdcWebCoroutineScope { bluePrintModelHandler.enrichAndPublishBlueprint(file) } - @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE]) + @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) + @ApiOperation( + value = "Publish a Blueprint Model", + notes = "Validates the attached CBA file and saves it in CDS if validation was successful. CBA needs to be already enriched." + ) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") - suspend fun publishBlueprint(@RequestPart("file") file: FilePart): BlueprintModelSearch = mdcWebCoroutineScope { + suspend fun publishBlueprint( + @ApiParam(name = "file", value = "Enriched CBA zip file to be uploaded (example: cba_enriched.zip)", required = true) + @RequestPart("file") file: FilePart + ): BlueprintModelSearch = mdcWebCoroutineScope { bluePrintModelHandler.publishBlueprint(file) } @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ApiOperation( + value = "Search for a Blueprint by Tag", + notes = "Searches for all blueprint models which contain the specified input parameter in their tags. " + + "Blueprint models which contain just parts of the searched word in their tags are also returned." + ) @ResponseBody @PreAuthorize("hasRole('USER')") - suspend fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List<BlueprintModelSearch> = + suspend fun searchBlueprintModels( + @ApiParam(value = "Tag to search for", example = "test", required = true) + @PathVariable(value = "tags") tags: String + ): List<BlueprintModelSearch> = mdcWebCoroutineScope { bluePrintModelHandler.searchBlueprintModels(tags) } @DeleteMapping("/name/{name}/version/{version}") @ApiOperation( - value = "Delete a CBA", - notes = "Delete the CBA package identified by its name and version.", - nickname = "BlueprintModelController_deleteBlueprint_1_DELETE.org.onap.ccsdk.cds.blueprintsprocessor.designer.api", + value = "Delete a Blueprint Model by Name", + notes = "Deletes a blueprint model identified by its name and version from CDS.", + // to avoid duplicate operation IDs + nickname = "BlueprintModelController_deleteBlueprintByName_DELETE.org.onap.ccsdk.cds.blueprintsprocessor.designer.api", produces = MediaType.APPLICATION_JSON_VALUE ) @PreAuthorize("hasRole('USER')") suspend fun deleteBlueprint( - @ApiParam(value = "Name of the CBA.", required = true) + @ApiParam(value = "Name of the blueprint model", required = true, example = "pnf_netconf") @PathVariable(value = "name") name: String, - @ApiParam(value = "Version of the CBA.", required = true) + @ApiParam(value = "Version of the blueprint model", required = true, example = "1.0.0") @PathVariable(value = "version") version: String ) = mdcWebCoroutineScope { bluePrintModelHandler.deleteBlueprintModel(name, version) @@ -244,6 +389,11 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint ), consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE) ) + @ApiOperation( + value = "Get Workflow Specification", + notes = "Get the workflow of a blueprint identified by Blueprint and workflow name. " + + "Inputs, outputs and data types of workflow is returned." + ) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") @@ -256,18 +406,21 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint @GetMapping( path = arrayOf( - "/workflows/blueprint-name/{name}/version/{version" + - "}" + "/workflows/blueprint-name/{name}/version/{version}" ), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE) ) + @ApiOperation( + value = "Get Workflows of a Blueprint", + notes = "Get all available workflows of a Blueprint identified by its name and version." + ) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") suspend fun getWorkflowList( - @ApiParam(value = "Name of the CBA.", required = true) + @ApiParam(value = "Name of the blueprint model", example = "pnf_netconf", required = true) @PathVariable(value = "name") name: String, - @ApiParam(value = "Version of the CBA.", required = true) + @ApiParam(value = "Version of the blueprint model", example = "1.0.0", required = true) @PathVariable(value = "version") version: String ): ResponseEntity<String> = mdcWebCoroutineScope { var json = bluePrintModelHandler.getWorkflowNames(name, version) diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt index 1d32b9493..741a9115c 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt @@ -17,6 +17,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.DATA_TYPE_JSON import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.DEFAULT_VERSION_NUMBER @@ -27,8 +29,11 @@ import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment class BootstrapRequest { + @ApiModelProperty(value = "Specifies if default model types should be loaded", example = "true", required = true) var loadModelType: Boolean = false + @ApiModelProperty(value = "Specifies if default data dictionaries should be loaded", example = "true", required = true) var loadResourceDictionary: Boolean = false + @ApiModelProperty(value = "Specifies if default blueprint models should be loaded", example = "true", required = true) var loadCBA: Boolean = false } @@ -39,11 +44,14 @@ class WorkFlowsResponse { var workflows: MutableSet<String> = mutableSetOf() } +@ApiModel class WorkFlowSpecRequest { + @ApiModelProperty(value = "Name of the BLueprint", example = "\"pnf_netconf\"", required = true) lateinit var blueprintName: String var version: String = DEFAULT_VERSION_NUMBER var returnContent: String = DATA_TYPE_JSON + @ApiModelProperty(value = "Name of the Workflow", example = "\"config-assign\"", required = true) lateinit var workflowName: String var specType: String = TOSCA_SPEC } |