Skip to content
Snippets Groups Projects
Commit d319968b authored by Anthony Ittiyera vazhappilly's avatar Anthony Ittiyera vazhappilly
Browse files

create feature flag to toggle enableFullSwaggerUrlProperty

parent 2e001b65
No related branches found
No related tags found
1 merge request!335Use full URL instead of relative path
Pipeline #238017 failed
......@@ -74,7 +74,13 @@ to send a GET request to obtaining the Swagger API documentation
- api-docs [Version V2] (JSON) : https://host/context-path/api-docs/v2
- api-docs [Version V3] (JSON) : https://host/context-path/api-docs/v3
All the Swagger and OpenAPI related common properties are managed here [swagger.properties](https://community.opengroup.org/osdu/platform/system/reference/crs-catalog-service/-/blob/jb/az_swagger_openapi/crs-catalog-core/src/main/resources/swagger.properties)
All the Swagger and OpenAPI related common properties are managed here [swagger.properties](https://community.opengroup.org/osdu/platform/system/reference/crs-catalog-service/-/blob/jb/az_swagger_openapi/crs-catalog-core/src/main/resources/swagger.properties)
#### Server Url(full path vs relative path) configuration
- `api.server.fullUrl.enabled=true` It will generate full server url in the OpenAPI swagger
- `api.server.fullUrl.enabled=false` It will generate only the contextPath only
- default value is false (Currently only in Azure it is enabled)
[Reference]:(https://springdoc.org/faq.html#_how_is_server_url_generated)
```
http://localhost:8080/api/crs/catalog/v2/swagger.json
......
......@@ -9,6 +9,7 @@ import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import io.swagger.v3.oas.models.tags.Tag;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.springdoc.core.GroupedOpenApi;
......@@ -18,6 +19,9 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Configuration
......@@ -41,10 +45,16 @@ public class SwaggerConfiguration {
@Value("${api.license.url}")
private String licenseUrl;
@Value("${api.server.url}")
private String apiServerUrl;
@Value("${api.server.fullUrl.enabled:false}")
private boolean isServerFullUrlEnabled;
@Bean
public OpenAPI customOpenAPI() {
final String securitySchemeName = "Authorization";
return new OpenAPI()
OpenAPI openAPI = new OpenAPI()
.addSecurityItem(new SecurityRequirement().addList(securitySchemeName))
.components(new Components().addSecuritySchemes(securitySchemeName, new SecurityScheme()
.type(SecurityScheme.Type.HTTP)
......@@ -53,6 +63,10 @@ public class SwaggerConfiguration {
.in(SecurityScheme.In.HEADER)
.name("Authorization")))
.info(apiInfo());
if (isServerFullUrlEnabled)
return openAPI;
return openAPI
.servers(Arrays.asList(new Server().url(apiServerUrl)));
}
......
......@@ -46,3 +46,6 @@ logging.ignore.servlet.paths=/swagger-ui.html
# Disable keyVault for actuator health check
management.health.azure-key-vault.enabled=false
# To enable the full server path url in OpenAPI Swagger
api.server.fullUrl.enabled=${swaggerFullUrlEnabled:true}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment