Enum values wrongly converted #4490
Unanswered
Garfield20001
asked this question in
Q&A
Replies: 2 comments
-
If I understand this right, you need to serialize your enum as integer and provide |
Beta Was this translation helpful? Give feedback.
0 replies
-
The enumname attribute is not the problem. In the swagger description the value is set to 1 although it is the first enum value in the list (and for an int enum in C# this would normally assigned to zero)
"printerSupplier": {
"allOf": [
{
"$ref": "#/components/schemas/FluxModels.ManScan.PrinterSupplier"
}
],
"description": "Supplying company of the printer",
"example": "",
"x-enumNames": [
"Zebra"
],
"x-ms-enum": {
"name": "PrinterSupplier",
"modelAsString": false,
"values": [
{
"value": 1,
"name": "Zebra"
}
]
}
},
What I need is that in the resulting C# client that I get an enum the following way:
/// <summary>
/// Supplier of label printer
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")]
public enum PrinterSupplier
{
[System.Runtime.Serialization.EnumMember(Value = @"Zebra")]
Zebra = 1,
}
and not the wrong way (like it currently is)
/// <summary>
/// Supplier of label printer
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.20.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.0.0))")]
public enum PrinterSupplier
{
[System.Runtime.Serialization.EnumMember(Value = @"Zebra")]
Zebra = 0,
}
Thanks for help!!
René
Von: olegd-superoffice ***@***.***>
Gesendet: Montag, 21. August 2023 12:26
An: RicoSuter/NSwag ***@***.***>
Cc: René Petton ***@***.***>; Author ***@***.***>
Betreff: Re: [RicoSuter/NSwag] Enum values wrongly converted (Discussion #4490)
If I understand this right, you need to serialize your enum as integer and provide x-enumNames attribute.
—
Reply to this email directly, view it on GitHub<#4490 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BBP6PRAJQOEN6HSJ7CX6FVTXWMZVDANCNFSM6AAAAAA2W23ZHE>.
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Dear all,
I have the problem that NSwagStudio converts enums in a swagger wrong. Or the other way round. How do I have to define a swagger that a enum is converted the right way?
Here is my swagger:
{
"openapi": "3.0.1",
"components": {
"schemas": {
"FluxModels.Base.UnitLevel": {
"enum": [
"Package",
"Bundle",
"Mastercase",
"Pallet"
],
"type": "string",
"x-enumNames": [
"Package",
"Bundle",
"Mastercase",
"Pallet"
],
"x-ms-enum": {
"name": "UnitLevel",
"modelAsString": false,
"values": [
{
"value": 1,
"name": "Package"
},
{
"value": 4,
"name": "Bundle"
},
{
"value": 7,
"name": "Mastercase"
},
{
"value": 10,
"name": "Pallet"
}
]
}
}
}
}
}
And that is what I get as C# code:
namespace DataAccessLibrary.API
{
using System = global::System;
}
As you can see in the enum of the C# class e.g. the value of a Pallet is 3 but it should be 10.
How can I convince NSwagStudio to do it the right way?
Or how must the swagger look like to get the expected result?
Thanks for help!!
Beta Was this translation helpful? Give feedback.
All reactions