Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAPI - added more mappings between smallrye and quarkus config #16120

Merged
merged 1 commit into from Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions docs/src/main/asciidoc/openapi-swaggerui.adoc
Expand Up @@ -306,17 +306,17 @@ For example, add the following to your `application.properties`:

[source, properties]
----
mp.openapi.extensions.smallrye.info.title=Example API
%dev.mp.openapi.extensions.smallrye.info.title=Example API (development)
%test.mp.openapi.extensions.smallrye.info.title=Example API (test)
mp.openapi.extensions.smallrye.info.version=1.0.1
mp.openapi.extensions.smallrye.info.description=Just an example service
mp.openapi.extensions.smallrye.info.termsOfService=Your terms here
mp.openapi.extensions.smallrye.info.contact.email=techsupport@example.com
mp.openapi.extensions.smallrye.info.contact.name=Example API Support
mp.openapi.extensions.smallrye.info.contact.url=http://exampleurl.com/contact
mp.openapi.extensions.smallrye.info.license.name=Apache 2.0
mp.openapi.extensions.smallrye.info.license.url=https://www.apache.org/licenses/LICENSE-2.0.html
quarkus.smallrye-openapi.info-title=Example API
%dev.quarkus.smallrye-openapi.info-title=Example API (development)
%test.quarkus.smallrye-openapi.info-title=Example API (test)
quarkus.smallrye-openapi.info-version=1.0.1
quarkus.smallrye-openapi.info-description=Just an example service
quarkus.smallrye-openapi.info-terms-of-service=Your terms here
quarkus.smallrye-openapi.info-contact-email=techsupport@example.com
quarkus.smallrye-openapi.info-contact-name=Example API Support
quarkus.smallrye-openapi.info-contact-url=http://exampleurl.com/contact
quarkus.smallrye-openapi.info-license-name=Apache 2.0
quarkus.smallrye-openapi.info-license-url=https://www.apache.org/licenses/LICENSE-2.0.html
----

This will give you similar information as the `@OpenAPIDefinition` example above.
Expand Down
Expand Up @@ -80,10 +80,82 @@ public final class SmallRyeOpenApiConfig {
@ConfigItem
public Optional<String> oauth2ImplicitTokenUrl;

/**
* Override the openapi version in the Schema document
*/
@ConfigItem
public Optional<String> openApiVersion;

/**
* Set the title in Info tag in the Schema document
*/
@ConfigItem
public Optional<String> infoTitle;

/**
* Set the version in Info tag in the Schema document
*/
@ConfigItem
public Optional<String> infoVersion;

/**
* Set the description in Info tag in the Schema document
*/
@ConfigItem
public Optional<String> infoDescription;

/**
* Set the terms of the service in Info tag in the Schema document
*/
@ConfigItem
public Optional<String> infoTermsOfService;

/**
* Set the contact email in Info tag in the Schema document
*/
@ConfigItem
public Optional<String> infoContactEmail;

/**
* Set the contact name in Info tag in the Schema document
*/
@ConfigItem
public Optional<String> infoContactName;

/**
* Set the contact url in Info tag in the Schema document
*/
@ConfigItem
public Optional<String> infoContactUrl;

/**
* Set the license name in Info tag in the Schema document
*/
@ConfigItem
public Optional<String> infoLicenseName;

/**
* Set the license url in Info tag in the Schema document
*/
@ConfigItem
public Optional<String> infoLicenseUrl;

/**
* Set the strategy to automatically create an operation Id
*/
@ConfigItem
public Optional<OperationIdStrategy> operationIdStrategy;

public enum SecurityScheme {
basic,
jwt,
oidc,
oauth2Implicit
}

public enum OperationIdStrategy {
METHOD,
CLASS_METHOD,
PACKAGE_CLASS_METHOD
}
}
Expand Up @@ -51,6 +51,7 @@
import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.deployment.builditem.SystemPropertyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyBuildItem;
Expand Down Expand Up @@ -126,6 +127,58 @@ CapabilityBuildItem capability() {
return new CapabilityBuildItem(Capability.SMALLRYE_OPENAPI);
}

