Ejemplo n.º 1
0
        public object Get(Resources request)
        {
            var basePath = EndpointHost.Config.WebHostUrl;
            if (basePath == null)
            {
                basePath = EndpointHost.Config.UseHttpsLinks
                    ? Request.GetParentPathUrl().ToHttps()
                    : Request.GetParentPathUrl();
            }

            var result = new ResourcesResponse
            {
                SwaggerVersion = "1.1",
                BasePath = basePath,
                Apis = new List<RestService>()
            };
            var operations = EndpointHost.Metadata;
            var allTypes = operations.GetAllTypes();
            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(Resources) || operationType == typeof(ResourceRequest))
                    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;
        }
Ejemplo n.º 2
0
        public object Get(Resources request)
        {
            var basePath = EndpointHost.Config.WebHostUrl;

            if (basePath == null)
            {
                basePath = EndpointHost.Config.UseHttpsLinks
                    ? Request.GetParentPathUrl().ToHttps()
                    : Request.GetParentPathUrl();
            }

            var result = new ResourcesResponse
            {
                SwaggerVersion = "1.1",
                BasePath       = basePath,
                Apis           = new List <RestService>()
            };
            var operations        = EndpointHost.Metadata;
            var allTypes          = operations.GetAllTypes();
            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(Resources) || operationType == typeof(ResourceRequest))
                {
                    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);
        }