Skip to content

Commit 5c53abb

Browse files
committed
Do not wrap resource type in allOf. It is never null or documented, so there's no need.
1 parent 37f41fe commit 5c53abb

File tree

15 files changed

+94
-407
lines changed

15 files changed

+94
-407
lines changed

src/Examples/JsonApiDotNetCoreExampleClient/OpenAPIs/swagger.json

Lines changed: 18 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,11 +3080,7 @@
30803080
"type": "object",
30813081
"properties": {
30823082
"type": {
3083-
"allOf": [
3084-
{
3085-
"$ref": "#/components/schemas/personResourceType"
3086-
}
3087-
]
3083+
"$ref": "#/components/schemas/personResourceType"
30883084
},
30893085
"id": {
30903086
"minLength": 1,
@@ -3114,11 +3110,7 @@
31143110
"type": "object",
31153111
"properties": {
31163112
"type": {
3117-
"allOf": [
3118-
{
3119-
"$ref": "#/components/schemas/personResourceType"
3120-
}
3121-
]
3113+
"$ref": "#/components/schemas/personResourceType"
31223114
},
31233115
"attributes": {
31243116
"allOf": [
@@ -3146,11 +3138,7 @@
31463138
"type": "object",
31473139
"properties": {
31483140
"type": {
3149-
"allOf": [
3150-
{
3151-
"$ref": "#/components/schemas/personResourceType"
3152-
}
3153-
]
3141+
"$ref": "#/components/schemas/personResourceType"
31543142
},
31553143
"id": {
31563144
"minLength": 1,
@@ -3195,11 +3183,7 @@
31953183
"type": "object",
31963184
"properties": {
31973185
"type": {
3198-
"allOf": [
3199-
{
3200-
"$ref": "#/components/schemas/personResourceType"
3201-
}
3202-
]
3186+
"$ref": "#/components/schemas/personResourceType"
32033187
},
32043188
"id": {
32053189
"minLength": 1,
@@ -3366,7 +3350,8 @@
33663350
"enum": [
33673351
"people"
33683352
],
3369-
"type": "string"
3353+
"type": "string",
3354+
"additionalProperties": false
33703355
},
33713356
"personSecondaryResponseDocument": {
33723357
"required": [
@@ -3470,11 +3455,7 @@
34703455
"type": "object",
34713456
"properties": {
34723457
"type": {
3473-
"allOf": [
3474-
{
3475-
"$ref": "#/components/schemas/tagResourceType"
3476-
}
3477-
]
3458+
"$ref": "#/components/schemas/tagResourceType"
34783459
},
34793460
"id": {
34803461
"minLength": 1,
@@ -3504,11 +3485,7 @@
35043485
"type": "object",
35053486
"properties": {
35063487
"type": {
3507-
"allOf": [
3508-
{
3509-
"$ref": "#/components/schemas/tagResourceType"
3510-
}
3511-
]
3488+
"$ref": "#/components/schemas/tagResourceType"
35123489
},
35133490
"attributes": {
35143491
"allOf": [
@@ -3536,11 +3513,7 @@
35363513
"type": "object",
35373514
"properties": {
35383515
"type": {
3539-
"allOf": [
3540-
{
3541-
"$ref": "#/components/schemas/tagResourceType"
3542-
}
3543-
]
3516+
"$ref": "#/components/schemas/tagResourceType"
35443517
},
35453518
"id": {
35463519
"minLength": 1,
@@ -3585,11 +3558,7 @@
35853558
"type": "object",
35863559
"properties": {
35873560
"type": {
3588-
"allOf": [
3589-
{
3590-
"$ref": "#/components/schemas/tagResourceType"
3591-
}
3592-
]
3561+
"$ref": "#/components/schemas/tagResourceType"
35933562
},
35943563
"id": {
35953564
"minLength": 1,
@@ -3734,7 +3703,8 @@
37343703
"enum": [
37353704
"tags"
37363705
],
3737-
"type": "string"
3706+
"type": "string",
3707+
"additionalProperties": false
37383708
},
37393709
"toManyTagInRequest": {
37403710
"required": [
@@ -3984,11 +3954,7 @@
39843954
"type": "object",
39853955
"properties": {
39863956
"type": {
3987-
"allOf": [
3988-
{
3989-
"$ref": "#/components/schemas/todoItemResourceType"
3990-
}
3991-
]
3957+
"$ref": "#/components/schemas/todoItemResourceType"
39923958
},
39933959
"id": {
39943960
"minLength": 1,
@@ -4018,11 +3984,7 @@
40183984
"type": "object",
40193985
"properties": {
40203986
"type": {
4021-
"allOf": [
4022-
{
4023-
"$ref": "#/components/schemas/todoItemResourceType"
4024-
}
4025-
]
3987+
"$ref": "#/components/schemas/todoItemResourceType"
40263988
},
40273989
"attributes": {
40283990
"allOf": [
@@ -4050,11 +4012,7 @@
40504012
"type": "object",
40514013
"properties": {
40524014
"type": {
4053-
"allOf": [
4054-
{
4055-
"$ref": "#/components/schemas/todoItemResourceType"
4056-
}
4057-
]
4015+
"$ref": "#/components/schemas/todoItemResourceType"
40584016
},
40594017
"id": {
40604018
"minLength": 1,
@@ -4099,11 +4057,7 @@
40994057
"type": "object",
41004058
"properties": {
41014059
"type": {
4102-
"allOf": [
4103-
{
4104-
"$ref": "#/components/schemas/todoItemResourceType"
4105-
}
4106-
]
4060+
"$ref": "#/components/schemas/todoItemResourceType"
41074061
},
41084062
"id": {
41094063
"minLength": 1,
@@ -4301,7 +4255,8 @@
43014255
"enum": [
43024256
"todoItems"
43034257
],
4304-
"type": "string"
4258+
"type": "string",
4259+
"additionalProperties": false
43054260
}
43064261
}
43074262
}

src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceTypeSchemaGenerator.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public OpenApiSchema Get(ResourceType resourceType)
2525
{
2626
ArgumentGuard.NotNull(resourceType);
2727

28-
if (_resourceClrTypeSchemaCache.TryGetValue(resourceType.ClrType, out OpenApiSchema? extendedReferenceSchema))
28+
if (_resourceClrTypeSchemaCache.TryGetValue(resourceType.ClrType, out OpenApiSchema? referenceSchema))
2929
{
30-
return extendedReferenceSchema;
30+
return referenceSchema;
3131
}
3232

3333
var fullSchema = new OpenApiSchema
@@ -42,7 +42,7 @@ public OpenApiSchema Get(ResourceType resourceType)
4242

4343
string schemaId = GetSchemaId(resourceType);
4444

45-
var referenceSchema = new OpenApiSchema
45+
referenceSchema = new OpenApiSchema
4646
{
4747
Reference = new OpenApiReference
4848
{
@@ -51,18 +51,10 @@ public OpenApiSchema Get(ResourceType resourceType)
5151
}
5252
};
5353

54-
extendedReferenceSchema = new OpenApiSchema
55-
{
56-
AllOf = new List<OpenApiSchema>
57-
{
58-
referenceSchema
59-
}
60-
};
61-
6254
_schemaRepositoryAccessor.Current.AddDefinition(schemaId, fullSchema);
63-
_resourceClrTypeSchemaCache.Add(resourceType.ClrType, extendedReferenceSchema);
55+
_resourceClrTypeSchemaCache.Add(resourceType.ClrType, referenceSchema);
6456

65-
return extendedReferenceSchema;
57+
return referenceSchema;
6658
}
6759

6860
private string GetSchemaId(ResourceType resourceType)

test/OpenApiClientTests/LegacyClient/swagger.g.json

Lines changed: 13 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3250,11 +3250,7 @@
32503250
"type": "object",
32513251
"properties": {
32523252
"type": {
3253-
"allOf": [
3254-
{
3255-
"$ref": "#/components/schemas/airplane-resource-type"
3256-
}
3257-
]
3253+
"$ref": "#/components/schemas/airplane-resource-type"
32583254
},
32593255
"id": {
32603256
"minLength": 1,
@@ -3284,11 +3280,7 @@
32843280
"type": "object",
32853281
"properties": {
32863282
"type": {
3287-
"allOf": [
3288-
{
3289-
"$ref": "#/components/schemas/airplane-resource-type"
3290-
}
3291-
]
3283+
"$ref": "#/components/schemas/airplane-resource-type"
32923284
},
32933285
"attributes": {
32943286
"allOf": [
@@ -3316,11 +3308,7 @@
33163308
"type": "object",
33173309
"properties": {
33183310
"type": {
3319-
"allOf": [
3320-
{
3321-
"$ref": "#/components/schemas/airplane-resource-type"
3322-
}
3323-
]
3311+
"$ref": "#/components/schemas/airplane-resource-type"
33243312
},
33253313
"id": {
33263314
"minLength": 1,
@@ -3593,11 +3581,7 @@
35933581
"type": "object",
35943582
"properties": {
35953583
"type": {
3596-
"allOf": [
3597-
{
3598-
"$ref": "#/components/schemas/flight-attendant-resource-type"
3599-
}
3600-
]
3584+
"$ref": "#/components/schemas/flight-attendant-resource-type"
36013585
},
36023586
"id": {
36033587
"minLength": 1,
@@ -3627,11 +3611,7 @@
36273611
"type": "object",
36283612
"properties": {
36293613
"type": {
3630-
"allOf": [
3631-
{
3632-
"$ref": "#/components/schemas/flight-attendant-resource-type"
3633-
}
3634-
]
3614+
"$ref": "#/components/schemas/flight-attendant-resource-type"
36353615
},
36363616
"attributes": {
36373617
"allOf": [
@@ -3659,11 +3639,7 @@
36593639
"type": "object",
36603640
"properties": {
36613641
"type": {
3662-
"allOf": [
3663-
{
3664-
"$ref": "#/components/schemas/flight-attendant-resource-type"
3665-
}
3666-
]
3642+
"$ref": "#/components/schemas/flight-attendant-resource-type"
36673643
},
36683644
"id": {
36693645
"minLength": 1,
@@ -3708,11 +3684,7 @@
37083684
"type": "object",
37093685
"properties": {
37103686
"type": {
3711-
"allOf": [
3712-
{
3713-
"$ref": "#/components/schemas/flight-attendant-resource-type"
3714-
}
3715-
]
3687+
"$ref": "#/components/schemas/flight-attendant-resource-type"
37163688
},
37173689
"id": {
37183690
"minLength": 1,
@@ -4076,11 +4048,7 @@
40764048
"type": "object",
40774049
"properties": {
40784050
"type": {
4079-
"allOf": [
4080-
{
4081-
"$ref": "#/components/schemas/flight-resource-type"
4082-
}
4083-
]
4051+
"$ref": "#/components/schemas/flight-resource-type"
40844052
},
40854053
"id": {
40864054
"minLength": 1,
@@ -4110,11 +4078,7 @@
41104078
"type": "object",
41114079
"properties": {
41124080
"type": {
4113-
"allOf": [
4114-
{
4115-
"$ref": "#/components/schemas/flight-resource-type"
4116-
}
4117-
]
4081+
"$ref": "#/components/schemas/flight-resource-type"
41184082
},
41194083
"relationships": {
41204084
"allOf": [
@@ -4135,11 +4099,7 @@
41354099
"type": "object",
41364100
"properties": {
41374101
"type": {
4138-
"allOf": [
4139-
{
4140-
"$ref": "#/components/schemas/flight-resource-type"
4141-
}
4142-
]
4102+
"$ref": "#/components/schemas/flight-resource-type"
41434103
},
41444104
"id": {
41454105
"minLength": 1,
@@ -4184,11 +4144,7 @@
41844144
"type": "object",
41854145
"properties": {
41864146
"type": {
4187-
"allOf": [
4188-
{
4189-
"$ref": "#/components/schemas/flight-resource-type"
4190-
}
4191-
]
4147+
"$ref": "#/components/schemas/flight-resource-type"
41924148
},
41934149
"id": {
41944150
"minLength": 1,
@@ -4762,11 +4718,7 @@
47624718
"type": "object",
47634719
"properties": {
47644720
"type": {
4765-
"allOf": [
4766-
{
4767-
"$ref": "#/components/schemas/passenger-resource-type"
4768-
}
4769-
]
4721+
"$ref": "#/components/schemas/passenger-resource-type"
47704722
},
47714723
"id": {
47724724
"minLength": 1,
@@ -4804,11 +4756,7 @@
48044756
"type": "object",
48054757
"properties": {
48064758
"type": {
4807-
"allOf": [
4808-
{
4809-
"$ref": "#/components/schemas/passenger-resource-type"
4810-
}
4811-
]
4759+
"$ref": "#/components/schemas/passenger-resource-type"
48124760
},
48134761
"id": {
48144762
"minLength": 1,

0 commit comments

Comments
 (0)