Skip to content

Commit 197e4ce

Browse files
committed
Migrate from springfox to springdoc-openapi
Resolves #12.
1 parent e65f488 commit 197e4ce

File tree

7 files changed

+80
-102
lines changed

7 files changed

+80
-102
lines changed

pom.xml

+14-36
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
<java-support.version>8.2.1</java-support.version>
3030
<spring-extensions.version>6.1.3</spring-extensions.version>
3131

32-
<springfox-version>2.9.2</springfox-version>
3332
<spring.boot.version>2.4.13</spring.boot.version>
33+
<springdoc.version>1.6.3</springdoc.version>
3434
</properties>
3535

3636
<dependencies>
@@ -79,28 +79,6 @@
7979
<artifactId>spring-boot-autoconfigure</artifactId>
8080
</dependency>
8181

82-
<!--SpringFox dependencies -->
83-
<dependency>
84-
<groupId>io.springfox</groupId>
85-
<artifactId>springfox-core</artifactId>
86-
<version>${springfox-version}</version>
87-
</dependency>
88-
<dependency>
89-
<groupId>io.springfox</groupId>
90-
<artifactId>springfox-swagger2</artifactId>
91-
<version>${springfox-version}</version>
92-
</dependency>
93-
<dependency>
94-
<groupId>io.springfox</groupId>
95-
<artifactId>springfox-spi</artifactId>
96-
<version>${springfox-version}</version>
97-
</dependency>
98-
<dependency>
99-
<groupId>io.springfox</groupId>
100-
<artifactId>springfox-spring-web</artifactId>
101-
<version>${springfox-version}</version>
102-
</dependency>
103-
10482
<dependency>
10583
<groupId>com.fasterxml.jackson.core</groupId>
10684
<artifactId>jackson-annotations</artifactId>
@@ -111,10 +89,17 @@
11189
</dependency>
11290

11391
<dependency>
114-
<groupId>io.swagger</groupId>
92+
<groupId>io.swagger.core.v3</groupId>
11593
<artifactId>swagger-annotations</artifactId>
116-
<version>1.6.3</version>
94+
<version>2.1.12</version>
11795
</dependency>
96+
97+
<dependency>
98+
<groupId>org.springdoc</groupId>
99+
<artifactId>springdoc-openapi-ui</artifactId>
100+
<version>${springdoc.version}</version>
101+
</dependency>
102+
118103
<dependency>
119104
<groupId>jakarta.xml.bind</groupId>
120105
<artifactId>jakarta.xml.bind-api</artifactId>
@@ -157,13 +142,6 @@
157142
<scope>runtime</scope>
158143
</dependency>
159144

160-
<dependency>
161-
<groupId>io.springfox</groupId>
162-
<artifactId>springfox-swagger-ui</artifactId>
163-
<version>${springfox-version}</version>
164-
<scope>runtime</scope>
165-
</dependency>
166-
167145
<dependency>
168146
<groupId>ch.qos.logback</groupId>
169147
<artifactId>logback-classic</artifactId>
@@ -259,9 +237,9 @@
259237

