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

Schema generation fails when a KnownType attribute specifies a method name instead of a type #291

Closed
csdahlberg opened this issue Jan 9, 2017 · 1 comment

Comments

@csdahlberg
Copy link
Contributor

If a type uses a KnownType attribute to specify the name of a method that returns known types, a NullReferenceException is thrown when JsonSchemaGenerator.GenerateKnownTypesAsync calls JsonObjectTypeDescription.FromType. A simple example:

    public class Pencil
    {
    }

    [KnownType("GetKnownTypes")]
    public class WritingInstrument
    {
        public static Type[] GetKnownTypes()
        {
            return new[] { typeof(Pencil) };
        }
    }

    public class Container
    {
        public WritingInstrument WritingInstrument { get; set; }
    }

    public async Task ReproAsync()
    {
        var schema = await JsonSchema4.FromTypeAsync<Container>();
    }

I have support for this scenario coded, and plan on submitting a pull request shortly.

@RicoSuter
Copy link
Owner

I didnt know that this is possible. 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

No branches or pull requests

2 participants