@@ -1153,6 +1153,8 @@ await VerifyOpenApiDocument(builder, document =>
1153
1153
Assert . NotNull ( operation . RequestBody . Content ) ;
1154
1154
var content = Assert . Single ( operation . RequestBody . Content ) ;
1155
1155
Assert . Equal ( "application/json-patch+json" , content . Key ) ;
1156
+ var schema = Assert . IsType < OpenApiSchemaReference > ( content . Value . Schema ) ;
1157
+ Assert . Equal ( "JsonPatchDocument" , schema . Reference . Id ) ;
1156
1158
} ) ;
1157
1159
}
1158
1160
@@ -1206,6 +1208,8 @@ await VerifyOpenApiDocument(builder, document =>
1206
1208
Assert . NotNull ( operation . RequestBody . Content ) ;
1207
1209
var content = Assert . Single ( operation . RequestBody . Content ) ;
1208
1210
Assert . Equal ( "application/json-patch+json" , content . Key ) ;
1211
+ var schema = Assert . IsType < OpenApiSchemaReference > ( content . Value . Schema ) ;
1212
+ Assert . Equal ( "JsonPatchDocument" , schema . Reference . Id ) ;
1209
1213
} ) ;
1210
1214
}
1211
1215
@@ -1227,6 +1231,8 @@ await VerifyOpenApiDocument(builder, document =>
1227
1231
Assert . NotNull ( operation . RequestBody . Content ) ;
1228
1232
var content = Assert . Single ( operation . RequestBody . Content ) ;
1229
1233
Assert . Equal ( "application/vnd.github.patch+json" , content . Key ) ;
1234
+ var schema = Assert . IsType < OpenApiSchemaReference > ( content . Value . Schema ) ;
1235
+ Assert . Equal ( "JsonPatchDocument" , schema . Reference . Id ) ;
1230
1236
} ) ;
1231
1237
}
1232
1238
@@ -1248,6 +1254,8 @@ await VerifyOpenApiDocument(builder, document =>
1248
1254
Assert . NotNull ( operation . RequestBody . Content ) ;
1249
1255
var content = Assert . Single ( operation . RequestBody . Content ) ;
1250
1256
Assert . Equal ( "application/vnd.github.patch+json" , content . Key ) ;
1257
+ var schema = Assert . IsType < OpenApiSchemaReference > ( content . Value . Schema ) ;
1258
+ Assert . Equal ( "JsonPatchDocument" , schema . Reference . Id ) ;
1251
1259
} ) ;
1252
1260
}
1253
1261
@@ -1270,6 +1278,8 @@ await VerifyOpenApiDocument(builder, document =>
1270
1278
Assert . NotNull ( operation . RequestBody . Content ) ;
1271
1279
var content = Assert . Single ( operation . RequestBody . Content ) ;
1272
1280
Assert . Equal ( "application/json-patch+json" , content . Key ) ;
1281
+ var schema = Assert . IsType < OpenApiSchemaReference > ( content . Value . Schema ) ;
1282
+ Assert . Equal ( "JsonPatchDocument" , schema . Reference . Id ) ;
1273
1283
} ) ;
1274
1284
}
1275
1285
@@ -1323,6 +1333,8 @@ await VerifyOpenApiDocument(builder, document =>
1323
1333
Assert . NotNull ( operation . RequestBody . Content ) ;
1324
1334
var content = Assert . Single ( operation . RequestBody . Content ) ;
1325
1335
Assert . Equal ( "application/json-patch+json" , content . Key ) ;
1336
+ var schema = Assert . IsType < OpenApiSchemaReference > ( content . Value . Schema ) ;
1337
+ Assert . Equal ( "JsonPatchDocument" , schema . Reference . Id ) ;
1326
1338
} ) ;
1327
1339
}
1328
1340
@@ -1345,6 +1357,8 @@ await VerifyOpenApiDocument(builder, document =>
1345
1357
Assert . NotNull ( operation . RequestBody . Content ) ;
1346
1358
var content = Assert . Single ( operation . RequestBody . Content ) ;
1347
1359
Assert . Equal ( "application/vnd.github.patch+json" , content . Key ) ;
1360
+ var schema = Assert . IsType < OpenApiSchemaReference > ( content . Value . Schema ) ;
1361
+ Assert . Equal ( "JsonPatchDocument" , schema . Reference . Id ) ;
1348
1362
} ) ;
1349
1363
}
1350
1364
@@ -1366,6 +1380,8 @@ await VerifyOpenApiDocument(builder, document =>
1366
1380
Assert . NotNull ( operation . RequestBody . Content ) ;
1367
1381
var content = Assert . Single ( operation . RequestBody . Content ) ;
1368
1382
Assert . Equal ( "application/vnd.github.patch+json" , content . Key ) ;
1383
+ var schema = Assert . IsType < OpenApiSchemaReference > ( content . Value . Schema ) ;
1384
+ Assert . Equal ( "JsonPatchDocument" , schema . Reference . Id ) ;
1369
1385
} ) ;
1370
1386
}
1371
1387
@@ -1379,4 +1395,56 @@ private sealed class JsonPatchModel
1379
1395
public string ? Second { get ; set ; }
1380
1396
}
1381
1397
#nullable restore
1398
+
1399
+ [ Fact ]
1400
+ public async Task GetRequestBody_HandlesCustomJsonPatchBody ( )
1401
+ {
1402
+ // Arrange
1403
+ var builder = CreateBuilder ( ) ;
1404
+
1405
+ // Act
1406
+ builder . MapPatch ( "/" , ( CustomJsonPatchDocument patch ) => { } ) ;
1407
+
1408
+ // Assert
1409
+ await VerifyOpenApiDocument ( builder , document =>
1410
+ {
1411
+ var paths = Assert . Single ( document . Paths . Values ) ;
1412
+ var operation = paths . Operations [ HttpMethod . Patch ] ;
1413
+ Assert . NotNull ( operation . RequestBody ) ;
1414
+ Assert . False ( operation . RequestBody . Required ) ;
1415
+ Assert . NotNull ( operation . RequestBody . Content ) ;
1416
+ var content = Assert . Single ( operation . RequestBody . Content ) ;
1417
+ Assert . Equal ( "application/json-patch+json" , content . Key ) ;
1418
+ var schema = Assert . IsType < OpenApiSchemaReference > ( content . Value . Schema ) ;
1419
+ Assert . Equal ( "JsonPatchDocument" , schema . Reference . Id ) ;
1420
+ } ) ;
1421
+ }
1422
+
1423
+ private class CustomJsonPatchDocument : JsonPatchDocument ;
1424
+
1425
+ [ Fact ]
1426
+ public async Task GetRequestBody_HandlesGenericCustomJsonPatchBody( )
1427
+ {
1428
+ // Arrange
1429
+ var builder = CreateBuilder ( ) ;
1430
+
1431
+ // Act
1432
+ builder . MapPatch ( "/ ", (CustomJsonPatchDocument<JsonPatchModel> patch) => { });
1433
+
1434
+ // Assert
1435
+ await VerifyOpenApiDocument ( builder , document =>
1436
+ {
1437
+ var paths = Assert . Single ( document . Paths . Values ) ;
1438
+ var operation = paths . Operations [ HttpMethod . Patch ] ;
1439
+ Assert . NotNull ( operation . RequestBody ) ;
1440
+ Assert . False ( operation . RequestBody . Required ) ;
1441
+ Assert . NotNull ( operation . RequestBody . Content ) ;
1442
+ var content = Assert . Single ( operation . RequestBody . Content ) ;
1443
+ Assert . Equal ( "application/json-patch+json" , content . Key ) ;
1444
+ var schema = Assert . IsType < OpenApiSchemaReference > ( content . Value . Schema ) ;
1445
+ Assert . Equal ( "JsonPatchDocument" , schema . Reference . Id ) ;
1446
+ } ) ;
1447
+ }
1448
+
1449
+ private class CustomJsonPatchDocument < T > : JsonPatchDocument < T > where T : class ;
1382
1450
}
0 commit comments