Skip to content
Permalink
Browse files

Add anyOf schema reference handling, closes RicoSuter/NSwag#2107

  • Loading branch information...
RicoSuter committed Apr 15, 2019
1 parent d7c9fe4 commit 35016973e28959025d50b2dd8f5b04dbb0cb9644
Showing with 20 additions and 3 deletions.
  1. +20 −3 src/NJsonSchema/JsonSchema4.Reference.cs
@@ -42,9 +42,9 @@ public virtual JsonSchema4 ActualTypeSchema
}
}

/// <summary>Gets a value indicating whether this is a schema reference ($ref, <see cref="HasAllOfSchemaReference"/> or <see cref="HasOneOfSchemaReference"/>).</summary>
/// <summary>Gets a value indicating whether this is a schema reference ($ref, <see cref="HasAllOfSchemaReference"/>, <see cref="HasOneOfSchemaReference"/> or <see cref="HasAnyOfSchemaReference"/>).</summary>
[JsonIgnore]
public bool HasReference => Reference != null || HasAllOfSchemaReference || HasOneOfSchemaReference;
public bool HasReference => Reference != null || HasAllOfSchemaReference || HasOneOfSchemaReference || HasAnyOfSchemaReference;

/// <summary>Gets a value indicating whether this is an allOf schema reference.</summary>
[JsonIgnore]
@@ -74,6 +74,20 @@ public virtual JsonSchema4 ActualTypeSchema
MultipleOf == null &&
IsEnumeration == false;

/// <summary>Gets a value indicating whether this is an anyOf schema reference.</summary>
[JsonIgnore]
public bool HasAnyOfSchemaReference => AnyOf.Count == 1 &&
AnyOf.Any(s => s.HasReference) &&
Type == JsonObjectType.None &&
AllOf.Count == 0 &&
OneOf.Count == 0 &&
Properties.Count == 0 &&
PatternProperties.Count == 0 &&
AllowAdditionalProperties &&
AdditionalPropertiesSchema == null &&
MultipleOf == null &&
IsEnumeration == false;

/// <summary>Gets or sets the type reference.</summary>
[JsonIgnore]
[Obsolete("Use the Reference property instead.")]
@@ -83,7 +97,7 @@ public JsonSchema4 SchemaReference
set => Reference = value;
}

/// <summary>Gets a value indicating whether this is a schema reference ($ref, <see cref="HasAllOfSchemaReference"/> or <see cref="HasOneOfSchemaReference"/>).</summary>
/// <summary>Gets a value indicating whether this is a schema reference ($ref, <see cref="HasAllOfSchemaReference"/>, <see cref="HasOneOfSchemaReference"/> or <see cref="HasAnyOfSchemaReference"/>).</summary>
[JsonIgnore]
[Obsolete("Use the HasReference property instead.")]
public bool HasSchemaReference => HasReference;
@@ -108,6 +122,9 @@ private JsonSchema4 GetActualSchema(IList<JsonSchema4> checkedSchemas)
if (HasOneOfSchemaReference)
return OneOf.First().GetActualSchema(checkedSchemas);

if (HasAnyOfSchemaReference)
return AnyOf.First().GetActualSchema(checkedSchemas);

return Reference.GetActualSchema(checkedSchemas);
}

0 comments on commit 3501697

Please sign in to comment.
You can’t perform that action at this time.