Skip to content

Commit 296beed

Browse files
committed
Provide a better consistency for parameters and responses. Fixes #2888
1 parent 567d724 commit 296beed

File tree

19 files changed

+136
-127
lines changed

19 files changed

+136
-127
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/customizers/QuerydslPredicateOperationCustomizer.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.ArrayList;
3333
import java.util.Arrays;
3434
import java.util.Collections;
35+
import java.util.LinkedHashSet;
3536
import java.util.List;
3637
import java.util.Map;
3738
import java.util.Optional;
@@ -112,7 +113,7 @@ public Operation customize(Operation operation, HandlerMethod handlerMethod) {
112113

113114
QuerydslBindings bindings = extractQdslBindings(predicate);
114115

115-
Set<String> fieldsToAdd = Arrays.stream(predicate.root().getDeclaredFields()).filter(field -> !Modifier.isStatic(field.getModifiers())).map(Field::getName).collect(Collectors.toSet());
116+
Set<String> fieldsToAdd = Arrays.stream(predicate.root().getDeclaredFields()).filter(field -> !Modifier.isStatic(field.getModifiers())).map(Field::getName).collect(Collectors.toCollection(LinkedHashSet::new));
116117

117118
Map<String, Object> pathSpecMap = getPathSpec(bindings, "pathSpecs");
118119
//remove blacklisted fields

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/data/DataRestRouterOperationService.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import java.util.Arrays;
3030
import java.util.LinkedHashMap;
31+
import java.util.LinkedHashSet;
3132
import java.util.List;
3233
import java.util.Locale;
3334
import java.util.Map;
@@ -178,15 +179,15 @@ private void buildRouterOperationList(List<RouterOperation> routerOperationList,
178179
if (andCheck(resourceMetadata != null, !controllerType.equals(ControllerType.SEARCH))) {
179180
HttpMethods httpMethodsItem = resourceMetadata.getSupportedHttpMethods().getMethodsFor(ResourceType.ITEM);
180181
requestMethodsItem = requestMethods.stream().filter(requestMethod -> httpMethodsItem.contains(HttpMethod.valueOf(requestMethod.toString())))
181-
.collect(Collectors.toSet());
182+
.collect(Collectors.toCollection(LinkedHashSet::new));
182183

183184
buildRouterOperation(routerOperationList, resourceMetadata, dataRestRepository, openAPI, path,
184185
subPath, controllerType, methodResourceMapping, requestMappingInfo, handlerMethod, requestMethodsItem, ResourceType.ITEM);
185186

186187
if (!ControllerType.PROPERTY.equals(controllerType)) {
187188
HttpMethods httpMethodsCollection = resourceMetadata.getSupportedHttpMethods().getMethodsFor(ResourceType.COLLECTION);
188189
requestMethodsCollection = requestMethods.stream().filter(requestMethod -> httpMethodsCollection.contains(HttpMethod.valueOf(requestMethod.toString())))
189-
.collect(Collectors.toSet());
190+
.collect(Collectors.toCollection(LinkedHashSet::new));
190191

191192
buildRouterOperation(routerOperationList, resourceMetadata, dataRestRepository, openAPI, path,
192193
subPath, controllerType, methodResourceMapping, requestMappingInfo, handlerMethod, requestMethodsCollection, ResourceType.COLLECTION);

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/extractor/MethodParameterPojoExtractor.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.Arrays;
4141
import java.util.Collection;
4242
import java.util.HashSet;
43+
import java.util.LinkedHashSet;
4344
import java.util.List;
4445
import java.util.Map;
4546
import java.util.Objects;
@@ -361,7 +362,7 @@ private static boolean isNullable(Annotation[] fieldAnnotations) {
361362
Collection<String> annotationSimpleNames = Arrays.stream(fieldAnnotations)
362363
.map(Annotation::annotationType)
363364
.map(Class::getSimpleName)
364-
.collect(Collectors.toSet());
365+
.collect(Collectors.toCollection(LinkedHashSet::new));
365366
return !hasNotNullAnnotation(annotationSimpleNames);
366367
}
367368
}

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/properties/SwaggerUiConfigProperties.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
package org.springdoc.core.properties;
2828

2929
import java.io.IOException;
30+
import java.util.LinkedHashSet;
3031
import java.util.Properties;
3132
import java.util.Set;
3233
import java.util.stream.Collectors;
@@ -239,7 +240,7 @@ public void setSyntaxHighlight(SyntaxHighlight syntaxHighlight) {
239240
* @return the set
240241
*/
241242
public Set<SwaggerUrl> cloneUrls() {
242-
return this.urls.stream().map(swaggerUrl -> new SwaggerUrl(swaggerUrl.getName(), swaggerUrl.getUrl(), swaggerUrl.getDisplayName())).collect(Collectors.toSet());
243+
return this.urls.stream().map(swaggerUrl -> new SwaggerUrl(swaggerUrl.getName(), swaggerUrl.getUrl(), swaggerUrl.getDisplayName())).collect(Collectors.toCollection(LinkedHashSet::new));
243244
}
244245

245246
/**

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Collection;
3737
import java.util.HashSet;
3838
import java.util.LinkedHashMap;
39+
import java.util.LinkedHashSet;
3940
import java.util.List;
4041
import java.util.Locale;
4142
import java.util.Map;
@@ -489,12 +490,12 @@ public Set<io.swagger.v3.oas.annotations.responses.ApiResponse> getApiResponses(
489490
Set<io.swagger.v3.oas.annotations.responses.ApiResponses> apiResponsesDoc = AnnotatedElementUtils
490491
.findAllMergedAnnotations(method, io.swagger.v3.oas.annotations.responses.ApiResponses.class);
491492
Set<io.swagger.v3.oas.annotations.responses.ApiResponse> responses = apiResponsesDoc.stream()
492-
.flatMap(x -> Stream.of(x.value())).collect(Collectors.toSet());
493+
.flatMap(x -> Stream.of(x.value())).collect(Collectors.toCollection(LinkedHashSet::new));
493494

494495
Set<io.swagger.v3.oas.annotations.responses.ApiResponses> apiResponsesDocDeclaringClass = AnnotatedElementUtils
495496
.findAllMergedAnnotations(declaringClass, io.swagger.v3.oas.annotations.responses.ApiResponses.class);
496497
responses.addAll(
497-
apiResponsesDocDeclaringClass.stream().flatMap(x -> Stream.of(x.value())).collect(Collectors.toSet()));
498+
apiResponsesDocDeclaringClass.stream().flatMap(x -> Stream.of(x.value())).collect(Collectors.toCollection(LinkedHashSet::new)));
498499

499500
Set<io.swagger.v3.oas.annotations.responses.ApiResponse> apiResponseDoc = AnnotatedElementUtils
500501
.findMergedRepeatableAnnotations(method, io.swagger.v3.oas.annotations.responses.ApiResponse.class);

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.HashMap;
3434
import java.util.HashSet;
3535
import java.util.LinkedHashMap;
36+
import java.util.LinkedHashSet;
3637
import java.util.List;
3738
import java.util.Locale;
3839
import java.util.Map;
@@ -336,7 +337,7 @@ public Operation buildTags(HandlerMethod handlerMethod, Operation operation, Ope
336337
if (!CollectionUtils.isEmpty(tagsStr))
337338
tagsStr = tagsStr.stream()
338339
.map(str -> propertyResolverUtils.resolve(str, locale))
339-
.collect(Collectors.toSet());
340+
.collect(Collectors.toCollection(LinkedHashSet::new));
340341

341342
if (springdocTags.containsKey(handlerMethod)) {
342343
io.swagger.v3.oas.models.tags.Tag tag = springdocTags.get(handlerMethod);
@@ -407,10 +408,10 @@ private void buildTagsFromMethod(Method method, Set<io.swagger.v3.oas.models.tag
407408
Set<Tags> tagsSet = AnnotatedElementUtils
408409
.findAllMergedAnnotations(method, Tags.class);
409410
Set<Tag> methodTags = tagsSet.stream()
410-
.flatMap(x -> Stream.of(x.value())).collect(Collectors.toSet());
411+
.flatMap(x -> Stream.of(x.value())).collect(Collectors.toCollection(LinkedHashSet::new));
411412
methodTags.addAll(AnnotatedElementUtils.findAllMergedAnnotations(method, Tag.class));
412413
if (!CollectionUtils.isEmpty(methodTags)) {
413-
tagsStr.addAll(methodTags.stream().map(tag -> propertyResolverUtils.resolve(tag.name(), locale)).collect(Collectors.toSet()));
414+
tagsStr.addAll(methodTags.stream().map(tag -> propertyResolverUtils.resolve(tag.name(), locale)).collect(Collectors.toCollection(LinkedHashSet::new)));
414415
List<Tag> allTags = new ArrayList<>(methodTags);
415416
addTags(allTags, tags, locale);
416417
}
@@ -450,10 +451,10 @@ public void buildTagsFromClass(Class<?> beanType, Set<io.swagger.v3.oas.models.t
450451
Set<Tags> tagsSet = AnnotatedElementUtils
451452
.findAllMergedAnnotations(beanType, Tags.class);
452453
Set<Tag> classTags = tagsSet.stream()
453-
.flatMap(x -> Stream.of(x.value())).collect(Collectors.toSet());
454+
.flatMap(x -> Stream.of(x.value())).collect(Collectors.toCollection(LinkedHashSet::new));
454455
classTags.addAll(AnnotatedElementUtils.findAllMergedAnnotations(beanType, Tag.class));
455456
if (!CollectionUtils.isEmpty(classTags)) {
456-
tagsStr.addAll(classTags.stream().map(tag -> propertyResolverUtils.resolve(tag.name(), locale)).collect(Collectors.toSet()));
457+
tagsStr.addAll(classTags.stream().map(tag -> propertyResolverUtils.resolve(tag.name(), locale)).collect(Collectors.toCollection(LinkedHashSet::new)));
457458
allTags.addAll(classTags);
458459
addTags(allTags, tags, locale);
459460
}

springdoc-openapi-starter-webflux-api/src/main/java/org/springdoc/webflux/core/providers/SpringWebFluxProvider.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.util.Collection;
2929
import java.util.LinkedHashMap;
30+
import java.util.LinkedHashSet;
3031
import java.util.Map;
3132
import java.util.Map.Entry;
3233
import java.util.Set;
@@ -84,7 +85,7 @@ public Set<String> getActivePatterns(Object requestMapping) {
8485
RequestMappingInfo requestMappingInfo = (RequestMappingInfo) requestMapping;
8586
PatternsRequestCondition patternsRequestCondition = requestMappingInfo.getPatternsCondition();
8687
return patternsRequestCondition.getPatterns().stream()
87-
.map(PathPattern::getPatternString).collect(Collectors.toSet());
88+
.map(PathPattern::getPatternString).collect(Collectors.toCollection(LinkedHashSet::new));
8889
}
8990

9091

springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app233/SpringDocApp233Test.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
package test.org.springdoc.api.v30.app233;
2828

2929
import java.util.Collection;
30+
import java.util.LinkedHashSet;
3031
import java.util.List;
3132
import java.util.Optional;
3233
import java.util.Set;
@@ -167,7 +168,7 @@ private void verifySwaggerFieldRequirementsMatchJavaValidation(Collection<String
167168
.stream()
168169
.flatMap(Collection::stream)
169170
.map(field -> field.getObjectName() + "." + field.getField())
170-
.collect(Collectors.toSet());
171+
.collect(Collectors.toCollection(LinkedHashSet::new));
171172

172173

173174
assertThat(errorFields).containsExactlyElementsOf(expectedErrorFields);

springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app233/SpringDocApp233Test.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
package test.org.springdoc.api.v31.app233;
2828

2929
import java.util.Collection;
30+
import java.util.LinkedHashSet;
3031
import java.util.List;
3132
import java.util.Optional;
3233
import java.util.Set;
@@ -167,7 +168,7 @@ private void verifySwaggerFieldRequirementsMatchJavaValidation(Collection<String
167168
.stream()
168169
.flatMap(Collection::stream)
169170
.map(field -> field.getObjectName() + "." + field.getField())
170-
.collect(Collectors.toSet());
171+
.collect(Collectors.toCollection(LinkedHashSet::new));
171172

172173

173174
assertThat(errorFields).containsExactlyElementsOf(expectedErrorFields);

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app126.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
"description": "Get all currencies",
2121
"operationId": "getAllCurrencies",
2222
"responses": {
23-
"401": {
24-
"$ref": "#/components/responses/http401NoToken"
25-
},
26-
"403": {
27-
"$ref": "#/components/responses/http403"
28-
},
2923
"200": {
3024
"description": "All currencies returned",
3125
"content": {
@@ -38,6 +32,12 @@
3832
}
3933
}
4034
}
35+
},
36+
"401": {
37+
"$ref": "#/components/responses/http401BadToken"
38+
},
39+
"403": {
40+
"$ref": "#/components/responses/http403"
4141
}
4242
}
4343
}

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app126.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
"description": "Get all currencies",
2121
"operationId": "getAllCurrencies",
2222
"responses": {
23-
"401": {
24-
"$ref": "#/components/responses/http401NoToken"
25-
},
26-
"403": {
27-
"$ref": "#/components/responses/http403"
28-
},
2923
"200": {
3024
"description": "All currencies returned",
3125
"content": {
@@ -38,6 +32,12 @@
3832
}
3933
}
4034
}
35+
},
36+
"401": {
37+
"$ref": "#/components/responses/http401BadToken"
38+
},
39+
"403": {
40+
"$ref": "#/components/responses/http403"
4141
}
4242
}
4343
}
@@ -62,15 +62,15 @@
6262
"type": "object"
6363
}
6464
},
65-
"status": {
66-
"type": "integer",
67-
"format": "int32"
68-
},
6965
"title": {
7066
"type": "string"
7167
},
7268
"detail": {
7369
"type": "string"
70+
},
71+
"status": {
72+
"type": "integer",
73+
"format": "int32"
7474
}
7575
}
7676
}

springdoc-openapi-tests/springdoc-openapi-data-rest-tests/src/test/resources/results/3.0.1/app24.json

+16-16
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
}
2828
},
2929
{
30-
"name": "name",
30+
"name": "email",
3131
"in": "query",
3232
"schema": {
3333
"type": "string"
3434
}
3535
},
3636
{
37-
"name": "email",
37+
"name": "name",
3838
"in": "query",
3939
"schema": {
4040
"type": "string"
@@ -90,6 +90,12 @@
9090
"type": "integer",
9191
"format": "int64"
9292
},
93+
"first": {
94+
"type": "boolean"
95+
},
96+
"last": {
97+
"type": "boolean"
98+
},
9399
"size": {
94100
"type": "integer",
95101
"format": "int32"
@@ -107,15 +113,9 @@
107113
"sort": {
108114
"$ref": "#/components/schemas/SortObject"
109115
},
110-
"last": {
111-
"type": "boolean"
112-
},
113116
"pageable": {
114117
"$ref": "#/components/schemas/PageableObject"
115118
},
116-
"first": {
117-
"type": "boolean"
118-
},
119119
"numberOfElements": {
120120
"type": "integer",
121121
"format": "int32"
@@ -135,19 +135,19 @@
135135
"sort": {
136136
"$ref": "#/components/schemas/SortObject"
137137
},
138+
"unpaged": {
139+
"type": "boolean"
140+
},
141+
"paged": {
142+
"type": "boolean"
143+
},
138144
"pageNumber": {
139145
"type": "integer",
140146
"format": "int32"
141147
},
142148
"pageSize": {
143149
"type": "integer",
144150
"format": "int32"
145-
},
146-
"paged": {
147-
"type": "boolean"
148-
},
149-
"unpaged": {
150-
"type": "boolean"
151151
}
152152
}
153153
},
@@ -157,10 +157,10 @@
157157
"empty": {
158158
"type": "boolean"
159159
},
160-
"sorted": {
160+
"unsorted": {
161161
"type": "boolean"
162162
},
163-
"unsorted": {
163+
"sorted": {
164164
"type": "boolean"
165165
}
166166
}

springdoc-openapi-tests/springdoc-openapi-data-rest-tests/src/test/resources/results/3.0.1/app30.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
"operationId": "testQueryDslAndSpringDoc",
2020
"parameters": [
2121
{
22-
"name": "name",
22+
"name": "email",
2323
"in": "query",
2424
"schema": {
2525
"type": "string"
2626
}
2727
},
2828
{
29-
"name": "email",
29+
"name": "name",
3030
"in": "query",
3131
"schema": {
3232
"type": "string"
@@ -70,4 +70,4 @@
7070
}
7171
}
7272
}
73-
}
73+
}

0 commit comments

Comments
 (0)