Example #1
0
        public object Get(SwaggerResource request)
        {
            var path  = "/" + request.Name;
            var map   = HostContext.ServiceController.RestPathMap;
            var paths = new List <RestPath>();

            var basePath = base.Request.ResolveBaseUrl();

            var meta = HostContext.Metadata;

            foreach (var key in map.Keys)
            {
                var restPaths     = map[key];
                var selectedPaths = restPaths.Where(x => x.Path == path || x.Path.StartsWith(path + "/"));
                var visiblePaths  = selectedPaths.Where(x => meta.IsVisible(Request, Format.Json, x.RequestType.Name));
                paths.AddRange(visiblePaths);
            }

            var models = new Dictionary <string, SwaggerModel>();

            foreach (var restPath in paths.SelectMany(x => x.Verbs.Select(y => new { Value = x, Verb = y })))
            {
                ParseModel(models, restPath.Value.RequestType, restPath.Value.Path, restPath.Verb);
            }

            var apis = paths.Select(p => FormatMethodDescription(p, models))
                       .ToArray().OrderBy(md => md.Path).ToList();

            var result = new SwaggerApiDeclaration
            {
                ApiVersion   = HostContext.Config.ApiVersion,
                ResourcePath = path,
                BasePath     = basePath,
                Apis         = apis,
                Models       = models
            };

            if (OperationFilter != null)
            {
                apis.Each(x => x.Operations.Each(OperationFilter));
            }

            if (ApiDeclarationFilter != null)
            {
                ApiDeclarationFilter(result);
            }

            return(new HttpResult(result)
            {
                ResultScope = () => JsConfig.With(includeNullValues: false)
            });
        }
        public object Get(SwaggerResource request)
        {
            var httpReq = Request;
            var path    = "/" + request.Name;
            var map     = HostContext.ServiceController.RestPathMap;
            var paths   = new List <RestPath>();

            var basePath = HostContext.Config.WebHostUrl
                           ?? httpReq.GetParentPathUrl().NormalizeScheme();

            if (basePath.EndsWith(SwaggerResourcesService.RESOURCE_PATH, StringComparison.OrdinalIgnoreCase))
            {
                basePath = basePath.Substring(0, basePath.LastIndexOf(SwaggerResourcesService.RESOURCE_PATH, StringComparison.OrdinalIgnoreCase));
            }
            var meta = HostContext.Metadata;

            foreach (var key in map.Keys)
            {
                paths.AddRange(map[key].Where(x => (x.Path == path || x.Path.StartsWith(path + "/") && meta.IsVisible(Request, Format.Json, x.RequestType.Name))));
            }

            var models = new Dictionary <string, SwaggerModel>();

            foreach (var restPath in paths.SelectMany(x => x.Verbs.Select(y => new { Value = x, Verb = y })))
            {
                ParseModel(models, restPath.Value.RequestType, restPath.Value.Path, restPath.Verb);
            }

            var apis = paths.Select(p => FormatMethodDescription(p, models))
                       .ToArray().OrderBy(md => md.Path).ToList();

            var result = new SwaggerApiDeclaration
            {
                ApiVersion   = HostContext.Config.ApiVersion,
                ResourcePath = path,
                BasePath     = basePath,
                Apis         = apis,
                Models       = models
            };

            return(new HttpResult(result)
            {
                ResultScope = () => JsConfig.With(includeNullValues: false)
            });
        }