Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48696d0374 | ||
|
|
77a5b81b2c | ||
|
|
c88c7851f9 | ||
|
|
b5510f5294 | ||
|
|
7854148cef | ||
|
|
6ce7b9dd5c |
2
.gitignore
vendored
2
.gitignore
vendored
@ -31,3 +31,5 @@ build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
.DS_Store/
|
||||
.DS_Store
|
||||
|
||||
2
pom.xml
2
pom.xml
@ -10,7 +10,7 @@
|
||||
</parent>
|
||||
<groupId>com.knecon.fforesight</groupId>
|
||||
<artifactId>swagger-commons</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<name>swagger-commons</name>
|
||||
<description>swagger-commons</description>
|
||||
<properties>
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
package com.knecon.fforesight.swaggercommons;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CorsConfigurer implements WebMvcConfigurer {
|
||||
|
||||
private final boolean corsEnabled;
|
||||
|
||||
|
||||
@Autowired
|
||||
public CorsConfigurer(@Value("${cors.enabled:false}") boolean corsEnabled) {
|
||||
|
||||
this.corsEnabled = corsEnabled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
|
||||
if (corsEnabled) {
|
||||
log.info("Cross Origin Requests are enabled !!!");
|
||||
registry.addMapping("/**").allowedOrigins("*").allowedMethods("GET", "POST", "DELETE", "PUT", "HEAD");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -40,6 +40,7 @@ import io.swagger.v3.oas.models.security.OAuthFlow;
|
||||
import io.swagger.v3.oas.models.security.OAuthFlows;
|
||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import lombok.Value;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@ -87,23 +88,6 @@ public class SpringDocConfiguration {
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(value = "cors.enabled", havingValue = "true")
|
||||
public WebMvcConfigurer corsConfigurer() {
|
||||
|
||||
return new WebMvcConfigurer() {
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
|
||||
log.info("Cross Origin Requests are enabled !!!");
|
||||
registry.addMapping("/**").allowedOrigins("*").allowedMethods("GET", "POST", "DELETE", "PUT", "HEAD");
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public CorsConfigurationSource corsConfigurationSource() {
|
||||
|
||||
@ -135,16 +119,18 @@ public class SpringDocConfiguration {
|
||||
|
||||
private OAuthFlows createOAuthFlows(SpringDocProperties springDocProperties) {
|
||||
|
||||
OAuthFlow flow = createAuthorizationCodeFlow(springDocProperties);
|
||||
var codeFlow = new OAuthFlow().authorizationUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/auth")
|
||||
.tokenUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/token");
|
||||
|
||||
return new OAuthFlows().authorizationCode(flow);
|
||||
}
|
||||
var flows = new OAuthFlows().authorizationCode(codeFlow);
|
||||
|
||||
if (springDocProperties.isShowImplicitFlow()) {
|
||||
var implicitFlow = new OAuthFlow().authorizationUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/auth")
|
||||
.tokenUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/token");
|
||||
flows.implicit(implicitFlow);
|
||||
}
|
||||
|
||||
private OAuthFlow createAuthorizationCodeFlow(SpringDocProperties springDocProperties) {
|
||||
|
||||
return new OAuthFlow().authorizationUrl(springDocProperties.getAuthServerUrl()+PROTOCOL_URL_FORMAT + "/auth")
|
||||
.tokenUrl(springDocProperties.getAuthServerUrl()+PROTOCOL_URL_FORMAT + "/token");
|
||||
return flows;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ public class SpringDocCustomDocsController {
|
||||
|
||||
private final SpringDocProperties springDocProperties;
|
||||
|
||||
@Value("${springdoc.api-docs.path:#{T(org.springdoc.core.Constants).DEFAULT_API_DOCS_URL}}")
|
||||
@Value("${springdoc.api-docs.path:#{T(org.springdoc.core.utils.Constants).DEFAULT_API_DOCS_URL}}")
|
||||
private String apiDocsUrl;
|
||||
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ public class SpringDocProperties {
|
||||
private String title ="Service Open API Documentation";
|
||||
private String description ="Service Open API Documentation";
|
||||
private String version = "1.0";
|
||||
private boolean showImplicitFlow = true;
|
||||
|
||||
private List<String> packagesToScan = new ArrayList<>();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user