10

I have working project which is using springfox to generate API documentations.

I want to generate swagger.json at compile time.

following is sample springfox configuration,

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()                 
                .apis(RequestHandlerSelectors.basePackage("com.abc.xyz"))
                .paths(regex("/*.*"))
                .build();
    }
}

FYI : I have also tried https://github.com/kongchen/swagger-maven-plugin plugin but it's not working

Mayur
  • 576
  • 2
  • 5
  • 26
  • 1
    For a kongchen example you can check my repo: https://github.com/evgdim/SwaggerGenerator . Usually the springfox lib returns the swagger json when you access `http://:/v2/api-docs` – Evgeni Dimitrov Dec 19 '18 at 13:09
  • I have already tried changes you have It in your example. swagger UI required swagger json on to replay it on UI. My question is to get or generate that swagger json at compile / build time – Mayur Dec 20 '18 at 05:49

1 Answers1

11

This is achieved using JUnit test case, follow https://github.com/springfox/springfox/issues/1959 for more details.

Mayur
  • 576
  • 2
  • 5
  • 26