Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
oneslideicywater opened this issue Aug 14, 2019 · 0 comments

Comments

@oneslideicywater
Copy link

oneslideicywater commented Aug 14, 2019

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";
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant