From dd3d4e1d531ccd3ef0bc90a962bab21186b5c040 Mon Sep 17 00:00:00 2001 From: Greg Dennis Date: Fri, 16 Oct 2020 18:02:25 +1300 Subject: [PATCH] resolves #15 - added extension method for getting subschemas --- JsonSchema/KeywordExtensions.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/JsonSchema/KeywordExtensions.cs b/JsonSchema/KeywordExtensions.cs index 73fa3d50b5..f005bd7612 100644 --- a/JsonSchema/KeywordExtensions.cs +++ b/JsonSchema/KeywordExtensions.cs @@ -66,5 +66,21 @@ public static bool IsApplicator(this IJsonSchemaKeyword keyword) { return keyword.GetType().GetCustomAttribute() != null; } + + /// + /// Gets all immediate subschemas for a keyword. + /// + /// The keyword. + /// An `IEnumerable<JsonSchema>`. + public static IEnumerable GetSubschemas(this IJsonSchemaKeyword keyword) + { + return keyword switch + { + ISchemaContainer container => new[] {container.Schema}, + ISchemaCollector collector => collector.Schemas, + IKeyedSchemaCollector collector => collector.Schemas.Values, + _ => Enumerable.Empty() + }; + } } } \ No newline at end of file