OpenAPI.NET icon indicating copy to clipboard operation
OpenAPI.NET copied to clipboard

Make OpenAPI.NET library trim-compatible

Open captainsafia opened this issue 1 year ago • 0 comments

This PR removes the use of reflection in GetDisplayName for enums and adds [DynamicallyAccessMembers] attributes to CloneFromCopyConstructor.

Prior to this change, using the Microsoft.OpenApi package in an application with trimming enabled would present the following warnings:

    /_/src/Microsoft.OpenApi/Extensions/EnumExtensions.cs(27): Trim analysis warning IL2075: Microsoft.OpenApi.Extensions.EnumExtensions.GetAttributeOfType<T>(Enum): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.PublicNestedTypes', 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.PublicEvents' in call to 'System.Type.GetMember(String)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
    /_/src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs(23): Trim analysis warning IL2075: Microsoft.OpenApi.Any.OpenApiAnyCloneHelper.CloneFromCopyConstructor(IOpenApiAny): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'System.Type.GetConstructors()'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

Closes https://github.com/microsoft/OpenAPI.NET/issues/1715 Closes https://github.com/microsoft/OpenAPI.NET/issues/1114

captainsafia avatar Jul 04 '24 01:07 captainsafia