spring-swagger2markup-demo
spring-swagger2markup-demo copied to clipboard
could you tell me where you set the property `io.springfox.staticdocs.outputDir`
hello,there! I copy your pom and reduce your dependencies into two
<!--Spring-fox dependency-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
and copy all your plugins and properties setting in pom.xml
,and write a HelloController
with an simple hello.
So basically,I have three questions
- swagger.yml under the src/main/test is auto-generated or hand-written?
- under your test class,a code snippet is writing the
http://localhost:8080/v2/api-docs
responses into swagger/swagger.json,where did you set the propertyio.springfox.staticdocs.outputDir
@Test
public void createSpringfoxSwaggerJson() throws Exception {
//String designFirstSwaggerLocation = Swagger2MarkupTest.class.getResource("/swagger.yaml").getPath();
String outputDir = System.getProperty("io.springfox.staticdocs.outputDir");
System.out.println("outputDir="+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);
}
}
I get a null in test case.
@RequestMapping("/hello")
@ApiOperation(value = "Find pet by ID")
public String getHello(){
String outputDir = System.getProperty("io.springfox.staticdocs.outputDir");
System.out.println("outputDir="+outputDir);
return "hello";
}