<PackageReference Include="NJsonSchema" Version="4.25.6122.24179" />

SchemaResolver

Manager which resolves types to schemas.
using System; using System.Collections.Generic; namespace NJsonSchema { public class SchemaResolver : ISchemaResolver { private readonly Dictionary<string, JsonSchema4> _mappings = new Dictionary<string, JsonSchema4>(); public IEnumerable<JsonSchema4> Schemas => _mappings.Values; public bool HasSchema(Type type, bool isIntegerEnumeration) { return _mappings.ContainsKey(GetKey(type, isIntegerEnumeration)); } public JsonSchema4 GetSchema(Type type, bool isIntegerEnumeration) { return _mappings[GetKey(type, isIntegerEnumeration)]; } public void AddSchema(Type type, bool isIntegerEnumeration, JsonSchema4 schema) { if ((object)schema.GetType() != typeof(JsonSchema4)) throw new InvalidOperationException("Added schema is not a JsonSchema4 instance."); _mappings.Add(GetKey(type, isIntegerEnumeration), schema); } private string GetKey(Type type, bool isIntegerEnum) { return type.FullName + (isIntegerEnum ? ":Integer" : string.Empty); } } }