Skip to content

Commit

Permalink
Initial support for spring-native:
Browse files Browse the repository at this point in the history
- Added property springdoc.enable-native-image-support to enable support of native images.
Add feature to display the swagger-ui by default in the root path using the property springdoc.swagger-ui.use-root-path
  • Loading branch information
bnasslahsen committed May 14, 2021
1 parent c065481 commit 60e458e
Show file tree
Hide file tree
Showing 25 changed files with 763 additions and 10 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<jaxb-impl.version>2.1</jaxb-impl.version>
<javax.jws-api.version>1.1</javax.jws-api.version>
<jjwt.version>0.9.1</jjwt.version>
<spring-native.version>0.9.2</spring-native.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -145,6 +146,11 @@
<version>${jjwt.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-native</artifactId>
<version>${spring-native.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down
11 changes: 11 additions & 0 deletions springdoc-openapi-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,19 @@
<artifactId>spring-boot-starter-actuator</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-native</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public final class Constants {
*/
public static final String SPRINGDOC_SWAGGER_UI_ENABLED = "springdoc.swagger-ui.enabled";

/**
* The constant SPRINGDOC_ENABLE_NATIVE_IMAGE_SUPPORT.
*/
public static final String SPRINGDOC_ENABLE_NATIVE_IMAGE_SUPPORT = "springdoc.enable-native-image-support";

/**
* The constant NULL.
*/
Expand Down Expand Up @@ -150,15 +155,30 @@ public final class Constants {
*/
public static final String CLASSPATH_RESOURCE_LOCATION = ResourceUtils.CLASSPATH_URL_PREFIX + "/META-INF/resources";

/**
* The constant SPRINGDOC_CONFIG_FILE.
*/
public static final String SPRINGDOC_CONFIG_FILE = ResourceUtils.CLASSPATH_URL_PREFIX + "springdoc.swagger-ui.config";

/**
* The constant SWAGGER_UI_VERSION.
*/
public static final String SWAGGER_UI_VERSION= "${springdoc.swagger-ui.version}";

/**
* The constant SWAGGER_UI_PREFIX.
*/
public static final String SWAGGER_UI_PREFIX = "/swagger-ui";

/**
* The constant INDEX_PAGE.
*/
public static final String INDEX_PAGE = "/index.html";

/**
* The constant SWAGGER_UI_URL.
*/
public static final String SWAGGER_UI_URL = SWAGGER_UI_PREFIX + "/index.html";
public static final String SWAGGER_UI_URL = SWAGGER_UI_PREFIX + INDEX_PAGE;

/**
* The constant SWAGGER_UI_OAUTH_REDIRECT_URL.
Expand Down Expand Up @@ -310,6 +330,11 @@ public final class Constants {
*/
public static final String SPRINGDOC_USE_MANAGEMENT_PORT = "springdoc.use-management-port";

/**
* The constant SPRINGDOC_USE_ROOT_PATH.
*/
public static final String SPRINGDOC_USE_ROOT_PATH ="springdoc.swagger-ui.use-root-path";

/**
* The constant DEFAULT_SWAGGER_UI_ACTUATOR_PATH.
*/
Expand All @@ -334,6 +359,7 @@ public final class Constants {
* The constant LINKS_SCHEMA_CUSTOMISER.
*/
public static final String LINKS_SCHEMA_CUSTOMISER = "linksSchemaCustomiser";

/**
* Instantiates a new Constants.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,29 @@ public class SpringDocConfigProperties {
*/
private boolean useManagementPort;

/**
* The Enable native support.
*/
protected boolean enableNativeImageSupport;

/**
* Is enable native image support boolean.
*
* @return the boolean
*/
public boolean isEnableNativeImageSupport() {
return enableNativeImageSupport;
}

/**
* Sets enable native image support.
*
* @param enableNativeImageSupport the enable native image support
*/
public void setEnableNativeImageSupport(boolean enableNativeImageSupport) {
this.enableNativeImageSupport = enableNativeImageSupport;
}

/**
* Is use management port boolean.
*
Expand Down Expand Up @@ -614,6 +637,7 @@ public boolean isPreLoadingEnabled() {

/**
* The type Model converters.
* @author bnasslashen
*/
public static class ModelConverters {

Expand Down Expand Up @@ -642,6 +666,7 @@ public void setDeprecatingConverter(DeprecatingConverter deprecatingConverter) {

/**
* The type Deprecating converter.
* @author bnasslashen
*/
public static class DeprecatingConverter {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package org.springdoc.core;

import io.swagger.v3.core.converter.ModelConverter;
import io.swagger.v3.core.converter.ModelConverters;
import io.swagger.v3.core.filter.SpecFilter;
import io.swagger.v3.core.jackson.ApiResponsesSerializer;
import io.swagger.v3.core.jackson.PathsSerializer;
import io.swagger.v3.core.jackson.mixin.ComponentsMixin;
import io.swagger.v3.core.jackson.mixin.ExtensionsMixin;
import io.swagger.v3.core.jackson.mixin.OpenAPIMixin;
import io.swagger.v3.core.jackson.mixin.OperationMixin;
import io.swagger.v3.core.jackson.mixin.SchemaMixin;
import io.swagger.v3.oas.annotations.ExternalDocumentation;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.callbacks.Callbacks;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.extensions.Extension;
import io.swagger.v3.oas.annotations.extensions.ExtensionProperty;
import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.links.Link;
import io.swagger.v3.oas.annotations.links.LinkParameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.DiscriminatorMapping;
import io.swagger.v3.oas.annotations.media.Encoding;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.OAuthFlow;
import io.swagger.v3.oas.annotations.security.OAuthFlows;
import io.swagger.v3.oas.annotations.security.OAuthScope;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.security.SecurityRequirements;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import io.swagger.v3.oas.annotations.security.SecuritySchemes;
import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.servers.ServerVariable;
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.PathItem;
import io.swagger.v3.oas.models.Paths;
import io.swagger.v3.oas.models.media.BooleanSchema;
import io.swagger.v3.oas.models.media.DateTimeSchema;
import io.swagger.v3.oas.models.media.Discriminator;
import io.swagger.v3.oas.models.media.FileSchema;
import io.swagger.v3.oas.models.media.IntegerSchema;
import io.swagger.v3.oas.models.media.MapSchema;
import io.swagger.v3.oas.models.media.MediaType;
import io.swagger.v3.oas.models.media.ObjectSchema;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.media.UUIDSchema;
import io.swagger.v3.oas.models.media.XML;
import io.swagger.v3.oas.models.security.Scopes;
import io.swagger.v3.oas.models.servers.ServerVariables;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.nativex.hint.AccessBits;
import org.springframework.nativex.hint.ProxyHint;
import org.springframework.nativex.hint.ResourceHint;
import org.springframework.nativex.hint.TypeHint;

import static org.springdoc.core.Constants.SPRINGDOC_ENABLE_NATIVE_IMAGE_SUPPORT;

@ProxyHint(typeNames = "javax.servlet.http.HttpServletRequest")

@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.RestController", "org.springframework.core.annotation.SynthesizedAnnotation" })
@ProxyHint(typeNames = { "org.springframework.stereotype.Controller", "org.springframework.core.annotation.SynthesizedAnnotation" })
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.SessionAttribute", "org.springframework.core.annotation.SynthesizedAnnotation" })
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.RestControllerAdvice", "org.springframework.core.annotation.SynthesizedAnnotation" })
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.ResponseStatus", "org.springframework.core.annotation.SynthesizedAnnotation" })
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.ResponseBody", "org.springframework.core.annotation.SynthesizedAnnotation" })
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.RequestPart", "org.springframework.core.annotation.SynthesizedAnnotation" })
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.RequestPart", "org.springframework.core.annotation.SynthesizedAnnotation" })
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.RequestMapping", "org.springframework.core.annotation.SynthesizedAnnotation" })
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.GetMapping", "org.springframework.core.annotation.SynthesizedAnnotation" })
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.PostMapping", "org.springframework.core.annotation.SynthesizedAnnotation" })
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.PutMapping", "org.springframework.core.annotation.SynthesizedAnnotation" })
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.PatchMapping", "org.springframework.core.annotation.SynthesizedAnnotation" })
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.DeleteMapping", "org.springframework.core.annotation.SynthesizedAnnotation" })
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.ControllerAdvice", "org.springframework.core.annotation.SynthesizedAnnotation" })
@ProxyHint(typeNames = {"org.springframework.web.bind.annotation.RequestParam", "org.springframework.core.annotation.SynthesizedAnnotation"})
@ProxyHint(typeNames = {"org.springframework.web.bind.annotation.RequestHeader", "org.springframework.core.annotation.SynthesizedAnnotation"})
@ProxyHint(typeNames = {"org.springframework.web.bind.annotation.RequestBody", "org.springframework.core.annotation.SynthesizedAnnotation"})
@ProxyHint(typeNames = {"org.springframework.web.bind.annotation.PathVariable", "org.springframework.core.annotation.SynthesizedAnnotation"})
@ProxyHint(typeNames = {"org.springframework.web.bind.annotation.ModelAttribute", "org.springframework.core.annotation.SynthesizedAnnotation"})
@ProxyHint(typeNames = {"org.springframework.stereotype.Controller", "org.springframework.core.annotation.SynthesizedAnnotation"})
@ProxyHint(typeNames = {"org.springframework.web.bind.annotation.ControllerAdvice", "org.springframework.core.annotation.SynthesizedAnnotation"})

@TypeHint(typeNames = { "org.springdoc.core.CacheOrGroupedOpenApiCondition$OnCacheDisabled", "io.swagger.v3.oas.models.parameters.Parameter$StyleEnum",
"io.swagger.v3.oas.models.security.SecurityScheme$In" , "io.swagger.v3.oas.models.security.SecurityScheme$Type",
"org.springdoc.core.CacheOrGroupedOpenApiCondition$OnMultipleOpenApiSupportCondition" }, access = AccessBits.ALL)

@TypeHint(types = { Constants.class, ModelConverter.class , ModelConverters.class})
@TypeHint(types = { SecurityRequirements.class, SecurityRequirement.class, ApiResponses.class, Callbacks.class, PropertySource.class, ExternalDocumentation.class, Hidden.class,
Operation.class, Parameter.class, Callbacks.class, Extension.class, ExtensionProperty.class, Header.class, Link.class, LinkParameter.class,
ArraySchema.class, Content.class, DiscriminatorMapping.class, Encoding.class, ExampleObject.class, Schema.class, RequestBody.class, ApiResponse.class,
Info.class, Server.class, ServerVariable.class, OpenAPIDefinition.class, Tag.class, SecuritySchemes.class, SecurityScheme.class, SecuritySchemeType.class,
OAuthFlow.class, OAuthFlows.class, OAuthScope.class })

@TypeHint(types = {
SpecFilter.class,
MediaType.class,
ApiResponsesSerializer.class,
PathsSerializer.class,
ComponentsMixin.class,
ExtensionsMixin.class,
OpenAPIMixin.class,
OperationMixin.class,
SchemaMixin.class,
Paths.class,
XML.class,
UUIDSchema.class,
PathItem.class,
ServerVariables.class,
OpenAPI.class,
Components.class,
StringSchema.class,
DateTimeSchema.class,
Discriminator.class,
BooleanSchema.class,
FileSchema.class,
IntegerSchema.class,
MapSchema.class,
ObjectSchema.class,
Scopes.class,
io.swagger.v3.oas.models.security.OAuthFlow.class, io.swagger.v3.oas.models.security.OAuthFlows.class,
io.swagger.v3.oas.models.security.SecurityScheme.class,
io.swagger.v3.oas.models.tags.Tag.class,
io.swagger.v3.oas.models.servers.ServerVariable.class,
io.swagger.v3.oas.models.servers.Server.class,
io.swagger.v3.oas.models.security.SecurityRequirement.class,
io.swagger.v3.oas.models.info.Info.class,
io.swagger.v3.oas.models.parameters.RequestBody.class,
io.swagger.v3.oas.models.media.Schema.class,
io.swagger.v3.oas.models.media.Content.class,
io.swagger.v3.oas.models.media.ArraySchema.class,
io.swagger.v3.oas.models.responses.ApiResponse.class,
io.swagger.v3.oas.models.responses.ApiResponses.class,
io.swagger.v3.oas.models.ExternalDocumentation.class,
io.swagger.v3.oas.models.links.LinkParameter.class,
io.swagger.v3.oas.models.links.Link.class,
io.swagger.v3.oas.models.parameters.Parameter.class,
io.swagger.v3.oas.models.Operation.class,
})

@ResourceHint(patterns = "springdoc.swagger-ui.config")
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(name = SPRINGDOC_ENABLE_NATIVE_IMAGE_SUPPORT, havingValue = "true")
public class SpringDocHints {}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@

import org.apache.commons.lang3.StringUtils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.PropertySource;
import org.springframework.util.CollectionUtils;

import static org.springdoc.core.Constants.SPRINGDOC_CONFIG_FILE;
import static org.springdoc.core.Constants.SPRINGDOC_SWAGGER_UI_ENABLED;
import static org.springdoc.core.Constants.SWAGGER_UI_OAUTH_REDIRECT_URL;
import static org.springdoc.core.Constants.SWAGGER_UI_VERSION;
import static org.springframework.util.AntPathMatcher.DEFAULT_PATH_SEPARATOR;

/**
Expand All @@ -49,6 +53,7 @@
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(name = SPRINGDOC_SWAGGER_UI_ENABLED, matchIfMissing = true)
@ConditionalOnBean(SpringDocConfiguration.class)
@PropertySource(SPRINGDOC_CONFIG_FILE)
public class SwaggerUiConfigParameters extends AbstractSwaggerUiConfigProperties {

/**
Expand Down Expand Up @@ -86,6 +91,12 @@ public class SwaggerUiConfigParameters extends AbstractSwaggerUiConfigProperties
*/
private final SwaggerUiConfigProperties swaggerUiConfig;

/**
* The Swagger ui version.
*/
@Value(SWAGGER_UI_VERSION)
private String swaggerUiVersion;

/**
* Instantiates a new Swagger ui config parameters.
*
Expand Down Expand Up @@ -121,6 +132,24 @@ public SwaggerUiConfigParameters(SwaggerUiConfigProperties swaggerUiConfig) {
this.persistAuthorization = swaggerUiConfig.getPersistAuthorization();
}

/**
* Gets swagger ui version.
*
* @return the swagger ui version
*/
public String getSwaggerUiVersion() {
return swaggerUiVersion;
}

/**
* Sets swagger ui version.
*
* @param swaggerUiVersion the swagger ui version
*/
public void setSwaggerUiVersion(String swaggerUiVersion) {
this.swaggerUiVersion = swaggerUiVersion;
}

/**
* Add group.
*
Expand Down
Loading

0 comments on commit 60e458e

Please sign in to comment.