private Operation CreateDeleteByIdOperation(OpenApiMetadataPathsResource openApiMetadataResource)
 {
     return(new Operation
     {
         tags = new List <string>
         {
             OpenApiMetadataDocumentHelper.GetResourcePluralName(openApiMetadataResource.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{openApiMetadataResource.Name}ById",
         deprecated = openApiMetadataResource.IsDeprecated,
         consumes = new[]
         {
             _contentTypeStrategy.GetOperationContentType(openApiMetadataResource, ContentTypeUsage.Writable)
         },
         parameters = new[]
         {
             OpenApiMetadataDocumentHelper.CreateIdParameter(),
             CreateIfMatchParameter("DELETE from removing")
         },
         responses = OpenApiMetadataDocumentHelper.GetWriteOperationResponses(HttpMethod.Delete)
     });
 }
Beispiel #2
0
        private Operation CreatePostOperation(OpenApiMetadataPathsResource openApiMetadataResource)
        {
            var responses = OpenApiMetadataDocumentHelper.GetWriteOperationResponses(HttpMethod.Post);

            if (_apiSettings.IsFeatureEnabled(ApiFeature.ChangeQueries.GetConfigKeyName()))
            {
                responses.Add(
                    "405",
                    new Response
                {
                    description =
                        "Method Is Not Allowed. When the Snapshot-Identifier header is present the method is not allowed."
                });
            }

            return(new Operation
            {
                tags = new List <string>
                {
                    OpenApiMetadataDocumentHelper.GetResourcePluralName(openApiMetadataResource.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. The web service will identify whether the resource already exists based on the natural key values provided, and update or create the resource appropriately. It is recommended to use POST for both create and update except while updating natural key of a resource in which case PUT operation must be used.",
                operationId = "post" + openApiMetadataResource.Name,
                deprecated = openApiMetadataResource.IsDeprecated,
                consumes = new[]
                {
                    _contentTypeStrategy.GetOperationContentType(openApiMetadataResource, ContentTypeUsage.Writable)
                },
                parameters = CreatePostParameters(openApiMetadataResource),
                responses = responses
            });
        }
        private Operation CreateGetOperation(OpenApiMetadataPathsResource openApiMetadataResource, bool isCompositeContext)
        {
            var operation = new Operation
            {
                tags = new List <string>
                {
                    OpenApiMetadataDocumentHelper.GetResourcePluralName(openApiMetadataResource.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 = openApiMetadataResource.OperationId ?? $"get{openApiMetadataResource.Resource.PluralName}",
                deprecated  = openApiMetadataResource.IsDeprecated,
                produces    = new[]
                {
                    _contentTypeStrategy.GetOperationContentType(openApiMetadataResource, ContentTypeUsage.Readable)
                },
                parameters = CreateGetByExampleParameters(openApiMetadataResource, isCompositeContext),
                responses  = OpenApiMetadataDocumentHelper.GetReadOperationResponses(
                    _pathsFactoryNamingStrategy.GetResourceName(openApiMetadataResource, ContentTypeUsage.Readable),
                    true)
            };

            return(operation);
        }
Beispiel #4
0
        private Operation CreatePutByIdOperation(OpenApiMetadataPathsResource openApiMetadataResource)
        {
            var responses = OpenApiMetadataDocumentHelper.GetWriteOperationResponses(HttpMethod.Put);

            if (_apiSettings.IsFeatureEnabled(ApiFeature.ChangeQueries.GetConfigKeyName()))
            {
                responses.Add(
                    "405",
                    new Response
                {
                    description =
                        "Method Is Not Allowed. When the Snapshot-Identifier header is present the method is not allowed."
                });
            }

            return(new Operation
            {
                tags = new List <string>
                {
                    OpenApiMetadataDocumentHelper.GetResourcePluralName(openApiMetadataResource.Resource)
                    .ToCamelCase()
                },
                summary = "Updates a resource based on the resource identifier.",
                description = GetDescription(openApiMetadataResource),
                operationId = $"put{openApiMetadataResource.Name}",
                deprecated = openApiMetadataResource.IsDeprecated,
                consumes = new[]
                {
                    _contentTypeStrategy.GetOperationContentType(openApiMetadataResource, ContentTypeUsage.Writable)
                },
                parameters = CreatePutParameters(openApiMetadataResource),
                responses = responses,
                isUpdatable = GetIsUpdatableCustomMetadataValue(openApiMetadataResource)
            });
        }
 public IList <Tag> Create(IEnumerable <OpenApiMetadataResource> openApiMetadataResources)
 {
     return(openApiMetadataResources.Where(x => _filterStrategy.ShouldInclude(x.Resource))
            .Select(
                x => new Tag
     {
         name = OpenApiMetadataDocumentHelper.GetResourcePluralName(x.Resource).ToCamelCase(),
         description = x.Description
     })
            .GroupBy(t => t.name)
            .Select(g => g.First())
            .OrderBy(x => x.name)
            .ToList());
 }
        public IDictionary <string, PathItem> Create(IList <OpenApiMetadataResource> openApiMetadataResources,
                                                     bool isCompositeContext)
        {
            return(_openApiMetadataPathsFactorySelectorStrategy
                   .ApplyStrategy(openApiMetadataResources)
                   .Where(r => r.Readable || r.Writable)
                   .OrderBy(r => r.Name)
                   .SelectMany(
                       r =>
            {
                var resourceName = string.IsNullOrWhiteSpace(r.Path)
                            ? $"/{OpenApiMetadataDocumentHelper.GetResourcePluralName(r.Resource).ToCamelCase()}"
                            : r.Path;

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

                var paths = new[]
                {
                    r.SupportsAccessNonIdAccessOperations
                                ? new
                    {
                        Path = resourcePath,
                        PathItem = CreatePathItemForNonIdAccessedOperations(r, isCompositeContext)
                    }
                                : null,
                    r.SupportsIdAccessOperations
                                ? new
                    {
                        Path = $"{resourcePath}/{{id}}",
                        PathItem = CreatePathItemForAccessByIdsOperations(r)
                    }
                                : null,
                    _apiSettings.IsFeatureEnabled("ChangeQueries") &&
                    !r.Name.Equals(ChangeQueriesConstants.SchoolYearTypesResourceName) &&
                    !isCompositeContext
                                ? 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));
        }
Beispiel #7
0
        private Operation CreateGetByIdOperation(OpenApiMetadataPathsResource openApiMetadataResource)
        {
            var parameters = new[]
            {
                // Path parameters need to be inline in the operation, and not referenced.
                OpenApiMetadataDocumentHelper.CreateIdParameter(),
                new Parameter {
                    @ref = OpenApiMetadataDocumentHelper.GetParameterReference("If-None-Match")
                }
            }.Concat(
                openApiMetadataResource.DefaultGetByIdParameters
                .Select(p => new Parameter {
                @ref = OpenApiMetadataDocumentHelper.GetParameterReference(p)
            }))
            .ToList();

            if (_apiSettings.IsFeatureEnabled(ApiFeature.ChangeQueries.GetConfigKeyName()))
            {
                parameters.Add(new Parameter
                {
                    name        = "Snapshot-Identifier",
                    @in         = "header",
                    description = "Indicates the Snapshot-Identifier that should be used.",
                    type        = "string",
                    required    = false
                });
            }

            return(new Operation
            {
                tags = new List <string>
                {
                    OpenApiMetadataDocumentHelper.GetResourcePluralName(openApiMetadataResource.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{openApiMetadataResource.Resource.PluralName}ById",
                deprecated = openApiMetadataResource.IsDeprecated,
                produces = new[]
                {
                    _contentTypeStrategy.GetOperationContentType(openApiMetadataResource, ContentTypeUsage.Readable)
                },
                parameters = parameters,
                responses = CreateReadResponses(openApiMetadataResource, false)
            });
        }
 private Operation CreatePostOperation(OpenApiMetadataPathsResource openApiMetadataResource)
 {
     return(new Operation
     {
         tags = new List <string>
         {
             OpenApiMetadataDocumentHelper.GetResourcePluralName(openApiMetadataResource.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" + openApiMetadataResource.Name,
         deprecated = openApiMetadataResource.IsDeprecated,
         consumes = new[]
         {
             _contentTypeStrategy.GetOperationContentType(openApiMetadataResource, ContentTypeUsage.Writable)
         },
         parameters = CreatePostParameters(openApiMetadataResource),
         responses = OpenApiMetadataDocumentHelper.GetWriteOperationResponses(HttpMethod.Post)
     });
 }
 private Operation CreateDeletesOperation(OpenApiMetadataPathsResource openApiMetadataResource)
 {
     return(new Operation
     {
         tags = new List <string>
         {
             OpenApiMetadataDocumentHelper.GetResourcePluralName(openApiMetadataResource.Resource)
             .ToCamelCase()
         },
         summary = "Retrieves deleted resources based on change version.",
         description = "The DELETES operation is used to retrieve deleted resources.",
         operationId = $"deletes{openApiMetadataResource.Resource.PluralName}",
         deprecated = openApiMetadataResource.IsDeprecated,
         consumes = new[]
         {
             _contentTypeStrategy.GetOperationContentType(
                 openApiMetadataResource,
                 ContentTypeUsage.Writable)
         },
         parameters = new List <Parameter>
         {
             new Parameter {
                 @ref = OpenApiMetadataDocumentHelper.GetParameterReference("offset")
             },
             new Parameter {
                 @ref = OpenApiMetadataDocumentHelper.GetParameterReference("limit")
             },
             new Parameter {
                 @ref = OpenApiMetadataDocumentHelper.GetParameterReference("MinChangeVersion")
             },
             new Parameter {
                 @ref = OpenApiMetadataDocumentHelper.GetParameterReference("MaxChangeVersion")
             }
         },
         responses = OpenApiMetadataDocumentHelper.GetReadOperationResponses(
             _pathsFactoryNamingStrategy.GetResourceName(openApiMetadataResource, ContentTypeUsage.Readable),
             true, true)
     });
 }
 private Operation CreatePutByIdOperation(OpenApiMetadataPathsResource openApiMetadataResource)
 {
     return(new Operation
     {
         tags = new List <string>
         {
             OpenApiMetadataDocumentHelper.GetResourcePluralName(openApiMetadataResource.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{openApiMetadataResource.Name}",
         deprecated = openApiMetadataResource.IsDeprecated,
         consumes = new[]
         {
             _contentTypeStrategy.GetOperationContentType(openApiMetadataResource, ContentTypeUsage.Writable)
         },
         parameters = CreatePutParameters(openApiMetadataResource),
         responses = OpenApiMetadataDocumentHelper.GetWriteOperationResponses(HttpMethod.Put)
     });
 }
Beispiel #11
0
        private Operation CreateDeleteByIdOperation(OpenApiMetadataPathsResource openApiMetadataResource)
        {
            var responses = OpenApiMetadataDocumentHelper.GetWriteOperationResponses(HttpMethod.Delete);

            if (_apiSettings.IsFeatureEnabled(ApiFeature.ChangeQueries.GetConfigKeyName()))
            {
                responses.Add(
                    "405",
                    new Response
                {
                    description =
                        "Method Is Not Allowed. When the Snapshot-Identifier header is present the method is not allowed."
                });
            }

            return(new Operation
            {
                tags = new List <string>
                {
                    OpenApiMetadataDocumentHelper.GetResourcePluralName(openApiMetadataResource.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{openApiMetadataResource.Name}ById",
                deprecated = openApiMetadataResource.IsDeprecated,
                consumes = new[]
                {
                    _contentTypeStrategy.GetOperationContentType(openApiMetadataResource, ContentTypeUsage.Writable)
                },
                parameters = new[]
                {
                    OpenApiMetadataDocumentHelper.CreateIdParameter(),
                    CreateIfMatchParameter("DELETE from removing")
                },
                responses = responses
            });
        }
 private Operation CreateGetByIdOperation(OpenApiMetadataPathsResource openApiMetadataResource)
 {
     return(new Operation
     {
         tags = new List <string>
         {
             OpenApiMetadataDocumentHelper.GetResourcePluralName(openApiMetadataResource.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{openApiMetadataResource.Resource.PluralName}ById",
         deprecated = openApiMetadataResource.IsDeprecated,
         produces = new[]
         {
             _contentTypeStrategy.GetOperationContentType(openApiMetadataResource, ContentTypeUsage.Readable)
         },
         parameters = new[]
         {
             // Path parameters need to be inline in the operation, and not referenced.
             OpenApiMetadataDocumentHelper.CreateIdParameter(),
             new Parameter {
                 @ref = OpenApiMetadataDocumentHelper.GetParameterReference("If-None-Match")
             }
         }.Concat(
             openApiMetadataResource.DefaultGetByIdParameters
             .Select(p => new Parameter {
             @ref = OpenApiMetadataDocumentHelper.GetParameterReference(p)
         }))
         .ToList(),
         responses =
             OpenApiMetadataDocumentHelper.GetReadOperationResponses(
                 _pathsFactoryNamingStrategy.GetResourceName(openApiMetadataResource, ContentTypeUsage.Readable),
                 false)
     });
 }
Beispiel #13
0
        // NOTE: This adds the deletes get request for change queries.
        private Operation CreateDeletesOperation(OpenApiMetadataPathsResource openApiMetadataResource)
        {
            var responses = OpenApiMetadataDocumentHelper.GetReadOperationResponses(
                _pathsFactoryNamingStrategy.GetResourceName(openApiMetadataResource, ContentTypeUsage.Readable),
                true, true);

            var parameters = new List <Parameter>
            {
                new Parameter {
                    @ref = OpenApiMetadataDocumentHelper.GetParameterReference("offset")
                },
                new Parameter {
                    @ref = OpenApiMetadataDocumentHelper.GetParameterReference("limit")
                },
                new Parameter {
                    @ref = OpenApiMetadataDocumentHelper.GetParameterReference("MinChangeVersion")
                },
                new Parameter {
                    @ref = OpenApiMetadataDocumentHelper.GetParameterReference("MaxChangeVersion")
                }
            };

            if (_apiSettings.IsFeatureEnabled(ApiFeature.ChangeQueries.GetConfigKeyName()))
            {
                responses.Add(
                    "410",
                    new Response
                {
                    description =
                        "Gone. An attempt to connect to the database for the snapshot specified by the Snapshot-Identifier header was unsuccessful (indicating the snapshot may have been removed)."
                });

                parameters.Add(new Parameter {
                    name        = "Snapshot-Identifier",
                    @in         = "header",
                    description = "Indicates the Snapshot-Identifier that should be used.",
                    type        = "string",
                    required    = false
                });
            }

            return(new Operation
            {
                tags = new List <string>
                {
                    OpenApiMetadataDocumentHelper.GetResourcePluralName(openApiMetadataResource.Resource)
                    .ToCamelCase()
                },
                summary = "Retrieves deleted resources based on change version.",
                description = "The DELETES operation is used to retrieve deleted resources.",
                operationId = $"deletes{openApiMetadataResource.Resource.PluralName}",
                deprecated = openApiMetadataResource.IsDeprecated,
                consumes = new[]
                {
                    _contentTypeStrategy.GetOperationContentType(
                        openApiMetadataResource,
                        ContentTypeUsage.Writable)
                },
                parameters = parameters,
                responses = responses
            });
        }