Example #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="token"></param>
        /// <param name="parent"></param>
        public ClassApi(JToken token, ClassApi parent)
        {
            Name      = token["text"].ToString();
            IndexName = Name.Replace("{", "").Replace("}", "");
            Parent    = parent;
            Resource  = token["path"].ToString();

            Keys.AddRange(parent.Keys);
            parent.SubClasses.Add(this);

            IsIndexed = token["text"].ToString().StartsWith("{");
            if (IsIndexed)
            {
                Keys.Add(IndexName);
            }

            if (token["info"] != null)
            {
                Methods.AddRange(token["info"].Select(a => new MethodApi(a.Parent[((JProperty)a).Name], this)).ToArray());
            }

            //tree children
            if (token["children"] != null)
            {
                foreach (var child in token["children"])
                {
                    new ClassApi(child, this);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Generate class Api
        /// </summary>
        /// <param name="host"></param>
        /// <param name="port"></param>
        /// <returns></returns>
        public static ClassApi Generate(string host = "pve.proxmox.com", int port = 443)
        {
            var classApi = new ClassApi();

            foreach (var token in JArray.Parse(GetJsonSchemaFromApiDoc(host, port)))
            {
                new ClassApi(token, classApi);
            }
            return(classApi);
        }
Example #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="token"></param>
        /// <param name="classApi"></param>
        public MethodApi(JToken token, ClassApi classApi)
        {
            MethodType = token["method"].ToString();
            MethodName = token["name"].ToString();
            Comment    = token["description"] + "";
            ClassApi   = classApi;

            var returns = token["returns"];

            if (returns != null)
            {
                ReturnType = returns["type"] + "";

                if (returns["properties"] != null)
                {
                    ReturnParameters.AddRange(returns["properties"]
                                              .Select(a => new ParameterApi(a.Parent[((JProperty)a).Name]))
                                              .ToArray());
                }
                else if (returns["items"] != null && returns["items"]["properties"] != null)
                {
                    ReturnParameters.AddRange(returns["items"]["properties"]
                                              .Select(a => new ParameterApi(a.Parent[((JProperty)a).Name]))
                                              .ToArray());
                }

                if (returns["links"] != null)
                {
                    ReturnLinkHRef = returns["links"][0]["href"].ToString();
                    ReturnLinkRel  = returns["links"][0]["rel"].ToString();
                }
            }

            if (token["parameters"] != null && token["parameters"]["properties"] != null)
            {
                Parameters.AddRange(token["parameters"]["properties"]
                                    .Select(a => new ParameterApi(a.Parent[((JProperty)a).Name]))
                                    .ToArray());
            }

            ReturnIsArray = ReturnType == "array";
            ReturnIsNull  = ReturnType == "null";
        }
Example #4
0
        /// <summary>
        /// Get From Resource
        /// </summary>
        /// <param name="classApiRoot"></param>
        /// <param name="resource"></param>
        /// <returns></returns>
        public static ClassApi GetFromResource(ClassApi classApiRoot, string resource)
        {
            var classApi = classApiRoot;

            foreach (var item in resource.Split('/'))
            {
                if (string.IsNullOrWhiteSpace(item))
                {
                    continue;
                }
                var oldClassApi = classApi;
                classApi = classApi.SubClasses.Where(a => a.Resource == classApi.Resource + "/" + item).FirstOrDefault();
                if (classApi == null)
                {
                    classApi = oldClassApi.SubClasses.Where(a => a.IsIndexed).FirstOrDefault();
                }
                if (classApi == null)
                {
                    break;
                }
            }

            return(classApi);
        }