Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace ModifyServersOpenApiFilter with ServerBaseUrlCustomizer #26706

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -355,6 +360,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
Loading