Exemple #1
0
 public void Read(YamlNode rootNode)
 {
     this.root = rootNode;
     if (rootNode.GetRequiredString("swagger") != "2.0")
     {
         throw new YamlError(rootNode, "swagger isn't 2.0");
     }
     ReadPaths(rootNode.FirstChildNamed("paths"));
 }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
 private void ReadOperationsObject(YamlNode yamlNode)
 {
     var p = yamlNode.FirstChildNamedOrNull("parameters");
     if( p != null )
         foreach (var x in p.ArrayItems())
         {
             ReadParametersObject(x);
         }
     ReadResponsesObject(yamlNode.FirstChildNamed("responses"));
 }
Exemple #4
0
        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");
            }
        }