Skip to content

Avoid use of unbounded reflection to resolve Enum display names #1715

@captainsafia

Description

@captainsafia

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.

public static string GetDisplayName(this Enum enumValue)

The use of unbounded reflection in this codepath makes it difficult to enable trimming for applications that use Microsoft.OpenApi in any capacity.

public static T GetAttributeOfType<T>(this Enum enumValue) where T : Attribute

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions