Skip to content

Commit a26dcb0

Browse files
Update swagger workflow and add server urls (#187)
* Add documentation badge * chore(swagger): automate swagger sync to amrit-docs * chore(swagger): automate swagger sync to amrit-docs * chore(swagger): automate swagger sync to amrit-docs * chore(swagger): automate swagger sync to amrit-docs * chore(swagger): update swagger workflow * chore(swagger): add env-driven Dev/UAT/Demo servers and update swagger workflow * chore(swagger): add version for swagger doc
1 parent ca5dc75 commit a26dcb0

3 files changed

Lines changed: 26 additions & 9 deletions

File tree

.github/workflows/swagger-json.yml

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

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

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

33
import org.springframework.context.annotation.Bean;
44
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.core.env.Environment;
6+
import org.springframework.beans.factory.annotation.Value;
57

68
import io.swagger.v3.oas.models.Components;
79
import io.swagger.v3.oas.models.OpenAPI;
@@ -11,14 +13,25 @@
1113

1214
@Configuration
1315
public class SwaggerConfig {
14-
15-
@Bean
16-
public OpenAPI customOpenAPI() {
17-
return new OpenAPI().info(new
18-
Info().title("HWC 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")));
16+
@Value("${api.version:1.0.0}")
17+
private String apiVersion;
18+
private static final String DEFAULT_SERVER_URL = "http://localhost:9090";
19+
20+
@Bean
21+
public OpenAPI customOpenAPI(Environment env) {
22+
String devUrl = env.getProperty("api.dev.url", DEFAULT_SERVER_URL);
23+
String uatUrl = env.getProperty("api.uat.url", DEFAULT_SERVER_URL);
24+
String demoUrl = env.getProperty("api.demo.url", DEFAULT_SERVER_URL);
25+
return new OpenAPI()
26+
.info(new Info().title("HWC API").version(apiVersion).description("A microservice for the creation and management of beneficiaries."))
27+
.addSecurityItem(new SecurityRequirement().addList("my security"))
28+
.components(new Components().addSecuritySchemes("my security",
29+
new SecurityScheme().name("my security").type(SecurityScheme.Type.HTTP).scheme("bearer")))
30+
.servers(java.util.Arrays.asList(
31+
new io.swagger.v3.oas.models.servers.Server().url(devUrl).description("Dev"),
32+
new io.swagger.v3.oas.models.servers.Server().url(uatUrl).description("UAT"),
33+
new io.swagger.v3.oas.models.servers.Server().url(demoUrl).description("Demo")
34+
));
2235
}
2336

2437
}

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
registrationUrl=http://localhost:8080/registration
26
syncSearchByLocation=http://localhost:8080/syncSearchByLocation
37
getBenCountToSync=10

0 commit comments

Comments
 (0)