diff options
author | Bogumil Zebek <bogumil.zebek@nokia.com> | 2021-03-15 12:57:59 +0100 |
---|---|---|
committer | Zebek Bogumil <bogumil.zebek@nokia.com> | 2021-03-15 12:57:59 +0100 |
commit | bb84e030c255b379a46cc1b0bbaaebb24ec056b9 (patch) | |
tree | 0b9a6a23b5f39b5adfdd30715fb43f885688e2a6 /src | |
parent | bae12bf7d5a92a4d6be22e9ce8c3dc9878c59f36 (diff) |
Update swagger doc Extend swagger documentation.
Issue-ID: INT-1869
Signed-off-by: Zebek Bogumil <bogumil.zebek@nokia.com>
Change-Id: I5496b5f28a6599da231b2542c270682243c5421f
Diffstat (limited to 'src')
4 files changed, 89 insertions, 7 deletions
diff --git a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/SwaggerConfig.java b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/SwaggerConfig.java index c709729..1973621 100644 --- a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/SwaggerConfig.java +++ b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/SwaggerConfig.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ - * Copyright (C) 2018 Nokia. All rights reserved. + * Copyright (C) 2021 Nokia. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ public class SwaggerConfig { public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() - .apis(RequestHandlerSelectors.basePackage("org.onap.pnfsimulator")) + .apis(RequestHandlerSelectors.basePackage("org.onap.integration.simulators.nfsimulator.vesclient")) .paths(PathSelectors.any()) .build(); } diff --git a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/SimulatorController.java b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/SimulatorController.java index d9aebe3..e9073fd 100644 --- a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/SimulatorController.java +++ b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/SimulatorController.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ - * Copyright (C) 2018 Nokia. All rights reserved. + * Copyright (C) 2021 Nokia. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,11 @@ package org.onap.integration.simulators.nfsimulator.vesclient.rest; import com.google.common.collect.ImmutableMap; import com.google.gson.JsonSyntaxException; +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 org.json.JSONException; import org.onap.integration.simulators.nfsimulator.vesclient.event.EventData; import org.onap.integration.simulators.nfsimulator.vesclient.event.EventDataService; @@ -70,6 +75,7 @@ import static org.springframework.http.HttpStatus.OK; @RestController @RequestMapping("/simulator") +@Api(tags = "Ves client", value = "Simulate Ves client") public class SimulatorController { private static final Logger LOGGER = LoggerFactory.getLogger(SimulatorController.class); @@ -101,8 +107,18 @@ public class SimulatorController { } @PostMapping(value = "start") + @ApiOperation(value = "Start a job which will send a multiple events to VES") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Job scheduled successfully. It returns: {'message':'<txt>', 'jobName':'<job_name>'}"), + @ApiResponse(code = 400, message = "Bad request: invalid json in payload"), + @ApiResponse(code = 500, message = "Internal server error: unexpected error") }) public ResponseEntity<Map<String, Object>> start(@RequestHeader HttpHeaders headers, - @Valid @RequestBody SimulatorRequest triggerEventRequest) { + @Valid + @RequestBody + @ApiParam( + name = "jobConfiguration", + value = "Information what to send as event and when", + required = true) SimulatorRequest triggerEventRequest) { logContextHeaders(headers, "/simulator/start"); LOGGER.info(ENTRY, "Simulator started"); @@ -152,18 +168,42 @@ public class SimulatorController { } @GetMapping("config") + @ApiOperation(value = "Get simulator configuration") + @ApiResponses( + value = { + @ApiResponse(code=200, message = "Ves client configuration fetched. It returns: {'simulatorConfig': {'vesServerUrl': '<urlToVesService>'} }"), + } + ) public ResponseEntity<Map<String, Object>> getConfig() { SimulatorConfig configToGet = simulatorService.getConfiguration(); return buildResponse(OK, ImmutableMap.of("simulatorConfig", configToGet)); } @PutMapping("config") - public ResponseEntity<Map<String, Object>> updateConfig(@Valid @RequestBody SimulatorConfig newConfig) { + @ApiOperation(value = "Update simulator configuration") + @ApiResponses( + value = { + @ApiResponse(code=200, message = "Ves client configuration updated. It returns: {'simulatorConfig': {'vesServerUrl': '<urlToVesService>'} }"), + } + ) + public ResponseEntity<Map<String, Object>> updateConfig( + @Valid @RequestBody + @ApiParam( + name = "clientConfiguration", + value = "Client configuration", + required = true) SimulatorConfig newConfig) { SimulatorConfig updatedConfig = simulatorService.updateConfiguration(newConfig); return buildResponse(OK, ImmutableMap.of("simulatorConfig", updatedConfig)); } @PostMapping("cancel/{jobName}") + @ApiOperation(value = "Cancel a single job which sends events to VES") + @ApiResponses( + value = { + @ApiResponse(code=200, message = "Job cancelled successfully"), + @ApiResponse(code=404, message = "Unable to find job to cancel"), + } + ) public ResponseEntity<Map<String, Object>> cancelEvent(@PathVariable String jobName) throws SchedulerException { String jobNameNoBreakingCharacters = replaceBreakingCharacters(jobName); LOGGER.info(ENTRY, "Cancel called on {}.", jobNameNoBreakingCharacters); @@ -172,6 +212,13 @@ public class SimulatorController { } @PostMapping("cancel") + @ApiOperation(value = "Cancel all jobs which send events to VES") + @ApiResponses( + value = { + @ApiResponse(code=200, message = "Jobs cancelled successfully"), + @ApiResponse(code=404, message = "Unable to find job to cancel"), + } + ) public ResponseEntity<Map<String, Object>> cancelAllEvent() throws SchedulerException { LOGGER.info(ENTRY, "Cancel called on all jobs"); boolean isCancelled = simulatorService.cancelAllEvents(); @@ -179,7 +226,19 @@ public class SimulatorController { } @PostMapping("event") - public ResponseEntity<Map<String, Object>> sendEventDirectly(@RequestHeader HttpHeaders headers, @Valid @RequestBody FullEvent event) + @ApiOperation(value = "Send single event to VES") + @ApiResponses( + value = { + @ApiResponse(code=200, message = "Event sent successfully") + } + ) + public ResponseEntity<Map<String, Object>> sendEventDirectly( + @RequestHeader HttpHeaders headers, + @Valid @RequestBody + @ApiParam( + name = "event", + value = "Event to send", + required = true) FullEvent event) throws IOException, GeneralSecurityException { logContextHeaders(headers, "/simulator/event"); LOGGER.info(ENTRY, "Trying to send one-time event directly to VES Collector"); diff --git a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/TemplateController.java b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/TemplateController.java index 120b24d..9d9c1e3 100644 --- a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/TemplateController.java +++ b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/TemplateController.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Simulator * ================================================================================ - * Copyright (C) 2019 Nokia. All rights reserved. + * Copyright (C) 2021 Nokia. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,10 @@ import java.util.Optional; import javax.validation.Valid; import com.google.gson.Gson; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.onap.integration.simulators.nfsimulator.vesclient.db.Storage; import org.onap.integration.simulators.nfsimulator.vesclient.rest.model.TemplateRequest; import org.onap.integration.simulators.nfsimulator.vesclient.template.Template; @@ -48,6 +52,7 @@ import org.springframework.web.server.ResponseStatusException; @RestController @RequestMapping("/template") +@Api(tags = "Template controller", value = "Template controller") public class TemplateController { static final String TEMPLATE_NOT_FOUND_MSG = "A template with given name does not exist"; static final String CANNOT_OVERRIDE_TEMPLATE_MSG = "Cannot overwrite existing template. Use override=true to override"; @@ -59,11 +64,19 @@ public class TemplateController { } @GetMapping("list") + @ApiOperation(value = "Fetch all templates supported by Ves client") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "It returns list of supported templates.") + }) public ResponseEntity<List<Template>> list() { return new ResponseEntity<>(service.getAll(), HttpStatus.OK); } @GetMapping("get/{templateName}") + @ApiOperation(value = "Fetch details about selected template") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "It returns an information about selected template.") + }) public ResponseEntity<String> get(@PathVariable String templateName) { Optional<Template> template = service.get(templateName); return template @@ -84,6 +97,10 @@ public class TemplateController { } @PostMapping("upload") + @ApiOperation(value = "Upload a new template") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Template uploaded") + }) public ResponseEntity<String> upload( @RequestBody @Valid TemplateRequest templateRequest, @RequestParam(required = false) boolean override) { @@ -98,6 +115,10 @@ public class TemplateController { } @PostMapping("search") + @ApiOperation(value = "Fetch templates which fit to query") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Returns list of templates fitted to query.") + }) public ResponseEntity<List<String>> searchByCriteria(@RequestBody SearchExp queryJson) { try { List<String> templateNames = service.getIdsByContentCriteria(queryJson.getSearchExpr()); diff --git a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulatorconfig/SimulatorConfig.java b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulatorconfig/SimulatorConfig.java index 8b0588c..3f8c90e 100644 --- a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulatorconfig/SimulatorConfig.java +++ b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulatorconfig/SimulatorConfig.java @@ -21,6 +21,7 @@ package org.onap.integration.simulators.nfsimulator.vesclient.simulatorconfig; import com.fasterxml.jackson.annotation.JsonIgnore; +import io.swagger.annotations.ApiModel; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -37,6 +38,7 @@ import java.net.URL; @AllArgsConstructor @NoArgsConstructor @ToString +@ApiModel(value = "ClientConfiguration", description = "Provides url to VES endpoint") public class SimulatorConfig { @JsonIgnore |