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

create feature flag to toggle enableFullSwaggerUrlProperty

parent 7bbe9b00
No related branches found
No related tags found
1 merge request!607Use full URL instead of relative path
Pipeline #238102 failed
......@@ -56,6 +56,12 @@ go-swagger brings to the go community a complete suite of fully-featured, high-p
swagger generate client -f 'search_openapi.json' -A search_openapi
```
#### 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)
### Maintenance
* Indexer:
* Cleanup indexes - Indexer has a cron job running which hits following url:
......
......@@ -92,3 +92,6 @@ service.policy.id=${service_policy_id:osdu.partition["%s"].search}
validation.spatial.longitude.enableExtendedRange=true
redis.command.timeout=5
# To enable the full server path url in OpenAPI Swagger
api.server.fullUrl.enabled=${swaggerFullUrlEnabled:true}
\ No newline at end of file
package org.opengroup.osdu.search.swagger;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
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.customizers.OperationCustomizer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@OpenAPIDefinition(
info = @Info(
title = "${api.title}",
description = "${api.description}",
version = "${api.version}",
contact = @Contact(name = "${api.contact.name}", email = "${api.contact.email}"),
license = @License(name = "${api.license.name}", url = "${api.license.url}")),
security = @SecurityRequirement(name = "Authorization"),
tags = {
@Tag(name = "search-api", description = "Service endpoints to search data in datalake"),
@Tag(name = "health-check-api", description = "Health Check API"),
@Tag(name = "info", description = "Version info endpoint")
}
)
@SecurityScheme(name = "Authorization", scheme = "bearer", bearerFormat = "Authorization", type = SecuritySchemeType.HTTP)
@Configuration
@Profile("!noswagger")
public class SwaggerConfiguration {
@Value("${api.title}")
private String apiTitle;
@Value("${api.description}")
private String apiDescription;
@Value("${api.version}")
private String apiVersion;
@Value("${api.contact.name}")
private String contactName;
@Value("${api.contact.email}")
private String contactEmail;
@Value("${api.license.name}")
private String licenseName;
@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() {
SecurityScheme securityScheme = new SecurityScheme()
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("Authorization")
.in(SecurityScheme.In.HEADER)
.name("Authorization");
final String securitySchemeName = "Authorization";
SecurityRequirement securityRequirement = new SecurityRequirement().addList(securitySchemeName);
Components components = new Components().addSecuritySchemes(securitySchemeName, securityScheme);
OpenAPI openAPI = new OpenAPI()
.addSecurityItem(securityRequirement)
.components(components)
.info(apiInfo())
.tags(tags());
if(isServerFullUrlEnabled)
return openAPI;
return openAPI
.servers(Arrays.asList(new Server().url(apiServerUrl)));
}
private List<Tag> tags() {
List<Tag> tags = new ArrayList<>();
tags.add(new Tag().name("search-api").description("Service endpoints to search data in datalake"));
tags.add(new Tag().name("health-check-api").description("Health Check API"));
tags.add(new Tag().name("info").description("Version info endpoint"));
return tags;
}
private Info apiInfo() {
return new Info()
.title(apiTitle)
.description(apiDescription)
.version(apiVersion)
.license(new License().name(licenseName).url(licenseUrl))
.contact(new Contact().name(contactName).email(contactEmail));
}
@Bean
public OperationCustomizer customize() {
public OperationCustomizer operationCustomizer() {
return (operation, handlerMethod) -> {
Parameter dataPartitionId = new Parameter()
.name(DpsHeaders.DATA_PARTITION_ID)
......
......@@ -16,6 +16,7 @@ api.contact.name=OSDU Data Platform Team
api.contact.email=dps@OSDU.org
api.license.name=Apache 2.0
api.license.url=https://www.apache.org/licenses/LICENSE-2.0.html
api.server.url=${server.servlet.contextPath}
#Search API related properties
searchApi.queryRecords.summary=Queries the index for the input request criteria.
......
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