-
Notifications
You must be signed in to change notification settings - Fork 253
Avoid use of unbounded reflection to resolve Enum display names #1715
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
Comments
Thanks for bringing this up. Do you think we could simply add the AOT attributes ( |
Yep, that's an option. It does get a little bit interested since we're targeting So our two approaches would be:
The first seemed cleaner to me, especially given that there is a finite set enums and I don't expect them to change much (as long as we are targeting OpenAPI v3.x) |
While digging into implementing this, I realized that the I believe that the annotations referenced above will help with this but I have to give it a try. |
In the kiota libraries, we've used the first option from the blog post which is using if definitions. If we decided to go with a registration option instead, I like to see what would the developer experience be before we start doing any work. |
This approach would require that we add targets for net8+ place to the Microsoft.OpenApi library. It's feasible, but I think it's a bit more expensive implementation wise then figuring out a way to get rid of the reflection altogether.
Would love your thoughts on #1717. I tried to address the trim warnings with a focus on source/binary compat for end users. |
In a few places in the OpenAPI.NET codebase, the
GetDisplayName
method is used to resolve a prettified display name associated with an enum value from the[Display]
attribute.OpenAPI.NET/src/Microsoft.OpenApi/Extensions/EnumExtensions.cs
Line 40 in 3d971de
The use of unbounded reflection in this codepath makes it difficult to enable trimming for applications that use Microsoft.OpenApi in any capacity.
OpenAPI.NET/src/Microsoft.OpenApi/Extensions/EnumExtensions.cs
Line 24 in 3d971de
Given the limited set of enums used in the application, I'd recommend an alternative reflection-free approach for resolving display names associated with enums. Something like a Enum <> string cache can be used to resolve this.
Assuming folks are OK with this approach, I'd be happy to submit a PR for review.
cc: @MaggieKimani1 @baywet
The text was updated successfully, but these errors were encountered: