JsonSchemaGeneratorSettings
The JSON Schema generator settings.
using Namotion.Reflection;
using Newtonsoft.Json;
using NJsonSchema.Generation.TypeMappers;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace NJsonSchema.Generation
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public abstract class JsonSchemaGeneratorSettings : IXmlDocsSettings
{
public ReferenceTypeNullHandling DefaultReferenceTypeNullHandling { get; set; }
public ReferenceTypeNullHandling DefaultDictionaryValueReferenceTypeNullHandling { get; set; }
public bool GenerateAbstractProperties { get; set; }
public bool FlattenInheritanceHierarchy { get; set; }
public bool GenerateAbstractSchemas { get; set; }
public bool GenerateKnownTypes { get; set; } = true;
public bool GenerateXmlObjects { get; set; }
public bool IgnoreObsoleteProperties { get; set; }
public bool AllowReferencesWithProperties { get; set; }
public bool GenerateEnumMappingDescription { get; set; }
public bool AlwaysAllowAdditionalObjectProperties { get; set; }
public bool GenerateExamples { get; set; }
public SchemaType SchemaType { get; set; }
public string[] ExcludedTypeNames { get; set; }
public bool UseXmlDocumentation { get; set; }
public bool ResolveExternalXmlDocumentation { get; set; }
public XmlDocsFormattingMode XmlDocumentationFormatting { get; set; }
[JsonIgnore]
public ITypeNameGenerator TypeNameGenerator { get; set; }
[JsonIgnore]
public ISchemaNameGenerator SchemaNameGenerator { get; set; }
[JsonIgnore]
public IReflectionService ReflectionService { get; set; }
[JsonIgnore]
public ICollection<ITypeMapper> TypeMappers { get; set; } = new Collection<ITypeMapper>();
[JsonIgnore]
public ICollection<ISchemaProcessor> SchemaProcessors { get; } = new Collection<ISchemaProcessor>();
public bool GenerateCustomNullableProperties { get; set; }
public JsonSchemaGeneratorSettings(IReflectionService reflectionService)
{
ReflectionService = reflectionService;
DefaultReferenceTypeNullHandling = ReferenceTypeNullHandling.Null;
DefaultDictionaryValueReferenceTypeNullHandling = ReferenceTypeNullHandling.NotNull;
SchemaType = SchemaType.JsonSchema;
GenerateAbstractSchemas = true;
GenerateExamples = true;
TypeNameGenerator = new DefaultTypeNameGenerator();
SchemaNameGenerator = new DefaultSchemaNameGenerator();
ExcludedTypeNames = Array.Empty<string>();
UseXmlDocumentation = true;
ResolveExternalXmlDocumentation = true;
XmlDocumentationFormatting = 0;
}
public bool GetActualGenerateAbstractSchema(Type type)
{
object obj = EnumerableExtensions.FirstAssignableToTypeNameOrDefault<object>((IEnumerable<object>)type.GetTypeInfo().GetCustomAttributes(false), "JsonSchemaAbstractAttribute", 0);
if (!GenerateAbstractSchemas || obj != null) {
if (obj == null)
return false;
return ObjectExtensions.TryGetPropertyValue<bool>(obj, "IsAbstract", true);
}
return true;
}
public bool GetActualFlattenInheritanceHierarchy(Type type)
{
object obj = EnumerableExtensions.FirstAssignableToTypeNameOrDefault<object>((IEnumerable<object>)type.GetTypeInfo().GetCustomAttributes(false), "JsonSchemaFlattenAttribute", 0);
if (!FlattenInheritanceHierarchy || obj != null) {
if (obj == null)
return false;
return ObjectExtensions.TryGetPropertyValue<bool>(obj, "Flatten", true);
}
return true;
}
}
}