|
2 | 2 |
|
3 | 3 | import org.springframework.context.annotation.Bean; |
4 | 4 | import org.springframework.context.annotation.Configuration; |
| 5 | +import org.springframework.core.env.Environment; |
5 | 6 |
|
6 | 7 | import io.swagger.v3.oas.models.Components; |
7 | 8 | import io.swagger.v3.oas.models.OpenAPI; |
|
11 | 12 |
|
12 | 13 | @Configuration |
13 | 14 | public class SwaggerConfig { |
14 | | - |
15 | | - @Bean |
16 | | - public OpenAPI customOpenAPI() { |
17 | | - return new OpenAPI().info(new |
18 | | - Info().title("ECD API").version("version").description("A microservice for the creation and management of beneficiaries.")) |
19 | | - .addSecurityItem(new SecurityRequirement().addList("my security")) |
20 | | - .components(new Components().addSecuritySchemes("my security", |
21 | | - new SecurityScheme().name("my security").type(SecurityScheme.Type.HTTP).scheme("bearer"))); |
| 15 | + private static final String DEFAULT_SERVER_URL = "http://localhost:9090"; |
| 16 | + |
| 17 | + @Bean |
| 18 | + public OpenAPI customOpenAPI(Environment env) { |
| 19 | + String devUrl = env.getProperty("api.dev.url", DEFAULT_SERVER_URL); |
| 20 | + String uatUrl = env.getProperty("api.uat.url", DEFAULT_SERVER_URL); |
| 21 | + String demoUrl = env.getProperty("api.demo.url", DEFAULT_SERVER_URL); |
| 22 | + return new OpenAPI() |
| 23 | + .info(new Info().title("ECD API").version("version").description("A microservice for the creation and management of beneficiaries.")) |
| 24 | + .addSecurityItem(new SecurityRequirement().addList("my security")) |
| 25 | + .components(new Components().addSecuritySchemes("my security", |
| 26 | + new SecurityScheme().name("my security").type(SecurityScheme.Type.HTTP).scheme("bearer"))) |
| 27 | + .servers(java.util.Arrays.asList( |
| 28 | + new io.swagger.v3.oas.models.servers.Server().url(devUrl).description("Dev"), |
| 29 | + new io.swagger.v3.oas.models.servers.Server().url(uatUrl).description("UAT"), |
| 30 | + new io.swagger.v3.oas.models.servers.Server().url(demoUrl).description("Demo") |
| 31 | + )); |
22 | 32 | } |
23 | 33 |
|
24 | 34 | } |
0 commit comments