Skip to content

Commit 7c91575

Browse files
Add server urls and update swagger workflow (#135)
* docs(readme): add documentation badge * chore(swagger): automate swagger sync to amrit-docs * chore(swagger): automate swagger sync to amrit-docs * chore(swagger): update github workflow for swagger json * fix(swagger): fix the stop api issue in swagger workflow * fix(swagger): removed the unnecessary initial sleep * chore(swagger): add env-driven Dev/UAT/Demo servers and update swagger workflow
1 parent 29c461c commit 7c91575

3 files changed

Lines changed: 24 additions & 10 deletions

File tree

.github/workflows/swagger-json.yml

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

src/main/java/com/iemr/common/identity/config/SwaggerConfig.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.springframework.context.annotation.Bean;
2525
import org.springframework.context.annotation.Configuration;
26+
import org.springframework.core.env.Environment;
2627

2728
import io.swagger.v3.oas.models.Components;
2829
import io.swagger.v3.oas.models.OpenAPI;
@@ -32,14 +33,23 @@
3233

3334

3435
@Configuration
35-
public class SwaggerConfig
36-
{
37-
@Bean
38-
public OpenAPI customOpenAPI() {
39-
return new OpenAPI().info(new
40-
Info().title("Identity API").version("version").description("A microservice for the creation and management of beneficiaries."))
41-
.addSecurityItem(new SecurityRequirement().addList("my security"))
42-
.components(new Components().addSecuritySchemes("my security",
43-
new SecurityScheme().name("my security").type(SecurityScheme.Type.HTTP).scheme("bearer")));
36+
public class SwaggerConfig {
37+
private static final String DEFAULT_SERVER_URL = "http://localhost:9090";
38+
39+
@Bean
40+
public OpenAPI customOpenAPI(Environment env) {
41+
String devUrl = env.getProperty("api.dev.url", DEFAULT_SERVER_URL);
42+
String uatUrl = env.getProperty("api.uat.url", DEFAULT_SERVER_URL);
43+
String demoUrl = env.getProperty("api.demo.url", DEFAULT_SERVER_URL);
44+
return new OpenAPI()
45+
.info(new Info().title("Identity API").version("version").description("A microservice for the creation and management of beneficiaries."))
46+
.addSecurityItem(new SecurityRequirement().addList("my security"))
47+
.components(new Components().addSecuritySchemes("my security",
48+
new SecurityScheme().name("my security").type(SecurityScheme.Type.HTTP).scheme("bearer")))
49+
.servers(java.util.Arrays.asList(
50+
new io.swagger.v3.oas.models.servers.Server().url(devUrl).description("Dev"),
51+
new io.swagger.v3.oas.models.servers.Server().url(uatUrl).description("UAT"),
52+
new io.swagger.v3.oas.models.servers.Server().url(demoUrl).description("Demo")
53+
));
4454
}
4555
}

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)