private SwaggerRouteData CreateSwaggerRouteData(INancyModule module, Route route, Dictionary <RouteId, MethodInfo> routeHandlers)
        {
            var operation = new Operation()
            {
                OperationId = route.Description.Name
            };


            var data = new SwaggerRouteData(route.Description.Path, new PathItem());

            var method = route.Description.Method.ToHttpMethod();

            switch (route.Description.Method.ToLowerInvariant())
            {
            case "get":
                data.PathItem.Get = operation;
                break;

            case "post":
                data.PathItem.Post = operation;
                break;

            case "patch":
                data.PathItem.Patch = operation;
                break;

            case "delete":
                data.PathItem.Delete = operation;
                break;

            case "put":
                data.PathItem.Put = operation;
                break;

            case "head":
                data.PathItem.Head = operation;
                break;

            case "options":
                data.PathItem.Options = operation;
                break;
            }

            var routeId = RouteId.Create(module, route);
            var handler = routeHandlers.ContainsKey(routeId) ? routeHandlers[routeId] : null;

            if (handler == null)
            {
                operation.Description = "[example]"; // TODO: Insert example how to annotate a route
                operation.Summary     = "Warning: no annotated method found for this route";

                return(data);
            }

            Type model = null;

            foreach (var attr in handler.GetCustomAttributes <RouteAttribute>())
            {
                operation.Summary     = attr.Summary ?? operation.Summary;
                operation.Description = attr.Notes ?? operation.Description;
                model = attr.Response ?? model;
                operation.Consumes = attr.Consumes ?? operation.Consumes;
                operation.Consumes = attr.Produces ?? operation.Produces;
            }

            if (model != null)
            {
                data.Types.Add(method, model);
            }

            operation.Responses = handler.GetCustomAttributes <SwaggerResponseAttribute>()
                                  .Select(attr =>
            {
                var msg = new global::Swagger.ObjectModel.Response()
                {
                    Description = attr.Message
                };

                //if (attr.Model != null)
                //{
                //    msg.ResponseModel = Primitive.IsPrimitive(attr.Model)
                //                            ? Primitive.FromType(attr.Model).Type
                //                            : SwaggerConfig.ModelIdConvention(attr.Model);
                //}

                return(Tuple.Create((int)attr.Code, msg));
            })
                                  .ToDictionary(x => x.Item1.ToString(), x => x.Item2);


            operation.Parameters = handler.GetParameters()
                                   .Select(CreateSwaggerParameterData)
                                   .ToList();

            return(data);
        }
        private SwaggerRouteData CreateSwaggerRouteData(INancyModule module, Route route, Dictionary<RouteId, MethodInfo> routeHandlers)
        {
            var operation = new Operation()
            {
                OperationId = route.Description.Name
            };


            var data = new SwaggerRouteData(route.Description.Path, new PathItem());

            var method = route.Description.Method.ToHttpMethod();
            switch (route.Description.Method.ToLowerInvariant())
            {
                case "get":
                    data.PathItem.Get = operation;
                    break;
                case "post":
                    data.PathItem.Post = operation;
                    break;
                case "patch":
                    data.PathItem.Patch = operation;
                    break;
                case "delete":
                    data.PathItem.Delete = operation;
                    break;
                case "put":
                    data.PathItem.Put = operation;
                    break;
                case "head":
                    data.PathItem.Head = operation;
                    break;
                case "options":
                    data.PathItem.Options = operation;
                    break;
            }

            var routeId = RouteId.Create(module, route);
            var handler = routeHandlers.ContainsKey(routeId) ? routeHandlers[routeId] : null;
            if (handler == null)
            {
                operation.Description = "[example]"; // TODO: Insert example how to annotate a route
                operation.Summary = "Warning: no annotated method found for this route";

                return data;
            }

            Type model = null;
            foreach (var attr in handler.GetCustomAttributes<RouteAttribute>())
            {
                operation.Summary = attr.Summary ?? operation.Summary;
                operation.Description = attr.Notes ?? operation.Description;
                model = attr.Response ?? model;
                operation.Consumes = attr.Consumes ?? operation.Consumes;
                operation.Consumes = attr.Produces ?? operation.Produces;
            }

            if (model != null)
            {
                data.Types.Add(method, model);
            }

            operation.Responses = handler.GetCustomAttributes<SwaggerResponseAttribute>()
                .Select(attr =>
                {
                    var msg = new global::Swagger.ObjectModel.Response()
                    {
                        Description = attr.Message
                    };

                    //if (attr.Model != null)
                    //{
                    //    msg.ResponseModel = Primitive.IsPrimitive(attr.Model)
                    //                            ? Primitive.FromType(attr.Model).Type
                    //                            : SwaggerConfig.ModelIdConvention(attr.Model);
                    //}

                    return Tuple.Create((int)attr.Code, msg);
                })
                .ToDictionary(x => x.Item1.ToString(), x => x.Item2);


            operation.Parameters = handler.GetParameters()
                .Select(CreateSwaggerParameterData)
                .ToList();

            return data;
        }