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

Demonstrate how to get swagger.json #64

Open
opticyclic opened this issue Jul 25, 2019 · 0 comments
Open

Demonstrate how to get swagger.json #64

opticyclic opened this issue Jul 25, 2019 · 0 comments

Comments

@opticyclic
Copy link

Add a demo on how to get the swagger.json file as it is sometimes required to upload to external sites that are hosting your documentation.

e.g.

@RunWith(SpringRunner.class)
@SpringBootTest
public class GenerateSwagger {

    @Autowired
    WebApplicationContext context;

    @Test
    public void generateSwagger() throws Exception {
        MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
        mockMvc.perform(MockMvcRequestBuilders.get("/v2/api-docs").accept(MediaType.APPLICATION_JSON))
                .andDo((result) -> {
                    FileUtils.writeStringToFile(new File("swagger.json"), result.getResponse().getContentAsString());
                });

    }
}

Originally posted by @yissachar in springfox/springfox#1959 (comment)

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