Using Swashbuckle.AspNetCore v6.0.7
in an asp.net core
project net5.0
.
Let say I have models like these:
public enum MyEnum
{
A, B
}
and
public class MyModel
{
public MyEnum MyEnum { get; set; }
public MyEnum? MyEnum2 { get; set; }
}
and the swagger schema is generated like this:
"MyEnum": {
"enum": [
"A",
"B"
],
"type": "string"
},
"MyModel": {
"type": "object",
"properties": {
"myEnum": {
"$ref": "#/components/schemas/MyEnum"
},
"myEnum2": {
"$ref": "#/components/schemas/MyEnum"
}
},
"additionalProperties": false
}
As you can see, there is no difference between MyEnum
and MyEnum?
in the open-API JSON schema!
And seems nullable enum is not presented in the schema properly.
Does anyone have any idea how can I fix this?
Best
UseAllOfToExtendReferenceSchemas()
as domaindrivendev said. – Florrieflorry