コード例 #1
0
        public bool TryWriteValue(IOpenApiWriter writer, JSchema schema)
        {
            switch (schema.GetSchemaType())
            {
            case OpenApiSchemaType.Null:
                writer.WriteNull();
                return(true);

            case OpenApiSchemaType.Boolean:
                writer.WriteValue(true);
                return(true);

            case OpenApiSchemaType.Integer:
                writer.WriteValue(GetIntValue(schema));
                return(true);

            case OpenApiSchemaType.Number:
                var rawValue = GetNumberValue(schema).ToString("F", CultureInfo.InvariantCulture);
                writer.WriteRaw(rawValue);
                return(true);

            case OpenApiSchemaType.String:
            case OpenApiSchemaType.Object:
            case OpenApiSchemaType.Array:
            case OpenApiSchemaType.Any:
            case OpenApiSchemaType.Combined:
                return(false);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #2
0
        public bool TryWriteValue(IOpenApiWriter writer, JSchema schema)
        {
            if (schema.GetSchemaType() != OpenApiSchemaType.Any)
            {
                return(false);
            }

            writer.WriteStartObject();
            writer.WriteEndObject();
            return(true);
        }
コード例 #3
0
        public bool TryWriteValue(IOpenApiWriter writer, JSchema schema)
        {
            if (schema.GetSchemaType() != OpenApiSchemaType.Combined)
            {
                return(false);
            }

            var schemes  = SelectSchemes(schema);
            var combined = CombineSchemes(schemes);

            Providers.WriteValueOrThrow(writer, combined);

            return(true);
        }
コード例 #4
0
        private static bool TryParseToRequiredType(string value, JSchema schema, out object result)
        {
            var type = schema.GetSchemaType();

            switch (type)
            {
            case OpenApiSchemaType.Boolean:
                var hasResult = bool.TryParse(value, out var boolean);
                result = boolean;
                return(hasResult);

            case OpenApiSchemaType.Integer:
                hasResult = int.TryParse(value, out var integer);
                result    = integer;
                return(hasResult);

            case OpenApiSchemaType.Number:
                hasResult = double.TryParse(value, out var number);
                result    = number;
                return(hasResult);

            case OpenApiSchemaType.String:
                result = value;
                return(true);

            case OpenApiSchemaType.Any:
                result = value;
                return(false);

            case OpenApiSchemaType.Null:
                result = null;
                return(value == null);

            case OpenApiSchemaType.Combined:
                object combined = null;
                var    schemas  = schema.AnyOf.Concat(schema.OneOf).Concat(schema.OneOf);
                hasResult = schemas.Any(x => TryParseToRequiredType(value, x, out combined));
                result    = combined;
                return(hasResult);

            case OpenApiSchemaType.Object:
            case OpenApiSchemaType.Array:
                result = null;
                return(false);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #5
0
 public static bool IsArray(this JSchema schema) => schema.GetSchemaType() == OpenApiSchemaType.Array;
コード例 #6
0
 public static bool IsObject(this JSchema schema) => schema.GetSchemaType() == OpenApiSchemaType.Object;
コード例 #7
0
 public static bool IsString(this JSchema schema) => schema.GetSchemaType() == OpenApiSchemaType.String;