コード例 #1
0
 private Operation CreateGetByIdOperation(SwaggerPathsResource swaggerResource)
 {
     return(new Operation
     {
         tags = new List <string>
         {
             SwaggerDocumentHelper.GetResourcePluralName(swaggerResource.Resource)
             .ToCamelCase()
         },
         summary = "Retrieves a specific resource using the resource's identifier (using the \"Get By Id\" pattern).",
         description = "This GET operation retrieves a resource by the specified resource identifier.",
         operationId = $"get{swaggerResource.Resource.PluralName}ById",
         deprecated = swaggerResource.IsDeprecated,
         produces = new[] { _contentTypeStrategy.GetOperationContentType(swaggerResource, ContentTypeUsage.Readable) },
         parameters = new[]
         {
             // Path parameters need to be inline in the operation, and not referenced.
             SwaggerDocumentHelper.CreateIdParameter(),
             new Parameter {
                 @ref = SwaggerDocumentHelper.GetParameterReference("If-None-Match")
             }
         }.Concat(
             swaggerResource.DefaultGetByIdParameters
             .Select(p => new Parameter {
             @ref = SwaggerDocumentHelper.GetParameterReference(p)
         }))
         .ToList(),
         responses =
             SwaggerDocumentHelper.GetReadOperationResponses(
                 _pathsFactoryNamingStrategy.GetResourceName(swaggerResource, ContentTypeUsage.Readable), false)
     });
 }
コード例 #2
0
 public IList <Tag> Create(IEnumerable <SwaggerResource> swaggerResources)
 {
     return(swaggerResources.Where(x => _filterStrategy.ShouldInclude(x.Resource))
            .Select(
                x => new Tag
     {
         name = SwaggerDocumentHelper.GetResourcePluralName(x.Resource)
                .ToCamelCase(),
         description = x.Description
     })
            .GroupBy(t => t.name)
            .Select(g => g.First())
            .OrderBy(x => x.name)
            .ToList());
 }
コード例 #3
0
        public IDictionary <string, PathItem> Create(IList <SwaggerResource> swaggerResources)
        {
            return(_swaggerPathsFactorySelectorStrategy
                   .ApplyStrategy(swaggerResources)
                   .Where(r => r.Readable || r.Writable)
                   .OrderBy(r => r.Name)
                   .SelectMany(
                       r =>
            {
                var resourceName = string.IsNullOrWhiteSpace(r.Path)
                            ? $"/{SwaggerDocumentHelper.GetResourcePluralName(r.Resource).ToCamelCase()}"
                            : r.Path;

                var resourcePath = $"/{r.ResourceSchema}{resourceName}";

                var paths = new[]
                {
                    r.SupportsAccessNonIdAccessOperations
                                ? new
                    {
                        Path = resourcePath,
                        PathItem = CreatePathItemForNonIdAccessedOperations(r)
                    }
                                : null,
                    r.SupportsIdAccessOperations
                                ? new
                    {
                        Path = $"{resourcePath}/{{id}}",
                        PathItem = CreatePathItemForAccessByIdsOperations(r)
                    }
                                : null,
                    ChangeQueryFeature.IsEnabled && !r.Name.Equals(ChangeQueryFeature.SchoolYearTypesResourceName)
                                ? new
                    {
                        Path = $"{resourcePath}/deletes",
                        PathItem = CreatePathItemForChangeQueryOperation(r)
                    }
                                : null
                };

                return paths.Where(p => p != null);
            })
                   .GroupBy(p => p.Path)
                   .Select(p => p.First())
                   .ToDictionary(p => p.Path, p => p.PathItem));
        }
コード例 #4
0
 private Operation CreatePostOperation(SwaggerPathsResource swaggerResource)
 {
     return(new Operation
     {
         tags = new List <string>
         {
             SwaggerDocumentHelper.GetResourcePluralName(swaggerResource.Resource)
             .ToCamelCase()
         },
         summary = "Creates or updates resources based on the natural key values of the supplied resource.",
         description =
             "The POST operation can be used to create or update resources. In database terms, this is often referred to as an \"upsert\" operation (insert + update). Clients should NOT include the resource \"id\" in the JSON body because it will result in an error (you must use a PUT operation to update a resource by \"id\"). The web service will identify whether the resource already exists based on the natural key values provided, and update or create the resource appropriately.",
         operationId = "post" + swaggerResource.Name,
         deprecated = swaggerResource.IsDeprecated,
         consumes = new[] { _contentTypeStrategy.GetOperationContentType(swaggerResource, ContentTypeUsage.Writable) },
         parameters = CreatePostParameters(swaggerResource),
         responses = SwaggerDocumentHelper.GetWriteOperationResponses(HttpMethod.Post)
     });
 }
