Skip to content

Commit 335e7b8

Browse files
committed
Endpoint parameters are translated even if they should not. fixes #1331
1 parent abf8f4e commit 335e7b8

File tree

7 files changed

+146
-10
lines changed

7 files changed

+146
-10
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/core/PropertyResolverUtils.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public class PropertyResolverUtils {
4545
*/
4646
private final MessageSource messageSource;
4747

48+
/**
49+
* The Spring doc config properties.
50+
*/
51+
private final SpringDocConfigProperties springDocConfigProperties;
52+
4853
/**
4954
* The constant LOGGER.
5055
*/
@@ -55,10 +60,12 @@ public class PropertyResolverUtils {
5560
*
5661
* @param factory the factory
5762
* @param messageSource the message source
63+
* @param springDocConfigProperties the spring doc config properties
5864
*/
59-
public PropertyResolverUtils(ConfigurableBeanFactory factory, MessageSource messageSource) {
65+
public PropertyResolverUtils(ConfigurableBeanFactory factory, MessageSource messageSource, SpringDocConfigProperties springDocConfigProperties) {
6066
this.factory = factory;
6167
this.messageSource = messageSource;
68+
this.springDocConfigProperties = springDocConfigProperties;
6269
}
6370

6471
/**
@@ -69,12 +76,13 @@ public PropertyResolverUtils(ConfigurableBeanFactory factory, MessageSource mess
6976
* @return the string
7077
*/
7178
public String resolve(String parameterProperty, Locale locale) {
72-
try {
73-
return messageSource.getMessage(parameterProperty, null, locale);
74-
}
75-
catch (NoSuchMessageException ex) {
76-
LOGGER.trace(ex.getMessage());
77-
}
79+
if (!springDocConfigProperties.isDisableI18n())
80+
try {
81+
return messageSource.getMessage(parameterProperty, null, locale);
82+
}
83+
catch (NoSuchMessageException ex) {
84+
LOGGER.trace(ex.getMessage());
85+
}
7886
try {
7987
return factory.resolveEmbeddedValue(parameterProperty);
8088
}

springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocConfigProperties.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ public class SpringDocConfigProperties {
167167
*/
168168
protected Boolean enableNativeImageSupport;
169169

170+
/**
171+
* The Disable i18n.
172+
*/
173+
private boolean disableI18n;
174+
170175
/**
171176
* Gets enable native image support.
172177
*
@@ -626,6 +631,24 @@ public void setPreLoadingEnabled(boolean preLoadingEnabled) {
626631
this.preLoadingEnabled = preLoadingEnabled;
627632
}
628633

634+
/**
635+
* Is disable i 18 n boolean.
636+
*
637+
* @return the boolean
638+
*/
639+
public boolean isDisableI18n() {
640+
return disableI18n;
641+
}
642+
643+
/**
644+
* Sets disable i 18 n.
645+
*
646+
* @param disableI18n the disable i 18 n
647+
*/
648+
public void setDisableI18n(boolean disableI18n) {
649+
this.disableI18n = disableI18n;
650+
}
651+
629652
/**
630653
* Is pre loading enabled boolean.
631654
*

springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,12 @@ OperationService operationBuilder(GenericParameterService parameterBuilder, Requ
253253
*
254254
* @param factory the factory
255255
* @param messageSource the message source
256+
* @param springDocConfigProperties the spring doc config properties
256257
* @return the property resolver utils
257258
*/
258259
@Bean
259-
PropertyResolverUtils propertyResolverUtils(ConfigurableBeanFactory factory, MessageSource messageSource) {
260-
return new PropertyResolverUtils(factory, messageSource);
260+
PropertyResolverUtils propertyResolverUtils(ConfigurableBeanFactory factory, MessageSource messageSource, SpringDocConfigProperties springDocConfigProperties) {
261+
return new PropertyResolverUtils(factory, messageSource,springDocConfigProperties);
261262
}
262263

263264
/**
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package test.org.springdoc.api.app167;
2+
3+
import io.swagger.v3.oas.annotations.Parameter;
4+
5+
import org.springframework.http.ResponseEntity;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
/**
11+
* @author bnasslahsen
12+
*/
13+
@RestController
14+
@RequestMapping("/api")
15+
public class HelloController {
16+
17+
@GetMapping("/sample1")
18+
public ResponseEntity sample1(@Parameter(name="mySample") String mySample) {
19+
throw new UnsupportedOperationException("the body is not relevant now");
20+
}
21+
22+
23+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
*
3+
* * Copyright 2019-2021 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app167;
20+
21+
import test.org.springdoc.api.AbstractSpringDocTest;
22+
23+
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
import org.springframework.test.context.TestPropertySource;
25+
26+
27+
@TestPropertySource(properties = "springdoc.disable-i18n=true")
28+
public class SpringDocApp167Test extends AbstractSpringDocTest {
29+
30+
@SpringBootApplication
31+
static class SpringDocTestApp {
32+
}
33+
34+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
greeting=Hello! Welcome to our website!
22
lang.change=Change the language
33
lang.eng=English
4-
lang.fr=French
4+
lang.fr=French
5+
mySample=toto
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/api/sample1": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "sample1",
20+
"parameters": [
21+
{
22+
"name": "mySample",
23+
"in": "query",
24+
"required": true,
25+
"schema": {
26+
"type": "string"
27+
}
28+
}
29+
],
30+
"responses": {
31+
"200": {
32+
"description": "OK",
33+
"content": {
34+
"*/*": {
35+
"schema": {
36+
"type": "string"
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
}
44+
},
45+
"components": {}
46+
}

0 commit comments

Comments
 (0)