Skip to content

Commit

Permalink
[Improve] [ISSUE apache#5628] Migrate Admin swagger from springfox to…
Browse files Browse the repository at this point in the history
… springdoc (apache#5630)

* [Improve] Migrate Admin swagger from springfox to springdoc

* [Fix] try fix ci

* [Fix] fix test case

* [Fix] fix test case

* [Fix] fix test case
  • Loading branch information
VampireAchao authored Aug 24, 2024
1 parent 3c326cd commit 4824cd1
Show file tree
Hide file tree
Showing 35 changed files with 327 additions and 455 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<skipTests>false</skipTests>
<!-- maven plugin version start -->
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.7</jacoco-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.12</jacoco-maven-plugin.version>
<nexus-staging-maven-plugin.version>1.6.3</nexus-staging-maven-plugin.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class PullSwaggerDocServiceImpl implements PullSwaggerDocService {

private static final HttpUtils HTTP_UTILS = new HttpUtils();

private static final String SWAGGER_V2_PATH = "/v2/api-docs";
private static final String SWAGGER_V3_PATH = "/v3/api-docs";

private static final long PULL_MIN_INTERVAL_TIME = 30 * 1000;

Expand Down Expand Up @@ -181,7 +181,7 @@ private String getSwaggerRequestUrl(final UpstreamInstance instance) {
uriComponentsBuilder.host(instance.getIp());
uriComponentsBuilder.port(instance.getPort());
uriComponentsBuilder.path(Optional.ofNullable(instance.getContextPath()).orElse(""));
uriComponentsBuilder.path(SWAGGER_V2_PATH);
uriComponentsBuilder.path(SWAGGER_V3_PATH);
return uriComponentsBuilder.build().toUriString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,8 @@ protected List<DocParameter> buildResponseParameterList(final JsonObject docInfo
}

protected List<DocParameter> buildDocParameters(final String ref, final JsonObject docRoot, final boolean doSubRef) {
JsonObject responseObject = docRoot.getAsJsonObject("definitions").getAsJsonObject(ref);
String className = responseObject.get("title").getAsString();
JsonObject extProperties = docRoot.getAsJsonObject(className);
JsonObject responseObject = docRoot.getAsJsonObject("components").getAsJsonObject("schemas").getAsJsonObject(ref);
JsonObject extProperties = responseObject.getAsJsonObject("properties");
JsonArray requiredProperties = responseObject.getAsJsonArray("required");
List<String> requiredFieldList = this.jsonArrayToStringList(requiredProperties);
JsonObject properties = responseObject.getAsJsonObject("properties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testAddDocInfo() {
instance.setContextPath("/testClusterName");
AtomicBoolean atomicBoolean = new AtomicBoolean(false);
docManager.addDocInfo(instance, SwaggerDocParserTest.DOC_INFO_JSON, "", docInfo -> {
Assertions.assertEquals(docInfo.getTitle(), "shenyu-examples-http-swagger2 API");
Assertions.assertEquals(docInfo.getTitle(), "shenyu-examples-http-swagger3 API");
Assertions.assertEquals(docInfo.getClusterName(), "testClusterName");
atomicBoolean.set(true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,165 +32,86 @@
public class SwaggerDocParserTest {

public static final String DOC_INFO_JSON = "{\n"
+ " \"swagger\":\"2.0\",\n"
+ " \"info\":{\n"
+ " \"description\":\"shenyu-examples-http-swagger2 API\",\n"
+ " \"version\":\"2.3.0\",\n"
+ " \"title\":\"shenyu-examples-http-swagger2 API\",\n"
+ " \"contact\":{\n"
+ " \"name\":\"ShenYu\",\n"
+ " \"url\":\"https://github.com/apache/shenyu\",\n"
+ " \"email\":\"[email protected]\"\n"
+ " }\n"
+ " },\n"
+ " \"host\":\"127.0.0.1:8190\",\n"
+ " \"basePath\":\"/\",\n"
+ " \"tags\":[\n"
+ " {\n"
+ " \"name\":\"Order API\",\n"
+ " \"description\":\"Order Controller\"\n"
+ " },\n"
+ " {\n"
+ " \"name\":\"http-test-controller\",\n"
+ " \"description\":\"Http Test Controller\"\n"
+ " }\n"
+ " ],\n"
+ " \"paths\":{\n"
+ " \"/order/path/{id}/{name}\":{\n"
+ " \"get\":{\n"
+ " \"tags\":[\n"
+ " \"Order API\"\n"
+ " ],\n"
+ " \"summary\":\"getPathVariable\",\n"
+ " \"description\":\"get path variable.\",\n"
+ " \"operationId\":\"getPathVariableUsingGET_1\",\n"
+ " \"produces\":[\n"
+ " \"*/*\"\n"
+ " ],\n"
+ " \"parameters\":[\n"
+ " {\n"
+ " \"name\":\"X-Access-Token\",\n"
+ " \"in\":\"header\",\n"
+ " \"description\":\"user auth\",\n"
+ " \"required\":false,\n"
+ " \"type\":\"string\"\n"
+ " },\n"
+ " {\n"
+ " \"name\":\"id\",\n"
+ " \"in\":\"path\",\n"
+ " \"description\":\"id\",\n"
+ " \"required\":true,\n"
+ " \"type\":\"string\"\n"
+ " },\n"
+ " {\n"
+ " \"name\":\"name\",\n"
+ " \"in\":\"path\",\n"
+ " \"description\":\"name\",\n"
+ " \"required\":true,\n"
+ " \"type\":\"string\"\n"
+ " }\n"
+ " ],\n"
+ " \"responses\":{\n"
+ " \"200\":{\n"
+ " \"description\":\"OK\",\n"
+ " \"schema\":{\n"
+ " \"$ref\":\"#/definitions/OrderDTO\"\n"
+ " }\n"
+ " },\n"
+ " \"deprecated\":false\n"
+ " }\n"
+ " }\n"
+ " },\n"
+ " \"/test/payment\":{\n"
+ " \"post\":{\n"
+ " \"tags\":[\n"
+ " \"http-test-controller\"\n"
+ " ],\n"
+ " \"summary\":\"payment\",\n"
+ " \"description\":\"The user pays the order.\",\n"
+ " \"operationId\":\"postUsingPOST\",\n"
+ " \"consumes\":[\n"
+ " \"application/json\"\n"
+ " ],\n"
+ " \"produces\":[\n"
+ " \"*/*\"\n"
+ " ],\n"
+ " \"parameters\":[\n"
+ " {\n"
+ " \"name\":\"X-Access-Token\",\n"
+ " \"in\":\"header\",\n"
+ " \"description\":\"user auth\",\n"
+ " \"required\":false,\n"
+ " \"type\":\"string\"\n"
+ " },\n"
+ " {\n"
+ " \"in\":\"body\",\n"
+ " \"name\":\"userDTO\",\n"
+ " \"description\":\"userDTO\",\n"
+ " \"required\":true,\n"
+ " \"schema\":{\n"
+ " \"$ref\":\"#/definitions/UserDTO\"\n"
+ " }\n"
+ " }\n"
+ " ],\n"
+ " \"responses\":{\n"
+ " \"200\":{\n"
+ " \"description\":\"OK\",\n"
+ " \"schema\":{\n"
+ " \"$ref\":\"#/definitions/UserDTO\"\n"
+ " }\n"
+ " }\n"
+ " },\n"
+ " \"deprecated\":false\n"
+ " }\n"
+ " }\n"
+ " },\n"
+ " \"definitions\":{\n"
+ " \"Mono«string»\":{\n"
+ " \"type\":\"object\",\n"
+ " \"title\":\"Mono«string»\"\n"
+ " },\n"
+ " \"OrderDTO\":{\n"
+ " \"type\":\"object\",\n"
+ " \"required\":[\n"
+ " \"id\",\n"
+ " \"name\"\n"
+ " ],\n"
+ " \"properties\":{\n"
+ " \"id\":{\n"
+ " \"type\":\"string\",\n"
+ " \"example\":100000,\n"
+ " \"description\":\"id\"\n"
+ " },\n"
+ " \"name\":{\n"
+ " \"type\":\"string\",\n"
+ " \"example\":\"jack\",\n"
+ " \"description\":\"name\"\n"
+ " }\n"
+ " },\n"
+ " \"title\":\"OrderDTO\"\n"
+ " },\n"
+ " \"UserDTO\":{\n"
+ " \"type\":\"object\",\n"
+ " \"required\":[\n"
+ " \"userId\"\n"
+ " ],\n"
+ " \"properties\":{\n"
+ " \"userId\":{\n"
+ " \"type\":\"string\",\n"
+ " \"example\":100000,\n"
+ " \"description\":\"user id\"\n"
+ " },\n"
+ " \"userName\":{\n"
+ " \"type\":\"string\",\n"
+ " \"example\":\"shenyu\",\n"
+ " \"description\":\"user name\"\n"
+ " }\n"
+ " },\n"
+ " \"title\":\"UserDTO\"\n"
+ " }\n"
+ " }\n"
+ "}";
+ " \"openapi\": \"3.0.1\",\n"
+ " \"info\": {\n"
+ " \"title\": \"shenyu-examples-http-swagger3 API\",\n"
+ " \"description\": \"shenyu-examples-http-swagger3 API\",\n"
+ " \"version\": \"3.0.1\",\n"
+ " \"contact\": {\n"
+ " \"name\": \"ShenYu\",\n"
+ " \"url\": \"https://github.com/apache/shenyu\",\n"
+ " \"email\": \"[email protected]\"\n"
+ " }\n"
+ " },\n"
+ " \"servers\": [\n"
+ " {\n"
+ " \"url\": \"http://127.0.0.1:8190\",\n"
+ " \"description\": \"Local server\"\n"
+ " }\n"
+ " ],\n"
+ " \"tags\": [\n"
+ " {\n"
+ " \"name\": \"Order API\",\n"
+ " \"description\": \"Order Controller\"\n"
+ " }\n"
+ " ],\n"
+ " \"paths\": {\n"
+ " \"/order/path/{id}/{name}\": {\n"
+ " \"get\": {\n"
+ " \"tags\": [\"Order API\"],\n"
+ " \"summary\": \"Get path variable\",\n"
+ " \"parameters\": [\n"
+ " {\n"
+ " \"name\": \"id\",\n"
+ " \"in\": \"path\",\n"
+ " \"required\": true,\n"
+ " \"schema\": {\n"
+ " \"type\": \"string\"\n"
+ " }\n"
+ " },\n"
+ " {\n"
+ " \"name\": \"name\",\n"
+ " \"in\": \"path\",\n"
+ " \"required\": true,\n"
+ " \"schema\": {\n"
+ " \"type\": \"string\"\n"
+ " }\n"
+ " }\n"
+ " ],\n"
+ " \"responses\": {\n"
+ " \"200\": {\n"
+ " \"description\": \"Successful response\",\n"
+ " \"content\": {\n"
+ " \"application/json\": {\n"
+ " \"schema\": {\n"
+ " \"$ref\": \"#/components/schemas/OrderDTO\"\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " },\n"
+ " \"components\": {\n"
+ " \"schemas\": {\n"
+ " \"OrderDTO\": {\n"
+ " \"type\": \"object\",\n"
+ " \"required\": [\"id\", \"name\"],\n"
+ " \"properties\": {\n"
+ " \"id\": {\n"
+ " \"type\": \"string\",\n"
+ " \"example\": \"100000\"\n"
+ " },\n"
+ " \"name\": {\n"
+ " \"type\": \"string\",\n"
+ " \"example\": \"jack\"\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}\n";

@InjectMocks
private SwaggerDocParser swaggerDocParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testValidateWhenMeetsConstraintThenValidationFailed() throws Excepti
.validate(
"methodTwo",
new Class<?>[]{MockValidationParameter.class},
new Object[]{new MockValidationParameter("NotBeNull")}));
new Object[]{new MockValidationParameter()}));
}

@Test
Expand Down
14 changes: 4 additions & 10 deletions shenyu-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
<versions-maven-plugin.version>2.5</versions-maven-plugin.version>
<docker-maven-plugin.version>0.40.1</docker-maven-plugin.version>
<maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version>
<swagger.version>2.9.2</swagger.version>
<swagger.version>2.6.0</swagger.version>
</properties>

<modules>
<module>shenyu-examples-common</module>
<module>shenyu-examples-http</module>
<module>shenyu-examples-http-swagger2</module>
<module>shenyu-examples-http-swagger3</module>
<module>shenyu-examples-https</module>
<module>shenyu-examples-dubbo</module>
<module>shenyu-examples-springcloud</module>
Expand All @@ -63,14 +63,8 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
</dependencies>
Expand Down
Loading

0 comments on commit 4824cd1

Please sign in to comment.