コード例 #1
0
ファイル: Swagger.cs プロジェクト: madeso/swagger-compiler
        private void ReadParametersObject(YamlNode par)
        {
            var name = "<unknown>";
            try
            {
                name = par.GetRequiredString("name");
                this.MatchName(par, name);

                var din = par.GetRequiredString("in");
                IsOneOf(din, "query", "header", "path", "formData", "body");
                if (din == "body")
                {
                    this.ReadSchemaObject(par.FirstChildNamed("schema"));
                }
                else
                {
                    par.GetRequiredString("type"); // required
                    this.ReadSchemaObject(par);

                    var form = par.GetStringOrNull("format");
                    if (form != null)
                    {
                        this.IsOneOf(form, "int32", "int64", "float", "double", "byte", "date", "date-time", "password");
                    }
                }

                this.ReadSchemaObject(par);
            }
            catch (Exception xx)
            {
                throw new YamlError(xx, par, "...while reading parameter " + name);
            }
        }
コード例 #2
0
ファイル: Swagger.cs プロジェクト: madeso/swagger-compiler
        private void ReadSchemaObject(YamlNode schema)
        {
            try
            {
                var r = schema.GetStringOrNull("$ref");
                if (r != null)
                {
                    try
                    {
                        var node = GetNode(r);
                        this.ReadSchemaObject(node);
                    }
                    catch (Exception x)
                    {
                        throw new YamlError(x, schema, "...while reading ref " + r);
                    }
                }

                var type = schema.GetStringOrNull("type");
                if (type != null)
                {
                    this.IsOneOf(type, "array", "boolean", "integer", "number", "null", "object", "string");
                    if (type == "array")
                    {
                        this.ReadSchemaObject(schema.FirstChildNamed("items"));
                    }
                }

                var properties = schema.FirstChildNamedOrNull("properties");
                if (properties != null)
                {
                    foreach (var prop in properties.Children())
                    {
                        MatchName(prop.Key, prop.Key.AsString());
                        this.ReadSchemaObject(prop.Value);
                    }
                }
            }
            catch (Exception xx)
            {
                throw new YamlError(xx, schema, "...while schema object");
            }
        }