Skip to content

Commit 9b6de3a

Browse files
committed
Serialization to openapi of org.springframework.data.domain.Sort is not done correctly
fixes #2447
1 parent 78e857f commit 9b6de3a

File tree

5 files changed

+108
-30
lines changed

5 files changed

+108
-30
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/configuration/SpringDocSortConfiguration.java

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Optional;
2828

2929
import org.springdoc.core.converters.SortOpenAPIConverter;
30+
import org.springdoc.core.converters.models.SortObject;
3031
import org.springdoc.core.customizers.DataRestDelegatingMethodParameterCustomizer;
3132
import org.springdoc.core.customizers.DelegatingMethodParameterCustomizer;
3233
import org.springdoc.core.providers.ObjectMapperProvider;
@@ -71,6 +72,7 @@ public class SpringDocSortConfiguration {
7172
@Lazy(false)
7273
SortOpenAPIConverter sortOpenAPIConverter(ObjectMapperProvider objectMapperProvider) {
7374
getConfig().replaceParameterObjectWithClass(org.springframework.data.domain.Sort.class, org.springdoc.core.converters.models.Sort.class);
75+
getConfig().replaceWithClass(org.springframework.data.domain.Sort.class, SortObject.class);
7476
return new SortOpenAPIConverter(objectMapperProvider);
7577
}
7678

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * * Copyright 2019-2022 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
19+
* * * *
20+
* * *
21+
* *
22+
*
23+
*/
24+
package org.springdoc.core.converters.models;
25+
26+
import com.fasterxml.jackson.annotation.JsonProperty;
27+
28+
/**
29+
* The type Sort response.
30+
* @author bnasslahsen
31+
*/
32+
public class SortObject {
33+
34+
/**
35+
* The Direction.
36+
*/
37+
@JsonProperty
38+
private String direction;
39+
40+
/**
41+
* The Null handling.
42+
*/
43+
@JsonProperty
44+
private String nullHandling;
45+
46+
/**
47+
* The Ascending.
48+
*/
49+
@JsonProperty
50+
private boolean ascending;
51+
52+
/**
53+
* The Property.
54+
*/
55+
@JsonProperty
56+
private String property;
57+
58+
/**
59+
* The Ignore case.
60+
*/
61+
@JsonProperty
62+
private boolean ignoreCase;
63+
64+
}

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/utils/Constants.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public final class Constants {
403403
/**
404404
* The constant SPRINGDOC_SORT_CONVERTER_ENABLED.
405405
*/
406-
public static final String SPRINGDOC_SORT_CONVERTER_ENABLED = "springdoc.model-converters.sort-converter.enabled";
406+
public static final String SPRINGDOC_SORT_CONVERTER_ENABLED = "springdoc.sort-converter.enabled";
407407

408408
/**
409409
* The constant SPRINGDOC_NULLABLE_REQUEST_PARAMETER_ENABLED.

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

+22-16
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@
9090
"type": "integer",
9191
"format": "int64"
9292
},
93-
"numberOfElements": {
94-
"type": "integer",
95-
"format": "int32"
96-
},
9793
"size": {
9894
"type": "integer",
9995
"format": "int32"
@@ -108,12 +104,16 @@
108104
"type": "integer",
109105
"format": "int32"
110106
},
111-
"pageable": {
112-
"$ref": "#/components/schemas/PageableObject"
113-
},
114107
"sort": {
115108
"$ref": "#/components/schemas/SortObject"
116109
},
110+
"numberOfElements": {
111+
"type": "integer",
112+
"format": "int32"
113+
},
114+
"pageable": {
115+
"$ref": "#/components/schemas/PageableObject"
116+
},
117117
"first": {
118118
"type": "boolean"
119119
},
@@ -132,6 +132,9 @@
132132
"type": "integer",
133133
"format": "int64"
134134
},
135+
"sort": {
136+
"$ref": "#/components/schemas/SortObject"
137+
},
135138
"pageNumber": {
136139
"type": "integer",
137140
"format": "int32"
@@ -140,27 +143,30 @@
140143
"type": "integer",
141144
"format": "int32"
142145
},
143-
"sort": {
144-
"$ref": "#/components/schemas/SortObject"
145-
},
146-
"unpaged": {
146+
"paged": {
147147
"type": "boolean"
148148
},
149-
"paged": {
149+
"unpaged": {
150150
"type": "boolean"
151151
}
152152
}
153153
},
154154
"SortObject": {
155155
"type": "object",
156156
"properties": {
157-
"sorted": {
158-
"type": "boolean"
157+
"direction": {
158+
"type": "string"
159+
},
160+
"nullHandling": {
161+
"type": "string"
159162
},
160-
"unsorted": {
163+
"ascending": {
161164
"type": "boolean"
162165
},
163-
"empty": {
166+
"property": {
167+
"type": "string"
168+
},
169+
"ignoreCase": {
164170
"type": "boolean"
165171
}
166172
}

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

+19-13
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@
5858
"Pageable": {
5959
"type": "object",
6060
"properties": {
61-
"paged": {
62-
"type": "boolean"
61+
"offset": {
62+
"type": "integer",
63+
"format": "int64"
6364
},
64-
"unpaged": {
65-
"type": "boolean"
65+
"sort": {
66+
"$ref": "#/components/schemas/SortObject"
6667
},
6768
"pageNumber": {
6869
"type": "integer",
@@ -72,25 +73,30 @@
7273
"type": "integer",
7374
"format": "int32"
7475
},
75-
"offset": {
76-
"type": "integer",
77-
"format": "int64"
76+
"paged": {
77+
"type": "boolean"
7878
},
79-
"sort": {
80-
"$ref": "#/components/schemas/SortObject"
79+
"unpaged": {
80+
"type": "boolean"
8181
}
8282
}
8383
},
8484
"SortObject": {
8585
"type": "object",
8686
"properties": {
87-
"sorted": {
88-
"type": "boolean"
87+
"direction": {
88+
"type": "string"
89+
},
90+
"nullHandling": {
91+
"type": "string"
8992
},
90-
"unsorted": {
93+
"ascending": {
9194
"type": "boolean"
9295
},
93-
"empty": {
96+
"property": {
97+
"type": "string"
98+
},
99+
"ignoreCase": {
94100
"type": "boolean"
95101
}
96102
}

0 commit comments

Comments
 (0)