Пример #1
0
        private SwaggerApi FormatMethodDescription(RestPath restPath, Dictionary <string, SwaggerModel> models)
        {
            var verbs   = new List <string>();
            var summary = restPath.Summary ?? restPath.RequestType.GetDescription();
            var notes   = restPath.Notes;

            verbs.AddRange(restPath.AllowsAllVerbs
                ? AnyRouteVerbs
                : restPath.Verbs);

            var routePath   = restPath.Path.Replace("*", "");
            var requestType = restPath.RequestType;

            var md = new SwaggerApi
            {
                Path        = routePath,
                Description = summary,
                Operations  = verbs.Map(verb => new SwaggerOperation
                {
                    Method         = verb,
                    Nickname       = requestType.Name,
                    Summary        = summary,
                    Notes          = notes,
                    Parameters     = ParseParameters(verb, requestType, models, routePath),
                    ResponseClass  = GetResponseClass(restPath, models),
                    ErrorResponses = GetMethodResponseCodes(requestType),
                    Deprecated     = requestType.HasAttribute <ObsoleteAttribute>() ? "true" : null
                })
            };

            return(md);
        }
Пример #2
0
        private SwaggerApi FormatMethodDescription(RestPath restPath, Dictionary <string, SwaggerModel> models)
        {
            var verbs   = new List <string>();
            var summary = restPath.Summary;
            var notes   = restPath.Notes;

            verbs.AddRange(restPath.AllowsAllVerbs
                ? new[] { "GET", "POST", "PUT", "DELETE" }
                : restPath.AllowedVerbs.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries));

            var routePath = restPath.Path.Replace("*", "");
            var md        = new SwaggerApi
            {
                Path        = routePath,
                Description = summary,
                Operations  = verbs.Select(verb =>
                                           new SwaggerOperation
                {
                    Method         = verb,
                    Nickname       = restPath.RequestType.Name,
                    Summary        = summary,
                    Notes          = notes,
                    Parameters     = ParseParameters(verb, restPath.RequestType, models, routePath),
                    ResponseClass  = GetResponseClass(restPath, models),
                    ErrorResponses = GetMethodResponseCodes(restPath.RequestType)
                }).ToList()
            };

            return(md);
        }