Skip to content

Commit 58c777f

Browse files
committed
code review
1 parent cf3b328 commit 58c777f

File tree

2 files changed

+62
-54
lines changed

2 files changed

+62
-54
lines changed

springdoc-openapi-data-rest/src/main/java/org/springdoc/data/rest/utils/SpringDocDataRestUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public void enhanceResponseContent(OpenAPI openAPI, ResourceMetadata resourceMet
7878
if (!key.endsWith(RESPONSE) && key.toLowerCase().contains(returnType.getSimpleName().toLowerCase())) {
7979
String newKey = key + RESPONSE;
8080
Schema newSchema = new ObjectSchema();
81+
newSchema.setRequired(existingSchema.getRequired());
8182
Map<String, Schema> properties = existingSchema.getProperties();
8283
properties.forEach((propId, val) -> updateResponseSchema(newSchema, returnType, ignoredFields, propId, val));
8384
if (key.equals(returnType.getSimpleName()))
@@ -111,6 +112,7 @@ public void enhanceRequestBodyContent(OpenAPI openAPI, ResourceMetadata resource
111112
if (!key.endsWith(REQUEST_BODY) && returnType.getSimpleName().equals(key)) {
112113
String newKey = key + REQUEST_BODY;
113114
Schema newSchema = new ObjectSchema();
115+
newSchema.setRequired(existingSchema.getRequired());
114116
Map<String, Schema> properties = existingSchema.getProperties();
115117
properties.forEach((propId, val) -> updateRequestBodySchema(associationsFields, newSchema, propId, val));
116118
schemas.put(newKey, newSchema);

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

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -853,66 +853,58 @@
853853
}
854854
}
855855
},
856-
"CollectionModelEntityModelClinic": {
856+
"DoctorRequestBody": {
857857
"type": "object",
858858
"properties": {
859-
"_embedded": {
860-
"type": "object",
861-
"properties": {
862-
"clinics": {
863-
"type": "array",
864-
"items": {
865-
"$ref": "#/components/schemas/EntityModelClinic"
866-
}
867-
}
868-
}
859+
"id": {
860+
"type": "integer",
861+
"format": "int64"
869862
},
870-
"_links": {
871-
"$ref": "#/components/schemas/Links"
863+
"clinics": {
864+
"type": "array",
865+
"items": {
866+
"type": "string"
867+
}
872868
}
873869
}
874870
},
875-
"EntityModelClinic": {
871+
"EntityModelDoctor": {
876872
"type": "object",
877873
"properties": {
878-
"name": {
879-
"type": "string"
880-
},
881874
"_links": {
882875
"$ref": "#/components/schemas/Links"
883876
}
884877
}
885878
},
886-
"ClinicResponse": {
887-
"type": "object",
888-
"properties": {
889-
"name": {
890-
"type": "string"
891-
}
892-
}
893-
},
894-
"ClinicRequestBody": {
879+
"CollectionModelEntityModelDoctor": {
895880
"type": "object",
896881
"properties": {
897-
"id": {
898-
"type": "integer",
899-
"format": "int64"
882+
"_embedded": {
883+
"type": "object",
884+
"properties": {
885+
"doctors": {
886+
"type": "array",
887+
"items": {
888+
"$ref": "#/components/schemas/EntityModelDoctor"
889+
}
890+
}
891+
}
900892
},
901-
"name": {
902-
"type": "string"
893+
"_links": {
894+
"$ref": "#/components/schemas/Links"
903895
}
904896
}
905897
},
906-
"CollectionModelEntityModelDoctor": {
898+
"CollectionModelClinic": {
907899
"type": "object",
908900
"properties": {
909901
"_embedded": {
910902
"type": "object",
911903
"properties": {
912-
"doctors": {
904+
"clinics": {
913905
"type": "array",
914906
"items": {
915-
"$ref": "#/components/schemas/EntityModelDoctor"
907+
"$ref": "#/components/schemas/ClinicResponse"
916908
}
917909
}
918910
}
@@ -922,49 +914,63 @@
922914
}
923915
}
924916
},
925-
"EntityModelDoctor": {
917+
"CollectionModelObject": {
926918
"type": "object",
927919
"properties": {
920+
"_embedded": {
921+
"type": "object",
922+
"properties": {
923+
"objects": {
924+
"type": "array",
925+
"items": {
926+
"type": "object"
927+
}
928+
}
929+
}
930+
},
928931
"_links": {
929932
"$ref": "#/components/schemas/Links"
930933
}
931934
}
932935
},
933-
"DoctorRequestBody": {
936+
"ClinicRequestBody": {
937+
"required": [
938+
"name"
939+
],
934940
"type": "object",
935941
"properties": {
936942
"id": {
937943
"type": "integer",
938944
"format": "int64"
939945
},
940-
"clinics": {
941-
"type": "array",
942-
"items": {
943-
"type": "string"
944-
}
946+
"name": {
947+
"type": "string"
945948
}
946949
}
947950
},
948-
"CollectionModelObject": {
951+
"EntityModelClinic": {
949952
"type": "object",
950953
"properties": {
951-
"_embedded": {
952-
"type": "object",
953-
"properties": {
954-
"objects": {
955-
"type": "array",
956-
"items": {
957-
"type": "object"
958-
}
959-
}
960-
}
954+
"name": {
955+
"type": "string"
961956
},
962957
"_links": {
963958
"$ref": "#/components/schemas/Links"
964959
}
965960
}
966961
},
967-
"CollectionModelClinic": {
962+
"ClinicResponse": {
963+
"required": [
964+
"name"
965+
],
966+
"type": "object",
967+
"properties": {
968+
"name": {
969+
"type": "string"
970+
}
971+
}
972+
},
973+
"CollectionModelEntityModelClinic": {
968974
"type": "object",
969975
"properties": {
970976
"_embedded": {
@@ -973,7 +979,7 @@
973979
"clinics": {
974980
"type": "array",
975981
"items": {
976-
"$ref": "#/components/schemas/ClinicResponse"
982+
"$ref": "#/components/schemas/EntityModelClinic"
977983
}
978984
}
979985
}

0 commit comments

Comments
 (0)