예제 #1
0
        private ApiSpec DescriptionGroupToApiSpec(IGrouping<string, ApiDescription> descriptionGroup, ModelSpecsBuilder modelSpecsBuilder)
        {
            var pathParts = descriptionGroup.Key.Split('?');
            var pathOnly = pathParts[0];
            var queryString = pathParts.Length == 1 ? String.Empty : pathParts[1];

            var operationSpecs = descriptionGroup
                .Select(dg => DescriptionToOperationSpec(dg, queryString, modelSpecsBuilder))
                .ToList();

            return new ApiSpec
                {
                    path = "/" + pathOnly,
                    description = String.Empty,
                    operations = operationSpecs
                };
        }
예제 #2
0
        private ApiDeclaration DescriptionGroupToApiDeclaration(IGrouping <string, ApiDescription> descriptionGroup)
        {
            var modelSpecsBuilder = new ModelSpecsBuilder();

            // Group further by relative path - each group corresponds to an ApiSpec
            var apiSpecs = descriptionGroup
                           .GroupBy(ad => ad.RelativePath)
                           .Select(dg => DescriptionGroupToApiSpec(dg, modelSpecsBuilder))
                           .ToList();

            return(new ApiDeclaration
            {
                apiVersion = "1.0",
                swaggerVersion = SwaggerVersion,
                basePath = _basePathAccessor(),
                resourcePath = descriptionGroup.Key,
                apis = apiSpecs,
                models = modelSpecsBuilder.Build()
            });
        }
예제 #3
0
        private ApiDeclaration DescriptionGroupToApiDeclaration(IGrouping<string, ApiDescription> descriptionGroup)
        {
            var modelSpecsBuilder = new ModelSpecsBuilder();

            // Group further by relative path - each group corresponds to an ApiSpec
            var apiSpecs = descriptionGroup
                .GroupBy(ad => ad.RelativePath)
                .Select(dg => DescriptionGroupToApiSpec(dg, modelSpecsBuilder))
                .ToList();

            return new ApiDeclaration
                {
                    apiVersion = "1.0",
                    swaggerVersion = SwaggerVersion,
                    basePath = _basePathAccessor(),
                    resourcePath = descriptionGroup.Key,
                    apis = apiSpecs,
                    models = modelSpecsBuilder.Build()
                };
        }
예제 #4
0
        private ApiSpec DescriptionGroupToApiSpec(IGrouping <string, ApiDescription> descriptionGroup, ModelSpecsBuilder modelSpecsBuilder)
        {
            var pathParts   = descriptionGroup.Key.Split('?');
            var pathOnly    = pathParts[0];
            var queryString = pathParts.Length == 1 ? String.Empty : pathParts[1];

            var operationSpecs = descriptionGroup
                                 .Select(dg => DescriptionToOperationSpec(dg, queryString, modelSpecsBuilder))
                                 .ToList();

            return(new ApiSpec
            {
                path = "/" + pathOnly,
                description = String.Empty,
                operations = operationSpecs
            });
        }
예제 #5
0
        private ApiParameterSpec ParamDescriptionToParameterSpec(ApiParameterDescription parameterDescription, bool isInQueryString, ModelSpecsBuilder modelSpecsBuilder)
        {
            modelSpecsBuilder.AddType(parameterDescription.ParameterDescriptor.ParameterType);

            var paramType = "";

            switch (parameterDescription.Source)
            {
            case ApiParameterSource.FromBody:
                paramType = "body";
                break;

            case ApiParameterSource.FromUri:
                paramType = isInQueryString ? "query" : "path";
                break;
            }

            return(new ApiParameterSpec
            {
                paramType = paramType,
                name = parameterDescription.Name,
                description = parameterDescription.Documentation,
                dataType = parameterDescription.ParameterDescriptor.ParameterType.ToSwaggerType(),
                required = !parameterDescription.ParameterDescriptor.IsOptional,
                allowableValues = parameterDescription.ParameterDescriptor.ParameterType.AllowableValues()
            });
        }
예제 #6
0
        private ApiOperationSpec DescriptionToOperationSpec(ApiDescription description, string queryString, ModelSpecsBuilder modelSpecsBuilder)
        {
            modelSpecsBuilder.AddType(description.ActionDescriptor.ReturnType);

            var paramSpecs = description.ParameterDescriptions
                             .Select(pd => ParamDescriptionToParameterSpec(pd, queryString.Contains(pd.Name), modelSpecsBuilder))
                             .ToList();


            var operationSpec = new ApiOperationSpec
            {
                httpMethod     = description.HttpMethod.Method,
                nickname       = description.ActionDescriptor.ControllerDescriptor.ControllerName,
                parameters     = paramSpecs,
                responseClass  = description.ActionDescriptor.ReturnType.ToSwaggerType(),
                summary        = description.Documentation,
                errorResponses = new List <ApiErrorResponseSpec>()
            };

            foreach (var filter in _postFilters)
            {
                filter.Apply(description, operationSpec);
            }

            return(operationSpec);
        }
예제 #7
0
        private ApiOperationSpec DescriptionToOperationSpec(ApiDescription description, string queryString, ModelSpecsBuilder modelSpecsBuilder)
        {
            modelSpecsBuilder.AddType(description.ActionDescriptor.ReturnType);

            var paramSpecs = description.ParameterDescriptions
                .Select(pd => ParamDescriptionToParameterSpec(pd, queryString.Contains(pd.Name), modelSpecsBuilder))
                .ToList();

            var operationSpec = new ApiOperationSpec
                {
                    httpMethod = description.HttpMethod.Method,
                    nickname = description.ActionDescriptor.ControllerDescriptor.ControllerName,
                    parameters = paramSpecs,
                    responseClass = description.ActionDescriptor.ReturnType.ToSwaggerType(),
                    summary = description.Documentation,
                    errorResponses = new List<ApiErrorResponseSpec>()
                };

            foreach (var filter in _postFilters)
            {
                filter.Apply(description, operationSpec);
            }

            return operationSpec;
        }
예제 #8
0
        private ApiParameterSpec ParamDescriptionToParameterSpec(ApiParameterDescription parameterDescription, bool isInQueryString, ModelSpecsBuilder modelSpecsBuilder)
        {
            modelSpecsBuilder.AddType(parameterDescription.ParameterDescriptor.ParameterType);

            var paramType = "";
            switch (parameterDescription.Source)
            {
                case ApiParameterSource.FromBody:
                    paramType = "body";
                    break;
                case ApiParameterSource.FromUri:
                    paramType = isInQueryString ? "query" : "path";
                    break;
            }

            return new ApiParameterSpec
                {
                    paramType = paramType,
                    name = parameterDescription.Name,
                    description = parameterDescription.Documentation,
                    dataType = parameterDescription.ParameterDescriptor.ParameterType.ToSwaggerType(),
                    required = !parameterDescription.ParameterDescriptor.IsOptional,
                    allowableValues = parameterDescription.ParameterDescriptor.ParameterType.AllowableValues()
                };
        }