Skip to content

Commit

Permalink
Add anyOf schema reference handling, closes RicoSuter/NSwag#2107
Browse files Browse the repository at this point in the history
  • Loading branch information
RicoSuter committed Apr 15, 2019
1 parent d7c9fe4 commit 3501697
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/NJsonSchema/JsonSchema4.Reference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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.")]
Expand All @@ -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;
Expand All @@ -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);
}

Expand Down

0 comments on commit 3501697

Please sign in to comment.