Make simple usage of Microsoft.OpenAPI
trimmable
#1114
Labels
status:needs-discussion
An issue that requires more discussion internally before resolving
type:enhancement
Enhancement request targeting an existing experience
I'm trying to use this library in a console app. When trying to publish using trimming, I encountered the fact that this library is not trimmable for even the simplest of cases.
Is your feature request related to a problem? Please describe.
The library is not trimmable when only the following functionality is used:
new OpenApiDocument { ... }
OpenApiJsonWriter
orOpenApiYamlWriter
Since these 2 steps don't feel like they are using reflection, I would expect this to be trimmable, which it is not. AFAIK, this is due to
EnumExtensions.GetDisplayName()
:Describe the solution you'd like
In short, make
Microsoft.OpenAPI
trimmable for the simple scenario as described before (creating the model and serializing it).The code that triggers this is:
This is only used to associate a string with an enum value. My proposed solution is:
Wrap this logic into an
IEnumDisplayValueStrategy
/DefaultEnumDisplayValueStrategy
that we can supply on theOpenApiWriterSettings
. End users can implement this themselves, allowing the compiler to trim theDefaultEnumDisplayValueStrategy
, thus removing the reflection code.Describe alternatives you've considered
[Display]
attribute, create an extension method that maps Enum to string. This would look something like this:The text was updated successfully, but these errors were encountered: