示例#1
0
        protected internal AspNetRouteDetails GetRouteDetails(Route route)
        {
            var routeDetails = new AspNetRouteDetails();

            if (route.Url.StartsWith("/"))
            {
                routeDetails.RouteTemplate = route.Url;
            }
            else
            {
                routeDetails.RouteTemplate = "/" + route.Url;
            }

            return(routeDetails);
        }
        protected internal IRouteDetails GetRouteDetails(ApiDescription desc)
        {
            var routeDetails = new AspNetRouteDetails
            {
                HttpMethods = GetHttpMethods(desc)
            };

            if (desc.Route?.RouteTemplate != null)
            {
                routeDetails.RouteTemplate = "/" + desc.Route?.RouteTemplate;
            }
            else if (desc.ActionDescriptor?.ControllerDescriptor != null)
            {
                routeDetails.RouteTemplate = $"/{desc.ActionDescriptor.ControllerDescriptor.ControllerName}/{desc.ActionDescriptor.ActionName}";
            }

            List <string> produces = new List <string>();

            foreach (var respTypes in desc.SupportedResponseFormatters)
            {
                foreach (var format in respTypes.SupportedMediaTypes)
                {
                    produces.Add(format.MediaType);
                }
            }

            routeDetails.Produces = produces;

            List <string> consumes = new List <string>();

            foreach (var reqTypes in desc.SupportedRequestBodyFormatters)
            {
                foreach (var format in reqTypes.SupportedMediaTypes)
                {
                    produces.Add(format.MediaType);
                }
            }

            routeDetails.Consumes = consumes;

            return(routeDetails);
        }