-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
help-wantedA change up for grabs for contributions from the communityA change up for grabs for contributions from the community
Description
Using Swashbuckle.AspNetCore 6.2.3
Classes definition
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Runtime.Serialization;
using System.Runtime.Serialization;
namespace Pets
{
/// <summary>
/// Pet
/// </summary>
public class Pet
{
/// <summary>
/// Gets or Sets Name
/// </summary>
public string Name { get; set; }
}
/// <summary>
/// A representation of a cat. Note that `Cat` will be used as the discriminator value.
/// </summary>
public class Cat : Pet
{
/// <summary>
/// The measured skill for hunting
/// </summary>
/// <value>The measured skill for hunting</value>
[JsonConverter(typeof(StringEnumConverter))]
public enum HuntingSkillEnum
{
[EnumMember(Value = "clueless")]
Clueless = 1,
[EnumMember(Value = "lazy")]
Lazy = 2,
[EnumMember(Value = "adventurous")]
Adventurous = 3,
[EnumMember(Value = "aggressive")]
Aggressive = 4
}
/// <summary>
/// The measured skill for hunting
/// </summary>
/// <value>The measured skill for hunting</value>
public HuntingSkillEnum HuntingSkill { get; set; }
}
/// <summary>
/// A representation of a dog. Note that `Dog` will be used as the discriminator value.
/// </summary>
[DataContract(Name = "Dog")]
public class Dog : Pet
{
/// <summary>
/// the size of the pack the dog is from
/// </summary>
/// <value>the size of the pack the dog is from</value>
public int PackSize { get; set; }
}
/// <summary>
/// A representation of a bulldog. Note that `BullDog` will be used as the discriminator value.
/// </summary>
[DataContract(Name = "BullDog")]
public class BullDog : Dog
{
public bool IsFriendly { get; set; }
}
}Service configuration
services.AddSwaggerGen(options =>
{
options.EnableAnnotations(enableAnnotationsForInheritance: false, enableAnnotationsForPolymorphism: false);
options.UseAllOfForInheritance();
options.SelectDiscriminatorNameUsing(_ => "discriminator");
options.SelectDiscriminatorValueUsing(_ => _.Name);
});With these classes the openapi document is different from the one proposed at
My output doc:
{
"openapi": "3.0.1",
"paths": {
...
},
"components": {
"schemas": {
"BullDog": {
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/Dog"
}
],
"properties": {
"isFriendly": {
"type": "boolean"
}
},
"additionalProperties": false
},
"Cat": {
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/Pet"
}
],
"properties": {
"huntingSkill": {
"$ref": "#/components/schemas/HuntingSkillEnum"
}
},
"additionalProperties": false
},
"Dog": {
"required": [
"discriminator"
],
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/Pet"
}
],
"properties": {
"discriminator": {
"type": "string"
},
"packSize": {
"type": "integer",
"format": "int32"
}
},
"additionalProperties": false,
"discriminator": {
"propertyName": "discriminator",
"mapping": {
"Dog": "#/components/schemas/Dog",
"BullDog": "#/components/schemas/BullDog"
}
}
},
"HuntingSkillEnum": {
"enum": [
"Clueless",
"Lazy",
"Adventurous",
"Aggressive"
],
"type": "string"
},
"Pet": {
"required": [
"discriminator"
],
"type": "object",
"properties": {
"discriminator": {
"type": "string"
},
"name": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false,
"discriminator": {
"propertyName": "discriminator",
"mapping": {
"Pet": "#/components/schemas/Pet",
"Cat": "#/components/schemas/Cat",
"Dog": "#/components/schemas/Dog",
"BullDog": "#/components/schemas/BullDog"
}
}
},
...
}
}
}The type , properties and required properties are not inside the allOff property of JSON Schema, but at the same level.
Trying to create autogenerated client with openapi-generator-cli fails.
If I try the version with all inside the allOff property it succeeds.
Metadata
Metadata
Assignees
Labels
help-wantedA change up for grabs for contributions from the communityA change up for grabs for contributions from the community