/// <summary> /// Determines if the schema should be represented as a ComplexType in the XSD. /// </summary> /// <param name="schema">The Json Schema to analyze.</param> /// <returns>True if it should be represented as a ComplexType in the XSD; otherwise, false.</returns> protected bool IsValidComplexType(JsonSchema schema) { schema = FollowReferencesIfAny(schema); if (schema.HasKeyword <PropertiesKeyword>()) { return(true); } if (schema.TryGetKeyword(out AllOfKeyword allOfKeyword)) { foreach (var subSchema in allOfKeyword.GetSubschemas()) { var isComplexType = IsValidComplexType(subSchema); if (isComplexType) { return(true); } } } if (schema.TryGetKeyword(out AnyOfKeyword anyOfKeyword)) { foreach (var subSchema in anyOfKeyword.GetSubschemas()) { var isComplexType = IsValidComplexType(subSchema); if (isComplexType) { return(true); } } } if (schema.TryGetKeyword(out OneOfKeyword oneOfKeyword)) { foreach (var subSchema in oneOfKeyword.GetSubschemas()) { var isComplexType = IsValidComplexType(subSchema); if (isComplexType) { return(true); } } } return(false); }
/// <summary> /// Determines if a schema is a reference schema or not. /// A reference schema is a schema that has the $ref keyword. /// For further reference see https://json-schema.org/understanding-json-schema/structuring.html#ref /// </summary> /// <param name="schema">The Json Schema to analyze.</param> /// <returns></returns> protected static bool IsRefSchema(JsonSchema schema) { return(schema.HasKeyword <RefKeyword>()); }