@BuildStep
void mapConfig(SmallRyeOpenApiConfig openApiConfig,
BuildProducer<SystemPropertyBuildItem> systemProperties) {

if (openApiConfig.openApiVersion.isPresent()) {
systemProperties.produce(new SystemPropertyBuildItem(
io.smallrye.openapi.api.constants.OpenApiConstants.OPEN_API_VERSION, openApiConfig.openApiVersion.get()));
}
if (openApiConfig.infoTitle.isPresent()) {
systemProperties.produce(new SystemPropertyBuildItem(io.smallrye.openapi.api.constants.OpenApiConstants.INFO_TITLE,
openApiConfig.infoTitle.get()));
}
if (openApiConfig.infoVersion.isPresent()) {
systemProperties.produce(new SystemPropertyBuildItem(
io.smallrye.openapi.api.constants.OpenApiConstants.INFO_VERSION, openApiConfig.infoVersion.get()));
}
if (openApiConfig.infoDescription.isPresent()) {
systemProperties.produce(new SystemPropertyBuildItem(
io.smallrye.openapi.api.constants.OpenApiConstants.INFO_DESCRIPTION, openApiConfig.infoDescription.get()));
}
if (openApiConfig.infoTermsOfService.isPresent()) {
systemProperties.produce(new SystemPropertyBuildItem(io.smallrye.openapi.api.constants.OpenApiConstants.INFO_TERMS,
openApiConfig.infoTermsOfService.get()));
}
if (openApiConfig.infoContactEmail.isPresent()) {
systemProperties
.produce(new SystemPropertyBuildItem(io.smallrye.openapi.api.constants.OpenApiConstants.INFO_CONTACT_EMAIL,
openApiConfig.infoContactEmail.get()));
}
if (openApiConfig.infoContactName.isPresent()) {
systemProperties.produce(new SystemPropertyBuildItem(
io.smallrye.openapi.api.constants.OpenApiConstants.INFO_CONTACT_NAME, openApiConfig.infoContactName.get()));
}
if (openApiConfig.infoContactUrl.isPresent()) {
systemProperties.produce(new SystemPropertyBuildItem(
io.smallrye.openapi.api.constants.OpenApiConstants.INFO_CONTACT_URL, openApiConfig.infoContactUrl.get()));
}
if (openApiConfig.infoLicenseName.isPresent()) {
systemProperties.produce(new SystemPropertyBuildItem(
io.smallrye.openapi.api.constants.OpenApiConstants.INFO_LICENSE_NAME, openApiConfig.infoLicenseName.get()));
}
if (openApiConfig.infoLicenseUrl.isPresent()) {
systemProperties.produce(new SystemPropertyBuildItem(
io.smallrye.openapi.api.constants.OpenApiConstants.INFO_LICENSE_URL, openApiConfig.infoLicenseUrl.get()));
}
if (openApiConfig.operationIdStrategy.isPresent()) {
systemProperties.produce(
new SystemPropertyBuildItem(io.smallrye.openapi.api.constants.OpenApiConstants.OPERATION_ID_STRAGEGY,
openApiConfig.operationIdStrategy.get().name()));
}
}

@BuildStep
void contributeClassesToIndex(BuildProducer<AdditionalIndexedClassesBuildItem> additionalIndexedClasses) {
// contribute additional JDK classes to the index, because SmallRye OpenAPI will check if some
Expand Down
Expand Up @@ -18,7 +18,9 @@ public class OpenApiWithConfigTestCase {
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(OpenApiResource.class, ResourceBean.class)
.addAsManifestResource("test-openapi.yaml", "openapi.yaml")
.addAsResource(new StringAsset("mp.openapi.scan.disable=true\nmp.openapi.servers=https://api.acme.org/"),
.addAsResource(new StringAsset("mp.openapi.scan.disable=true"
+ "\nmp.openapi.servers=https://api.acme.org/"
+ "\nquarkus.smallrye-openapi.info-title=Bla"),
"application.properties"));

@Test
Expand All @@ -28,11 +30,13 @@ public void testOpenAPI() {
.then()
.header("Content-Type", "application/json;charset=UTF-8")
.body("openapi", Matchers.startsWith("3.0"))
.body("info.title", Matchers.equalTo("Test OpenAPI"))
.body("info.title", Matchers.equalTo("Bla"))
.body("info.description", Matchers.equalTo("Some description"))
.body("info.version", Matchers.equalTo("4.2"))
.body("servers[0].url", Matchers.equalTo("https://api.acme.org/"))
.body("paths", Matchers.hasKey("/openapi"))
.body("paths", Matchers.not(Matchers.hasKey("/resource")));

System.clearProperty(io.smallrye.openapi.api.constants.OpenApiConstants.INFO_TITLE);
}
}
}
Expand Up @@ -31,4 +31,4 @@ public void testOpenApiResteasyPathHttpRootDefaultPath() {
.body("info.title", Matchers.equalTo("Generated API"))
.body("paths", Matchers.hasKey("/http-root-path/resteasy-path/resource"));
}
}
}
Expand Up @@ -30,4 +30,4 @@ public void testOpenApiResteasyPath() {
.body("info.title", Matchers.equalTo("Generated API"))
.body("paths", Matchers.hasKey("/foo/bar/resource"));
}
}
}