You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing an OpenApiOperation extension using enum and I've noticed that it has a method named GetDisplayName to use a display name instead of a enum name.
Is it possible to change this attribute to be public instead internal class?
Example of use:
//my enum, used on docOptionspublicenumApiLevel{[DisplayAttribute(Name="private")]Privada=1,[Display(Name="public")]Publica=2,[Display(Name="corporate")]Corporativa=3}//my filter where i use the enuminternalclassOpenApiExampleFilter:IOperationFilter{privatereadonlyDocOptions_docOptions;publicOpenApiExampleFilter(DocOptionsdocOptions){_docOptions=docOptions;}publicvoidApply(OpenApiOperationoperation,OperationFilterContextcontext){operation.AddExtension("x-test",newOpenApiObject{["apiLevel"]=newOpenApiString(_docOptions.ApiLevel.GetDisplayName()),//here i cant use GetDisplayName() :(["apiDomain"]=newOpenApiString(_docOptions.ApiDomain)});}}
On the other hand, one might want to differ between DataAnnotations.Display for MVC purposes, and OpenApi.Attributes.Display for OpenAPI descriptions, I think? Not sure what the intended usage for the attribute is, other than to annotate your classes exposed from your API?
On the other hand, one might want to differ between DataAnnotations.Display for MVC purposes, and OpenApi.Attributes.Display for OpenAPI descriptions, I think? Not sure what the intended usage for the attribute is, other than to annotate your classes exposed from your API?
I was analyzing the code. Display attribute is used to standardize the display name of the enum.
And get enum from display name on StringExtensions
In my code i'm using to solve the same problem, i need to expose this enums using lower case and translated.
Both attribute is used to the same thing, but to use from System.ComponentModel.DataAnnotations is necessary install the package System.ComponentModel.Annotations.
I don't know if reference this package in this project is a problem. If not, this change make sense and is simple.
I made this change in my local branch and all test have passed, i can push if there is no problem.
CodeCasterNL I agree less code is more, and the problem with System.ComponentModel.DataAnnotations is that it pulls in all kinds other code that we don't use and don't support. The DisplayAttribute class is only a few lines of code. I'd rather not take another dependency for just this small feature.
Darrel (@darrelmiller) sorry, I meant System.ComponentModel.DisplayNameAttribute all along, which is covered in netstandard2.0. You're right in that referencing the package System.ComponentModel.DataAnnotations would be overkill to remove like ten lines of code.
Activity
darrelmiller commentedon Jun 17, 2022
That seems like a reasonable request to me.
CodeCasterNL commentedon Aug 4, 2022
Darrel (@darrelmiller) any reason not to use
System.ComponentModel.DataAnnotations.DisplayAttributebut to roll your own?Perhaps remove it and use the BCL one? This library targets NETStandard 2.0, which covers the existing attribute (.NET Framework 4+, .NET Core 1+).
fernandolamp commentedon Aug 4, 2022
This make sense. I can change if Darrel (@darrelmiller) agrees.
CodeCasterNL commentedon Aug 5, 2022
On the other hand, one might want to differ between
DataAnnotations.Displayfor MVC purposes, andOpenApi.Attributes.Displayfor OpenAPI descriptions, I think? Not sure what the intended usage for the attribute is, other than to annotate your classes exposed from your API?fernandolamp commentedon Aug 10, 2022
I was analyzing the code. Display attribute is used to standardize the display name of the enum.
And get enum from display name on
StringExtensionsOpenAPI.NET/src/Microsoft.OpenApi/Extensions/StringExtensions.cs
Line 19 in a17303c
In my code i'm using to solve the same problem, i need to expose this enums using lower case and translated.
Both attribute is used to the same thing, but to use from
System.ComponentModel.DataAnnotationsis necessary install the packageSystem.ComponentModel.Annotations.I don't know if reference this package in this project is a problem. If not, this change make sense and is simple.
I made this change in my local branch and all test have passed, i can push if there is no problem.
CodeCasterNL commentedon Aug 14, 2022
Maggie Kimani (@MaggieKimani1) or Darrel (@darrelmiller) can you chime in on the discussion? Does the attribute need to exist in the first place? Less code being more and all.
darrelmiller commentedon Aug 16, 2022
CodeCasterNL I agree less code is more, and the problem with System.ComponentModel.DataAnnotations is that it pulls in all kinds other code that we don't use and don't support. The DisplayAttribute class is only a few lines of code. I'd rather not take another dependency for just this small feature.
CodeCasterNL commentedon Aug 16, 2022
Darrel (@darrelmiller) sorry, I meant
System.ComponentModel.DisplayNameAttributeall along, which is covered in netstandard2.0. You're right in that referencing the packageSystem.ComponentModel.DataAnnotationswould be overkill to remove like ten lines of code.