From 1c1ea01c2a4d5602d0e665c7e523342f9abdb13c Mon Sep 17 00:00:00 2001 From: skdong Date: Thu, 30 Apr 2020 18:04:38 +0800 Subject: [PATCH 1/6] add auto swagger not use mvn plugin --- .../macmanager/swagger/SwaggerConfig.java | 48 +++++ .../macmanager/swagger/SwaggerJsonTest.java | 68 +++++++ .../swagger/SwaggerConfig.java | 48 +++++ .../swagger/SwaggerJsonTest.java | 65 +++++++ .../alcor/route/swagger/SwaggerConfig.java | 48 +++++ .../alcor/route/swagger/SwaggerJsonTest.java | 65 +++++++ services/subnet_manager/pom.xml | 171 +++++++++++++++++- .../alcor/subnet/swagger/SwaggerConfig.java | 48 +++++ .../alcor/subnet/swagger/SwaggerJsonTest.java | 66 +++++++ services/vpc_manager/pom.xml | 28 ++- .../src/main/resources/application.properties | 2 +- .../vpcmanager/swagger/SwaggerConfig.java | 52 ++++++ .../vpcmanager/swagger/SwaggerJsonTest.java | 79 ++++++++ 13 files changed, 772 insertions(+), 16 deletions(-) create mode 100644 services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/swagger/SwaggerConfig.java create mode 100644 services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/swagger/SwaggerJsonTest.java create mode 100644 services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/swagger/SwaggerConfig.java create mode 100644 services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/swagger/SwaggerJsonTest.java create mode 100644 services/route_manager/src/test/java/com/futurewei/alcor/route/swagger/SwaggerConfig.java create mode 100644 services/route_manager/src/test/java/com/futurewei/alcor/route/swagger/SwaggerJsonTest.java create mode 100644 services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/swagger/SwaggerConfig.java create mode 100644 services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/swagger/SwaggerJsonTest.java create mode 100644 services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/swagger/SwaggerConfig.java create mode 100644 services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/swagger/SwaggerJsonTest.java diff --git a/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/swagger/SwaggerConfig.java b/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/swagger/SwaggerConfig.java new file mode 100644 index 000000000..668d4d14e --- /dev/null +++ b/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/swagger/SwaggerConfig.java @@ -0,0 +1,48 @@ +/* +Copyright 2019 The Alcor Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.futurewei.alcor.macmanager.swagger; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class SwaggerConfig{ + @Bean + public Docket api(){ + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build(); +// .apiInfo(apiInfo()); + } + + private ApiInfo apiInfo(){ + return new ApiInfo("MAC Manager", "MAC pool management", + "version", "termsOfServiceUrl", + "contact", "license", + "licenseUrl"); + } +} \ No newline at end of file diff --git a/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/swagger/SwaggerJsonTest.java b/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/swagger/SwaggerJsonTest.java new file mode 100644 index 000000000..ec906bf0e --- /dev/null +++ b/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/swagger/SwaggerJsonTest.java @@ -0,0 +1,68 @@ +/* +Copyright 2019 The Alcor Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.futurewei.alcor.macmanager.swagger; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; + +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; + +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; + +import org.springframework.http.MediaType; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.junit4.SpringRunner; +import java.io.BufferedWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +//import org.springframework.test.context.web.WebAppConfiguration; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; + +//@WebAppConfiguration +@RunWith(SpringRunner.class) +@SpringBootTest +@AutoConfigureMockMvc +public class SwaggerJsonTest{ + + @Autowired + private MockMvc mockMvc; + + @Test + public void createSpringfoxSwaggerJson() throws Exception{ + //String outputDir = System.getProperty("io.springfox.staticdocs.outputDir"); + String outputDir = System.getProperty("io.springfox.staticdocs.outputDir"); + MvcResult mvcResult = this.mockMvc.perform(get("/v2/api-docs") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn(); + + MockHttpServletResponse response = mvcResult.getResponse(); + String swaggerJson = response.getContentAsString(); + Files.createDirectories(Paths.get(outputDir)); + try(BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputDir, "swagger.json"), StandardCharsets.UTF_8)){ + writer.write(swaggerJson); + } + } + +} \ No newline at end of file diff --git a/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/swagger/SwaggerConfig.java b/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/swagger/SwaggerConfig.java new file mode 100644 index 000000000..b9c5b0367 --- /dev/null +++ b/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/swagger/SwaggerConfig.java @@ -0,0 +1,48 @@ +/* +Copyright 2019 The Alcor Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.futurewei.alcor.privatemanager.swagger; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class SwaggerConfig{ + @Bean + public Docket api(){ + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build(); + // .apiInfo(apiInfo()); + } + + private ApiInfo apiInfo(){ + return new ApiInfo("Subnet Manager", "To manager subnet address", + "version", "termsOfServiceUrl", + "contact", "license", + "licenseUrl"); + } +} \ No newline at end of file diff --git a/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/swagger/SwaggerJsonTest.java b/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/swagger/SwaggerJsonTest.java new file mode 100644 index 000000000..15b11a65c --- /dev/null +++ b/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/swagger/SwaggerJsonTest.java @@ -0,0 +1,65 @@ +/* +Copyright 2019 The Alcor Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.futurewei.alcor.privateipmanager.swagger; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; + +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; + +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; + +import org.springframework.http.MediaType; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.junit4.SpringRunner; +import java.io.BufferedWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; + +@RunWith(SpringRunner.class) +@SpringBootTest +@AutoConfigureMockMvc +public class SwaggerJsonTest{ + + @Autowired + private MockMvc mockMvc; + + @Test + public void createSpringfoxSwaggerJson() throws Exception{ + String outputDir = System.getProperty("io.springfox.staticdocs.outputDir"); + MvcResult mvcResult = this.mockMvc.perform(get("/v2/api-docs") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn(); + + MockHttpServletResponse response = mvcResult.getResponse(); + String swaggerJson = response.getContentAsString(); + Files.createDirectories(Paths.get(outputDir)); + try(BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputDir, "swagger.json"), StandardCharsets.UTF_8)){ + writer.write(swaggerJson); + } + } + +} \ No newline at end of file diff --git a/services/route_manager/src/test/java/com/futurewei/alcor/route/swagger/SwaggerConfig.java b/services/route_manager/src/test/java/com/futurewei/alcor/route/swagger/SwaggerConfig.java new file mode 100644 index 000000000..6cd486b99 --- /dev/null +++ b/services/route_manager/src/test/java/com/futurewei/alcor/route/swagger/SwaggerConfig.java @@ -0,0 +1,48 @@ +/* +Copyright 2019 The Alcor Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.futurewei.alcor.route.swagger; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class SwaggerConfig{ + @Bean + public Docket api(){ + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build(); + //.apiInfo(apiInfo()); + } + + private ApiInfo apiInfo(){ + return new ApiInfo("Subnet Manager", "To manager subnet address", + "version", "termsOfServiceUrl", + "contact", "license", + "licenseUrl"); + } +} \ No newline at end of file diff --git a/services/route_manager/src/test/java/com/futurewei/alcor/route/swagger/SwaggerJsonTest.java b/services/route_manager/src/test/java/com/futurewei/alcor/route/swagger/SwaggerJsonTest.java new file mode 100644 index 000000000..685e3780c --- /dev/null +++ b/services/route_manager/src/test/java/com/futurewei/alcor/route/swagger/SwaggerJsonTest.java @@ -0,0 +1,65 @@ +/* +Copyright 2019 The Alcor Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.futurewei.alcor.route.swagger; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; + +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; + +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; + +import org.springframework.http.MediaType; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.junit4.SpringRunner; +import java.io.BufferedWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; + +@RunWith(SpringRunner.class) +@SpringBootTest +@AutoConfigureMockMvc +public class SwaggerJsonTest{ + + @Autowired + private MockMvc mockMvc; + + @Test + public void createSpringfoxSwaggerJson() throws Exception{ + String outputDir = System.getProperty("io.springfox.staticdocs.outputDir"); + MvcResult mvcResult = this.mockMvc.perform(get("/v2/api-docs") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn(); + + MockHttpServletResponse response = mvcResult.getResponse(); + String swaggerJson = response.getContentAsString(); + Files.createDirectories(Paths.get(outputDir)); + try(BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputDir, "swagger.json"), StandardCharsets.UTF_8)){ + writer.write(swaggerJson); + } + } + +} \ No newline at end of file diff --git a/services/subnet_manager/pom.xml b/services/subnet_manager/pom.xml index f40e856f2..0484eb199 100644 --- a/services/subnet_manager/pom.xml +++ b/services/subnet_manager/pom.xml @@ -20,6 +20,15 @@ 1.7 1.5.6 ${project.basedir}/target/generated-snippets/ + + ${project.build.directory}/swagger + ${project.build.directory}/asciidoc/snippets + 1.2.0 + ${project.build.directory}/asciidoc/generated + ${project.basedir}/../../docs/asciidoc + ${project.build.directory}/asciidoc/html + ${project.build.directory}/asciidoc/pdf + ${swagger.output.dir}/swagger.json @@ -60,18 +69,22 @@ org.springframework.boot spring-boot-starter-test test - - - org.junit.vintage - junit-vintage-engine - - commons-net commons-net 3.6 + + io.springfox + springfox-swagger2 + 2.6.1 + + + io.springfox + springfox-swagger-ui + 2.2.2 + com.futurewei.alcor.common @@ -98,9 +111,9 @@ org.apache.maven.plugins maven-surefire-plugin - + org.springframework.boot @@ -167,6 +180,148 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + + ${swagger.output.dir} + + + + + + + io.github.swagger2markup + swagger2markup-maven-plugin + ${swagger2markup.version} + + + io.github.swagger2markup + swagger2markup-import-files-ext + ${swagger2markup.version} + + + io.github.swagger2markup + swagger2markup-spring-restdocs-ext + ${swagger2markup.version} + + + + ${swagger.input} + ${generated.asciidoc.directory} + + ASCIIDOC + TAGS + true + ${project.basedir}/src/docs/asciidoc/extensions/overview + ${project.basedir}/src/docs/asciidoc/extensions/definitions + ${project.basedir}/src/docs/asciidoc/extensions/paths + ${project.basedir}src/docs/asciidoc/extensions/security/ + + ${swagger.snippetOutput.dir} + true + + + + + test + + convertSwagger2markup + + + + + + + + org.asciidoctor + asciidoctor-maven-plugin + 1.5.6 + + + + org.asciidoctor + asciidoctorj-pdf + 1.5.0-alpha.16 + + + org.jruby + jruby-complete + 1.7.21 + + + + + ${asciidoctor.input.directory} + index.adoc + + book + left + 3 + + + + + ${generated.asciidoc.directory} + + + + + + output-html + test + + process-asciidoc + + + html5 + ${asciidoctor.html.output.directory} + + + + + output-pdf + test + + process-asciidoc + + + pdf + ${asciidoctor.pdf.output.directory} + + + + + + + + maven-resources-plugin + 3.1.0 + + + copy-resources + + test + + copy-resources + + + ${project.build.outputDirectory}/static/docs + + + ${asciidoctor.html.output.directory} + + + ${asciidoctor.pdf.output.directory} + + + + + + diff --git a/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/swagger/SwaggerConfig.java b/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/swagger/SwaggerConfig.java new file mode 100644 index 000000000..b1310e842 --- /dev/null +++ b/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/swagger/SwaggerConfig.java @@ -0,0 +1,48 @@ +/* +Copyright 2019 The Alcor Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.futurewei.alcor.subnet.swagger; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class SwaggerConfig{ + @Bean + public Docket api(){ + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build(); + //.apiInfo(apiInfo()); + } + + private ApiInfo apiInfo(){ + return new ApiInfo("Subnet Manager", "To manager subnet address", + "version", "termsOfServiceUrl", + "contact", "license", + "licenseUrl"); + } +} \ No newline at end of file diff --git a/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/swagger/SwaggerJsonTest.java b/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/swagger/SwaggerJsonTest.java new file mode 100644 index 000000000..291010310 --- /dev/null +++ b/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/swagger/SwaggerJsonTest.java @@ -0,0 +1,66 @@ +/* +Copyright 2019 The Alcor Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.futurewei.alcor.subnet.swagger; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; + +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; + +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; + +import org.springframework.http.MediaType; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.junit4.SpringRunner; +import java.io.BufferedWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; + +@RunWith(SpringRunner.class) +@SpringBootTest +@AutoConfigureMockMvc +public class SwaggerJsonTest{ + + @Autowired + private MockMvc mockMvc; + + @Test + public void createSpringfoxSwaggerJson() throws Exception{ + //String outputDir = System.getProperty("io.springfox.staticdocs.outputDir"); + String outputDir = System.getProperty("io.springfox.staticdocs.outputDir"); + MvcResult mvcResult = this.mockMvc.perform(get("/v2/api-docs") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn(); + + MockHttpServletResponse response = mvcResult.getResponse(); + String swaggerJson = response.getContentAsString(); + Files.createDirectories(Paths.get(outputDir)); + try(BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputDir, "swagger.json"), StandardCharsets.UTF_8)){ + writer.write(swaggerJson); + } + } + +} \ No newline at end of file diff --git a/services/vpc_manager/pom.xml b/services/vpc_manager/pom.xml index 204d33b5a..87139e100 100644 --- a/services/vpc_manager/pom.xml +++ b/services/vpc_manager/pom.xml @@ -14,7 +14,9 @@ 1.7 1.7 1.5.6 + 1.2.0 ${project.basedir}/target/generated-snippets/ + ${project.build.directory}/swagger @@ -61,12 +63,18 @@ org.springframework.boot spring-boot-starter-test test - - - org.junit.vintage - junit-vintage-engine - - + + + + io.springfox + springfox-swagger2 + 2.6.1 + + + + io.github.swagger2markup + swagger2markup-spring-restdocs-ext + ${swagger2markup.version} @@ -92,11 +100,17 @@ + + org.apache.maven.plugins + maven-surefire-plugin + org.apache.maven.plugins maven-surefire-plugin - true + + ${swagger.output.dir} + diff --git a/services/vpc_manager/src/main/resources/application.properties b/services/vpc_manager/src/main/resources/application.properties index d72d7f9e9..51076e617 100644 --- a/services/vpc_manager/src/main/resources/application.properties +++ b/services/vpc_manager/src/main/resources/application.properties @@ -13,7 +13,7 @@ #logging.file.path=. #logging.type=file #Ignite configuration -ignite.host=192.168.137.1 +ignite.host=localhost ignite.port=10800 #ignite.key-store-path=F:\\work\\alcor\\git\\chenpp\\alcor\\src\\resources\\keystore.jks #ignite.key-store-password=123456 diff --git a/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/swagger/SwaggerConfig.java b/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/swagger/SwaggerConfig.java new file mode 100644 index 000000000..717f41156 --- /dev/null +++ b/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/swagger/SwaggerConfig.java @@ -0,0 +1,52 @@ +/* +Copyright 2019 The Alcor Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.futurewei.alcor.vpcmanager.swagger; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class SwaggerConfig{ + @Bean + public Docket api(){ + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.regex("(?!/error).+")):web + .paths(PathSelectors.regex("(?!/actuator).+")) + .build(); + } + + private ApiInfo apiInfo(){ + return new ApiInfoBuilder() + .title("VPC Manager") + .description("VPC Manager") + .license("Apache 2.0") + .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") + .build(); + } +} \ No newline at end of file diff --git a/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/swagger/SwaggerJsonTest.java b/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/swagger/SwaggerJsonTest.java new file mode 100644 index 000000000..9f1f8ad23 --- /dev/null +++ b/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/swagger/SwaggerJsonTest.java @@ -0,0 +1,79 @@ +/* +Copyright 2019 The Alcor Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.futurewei.alcor.vpcmanager.swagger; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; + +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; + +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; + +import org.springframework.http.MediaType; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.junit4.SpringRunner; +import java.io.BufferedWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; + +import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.Swagger2MarkupProperties; +import io.github.swagger2markup.Swagger2MarkupConfig; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; + +@RunWith(SpringRunner.class) +@SpringBootTest +@AutoConfigureMockMvc +public class SwaggerJsonTest{ + + @Autowired + private MockMvc mockMvc; + + @Test + public void createSpringfoxSwaggerJson() throws Exception{ + String outputDir = System.getProperty("io.springfox.staticdocs.outputDir"); + MvcResult mvcResult = this.mockMvc.perform(get("/v2/api-docs") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn(); + + MockHttpServletResponse response = mvcResult.getResponse(); + String swaggerJson = response.getContentAsString(); + Files.createDirectories(Paths.get(outputDir)); + try(BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputDir, "swagger.json"), StandardCharsets.UTF_8)){ + writer.write(swaggerJson); + } + + Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + .withGeneratedExamples() + .withInterDocumentCrossReferences() + .build(); + Swagger2MarkupConverter.from(Paths.get(outputDir,"swagger.json")) + .withConfig(config) + .build() + .toFile(Paths.get(outputDir, "swagger")); + } + +} \ No newline at end of file From 9d8501ab21caaa0070f2422232290de9d907d862 Mon Sep 17 00:00:00 2001 From: skdong Date: Thu, 30 Apr 2020 18:28:48 +0800 Subject: [PATCH 2/6] fix syntax bug --- services/vpc_manager/pom.xml | 2 ++ .../com/futurewei/alcor/vpcmanager/swagger/SwaggerConfig.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/services/vpc_manager/pom.xml b/services/vpc_manager/pom.xml index 87139e100..bad1826c8 100644 --- a/services/vpc_manager/pom.xml +++ b/services/vpc_manager/pom.xml @@ -69,12 +69,14 @@ io.springfox springfox-swagger2 2.6.1 + test io.github.swagger2markup swagger2markup-spring-restdocs-ext ${swagger2markup.version} + test diff --git a/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/swagger/SwaggerConfig.java b/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/swagger/SwaggerConfig.java index 717f41156..951d6054f 100644 --- a/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/swagger/SwaggerConfig.java +++ b/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/swagger/SwaggerConfig.java @@ -36,7 +36,7 @@ public Docket api(){ .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.any()) - .paths(PathSelectors.regex("(?!/error).+")):web + .paths(PathSelectors.regex("(?!/error).+")) .paths(PathSelectors.regex("(?!/actuator).+")) .build(); } From 747170abd2d5015984e4292a408a8ec046617552 Mon Sep 17 00:00:00 2001 From: kaidong Date: Tue, 5 May 2020 11:38:58 +0800 Subject: [PATCH 3/6] 1. Add Swagger configuration during unit testing 2. Export Swagger json document through unit test, document directory /target/swagger/swagger.json 3. Convert Swagger json document to adoc document, document directory target / swagger / swagger.adoc --- services/mac_manager/pom.xml | 23 +++ .../macmanager/swagger/SwaggerConfig.java | 16 +- .../macmanager/swagger/SwaggerJsonTest.java | 17 +- services/private_ip_manager/pom.xml | 24 ++- .../swagger/SwaggerConfig.java | 18 +- .../swagger/SwaggerJsonTest.java | 14 ++ services/route_manager/pom.xml | 23 ++- .../alcor/route/swagger/SwaggerConfig.java | 16 +- .../alcor/route/swagger/SwaggerJsonTest.java | 14 ++ services/subnet_manager/pom.xml | 164 ++---------------- .../alcor/subnet/swagger/SwaggerConfig.java | 16 +- .../alcor/subnet/swagger/SwaggerJsonTest.java | 15 +- .../vpcmanager/swagger/SwaggerConfig.java | 2 +- 13 files changed, 165 insertions(+), 197 deletions(-) diff --git a/services/mac_manager/pom.xml b/services/mac_manager/pom.xml index becf7f0cb..fea4d354a 100644 --- a/services/mac_manager/pom.xml +++ b/services/mac_manager/pom.xml @@ -16,6 +16,8 @@ 1.8 + ${project.build.directory}/swagger + 1.2.0 @@ -71,6 +73,18 @@ + + io.springfox + springfox-swagger2 + 2.6.1 + test + + + io.github.swagger2markup + swagger2markup-spring-restdocs-ext + ${swagger2markup.version} + test + com.futurewei.alcor.common AlcorCommonLib @@ -85,6 +99,15 @@ org.springframework.boot spring-boot-maven-plugin + + org.apache.maven.plugins + maven-surefire-plugin + + + ${swagger.output.dir} + + + diff --git a/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/swagger/SwaggerConfig.java b/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/swagger/SwaggerConfig.java index 668d4d14e..4135f1523 100644 --- a/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/swagger/SwaggerConfig.java +++ b/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/swagger/SwaggerConfig.java @@ -24,6 +24,7 @@ import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @@ -32,17 +33,20 @@ public class SwaggerConfig{ @Bean public Docket api(){ return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.any()) - .paths(PathSelectors.any()) + .paths(PathSelectors.regex("(?!/error).+")) + .paths(PathSelectors.regex("(?!/actuator).+")) .build(); -// .apiInfo(apiInfo()); } private ApiInfo apiInfo(){ - return new ApiInfo("MAC Manager", "MAC pool management", - "version", "termsOfServiceUrl", - "contact", "license", - "licenseUrl"); + return new ApiInfoBuilder() + .title("Virtual MAC Manager") + .description("Virtual MAC pool management") + .license("Apache 2.0") + .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") + .build(); } } \ No newline at end of file diff --git a/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/swagger/SwaggerJsonTest.java b/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/swagger/SwaggerJsonTest.java index ec906bf0e..293d408d6 100644 --- a/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/swagger/SwaggerJsonTest.java +++ b/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/swagger/SwaggerJsonTest.java @@ -33,13 +33,16 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; -//import org.springframework.test.context.web.WebAppConfiguration; + +import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.Swagger2MarkupProperties; +import io.github.swagger2markup.Swagger2MarkupConfig; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -//@WebAppConfiguration @RunWith(SpringRunner.class) @SpringBootTest @AutoConfigureMockMvc @@ -50,7 +53,6 @@ public class SwaggerJsonTest{ @Test public void createSpringfoxSwaggerJson() throws Exception{ - //String outputDir = System.getProperty("io.springfox.staticdocs.outputDir"); String outputDir = System.getProperty("io.springfox.staticdocs.outputDir"); MvcResult mvcResult = this.mockMvc.perform(get("/v2/api-docs") .accept(MediaType.APPLICATION_JSON)) @@ -63,6 +65,15 @@ public void createSpringfoxSwaggerJson() throws Exception{ try(BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputDir, "swagger.json"), StandardCharsets.UTF_8)){ writer.write(swaggerJson); } + + Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + .withGeneratedExamples() + .withInterDocumentCrossReferences() + .build(); + Swagger2MarkupConverter.from(Paths.get(outputDir,"swagger.json")) + .withConfig(config) + .build() + .toFile(Paths.get(outputDir, "swagger")); } } \ No newline at end of file diff --git a/services/private_ip_manager/pom.xml b/services/private_ip_manager/pom.xml index 0fe4f3a04..c9bb4a27d 100644 --- a/services/private_ip_manager/pom.xml +++ b/services/private_ip_manager/pom.xml @@ -16,6 +16,8 @@ 1.8 + ${project.build.directory}/swagger + 1.2.0 @@ -28,12 +30,6 @@ org.springframework.boot spring-boot-starter-test test - - - org.junit.vintage - junit-vintage-engine - - @@ -41,7 +37,18 @@ lombok 1.18.0 - + + io.springfox + springfox-swagger2 + 2.6.1 + test + + + io.github.swagger2markup + swagger2markup-spring-restdocs-ext + ${swagger2markup.version} + test + com.futurewei.alcor.common AlcorCommonLib @@ -67,6 +74,9 @@ maven-surefire-plugin true + + ${swagger.output.dir} + diff --git a/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/swagger/SwaggerConfig.java b/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/swagger/SwaggerConfig.java index b9c5b0367..83ec3c2ed 100644 --- a/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/swagger/SwaggerConfig.java +++ b/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/swagger/SwaggerConfig.java @@ -14,7 +14,7 @@ limitations under the License. */ -package com.futurewei.alcor.privatemanager.swagger; +package com.futurewei.alcor.privateipmanager.swagger; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -24,6 +24,7 @@ import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @@ -32,17 +33,20 @@ public class SwaggerConfig{ @Bean public Docket api(){ return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.any()) - .paths(PathSelectors.any()) + .paths(PathSelectors.regex("(?!/error).+")) + .paths(PathSelectors.regex("(?!/actuator).+")) .build(); - // .apiInfo(apiInfo()); } private ApiInfo apiInfo(){ - return new ApiInfo("Subnet Manager", "To manager subnet address", - "version", "termsOfServiceUrl", - "contact", "license", - "licenseUrl"); + return new ApiInfoBuilder() + .title("Private IP Manager") + .description("VPC Private IP lifecycle management(IPv4/6)") + .license("Apache 2.0") + .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") + .build(); } } \ No newline at end of file diff --git a/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/swagger/SwaggerJsonTest.java b/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/swagger/SwaggerJsonTest.java index 15b11a65c..9b4629565 100644 --- a/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/swagger/SwaggerJsonTest.java +++ b/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/swagger/SwaggerJsonTest.java @@ -34,6 +34,11 @@ import java.nio.file.Files; import java.nio.file.Paths; +import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.Swagger2MarkupProperties; +import io.github.swagger2markup.Swagger2MarkupConfig; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; + import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; @@ -60,6 +65,15 @@ public void createSpringfoxSwaggerJson() throws Exception{ try(BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputDir, "swagger.json"), StandardCharsets.UTF_8)){ writer.write(swaggerJson); } + + Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + .withGeneratedExamples() + .withInterDocumentCrossReferences() + .build(); + Swagger2MarkupConverter.from(Paths.get(outputDir,"swagger.json")) + .withConfig(config) + .build() + .toFile(Paths.get(outputDir, "swagger")); } } \ No newline at end of file diff --git a/services/route_manager/pom.xml b/services/route_manager/pom.xml index 28c03b317..babd02af9 100644 --- a/services/route_manager/pom.xml +++ b/services/route_manager/pom.xml @@ -20,6 +20,8 @@ 1.7 1.5.6 ${project.basedir}/target/generated-snippets/ + ${project.build.directory}/swagger + 1.2.0 @@ -59,12 +61,18 @@ org.springframework.boot spring-boot-starter-test test - - - org.junit.vintage - junit-vintage-engine - - + + + io.springfox + springfox-swagger2 + 2.6.1 + test + + + io.github.swagger2markup + swagger2markup-spring-restdocs-ext + ${swagger2markup.version} + test @@ -95,6 +103,9 @@ maven-surefire-plugin true + + ${swagger.output.dir} + diff --git a/services/route_manager/src/test/java/com/futurewei/alcor/route/swagger/SwaggerConfig.java b/services/route_manager/src/test/java/com/futurewei/alcor/route/swagger/SwaggerConfig.java index 6cd486b99..9e75b1467 100644 --- a/services/route_manager/src/test/java/com/futurewei/alcor/route/swagger/SwaggerConfig.java +++ b/services/route_manager/src/test/java/com/futurewei/alcor/route/swagger/SwaggerConfig.java @@ -24,6 +24,7 @@ import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @@ -32,17 +33,20 @@ public class SwaggerConfig{ @Bean public Docket api(){ return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.any()) - .paths(PathSelectors.any()) + .paths(PathSelectors.regex("(?!/error).+")) + .paths(PathSelectors.regex("(?!/actuator).+")) .build(); - //.apiInfo(apiInfo()); } private ApiInfo apiInfo(){ - return new ApiInfo("Subnet Manager", "To manager subnet address", - "version", "termsOfServiceUrl", - "contact", "license", - "licenseUrl"); + return new ApiInfoBuilder() + .title("Route Manager") + .description("Route lifecycle management") + .license("Apache 2.0") + .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") + .build(); } } \ No newline at end of file diff --git a/services/route_manager/src/test/java/com/futurewei/alcor/route/swagger/SwaggerJsonTest.java b/services/route_manager/src/test/java/com/futurewei/alcor/route/swagger/SwaggerJsonTest.java index 685e3780c..c441ebf8a 100644 --- a/services/route_manager/src/test/java/com/futurewei/alcor/route/swagger/SwaggerJsonTest.java +++ b/services/route_manager/src/test/java/com/futurewei/alcor/route/swagger/SwaggerJsonTest.java @@ -34,6 +34,11 @@ import java.nio.file.Files; import java.nio.file.Paths; +import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.Swagger2MarkupProperties; +import io.github.swagger2markup.Swagger2MarkupConfig; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; + import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; @@ -60,6 +65,15 @@ public void createSpringfoxSwaggerJson() throws Exception{ try(BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputDir, "swagger.json"), StandardCharsets.UTF_8)){ writer.write(swaggerJson); } + + Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + .withGeneratedExamples() + .withInterDocumentCrossReferences() + .build(); + Swagger2MarkupConverter.from(Paths.get(outputDir,"swagger.json")) + .withConfig(config) + .build() + .toFile(Paths.get(outputDir, "swagger")); } } \ No newline at end of file diff --git a/services/subnet_manager/pom.xml b/services/subnet_manager/pom.xml index 0484eb199..3c3108afb 100644 --- a/services/subnet_manager/pom.xml +++ b/services/subnet_manager/pom.xml @@ -19,16 +19,9 @@ 1.7 1.7 1.5.6 - ${project.basedir}/target/generated-snippets/ ${project.build.directory}/swagger - ${project.build.directory}/asciidoc/snippets 1.2.0 - ${project.build.directory}/asciidoc/generated - ${project.basedir}/../../docs/asciidoc - ${project.build.directory}/asciidoc/html - ${project.build.directory}/asciidoc/pdf - ${swagger.output.dir}/swagger.json @@ -79,11 +72,13 @@ io.springfox springfox-swagger2 2.6.1 + test - io.springfox - springfox-swagger-ui - 2.2.2 + io.github.swagger2markup + swagger2markup-spring-restdocs-ext + ${swagger2markup.version} + test @@ -111,9 +106,12 @@ org.apache.maven.plugins maven-surefire-plugin - + + ${swagger.output.dir} + + org.springframework.boot @@ -180,148 +178,6 @@ - - org.apache.maven.plugins - maven-surefire-plugin - - - ${swagger.output.dir} - - - - - - - io.github.swagger2markup - swagger2markup-maven-plugin - ${swagger2markup.version} - - - io.github.swagger2markup - swagger2markup-import-files-ext - ${swagger2markup.version} - - - io.github.swagger2markup - swagger2markup-spring-restdocs-ext - ${swagger2markup.version} - - - - ${swagger.input} - ${generated.asciidoc.directory} - - ASCIIDOC - TAGS - true - ${project.basedir}/src/docs/asciidoc/extensions/overview - ${project.basedir}/src/docs/asciidoc/extensions/definitions - ${project.basedir}/src/docs/asciidoc/extensions/paths - ${project.basedir}src/docs/asciidoc/extensions/security/ - - ${swagger.snippetOutput.dir} - true - - - - - test - - convertSwagger2markup - - - - - - - - org.asciidoctor - asciidoctor-maven-plugin - 1.5.6 - - - - org.asciidoctor - asciidoctorj-pdf - 1.5.0-alpha.16 - - - org.jruby - jruby-complete - 1.7.21 - - - - - ${asciidoctor.input.directory} - index.adoc - - book - left - 3 - - - - - ${generated.asciidoc.directory} - - - - - - output-html - test - - process-asciidoc - - - html5 - ${asciidoctor.html.output.directory} - - - - - output-pdf - test - - process-asciidoc - - - pdf - ${asciidoctor.pdf.output.directory} - - - - - - - - maven-resources-plugin - 3.1.0 - - - copy-resources - - test - - copy-resources - - - ${project.build.outputDirectory}/static/docs - - - ${asciidoctor.html.output.directory} - - - ${asciidoctor.pdf.output.directory} - - - - - - diff --git a/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/swagger/SwaggerConfig.java b/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/swagger/SwaggerConfig.java index b1310e842..d40a887d6 100644 --- a/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/swagger/SwaggerConfig.java +++ b/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/swagger/SwaggerConfig.java @@ -24,6 +24,7 @@ import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @@ -32,17 +33,20 @@ public class SwaggerConfig{ @Bean public Docket api(){ return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.any()) - .paths(PathSelectors.any()) + .paths(PathSelectors.regex("(?!/error).+")) + .paths(PathSelectors.regex("(?!/actuator).+")) .build(); - //.apiInfo(apiInfo()); } private ApiInfo apiInfo(){ - return new ApiInfo("Subnet Manager", "To manager subnet address", - "version", "termsOfServiceUrl", - "contact", "license", - "licenseUrl"); + return new ApiInfoBuilder() + .title("Subnet Manager") + .description("Subnet lifecycle management") + .license("Apache 2.0") + .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") + .build(); } } \ No newline at end of file diff --git a/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/swagger/SwaggerJsonTest.java b/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/swagger/SwaggerJsonTest.java index 291010310..21f37cc3b 100644 --- a/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/swagger/SwaggerJsonTest.java +++ b/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/swagger/SwaggerJsonTest.java @@ -34,6 +34,11 @@ import java.nio.file.Files; import java.nio.file.Paths; +import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.Swagger2MarkupProperties; +import io.github.swagger2markup.Swagger2MarkupConfig; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; + import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; @@ -48,7 +53,6 @@ public class SwaggerJsonTest{ @Test public void createSpringfoxSwaggerJson() throws Exception{ - //String outputDir = System.getProperty("io.springfox.staticdocs.outputDir"); String outputDir = System.getProperty("io.springfox.staticdocs.outputDir"); MvcResult mvcResult = this.mockMvc.perform(get("/v2/api-docs") .accept(MediaType.APPLICATION_JSON)) @@ -61,6 +65,15 @@ public void createSpringfoxSwaggerJson() throws Exception{ try(BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputDir, "swagger.json"), StandardCharsets.UTF_8)){ writer.write(swaggerJson); } + + Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + .withGeneratedExamples() + .withInterDocumentCrossReferences() + .build(); + Swagger2MarkupConverter.from(Paths.get(outputDir,"swagger.json")) + .withConfig(config) + .build() + .toFile(Paths.get(outputDir, "swagger")); } } \ No newline at end of file diff --git a/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/swagger/SwaggerConfig.java b/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/swagger/SwaggerConfig.java index 951d6054f..2ffeaa235 100644 --- a/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/swagger/SwaggerConfig.java +++ b/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/swagger/SwaggerConfig.java @@ -44,7 +44,7 @@ public Docket api(){ private ApiInfo apiInfo(){ return new ApiInfoBuilder() .title("VPC Manager") - .description("VPC Manager") + .description("VPC lifecycle management") .license("Apache 2.0") .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") .build(); From b2190f66e175784bab83d51be96643e88f74db26 Mon Sep 17 00:00:00 2001 From: kaidong Date: Tue, 5 May 2020 14:31:02 +0800 Subject: [PATCH 4/6] reset configure file to master branch --- services/vpc_manager/pom.xml | 5 +---- .../vpc_manager/src/main/resources/application.properties | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/services/vpc_manager/pom.xml b/services/vpc_manager/pom.xml index bad1826c8..619a5acd8 100644 --- a/services/vpc_manager/pom.xml +++ b/services/vpc_manager/pom.xml @@ -102,14 +102,11 @@ - - org.apache.maven.plugins - maven-surefire-plugin - org.apache.maven.plugins maven-surefire-plugin + true ${swagger.output.dir} diff --git a/services/vpc_manager/src/main/resources/application.properties b/services/vpc_manager/src/main/resources/application.properties index 51076e617..d72d7f9e9 100644 --- a/services/vpc_manager/src/main/resources/application.properties +++ b/services/vpc_manager/src/main/resources/application.properties @@ -13,7 +13,7 @@ #logging.file.path=. #logging.type=file #Ignite configuration -ignite.host=localhost +ignite.host=192.168.137.1 ignite.port=10800 #ignite.key-store-path=F:\\work\\alcor\\git\\chenpp\\alcor\\src\\resources\\keystore.jks #ignite.key-store-password=123456 From e3ddc71a85334f815a0c6d501f21f4d42939985a Mon Sep 17 00:00:00 2001 From: skdong Date: Wed, 6 May 2020 11:42:27 +0800 Subject: [PATCH 5/6] add jcenter repository for swagger2markup --- services/mac_manager/pom.xml | 11 +++++++++++ services/private_ip_manager/pom.xml | 11 +++++++++++ services/route_manager/pom.xml | 11 +++++++++++ services/subnet_manager/pom.xml | 11 +++++++++++ services/vpc_manager/pom.xml | 11 +++++++++++ 5 files changed, 55 insertions(+) diff --git a/services/mac_manager/pom.xml b/services/mac_manager/pom.xml index fea4d354a..30799ec9f 100644 --- a/services/mac_manager/pom.xml +++ b/services/mac_manager/pom.xml @@ -20,6 +20,17 @@ 1.2.0 + + + + false + + jcenter-releases + jcenter + https://jcenter.bintray.com + + + org.springframework.boot diff --git a/services/private_ip_manager/pom.xml b/services/private_ip_manager/pom.xml index c9bb4a27d..aaad27417 100644 --- a/services/private_ip_manager/pom.xml +++ b/services/private_ip_manager/pom.xml @@ -20,6 +20,17 @@ 1.2.0 + + + + false + + jcenter-releases + jcenter + https://jcenter.bintray.com + + + org.springframework.boot diff --git a/services/route_manager/pom.xml b/services/route_manager/pom.xml index babd02af9..9dc318a37 100644 --- a/services/route_manager/pom.xml +++ b/services/route_manager/pom.xml @@ -24,6 +24,17 @@ 1.2.0 + + + + false + + jcenter-releases + jcenter + https://jcenter.bintray.com + + + org.springframework.boot diff --git a/services/subnet_manager/pom.xml b/services/subnet_manager/pom.xml index 3c3108afb..bbfe876d9 100644 --- a/services/subnet_manager/pom.xml +++ b/services/subnet_manager/pom.xml @@ -24,6 +24,17 @@ 1.2.0 + + + + false + + jcenter-releases + jcenter + https://jcenter.bintray.com + + + org.springframework.boot diff --git a/services/vpc_manager/pom.xml b/services/vpc_manager/pom.xml index 619a5acd8..5f691e87b 100644 --- a/services/vpc_manager/pom.xml +++ b/services/vpc_manager/pom.xml @@ -26,6 +26,17 @@ + + + + false + + jcenter-releases + jcenter + https://jcenter.bintray.com + + + org.springframework.boot From 905194a61f47fb1e769fe720b00437ed6c37751c Mon Sep 17 00:00:00 2001 From: skdong Date: Fri, 8 May 2020 10:41:34 +0800 Subject: [PATCH 6/6] skip private ip manager UTs --- services/private_ip_manager/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/private_ip_manager/pom.xml b/services/private_ip_manager/pom.xml index 4affd71ea..aaad27417 100644 --- a/services/private_ip_manager/pom.xml +++ b/services/private_ip_manager/pom.xml @@ -84,7 +84,7 @@ org.apache.maven.plugins maven-surefire-plugin - false + true ${swagger.output.dir}