Skip to content

Commit

Permalink
Merge pull request #26706 from mshima/openapi
Browse files Browse the repository at this point in the history
replace ModifyServersOpenApiFilter with ServerBaseUrlCustomizer
  • Loading branch information
DanielFran authored Jul 12, 2024
2 parents 42238ab + 7a62731 commit 5059d28
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 340 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,7 @@ spring:
args:
pattern: "'/services/'+serviceId.toLowerCase()+'/**'"
filters:
- name: RewritePath
args:
regexp: "'/services/' + serviceId.toLowerCase() + '/(?<remaining>.*)'"
replacement: "'/${remaining}'"
- StripPrefix=2
httpclient:
pool:
max-connections: 1000
Expand Down
11 changes: 10 additions & 1 deletion generators/spring-boot/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
*/
import { SERVER_MAIN_SRC_DIR, SERVER_MAIN_RES_DIR, SERVER_TEST_SRC_DIR, SERVER_TEST_RES_DIR } from '../generator-constants.js';
import { addSectionsCondition, mergeSections } from '../base/support/index.js';
import { moveToJavaPackageSrcDir, moveToJavaPackageTestDir, moveToSrcMainResourcesDir } from '../java/support/index.js';
import {
javaMainPackageTemplatesBlock,
moveToJavaPackageSrcDir,
moveToJavaPackageTestDir,
moveToSrcMainResourcesDir,
} from '../java/support/index.js';

const imperativeConfigFiles = {
imperativeFiles: [
Expand Down Expand Up @@ -347,6 +352,10 @@ export const baseServerFiles = {
},
],
serverMicroservice: [
javaMainPackageTemplatesBlock({
condition: generator => generator.applicationTypeMicroservice,
templates: ['config/SpringDocConfiguration.java'],
}),
{
condition: generator => generator.applicationTypeMicroservice,
path: SERVER_MAIN_RES_DIR,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<%#
Copyright 2013-2024 the original author or authors from the JHipster project.

This file is part of the JHipster project, see https://www.jhipster.tech/
for more information.

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 <%- packageName %>.config;

import java.util.List;

import org.springdoc.core.customizers.ServerBaseUrlCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SpringDocConfiguration {

@Bean
public ServerBaseUrlCustomizer serverBaseUrlRequestCustomizer() {
return (serverBaseUrl, request) -> {
List<String> forwardedPrefix = request.getHeaders().get("X-Forwarded-Prefix");
if (forwardedPrefix != null && forwardedPrefix.size() > 0) {
return forwardedPrefix.get(0);
}
return serverBaseUrl;
};
}
}
19 changes: 13 additions & 6 deletions generators/spring-cloud/generators/gateway/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/
import BaseApplicationGenerator from '../../../base-application/index.js';
import { javaMainPackageTemplatesBlock, javaTestPackageTemplatesBlock } from '../../../java/support/files.js';
import { javaMainPackageTemplatesBlock } from '../../../java/support/files.js';

const WAIT_TIMEOUT = 3 * 60000;

Expand Down Expand Up @@ -69,6 +69,17 @@ export default class GatewayGenerator extends BaseApplicationGenerator {

get writing() {
return this.asWritingTaskGroup({
cleanup({ control, application }) {
control.cleanupFiles({
'8.6.1': [
[
application.reactive && (application as any).serviceDiscoveryAny,
`${application.javaPackageSrcDir}/web/filter/ModifyServersOpenApiFilter.java`,
`${application.javaPackageTestDir}/web/filter/ModifyServersOpenApiFilterTest.java`,
],
],
});
},
async writing({ application }) {
await this.writeFiles({
blocks: [
Expand All @@ -78,11 +89,7 @@ export default class GatewayGenerator extends BaseApplicationGenerator {
}),
javaMainPackageTemplatesBlock({
condition: ctx => ctx.reactive && ctx.serviceDiscoveryAny,
templates: ['web/rest/vm/RouteVM.java', 'web/rest/GatewayResource.java', 'web/filter/ModifyServersOpenApiFilter.java'],
}),
javaTestPackageTemplatesBlock({
condition: ctx => ctx.reactive && ctx.serviceDiscoveryAny,
templates: ['web/filter/ModifyServersOpenApiFilterTest.java'],
templates: ['web/rest/vm/RouteVM.java', 'web/rest/GatewayResource.java'],
}),
],
context: application,
Expand Down

This file was deleted.

Loading

0 comments on commit 5059d28

Please sign in to comment.