Skip to content

Commit 7f82a76

Browse files
author
bnasslahsen
committed
Improve the support of Pageable. Fixes #499
1 parent b1e5942 commit 7f82a76

File tree

5 files changed

+90
-111
lines changed

5 files changed

+90
-111
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/core/converters/AdditionalModelsConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterato
4343
if(modelToSchemaMap.containsKey(cls))
4444
return modelToSchemaMap.get(cls);
4545
if(modelToClassMap.containsKey(cls))
46-
type = new AnnotatedType(modelToClassMap.get(cls));
46+
type = new AnnotatedType(modelToClassMap.get(cls)).resolveAsRef(true);
4747
}
4848
if (chain.hasNext()) {
4949
return chain.next().resolve(type, context, chain);

springdoc-openapi-data-rest/src/main/java/org/springdoc/core/SpringDocDataRestConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public OpenApiCustomiser linksSchemaCustomiser(Optional<RepositoryRestConfigurat
9595
Json.mapper().addMixIn(RepresentationModel.class, RepresentationModelLinksOASMixin.class);
9696

9797
ResolvedSchema resolvedLinkSchema = ModelConverters.getInstance()
98-
.resolveAsResolvedSchema(new AnnotatedType(Link.class));
98+
.resolveAsResolvedSchema(new AnnotatedType(Link.class).resolveAsRef(true));
9999

100100
return openApi -> openApi
101101
.schema("Link", resolvedLinkSchema.schema)

springdoc-openapi-data-rest/src/main/java/org/springdoc/core/converters/Pageable.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class Pageable {
3737
@Max(2000)
3838
private int size;
3939

40+
@NotNull
4041
private List<String> sort;
4142

4243
public Pageable(@NotNull @Min(0) int page, @NotNull @Min(1) @Max(2000) int size, List<String> sort) {

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

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,7 @@
2323
"in": "query",
2424
"required": true,
2525
"schema": {
26-
"required": [
27-
"page",
28-
"size"
29-
],
30-
"type": "object",
31-
"properties": {
32-
"page": {
33-
"minimum": 0,
34-
"type": "integer",
35-
"format": "int32"
36-
},
37-
"size": {
38-
"maximum": 2000,
39-
"minimum": 1,
40-
"type": "integer",
41-
"format": "int32"
42-
},
43-
"sort": {
44-
"type": "array",
45-
"items": {
46-
"type": "string"
47-
}
48-
}
49-
}
26+
"$ref": "#/components/schemas/Pageable"
5027
}
5128
}
5229
],
@@ -78,6 +55,33 @@
7855
},
7956
"components": {
8057
"schemas": {
58+
"Pageable": {
59+
"required": [
60+
"page",
61+
"size",
62+
"sort"
63+
],
64+
"type": "object",
65+
"properties": {
66+
"page": {
67+
"minimum": 0,
68+
"type": "integer",
69+
"format": "int32"
70+
},
71+
"size": {
72+
"maximum": 2000,
73+
"minimum": 1,
74+
"type": "integer",
75+
"format": "int32"
76+
},
77+
"sort": {
78+
"type": "array",
79+
"items": {
80+
"type": "string"
81+
}
82+
}
83+
}
84+
},
8185
"PersonDTO": {
8286
"type": "object",
8387
"properties": {

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

Lines changed: 59 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,30 @@
1111
}
1212
],
1313
"paths": {
14-
"/employees/{id}": {
14+
"/employees": {
1515
"get": {
1616
"tags": [
1717
"employee-controller"
1818
],
19-
"operationId": "findOne",
20-
"parameters": [
21-
{
22-
"name": "id",
23-
"in": "path",
24-
"required": true,
25-
"schema": {
26-
"type": "integer",
27-
"format": "int64"
28-
}
29-
}
30-
],
19+
"operationId": "findAll",
3120
"responses": {
3221
"200": {
3322
"description": "default response",
3423
"content": {
3524
"*/*": {
3625
"schema": {
37-
"$ref": "#/components/schemas/EntityModelEmployee"
26+
"$ref": "#/components/schemas/CollectionModelEntityModelEmployee"
3827
}
3928
}
4029
}
4130
}
4231
}
4332
},
44-
"put": {
33+
"post": {
4534
"tags": [
4635
"employee-controller"
4736
],
48-
"operationId": "updateEmployee",
49-
"parameters": [
50-
{
51-
"name": "id",
52-
"in": "path",
53-
"required": true,
54-
"schema": {
55-
"type": "integer",
56-
"format": "int64"
57-
}
58-
}
59-
],
37+
"operationId": "newEmployee",
6038
"requestBody": {
6139
"content": {
6240
"application/json": {
@@ -69,35 +47,64 @@
6947
},
7048
"responses": {
7149
"200": {
72-
"description": "default response"
50+
"description": "default response",
51+
"content": {
52+
"*/*": {
53+
"schema": {
54+
"$ref": "#/components/schemas/EntityModelEmployee"
55+
}
56+
}
57+
}
7358
}
7459
}
7560
}
7661
},
77-
"/employees": {
62+
"/employees/{id}": {
7863
"get": {
7964
"tags": [
8065
"employee-controller"
8166
],
82-
"operationId": "findAll",
67+
"operationId": "findOne",
68+
"parameters": [
69+
{
70+
"name": "id",
71+
"in": "path",
72+
"required": true,
73+
"schema": {
74+
"type": "integer",
75+
"format": "int64"
76+
}
77+
}
78+
],
8379
"responses": {
8480
"200": {
8581
"description": "default response",
8682
"content": {
8783
"*/*": {
8884
"schema": {
89-
"$ref": "#/components/schemas/CollectionModelEntityModelEmployee"
85+
"$ref": "#/components/schemas/EntityModelEmployee"
9086
}
9187
}
9288
}
9389
}
9490
}
9591
},
96-
"post": {
92+
"put": {
9793
"tags": [
9894
"employee-controller"
9995
],
100-
"operationId": "newEmployee",
96+
"operationId": "updateEmployee",
97+
"parameters": [
98+
{
99+
"name": "id",
100+
"in": "path",
101+
"required": true,
102+
"schema": {
103+
"type": "integer",
104+
"format": "int64"
105+
}
106+
}
107+
],
101108
"requestBody": {
102109
"content": {
103110
"application/json": {
@@ -110,21 +117,31 @@
110117
},
111118
"responses": {
112119
"200": {
113-
"description": "default response",
114-
"content": {
115-
"*/*": {
116-
"schema": {
117-
"$ref": "#/components/schemas/EntityModelEmployee"
118-
}
119-
}
120-
}
120+
"description": "default response"
121121
}
122122
}
123123
}
124124
}
125125
},
126126
"components": {
127127
"schemas": {
128+
"CollectionModelEntityModelEmployee": {
129+
"type": "object",
130+
"properties": {
131+
"_embedded": {
132+
"type": "object",
133+
"additionalProperties": {
134+
"type": "array",
135+
"items": {
136+
"$ref": "#/components/schemas/EntityModelEmployee"
137+
}
138+
}
139+
},
140+
"_links": {
141+
"$ref": "#/components/schemas/Links"
142+
}
143+
}
144+
},
128145
"Employee": {
129146
"type": "object",
130147
"properties": {
@@ -170,51 +187,8 @@
170187
"$ref": "#/components/schemas/Link"
171188
}
172189
},
173-
"CollectionModelEntityModelEmployee": {
174-
"type": "object",
175-
"properties": {
176-
"_embedded": {
177-
"type": "object",
178-
"additionalProperties": {
179-
"type": "array",
180-
"items": {
181-
"$ref": "#/components/schemas/EntityModelEmployee"
182-
}
183-
}
184-
},
185-
"_links": {
186-
"$ref": "#/components/schemas/Links"
187-
}
188-
}
189-
},
190190
"Link": {
191-
"type": "object",
192-
"properties": {
193-
"href": {
194-
"type": "string"
195-
},
196-
"hreflang": {
197-
"type": "string"
198-
},
199-
"title": {
200-
"type": "string"
201-
},
202-
"type": {
203-
"type": "string"
204-
},
205-
"deprecation": {
206-
"type": "string"
207-
},
208-
"profile": {
209-
"type": "string"
210-
},
211-
"name": {
212-
"type": "string"
213-
},
214-
"templated": {
215-
"type": "boolean"
216-
}
217-
}
191+
"$ref": "#/components/schemas/Link"
218192
}
219193
}
220194
}

0 commit comments

Comments
 (0)