コード例 #5
0
 private Operation CreatePutByIdOperation(SwaggerPathsResource swaggerResource)
 {
     return(new Operation
     {
         tags = new List <string>
         {
             SwaggerDocumentHelper.GetResourcePluralName(swaggerResource.Resource)
             .ToCamelCase()
         },
         summary = "Updates or creates a resource based on the resource identifier.",
         description =
             "The PUT operation is used to update or create a resource by identifier. If the resource doesn't exist, the resource will be created using that identifier. Additionally, natural key values cannot be changed using this operation, and will not be modified in the database.  If the resource \"id\" is provided in the JSON body, it will be ignored as well.",
         operationId = $"put{swaggerResource.Name}",
         deprecated = swaggerResource.IsDeprecated,
         consumes = new[] { _contentTypeStrategy.GetOperationContentType(swaggerResource, ContentTypeUsage.Writable) },
         parameters = CreatePutParameters(swaggerResource),
         responses = SwaggerDocumentHelper.GetWriteOperationResponses(HttpMethod.Put)
     });
 }
コード例 #6
0
        private Operation CreateGetOperation(SwaggerPathsResource swaggerResource)
        {
            var operation = new Operation
            {
                tags = new List <string>
                {
                    SwaggerDocumentHelper.GetResourcePluralName(swaggerResource.Resource)
                    .ToCamelCase()
                },
                summary     = "Retrieves specific resources using the resource's property values (using the \"Get\" pattern).",
                description =
                    "This GET operation provides access to resources using the \"Get\" search pattern.  The values of any properties of the resource that are specified will be used to return all matching results (if it exists).",
                operationId = swaggerResource.OperationId ?? $"get{swaggerResource.Resource.PluralName}",
                deprecated  = swaggerResource.IsDeprecated,
                produces    = new[] { _contentTypeStrategy.GetOperationContentType(swaggerResource, ContentTypeUsage.Readable) },
                parameters  = CreateGetByExampleParameters(swaggerResource),
                responses   = SwaggerDocumentHelper.GetReadOperationResponses(
                    _pathsFactoryNamingStrategy.GetResourceName(swaggerResource, ContentTypeUsage.Readable), true)
            };

            return(operation);
        }
コード例 #7
0
 private Operation CreateDeletesOperation(SwaggerPathsResource swaggerResource)
 {
     return(new Operation
     {
         tags = new List <string>
         {
             SwaggerDocumentHelper.GetResourcePluralName(swaggerResource.Resource)
             .ToCamelCase()
         },
         summary = "Retrieves deleted resources based on change version.",
         description = "The DELETES operation is used to retrieve deleted resources.",
         operationId = $"deletes{swaggerResource.Resource.PluralName}",
         deprecated = swaggerResource.IsDeprecated,
         consumes = new[]
         {
             _contentTypeStrategy.GetOperationContentType(
                 swaggerResource,
                 ContentTypeUsage.Writable)
         },
         parameters = new List <Parameter>
         {
             new Parameter {
                 @ref = SwaggerDocumentHelper.GetParameterReference("offset")
             },
             new Parameter {
                 @ref = SwaggerDocumentHelper.GetParameterReference("limit")
             },
             new Parameter {
                 @ref = SwaggerDocumentHelper.GetParameterReference("MinChangeVersion")
             },
             new Parameter {
                 @ref = SwaggerDocumentHelper.GetParameterReference("MaxChangeVersion")
             }
         },
         responses = SwaggerDocumentHelper.GetReadOperationResponses(
             _pathsFactoryNamingStrategy.GetResourceName(swaggerResource, ContentTypeUsage.Readable), true)
     });
 }
コード例 #8
0
 private Operation CreateDeleteByIdOperation(SwaggerPathsResource swaggerResource)
 {
     return(new Operation
     {
         tags = new List <string>
         {
             SwaggerDocumentHelper.GetResourcePluralName(swaggerResource.Resource)
             .ToCamelCase()
         },
         summary = "Deletes an existing resource using the resource identifier.",
         description =
             "The DELETE operation is used to delete an existing resource by identifier. If the resource doesn't exist, an error will result (the resource will not be found).",
         operationId = $"delete{swaggerResource.Name}ById",
         deprecated = swaggerResource.IsDeprecated,
         consumes = new[] { _contentTypeStrategy.GetOperationContentType(swaggerResource, ContentTypeUsage.Writable) },
         parameters = new[]
         {
             SwaggerDocumentHelper.CreateIdParameter(),
             CreateIfMatchParameter("DELETE from removing")
         },
         responses = SwaggerDocumentHelper.GetWriteOperationResponses(HttpMethod.Delete)
     });
 }