JsonSchemaProperty
A description of a JSON property of a JSON schema.
using Newtonsoft.Json;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace NJsonSchema
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class JsonSchemaProperty : JsonSchema
{
[System.Runtime.CompilerServices.Nullable(2)]
private object _parent;
[JsonIgnore]
public string Name { get; set; }
[System.Runtime.CompilerServices.Nullable(2)]
[JsonIgnore]
public override object Parent {
[System.Runtime.CompilerServices.NullableContext(2)]
get {
return _parent;
}
[System.Runtime.CompilerServices.NullableContext(2)]
set {
bool flag = _parent == null;
_parent = value;
if (flag && InitialIsRequired)
IsRequired = InitialIsRequired;
}
}
[JsonIgnore]
public bool IsRequired {
get {
return base.ParentSchema.RequiredProperties.Contains(Name);
}
set {
if (base.ParentSchema == null)
InitialIsRequired = value;
else if (value) {
if (!base.ParentSchema.RequiredProperties.Contains(Name))
base.ParentSchema.RequiredProperties.Add(Name);
} else if (base.ParentSchema.RequiredProperties.Contains(Name)) {
base.ParentSchema.RequiredProperties.Remove(Name);
}
}
}
[JsonIgnore]
internal bool InitialIsRequired { get; set; }
[DefaultValue(false)]
[JsonProperty("x-readOnly", DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool IsReadOnly { get; set; }
[DefaultValue(false)]
[JsonProperty("x-writeOnly", DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool IsWriteOnly { get; set; }
[JsonIgnore]
public bool IsInheritanceDiscriminator {
get {
return base.ParentSchema.ActualDiscriminator == Name;
}
}
public override bool IsNullable(SchemaType schemaType)
{
if (schemaType == SchemaType.Swagger2 && !IsRequired)
return true;
return base.IsNullable(schemaType);
}
}
}