Swagger2Markup / spring-swagger2markup-demo

A demo project template using Swagger2Markup, Spring Boot, Springfox and spring-restdocs
398 stars 259 forks source link

could you tell me where you set the property `io.springfox.staticdocs.outputDir` #24

Open oneslideicywater opened 5 years ago

oneslideicywater commented 5 years ago

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 inpom.xml,and write a HelloController with an simple hello.

So basically,I have three questions

  1. swagger.yml under the src/main/test is auto-generated or hand-written?
  2. 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 property io.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";
    }