Compare commits
No commits in common. "main" and "dev" have entirely different histories.
2
.gitignore
vendored
2
.gitignore
vendored
@ -31,5 +31,3 @@ build/
|
|||||||
|
|
||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
||||||
.DS_Store/
|
|
||||||
.DS_Store
|
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@ -10,7 +10,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<groupId>com.knecon.fforesight</groupId>
|
<groupId>com.knecon.fforesight</groupId>
|
||||||
<artifactId>swagger-commons</artifactId>
|
<artifactId>swagger-commons</artifactId>
|
||||||
<version>0.1-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<name>swagger-commons</name>
|
<name>swagger-commons</name>
|
||||||
<description>swagger-commons</description>
|
<description>swagger-commons</description>
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@ -1,35 +0,0 @@
|
|||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -3,6 +3,7 @@ package com.knecon.fforesight.swaggercommons;
|
|||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|||||||
@ -40,7 +40,6 @@ import io.swagger.v3.oas.models.security.OAuthFlow;
|
|||||||
import io.swagger.v3.oas.models.security.OAuthFlows;
|
import io.swagger.v3.oas.models.security.OAuthFlows;
|
||||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||||
import lombok.Value;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -88,6 +87,23 @@ 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
|
@Bean
|
||||||
public CorsConfigurationSource corsConfigurationSource() {
|
public CorsConfigurationSource corsConfigurationSource() {
|
||||||
|
|
||||||
@ -119,18 +135,16 @@ public class SpringDocConfiguration {
|
|||||||
|
|
||||||
private OAuthFlows createOAuthFlows(SpringDocProperties springDocProperties) {
|
private OAuthFlows createOAuthFlows(SpringDocProperties springDocProperties) {
|
||||||
|
|
||||||
var codeFlow = new OAuthFlow().authorizationUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/auth")
|
OAuthFlow flow = createAuthorizationCodeFlow(springDocProperties);
|
||||||
.tokenUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/token");
|
|
||||||
|
|
||||||
var flows = new OAuthFlows().authorizationCode(codeFlow);
|
return new OAuthFlows().authorizationCode(flow);
|
||||||
|
}
|
||||||
|
|
||||||
if (springDocProperties.isShowImplicitFlow()) {
|
|
||||||
var implicitFlow = new OAuthFlow().authorizationUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/auth")
|
|
||||||
.tokenUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/token");
|
|
||||||
flows.implicit(implicitFlow);
|
|
||||||
}
|
|
||||||
|
|
||||||
return flows;
|
private OAuthFlow createAuthorizationCodeFlow(SpringDocProperties springDocProperties) {
|
||||||
|
|
||||||
|
return new OAuthFlow().authorizationUrl(springDocProperties.getAuthServerUrl()+PROTOCOL_URL_FORMAT + "/auth")
|
||||||
|
.tokenUrl(springDocProperties.getAuthServerUrl()+PROTOCOL_URL_FORMAT + "/token");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ public class SpringDocCustomDocsController {
|
|||||||
|
|
||||||
private final SpringDocProperties springDocProperties;
|
private final SpringDocProperties springDocProperties;
|
||||||
|
|
||||||
@Value("${springdoc.api-docs.path:#{T(org.springdoc.core.utils.Constants).DEFAULT_API_DOCS_URL}}")
|
@Value("${springdoc.api-docs.path:#{T(org.springdoc.core.Constants).DEFAULT_API_DOCS_URL}}")
|
||||||
private String apiDocsUrl;
|
private String apiDocsUrl;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,6 @@ public class SpringDocProperties {
|
|||||||
private String title ="Service Open API Documentation";
|
private String title ="Service Open API Documentation";
|
||||||
private String description ="Service Open API Documentation";
|
private String description ="Service Open API Documentation";
|
||||||
private String version = "1.0";
|
private String version = "1.0";
|
||||||
private boolean showImplicitFlow = true;
|
|
||||||
|
|
||||||
private List<String> packagesToScan = new ArrayList<>();
|
private List<String> packagesToScan = new ArrayList<>();
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
@EnableWebMvc
|
@EnableWebMvc
|
||||||
public class SpringDocTenantMvcConfigurer implements WebMvcConfigurer {
|
public class SpringDocTenantMvcConfigurer implements WebMvcConfigurer {
|
||||||
|
|
||||||
@Value("${springdoc.api-docs.path:#{T(org.springdoc.core.utils.Constants).DEFAULT_API_DOCS_URL}}")
|
@Value("${springdoc.api-docs.path:#{T(org.springdoc.core.Constants).DEFAULT_API_DOCS_URL}}")
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
private final SpringDocProperties springDocProperties;
|
private final SpringDocProperties springDocProperties;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user