public SwaggerRoute(string template, ODataRoute oDataRoute, PathItem pathItem)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(template));
            Contract.Requires(pathItem != null);
            Contract.Requires(oDataRoute != null);

            _template = template;
            _oDataRoute = oDataRoute;
            _pathItem = pathItem;
        }
 private PathItem RemoveVersionParamsFrom(PathItem pathItem)
 {
     RemoveVersionParamFrom(pathItem.get);
     RemoveVersionParamFrom(pathItem.put);
     RemoveVersionParamFrom(pathItem.post);
     RemoveVersionParamFrom(pathItem.delete);
     RemoveVersionParamFrom(pathItem.options);
     RemoveVersionParamFrom(pathItem.head);
     RemoveVersionParamFrom(pathItem.patch);
     return pathItem;
 }
        private PathItem CreatePathItem(IEnumerable<ApiDescription> apiDescriptions, SchemaRegistry schemaRegistry)
        {
            var pathItem = new PathItem();

            // Group further by http method
            var perMethodGrouping = apiDescriptions
                .GroupBy(apiDesc => apiDesc.HttpMethod.Method.ToLower());

            foreach (var group in perMethodGrouping)
            {
                var httpMethod = group.Key;

                var apiDescription = (group.Count() == 1)
                    ? group.First()
                    : _options.ConflictingActionsResolver(group);

                switch (httpMethod)
                {
                    case "get":
                        pathItem.get = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "put":
                        pathItem.put = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "post":
                        pathItem.post = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "delete":
                        pathItem.delete = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "options":
                        pathItem.options = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "head":
                        pathItem.head = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "patch":
                        pathItem.patch = CreateOperation(apiDescription, schemaRegistry);
                        break;
                }
            }

            return pathItem;
        }
        private PathItem CreatePathItem(IEnumerable<ApiDescription> apiDescriptions, SchemaRegistry schemaRegistry)
        {
            Contract.Requires(apiDescriptions != null);
            Contract.Requires(schemaRegistry != null);

            var pathItem = new PathItem();

            // Group further by http method
            var perMethodGrouping = apiDescriptions
                .GroupBy(apiDesc => apiDesc.HttpMethod.Method.ToLower());

            foreach (var group in perMethodGrouping)
            {
                Contract.Assume(group != null);

                var httpMethod = group.Key;

                var apiDescription = group.Count() == 1
                    ? group.First()
                    : _options.ConflictingActionsResolver(group);

                Contract.Assume(apiDescription != null);
                Contract.Assume(apiDescription.ParameterDescriptions != null);
                switch (httpMethod)
                {
                    case "get":
                        pathItem.get = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "put":
                        pathItem.put = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "post":
                        pathItem.post = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "delete":
                        pathItem.delete = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "patch":
                    case "merge":
                        pathItem.patch = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    default:
                        throw new InvalidOperationException($"HttpMethod {httpMethod} is not supported.");
                }
            }

            return pathItem;
        }
示例#5
0
        private PathItem CreatePathItem(IEnumerable<ApiDescription> apiDescriptions, ISchemaRegistry schemaRegistry)
        {
            var pathItem = new PathItem();

            // Group further by http method
            var perMethodGrouping = apiDescriptions
                .GroupBy(apiDesc => apiDesc.HttpMethod);

            foreach (var group in perMethodGrouping)
            {
                var httpMethod = group.Key;

                if (httpMethod == null)
                    throw new NotSupportedException(string.Format(
                        "Unbounded HTTP verbs for path '{0}'. Are you missing an HttpMethodAttribute?",
                        group.First().RelativePathSansQueryString()));

                if (group.Count() > 1)
                    throw new NotSupportedException(string.Format(
                        "Multiple operations with path '{0}' and method '{1}'. Are you overloading action methods?",
                        group.First().RelativePathSansQueryString(), httpMethod));

                var apiDescription = group.Single();

                switch (httpMethod)
                {
                    case "GET":
                        pathItem.Get = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "PUT":
                        pathItem.Put = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "POST":
                        pathItem.Post = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "DELETE":
                        pathItem.Delete = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "OPTIONS":
                        pathItem.Options = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "HEAD":
                        pathItem.Head = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "PATCH":
                        pathItem.Patch = CreateOperation(apiDescription, schemaRegistry);
                        break;
                }
            }

            return pathItem;
        }
        private PathItem CreatePathItem(IEnumerable<ApiDescription> apiDescriptions, ISchemaRegistry schemaRegistry)
        {
            var pathItem = new PathItem();

            // Group further by http method
            var perMethodGrouping = apiDescriptions
                .GroupBy(apiDesc => apiDesc.HttpMethod.ToLower());

            foreach (var group in perMethodGrouping)
            {
                var httpMethod = group.Key;

                if (group.Count() > 1) throw new NotSupportedException(string.Format(
                    "Not supported by Swagger 2.0: Multiple operations with path '{0}' and method '{1}'.",
                    group.First().RelativePathSansQueryString(), httpMethod));

                var apiDescription = group.Single();

                switch (httpMethod)
                {
                    case "get":
                        pathItem.Get = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "put":
                        pathItem.Put = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "post":
                        pathItem.Post = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "delete":
                        pathItem.Delete = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "options":
                        pathItem.Options = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "head":
                        pathItem.Head = CreateOperation(apiDescription, schemaRegistry);
                        break;
                    case "patch":
                        pathItem.Patch = CreateOperation(apiDescription, schemaRegistry);
                        break;
                }
            }

            return pathItem;
        }