Example #1
0
        private static bool HasValidTypeState(SchemaObject schemaObject)
        {
            var isArrayType       = schemaObject.GetDataType() == DataType.Array;
            var arrayItems        = schemaObject.Items;
            var arrayPropertyType = arrayItems?.Type;

            return((!isArrayType && schemaObject.Type != null) ||
                   (isArrayType && arrayPropertyType != null) ||
                   (isArrayType && arrayItems == null));
        }
Example #2
0
        private static (string, SchemaObject) GetPropertyReference(SchemaObject schemaObject, CaseInsensitiveDictionary <SchemaObject> schema, out bool hasError)
        {
            hasError = false;

            var isArrayType = schemaObject.GetDataType() == DataType.Array;

            var propertyReference = isArrayType ? schemaObject.Items.Reference : schemaObject.Reference;

            if (propertyReference == null)
            {
                hasError = true;
                return(default);
Example #3
0
        private static void PopulateNestedReference(SchemaObject objectToUpdate, CaseInsensitiveDictionary <SchemaObject> schema, out bool hasError)
        {
            hasError = false;

            foreach (var(propertyKey, propertySchemaObject) in objectToUpdate.Properties.ToArray())
            {
                var dataType = propertySchemaObject.GetDataType();

                if (dataType == DataType.Object)
                {
                    PopulateNestedReference(propertySchemaObject, schema, out var hasErrorNestedReference);
                    hasError = hasError || hasErrorNestedReference;
                }

                if (HasValidTypeState(propertySchemaObject))
                {
                    continue;
                }

                var(referenceName, reference) = GetPropertyReference(propertySchemaObject, schema, out var hasErrorGetRefecence);

                if (hasErrorGetRefecence)
                {
                    hasError = true;
                    continue;
                }

                var schemaObject = BuildSchemaObject(referenceName, reference, propertySchemaObject.Example ?? reference.Example);

                if (dataType == DataType.Array)
                {
                    objectToUpdate.Properties[propertyKey].Items           = schemaObject;
                    objectToUpdate.Properties[propertyKey].Items.Reference = referenceName;
                }
                else
                {
                    objectToUpdate.Properties[propertyKey]           = schemaObject;
                    objectToUpdate.Properties[propertyKey].Reference = referenceName;
                }
            }
        }