Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private static string AnnotationsDiscriminatorNameSelector(Type baseType)

if (jsonPolymorphicAttributes != null)
{
return jsonPolymorphicAttributes.TypeDiscriminatorPropertyName;
return jsonPolymorphicAttributes.TypeDiscriminatorPropertyName ?? "$type";
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,24 @@
}
}
},
"/SystemTextJsonAnimals": {
"/SystemTextJsonCustomDiscriminatorAnimals": {
"post": {
"tags": [
"SystemTextJsonAnimals"
"SystemTextJsonCustomDiscriminatorAnimals"
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/SystemTextJsonAnimal"
"$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal"
},
{
"$ref": "#/components/schemas/SystemTextJsonCat"
"$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat"
},
{
"$ref": "#/components/schemas/SystemTextJsonDog"
"$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog"
}
]
}
Expand All @@ -144,13 +144,13 @@
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/SystemTextJsonAnimal"
"$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal"
},
{
"$ref": "#/components/schemas/SystemTextJsonCat"
"$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat"
},
{
"$ref": "#/components/schemas/SystemTextJsonDog"
"$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog"
}
]
}
Expand All @@ -159,13 +159,75 @@
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/SystemTextJsonAnimal"
"$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal"
},
{
"$ref": "#/components/schemas/SystemTextJsonCat"
"$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat"
},
{
"$ref": "#/components/schemas/SystemTextJsonDog"
"$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog"
}
]
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/SystemTextJsonDefaultDiscriminatorAnimals": {
"post": {
"tags": [
"SystemTextJsonDefaultDiscriminatorAnimals"
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/SystemTextJsonDefaultDiscriminatorAnimal"
},
{
"$ref": "#/components/schemas/SystemTextJsonDefaultDiscriminatorCat"
},
{
"$ref": "#/components/schemas/SystemTextJsonDefaultDiscriminatorDog"
}
]
}
},
"text/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/SystemTextJsonDefaultDiscriminatorAnimal"
},
{
"$ref": "#/components/schemas/SystemTextJsonDefaultDiscriminatorCat"
},
{
"$ref": "#/components/schemas/SystemTextJsonDefaultDiscriminatorDog"
}
]
}
},
"application/*+json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/SystemTextJsonDefaultDiscriminatorAnimal"
},
{
"$ref": "#/components/schemas/SystemTextJsonDefaultDiscriminatorCat"
},
{
"$ref": "#/components/schemas/SystemTextJsonDefaultDiscriminatorDog"
}
]
}
Expand Down Expand Up @@ -282,7 +344,7 @@
}
]
},
"SystemTextJsonAnimal": {
"SystemTextJsonCustomDiscriminatorAnimal": {
"required": [
"animalType"
],
Expand All @@ -297,15 +359,72 @@
"discriminator": {
"propertyName": "animalType",
"mapping": {
"Cat": "#/components/schemas/SystemTextJsonCat",
"Dog": "#/components/schemas/SystemTextJsonDog"
"Cat": "#/components/schemas/SystemTextJsonCustomDiscriminatorCat",
"Dog": "#/components/schemas/SystemTextJsonCustomDiscriminatorDog"
}
}
},
"SystemTextJsonCustomDiscriminatorCat": {
"allOf": [
{
"$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal"
},
{
"type": "object",
"properties": {
"catSpecificProperty": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
}
]
},
"SystemTextJsonCustomDiscriminatorDog": {
"allOf": [
{
"$ref": "#/components/schemas/SystemTextJsonCustomDiscriminatorAnimal"
},
{
"type": "object",
"properties": {
"dogSpecificProperty": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
}
]
},
"SystemTextJsonDefaultDiscriminatorAnimal": {
"required": [
"$type"
],
"type": "object",
"properties": {
"$type": {
"type": "string"
},
"animalType": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false,
"discriminator": {
"propertyName": "$type",
"mapping": {
"Cat": "#/components/schemas/SystemTextJsonDefaultDiscriminatorCat",
"Dog": "#/components/schemas/SystemTextJsonDefaultDiscriminatorDog"
}
}
},
"SystemTextJsonCat": {
"SystemTextJsonDefaultDiscriminatorCat": {
"allOf": [
{
"$ref": "#/components/schemas/SystemTextJsonAnimal"
"$ref": "#/components/schemas/SystemTextJsonDefaultDiscriminatorAnimal"
},
{
"type": "object",
Expand All @@ -319,10 +438,10 @@
}
]
},
"SystemTextJsonDog": {
"SystemTextJsonDefaultDiscriminatorDog": {
"allOf": [
{
"$ref": "#/components/schemas/SystemTextJsonAnimal"
"$ref": "#/components/schemas/SystemTextJsonDefaultDiscriminatorAnimal"
},
{
"type": "object",
Expand Down
Loading