OpenApiDiscriminator
Describes a schema discriminator.
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Reflection;
namespace NJsonSchema
{
public class OpenApiDiscriminator
{
[JsonProperty("propertyName", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
public string PropertyName { get; set; }
[JsonProperty("mapping", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
public IDictionary<string, JsonSchema4> Mapping { get; } = new Dictionary<string, JsonSchema4>();
[JsonIgnore]
public object JsonInheritanceConverter { get; set; }
public void AddMapping(Type type, JsonSchema4 schema)
{
dynamic jsonInheritanceConverter = JsonInheritanceConverter;
if ((object)JsonInheritanceConverter.GetType().GetRuntimeMethod("GetDiscriminatorValue", new Type[1] {
typeof(Type)
}) != null) {
dynamic val = jsonInheritanceConverter.GetDiscriminatorValue(type);
Mapping[val] = new JsonSchema4 {
Reference = schema.ActualSchema
};
} else
Mapping[type.get_Name()] = new JsonSchema4 {
Reference = schema.ActualSchema
};
}
}
}