Skip to content

Commit 756ec3e

Browse files
committed
Spring Data Rest: RequestBody for POST, PUT, PATCH should be required. fixes #1081
1 parent 7ceb586 commit 756ec3e

File tree

9 files changed

+299
-254
lines changed

9 files changed

+299
-254
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ else if (!RequestMethod.GET.equals(requestMethod)) {
216216
parameterInfo, requestBodyInfo);
217217
requestBuilder.applyBeanValidatorAnnotations(requestBodyInfo.getRequestBody(), parameterAnnotations, methodParameter.isOptional());
218218
operation.setRequestBody(requestBodyInfo.getRequestBody());
219+
operation.getRequestBody().setRequired(true);
219220
}
220221
}
221222

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

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"$ref": "#/components/schemas/Account"
5555
}
5656
}
57-
}
57+
},
58+
"required": true
5859
},
5960
"responses": {
6061
"201": {
@@ -158,7 +159,8 @@
158159
"$ref": "#/components/schemas/Account"
159160
}
160161
}
161-
}
162+
},
163+
"required": true
162164
},
163165
"responses": {
164166
"200": {
@@ -234,7 +236,8 @@
234236
"$ref": "#/components/schemas/Account"
235237
}
236238
}
237-
}
239+
},
240+
"required": true
238241
},
239242
"responses": {
240243
"200": {
@@ -324,7 +327,8 @@
324327
"$ref": "#/components/schemas/CollectionModelObject"
325328
}
326329
}
327-
}
330+
},
331+
"required": true
328332
},
329333
"responses": {
330334
"200": {
@@ -410,7 +414,8 @@
410414
"$ref": "#/components/schemas/CollectionModelObject"
411415
}
412416
}
413-
}
417+
},
418+
"required": true
414419
},
415420
"responses": {
416421
"200": {
@@ -547,7 +552,8 @@
547552
"$ref": "#/components/schemas/Customer"
548553
}
549554
}
550-
}
555+
},
556+
"required": true
551557
},
552558
"responses": {
553559
"201": {
@@ -685,7 +691,8 @@
685691
"$ref": "#/components/schemas/Customer"
686692
}
687693
}
688-
}
694+
},
695+
"required": true
689696
},
690697
"responses": {
691698
"200": {
@@ -736,7 +743,8 @@
736743
"$ref": "#/components/schemas/Customer"
737744
}
738745
}
739-
}
746+
},
747+
"required": true
740748
},
741749
"responses": {
742750
"200": {
@@ -934,25 +942,6 @@
934942
}
935943
}
936944
},
937-
"CollectionModelEntityModelAccount": {
938-
"type": "object",
939-
"properties": {
940-
"_embedded": {
941-
"type": "object",
942-
"properties": {
943-
"accounts": {
944-
"type": "array",
945-
"items": {
946-
"$ref": "#/components/schemas/EntityModelAccount"
947-
}
948-
}
949-
}
950-
},
951-
"_links": {
952-
"$ref": "#/components/schemas/Links"
953-
}
954-
}
955-
},
956945
"Customer": {
957946
"type": "object",
958947
"properties": {
@@ -987,6 +976,25 @@
987976
}
988977
}
989978
},
979+
"CollectionModelEntityModelAccount": {
980+
"type": "object",
981+
"properties": {
982+
"_embedded": {
983+
"type": "object",
984+
"properties": {
985+
"accounts": {
986+
"type": "array",
987+
"items": {
988+
"$ref": "#/components/schemas/EntityModelAccount"
989+
}
990+
}
991+
}
992+
},
993+
"_links": {
994+
"$ref": "#/components/schemas/Links"
995+
}
996+
}
997+
},
990998
"EntityModelCustomer": {
991999
"type": "object",
9921000
"properties": {

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

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@
9090
"$ref": "#/components/schemas/Person"
9191
}
9292
}
93-
}
93+
},
94+
"required": true
9495
},
9596
"responses": {
9697
"201": {
@@ -194,7 +195,8 @@
194195
"$ref": "#/components/schemas/Person"
195196
}
196197
}
197-
}
198+
},
199+
"required": true
198200
},
199201
"responses": {
200202
"200": {
@@ -270,7 +272,8 @@
270272
"$ref": "#/components/schemas/Person"
271273
}
272274
}
273-
}
275+
},
276+
"required": true
274277
},
275278
"responses": {
276279
"200": {
@@ -422,22 +425,14 @@
422425
}
423426
}
424427
},
425-
"CollectionModelEntityModelPerson": {
428+
"Person": {
426429
"type": "object",
427430
"properties": {
428-
"_embedded": {
429-
"type": "object",
430-
"properties": {
431-
"people": {
432-
"type": "array",
433-
"items": {
434-
"$ref": "#/components/schemas/EntityModelPerson"
435-
}
436-
}
437-
}
431+
"firstName": {
432+
"type": "string"
438433
},
439-
"_links": {
440-
"$ref": "#/components/schemas/Links"
434+
"lastName": {
435+
"type": "string"
441436
}
442437
}
443438
},
@@ -455,14 +450,22 @@
455450
}
456451
}
457452
},
458-
"Person": {
453+
"CollectionModelEntityModelPerson": {
459454
"type": "object",
460455
"properties": {
461-
"firstName": {
462-
"type": "string"
456+
"_embedded": {
457+
"type": "object",
458+
"properties": {
459+
"people": {
460+
"type": "array",
461+
"items": {
462+
"$ref": "#/components/schemas/EntityModelPerson"
463+
}
464+
}
465+
}
463466
},
464-
"lastName": {
465-
"type": "string"
467+
"_links": {
468+
"$ref": "#/components/schemas/Links"
466469
}
467470
}
468471
},

0 commit comments

Comments
 (0)