260238
<!-- Generate code for the API using swagger-codegen. -->
261239
<plugin>
262-
<groupId>io.swagger</groupId>
240+
<groupId>io.swagger.codegen.v3</groupId>
263241
<artifactId>swagger-codegen-maven-plugin</artifactId>
264-
<version>2.4.24</version>
242+
<version>3.0.30</version>
265243
<executions>
266244
<execution>
267245
<goals>
@@ -324,9 +302,9 @@
324302
<pluginExecutions>
325303
<pluginExecution>
326304
<pluginExecutionFilter>
327-
<groupId>io.swagger</groupId>
305+
<groupId>io.swagger.codegen.v3</groupId>
328306
<artifactId>swagger-codegen-maven-plugin</artifactId>
329-
<versionRange>[2.3.1,)</versionRange>
307+
<versionRange>[3.0.0,)</versionRange>
330308
<goals>
331309
<goal>generate</goal>
332310
</goals>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package uk.org.iay.md.validator;
15+
16+
import javax.annotation.Nonnull;
17+
18+
import org.springframework.boot.CommandLineRunner;
19+
import org.springframework.boot.ExitCodeGenerator;
20+
import org.springframework.boot.SpringApplication;
21+
import org.springframework.boot.autoconfigure.SpringBootApplication;
22+
23+
/**
24+
* Main application class.
25+
*/
26+
@SpringBootApplication
27+
public class ValidatorApplication implements CommandLineRunner {
28+
29+
@Override
30+
public void run(final String... arg0) throws Exception {
31+
if (arg0.length > 0 && arg0[0].equals("exitcode")) {
32+
throw new ExitException();
33+
}
34+
}
35+
36+
/**
37+
* Command-line entry point.
38+
*
39+
* @param args command-line arguments
40+
* @throws Exception if something goes wrong
41+
*/
42+
public static void main(@Nonnull final String[] args) throws Exception {
43+
new SpringApplication(ValidatorApplication.class).run(args);
44+
}
45+
46+
class ExitException extends RuntimeException implements ExitCodeGenerator {
47+
private static final long serialVersionUID = 1L;
48+
49+
@Override
50+
public int getExitCode() {
51+
return 10;
52+
}
53+
54+
}
55+
56+
}

src/main/java/uk/org/iay/md/validator/api/ApiException.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**
2424
* Exception class for use within the API.
2525
*/
26-
public class ApiException extends Exception {
26+
public class ApiException extends RuntimeException {
2727

2828
/** Serial version UID. */
2929
private static final long serialVersionUID = -5046975083822313941L;

src/main/java/uk/org/iay/md/validator/api/ValidatorsApi.java

-52
This file was deleted.

src/main/java/uk/org/iay/md/validator/api/ValidatorsApiController.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.w3c.dom.Document;
3636
import org.w3c.dom.Element;
3737

38-
import io.swagger.annotations.ApiParam;
3938
import net.shibboleth.metadata.ErrorStatus;
4039
import net.shibboleth.metadata.InfoStatus;
4140
import net.shibboleth.metadata.Item;
@@ -118,11 +117,8 @@ private Status convertStatus(final StatusMetadata stat) {
118117

119118
@Override
120119
public ResponseEntity<List<Status>> validate(
121-
@ApiParam(value = "An identifier for the validation to be performed.", required = true)
122-
@PathVariable("validator_id")
123-
final String validatorId,
124-
@ApiParam(value = "The metadata to be validated.", required = true) @Valid @RequestBody
125-
final String metadata) throws ApiException {
120+
@PathVariable("validator_id") final String validatorId,
121+
@Valid @RequestBody final String metadata) {
126122

127123
// Fetch the required validator.
128124
final ValidatorCollection.Entry entry = validatorCollection.getEntry(validatorId);

src/main/resources/application.properties

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
springfox.documentation.swagger.v2.path=/api-docs
2-
31
server.port=8080
42
spring.jackson.date-format=uk.org.iay.md.validator.RFC3339DateFormat
53
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false

swagger/.swagger-codegen-ignore

+7-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ README.md
1717
**/ValidatorsApiController.java
1818

1919
#
20-
# Turns out we need to make changes to the API classes as well, to
21-
# allow for exceptions.
20+
# In turn, that means we don't need to generate the exception classes.
2221
#
23-
**/ValidatorsApi.java
22+
**/*Exception.java
2423

2524
#
26-
# In turn, that means we don't need to generate the exception classes.
25+
# Strip out the classes that bridge to springfox, now that we use
26+
# springdoc-openapi-ui.
2727
#
28-
**/*Exception.java
28+
**/Swagger2SpringBoot.java
29+
**/SwaggerDocumentationConfig.java
30+
**/SwaggerUIConfiguration.java

0 commit comments

Comments
 (0)