Skip to content

Commit

Permalink
resolves #15 - added extension method for getting subschemas
Browse files Browse the repository at this point in the history
  • Loading branch information
gregsdennis committed Oct 16, 2020
1 parent 28a034b commit dd3d4e1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions JsonSchema/KeywordExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,21 @@ public static bool IsApplicator(this IJsonSchemaKeyword keyword)
{
return keyword.GetType().GetCustomAttribute<ApplicatorAttribute>() != null;
}

/// <summary>
/// Gets all immediate subschemas for a keyword.
/// </summary>
/// <param name="keyword">The keyword.</param>
/// <returns>An `IEnumerable&lt;JsonSchema&gt;`.</returns>
public static IEnumerable<JsonSchema> GetSubschemas(this IJsonSchemaKeyword keyword)
{
return keyword switch
{
ISchemaContainer container => new[] {container.Schema},
ISchemaCollector collector => collector.Schemas,
IKeyedSchemaCollector collector => collector.Schemas.Values,
_ => Enumerable.Empty<JsonSchema>()
};
}
}
}

0 comments on commit dd3d4e1

Please sign in to comment.