Update Swagger ui

This commit is contained in:
George Kalampokis 2023-10-12 10:55:48 +03:00
parent 8b05ee1d0f
commit b845450ebd
6 changed files with 99 additions and 103 deletions

View File

@ -82,7 +82,7 @@
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.9.0</version>
<version>3.1.5</version>
</dependency>
@ -91,17 +91,17 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.2</version>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.22</version>
<version>42.6.0</version>
</dependency>
<dependency>
<!--<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
@ -116,7 +116,12 @@
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
-->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
</dependency>
<!-- facebook Login -->
<dependency>
<groupId>org.springframework.social</groupId>

View File

@ -1,20 +1,12 @@
package eu.eudat.publicapi.configurations;
import eu.eudat.models.data.security.Principal;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.SecurityScheme;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import java.util.Collections;
import java.util.HashSet;
@Configuration
public class SwaggerConfiguration {
@ -25,25 +17,16 @@ public class SwaggerConfiguration {
private Environment environment;
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.host(this.environment.getProperty("publicapi.host"))
.protocols(new HashSet<>(Collections.singleton(this.environment.getProperty("publicapi.schema"))))
.select()
.apis(RequestHandlerSelectors.basePackage("eu.eudat.publicapi.controllers"))
.paths(PathSelectors.regex("/api/public/(dmps|datasets)/?.*"))
.build().apiInfo(apiInfo())//.ignoredParameterTypes(Principal.class)
.pathMapping(this.environment.getProperty("publicapi.basePath"))
.useDefaultResponseMessages(false);
public OpenAPI ArgosOpenApi() {
return new OpenAPI().info(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfo(
"OpenDMP public API",
"Argos public API.",
"1.0",
"https://argos.openaire.eu/terms-and-conditions",
new Contact("Argos", "https://argos.openaire.eu/", "argos@openaire.eu "),
null, null, Collections.emptyList());
private Info apiInfo() {
return new Info()
.title("OpenDMP public API")
.description("Argos public API.")
.version("1.0")
.termsOfService("https://argos.openaire.eu/terms-and-conditions")
.contact(new Contact().name("Argos").url("https://argos.openaire.eu/").email("argos@openaire.eu "));
}
}

View File

@ -13,6 +13,12 @@ import eu.eudat.publicapi.request.dataset.DatasetPublicTableRequest;
import eu.eudat.types.ApiMessageCode;
import eu.eudat.types.Authorities;
import io.swagger.annotations.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -22,7 +28,7 @@ import org.springframework.web.bind.annotation.*;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@Api(tags = "Datasets Description", description = "Provides Dataset description public API's.")
@Tag(name = "Datasets Description", description = "Provides Dataset description public API's.")
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/public/datasets/"})
@ -214,34 +220,32 @@ public class PublicDatasetsDescriptionDocumentation extends BaseController {
this.datasetManager = datasetManager;
}
@ApiOperation(value = "This method is used to get a listing of public datasets.", notes = getPagedNotes)
@ApiResponses(value = {@ApiResponse(
code = 200,
message = "The following example is generated using body: *{\"criteria\": {},\"length\": 2,\"offset\": 0,\"orderings\": {\"fields\": []} }*",
examples = @Example({@ExampleProperty(
value = getPagedResponseExample,
mediaType = APPLICATION_JSON_VALUE
@Operation(summary = "This method is used to get a listing of public datasets.", description = getPagedNotes)
@io.swagger.v3.oas.annotations.responses.ApiResponses(value = {@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "200",
description = "The following example is generated using body: *{\"criteria\": {},\"length\": 2,\"offset\": 0,\"orderings\": {\"fields\": []} }*",
content = @Content(mediaType = APPLICATION_JSON_VALUE, examples = {@ExampleObject(
value = getPagedResponseExample
)})
)})
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DatasetPublicListingModel>>> getPaged(@RequestBody @ApiParam(value = getPagedRequestBodyDescription) DatasetPublicTableRequest datasetTableRequest) throws Exception {
ResponseEntity<ResponseItem<DataTableData<DatasetPublicListingModel>>> getPaged(@RequestBody @Parameter(description = getPagedRequestBodyDescription) DatasetPublicTableRequest datasetTableRequest) throws Exception {
DataTableData<DatasetPublicListingModel> dataTable = this.datasetManager.getPublicPaged(datasetTableRequest);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetPublicListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
}
@ApiOperation(value = "This method is used to get the overview of a public dataset.", notes = getOverviewSinglePublicNotes)
@ApiResponses(value = {@ApiResponse(
code = 200,
message = "The following example is generated using id: *ef7dfbdc-c5c1-46a7-a37b-c8d8692f1c0e*",
examples = @Example({@ExampleProperty(
value = getOverviewSinglePublicResponseExample,
mediaType = APPLICATION_JSON_VALUE
@Operation(summary = "This method is used to get the overview of a public dataset.", description = getOverviewSinglePublicNotes)
@io.swagger.v3.oas.annotations.responses.ApiResponses(value = {@ApiResponse(
responseCode = "200",
description = "The following example is generated using id: *ef7dfbdc-c5c1-46a7-a37b-c8d8692f1c0e*",
content = @Content(mediaType = APPLICATION_JSON_VALUE, examples = {@ExampleObject(
value = getOverviewSinglePublicResponseExample
)})
)})
@RequestMapping(method = RequestMethod.GET, value = {"/{id}"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DatasetPublicModel>> getOverviewSinglePublic(@PathVariable @ApiParam(value = "fetch the dataset with the given id", example = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") String id) throws Exception {
ResponseEntity<ResponseItem<DatasetPublicModel>> getOverviewSinglePublic(@PathVariable @Parameter(description = "fetch the dataset with the given id", example = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") String id) throws Exception {
// try {
DatasetPublicModel dataset = this.datasetManager.getOverviewSinglePublic(id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset));

View File

@ -1,18 +1,22 @@
package eu.eudat.publicapi.controllers;
import eu.eudat.controllers.BaseController;
import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.security.Principal;
import eu.eudat.publicapi.managers.DataManagementPlanPublicManager;
import eu.eudat.publicapi.models.listingmodels.DataManagementPlanPublicListingModel;
import eu.eudat.publicapi.models.overviewmodels.DataManagementPlanPublicModel;
import eu.eudat.publicapi.request.dmp.DataManagmentPlanPublicTableRequest;
import eu.eudat.types.ApiMessageCode;
import eu.eudat.types.Authorities;
import io.swagger.annotations.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -20,11 +24,9 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@Api(tags = "DMPs", description = "Provides DMP public API's.")
@Tag(name = "DMPs", description = "Provides DMP public API's.")
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/public/dmps"})
@ -48,8 +50,8 @@ public class PublicDmpsDocumentation extends BaseController {
" 4.7. groupId: uuid, group id in which dmp belongs\n" +
" 4.8. users: list of UserInfoPublicModel, user who collaborated on the dmp\n" +
" 4.9. researchers: list of ResearcherPublicModel, researchers involved in the dmp\n" +
"4.9. finalizedAt: date, finalization date\n" +
"4.10. publishedAt: date, publication date\n";
" 4.10. finalizedAt: date, finalization date\n" +
" 4.11. publishedAt: date, publication date\n";
private static final String getPagedResponseExample = "{\n" +
" \"statusCode\": 0,\n" +
" \"responseType\": 0,\n" +
@ -243,37 +245,35 @@ public class PublicDmpsDocumentation extends BaseController {
this.dataManagementPlanManager = dataManagementPlanManager;
}
@ApiOperation(value = "This method is used to get a listing of public dmps.", notes = getPagedNotes)
@ApiResponses(value = {@ApiResponse(
code = 200,
message = "The following example is generated using:\n" +
@Operation(summary = "This method is used to get a listing of public dmps.", description = getPagedNotes)
@io.swagger.v3.oas.annotations.responses.ApiResponses(value = {@ApiResponse(
responseCode = "200",
description = "The following example is generated using:\n" +
"a) body: *{\"criteria\": {},\"length\": 2,\"offset\": 0,\"orderings\": {\"fields\": []} }*\n" +
"b) fieldsGroup: listing",
examples = @Example({@ExampleProperty(
value = getPagedResponseExample,
mediaType = APPLICATION_JSON_VALUE
content = @Content(mediaType = APPLICATION_JSON_VALUE, examples = {@ExampleObject(
value = getPagedResponseExample
)})
)})
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanPublicListingModel>>> getPaged(@Valid @RequestBody @ApiParam(value = getPagedRequestBodyDescription) DataManagmentPlanPublicTableRequest dmpTableRequest,
@RequestParam @ApiParam(value = getPagedRequestParamDescription, example = "listing") String fieldsGroup) throws Exception {
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanPublicListingModel>>> getPaged(@Valid @RequestBody @Parameter(description = getPagedRequestBodyDescription) DataManagmentPlanPublicTableRequest dmpTableRequest,
@RequestParam @Parameter(description = getPagedRequestParamDescription, example = "listing") String fieldsGroup) throws Exception {
DataTableData<DataManagementPlanPublicListingModel> dataTable = this.dataManagementPlanManager.getPublicPaged(dmpTableRequest, fieldsGroup);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanPublicListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
}
@ApiOperation(value = "This method is used to get the overview of a public dmp.", notes = getOverviewSinglePublicNotes)
@ApiResponses(value = {@ApiResponse(
code = 200,
message = "The following example is generated using id: *e9a73d77-adfa-4546-974f-4a4a623b53a8*",
examples = @Example({@ExampleProperty(
value = getOverviewSinglePublicResponseExample,
mediaType = APPLICATION_JSON_VALUE
@Operation(summary = "This method is used to get the overview of a public dmp.", description = getOverviewSinglePublicNotes)
@io.swagger.v3.oas.annotations.responses.ApiResponses(value = {@ApiResponse(
responseCode = "200",
description = "The following example is generated using id: *e9a73d77-adfa-4546-974f-4a4a623b53a8*",
content = @Content(mediaType = APPLICATION_JSON_VALUE, examples = {@ExampleObject(
value = getOverviewSinglePublicResponseExample
)})
)})
@RequestMapping(method = RequestMethod.GET, value = {"/{id}"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataManagementPlanPublicModel>> getOverviewSinglePublic(@PathVariable @ApiParam(value = "fetch the dmp with the given id", example = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") String id) throws Exception {
ResponseEntity<ResponseItem<DataManagementPlanPublicModel>> getOverviewSinglePublic(@PathVariable @Parameter(description = "fetch the dmp with the given id", example = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") String id) throws Exception {
// try {
DataManagementPlanPublicModel dataManagementPlan = this.dataManagementPlanManager.getOverviewSinglePublic(id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));

View File

@ -12,4 +12,5 @@ spring:
optional:classpath:config/email.yml[.yml], optional:classpath:config/email-${spring.profiles.active}.yml[.yml], optional:file:../config/email-${spring.profiles.active}.yml[.yml],
optional:classpath:config/elasticsearch.yml[.yml], optional:classpath:config/elasticsearch-${spring.profiles.active}.yml[.yml], optional:file:../config/elasticsearch-${spring.profiles.active}.yml[.yml],
optional:classpath:config/file-path.yml[.yml], optional:classpath:config/file-path-${spring.profiles.active}.yml[.yml], optional:file:../config/file-path-${spring.profiles.active}.yml[.yml],
optional:classpath:config/external.yml[.yml], optional:classpath:config/external-${spring.profiles.active}.yml[.yml], optional:file:../config/external-${spring.profiles.active}.yml[.yml]
optional:classpath:config/external.yml[.yml], optional:classpath:config/external-${spring.profiles.active}.yml[.yml], optional:file:../config/external-${spring.profiles.active}.yml[.yml],
optional:classpath:config/swagger.yml[.yml], optional:classpath:config/swagger-${spring.profiles.active}.yml[.yml], optional:file:../config/swagger-${spring.profiles.active}.yml[.yml]

View File

@ -0,0 +1,3 @@
springdoc:
packagesToScan: eu.eudat.publicapi.controllers
pathsToScan: "/api/public/(dmps|datasets)/?.*"