Skip to content

Commit 3d3575c

Browse files
Add issue repro
Add repro for #3649.
1 parent 69e3210 commit 3d3575c

11 files changed

Lines changed: 344 additions & 2 deletions

Swashbuckle.AspNetCore.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<Project Path="test/WebSites/GenericControllers/GenericControllers.csproj" />
7070
<Project Path="test/WebSites/MinimalApp/MinimalApp.csproj" />
7171
<Project Path="test/WebSites/MinimalAppWithHostedServices/MinimalAppWithHostedServices.csproj" />
72+
<Project Path="test/WebSites/MinimalAppWithNullableEnums/MinimalAppWithNullableEnums.csproj" />
7273
<Project Path="test/WebSites/MultipleVersions/MultipleVersions.csproj" />
7374
<Project Path="test/WebSites/MvcWithNullable/MvcWithNullable.csproj" />
7475
<Project Path="test/WebSites/NswagClientExample/NswagClientExample.csproj" />

test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerIntegrationTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ public async Task SwaggerMiddleware_CanBeConfiguredMultipleTimes(
115115

116116
[Theory]
117117
[InlineData(typeof(MinimalApp.Program), "/swagger/v1/swagger.json")]
118-
[InlineData(typeof(TopLevelSwaggerDoc.Program), "/swagger/v1.json")]
118+
[InlineData(typeof(MinimalAppWithNullableEnums.Program), "/swagger/v1/swagger.json")]
119119
[InlineData(typeof(MvcWithNullable.Program), "/swagger/v1/swagger.json")]
120+
[InlineData(typeof(TopLevelSwaggerDoc.Program), "/swagger/v1.json")]
120121
[InlineData(typeof(WebApi.Program), "/swagger/v1/swagger.json")]
121122
[InlineData(typeof(WebApi.Aot.Program), "/swagger/v1/swagger.json")]
122123
public async Task SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup(

test/Swashbuckle.AspNetCore.IntegrationTests/VerifyTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ await Verify(swagger)
5656

5757
[Theory]
5858
[InlineData(typeof(MinimalApp.Program), "/swagger/v1/swagger.json")]
59-
[InlineData(typeof(TopLevelSwaggerDoc.Program), "/swagger/v1.json")]
59+
[InlineData(typeof(MinimalAppWithNullableEnums.Program), "/swagger/v1/swagger.json")]
6060
[InlineData(typeof(MvcWithNullable.Program), "/swagger/v1/swagger.json")]
61+
[InlineData(typeof(TopLevelSwaggerDoc.Program), "/swagger/v1.json")]
6162
[InlineData(typeof(WebApi.Program), "/swagger/v1/swagger.json")]
6263
[InlineData(typeof(WebApi.Aot.Program), "/swagger/v1/swagger.json")]
6364
public async Task Swagger_IsValidJson_No_Startup(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"openapi": "3.1.1",
3+
"info": {
4+
"title": "MinimalAppWithNullableEnums",
5+
"version": "1.0"
6+
},
7+
"paths": {
8+
"/weatherforecast": {
9+
"get": {
10+
"tags": [
11+
"MinimalAppWithNullableEnums"
12+
],
13+
"operationId": "GetWeatherForecast",
14+
"requestBody": {
15+
"content": {
16+
"application/json": {
17+
"schema": {
18+
"allOf": [
19+
{
20+
"$ref": "#/components/schemas/Parent"
21+
}
22+
]
23+
}
24+
}
25+
},
26+
"required": true
27+
},
28+
"responses": {
29+
"200": {
30+
"description": "OK"
31+
}
32+
}
33+
}
34+
}
35+
},
36+
"components": {
37+
"schemas": {
38+
"Child": {
39+
"type": "object",
40+
"properties": {
41+
"name": {
42+
"type": "string"
43+
}
44+
},
45+
"additionalProperties": false
46+
},
47+
"Parent": {
48+
"type": "object",
49+
"properties": {
50+
"child": {
51+
"type": "null",
52+
"allOf": [
53+
{
54+
"$ref": "#/components/schemas/Child"
55+
}
56+
]
57+
},
58+
"category": {
59+
"enum": [
60+
0,
61+
1,
62+
2
63+
],
64+
"type": [
65+
"null",
66+
"integer"
67+
],
68+
"format": "int32"
69+
}
70+
},
71+
"additionalProperties": false
72+
}
73+
}
74+
},
75+
"tags": [
76+
{
77+
"name": "MinimalAppWithNullableEnums"
78+
}
79+
]
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"openapi": "3.1.1",
3+
"info": {
4+
"title": "MinimalAppWithNullableEnums",
5+
"version": "1.0"
6+
},
7+
"paths": {
8+
"/weatherforecast": {
9+
"get": {
10+
"tags": [
11+
"MinimalAppWithNullableEnums"
12+
],
13+
"operationId": "GetWeatherForecast",
14+
"requestBody": {
15+
"content": {
16+
"application/json": {
17+
"schema": {
18+
"allOf": [
19+
{
20+
"$ref": "#/components/schemas/Parent"
21+
}
22+
]
23+
}
24+
}
25+
},
26+
"required": true
27+
},
28+
"responses": {
29+
"200": {
30+
"description": "OK"
31+
}
32+
}
33+
}
34+
}
35+
},
36+
"components": {
37+
"schemas": {
38+
"Child": {
39+
"type": "object",
40+
"properties": {
41+
"name": {
42+
"type": "string"
43+
}
44+
},
45+
"additionalProperties": false
46+
},
47+
"Parent": {
48+
"type": "object",
49+
"properties": {
50+
"child": {
51+
"type": "null",
52+
"allOf": [
53+
{
54+
"$ref": "#/components/schemas/Child"
55+
}
56+
]
57+
},
58+
"category": {
59+
"enum": [
60+
0,
61+
1,
62+
2
63+
],
64+
"type": [
65+
"null",
66+
"integer"
67+
],
68+
"format": "int32"
69+
}
70+
},
71+
"additionalProperties": false
72+
}
73+
}
74+
},
75+
"tags": [
76+
{
77+
"name": "MinimalAppWithNullableEnums"
78+
}
79+
]
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"openapi": "3.1.1",
3+
"info": {
4+
"title": "MinimalAppWithNullableEnums",
5+
"version": "1.0"
6+
},
7+
"paths": {
8+
"/weatherforecast": {
9+
"get": {
10+
"tags": [
11+
"MinimalAppWithNullableEnums"
12+
],
13+
"operationId": "GetWeatherForecast",
14+
"requestBody": {
15+
"content": {
16+
"application/json": {
17+
"schema": {
18+
"allOf": [
19+
{
20+
"$ref": "#/components/schemas/Parent"
21+
}
22+
]
23+
}
24+
}
25+
},
26+
"required": true
27+
},
28+
"responses": {
29+
"200": {
30+
"description": "OK"
31+
}
32+
}
33+
}
34+
}
35+
},
36+
"components": {
37+
"schemas": {
38+
"Child": {
39+
"type": "object",
40+
"properties": {
41+
"name": {
42+
"type": "string"
43+
}
44+
},
45+
"additionalProperties": false
46+
},
47+
"Parent": {
48+
"type": "object",
49+
"properties": {
50+
"child": {
51+
"type": "null",
52+
"allOf": [
53+
{
54+
"$ref": "#/components/schemas/Child"
55+
}
56+
]
57+
},
58+
"category": {
59+
"enum": [
60+
0,
61+
1,
62+
2
63+
],
64+
"type": [
65+
"null",
66+
"integer"
67+
],
68+
"format": "int32"
69+
}
70+
},
71+
"additionalProperties": false
72+
}
73+
}
74+
},
75+
"tags": [
76+
{
77+
"name": "MinimalAppWithNullableEnums"
78+
}
79+
]
80+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<NoWarn>$(NoWarn);CA1050</NoWarn>
6+
<Nullable>enable</Nullable>
7+
<TargetFrameworks>$(DefaultTargetFrameworks)</TargetFrameworks>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\..\..\src\Swashbuckle.AspNetCore.SwaggerGen\Swashbuckle.AspNetCore.SwaggerGen.csproj" />
12+
<ProjectReference Include="..\..\..\src\Swashbuckle.AspNetCore.SwaggerUI\Swashbuckle.AspNetCore.SwaggerUI.csproj" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.OpenApi;
3+
4+
var builder = WebApplication.CreateBuilder(args);
5+
6+
builder.Services.AddEndpointsApiExplorer();
7+
builder.Services.AddSwaggerGen((p) =>
8+
{
9+
p.SupportNonNullableReferenceTypes();
10+
p.UseInlineDefinitionsForEnums();
11+
p.UseAllOfToExtendReferenceSchemas();
12+
p.UseAllOfForInheritance();
13+
});
14+
15+
var app = builder.Build();
16+
17+
app.UseSwagger((p) => p.OpenApiVersion = OpenApiSpecVersion.OpenApi3_1);
18+
app.UseSwaggerUI();
19+
20+
app.MapGet("/weatherforecast", ([FromBody] Parent a) => { })
21+
.WithName("GetWeatherForecast");
22+
23+
app.Run();
24+
25+
public class Parent
26+
{
27+
public Child? Child { get; set; }
28+
29+
public Category? Category { get; set; }
30+
}
31+
32+
public class Child
33+
{
34+
public string Name { get; set; } = string.Empty;
35+
}
36+
37+
public enum Category
38+
{
39+
One,
40+
Two,
41+
Three,
42+
}
43+
44+
namespace MinimalAppWithNullableEnums
45+
{
46+
/// <summary>
47+
/// Expose the Program class for use with <c>WebApplicationFactory</c>
48+
/// </summary>
49+
public partial class Program
50+
{
51+
}
52+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"MinimalAppWithNullableEnums": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"launchUrl": "swagger",
9+
"applicationUrl": "https://localhost:7945;http://localhost:5267",
10+
"environmentVariables": {
11+
"ASPNETCORE_ENVIRONMENT": "Development"
12+
}
13+
}
14+
}
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)