Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JsonStringEnumMemberName instead of System.Runtime.Serialization.EnumMember when using System.Text.Json #5088

Open
mattrandle opened this issue Jan 15, 2025 · 1 comment

Comments

@mattrandle
Copy link

When using System.Text.Json as the serialization option in .NET 9, nswag is still marking up enums with System.Runtime.Serialization.EnumMember which is ignored

So this

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.2.0.0 (NJsonSchema v11.1.0.0 (Newtonsoft.Json v13.0.0.0))")]
public enum SmartRoutingLabelType
{
    [System.Runtime.Serialization.EnumMember(Value = @"parcel-connect-uk")]
    ParcelConnectUk = 0,

    [System.Runtime.Serialization.EnumMember(Value = @"parcel-international-uk")]
    ParcelInternationalUk = 1,

    [System.Runtime.Serialization.EnumMember(Value = @"domestic-uk")]
    DomesticUk = 2,

    [System.Runtime.Serialization.EnumMember(Value = @"international-uk")]
    InternationalUk = 3,

    [System.Runtime.Serialization.EnumMember(Value = @"express-uk")]
    ExpressUk = 4,
}

Should be,

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.2.0.0 (NJsonSchema v11.1.0.0 (Newtonsoft.Json v13.0.0.0))")]
public enum SmartRoutingLabelType
{

    [System.Text.Json.Serialization.JsonStringEnumMemberName(@"parcel-connect-uk")]
    ParcelConnectUk = 0,

    [System.Text.Json.Serialization.JsonStringEnumMemberName(@"parcel-international-uk")]
    ParcelInternationalUk = 1,

    [System.Text.Json.Serialization.JsonStringEnumMemberName(@"domestic-uk")]
    DomesticUk = 2,

    [System.Text.Json.Serialization.JsonStringEnumMemberName(@"international-uk")]
    InternationalUk = 3,

    [System.Text.Json.Serialization.JsonStringEnumMemberName(@"express-uk")]
    ExpressUk = 4,
}

I noticed this for the controller generation but I am guessing it is the same for the client also.

Was going to have a go at doing this myself but cannot find the liquid file where the enum is emitted - can anyone point me in right direction ?

@mattrandle
Copy link
Author

Nevermind - can see this is an issue with NJsonSchema

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant