From d456d537e57a38bbc86e603b9490641d5744def5 Mon Sep 17 00:00:00 2001 From: Dany Boisvert Date: Tue, 24 Oct 2023 13:03:17 -0400 Subject: [PATCH] Added security and components in swagger configuration. --- spotbugs.xml | 13 +++++++- .../swagger/SwaggerBundleConfiguration.java | 30 ++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/spotbugs.xml b/spotbugs.xml index 300363c9..0b9bd30b 100644 --- a/spotbugs.xml +++ b/spotbugs.xml @@ -15,4 +15,15 @@ limitations under the License. --> - + + + + + + + + + + + + diff --git a/src/main/java/io/federecio/dropwizard/swagger/SwaggerBundleConfiguration.java b/src/main/java/io/federecio/dropwizard/swagger/SwaggerBundleConfiguration.java index 1d6d840d..b3ed1858 100644 --- a/src/main/java/io/federecio/dropwizard/swagger/SwaggerBundleConfiguration.java +++ b/src/main/java/io/federecio/dropwizard/swagger/SwaggerBundleConfiguration.java @@ -32,10 +32,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Strings; import io.swagger.v3.oas.integration.SwaggerConfiguration; +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.servers.Server; import java.util.ArrayList; import java.util.Arrays; @@ -79,6 +81,10 @@ public class SwaggerBundleConfiguration implements Cloneable { @Nullable private List servers; + @Nullable private List security; + + @Nullable private Components components; + @Nullable private String customJavascript; private SwaggerViewConfiguration swaggerViewConfiguration = new SwaggerViewConfiguration(); @@ -317,6 +323,28 @@ public void setServers(List servers) { this.servers = servers != null ? new ArrayList<>(servers) : null; } + @Nullable + @JsonProperty + public List getSecurity() { + return security != null ? new ArrayList<>(security) : null; + } + + @JsonProperty + public void setSecurity(List security) { + this.security = security != null ? new ArrayList<>(security) : null; + } + + @Nullable + @JsonProperty + public Components getComponents() { + return components; + } + + @JsonProperty + public void setComponents(Components components) { + this.components = components; + } + @Nullable @JsonProperty public String getCustomJavascript() { @@ -358,7 +386,7 @@ public SwaggerConfiguration build() { final String[] exclusions = {SwaggerResource.PATH}; return new SwaggerConfiguration() - .openAPI(oas.info(info).servers(servers)) + .openAPI(oas.info(info).servers(servers).security(security).components(components)) .prettyPrint(prettyPrint) .readAllResources(readAllResources) .ignoredRoutes(Arrays.stream(exclusions).collect(Collectors.toSet()))