diff --git a/.github/workflows/swagger-json.yml b/.github/workflows/swagger-json.yml index 58b127f..4563221 100644 --- a/.github/workflows/swagger-json.yml +++ b/.github/workflows/swagger-json.yml @@ -99,7 +99,7 @@ jobs: with: token: ${{ secrets.DOCS_REPO_TOKEN }} path: amrit-docs - branch: auto/swagger-update-${{ github.run_id }}-${{ github.run_attempt }} + branch: auto/swagger-update-inventory-api base: main commit-message: "chore(docs): auto-update Inventory-API swagger" title: "chore(docs): auto-update Inventory-API swagger" diff --git a/src/main/java/com/iemr/inventory/config/SwaggerConfig.java b/src/main/java/com/iemr/inventory/config/SwaggerConfig.java index 93a3194..7429477 100644 --- a/src/main/java/com/iemr/inventory/config/SwaggerConfig.java +++ b/src/main/java/com/iemr/inventory/config/SwaggerConfig.java @@ -2,23 +2,37 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; + import io.swagger.v3.oas.models.security.SecurityRequirement; import io.swagger.v3.oas.models.security.SecurityScheme; +import java.util.List; +import io.swagger.v3.oas.models.servers.Server; @Configuration public class SwaggerConfig { - - @Bean - public OpenAPI customOpenAPI() { - return new OpenAPI().info(new - Info().title("Inventory API").version("version").description("A microservice for the creation and management of beneficiaries.")) - .addSecurityItem(new SecurityRequirement().addList("my security")) - .components(new Components().addSecuritySchemes("my security", - new SecurityScheme().name("my security").type(SecurityScheme.Type.HTTP).scheme("bearer"))); + private static final String DEFAULT_SERVER_URL = "http://localhost:9090"; + private static final String BEARER_AUTH_SCHEME = "bearerAuth"; + + @Bean + public OpenAPI customOpenAPI(Environment env) { + String devUrl = env.getProperty("api.dev.url", DEFAULT_SERVER_URL); + String uatUrl = env.getProperty("api.uat.url", DEFAULT_SERVER_URL); + String demoUrl = env.getProperty("api.demo.url", DEFAULT_SERVER_URL); + return new OpenAPI() + .info(new Info().title("Inventory API").version("version").description("A microservice for inventory management of items, stock levels, and related operations.")) + .addSecurityItem(new SecurityRequirement().addList(BEARER_AUTH_SCHEME)) + .components(new Components().addSecuritySchemes(BEARER_AUTH_SCHEME, + new SecurityScheme().name(BEARER_AUTH_SCHEME).type(SecurityScheme.Type.HTTP).scheme("bearer"))) + .servers(List.of( + new Server().url(devUrl).description("Dev"), + new Server().url(uatUrl).description("UAT"), + new Server().url(demoUrl).description("Demo") + )); } } diff --git a/src/main/resources/application-swagger.properties b/src/main/resources/application-swagger.properties index 129364c..5c0ddbc 100644 --- a/src/main/resources/application-swagger.properties +++ b/src/main/resources/application-swagger.properties @@ -1,3 +1,7 @@ +# Swagger server URLs +api.dev.url=${API_DEV_URL:https://amritwprdev.piramalswasthya.org} +api.uat.url=${API_UAT_URL:https://uatamrit.piramalswasthya.org} +api.demo.url=${API_DEMO_URL:https://amritdemo.piramalswasthya.org} spring.datasource.url=jdbc:h2:mem:swaggerdb spring.datasource.driver-class-name=org.h2.Driver spring.jpa.database-platform=org.hibernate.dialect.H2Dialect