Example #1
0
        public Schema Generate(string url = "", Dictionary <string, string> headers = null)
        {
            var schema = new Schema {
                Headers = headers, Url = url
            };

            var controllers = TypeLoader.Get(_assemblies, x => x.FullName.EndsWith("Controller"));

            foreach (var ctrl in controllers)
            {
                var controllerUrl = $"{url}/{ctrl.Name.Replace("Controller", "")}";
                var schCtrl       = new Controller {
                    Url = controllerUrl
                };

                var methods = MethodLoader.Get(ctrl, x => !x.IsSpecialName && x.DeclaringType?.FullName == ctrl.FullName);

                foreach (var method in methods)
                {
                    var methodUrl = $"{controllerUrl}/{method.Name}";
                    var endp      = new Endpoint {
                        Url = methodUrl, Verb = VerbLoader.Get(method)
                    };

                    foreach (var p in ParamLoader.Get(method))
                    {
                        endp.Input.Add(p.Name, p.ParameterType.IsPrimitive || p.ParameterType == typeof(string) ? p.ParameterType.FullName : GetBody(p));
                    }

                    schCtrl.Endpoints.Add(endp);
                }

                schema.Controllers.Add(schCtrl);
            }

            return(schema);
        }