Skip to content

OpenApi custom polymorphic type names #58332

Open

Description

@koenbeuk

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

We're looking into migrating from Swashbuckle to Microsoft.AspNetCore.OpenApi. There are many benefits but polymorphic type naming is a larger issue for us as it makes generated type names hard to read. In our case we use the base type name as a suffix, e.g.

abstract class JobTemplate { ... }
class FooJobTemplate : JobTemplate { .. }

Generates a type called: JobTemplateFooJobTemplate.

Describe the solution you'd like

Any way to customize the generated schema name. In Swashbuckle we could configure a delegate that took a Type and returned a String.

Additional context

#57982 and #58213 also mention this particular issue.

Activity

  1. ghost added
    old-area-web-frameworks-do-not-use
    on Oct 9, 2024
  2. captainsafia commented on Oct 9, 2024

    @captainsafia
    Contributor

    @koenbeuk Thanks for filing this issue! The default implementation for generating polymorphic type names use the BaseType as the prefix. We don't yet expose an API for customizing the polymorphic type name, although we can consider adding this in the future. The ship has sailed for introducing a new API in .NET 9.

    In the meantime, if it is a feasible approach for you, you may consider removing the suffix in your type names and relying on the prefixing behavior that is built-in.

  3. added
    area-mvc
    area-minimal
    and removed
    old-area-web-frameworks-do-not-use
    on Oct 9, 2024
  4. added this to the .NET 10 Planning milestone on Oct 9, 2024
  5. marinasundstrom commented on Oct 25, 2024

    @marinasundstrom

    I want to move from NSwag and I also see this as a problem. They way polymorphism is done doesn't match either NSwag, or Swashbuckle. The OpenAPI specification being generated is incompatible.

  6. marinasundstrom commented on Oct 25, 2024

    @marinasundstrom
  7. lvde0 commented on Nov 20, 2024

    @lvde0

    Experiencing the same problem. The transition from Swashbuckle is causing a lot of friction because of the way polymorphism is handled:

    • The base class prefix needs to be configurable.
    • It does not generate allof on the derived types
    • Instead of Pet it generates an extra PetBase, which is confusing too

    These things needs to be figured out...

  8. davesmits commented on Jun 19, 2025

    @davesmits

    Pleaasee include in .net 10 this

    Experiencing the same problem. The transition from Swashbuckle is causing a lot of friction because of the way polymorphism is handled:

    • The base class prefix needs to be configurable.
    • It does not generate allof on the derived types
    • Instead of Pet it generates an extra PetBase, which is confusing too

    These things needs to be figured out...

    and the custom naming! It blocked me from adopting this new inbox openapi stuff

  9. removed this from the .NET 10 Planning milestone on Aug 22, 2025
  10. added this to the Backlog milestone on Aug 25, 2025
  11. arknu commented on Aug 21, 2026

    @arknu

    How is this still not fixed? In which world is the current naming convention remotely acceptable? Naming of polymorphic types should be configurable and customizable. And please have a sane default of just using the name of the derived type instead of adding needless prefixes.

    This was reported in .NET 9 and is now pushed to .NET 12. Come on, at least fix this for .NET 11.

  12. lvde0 commented on Aug 21, 2026

    @lvde0

    @arknu Unfortunately, the list of "why is this not fixed yet?" issues in ASP.NET keeps increasing every year.

    Just two examples:

    #42561

    #47301

    For us, absolutely deal breaking issues. We're migrating away from Blazor due to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalarea-mvcfeature-openapi

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions