Search code examples
njsonschema

NJsonSchema v. 11 breaks JsonSchemaGeneratorSettings


In NJsonSchema 10.9 I used to create my schema generator in C# like this:

private static JsonSchemaGenerator MakeGenerator()
{
    JsonSchemaGeneratorSettings settings = new()
    {
        DefaultReferenceTypeNullHandling = ReferenceTypeNullHandling.NotNull,
        AllowReferencesWithProperties = true,
        FlattenInheritanceHierarchy = true
    };
    return new( settings );
}

As of version 11, JsonSchemaGeneratorSettings is an abstract class. The only implementation I can find is SystemTextSchemaGeneratorSettings, which doesn't do what I want. Implementing JsonSchemaGeneratorSettings requires an IReflectionService, but the DefaultReflectionService class has also disappeared.

Does anyone know what I have to do to get the same behavior I had in 10.9?


Solution

  • I used NJsonSchema.NewtonsoftJson.Generation.NewtonsoftJsonSchemaGeneratorSettings from https://www.nuget.org/packages/NJsonSchema.NewtonsoftJson It made it work again for me