Skip to content

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