diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=NSwagClientExample.Startup_swaggerRequestUri=v1.DotNet8_0.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=NSwagClientExample.Startup_swaggerRequestUri=v1.DotNet8_0.verified.txt index d99f5dd3b0..022f86beda 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=NSwagClientExample.Startup_swaggerRequestUri=v1.DotNet8_0.verified.txt +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=NSwagClientExample.Startup_swaggerRequestUri=v1.DotNet8_0.verified.txt @@ -118,10 +118,10 @@ } } }, - "/SystemTextJsonCustomDiscriminatorAnimals": { + "/SystemTextJsonAnimals": { "post": { "tags": [ - "SystemTextJsonCustomDiscriminatorAnimals" + "SystemTextJsonAnimals" ], "requestBody": { "content": { @@ -129,13 +129,13 @@ "schema": { "oneOf": [ { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" + "$ref": "#/components/schemas/SystemTextJsonAnimal" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat" + "$ref": "#/components/schemas/SystemTextJsonCat" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog" + "$ref": "#/components/schemas/SystemTextJsonDog" } ] } @@ -144,13 +144,13 @@ "schema": { "oneOf": [ { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" + "$ref": "#/components/schemas/SystemTextJsonAnimal" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat" + "$ref": "#/components/schemas/SystemTextJsonCat" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog" + "$ref": "#/components/schemas/SystemTextJsonDog" } ] } @@ -159,13 +159,13 @@ "schema": { "oneOf": [ { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" + "$ref": "#/components/schemas/SystemTextJsonAnimal" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat" + "$ref": "#/components/schemas/SystemTextJsonCat" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog" + "$ref": "#/components/schemas/SystemTextJsonDog" } ] } @@ -344,7 +344,7 @@ } ] }, - "SystemTextJsonCustomDiscriminatorAnimal": { + "SystemTextJsonAnimal": { "required": [ "animalType" ], @@ -359,15 +359,15 @@ "discriminator": { "propertyName": "animalType", "mapping": { - "Cat": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat", - "Dog": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog" + "Cat": "#/components/schemas/SystemTextJsonCat", + "Dog": "#/components/schemas/SystemTextJsonDog" } } }, - "SystemTextJsonCustomDiscriminatorCat": { + "SystemTextJsonCat": { "allOf": [ { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" + "$ref": "#/components/schemas/SystemTextJsonAnimal" }, { "type": "object", @@ -381,23 +381,6 @@ } ] }, - "SystemTextJsonCustomDiscriminatorDog": { - "allOf": [ - { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" - }, - { - "type": "object", - "properties": { - "dogSpecificProperty": { - "type": "string", - "nullable": true - } - }, - "additionalProperties": false - } - ] - }, "SystemTextJsonDefaultDiscriminatorAnimal": { "required": [ "$type" @@ -454,6 +437,23 @@ "additionalProperties": false } ] + }, + "SystemTextJsonDog": { + "allOf": [ + { + "$ref": "#/components/schemas/SystemTextJsonAnimal" + }, + { + "type": "object", + "properties": { + "dogSpecificProperty": { + "type": "string", + "nullable": true + } + }, + "additionalProperties": false + } + ] } } } diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=NSwagClientExample.Startup_swaggerRequestUri=v1.DotNet9_0.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=NSwagClientExample.Startup_swaggerRequestUri=v1.DotNet9_0.verified.txt index d99f5dd3b0..022f86beda 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=NSwagClientExample.Startup_swaggerRequestUri=v1.DotNet9_0.verified.txt +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=NSwagClientExample.Startup_swaggerRequestUri=v1.DotNet9_0.verified.txt @@ -118,10 +118,10 @@ } } }, - "/SystemTextJsonCustomDiscriminatorAnimals": { + "/SystemTextJsonAnimals": { "post": { "tags": [ - "SystemTextJsonCustomDiscriminatorAnimals" + "SystemTextJsonAnimals" ], "requestBody": { "content": { @@ -129,13 +129,13 @@ "schema": { "oneOf": [ { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" + "$ref": "#/components/schemas/SystemTextJsonAnimal" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat" + "$ref": "#/components/schemas/SystemTextJsonCat" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog" + "$ref": "#/components/schemas/SystemTextJsonDog" } ] } @@ -144,13 +144,13 @@ "schema": { "oneOf": [ { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" + "$ref": "#/components/schemas/SystemTextJsonAnimal" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat" + "$ref": "#/components/schemas/SystemTextJsonCat" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog" + "$ref": "#/components/schemas/SystemTextJsonDog" } ] } @@ -159,13 +159,13 @@ "schema": { "oneOf": [ { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" + "$ref": "#/components/schemas/SystemTextJsonAnimal" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat" + "$ref": "#/components/schemas/SystemTextJsonCat" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog" + "$ref": "#/components/schemas/SystemTextJsonDog" } ] } @@ -344,7 +344,7 @@ } ] }, - "SystemTextJsonCustomDiscriminatorAnimal": { + "SystemTextJsonAnimal": { "required": [ "animalType" ], @@ -359,15 +359,15 @@ "discriminator": { "propertyName": "animalType", "mapping": { - "Cat": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat", - "Dog": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog" + "Cat": "#/components/schemas/SystemTextJsonCat", + "Dog": "#/components/schemas/SystemTextJsonDog" } } }, - "SystemTextJsonCustomDiscriminatorCat": { + "SystemTextJsonCat": { "allOf": [ { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" + "$ref": "#/components/schemas/SystemTextJsonAnimal" }, { "type": "object", @@ -381,23 +381,6 @@ } ] }, - "SystemTextJsonCustomDiscriminatorDog": { - "allOf": [ - { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" - }, - { - "type": "object", - "properties": { - "dogSpecificProperty": { - "type": "string", - "nullable": true - } - }, - "additionalProperties": false - } - ] - }, "SystemTextJsonDefaultDiscriminatorAnimal": { "required": [ "$type" @@ -454,6 +437,23 @@ "additionalProperties": false } ] + }, + "SystemTextJsonDog": { + "allOf": [ + { + "$ref": "#/components/schemas/SystemTextJsonAnimal" + }, + { + "type": "object", + "properties": { + "dogSpecificProperty": { + "type": "string", + "nullable": true + } + }, + "additionalProperties": false + } + ] } } } diff --git a/test/WebSites/NswagClientExample/Controllers/SystemTextJsonAnimalsController.cs b/test/WebSites/NswagClientExample/Controllers/SystemTextJsonAnimalsController.cs new file mode 100644 index 0000000000..0c07ad83fb --- /dev/null +++ b/test/WebSites/NswagClientExample/Controllers/SystemTextJsonAnimalsController.cs @@ -0,0 +1,35 @@ +using System.ComponentModel.DataAnnotations; +using System.Text.Json.Serialization; +using Microsoft.AspNetCore.Mvc; + +namespace NSwagClientExample.Controllers; + +[ApiController] +[Route("[controller]")] +public class SystemTextJsonAnimalsController : ControllerBase +{ + [HttpPost] + [Produces("application/json")] + public void CreateAnimal([Required]SystemTextJsonAnimal animal) + { + throw new NotImplementedException(); + } +} + +[JsonPolymorphic(TypeDiscriminatorPropertyName = "animalType")] +[JsonDerivedType(typeof(SystemTextJsonCat), "Cat")] +[JsonDerivedType(typeof(SystemTextJsonDog), "Dog")] +public class SystemTextJsonAnimal +{ + public string AnimalType { get; set; } +} + +public class SystemTextJsonCat : SystemTextJsonAnimal +{ + public string CatSpecificProperty { get; set; } +} + +public class SystemTextJsonDog : SystemTextJsonAnimal +{ + public string DogSpecificProperty { get; set; } +} diff --git a/test/WebSites/NswagClientExample/Controllers/SystemTextJsonCustomDiscriminatorAnimalsController.cs b/test/WebSites/NswagClientExample/Controllers/SystemTextJsonCustomDiscriminatorAnimalsController.cs deleted file mode 100644 index 1ad4e65d4e..0000000000 --- a/test/WebSites/NswagClientExample/Controllers/SystemTextJsonCustomDiscriminatorAnimalsController.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Text.Json.Serialization; -using Microsoft.AspNetCore.Mvc; - -namespace NSwagClientExample.Controllers; - -[ApiController] -[Route("[controller]")] -public class SystemTextJsonCustomDiscriminatorAnimalsController : ControllerBase -{ - [HttpPost] - [Produces("application/json")] - public void CreateAnimal([Required] SystemTextJsonCustomDiscriminatorAnimal animal) - { - throw new NotImplementedException(); - } -} - -[JsonPolymorphic(TypeDiscriminatorPropertyName = "animalType")] -[JsonDerivedType(typeof(SystemTextJsonCustomDiscriminatorCat), "Cat")] -[JsonDerivedType(typeof(SystemTextJsonCustomDiscriminatorDog), "Dog")] -public class SystemTextJsonCustomDiscriminatorAnimal -{ - public string AnimalType { get; set; } -} - -public class SystemTextJsonCustomDiscriminatorCat : SystemTextJsonCustomDiscriminatorAnimal -{ - public string CatSpecificProperty { get; set; } -} - -public class SystemTextJsonCustomDiscriminatorDog : SystemTextJsonCustomDiscriminatorAnimal -{ - public string DogSpecificProperty { get; set; } -} diff --git a/test/WebSites/NswagClientExample/Controllers/SystemTextJsonDefaultDiscriminatorAnimalsController.cs b/test/WebSites/NswagClientExample/Controllers/SystemTextJsonDefaultDiscriminatorAnimalsController.cs index 97c78b9e37..ddf3fe6554 100644 --- a/test/WebSites/NswagClientExample/Controllers/SystemTextJsonDefaultDiscriminatorAnimalsController.cs +++ b/test/WebSites/NswagClientExample/Controllers/SystemTextJsonDefaultDiscriminatorAnimalsController.cs @@ -16,7 +16,7 @@ public void CreateAnimal([Required] SystemTextJsonDefaultDiscriminatorAnimal ani } } -[JsonPolymorphic()] +[JsonPolymorphic] [JsonDerivedType(typeof(SystemTextJsonDefaultDiscriminatorCat), "Cat")] [JsonDerivedType(typeof(SystemTextJsonDefaultDiscriminatorDog), "Dog")] public class SystemTextJsonDefaultDiscriminatorAnimal diff --git a/test/WebSites/NswagClientExample/swagger_net8.0.json b/test/WebSites/NswagClientExample/swagger_net8.0.json index 800d6e8726..e65495816b 100644 --- a/test/WebSites/NswagClientExample/swagger_net8.0.json +++ b/test/WebSites/NswagClientExample/swagger_net8.0.json @@ -123,10 +123,10 @@ } } }, - "/SystemTextJsonCustomDiscriminatorAnimals": { + "/SystemTextJsonAnimals": { "post": { "tags": [ - "SystemTextJsonCustomDiscriminatorAnimals" + "SystemTextJsonAnimals" ], "requestBody": { "content": { @@ -134,13 +134,13 @@ "schema": { "oneOf": [ { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" + "$ref": "#/components/schemas/SystemTextJsonAnimal" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat" + "$ref": "#/components/schemas/SystemTextJsonCat" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog" + "$ref": "#/components/schemas/SystemTextJsonDog" } ] } @@ -149,13 +149,13 @@ "schema": { "oneOf": [ { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" + "$ref": "#/components/schemas/SystemTextJsonAnimal" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat" + "$ref": "#/components/schemas/SystemTextJsonCat" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog" + "$ref": "#/components/schemas/SystemTextJsonDog" } ] } @@ -164,13 +164,13 @@ "schema": { "oneOf": [ { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" + "$ref": "#/components/schemas/SystemTextJsonAnimal" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat" + "$ref": "#/components/schemas/SystemTextJsonCat" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog" + "$ref": "#/components/schemas/SystemTextJsonDog" } ] } @@ -349,7 +349,7 @@ } ] }, - "SystemTextJsonCustomDiscriminatorAnimal": { + "SystemTextJsonAnimal": { "required": [ "animalType" ], @@ -364,15 +364,15 @@ "discriminator": { "propertyName": "animalType", "mapping": { - "Cat": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat", - "Dog": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog" + "Cat": "#/components/schemas/SystemTextJsonCat", + "Dog": "#/components/schemas/SystemTextJsonDog" } } }, - "SystemTextJsonCustomDiscriminatorCat": { + "SystemTextJsonCat": { "allOf": [ { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" + "$ref": "#/components/schemas/SystemTextJsonAnimal" }, { "type": "object", @@ -386,23 +386,6 @@ } ] }, - "SystemTextJsonCustomDiscriminatorDog": { - "allOf": [ - { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" - }, - { - "type": "object", - "properties": { - "dogSpecificProperty": { - "type": "string", - "nullable": true - } - }, - "additionalProperties": false - } - ] - }, "SystemTextJsonDefaultDiscriminatorAnimal": { "required": [ "$type" @@ -459,6 +442,23 @@ "additionalProperties": false } ] + }, + "SystemTextJsonDog": { + "allOf": [ + { + "$ref": "#/components/schemas/SystemTextJsonAnimal" + }, + { + "type": "object", + "properties": { + "dogSpecificProperty": { + "type": "string", + "nullable": true + } + }, + "additionalProperties": false + } + ] } } } diff --git a/test/WebSites/NswagClientExample/swagger_net9.0.json b/test/WebSites/NswagClientExample/swagger_net9.0.json index 800d6e8726..e65495816b 100644 --- a/test/WebSites/NswagClientExample/swagger_net9.0.json +++ b/test/WebSites/NswagClientExample/swagger_net9.0.json @@ -123,10 +123,10 @@ } } }, - "/SystemTextJsonCustomDiscriminatorAnimals": { + "/SystemTextJsonAnimals": { "post": { "tags": [ - "SystemTextJsonCustomDiscriminatorAnimals" + "SystemTextJsonAnimals" ], "requestBody": { "content": { @@ -134,13 +134,13 @@ "schema": { "oneOf": [ { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" + "$ref": "#/components/schemas/SystemTextJsonAnimal" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat" + "$ref": "#/components/schemas/SystemTextJsonCat" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog" + "$ref": "#/components/schemas/SystemTextJsonDog" } ] } @@ -149,13 +149,13 @@ "schema": { "oneOf": [ { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" + "$ref": "#/components/schemas/SystemTextJsonAnimal" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat" + "$ref": "#/components/schemas/SystemTextJsonCat" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog" + "$ref": "#/components/schemas/SystemTextJsonDog" } ] } @@ -164,13 +164,13 @@ "schema": { "oneOf": [ { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" + "$ref": "#/components/schemas/SystemTextJsonAnimal" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat" + "$ref": "#/components/schemas/SystemTextJsonCat" }, { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog" + "$ref": "#/components/schemas/SystemTextJsonDog" } ] } @@ -349,7 +349,7 @@ } ] }, - "SystemTextJsonCustomDiscriminatorAnimal": { + "SystemTextJsonAnimal": { "required": [ "animalType" ], @@ -364,15 +364,15 @@ "discriminator": { "propertyName": "animalType", "mapping": { - "Cat": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat", - "Dog": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog" + "Cat": "#/components/schemas/SystemTextJsonCat", + "Dog": "#/components/schemas/SystemTextJsonDog" } } }, - "SystemTextJsonCustomDiscriminatorCat": { + "SystemTextJsonCat": { "allOf": [ { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" + "$ref": "#/components/schemas/SystemTextJsonAnimal" }, { "type": "object", @@ -386,23 +386,6 @@ } ] }, - "SystemTextJsonCustomDiscriminatorDog": { - "allOf": [ - { - "$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal" - }, - { - "type": "object", - "properties": { - "dogSpecificProperty": { - "type": "string", - "nullable": true - } - }, - "additionalProperties": false - } - ] - }, "SystemTextJsonDefaultDiscriminatorAnimal": { "required": [ "$type" @@ -459,6 +442,23 @@ "additionalProperties": false } ] + }, + "SystemTextJsonDog": { + "allOf": [ + { + "$ref": "#/components/schemas/SystemTextJsonAnimal" + }, + { + "type": "object", + "properties": { + "dogSpecificProperty": { + "type": "string", + "nullable": true + } + }, + "additionalProperties": false + } + ] } } }