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

Support oneOf inheritance for JsonSchema Generation #832 #839

Closed
wants to merge 4 commits into from

Conversation

alb3ric
Copy link
Contributor

@alb3ric alb3ric commented Dec 7, 2018

Hello,

Just made some modifications to generate a jsonschema with oneOf inheritance. I didn't do anything for CodeGeneration as don't need it.
For schema generation do you think it is the way to go? And what did you think about when you mention inheritanceMode ? (which kind of mode would you propose?)

@RicoSuter
Copy link
Owner

RicoSuter commented Dec 8, 2018

@paul-michalik
Copy link

Any progress on this?

@qub1n
Copy link

qub1n commented Mar 30, 2020

Any progress on this?

This one is about generating C# OneOf from JsonSchema OneOf.
Is any progress in another direction? I mean generating JsonSchema OneOf from C# OneOf?

@darkflame0
Copy link

Any progress on this?

This one is about generating C# OneOf from JsonSchema OneOf. Is any progress in another direction? I mean generating JsonSchema OneOf from C# OneOf?

@RicoSuter Is any progress for it?
I really need it...

@icnocop
Copy link

icnocop commented Dec 8, 2022

Hi.

As a work-around I was able to use an operation processor.

See https://gist.github.com/icnocop/10de946939e5046190219cc8817356c4

It works for my case, but may not be the best solution, and may not support all scenarios.

For example, it may have been better to use a schema processor instead.

Usage, in Startup.cs, in ConfigureServices:

services.AddOpenApiDocument((settings, serviceProvider) =>
{
    settings.FlattenInheritanceHierarchy = true;
    settings.SchemaType = SchemaType.OpenApi3;
    settings.OperationProcessors.Add(new OneOfOperationProcessor());
    settings.AllowReferencesWithProperties = true;
});

My types are defined and decorated similar to the following:

[KnownType(typeof(ItemA))]
[KnownType(typeof(ItemB))]
[JsonConverter(typeof(JsonInheritanceConverter), "discriminator")]
[JsonInheritance("A", typeof(ItemA))]
[JsonInheritance("B", typeof(ItemB))]
public abstract class Item
{
}

public class ItemA : Item
{
}

public class ItemB : Item
{
}

I only tested with types, and generic types with one generic type parameter.

@RicoSuter
Copy link
Owner

Very old PR, closing now. Please open another PR against recent source if this is still an issue.

@RicoSuter RicoSuter closed this Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants