From bb84e030c255b379a46cc1b0bbaaebb24ec056b9 Mon Sep 17 00:00:00 2001 From: Bogumil Zebek Date: Mon, 15 Mar 2021 12:57:59 +0100 Subject: Update swagger doc Extend swagger documentation. Issue-ID: INT-1869 Signed-off-by: Zebek Bogumil Change-Id: I5496b5f28a6599da231b2542c270682243c5421f --- Makefile | 5 ++ .../nfsimulator/vesclient/SwaggerConfig.java | 4 +- .../vesclient/rest/SimulatorController.java | 67 ++++++++++++++++++++-- .../vesclient/rest/TemplateController.java | 23 +++++++- .../vesclient/simulatorconfig/SimulatorConfig.java | 2 + 5 files changed, 94 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index b851bcb..f85f364 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,11 @@ all: start .PHONY: start +build: + @echo "##### Build Ves client #####" + mvn clean package -Pdocker + @echo "##### DONE #####" + start: @echo "##### Start Ves client #####" docker-compose up -d 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':'', 'jobName':''}"), + @ApiResponse(code = 400, message = "Bad request: invalid json in payload"), + @ApiResponse(code = 500, message = "Internal server error: unexpected error") }) public ResponseEntity> 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': ''} }"), + } + ) public ResponseEntity> getConfig() { SimulatorConfig configToGet = simulatorService.getConfiguration(); return buildResponse(OK, ImmutableMap.of("simulatorConfig", configToGet)); } @PutMapping("config") - public ResponseEntity> updateConfig(@Valid @RequestBody SimulatorConfig newConfig) { + @ApiOperation(value = "Update simulator configuration") + @ApiResponses( + value = { + @ApiResponse(code=200, message = "Ves client configuration updated. It returns: {'simulatorConfig': {'vesServerUrl': ''} }"), + } + ) + public ResponseEntity> 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> 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> 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> 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> 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() { 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 get(@PathVariable String templateName) { Optional