Skip to content

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

@oneslideicywater

Description

@oneslideicywater

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

  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";
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions