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> Schemes => _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)
{
_mappings.Add(GetKey(type, isIntegerEnumeration), schema);
}
private string GetKey(Type type, bool isIntegerEnum)
{
return type.FullName + (isIntegerEnum ? ":Integer" : string.Empty);
}
}
}