Skip to content

Commit bd036c4

Browse files
committed
Add test coverage from reported issues
1 parent 7ba4318 commit bd036c4

File tree

5 files changed

+871
-0
lines changed

5 files changed

+871
-0
lines changed

src/OpenApi/sample/Endpoints/MapSchemasEndpoints.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public static IEndpointRouteBuilder MapSchemasEndpoints(this IEndpointRouteBuild
4141
schemas.MapPatch("/json-patch-generic", (JsonPatchDocument<ParentObject> patchDoc) => Results.NoContent());
4242
schemas.MapGet("/custom-iresult", () => new CustomIResultImplementor { Content = "Hello world!" })
4343
.Produces<CustomIResultImplementor>(200);
44+
45+
// Tests for validating scenarios related to https://github.com/dotnet/aspnetcore/issues/61194
46+
schemas.MapPost("/config-with-generic-lists", (Config config) => Results.Ok(config));
47+
schemas.MapPost("/project-response", (ProjectResponse project) => Results.Ok(project));
48+
schemas.MapPost("/subscription", (Subscription subscription) => Results.Ok(subscription));
4449
return endpointRouteBuilder;
4550
}
4651

@@ -111,4 +116,61 @@ public sealed class ChildObject
111116
public int Id { get; set; }
112117
public required ParentObject Parent { get; set; }
113118
}
119+
120+
// Example types for GitHub issue 61194: Generic types referenced multiple times
121+
public sealed class Config
122+
{
123+
public List<ConfigItem> Items1 { get; set; } = [];
124+
public List<ConfigItem> Items2 { get; set; } = [];
125+
}
126+
127+
public sealed class ConfigItem
128+
{
129+
public int? Id { get; set; }
130+
public string? Lang { get; set; }
131+
public Dictionary<string, object?>? Words { get; set; }
132+
public List<string>? Break { get; set; }
133+
public string? WillBeGood { get; set; }
134+
}
135+
136+
// Example types for GitHub issue 63054: Reused types across different hierarchies
137+
public sealed class ProjectResponse
138+
{
139+
public required ProjectAddressResponse Address { get; init; }
140+
public required ProjectBuilderResponse Builder { get; init; }
141+
}
142+
143+
public sealed class ProjectAddressResponse
144+
{
145+
public required CityResponse City { get; init; }
146+
}
147+
148+
public sealed class ProjectBuilderResponse
149+
{
150+
public required CityResponse City { get; init; }
151+
}
152+
153+
public sealed class CityResponse
154+
{
155+
public string Name { get; set; } = "";
156+
}
157+
158+
// Example types for GitHub issue 63211: Nullable reference types
159+
public sealed class Subscription
160+
{
161+
public required string Id { get; set; }
162+
public required RefProfile PrimaryUser { get; set; }
163+
public RefProfile? SecondaryUser { get; set; }
164+
}
165+
166+
public sealed class RefProfile
167+
{
168+
public required RefUser User { get; init; }
169+
}
170+
171+
public sealed class RefUser
172+
{
173+
public string Name { get; set; } = "";
174+
public string Email { get; set; } = "";
175+
}
114176
}

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=schemas-by-ref.verified.txt

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,72 @@
570570
}
571571
}
572572
}
573+
},
574+
"/schemas-by-ref/config-with-generic-lists": {
575+
"post": {
576+
"tags": [
577+
"Sample"
578+
],
579+
"requestBody": {
580+
"content": {
581+
"application/json": {
582+
"schema": {
583+
"$ref": "#/components/schemas/Config"
584+
}
585+
}
586+
},
587+
"required": true
588+
},
589+
"responses": {
590+
"200": {
591+
"description": "OK"
592+
}
593+
}
594+
}
595+
},
596+
"/schemas-by-ref/project-response": {
597+
"post": {
598+
"tags": [
599+
"Sample"
600+
],
601+
"requestBody": {
602+
"content": {
603+
"application/json": {
604+
"schema": {
605+
"$ref": "#/components/schemas/ProjectResponse"
606+
}
607+
}
608+
},
609+
"required": true
610+
},
611+
"responses": {
612+
"200": {
613+
"description": "OK"
614+
}
615+
}
616+
}
617+
},
618+
"/schemas-by-ref/subscription": {
619+
"post": {
620+
"tags": [
621+
"Sample"
622+
],
623+
"requestBody": {
624+
"content": {
625+
"application/json": {
626+
"schema": {
627+
"$ref": "#/components/schemas/Subscription"
628+
}
629+
}
630+
},
631+
"required": true
632+
},
633+
"responses": {
634+
"200": {
635+
"description": "OK"
636+
}
637+
}
638+
}
573639
}
574640
},
575641
"components": {
@@ -633,6 +699,60 @@
633699
}
634700
}
635701
},
702+
"CityResponse": {
703+
"type": "object",
704+
"properties": {
705+
"name": {
706+
"type": "string"
707+
}
708+
}
709+
},
710+
"Config": {
711+
"type": "object",
712+
"properties": {
713+
"items1": {
714+
"type": "array",
715+
"items": {
716+
"$ref": "#/components/schemas/ConfigItem"
717+
}
718+
},
719+
"items2": {
720+
"type": "array",
721+
"items": {
722+
"$ref": "#/components/schemas/ConfigItem"
723+
}
724+
}
725+
}
726+
},
727+
"ConfigItem": {
728+
"type": "object",
729+
"properties": {
730+
"id": {
731+
"type": "integer",
732+
"format": "int32",
733+
"nullable": true
734+
},
735+
"lang": {
736+
"type": "string",
737+
"nullable": true
738+
},
739+
"words": {
740+
"type": "object",
741+
"nullable": true
742+
},
743+
"break": {
744+
"type": "array",
745+
"items": {
746+
"type": "string"
747+
},
748+
"nullable": true
749+
},
750+
"willBeGood": {
751+
"type": "string",
752+
"nullable": true
753+
}
754+
}
755+
},
636756
"ContainerType": {
637757
"type": "object",
638758
"properties": {
@@ -856,6 +976,66 @@
856976
}
857977
}
858978
},
979+
"ProjectAddressResponse": {
980+
"required": [
981+
"city"
982+
],
983+
"type": "object",
984+
"properties": {
985+
"city": {
986+
"$ref": "#/components/schemas/CityResponse"
987+
}
988+
}
989+
},
990+
"ProjectBuilderResponse": {
991+
"required": [
992+
"city"
993+
],
994+
"type": "object",
995+
"properties": {
996+
"city": {
997+
"$ref": "#/components/schemas/CityResponse"
998+
}
999+
}
1000+
},
1001+
"ProjectResponse": {
1002+
"required": [
1003+
"address",
1004+
"builder"
1005+
],
1006+
"type": "object",
1007+
"properties": {
1008+
"address": {
1009+
"$ref": "#/components/schemas/ProjectAddressResponse"
1010+
},
1011+
"builder": {
1012+
"$ref": "#/components/schemas/ProjectBuilderResponse"
1013+
}
1014+
}
1015+
},
1016+
"RefProfile": {
1017+
"required": [
1018+
"user"
1019+
],
1020+
"type": "object",
1021+
"properties": {
1022+
"user": {
1023+
"$ref": "#/components/schemas/RefUser"
1024+
}
1025+
},
1026+
"nullable": true
1027+
},
1028+
"RefUser": {
1029+
"type": "object",
1030+
"properties": {
1031+
"name": {
1032+
"type": "string"
1033+
},
1034+
"email": {
1035+
"type": "string"
1036+
}
1037+
}
1038+
},
8591039
"Root": {
8601040
"type": "object",
8611041
"properties": {
@@ -930,6 +1110,24 @@
9301110
}
9311111
}
9321112
},
1113+
"Subscription": {
1114+
"required": [
1115+
"id",
1116+
"primaryUser"
1117+
],
1118+
"type": "object",
1119+
"properties": {
1120+
"id": {
1121+
"type": "string"
1122+
},
1123+
"primaryUser": {
1124+
"$ref": "#/components/schemas/RefProfile"
1125+
},
1126+
"secondaryUser": {
1127+
"$ref": "#/components/schemas/RefProfile"
1128+
}
1129+
}
1130+
},
9331131
"Tag": {
9341132
"required": [
9351133
"name"

0 commit comments

Comments
 (0)