This repository was archived by the owner on May 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 591
feature: springdoc integration #4836
Closed
klopfdreh
wants to merge
11
commits into
spring-attic:2.9.x
from
klopfdreh:feature/springdoc_integration
Closed
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f43b844
feat: springdoc integration
klopfdreh ddab034
fix: checkstyle issues
klopfdreh e211e64
fix: checkstyle issues
klopfdreh 765f209
feat: springdoc review changes
klopfdreh 6341ce4
fix: springdoc minor adjustments to defauls yml
klopfdreh 514352c
fix: springdoc changes second review
klopfdreh 12609c3
fix: removed unused imports
klopfdreh 8c339ff
feat: SpringDoc minor refactoring and docs
klopfdreh b8817a3
fix: SpringDoc checkstyle issues
klopfdreh 70f78be
fix: third review changes
klopfdreh 3a7b684
fix: small adjustments because of review
klopfdreh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...ingframework/cloud/dataflow/server/config/DataFlowSwaggerApiEnvironmentPostProcessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2016-2018 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.cloud.dataflow.server.config; | ||
|
||
import java.util.Optional; | ||
import java.util.Properties; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.env.EnvironmentPostProcessor; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
import org.springframework.core.env.PropertiesPropertySource; | ||
|
||
public class DataFlowSwaggerApiEnvironmentPostProcessor implements EnvironmentPostProcessor { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(DataFlowSwaggerApiEnvironmentPostProcessor.class); | ||
onobc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private static final String SPRINGDOC_API_DOCS_ENABLED_KEY = "springdoc.api-docs.enabled"; | ||
private static final String SWAGGER_UI_ENABLED_KEY = "springdoc.swagger-ui.enabled"; | ||
|
||
@Override | ||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { | ||
|
||
Optional<Object> apiDocsEnabledOptional = environment.getPropertySources().stream() | ||
.filter(p -> p.containsProperty(SPRINGDOC_API_DOCS_ENABLED_KEY)) | ||
.map(p -> p.getProperty(SPRINGDOC_API_DOCS_ENABLED_KEY)) | ||
.findAny(); | ||
// Apply default properties | ||
if (!apiDocsEnabledOptional.isPresent()) { | ||
LOG.debug("Disable springdoc {} feature, because it is not set.", SPRINGDOC_API_DOCS_ENABLED_KEY); | ||
applyDisableFeaturePropertySources(environment, "apiDocsDisabled", SPRINGDOC_API_DOCS_ENABLED_KEY); | ||
} | ||
|
||
Optional<Object> swaggerUiEnabledOptional = environment.getPropertySources().stream() | ||
.filter(p -> p.containsProperty(SWAGGER_UI_ENABLED_KEY)) | ||
.map(p -> p.getProperty(SWAGGER_UI_ENABLED_KEY)) | ||
.findAny(); | ||
if (!(swaggerUiEnabledOptional.isPresent())) { | ||
LOG.debug("Disable springdoc {} feature, because it is not set.", SWAGGER_UI_ENABLED_KEY); | ||
applyDisableFeaturePropertySources(environment, "swaggerUiDisabled", SWAGGER_UI_ENABLED_KEY); | ||
} | ||
} | ||
|
||
private void applyDisableFeaturePropertySources(ConfigurableEnvironment environment, String name, String key) { | ||
Properties properties = new Properties(); | ||
properties.setProperty(key, "false"); | ||
PropertiesPropertySource propertiesPropertySource = new PropertiesPropertySource(name, properties); | ||
environment.getPropertySources().addLast(propertiesPropertySource); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...springframework/cloud/dataflow/server/support/DataFlowSwaggerApiDocsJsonDecodeFilter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2016-2018 the original author or authors. | ||
klopfdreh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.cloud.dataflow.server.support; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import javax.servlet.Filter; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletOutputStream; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletRequestWrapper; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.commons.text.StringEscapeUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.util.ContentCachingResponseWrapper; | ||
|
||
klopfdreh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Component | ||
@Order | ||
klopfdreh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public class DataFlowSwaggerApiDocsJsonDecodeFilter implements Filter { | ||
klopfdreh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private static final Logger LOG = LoggerFactory.getLogger(DataFlowSwaggerApiDocsJsonDecodeFilter.class); | ||
|
||
@Value("${springdoc.api-docs.path:/v3/api-docs}") | ||
klopfdreh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private String apiDocsPath; | ||
|
||
|
||
@Value("${springdoc.swagger-ui.configUrl:/v3/api-docs/swagger-config}") | ||
private String swaggerUiConfig; | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
final HttpServletRequestWrapper httpServletRequestWrapper = new HttpServletRequestWrapper((HttpServletRequest) request); | ||
final ContentCachingResponseWrapper httpServletResponseWrapper = new ContentCachingResponseWrapper((HttpServletResponse) response); | ||
|
||
String apiDocsPathContext = StringUtils.substringBeforeLast(apiDocsPath, "/"); | ||
String swaggerUiConfigContext = StringUtils.substringBeforeLast(swaggerUiConfig, "/"); | ||
if (httpServletRequestWrapper.getServletPath().startsWith(apiDocsPathContext) || | ||
httpServletRequestWrapper.getServletPath().startsWith(swaggerUiConfigContext)) { | ||
// if api-docs path is requested, use wrapper classes, so that the body gets cached. | ||
chain.doFilter(httpServletRequestWrapper, httpServletResponseWrapper); | ||
|
||
ServletOutputStream outputStream = httpServletResponseWrapper.getResponse().getOutputStream(); | ||
|
||
LOG.debug("Request for Swagger api-docs detected - unescaping json content."); | ||
String content = new String(httpServletResponseWrapper.getContentAsByteArray(), StandardCharsets.UTF_8); | ||
content = StringUtils.stripStart(content, "\""); | ||
content = StringUtils.stripEnd(content, "\""); | ||
if (LOG.isTraceEnabled()) { | ||
LOG.trace("Using decoded JSON for serving api-docs: {}", content); | ||
} | ||
outputStream.write(StringEscapeUtils.unescapeJson(content).getBytes(StandardCharsets.UTF_8)); | ||
} else { | ||
// all other scdf related api calls do nothing. | ||
chain.doFilter(request, response); | ||
} | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
spring-cloud-dataflow-server-core/src/main/resources/META-INF/spring.factories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
org.springframework.boot.env.EnvironmentPostProcessor=\ | ||
org.springframework.cloud.dataflow.server.config.DefaultEnvironmentPostProcessor,\ | ||
org.springframework.cloud.dataflow.server.config.MetricsReplicationEnvironmentPostProcessor | ||
org.springframework.cloud.dataflow.server.config.MetricsReplicationEnvironmentPostProcessor,\ | ||
org.springframework.cloud.dataflow.server.config.DataFlowSwaggerApiEnvironmentPostProcessor | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
org.springframework.cloud.dataflow.server.config.DataFlowServerAutoConfiguration,\ | ||
org.springframework.cloud.dataflow.server.config.DataFlowControllerAutoConfiguration |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.