public ApiDeclaration GetDeclaration(string basePath, string version, string resourceName)
        {
            var apiDescriptionGroup = GetApplicableApiDescriptions(version)
                .Single(apiDescGrp => apiDescGrp.Key == resourceName);

            var dataTypeRegistry = new DataTypeRegistry(_customTypeMappings, _polymorphicTypes, _modelFilters);
            var operationGenerator = new OperationGenerator(dataTypeRegistry, _operationFilters);

            // Group further by relative path - each group corresponds to an Api
            var apis = apiDescriptionGroup
                .GroupBy(apiDesc => apiDesc.RelativePathSansQueryString())
                .Select(apiDescGrp => CreateApi(apiDescGrp, operationGenerator))
                .OrderBy(api => api.Path)
                .ToList();

            return new ApiDeclaration
            {
                SwaggerVersion = SwaggerVersion,
                ApiVersion = version,
                BasePath = basePath,
                ResourcePath = "/" + resourceName,
                Apis = apis,
                Models = dataTypeRegistry.GetModels()
            };
        }
Beispiel #2
0
        public ApiDeclaration GetDeclaration(string basePath, string version, string resourceName)
        {
            var apiDescriptionGroup = GetApplicableApiDescriptions(version)
                                      .Single(apiDescGrp => apiDescGrp.Key == resourceName);

            var dataTypeRegistry   = new DataTypeRegistry(_customTypeMappings, _polymorphicTypes, _modelFilters);
            var operationGenerator = new OperationGenerator(dataTypeRegistry, _operationFilters);

            // Group further by relative path - each group corresponds to an Api
            var apis = apiDescriptionGroup
                       .GroupBy(apiDesc => apiDesc.RelativePathSansQueryString())
                       .Select(apiDescGrp => CreateApi(apiDescGrp, operationGenerator))
                       .OrderBy(api => api.Path)
                       .ToList();

            return(new ApiDeclaration
            {
                SwaggerVersion = SwaggerVersion,
                ApiVersion = version,
                BasePath = basePath,
                ResourcePath = "/" + resourceName,
                Apis = apis,
                Models = dataTypeRegistry.GetModels()
            });
        }
        public ApiDeclaration GetDeclaration(string resourceName)
        {
            var apiDescriptionGroup = _apiDescriptions
                .GroupBy(apiDesc => _options.ResourceNameResolver(apiDesc))
                .SingleOrDefault(apiDescGrp => apiDescGrp.Key == resourceName);

            if (apiDescriptionGroup == null)
                throw new ApiDeclarationNotFoundException(resourceName);

            var dataTypeRegistry = new DataTypeRegistry(
                _options.CustomTypeMappings,
                _options.PolymorphicTypes,
                _options.ModelFilters);

            var operationGenerator = new OperationGenerator(
                dataTypeRegistry,
                _options.OperationFilters);

            // Group further by relative path - each group corresponds to an Api
            var apis = apiDescriptionGroup
                .GroupBy(apiDesc => apiDesc.RelativePathSansQueryString())
                .Select(apiDescGrp => CreateApi(apiDescGrp, operationGenerator))
                .OrderBy(api => api.Path)
                .ToList();

            return new ApiDeclaration
            {
                SwaggerVersion = SwaggerVersion,
                ApiVersion = _apiVersion,
                BasePath = _basePath,
                ResourcePath = "/" + resourceName,
                Apis = apis,
                Models = dataTypeRegistry.GetModels()
            };
        }
        private Api CreateApi(IGrouping<string, ApiDescription> apiDescriptionGroup, OperationGenerator operationGenerator)
        {
            var operations = apiDescriptionGroup
                .Select(operationGenerator.ApiDescriptionToOperation)
                .OrderBy(op => op.Method)
                .ToList();

            return new Api
            {
                Path = "/" + apiDescriptionGroup.Key,
                Operations = operations
            };
        }
        public ApiDeclaration GetDeclaration(string resourceName)
        {
            var apiDescriptionGroup = _apiDescriptions
                                      .GroupBy(apiDesc => _options.ResourceNameResolver(apiDesc))
                                      .SingleOrDefault(apiDescGrp => apiDescGrp.Key == resourceName);

            if (apiDescriptionGroup == null)
            {
                throw new ApiDeclarationNotFoundException(resourceName);
            }

            var dataTypeRegistry = new DataTypeRegistry(
                _options.CustomTypeMappings,
                _options.PolymorphicTypes,
                _options.ModelFilters);

            var operationGenerator = new OperationGenerator(
                dataTypeRegistry,
                _options.OperationFilters);

            // Group further by relative path - each group corresponds to an Api
            var apis = apiDescriptionGroup
                       .GroupBy(apiDesc => apiDesc.RelativePathSansQueryString())
                       .Select(apiDescGrp => CreateApi(apiDescGrp, operationGenerator))
                       .OrderBy(api => api.Path)
                       .ToList();

            return(new ApiDeclaration
            {
                SwaggerVersion = SwaggerVersion,
                ApiVersion = _apiVersion,
                BasePath = _basePath,
                ResourcePath = "/" + resourceName,
                Apis = apis,
                Models = dataTypeRegistry.GetModels()
            });
        }
        private Api CreateApi(IGrouping <string, ApiDescription> apiDescriptionGroup, OperationGenerator operationGenerator)
        {
            var operations = apiDescriptionGroup
                             .Select(operationGenerator.ApiDescriptionToOperation)
                             .OrderBy(op => op.Method)
                             .ToList();

            return(new Api
            {
                Path = "/" + apiDescriptionGroup.Key,
                Operations = operations
            });
        }