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

JsonInheritanceConverter discriminator name mapping #668

Closed
iatstoev opened this issue Mar 27, 2018 · 3 comments
Closed

JsonInheritanceConverter discriminator name mapping #668

iatstoev opened this issue Mar 27, 2018 · 3 comments

Comments

@iatstoev
Copy link

Hi,

we have the situation that our model classes are in Language A and the swagger must be in language B.
Furthermore we use the JsonInheritanceConverter.

The problem is that the JsonInheritanceConverter is unable to instantiate the correct type as the discriminator is in a different language.

Is it possible to include a method that provides the name, and can be overridden in a derived class?

I am currently using a custom converter based on the JsonInheritanceConverter to achieve this.
Note that inheriting from JsonInheritanceConverter is possibly only with the same name as there are some name checks in the NJsonSchema source like in

JsonSchemaGenerator.TryGetInheritanceDiscriminator

if (converterType.Name == "JsonInheritanceConverter")
{
....
}

@RicoSuter
Copy link
Owner

Ok, I'll change this "if" and make GetDiscriminatorValue() and GetDiscriminatorType() virtual so that you can provide your own implementation with renames (in both directions)?

@iatstoev
Copy link
Author

Yes, that would be perfect and thank you for the great lib!

@RicoSuter
Copy link
Owner

Yes, if you can change the discriminator values, then we also need to evaluate this in the schema generator and code generators (will be supported in JSON Schema and OpenApi3 but not with Swagger2)

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

No branches or pull requests

2 participants