Skip to content

Commit efceecd

Browse files
committed
override-with-generic-response shouldn't shallow copy fixes #1962
1 parent abf6816 commit efceecd

File tree

7 files changed

+162
-59
lines changed

7 files changed

+162
-59
lines changed

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ individual is representing the project or its community.
3535

3636
This Code of Conduct is adapted from the
3737
[Contributor Covenant](https://contributor-covenant.org), version 1.3.0, available at
38-
contributor-covenant.org/version/1/3/0/](https://contributor-covenant.org/version/1/3/0/[) and [spring-boot
38+
[contributor-covenant.org/version/1/3/0/](https://contributor-covenant.org/version/1/3/0/) and [spring-boot
3939
Contributor Code of Conduct](https://github.com/spring-projects/spring-boot/blob/master/CODE_OF_CONDUCT.adoc)

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ Pivotal)
8080
* Automatically deploys swagger-ui to a Spring Boot 2.x application
8181
* Documentation will be available in HTML format, using the
8282
official [swagger-ui jars](https://github.com/swagger-api/swagger-ui.git).
83-
* The Swagger UI page should then be available at http://server:
84-
port/context-path/swagger-ui.html and the OpenAPI description will be available at the
83+
* The Swagger UI page should then be available at
84+
http://server:port/context-path/swagger-ui.html and the OpenAPI description will be available at the
8585
following url for json format: http://server:port/context-path/v3/api-docs
8686
* `server`: The server name or IP
8787
* `port`: The server port
@@ -125,8 +125,7 @@ springdoc.swagger-ui.path=/swagger-ui.html
125125

126126
## Integration of the library in a Spring Boot 2.x.x project without the swagger-ui:
127127

128-
* Documentation will be available at the following url for json format: http://server:
129-
port/context-path/v3/api-docs
128+
* Documentation will be available at the following url for json format: http://server:port/context-path/v3/api-docs
130129
* `server`: The server name or IP
131130
* `port`: The server port
132131
* `context-path`: The context path of the application
@@ -220,7 +219,7 @@ its [contributors](https://github.com/springdoc/springdoc-openapi/graphs/contrib
220219
<img src="https://contrib.rocks/image?repo=springdoc/springdoc-openapi" width="50%"/>
221220
</a>
222221

223-
Thanks you all for your support!
222+
Thank you all for your support!
224223

225224
## Additional Support
226225

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.lang.reflect.Type;
3030
import java.util.ArrayList;
3131
import java.util.Arrays;
32+
import java.util.Collection;
3233
import java.util.HashSet;
3334
import java.util.LinkedHashMap;
3435
import java.util.List;
@@ -41,6 +42,8 @@
4142
import java.util.stream.Stream;
4243

4344
import com.fasterxml.jackson.annotation.JsonView;
45+
import com.fasterxml.jackson.core.JsonProcessingException;
46+
import com.fasterxml.jackson.databind.ObjectMapper;
4447
import io.swagger.v3.core.util.AnnotationsUtils;
4548
import io.swagger.v3.oas.models.Components;
4649
import io.swagger.v3.oas.models.Operation;
@@ -50,7 +53,11 @@
5053
import io.swagger.v3.oas.models.responses.ApiResponses;
5154
import org.apache.commons.lang3.ArrayUtils;
5255
import org.apache.commons.lang3.StringUtils;
56+
import org.slf4j.Logger;
57+
import org.slf4j.LoggerFactory;
58+
import org.springdoc.core.converters.AdditionalModelsConverter;
5359
import org.springdoc.core.providers.JavadocProvider;
60+
import org.springdoc.core.providers.ObjectMapperProvider;
5461

5562
import org.springframework.core.MethodParameter;
5663
import org.springframework.core.ResolvableType;
@@ -74,6 +81,7 @@
7481

7582
/**
7683
* The type Generic response builder.
84+
*
7785
* @author bnasslahsen
7886
*/
7987
public class GenericResponseService {
@@ -118,6 +126,11 @@ public class GenericResponseService {
118126
*/
119127
private final List<ControllerAdviceInfo> controllerAdviceInfos = new ArrayList<>();
120128

129+
/**
130+
* The constant LOGGER.
131+
*/
132+
private static final Logger LOGGER = LoggerFactory.getLogger(GenericResponseService.class);
133+
121134
/**
122135
* Instantiates a new Generic response builder.
123136
*
@@ -242,9 +255,9 @@ private Map<String, ApiResponse> filterAndEnrichGenericMapResponseByDeclarations
242255
JavadocProvider javadocProvider = operationService.getJavadocProvider();
243256
for (Map.Entry<String, ApiResponse> genericResponse : genericMapResponse.entrySet()) {
244257
Map<String, Object> extensions = genericResponse.getValue().getExtensions();
245-
Set<Class<?>> genericExceptions = (Set<Class<?>>) extensions.get(EXTENSION_EXCEPTION_CLASSES);
258+
Collection<String> genericExceptions = (Collection<String>) extensions.get(EXTENSION_EXCEPTION_CLASSES);
246259
for (Class<?> declaredException : handlerMethod.getMethod().getExceptionTypes()) {
247-
if (genericExceptions.contains(declaredException)) {
260+
if (genericExceptions.contains(declaredException.getName())) {
248261
Map<String, String> javadocThrows = javadocProvider.getMethodJavadocThrows(handlerMethod.getMethod());
249262
String description = javadocThrows.get(declaredException.getName());
250263
if (description == null)
@@ -675,7 +688,16 @@ private synchronized Map<String, ApiResponse> getGenericMapResponse(Class<?> bea
675688
});
676689
}
677690

678-
return genericApiResponseMap;
691+
LinkedHashMap<String, ApiResponse> genericApiResponsesClone;
692+
try {
693+
ObjectMapper objectMapper = ObjectMapperProvider.createJson(springDocConfigProperties);
694+
genericApiResponsesClone = objectMapper.readValue(objectMapper.writeValueAsString(genericApiResponseMap), ApiResponses.class);
695+
return genericApiResponsesClone;
696+
}
697+
catch (JsonProcessingException e) {
698+
LOGGER.warn("Json Processing Exception occurred: {}", e.getMessage());
699+
return genericApiResponseMap;
700+
}
679701
}
680702

681703
/**

springdoc-openapi-javadoc/src/test/resources/results/app162.json

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
}
3939
],
4040
"responses": {
41-
"400": {
42-
"description": "the <code>@throws NonUniqueResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
41+
"404": {
42+
"description": "the <code>@throws NoResultException</code> javadoc for the <code>#find(String)</code> method",
4343
"content": {
4444
"*/*": {
4545
"schema": {
@@ -48,11 +48,11 @@
4848
}
4949
},
5050
"x-exception-class": [
51-
"test.org.springdoc.api.app162.exception.NonUniqueResultException"
51+
"test.org.springdoc.api.app162.exception.NoResultException"
5252
]
5353
},
54-
"404": {
55-
"description": "the <code>@throws NoResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
54+
"400": {
55+
"description": "the <code>return</code> javadoc for the <code>#handleNonUniqueResultException(NonUniqueResultException)</code> method",
5656
"content": {
5757
"*/*": {
5858
"schema": {
@@ -61,7 +61,7 @@
6161
}
6262
},
6363
"x-exception-class": [
64-
"test.org.springdoc.api.app162.exception.NoResultException"
64+
"test.org.springdoc.api.app162.exception.NonUniqueResultException"
6565
]
6666
},
6767
"200": {
@@ -105,8 +105,8 @@
105105
"required": true
106106
},
107107
"responses": {
108-
"400": {
109-
"description": "the <code>@throws NonUniqueResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
108+
"404": {
109+
"description": "the <code>return</code> javadoc for the <code>#handleNotFoundException(NoResultException)</code> method",
110110
"content": {
111111
"*/*": {
112112
"schema": {
@@ -115,11 +115,11 @@
115115
}
116116
},
117117
"x-exception-class": [
118-
"test.org.springdoc.api.app162.exception.NonUniqueResultException"
118+
"test.org.springdoc.api.app162.exception.NoResultException"
119119
]
120120
},
121-
"404": {
122-
"description": "the <code>@throws NoResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
121+
"400": {
122+
"description": "the <code>return</code> javadoc for the <code>#handleNonUniqueResultException(NonUniqueResultException)</code> method",
123123
"content": {
124124
"*/*": {
125125
"schema": {
@@ -128,7 +128,7 @@
128128
}
129129
},
130130
"x-exception-class": [
131-
"test.org.springdoc.api.app162.exception.NoResultException"
131+
"test.org.springdoc.api.app162.exception.NonUniqueResultException"
132132
]
133133
},
134134
"200": {
@@ -153,8 +153,8 @@
153153
"description": "This is the list method's javadoc.\n The method's signature: <code>#list()</code>",
154154
"operationId": "list",
155155
"responses": {
156-
"400": {
157-
"description": "the <code>@throws NonUniqueResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
156+
"404": {
157+
"description": "the <code>return</code> javadoc for the <code>#handleNotFoundException(NoResultException)</code> method",
158158
"content": {
159159
"*/*": {
160160
"schema": {
@@ -163,11 +163,11 @@
163163
}
164164
},
165165
"x-exception-class": [
166-
"test.org.springdoc.api.app162.exception.NonUniqueResultException"
166+
"test.org.springdoc.api.app162.exception.NoResultException"
167167
]
168168
},
169-
"404": {
170-
"description": "the <code>@throws NoResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
169+
"400": {
170+
"description": "the <code>return</code> javadoc for the <code>#handleNonUniqueResultException(NonUniqueResultException)</code> method",
171171
"content": {
172172
"*/*": {
173173
"schema": {
@@ -176,7 +176,7 @@
176176
}
177177
},
178178
"x-exception-class": [
179-
"test.org.springdoc.api.app162.exception.NoResultException"
179+
"test.org.springdoc.api.app162.exception.NonUniqueResultException"
180180
]
181181
},
182182
"200": {
@@ -213,8 +213,8 @@
213213
"required": true
214214
},
215215
"responses": {
216-
"400": {
217-
"description": "the <code>@throws NonUniqueResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
216+
"404": {
217+
"description": "the <code>return</code> javadoc for the <code>#handleNotFoundException(NoResultException)</code> method",
218218
"content": {
219219
"*/*": {
220220
"schema": {
@@ -223,11 +223,11 @@
223223
}
224224
},
225225
"x-exception-class": [
226-
"test.org.springdoc.api.app162.exception.NonUniqueResultException"
226+
"test.org.springdoc.api.app162.exception.NoResultException"
227227
]
228228
},
229-
"404": {
230-
"description": "the <code>@throws NoResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
229+
"400": {
230+
"description": "the <code>return</code> javadoc for the <code>#handleNonUniqueResultException(NonUniqueResultException)</code> method",
231231
"content": {
232232
"*/*": {
233233
"schema": {
@@ -236,7 +236,7 @@
236236
}
237237
},
238238
"x-exception-class": [
239-
"test.org.springdoc.api.app162.exception.NoResultException"
239+
"test.org.springdoc.api.app162.exception.NonUniqueResultException"
240240
]
241241
},
242242
"201": {
@@ -272,8 +272,8 @@
272272
}
273273
],
274274
"responses": {
275-
"400": {
276-
"description": "the <code>@throws NonUniqueResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
275+
"404": {
276+
"description": "the <code>@throws NoResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
277277
"content": {
278278
"*/*": {
279279
"schema": {
@@ -282,11 +282,11 @@
282282
}
283283
},
284284
"x-exception-class": [
285-
"test.org.springdoc.api.app162.exception.NonUniqueResultException"
285+
"test.org.springdoc.api.app162.exception.NoResultException"
286286
]
287287
},
288-
"404": {
289-
"description": "the <code>@throws NoResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
288+
"400": {
289+
"description": "the <code>@throws NonUniqueResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
290290
"content": {
291291
"*/*": {
292292
"schema": {
@@ -295,7 +295,7 @@
295295
}
296296
},
297297
"x-exception-class": [
298-
"test.org.springdoc.api.app162.exception.NoResultException"
298+
"test.org.springdoc.api.app162.exception.NonUniqueResultException"
299299
]
300300
},
301301
"200": {

springdoc-openapi-javadoc/src/test/resources/results/app163.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
"required": true
4949
},
5050
"responses": {
51-
"400": {
52-
"description": "the <code>@throws NonUniqueResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
51+
"404": {
52+
"description": "the <code>return</code> javadoc for the <code>#handleNotFoundException(NoResultException)</code> method",
5353
"content": {
5454
"*/*": {
5555
"schema": {
@@ -58,11 +58,11 @@
5858
}
5959
},
6060
"x-exception-class": [
61-
"test.org.springdoc.api.app163.exception.NonUniqueResultException"
61+
"test.org.springdoc.api.app163.exception.NoResultException"
6262
]
6363
},
64-
"404": {
65-
"description": "the <code>@throws NoResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
64+
"400": {
65+
"description": "the <code>return</code> javadoc for the <code>#handleNonUniqueResultException(NonUniqueResultException)</code> method",
6666
"content": {
6767
"*/*": {
6868
"schema": {
@@ -71,7 +71,7 @@
7171
}
7272
},
7373
"x-exception-class": [
74-
"test.org.springdoc.api.app163.exception.NoResultException"
74+
"test.org.springdoc.api.app163.exception.NonUniqueResultException"
7575
]
7676
},
7777
"200": {
@@ -107,8 +107,8 @@
107107
"required": true
108108
},
109109
"responses": {
110-
"400": {
111-
"description": "the <code>@throws NonUniqueResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
110+
"404": {
111+
"description": "the <code>return</code> javadoc for the <code>#handleNotFoundException(NoResultException)</code> method",
112112
"content": {
113113
"*/*": {
114114
"schema": {
@@ -117,11 +117,11 @@
117117
}
118118
},
119119
"x-exception-class": [
120-
"test.org.springdoc.api.app163.exception.NonUniqueResultException"
120+
"test.org.springdoc.api.app163.exception.NoResultException"
121121
]
122122
},
123-
"404": {
124-
"description": "the <code>@throws NoResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
123+
"400": {
124+
"description": "the <code>return</code> javadoc for the <code>#handleNonUniqueResultException(NonUniqueResultException)</code> method",
125125
"content": {
126126
"*/*": {
127127
"schema": {
@@ -130,7 +130,7 @@
130130
}
131131
},
132132
"x-exception-class": [
133-
"test.org.springdoc.api.app163.exception.NoResultException"
133+
"test.org.springdoc.api.app163.exception.NonUniqueResultException"
134134
]
135135
},
136136
"default": {
@@ -166,9 +166,6 @@
166166
}
167167
],
168168
"responses": {
169-
"400": {
170-
"description": "API Response 400 for #findStartsBy(prefix)"
171-
},
172169
"404": {
173170
"description": "the <code>@throws NoResultException</code> javadoc for the <code>#findStartsBy(String)</code> method",
174171
"content": {
@@ -182,6 +179,9 @@
182179
"test.org.springdoc.api.app163.exception.NoResultException"
183180
]
184181
},
182+
"400": {
183+
"description": "API Response 400 for #findStartsBy(prefix)"
184+
},
185185
"200": {
186186
"description": "API Response 200 for #findStartsBy(prefix)",
187187
"content": {

springdoc-openapi-webmvc-core/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22
<modelVersion>4.0.0</modelVersion>
3-
<properties>
4-
<maven.compiler.source>17</maven.compiler.source>
5-
<maven.compiler.target>17</maven.compiler.target>
6-
</properties>
73
<parent>
84
<groupId>org.springdoc</groupId>
95
<artifactId>springdoc-openapi</artifactId>

0 commit comments

Comments
 (0)