示例#1
0
        public object Get(SwaggerResources request)
        {
            var basePath = base.Request.ResolveBaseUrl();

            var result = new SwaggerResourcesResponse
            {
                BasePath   = basePath,
                Apis       = new List <SwaggerResourceRef>(),
                ApiVersion = HostContext.Config.ApiVersion,
                Info       = new SwaggerInfo
                {
                    Title = HostContext.ServiceName,
                }
            };
            var operations        = HostContext.Metadata;
            var allTypes          = operations.GetAllOperationTypes();
            var allOperationNames = operations.GetAllOperationNames();

            foreach (var operationName in allOperationNames)
            {
                if (resourceFilterRegex != null && !resourceFilterRegex.IsMatch(operationName))
                {
                    continue;
                }
                var name          = operationName;
                var operationType = allTypes.FirstOrDefault(x => x.Name == name);
                if (operationType == null)
                {
                    continue;
                }
                if (operationType == typeof(SwaggerResources) || operationType == typeof(SwaggerResource))
                {
                    continue;
                }
                if (!operations.IsVisible(Request, Format.Json, operationName))
                {
                    continue;
                }

                CreateRestPaths(result.Apis, operationType, operationName);
            }

            result.Apis = result.Apis.OrderBy(a => a.Path).ToList();

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

            return(new HttpResult(result)
            {
                ResultScope = () => JsConfig.With(includeNullValues: false)
            });
        }
        public object Get(SwaggerResources request)
        {
            var basePath = HostContext.Config.WebHostUrl
                           ?? Request.GetParentPathUrl().NormalizeScheme();

            var result = new SwaggerResourcesResponse
            {
                BasePath   = basePath,
                Apis       = new List <SwaggerResourceRef>(),
                ApiVersion = HostContext.Config.ApiVersion,
                Info       = new SwaggerInfo
                {
                    Title = HostContext.ServiceName,
                }
            };
            var operations        = HostContext.Metadata;
            var allTypes          = operations.GetAllOperationTypes();
            var allOperationNames = operations.GetAllOperationNames();

            foreach (var operationName in allOperationNames)
            {
                if (resourceFilterRegex != null && !resourceFilterRegex.IsMatch(operationName))
                {
                    continue;
                }
                var name          = operationName;
                var operationType = allTypes.FirstOrDefault(x => x.Name == name);
                if (operationType == null)
                {
                    continue;
                }
                if (operationType == typeof(SwaggerResources) || operationType == typeof(SwaggerResource))
                {
                    continue;
                }
                if (!operations.IsVisible(Request, Format.Json, operationName))
                {
                    continue;
                }

                CreateRestPaths(result.Apis, operationType, operationName);
            }

            result.Apis = result.Apis.OrderBy(a => a.Path).ToList();
            return(result);
        }