-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
Describe the bug
A nullable enum property creates a C# class with a property that has an empty class as its type.
Version of NSwag toolchain, computer and .NET runtime used
NSwagStudio 14.6.3.0 with .NET 10
To Reproduce
I have a simple object with a nullable enum property.
{
"openapi": "3.1.1",
"info": {
"title": "TestApi | v1",
"version": "1.0.0"
},
"components": {
"schemas": {
"ResponseObject": {
"type": "object",
"properties": {
"testProperty": {
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/components/schemas/MyEnum"
}
]
}
}
},
"MyEnum": {
"enum": [
"Entry1",
"Entry2",
null
]
}
}
}
}
When creating a C# client out of this, the resulting property is:
public TestProperty? TestProperty { get; set; } = default!;
with TestProperty being an empty class (besided the AdditionalProperties)
public partial class TestProperty
{
private System.Collections.Generic.IDictionary<string, object>? _additionalProperties;
[Newtonsoft.Json.JsonExtensionData]
public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
{
get { return _additionalProperties ?? (_additionalProperties = new System.Collections.Generic.Dictionary<string, object>()); }
set { _additionalProperties = value; }
}
}
The enum itself is correctly created, but unsused.
public enum MyEnum
{
[System.Runtime.Serialization.EnumMember(Value = @"Entry1")]
Entry1 = 0,
[System.Runtime.Serialization.EnumMember(Value = @"Entry2")]
Entry2 = 1,
}
Expected behavior
A property that uses the correct nullable enum.
public MyEnum? TestProperty { get; set; }
Metadata
Metadata
Assignees
Labels
No labels