Multiple OpenAPI Beans

Viewed 40

We are generating two kind of API documentation: internal and external. We put them to seperate places but there multiple items that needs to be changed.

  • For external documentation there should be an extension for documentation
  • URLs for internal and external are different

Currently

@Bean
@ConditionalOnProperty(prefix = "yaml", name = "type", havingValue = "api", matchIfMissing = true)
public OpenAPI openApiYamlBean() {
      return new OpenAPI()
        .openapi("3.0.0")
        .addServersItem(
            new Server()
                .url("https://external-url")
                .description("Development environment"));
}

@Bean
@ConditionalOnProperty(prefix = "yaml", name = "type", havingValue = "service")
public OpenAPI openApiServiceBean() {
    return new OpenAPI()
        .openapi("3.0.0")
        .addServersItem(
            new Server()
                .url("https://internal-url")
                .description("Production environment"))
        .info(info);
}

Is there a way to provide single OpenAPI bean to expose conditional cases? With above approach it takes more time to generate documentation as it needs to be run twice.

0 Answers
Related