Skip to content
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

OpenApi custom polymorphic type names #58332

Open
1 task done
koenbeuk opened this issue Oct 9, 2024 · 4 comments
Open
1 task done

OpenApi custom polymorphic type names #58332

koenbeuk opened this issue Oct 9, 2024 · 4 comments
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi

Comments

@koenbeuk
Copy link

koenbeuk commented Oct 9, 2024

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.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Oct 9, 2024
@captainsafia
Copy link
Member

@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.

@captainsafia captainsafia added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels labels Oct 9, 2024
@captainsafia captainsafia added this to the .NET 10 Planning milestone Oct 9, 2024
@marinasundstrom
Copy link

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.

@marinasundstrom
Copy link

marinasundstrom commented Oct 25, 2024

My prototype, limited by the naming convention, and other things:

https://github.com/marinasundstrom/NullabilityTransformersPrototype/tree/main/WebApi

Also RicoSuter/NJsonSchema#1739

@lvde0
Copy link

lvde0 commented Nov 20, 2024

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi
Projects
None yet
Development

No branches or pull requests

4 participants