#55 migrated swagger2 to openApi specification 3

This commit is contained in:
Fabio Formosa
2021-11-09 23:39:38 +01:00
parent 3df1abd46e
commit 2ca2ba7ffc
4 changed files with 118 additions and 14 deletions

View File

@@ -137,16 +137,16 @@
<artifactId>snakeyaml</artifactId>
</dependency>
<!-- SWAGGER -->
<!-- OAS -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox.version}</version>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.12</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox.version}</version>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.1.11</version>
</dependency>
<!-- TEST -->

View File

@@ -0,0 +1,36 @@
package it.fabioformosa.quartzmanager.configuration;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class OpenApiConfig {
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI().info(apiInfo());
}
private Info apiInfo() {
return new Info()
.title("QUARTZ MANAGER API")
.description("Quartz Manager - REST API")
.version("1.0.0")
.license(new License()
.name("Apache License 2.0")
.url("https://github.com/fabioformosa/quartz-manager/blob/master/LICENSE"));
}
// private SecurityContext securityContext() {
// return SecurityContext.builder().forPaths(PathSelectors.any()).build();
// }
// @Override
// protected void addResourceHandlers(ResourceHandlerRegistry registry) {
// registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
// registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
// }
}

View File

@@ -1,18 +1,26 @@
package it.fabioformosa.quartzmanager.controllers;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import it.fabioformosa.quartzmanager.dto.SchedulerConfigParam;
import it.fabioformosa.quartzmanager.dto.SchedulerDTO;
import it.fabioformosa.quartzmanager.dto.TriggerStatus;
import it.fabioformosa.quartzmanager.enums.SchedulerStates;
import it.fabioformosa.quartzmanager.services.SchedulerService;
import org.quartz.*;
import org.quartz.SchedulerException;
import org.quartz.SimpleTrigger;
import org.quartz.impl.triggers.SimpleTriggerImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.ConversionService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Collections;
@@ -26,7 +34,6 @@ import java.util.Map;
*/
@RestController
@RequestMapping("/quartz-manager/scheduler")
@Api(value = "scheduler")
public class SchedulerController {
private final Logger log = LoggerFactory.getLogger(SchedulerController.class);
@@ -41,7 +48,14 @@ public class SchedulerController {
@Resource
private ConversionService conversionService;
//TODO replace this a list of trigger
@GetMapping("/config")
@Operation(summary = "Get the config of the trigger")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Return the trigger config",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = SchedulerConfigParam.class)) })
})
public SchedulerConfigParam getConfig() throws SchedulerException {
log.debug("SCHEDULER - GET CONFIG params");
SchedulerConfigParam schedulerConfigParam = schedulerService.getOneSimpleTrigger()
@@ -58,13 +72,26 @@ public class SchedulerController {
}
@GetMapping
@Operation(summary = "Get the scheduler details")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Return the scheduler config",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = SchedulerDTO.class)) })
})
public SchedulerDTO getScheduler() {
log.debug("SCHEDULER - GET Scheduler...");
SchedulerDTO schedulerDTO = conversionService.convert(schedulerService.getScheduler(), SchedulerDTO.class);
return schedulerDTO;
}
//TODO move this to the Trigger Controller
@GetMapping("/progress")
@Operation(summary = "Get the trigger status")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Return the trigger status",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = TriggerStatus.class)) })
})
public TriggerStatus getProgressInfo() throws SchedulerException {
log.trace("SCHEDULER - GET PROGRESS INFO");
TriggerStatus progress = new TriggerStatus();
@@ -84,6 +111,12 @@ public class SchedulerController {
}
@GetMapping(value = "/status", produces = "application/json")
@Operation(summary = "Get the scheduler status")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Return the scheduler status",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = SchedulerStates.class)) })
})
public Map<String, String> getStatus() throws SchedulerException {
log.trace("SCHEDULER - GET STATUS");
String schedulerState = "";
@@ -97,6 +130,10 @@ public class SchedulerController {
}
@GetMapping("/pause")
@Operation(summary = "Get paused the scheduler")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "Got paused successfully")
})
@ResponseStatus(HttpStatus.NO_CONTENT)
public void pause() throws SchedulerException {
log.info("SCHEDULER - PAUSE COMMAND");
@@ -104,6 +141,10 @@ public class SchedulerController {
}
@GetMapping("/resume")
@Operation(summary = "Get resumed the scheduler")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "Got resumed successfully")
})
@ResponseStatus(HttpStatus.NO_CONTENT)
public void resume() throws SchedulerException {
log.info("SCHEDULER - RESUME COMMAND");
@@ -111,6 +152,10 @@ public class SchedulerController {
}
@GetMapping("/run")
@Operation(summary = "Start the scheduler")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "Got started successfully")
})
@ResponseStatus(HttpStatus.NO_CONTENT)
public void run() throws SchedulerException {
log.info("SCHEDULER - START COMMAND");
@@ -118,6 +163,10 @@ public class SchedulerController {
}
@GetMapping("/stop")
@Operation(summary = "Stop the scheduler")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "Got stopped successfully")
})
@ResponseStatus(HttpStatus.NO_CONTENT)
public void stop() throws SchedulerException {
log.info("SCHEDULER - STOP COMMAND");

View File

@@ -1,6 +1,10 @@
package it.fabioformosa.quartzmanager.controllers;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import it.fabioformosa.quartzmanager.dto.SchedulerConfigParam;
import it.fabioformosa.quartzmanager.dto.TriggerDTO;
import it.fabioformosa.quartzmanager.services.SchedulerService;
@@ -15,7 +19,6 @@ import javax.validation.Valid;
@Slf4j
@RequestMapping(TriggerController.TRIGGER_CONTROLLER_BASE_URL)
@RestController
@Api(value = "triggers")
public class TriggerController {
static public final String TRIGGER_CONTROLLER_BASE_URL = "/quartz-manager/triggers";
@@ -34,8 +37,16 @@ public class TriggerController {
return schedulerService.getTriggerByName(name);
}
@ResponseStatus(HttpStatus.CREATED)
@PostMapping("/{name}")
@ResponseStatus(HttpStatus.CREATED)
@Operation(summary = "Create a new trigger")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "Created the new trigger",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = TriggerDTO.class)) }),
@ApiResponse(responseCode = "400", description = "Invalid config supplied",
content = @Content)
})
public TriggerDTO postTrigger(@PathVariable String name, @Valid @RequestBody SchedulerConfigParam config) throws SchedulerException, ClassNotFoundException {
log.info("TRIGGER - CREATING a trigger {} {}", name, config);
TriggerDTO newTriggerDTO = schedulerService.scheduleNewTrigger(name, jobClassname, config);
@@ -44,6 +55,14 @@ public class TriggerController {
}
@PutMapping("/{name}")
@Operation(summary = "Reschedule the trigger")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Rescheduled the trigger",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = TriggerDTO.class)) }),
@ApiResponse(responseCode = "400", description = "Invalid config supplied",
content = @Content)
})
public TriggerDTO rescheduleTrigger(@PathVariable String name, @Valid @RequestBody SchedulerConfigParam config) throws SchedulerException {
log.info("TRIGGER - RESCHEDULING the trigger {} {}", name, config);
TriggerDTO triggerDTO = schedulerService.rescheduleTrigger(name, config);