Skip to content

Commit 4cf7d45

Browse files
committed
Spring Data Rest: Wrong schema for request body in association controllers. Fixes #1082
1 parent 756ec3e commit 4cf7d45

File tree

9 files changed

+94
-89
lines changed

9 files changed

+94
-89
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import io.swagger.v3.oas.models.OpenAPI;
3636
import io.swagger.v3.oas.models.Operation;
3737
import io.swagger.v3.oas.models.media.Content;
38+
import io.swagger.v3.oas.models.media.MediaType;
39+
import io.swagger.v3.oas.models.media.StringSchema;
3840
import io.swagger.v3.oas.models.responses.ApiResponse;
3941
import io.swagger.v3.oas.models.responses.ApiResponses;
4042
import org.springdoc.core.GenericResponseService;
@@ -44,6 +46,7 @@
4446
import org.springframework.core.MethodParameter;
4547
import org.springframework.core.ResolvableType;
4648
import org.springframework.data.rest.core.mapping.MethodResourceMapping;
49+
import org.springframework.data.rest.webmvc.RestMediaTypes;
4750
import org.springframework.hateoas.CollectionModel;
4851
import org.springframework.hateoas.EntityModel;
4952
import org.springframework.hateoas.Link;
@@ -134,6 +137,8 @@ public void buildEntityResponse(Operation operation, HandlerMethod handlerMethod
134137
ApiResponses apiResponses = new ApiResponses();
135138
ApiResponse apiResponse = new ApiResponse();
136139
Content content = genericResponseService.buildContent(openAPI.getComponents(), methodParameterReturn.getParameterAnnotations(), methodAttributes.getMethodProduces(), null, returnType);
140+
if (content.get(RestMediaTypes.TEXT_URI_LIST_VALUE) != null)
141+
content.put(RestMediaTypes.TEXT_URI_LIST_VALUE, new MediaType().schema(new StringSchema()));
137142
apiResponse.setContent(content);
138143
addResponse(requestMethod, operationPath, apiResponses, apiResponse);
139144
operation.setResponses(apiResponses);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
"text/uri-list": {
3636
"schema": {
37-
"$ref": "#/components/schemas/CollectionModelEntityModelAccount"
37+
"type": "string"
3838
}
3939
}
4040
}
@@ -284,7 +284,7 @@
284284
},
285285
"text/uri-list": {
286286
"schema": {
287-
"$ref": "#/components/schemas/EntityModelCustomer"
287+
"type": "string"
288288
}
289289
}
290290
}
@@ -532,7 +532,7 @@
532532
},
533533
"text/uri-list": {
534534
"schema": {
535-
"$ref": "#/components/schemas/CollectionModelEntityModelCustomer"
535+
"type": "string"
536536
}
537537
}
538538
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
},
7171
"text/uri-list": {
7272
"schema": {
73-
"$ref": "#/components/schemas/CollectionModelEntityModelPerson"
73+
"type": "string"
7474
}
7575
}
7676
}

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

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
},
4040
"text/uri-list": {
4141
"schema": {
42-
"$ref": "#/components/schemas/CollectionModelEntityModelAccount"
42+
"type": "string"
4343
}
4444
}
4545
}
@@ -324,7 +324,7 @@
324324
},
325325
"text/uri-list": {
326326
"schema": {
327-
"$ref": "#/components/schemas/EntityModelCustomer"
327+
"type": "string"
328328
}
329329
}
330330
}
@@ -602,7 +602,7 @@
602602
},
603603
"text/uri-list": {
604604
"schema": {
605-
"$ref": "#/components/schemas/CollectionModelEntityModelCustomer"
605+
"type": "string"
606606
}
607607
}
608608
}
@@ -1001,6 +1001,22 @@
10011001
}
10021002
}
10031003
},
1004+
"Account": {
1005+
"type": "object",
1006+
"properties": {
1007+
"id": {
1008+
"type": "integer",
1009+
"format": "int64"
1010+
},
1011+
"customer": {
1012+
"$ref": "#/components/schemas/Customer"
1013+
},
1014+
"expiryDate": {
1015+
"type": "string",
1016+
"format": "date-time"
1017+
}
1018+
}
1019+
},
10041020
"Customer": {
10051021
"type": "object",
10061022
"properties": {
@@ -1016,34 +1032,35 @@
10161032
}
10171033
}
10181034
},
1019-
"EntityModelCustomer": {
1035+
"EntityModelAccount": {
10201036
"type": "object",
10211037
"properties": {
10221038
"id": {
10231039
"type": "integer",
10241040
"format": "int64"
10251041
},
1026-
"firstname": {
1027-
"type": "string"
1042+
"customer": {
1043+
"$ref": "#/components/schemas/Customer"
10281044
},
1029-
"lastname": {
1030-
"type": "string"
1045+
"expiryDate": {
1046+
"type": "string",
1047+
"format": "date-time"
10311048
},
10321049
"_links": {
10331050
"$ref": "#/components/schemas/Links"
10341051
}
10351052
}
10361053
},
1037-
"CollectionModelEntityModelCustomer": {
1054+
"CollectionModelEntityModelAccount": {
10381055
"type": "object",
10391056
"properties": {
10401057
"_embedded": {
10411058
"type": "object",
10421059
"properties": {
1043-
"customers": {
1060+
"accounts": {
10441061
"type": "array",
10451062
"items": {
1046-
"$ref": "#/components/schemas/EntityModelCustomer"
1063+
"$ref": "#/components/schemas/EntityModelAccount"
10471064
}
10481065
}
10491066
}
@@ -1053,85 +1070,44 @@
10531070
}
10541071
}
10551072
},
1056-
"PageMetadata": {
1073+
"EntityModelCustomer": {
10571074
"type": "object",
10581075
"properties": {
1059-
"size": {
1076+
"id": {
10601077
"type": "integer",
10611078
"format": "int64"
10621079
},
1063-
"totalElements": {
1064-
"type": "integer",
1065-
"format": "int64"
1080+
"firstname": {
1081+
"type": "string"
10661082
},
1067-
"totalPages": {
1068-
"type": "integer",
1069-
"format": "int64"
1083+
"lastname": {
1084+
"type": "string"
10701085
},
1071-
"number": {
1072-
"type": "integer",
1073-
"format": "int64"
1086+
"_links": {
1087+
"$ref": "#/components/schemas/Links"
10741088
}
10751089
}
10761090
},
1077-
"PagedModelCustomer": {
1091+
"CollectionModelObject": {
10781092
"type": "object",
10791093
"properties": {
10801094
"_embedded": {
10811095
"type": "object",
10821096
"properties": {
1083-
"customers": {
1097+
"objects": {
10841098
"type": "array",
10851099
"items": {
1086-
"$ref": "#/components/schemas/Customer"
1100+
"type": "object"
10871101
}
10881102
}
10891103
}
10901104
},
1091-
"_links": {
1092-
"$ref": "#/components/schemas/Links"
1093-
},
1094-
"page": {
1095-
"$ref": "#/components/schemas/PageMetadata"
1096-
}
1097-
}
1098-
},
1099-
"Account": {
1100-
"type": "object",
1101-
"properties": {
1102-
"id": {
1103-
"type": "integer",
1104-
"format": "int64"
1105-
},
1106-
"customer": {
1107-
"$ref": "#/components/schemas/Customer"
1108-
},
1109-
"expiryDate": {
1110-
"type": "string",
1111-
"format": "date-time"
1112-
}
1113-
}
1114-
},
1115-
"EntityModelAccount": {
1116-
"type": "object",
1117-
"properties": {
1118-
"id": {
1119-
"type": "integer",
1120-
"format": "int64"
1121-
},
1122-
"customer": {
1123-
"$ref": "#/components/schemas/Customer"
1124-
},
1125-
"expiryDate": {
1126-
"type": "string",
1127-
"format": "date-time"
1128-
},
11291105
"_links": {
11301106
"$ref": "#/components/schemas/Links"
11311107
}
11321108
}
11331109
},
1134-
"CollectionModelEntityModelAccount": {
1110+
"CollectionModelAccount": {
11351111
"type": "object",
11361112
"properties": {
11371113
"_embedded": {
@@ -1140,7 +1116,7 @@
11401116
"accounts": {
11411117
"type": "array",
11421118
"items": {
1143-
"$ref": "#/components/schemas/EntityModelAccount"
1119+
"$ref": "#/components/schemas/Account"
11441120
}
11451121
}
11461122
}
@@ -1150,16 +1126,16 @@
11501126
}
11511127
}
11521128
},
1153-
"CollectionModelObject": {
1129+
"CollectionModelEntityModelCustomer": {
11541130
"type": "object",
11551131
"properties": {
11561132
"_embedded": {
11571133
"type": "object",
11581134
"properties": {
1159-
"objects": {
1135+
"customers": {
11601136
"type": "array",
11611137
"items": {
1162-
"type": "object"
1138+
"$ref": "#/components/schemas/EntityModelCustomer"
11631139
}
11641140
}
11651141
}
@@ -1169,22 +1145,46 @@
11691145
}
11701146
}
11711147
},
1172-
"CollectionModelAccount": {
1148+
"PageMetadata": {
1149+
"type": "object",
1150+
"properties": {
1151+
"size": {
1152+
"type": "integer",
1153+
"format": "int64"
1154+
},
1155+
"totalElements": {
1156+
"type": "integer",
1157+
"format": "int64"
1158+
},
1159+
"totalPages": {
1160+
"type": "integer",
1161+
"format": "int64"
1162+
},
1163+
"number": {
1164+
"type": "integer",
1165+
"format": "int64"
1166+
}
1167+
}
1168+
},
1169+
"PagedModelCustomer": {
11731170
"type": "object",
11741171
"properties": {
11751172
"_embedded": {
11761173
"type": "object",
11771174
"properties": {
1178-
"accounts": {
1175+
"customers": {
11791176
"type": "array",
11801177
"items": {
1181-
"$ref": "#/components/schemas/Account"
1178+
"$ref": "#/components/schemas/Customer"
11821179
}
11831180
}
11841181
}
11851182
},
11861183
"_links": {
11871184
"$ref": "#/components/schemas/Links"
1185+
},
1186+
"page": {
1187+
"$ref": "#/components/schemas/PageMetadata"
11881188
}
11891189
}
11901190
},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
},
7171
"text/uri-list": {
7272
"schema": {
73-
"$ref": "#/components/schemas/CollectionModelEntityModelChildProperty"
73+
"type": "string"
7474
}
7575
}
7676
}
@@ -399,7 +399,7 @@
399399
},
400400
"text/uri-list": {
401401
"schema": {
402-
"$ref": "#/components/schemas/CollectionModelEntityModelProperty"
402+
"type": "string"
403403
}
404404
}
405405
}
@@ -617,7 +617,7 @@
617617
},
618618
"text/uri-list": {
619619
"schema": {
620-
"$ref": "#/components/schemas/EntityModelChildProperty"
620+
"type": "string"
621621
}
622622
}
623623
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
},
7070
"text/uri-list": {
7171
"schema": {
72-
"$ref": "#/components/schemas/CollectionModelEntityModelBank"
72+
"type": "string"
7373
}
7474
}
7575
}

0 commit comments

Comments
 (0)