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

fixes #1728 return null when subType is not found, fixes Stackoverflow exception #1729

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

ryanheath
Copy link
Contributor

@ryanheath ryanheath commented Sep 7, 2024

Fixes #1728

I do not know how to test it. The generated code in the liquid file is not the same as the 'real' NJsonSchema.Converters.JsonInheritanceConverter<TBase>, which has tests.

Also the 'real' code of GetObjectSubtype returns a null value when subType is not found.
so the fix got to be right! ;)

private static Type? GetObjectSubtype(Type baseType, string discriminatorValue)
{
    var jsonInheritanceAttributes = baseType
        .GetTypeInfo()
        .GetCustomAttributes(true)
        .OfType<JsonInheritanceAttribute>();

    return jsonInheritanceAttributes.SingleOrDefault(a => a.Key == discriminatorValue)?.Type;
}

@RicoSuter
Copy link
Owner

Fixes RicoSuter/NSwag#4375

@RicoSuter
Copy link
Owner

Thanks for the PR.

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.

Unknown subtype causes Stackoverflow exception at deserialization
2 participants