Exemplo n.º 1
0
        private static bool KeywordHasSingleNonNullSchema(OneOfKeyword keyword)
        {
            if (keyword.GetSubschemas().Count() > 1)
            {
                return(false);
            }

            if (keyword.GetSubschemas().First().TryGetKeyword <TypeKeyword>(out var typeKeyword) && typeKeyword.Type != SchemaValueType.Null)
            {
                return(true);
            }
Exemplo n.º 2
0
        private void ProcessOneOfKeyword(JsonPointer path, OneOfKeyword keyword, SchemaContext context)
        {
            // A oneOf keyword with only one subschema which isn't null makes it required
            if (KeywordHasSingleNonNullSchema(keyword))
            {
                AddRequiredProperties(context.Id, new List <string>()
                {
                    context.Name
                });
            }

            int subSchemaIndex = 0;

            foreach (var subSchema in keyword.GetSubschemas())
            {
                var subSchemaPath = path.Combine(JsonPointer.Parse($"/[{subSchemaIndex}]"));
                ProcessSubSchema(subSchemaPath, subSchema, context);

                subSchemaIndex++;
            }
        }