Skip to content

Commit ddf15cd

Browse files
committed
Modify local cases to be based on language tag so that it can support messages from differences countries. i.e. en_GB vs en_US
1 parent 6b7f5f3 commit ddf15cd

File tree

6 files changed

+75
-3
lines changed

6 files changed

+75
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ public Map<String, Object> getControllerAdviceMap() {
729729
* @return the cached open api
730730
*/
731731
public OpenAPI getCachedOpenAPI(Locale locale) {
732-
return cachedOpenAPI.get(locale.getLanguage());
732+
return cachedOpenAPI.get(locale.toLanguageTag());
733733
}
734734

735735
/**
@@ -739,7 +739,7 @@ public OpenAPI getCachedOpenAPI(Locale locale) {
739739
* @param cachedOpenAPI the cached open api
740740
*/
741741
public void setCachedOpenAPI(OpenAPI cachedOpenAPI, Locale locale) {
742-
this.cachedOpenAPI.put(locale.getLanguage(), cachedOpenAPI);
742+
this.cachedOpenAPI.put(locale.toLanguageTag(), cachedOpenAPI);
743743
}
744744

745745
/**

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app171/SpringDocApp171Test.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public void testApp() throws Exception {
4848
Locale.setDefault(Locale.US);
4949
testApp(Locale.US);
5050
testApp(Locale.FRANCE);
51+
testApp(Locale.UK);
5152
}
5253

5354
private void testApp(Locale locale) throws Exception {
@@ -57,7 +58,7 @@ private void testApp(Locale locale) throws Exception {
5758
mockMvc.perform(get(Constants.DEFAULT_API_DOCS_URL).locale(locale).header(HttpHeaders.ACCEPT_LANGUAGE, locale.toLanguageTag())).andExpect(status().isOk())
5859
.andExpect(jsonPath("$.openapi", is("3.0.1"))).andReturn();
5960
String result = mockMvcResult.getResponse().getContentAsString();
60-
String expected = getContent("results/app" + testNumber + "-" + locale.getLanguage() + ".json");
61+
String expected = getContent("results/app" + testNumber + "-" + locale.toLanguageTag() + ".json");
6162
assertEquals(expected, result, true);
6263
}
6364
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
greeting=Hello! Welcome to our website![EN_GB]
2+
lang.change=Change the language[EN_GB]
3+
lang.eng=English[EN_GB]
4+
lang.fr=French[EN_GB]
5+
mySample=toto[EN_GB]
6+
test=This is a test message[EN_GB]
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
"tags": [
14+
{
15+
"name": "Hello! Welcome to our website![EN_GB]",
16+
"description": "This is a test message[EN_GB]"
17+
}
18+
],
19+
"paths": {
20+
"/test": {
21+
"get": {
22+
"tags": [
23+
"Hello! Welcome to our website![EN_GB]"
24+
],
25+
"operationId": "demo2",
26+
"responses": {
27+
"200": {
28+
"description": "OK",
29+
"content": {
30+
"*/*": {
31+
"schema": {
32+
"type": "string"
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}
39+
},
40+
"/persons": {
41+
"get": {
42+
"tags": [
43+
"Hello! Welcome to our website![EN_GB]"
44+
],
45+
"operationId": "persons",
46+
"parameters": [
47+
{
48+
"name": "name",
49+
"in": "query",
50+
"required": true,
51+
"schema": {
52+
"type": "string"
53+
}
54+
}
55+
],
56+
"responses": {
57+
"200": {
58+
"description": "OK"
59+
}
60+
}
61+
}
62+
}
63+
},
64+
"components": {}
65+
}

0 commit comments

Comments
 (0)