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

Improve polymorphism & inheritance behavior incl. more flexible config #1766

Merged
merged 1 commit into from Aug 3, 2020

Conversation

domaindrivendev
Copy link
Owner

@domaindrivendev domaindrivendev commented Aug 3, 2020

Fixes #1643
Fixes #1662

Overview
With the existing support for polymorphism/inheritance (enabled with the GeneratePolymorphicSchemas setting), Swashbuckle will implicitly use the oneOf keyword in base type schemas (see "Polymorphism" in the Swagger docs) AND the allOf keyword in sub type schemas (see "Model Composition" in the Swagger docs).

However, it turns out there's many use cases where these two keywords might be used independently. For example, oneOf is particularly useful for documenting the various acceptable structures for payloads that are bound to an abstract/base class. But allOf on the other hand is more useful for client code generators when you want to maintain an inheritance structure in the generated client models.

This PR splits the setting into two separate settings that can be enabled independently or together:

services.AddSwagger(c =>
{
    ...
    c.UseOneOfForPolymorphism();
    c.UseAllOfForInheritance();
}

Additionnally, the existing implementation of "Polymorphic" schemas (i.e. schemas that include the oneOf keyword) didn't include the abstract/base class itself in the list which is technically incorrect. This PR also addresses this issue by including the abstract/base class in the list.

@maarten-kieft
Copy link

When can we expect the release for this one? Works as a charm :)

@kgreed
Copy link

kgreed commented Sep 12, 2020

I am hanging out for this release 👍

@domaindrivendev
Copy link
Owner Author

@kgreed v5.6.0 now pushed to Nuget. Pull it down and let me know how it goes

@martincostello martincostello deleted the polymorphism-enhancements branch May 13, 2024 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants