Skip to content

Commit 79ea1da

Browse files
chore(swagger): add env-driven Dev/UAT/Demo servers and update workflow
1 parent 25a4e25 commit 79ea1da

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

.github/workflows/swagger-json.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
with:
100100
token: ${{ secrets.DOCS_REPO_TOKEN }}
101101
path: amrit-docs
102-
branch: auto/swagger-update-${{ github.run_id }}-${{ github.run_attempt }}
102+
branch: auto/swagger-update-inventory-api
103103
base: main
104104
commit-message: "chore(docs): auto-update Inventory-API swagger"
105105
title: "chore(docs): auto-update Inventory-API swagger"

src/main/java/com/iemr/inventory/config/SwaggerConfig.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.springframework.context.annotation.Bean;
44
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.core.env.Environment;
56

67
import io.swagger.v3.oas.models.Components;
78
import io.swagger.v3.oas.models.OpenAPI;
@@ -11,14 +12,23 @@
1112

1213
@Configuration
1314
public class SwaggerConfig {
14-
15-
@Bean
16-
public OpenAPI customOpenAPI() {
17-
return new OpenAPI().info(new
18-
Info().title("Inventory 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("Inventory 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+
));
2232
}
2333

2434
}

src/main/resources/application-swagger.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Swagger server URLs
2+
api.dev.url=${API_DEV_URL:https://amritwprdev.piramalswasthya.org}
3+
api.uat.url=${API_UAT_URL:https://uatamrit.piramalswasthya.org}
4+
api.demo.url=${API_DEMO_URL:https://amritdemo.piramalswasthya.org}
15
spring.datasource.url=jdbc:h2:mem:swaggerdb
26
spring.datasource.driver-class-name=org.h2.Driver
37
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

0 commit comments

Comments
 (0)