Skip to content

Commit 4dc6e60

Browse files
authored
Add more schema tests (#60822)
1 parent d843809 commit 4dc6e60

File tree

4 files changed

+743
-0
lines changed

4 files changed

+743
-0
lines changed

src/OpenApi/sample/Endpoints/MapSchemasEndoints.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,72 @@ public static IEndpointRouteBuilder MapSchemasEndpoints(this IEndpointRouteBuild
3030
schemas.MapPost("/shape", (Shape shape) => { });
3131
schemas.MapPost("/weatherforecastbase", (WeatherForecastBase forecast) => { });
3232
schemas.MapPost("/person", (Person person) => { });
33+
schemas.MapPost("/category", (Category category) => { });
34+
schemas.MapPost("/container", (ContainerType container) => { });
35+
schemas.MapPost("/root", (Root root) => { });
36+
schemas.MapPost("/location", (LocationContainer location) => { });
37+
schemas.MapPost("/parent", (ParentObject parent) => Results.Ok(parent));
38+
schemas.MapPost("/child", (ChildObject child) => Results.Ok(child));
3339

3440
return endpointRouteBuilder;
3541
}
42+
43+
public sealed class Category
44+
{
45+
public required string Name { get; set; }
46+
47+
public required Category Parent { get; set; }
48+
49+
public IEnumerable<Tag> Tags { get; set; } = [];
50+
}
51+
52+
public sealed class Tag
53+
{
54+
public required string Name { get; set; }
55+
}
56+
57+
public sealed class ContainerType
58+
{
59+
public List<List<string>> Seq1 { get; set; } = [];
60+
public List<List<string>> Seq2 { get; set; } = [];
61+
}
62+
63+
public sealed class Root
64+
{
65+
public Item Item1 { get; set; } = null!;
66+
public Item Item2 { get; set; } = null!;
67+
}
68+
69+
public sealed class Item
70+
{
71+
public string[] Name { get; set; } = null!;
72+
public int value { get; set; }
73+
}
74+
75+
public sealed class LocationContainer
76+
{
77+
public required LocationDto Location { get; set; }
78+
}
79+
80+
public sealed class LocationDto
81+
{
82+
public required AddressDto Address { get; set; }
83+
}
84+
85+
public sealed class AddressDto
86+
{
87+
public required LocationDto RelatedLocation { get; set; }
88+
}
89+
90+
public sealed class ParentObject
91+
{
92+
public int Id { get; set; }
93+
public List<ChildObject> Children { get; set; } = [];
94+
}
95+
96+
public sealed class ChildObject
97+
{
98+
public int Id { get; set; }
99+
public required ParentObject Parent { get; set; }
100+
}
36101
}

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

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,138 @@
375375
}
376376
}
377377
}
378+
},
379+
"/schemas-by-ref/category": {
380+
"post": {
381+
"tags": [
382+
"Sample"
383+
],
384+
"requestBody": {
385+
"content": {
386+
"application/json": {
387+
"schema": {
388+
"$ref": "#/components/schemas/Category"
389+
}
390+
}
391+
},
392+
"required": true
393+
},
394+
"responses": {
395+
"200": {
396+
"description": "OK"
397+
}
398+
}
399+
}
400+
},
401+
"/schemas-by-ref/container": {
402+
"post": {
403+
"tags": [
404+
"Sample"
405+
],
406+
"requestBody": {
407+
"content": {
408+
"application/json": {
409+
"schema": {
410+
"$ref": "#/components/schemas/ContainerType"
411+
}
412+
}
413+
},
414+
"required": true
415+
},
416+
"responses": {
417+
"200": {
418+
"description": "OK"
419+
}
420+
}
421+
}
422+
},
423+
"/schemas-by-ref/root": {
424+
"post": {
425+
"tags": [
426+
"Sample"
427+
],
428+
"requestBody": {
429+
"content": {
430+
"application/json": {
431+
"schema": {
432+
"$ref": "#/components/schemas/Root"
433+
}
434+
}
435+
},
436+
"required": true
437+
},
438+
"responses": {
439+
"200": {
440+
"description": "OK"
441+
}
442+
}
443+
}
444+
},
445+
"/schemas-by-ref/location": {
446+
"post": {
447+
"tags": [
448+
"Sample"
449+
],
450+
"requestBody": {
451+
"content": {
452+
"application/json": {
453+
"schema": {
454+
"$ref": "#/components/schemas/LocationContainer"
455+
}
456+
}
457+
},
458+
"required": true
459+
},
460+
"responses": {
461+
"200": {
462+
"description": "OK"
463+
}
464+
}
465+
}
466+
},
467+
"/schemas-by-ref/parent": {
468+
"post": {
469+
"tags": [
470+
"Sample"
471+
],
472+
"requestBody": {
473+
"content": {
474+
"application/json": {
475+
"schema": {
476+
"$ref": "#/components/schemas/ParentObject"
477+
}
478+
}
479+
},
480+
"required": true
481+
},
482+
"responses": {
483+
"200": {
484+
"description": "OK"
485+
}
486+
}
487+
}
488+
},
489+
"/schemas-by-ref/child": {
490+
"post": {
491+
"tags": [
492+
"Sample"
493+
],
494+
"requestBody": {
495+
"content": {
496+
"application/json": {
497+
"schema": {
498+
"$ref": "#/components/schemas/ChildObject"
499+
}
500+
}
501+
},
502+
"required": true
503+
},
504+
"responses": {
505+
"200": {
506+
"description": "OK"
507+
}
508+
}
509+
}
378510
}
379511
},
380512
"components": {
@@ -391,6 +523,113 @@
391523
}
392524
}
393525
},
526+
"AddressDto": {
527+
"required": [
528+
"relatedLocation"
529+
],
530+
"type": "object",
531+
"properties": {
532+
"relatedLocation": {
533+
"$ref": "#/components/schemas/LocationDto"
534+
}
535+
}
536+
},
537+
"Category": {
538+
"required": [
539+
"name",
540+
"parent"
541+
],
542+
"type": "object",
543+
"properties": {
544+
"name": {
545+
"type": "string"
546+
},
547+
"parent": {
548+
"$ref": "#/components/schemas/Category"
549+
},
550+
"tags": { }
551+
}
552+
},
553+
"ChildObject": {
554+
"required": [
555+
"parent"
556+
],
557+
"type": "object",
558+
"properties": {
559+
"id": {
560+
"type": "integer",
561+
"format": "int32"
562+
},
563+
"parent": {
564+
"$ref": "#/components/schemas/ParentObject"
565+
}
566+
}
567+
},
568+
"ContainerType": {
569+
"type": "object",
570+
"properties": {
571+
"seq1": {
572+
"type": "array",
573+
"items": {
574+
"type": "array",
575+
"items": {
576+
"type": "string"
577+
}
578+
}
579+
},
580+
"seq2": {
581+
"type": "array",
582+
"items": { }
583+
}
584+
}
585+
},
586+
"Item": {
587+
"type": "object",
588+
"properties": {
589+
"name": { },
590+
"value": {
591+
"type": "integer",
592+
"format": "int32"
593+
}
594+
}
595+
},
596+
"LocationContainer": {
597+
"required": [
598+
"location"
599+
],
600+
"type": "object",
601+
"properties": {
602+
"location": {
603+
"$ref": "#/components/schemas/LocationDto"
604+
}
605+
}
606+
},
607+
"LocationDto": {
608+
"required": [
609+
"address"
610+
],
611+
"type": "object",
612+
"properties": {
613+
"address": {
614+
"$ref": "#/components/schemas/AddressDto"
615+
}
616+
}
617+
},
618+
"ParentObject": {
619+
"type": "object",
620+
"properties": {
621+
"id": {
622+
"type": "integer",
623+
"format": "int32"
624+
},
625+
"children": {
626+
"type": "array",
627+
"items": {
628+
"$ref": "#/components/schemas/ChildObject"
629+
}
630+
}
631+
}
632+
},
394633
"Person": {
395634
"required": [
396635
"discriminator"
@@ -454,6 +693,17 @@
454693
}
455694
}
456695
},
696+
"Root": {
697+
"type": "object",
698+
"properties": {
699+
"item1": {
700+
"$ref": "#/components/schemas/Item"
701+
},
702+
"item2": {
703+
"$ref": "#/components/schemas/Item"
704+
}
705+
}
706+
},
457707
"Shape": {
458708
"required": [
459709
"$type"
@@ -517,6 +767,17 @@
517767
}
518768
}
519769
},
770+
"Tag": {
771+
"required": [
772+
"name"
773+
],
774+
"type": "object",
775+
"properties": {
776+
"name": {
777+
"type": "string"
778+
}
779+
}
780+
},
520781
"Triangle": {
521782
"type": "object",
522783
"properties": {

0 commit comments

Comments
 (0)