Skip to content

Commit a7276d9

Browse files
committed
improve native support
1 parent 60e458e commit a7276d9

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/core/Constants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ public final class Constants {
101101
public static final String SPRINGDOC_SWAGGER_UI_ENABLED = "springdoc.swagger-ui.enabled";
102102

103103
/**
104-
* The constant SPRINGDOC_ENABLE_NATIVE_IMAGE_SUPPORT.
104+
* The constant SPRING_NATIVE_LISTENER.
105105
*/
106-
public static final String SPRINGDOC_ENABLE_NATIVE_IMAGE_SUPPORT = "springdoc.enable-native-image-support";
106+
public static final String SPRING_NATIVE_LISTENER = "org.springframework.nativex.NativeListener";
107107

108108
/**
109109
* The constant NULL.

springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocConfigProperties.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import java.util.ArrayList;
2424
import java.util.List;
25+
import java.util.Optional;
2526

2627
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2728
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -165,15 +166,24 @@ public class SpringDocConfigProperties {
165166
/**
166167
* The Enable native support.
167168
*/
168-
protected boolean enableNativeImageSupport;
169+
protected Boolean enableNativeImageSupport;
170+
171+
private final Optional<SpringDocHints> springDocHintsOptional;
172+
173+
public SpringDocConfigProperties(Optional<SpringDocHints> springDocHintsOptional) {
174+
this.springDocHintsOptional = springDocHintsOptional;
175+
}
169176

170177
/**
171178
* Is enable native image support boolean.
172179
*
173180
* @return the boolean
174181
*/
175182
public boolean isEnableNativeImageSupport() {
176-
return enableNativeImageSupport;
183+
if (enableNativeImageSupport != null)
184+
return enableNativeImageSupport;
185+
else
186+
return springDocHintsOptional.isPresent();
177187
}
178188

179189
/**
@@ -947,7 +957,7 @@ public GroupConfig() {
947957
*/
948958
public GroupConfig(String group, List<String> pathsToMatch, List<String> packagesToScan,
949959
List<String> packagesToExclude, List<String> pathsToExclude,
950-
List<String> producesToMatch,List<String> consumesToMatch,List<String> headersToMatch) {
960+
List<String> producesToMatch, List<String> consumesToMatch, List<String> headersToMatch) {
951961
this.pathsToMatch = pathsToMatch;
952962
this.pathsToExclude = pathsToExclude;
953963
this.packagesToExclude = packagesToExclude;

springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocHints.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,17 @@
6060
import io.swagger.v3.oas.models.security.Scopes;
6161
import io.swagger.v3.oas.models.servers.ServerVariables;
6262

63-
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
63+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
6464
import org.springframework.context.annotation.Configuration;
6565
import org.springframework.context.annotation.PropertySource;
6666
import org.springframework.nativex.hint.AccessBits;
6767
import org.springframework.nativex.hint.ProxyHint;
6868
import org.springframework.nativex.hint.ResourceHint;
6969
import org.springframework.nativex.hint.TypeHint;
7070

71-
import static org.springdoc.core.Constants.SPRINGDOC_ENABLE_NATIVE_IMAGE_SUPPORT;
71+
import static org.springdoc.core.Constants.SPRING_NATIVE_LISTENER;
7272

7373
@ProxyHint(typeNames = "javax.servlet.http.HttpServletRequest")
74-
7574
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.RestController", "org.springframework.core.annotation.SynthesizedAnnotation" })
7675
@ProxyHint(typeNames = { "org.springframework.stereotype.Controller", "org.springframework.core.annotation.SynthesizedAnnotation" })
7776
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.SessionAttribute", "org.springframework.core.annotation.SynthesizedAnnotation" })
@@ -87,25 +86,23 @@
8786
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.PatchMapping", "org.springframework.core.annotation.SynthesizedAnnotation" })
8887
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.DeleteMapping", "org.springframework.core.annotation.SynthesizedAnnotation" })
8988
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.ControllerAdvice", "org.springframework.core.annotation.SynthesizedAnnotation" })
90-
@ProxyHint(typeNames = {"org.springframework.web.bind.annotation.RequestParam", "org.springframework.core.annotation.SynthesizedAnnotation"})
91-
@ProxyHint(typeNames = {"org.springframework.web.bind.annotation.RequestHeader", "org.springframework.core.annotation.SynthesizedAnnotation"})
92-
@ProxyHint(typeNames = {"org.springframework.web.bind.annotation.RequestBody", "org.springframework.core.annotation.SynthesizedAnnotation"})
93-
@ProxyHint(typeNames = {"org.springframework.web.bind.annotation.PathVariable", "org.springframework.core.annotation.SynthesizedAnnotation"})
94-
@ProxyHint(typeNames = {"org.springframework.web.bind.annotation.ModelAttribute", "org.springframework.core.annotation.SynthesizedAnnotation"})
95-
@ProxyHint(typeNames = {"org.springframework.stereotype.Controller", "org.springframework.core.annotation.SynthesizedAnnotation"})
96-
@ProxyHint(typeNames = {"org.springframework.web.bind.annotation.ControllerAdvice", "org.springframework.core.annotation.SynthesizedAnnotation"})
89+
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.RequestParam", "org.springframework.core.annotation.SynthesizedAnnotation" })
90+
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.RequestHeader", "org.springframework.core.annotation.SynthesizedAnnotation" })
91+
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.RequestBody", "org.springframework.core.annotation.SynthesizedAnnotation" })
92+
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.PathVariable", "org.springframework.core.annotation.SynthesizedAnnotation" })
93+
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.ModelAttribute", "org.springframework.core.annotation.SynthesizedAnnotation" })
94+
@ProxyHint(typeNames = { "org.springframework.stereotype.Controller", "org.springframework.core.annotation.SynthesizedAnnotation" })
95+
@ProxyHint(typeNames = { "org.springframework.web.bind.annotation.ControllerAdvice", "org.springframework.core.annotation.SynthesizedAnnotation" })
9796

9897
@TypeHint(typeNames = { "org.springdoc.core.CacheOrGroupedOpenApiCondition$OnCacheDisabled", "io.swagger.v3.oas.models.parameters.Parameter$StyleEnum",
99-
"io.swagger.v3.oas.models.security.SecurityScheme$In" , "io.swagger.v3.oas.models.security.SecurityScheme$Type",
98+
"io.swagger.v3.oas.models.security.SecurityScheme$In", "io.swagger.v3.oas.models.security.SecurityScheme$Type",
10099
"org.springdoc.core.CacheOrGroupedOpenApiCondition$OnMultipleOpenApiSupportCondition" }, access = AccessBits.ALL)
101-
102-
@TypeHint(types = { Constants.class, ModelConverter.class , ModelConverters.class})
100+
@TypeHint(types = { Constants.class, ModelConverter.class, ModelConverters.class })
103101
@TypeHint(types = { SecurityRequirements.class, SecurityRequirement.class, ApiResponses.class, Callbacks.class, PropertySource.class, ExternalDocumentation.class, Hidden.class,
104102
Operation.class, Parameter.class, Callbacks.class, Extension.class, ExtensionProperty.class, Header.class, Link.class, LinkParameter.class,
105103
ArraySchema.class, Content.class, DiscriminatorMapping.class, Encoding.class, ExampleObject.class, Schema.class, RequestBody.class, ApiResponse.class,
106-
Info.class, Server.class, ServerVariable.class, OpenAPIDefinition.class, Tag.class, SecuritySchemes.class, SecurityScheme.class, SecuritySchemeType.class,
104+
Info.class, Server.class, ServerVariable.class, OpenAPIDefinition.class, Tag.class, SecuritySchemes.class, SecurityScheme.class, SecuritySchemeType.class,
107105
OAuthFlow.class, OAuthFlows.class, OAuthScope.class })
108-
109106
@TypeHint(types = {
110107
SpecFilter.class,
111108
MediaType.class,
@@ -153,6 +150,7 @@
153150
})
154151

155152
@ResourceHint(patterns = "springdoc.swagger-ui.config")
153+
156154
@Configuration(proxyBeanMethods = false)
157-
@ConditionalOnProperty(name = SPRINGDOC_ENABLE_NATIVE_IMAGE_SUPPORT, havingValue = "true")
155+
@ConditionalOnClass(name = SPRING_NATIVE_LISTENER)
158156
public class SpringDocHints {}

0 commit comments

Comments
 (0)