Skip to content

Commit 4dca644

Browse files
Replacing springfox with springdoc (#56)
Signed-off-by: Franck LECUYER <[email protected]>
1 parent b0ad7dd commit 4dca644

File tree

5 files changed

+25
-54
lines changed

5 files changed

+25
-54
lines changed

geo-data-server/pom.xml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,6 @@
6060
<groupId>org.springframework.boot</groupId>
6161
<artifactId>spring-boot-starter-data-cassandra</artifactId>
6262
</dependency>
63-
<dependency>
64-
<groupId>io.springfox</groupId>
65-
<artifactId>springfox-swagger2</artifactId>
66-
</dependency>
67-
<dependency>
68-
<groupId>io.springfox</groupId>
69-
<artifactId>springfox-swagger-ui</artifactId>
70-
</dependency>
71-
7263
<dependency>
7364
<groupId>org.springframework.boot</groupId>
7465
<artifactId>spring-boot-starter-web</artifactId>
@@ -81,7 +72,10 @@
8172
<groupId>io.dropwizard.metrics</groupId>
8273
<artifactId>metrics-core</artifactId>
8374
</dependency>
84-
75+
<dependency>
76+
<groupId>org.springdoc</groupId>
77+
<artifactId>springdoc-openapi-ui</artifactId>
78+
</dependency>
8579
<dependency>
8680
<groupId>com.powsybl</groupId>
8781
<artifactId>powsybl-network-store-client</artifactId>

geo-data-server/src/main/java/org/gridsuite/geodata/server/GeoDataController.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
*/
77
package org.gridsuite.geodata.server;
88

9+
import io.swagger.v3.oas.annotations.Operation;
10+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
11+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
12+
import io.swagger.v3.oas.annotations.tags.Tag;
913
import org.gridsuite.geodata.server.dto.LineGeoData;
1014
import org.gridsuite.geodata.server.dto.SubstationGeoData;
1115
import com.powsybl.iidm.network.Country;
1216
import com.powsybl.iidm.network.Network;
1317
import com.powsybl.network.store.client.NetworkStoreService;
14-
import io.swagger.annotations.Api;
15-
import io.swagger.annotations.ApiOperation;
16-
import io.swagger.annotations.ApiResponse;
17-
import io.swagger.annotations.ApiResponses;
1818
import org.springframework.beans.factory.annotation.Autowired;
1919
import org.springframework.context.annotation.ComponentScan;
2020
import org.springframework.http.MediaType;
@@ -32,7 +32,7 @@
3232
*/
3333
@RestController
3434
@RequestMapping(value = GeoDataController.API_VERSION)
35-
@Api(value = "Geo data")
35+
@Tag(name = "Geo data")
3636
@ComponentScan(basePackageClasses = {GeoDataController.class, GeoDataService.class, NetworkStoreService.class})
3737
public class GeoDataController {
3838

@@ -49,8 +49,8 @@ private static Set<Country> toCountrySet(@RequestParam(required = false) List<St
4949
}
5050

5151
@GetMapping(value = "/substations", produces = MediaType.APPLICATION_JSON_VALUE)
52-
@ApiOperation(value = "Get substations geographical data", response = List.class)
53-
@ApiResponses(value = {@ApiResponse(code = 200, message = "Substations geographical data")})
52+
@Operation(summary = "Get substations geographical data")
53+
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Substations geographical data")})
5454
public ResponseEntity<List<SubstationGeoData>> getSubstations(@RequestParam UUID networkUuid,
5555
@RequestParam(required = false) List<String> countries) {
5656
Set<Country> countrySet = toCountrySet(countries);
@@ -60,8 +60,8 @@ public ResponseEntity<List<SubstationGeoData>> getSubstations(@RequestParam UUID
6060
}
6161

6262
@GetMapping(value = "/lines", produces = MediaType.APPLICATION_JSON_VALUE)
63-
@ApiOperation(value = "Get lines geographical data", response = List.class)
64-
@ApiResponses(value = {@ApiResponse(code = 200, message = "Lines geographical data")})
63+
@Operation(summary = "Get lines geographical data")
64+
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Lines geographical data")})
6565
public ResponseEntity<List<LineGeoData>> getLines(@RequestParam UUID networkUuid,
6666
@RequestParam(required = false) List<String> countries) {
6767
Set<Country> countrySet = toCountrySet(countries);
@@ -71,15 +71,15 @@ public ResponseEntity<List<LineGeoData>> getLines(@RequestParam UUID networkUuid
7171
}
7272

7373
@PostMapping(value = "/substations")
74-
@ApiOperation(value = "Save substations geographical data")
75-
@ApiResponses(value = {@ApiResponse(code = 200, message = "Substations geographical data have been correctly saved")})
74+
@Operation(summary = "Save substations geographical data")
75+
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Substations geographical data have been correctly saved")})
7676
public void saveSubstations(@RequestBody List<SubstationGeoData> substationGeoData) {
7777
geoDataService.saveSubstations(substationGeoData);
7878
}
7979

8080
@PostMapping(value = "/lines")
81-
@ApiOperation(value = "Save lines geographical data")
82-
@ApiResponses(value = {@ApiResponse(code = 200, message = "Lines geographical data have been correctly saved")})
81+
@Operation(summary = "Save lines geographical data")
82+
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Lines geographical data have been correctly saved")})
8383
public void saveLines(@RequestBody List<LineGeoData> linesGeoData) {
8484
geoDataService.saveLines(linesGeoData);
8585
}

geo-data-server/src/main/java/org/gridsuite/geodata/server/GeoDataSwaggerConfig.java

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,22 @@
66
*/
77
package org.gridsuite.geodata.server;
88

9-
import com.google.common.base.Predicate;
10-
import com.google.common.base.Predicates;
9+
import io.swagger.v3.oas.models.OpenAPI;
10+
import io.swagger.v3.oas.models.info.Info;
1111
import org.springframework.context.annotation.Bean;
1212
import org.springframework.context.annotation.Configuration;
13-
import springfox.documentation.builders.ApiInfoBuilder;
14-
import springfox.documentation.builders.PathSelectors;
15-
import springfox.documentation.builders.RequestHandlerSelectors;
16-
import springfox.documentation.service.ApiInfo;
17-
import springfox.documentation.spi.DocumentationType;
18-
import springfox.documentation.spring.web.plugins.Docket;
19-
import springfox.documentation.swagger2.annotations.EnableSwagger2;
2013

2114
/**
2215
* @author Chamseddine Benhamed <chamseddine.benhamed at rte-france.com>
2316
*/
2417
@Configuration
25-
@EnableSwagger2
2618
public class GeoDataSwaggerConfig {
2719
@Bean
28-
public Docket produceApi() {
29-
return new Docket(DocumentationType.SWAGGER_2)
30-
.apiInfo(apiInfo())
31-
.select()
32-
.apis(RequestHandlerSelectors.basePackage(GeoDataApplication.class.getPackage().getName()))
33-
.paths(paths())
34-
.build();
35-
}
36-
37-
// Describe your apis
38-
private ApiInfo apiInfo() {
39-
return new ApiInfoBuilder()
20+
public OpenAPI createOpenApi() {
21+
return new OpenAPI()
22+
.info(new Info()
4023
.title("Geo data API")
4124
.description("This is the documentation of PowSyBl Geo Data API")
42-
.version(GeoDataController.API_VERSION)
43-
.build();
44-
}
45-
46-
// Only select apis that matches the given Predicates.
47-
private Predicate<String> paths() {
48-
// Match all paths except /error
49-
return Predicates.and(PathSelectors.regex("/" + GeoDataController.API_VERSION + ".*"), Predicates.not(PathSelectors.regex("/error.*"))::apply);
25+
.version(GeoDataController.API_VERSION));
5026
}
5127
}

geo-data-server/src/main/resources/application.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
server:
22
port : 8087
3+
forward-headers-strategy: framework
34

45
network-store-server:
56
base-uri: http://localhost:8080

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<properties>
5757
<java.version>11</java.version>
5858

59-
<gridsuite-dependencies.version>9</gridsuite-dependencies.version>
59+
<gridsuite-dependencies.version>10</gridsuite-dependencies.version>
6060
<commons-lang3.version>3.9</commons-lang3.version>
6161

6262
<sonar.coverage.jacoco.xmlReportPaths>

0 commit comments

Comments
 (0)