Skip to content
Snippets Groups Projects
Commit 0dc4e8d4 authored by Chad Leong's avatar Chad Leong :speech_balloon:
Browse files

Merge branch 'lach/master/fullApiUrl' into 'master'

Use full URL instead of relative path

See merge request !472
parents 9787bfa4 263eac40
No related branches found
No related tags found
1 merge request!472Use full URL instead of relative path
Pipeline #241345 failed
......@@ -63,6 +63,12 @@ server.port=8080
All the Swagger and OpenAPI related common properties are managed here [swagger.properties](./notification-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)
# new update
## AWS
......
package org.opengroup.osdu.notification.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.servers.Server;
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.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.springframework.beans.factory.annotation.Autowired;
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}")),
servers = @Server(url = "${api.server.url}"),
security = @SecurityRequirement(name = "Authorization"),
tags = {
@Tag(name = "pubsub-endpoint-api", description = "PubSub Endpoint API"),
@Tag(name = "health-checks-api", description = "Health Checks API"),
@Tag(name = "info", description = "Version info endpoint")
}
)
@SecurityScheme(name = "Authorization", scheme = "bearer", bearerFormat = "Authorization", type = SecuritySchemeType.HTTP)
@Configuration
@Profile("!noswagger")
public class SwaggerConfiguration {
@Autowired
private SwaggerConfigurationProperties configurationProperties;
@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 (configurationProperties.isApiServerFullUrlEnabled())
return openAPI;
return openAPI
.servers(Arrays.asList(new Server().url(configurationProperties.getApiServerUrl())));
}
private List<Tag> tags() {
List<Tag> tags = new ArrayList<>();
tags.add(new Tag().name("pubsub-endpoint-api").description("PubSub Endpoint API"));
tags.add(new Tag().name("health-checks-api").description("Health Checks API"));
tags.add(new Tag().name("info").description("Version info endpoint"));
return tags;
}
private Info apiInfo() {
return new Info()
.title(configurationProperties.getApiTitle())
.description(configurationProperties.getApiDescription())
.version(configurationProperties.getApiVersion())
.license(new License().name(configurationProperties.getApiLicenseName()).url(configurationProperties.getApiLicenseUrl()))
.contact(new Contact().name(configurationProperties.getApiContactName()).email(configurationProperties.getApiContactEmail()));
}
}
package org.opengroup.osdu.notification.swagger;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "swagger")
public class SwaggerConfigurationProperties {
private String apiTitle;
private String apiDescription;
private String apiVersion;
private String apiContactName;
private String apiContactEmail;
private String apiLicenseName;
private String apiLicenseUrl;
private String apiServerUrl;
private boolean apiServerFullUrlEnabled;
}
\ No newline at end of file
......@@ -9,14 +9,15 @@ springdoc.swagger-ui.displayOperationId=true
springdoc.api-docs.path=/api-docs
#OpenAPI 3.0 - Notification Service properties
api.title=Notification Service
api.description=The Notification service, with Register service, allow interested consumers to subscribe to data and metadata changes using a publisher/subscriber pattern
api.version=1.0.0
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.context-path}
swagger.apiTitle=Notification Service
swagger.apiDescription=The Notification service, with Register service, allow interested consumers to subscribe to data and metadata changes using a publisher/subscriber pattern
swagger.apiVersion=1.0.0
swagger.apiContactName=OSDU Data Platform Team
swagger.apiContactEmail=dps@OSDU.org
swagger.apiLicenseName=Apache 2.0
swagger.apiLicenseUrl=https://www.apache.org/licenses/LICENSE-2.0.html
swagger.apiServerUrl=${server.servlet.context-path:/api/notification/v1}
swagger.apiServerFullUrlEnabled=${api.server.fullUrl.enabled:false}
#PubSub Enpoint related properties
pubsubEndpointApi.recordChanged.summary=Record Changed
......
......@@ -89,4 +89,7 @@ management.server.port=8081
management.health.azure-key-vault.enabled=false
management.endpoints.web.exposure.include=${web_exposure_endpoints:health,info}
management.metrics.enable.all=${enable_metrics:false}
\ No newline at end of file
management.metrics.enable.all=${enable_metrics:false}
# To enable the full server path url in OpenAPI Swagger
api.server.fullUrl.enabled=${swaggerFullUrlEnabled:true}
\ No newline at end of file
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