diff --git a/services/mac_manager/pom.xml b/services/mac_manager/pom.xml
index becf7f0cb..30799ec9f 100644
--- a/services/mac_manager/pom.xml
+++ b/services/mac_manager/pom.xml
@@ -16,8 +16,21 @@
1.8
+ ${project.build.directory}/swagger
+ 1.2.0
+
+
+
+ false
+
+ jcenter-releases
+ jcenter
+ https://jcenter.bintray.com
+
+
+
org.springframework.boot
@@ -71,6 +84,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 +110,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
new file mode 100644
index 000000000..4135f1523
--- /dev/null
+++ b/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/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.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.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).+"))
+ .paths(PathSelectors.regex("(?!/actuator).+"))
+ .build();
+ }
+
+ private ApiInfo apiInfo(){
+ 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
new file mode 100644
index 000000000..293d408d6
--- /dev/null
+++ b/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/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.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 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
diff --git a/services/private_ip_manager/pom.xml b/services/private_ip_manager/pom.xml
index 3a3d086c6..aaad27417 100644
--- a/services/private_ip_manager/pom.xml
+++ b/services/private_ip_manager/pom.xml
@@ -16,8 +16,21 @@
1.8
+ ${project.build.directory}/swagger
+ 1.2.0
+
+
+
+ false
+
+ jcenter-releases
+ jcenter
+ https://jcenter.bintray.com
+
+
+
org.springframework.boot
@@ -28,12 +41,6 @@
org.springframework.boot
spring-boot-starter-test
test
-
-
- org.junit.vintage
- junit-vintage-engine
-
-
@@ -41,7 +48,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
@@ -66,7 +84,10 @@
org.apache.maven.plugins
maven-surefire-plugin
- false
+ 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
new file mode 100644
index 000000000..83ec3c2ed
--- /dev/null
+++ b/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/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.privateipmanager.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).+"))
+ .paths(PathSelectors.regex("(?!/actuator).+"))
+ .build();
+ }
+
+ private ApiInfo apiInfo(){
+ 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
new file mode 100644
index 000000000..9b4629565
--- /dev/null
+++ b/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/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.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 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
diff --git a/services/route_manager/pom.xml b/services/route_manager/pom.xml
index 5aa356b61..b7eba4df4 100644
--- a/services/route_manager/pom.xml
+++ b/services/route_manager/pom.xml
@@ -20,8 +20,21 @@
1.7
1.5.6
${project.basedir}/target/generated-snippets/
+ ${project.build.directory}/swagger
+ 1.2.0
+
+
+
+ false
+
+ jcenter-releases
+ jcenter
+ https://jcenter.bintray.com
+
+
+
org.springframework.boot
@@ -59,12 +72,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 +114,9 @@
maven-surefire-plugin
false
+
+ ${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
new file mode 100644
index 000000000..9e75b1467
--- /dev/null
+++ b/services/route_manager/src/test/java/com/futurewei/alcor/route/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.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.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).+"))
+ .paths(PathSelectors.regex("(?!/actuator).+"))
+ .build();
+ }
+
+ private ApiInfo apiInfo(){
+ 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
new file mode 100644
index 000000000..c441ebf8a
--- /dev/null
+++ b/services/route_manager/src/test/java/com/futurewei/alcor/route/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.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 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
diff --git a/services/subnet_manager/pom.xml b/services/subnet_manager/pom.xml
index 6eeba7d6e..ab0de2c9d 100644
--- a/services/subnet_manager/pom.xml
+++ b/services/subnet_manager/pom.xml
@@ -19,9 +19,22 @@
1.7
1.7
1.5.6
- ${project.basedir}/target/generated-snippets/
+
+ ${project.build.directory}/swagger
+ 1.2.0
+
+
+
+ false
+
+ jcenter-releases
+ jcenter
+ https://jcenter.bintray.com
+
+
+
org.springframework.boot
@@ -60,18 +73,24 @@
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
+ test
+
+
+ io.github.swagger2markup
+ swagger2markup-spring-restdocs-ext
+ ${swagger2markup.version}
+ test
+
com.futurewei.alcor.common
@@ -100,6 +119,9 @@
maven-surefire-plugin
false
+
+ ${swagger.output.dir}
+
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..d40a887d6
--- /dev/null
+++ b/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/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.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.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).+"))
+ .paths(PathSelectors.regex("(?!/actuator).+"))
+ .build();
+ }
+
+ private ApiInfo apiInfo(){
+ 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
new file mode 100644
index 000000000..21f37cc3b
--- /dev/null
+++ b/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/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.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 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
diff --git a/services/vpc_manager/pom.xml b/services/vpc_manager/pom.xml
index 31c3aeb5b..386c54c76 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
@@ -24,6 +26,17 @@
+
+
+
+ false
+
+ jcenter-releases
+ jcenter
+ https://jcenter.bintray.com
+
+
+
org.springframework.boot
@@ -61,12 +74,20 @@
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
@@ -97,6 +118,9 @@
maven-surefire-plugin
false
+
+ ${swagger.output.dir}
+
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..2ffeaa235
--- /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).+"))
+ .paths(PathSelectors.regex("(?!/actuator).+"))
+ .build();
+ }
+
+ private ApiInfo apiInfo(){
+ return new ApiInfoBuilder()
+ .title("VPC Manager")
+ .description("VPC 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/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