-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Csharp : Generate enum with annotations #2154
Comments
What library are you using to generate the swagger/openapi spec? |
If you use Swashbuckle to generate the swagger/openapi specification, I recommend:
See the README for details. |
Ok, interesting... :-) My question now: What do you expect as output? Do you want that it preserves the display name, the field name and number? Because I think that is not really possible (ie. not describable) in OpenAPI/Swagger. |
If you generate the spec with NSwag (not Swashbuckle) it will always generate an |
With Unchase.Swashbuckle.AspNetCore.Extensions nuget-package you can generate from: [DataContract]
public enum Title
{
[Description("None enum description")]
[EnumMember]
None = 0,
[Description("Miss enum description")]
[EnumMember]
Miss,
[Description("Mr enum description")]
[EnumMember]
Mr
} This: /// <summary>Sample Person title.
/// 0 = None (None enum description)
/// 1 = Miss (Miss enum description)
/// 2 = Mr (Mr enum description)</summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "9.13.35.0 (Newtonsoft.Json v11.0.0.0)")]
public enum Title
{
None = 0,
Miss = 1,
Mr = 2,
} In specification looks like this: After client code generating with NSwagStudio or Unchase OpenAPI (Swagger) Connected Service your annotation just will placed in summary-comments (not in attributes). P.S. OpenAPI (Swagger) Connected Service by Dmitry Pavlov is the same, only Unchase OpenAPI (Swagger) Connected Service more flexible in customization like NSwagStudio. |
With NSwag you can also generate the summary with the GenerateEnumMappingDescription setting See #1993 |
I need Display name annotation to show name in select asp-items="Html.GetEnumSelectList()" |
How to generate enum with annotations?
My original enum :
Enum generated:
The text was updated successfully, but these errors were encountered: