Skip to content

Commit dd3ebbf

Browse files
committed
[Swashbuckle] Added handling for NonNullableReferenceTypesAsRequired
1 parent 9c29261 commit dd3ebbf

File tree

314 files changed

+9832
-58
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

314 files changed

+9832
-58
lines changed

src/Thinktecture.Runtime.Extensions.Swashbuckle/Swashbuckle/Internal/AdHocUnions/AdHocUnionSchemaFilter.cs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public void Apply(OpenApiSchema schema, SchemaFilterContext context)
2525
public void Apply(OpenApiSchema schema, SchemaFilterContext context, Metadata.AdHocUnion metadata)
2626
{
2727
schema.Properties.Clear();
28+
schema.Required.Clear();
2829

2930
schema.Type = null;
3031
schema.OneOf = metadata.MemberTypes

src/Thinktecture.Runtime.Extensions.Swashbuckle/Swashbuckle/Internal/ComplexValueObjects/ComplexValueObjectSchemaFilter.cs

+9-8
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ public void Apply(OpenApiSchema schema, SchemaFilterContext context, Metadata.Co
4949
{
5050
foreach (var memberInfo in metadata.AssignableMembers)
5151
{
52-
if (memberInfo.GetCustomAttribute<RequiredAttribute>() is null && _requiredMemberEvaluator.IsRequired(schema, context, memberInfo))
53-
{
54-
var name = memberInfo.GetCustomAttribute<JsonPropertyNameAttribute>()?.Name
55-
?? _jsonSerializerOptions.PropertyNamingPolicy?.ConvertName(memberInfo.Name)
56-
?? memberInfo.Name;
57-
58-
schema.Required.Add(name);
59-
}
52+
if (memberInfo.GetCustomAttribute<RequiredAttribute>() is not null
53+
|| !_requiredMemberEvaluator.IsRequired(schema, context, memberInfo))
54+
continue;
55+
56+
var name = memberInfo.GetCustomAttribute<JsonPropertyNameAttribute>()?.Name
57+
?? _jsonSerializerOptions.PropertyNamingPolicy?.ConvertName(memberInfo.Name)
58+
?? memberInfo.Name;
59+
60+
schema.Required.Add(name);
6061
}
6162
}
6263
}

src/Thinktecture.Runtime.Extensions.Swashbuckle/Swashbuckle/Internal/KeyedValueObjects/KeyedValueObjectSchemaFilter.cs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public void Apply(OpenApiSchema schema, SchemaFilterContext context)
2525
public void Apply(OpenApiSchema schema, SchemaFilterContext context, Metadata.Keyed.ValueObject metadata)
2626
{
2727
schema.Properties.Clear();
28+
schema.Required.Clear();
2829

2930
var keySchema = context.SchemaGenerator.GenerateSchema(metadata.KeyType, context.SchemaRepository);
3031

src/Thinktecture.Runtime.Extensions.Swashbuckle/Swashbuckle/Internal/SmartEnums/SmartEnumSchemaFilterBase.cs

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public void Apply(OpenApiSchema schema, SchemaFilterContext context)
4444
public void Apply(OpenApiSchema schema, SchemaFilterContext context, Metadata.Keyed.SmartEnum metadata)
4545
{
4646
schema.Properties.Clear();
47+
schema.Required.Clear();
48+
4749
var items = GetItems(metadata.Type, metadata.KeyType, metadata.GetItems());
4850

4951
SetItems(schema, items);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"openapi": "3.0.4",
3+
"info": {
4+
"title": "Test API",
5+
"version": "v1"
6+
},
7+
"paths": {
8+
"/test": {
9+
"post": {
10+
"tags": [
11+
"Tests"
12+
],
13+
"requestBody": {
14+
"content": {
15+
"application/json": {
16+
"schema": {
17+
"allOf": [
18+
{
19+
"$ref": "#/components/schemas/TestUnion_class_string_int"
20+
}
21+
]
22+
}
23+
}
24+
}
25+
},
26+
"responses": {
27+
"200": {
28+
"description": "OK",
29+
"content": {
30+
"application/json": {
31+
"schema": {
32+
"$ref": "#/components/schemas/TestUnion_class_string_int"
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}
39+
}
40+
},
41+
"components": {
42+
"schemas": {
43+
"TestUnion_class_string_int": {
44+
"oneOf": [
45+
{
46+
"type": "string"
47+
},
48+
{
49+
"type": "integer",
50+
"format": "int32"
51+
}
52+
]
53+
}
54+
}
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"openapi": "3.0.4",
3+
"info": {
4+
"title": "Test API",
5+
"version": "v1"
6+
},
7+
"paths": {
8+
"/test": {
9+
"post": {
10+
"tags": [
11+
"Tests"
12+
],
13+
"requestBody": {
14+
"content": {
15+
"application/json": {
16+
"schema": {
17+
"allOf": [
18+
{
19+
"$ref": "#/components/schemas/TestUnion_class_string_int"
20+
}
21+
]
22+
}
23+
}
24+
},
25+
"required": true
26+
},
27+
"responses": {
28+
"200": {
29+
"description": "OK",
30+
"content": {
31+
"application/json": {
32+
"schema": {
33+
"$ref": "#/components/schemas/TestUnion_class_string_int"
34+
}
35+
}
36+
}
37+
}
38+
}
39+
}
40+
}
41+
},
42+
"components": {
43+
"schemas": {
44+
"TestUnion_class_string_int": {
45+
"oneOf": [
46+
{
47+
"type": "string"
48+
},
49+
{
50+
"type": "integer",
51+
"format": "int32"
52+
}
53+
]
54+
}
55+
}
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"openapi": "3.0.4",
3+
"info": {
4+
"title": "Test API",
5+
"version": "v1"
6+
},
7+
"paths": {
8+
"/test": {
9+
"post": {
10+
"tags": [
11+
"Tests"
12+
],
13+
"requestBody": {
14+
"content": {
15+
"application/json": {
16+
"schema": {
17+
"allOf": [
18+
{
19+
"$ref": "#/components/schemas/TestUnion_class_string_int"
20+
}
21+
]
22+
}
23+
}
24+
}
25+
},
26+
"responses": {
27+
"200": {
28+
"description": "OK",
29+
"content": {
30+
"application/json": {
31+
"schema": {
32+
"$ref": "#/components/schemas/TestUnion_class_string_int"
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}
39+
}
40+
},
41+
"components": {
42+
"schemas": {
43+
"TestUnion_class_string_int": {
44+
"oneOf": [
45+
{
46+
"type": "string"
47+
},
48+
{
49+
"type": "integer",
50+
"format": "int32"
51+
}
52+
]
53+
}
54+
}
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"openapi": "3.0.4",
3+
"info": {
4+
"title": "Test API",
5+
"version": "v1"
6+
},
7+
"paths": {
8+
"/test": {
9+
"post": {
10+
"tags": [
11+
"Tests"
12+
],
13+
"requestBody": {
14+
"content": {
15+
"application/json": {
16+
"schema": {
17+
"allOf": [
18+
{
19+
"$ref": "#/components/schemas/TestUnion_class_string_int"
20+
}
21+
]
22+
}
23+
}
24+
}
25+
},
26+
"responses": {
27+
"200": {
28+
"description": "OK",
29+
"content": {
30+
"application/json": {
31+
"schema": {
32+
"$ref": "#/components/schemas/TestUnion_class_string_int"
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}
39+
}
40+
},
41+
"components": {
42+
"schemas": {
43+
"TestUnion_class_string_int": {
44+
"oneOf": [
45+
{
46+
"type": "string"
47+
},
48+
{
49+
"type": "integer",
50+
"format": "int32"
51+
}
52+
]
53+
}
54+
}
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"openapi": "3.0.4",
3+
"info": {
4+
"title": "Test API",
5+
"version": "v1"
6+
},
7+
"paths": {
8+
"/test": {
9+
"post": {
10+
"tags": [
11+
"Tests"
12+
],
13+
"requestBody": {
14+
"content": {
15+
"multipart/form-data": {
16+
"schema": {
17+
"type": "object",
18+
"properties": {
19+
"value": {
20+
"allOf": [
21+
{
22+
"$ref": "#/components/schemas/TestUnion_class_string_int"
23+
}
24+
]
25+
}
26+
}
27+
},
28+
"encoding": {
29+
"value": {
30+
"style": "form"
31+
}
32+
}
33+
}
34+
}
35+
},
36+
"responses": {
37+
"200": {
38+
"description": "OK",
39+
"content": {
40+
"application/json": {
41+
"schema": {
42+
"$ref": "#/components/schemas/TestUnion_class_string_int"
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}
50+
},
51+
"components": {
52+
"schemas": {
53+
"TestUnion_class_string_int": {
54+
"oneOf": [
55+
{
56+
"type": "string"
57+
},
58+
{
59+
"type": "integer",
60+
"format": "int32"
61+
}
62+
]
63+
}
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)