private PathItem CreatePathItemForChangeQueryOperation(OpenApiMetadataPathsResource openApiMetadataResource)
 => new PathItem
 {
     get = openApiMetadataResource.Writable
             ? CreateDeletesOperation(openApiMetadataResource)
             : null
 };
        private IList <Parameter> CreateGetByExampleParameters(OpenApiMetadataPathsResource openApiMetadataResource,
                                                               bool isCompositeContext)
        {
            var parameterList = CreateQueryParameters(isCompositeContext)
                                .Concat(
                openApiMetadataResource.DefaultGetByExampleParameters.Select(
                    p => new Parameter {
                @ref = OpenApiMetadataDocumentHelper.GetParameterReference(p)
            }))
                                .ToList();

            IEnumerableExtensions.ForEach(
                openApiMetadataResource.RequestProperties, x =>
            {
                parameterList.Add(
                    new Parameter
                {
                    name = StringExtensions.ToCamelCase(x.PropertyName),
                    @in  = openApiMetadataResource.IsPathParameter(x)
                                ? "path"
                                : "query",
                    description       = OpenApiMetadataDocumentHelper.PropertyDescription(x),
                    type              = OpenApiMetadataDocumentHelper.PropertyType(x),
                    format            = x.PropertyType.ToOpenApiFormat(),
                    required          = openApiMetadataResource.IsPathParameter(x),
                    isIdentity        = OpenApiMetadataDocumentHelper.GetIsIdentity(x),
                    maxLength         = OpenApiMetadataDocumentHelper.GetMaxLength(x),
                    isDeprecated      = OpenApiMetadataDocumentHelper.GetIsDeprecated(x),
                    deprecatedReasons = OpenApiMetadataDocumentHelper.GetDeprecatedReasons(x)
                });
            });

            return(parameterList);
        }
Exemplo n.º 3
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)
            });
        }
 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)
     });
 }
Exemplo n.º 5
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);
        }
 private PathItem CreatePathItemForNonIdAccessedOperations(OpenApiMetadataPathsResource openApiMetadataResource,
                                                           bool isCompositeContext)
 => new PathItem
 {
     get = openApiMetadataResource.Readable
             ? CreateGetOperation(openApiMetadataResource, isCompositeContext)
             : null,
     post = openApiMetadataResource.Writable
             ? CreatePostOperation(openApiMetadataResource)
             : null
 };
        private IList <Parameter> CreatePutParameters(OpenApiMetadataPathsResource openApiMetadataResource)
        {
            IList <Parameter> parameterList = new List <Parameter>();

            parameterList.Add(OpenApiMetadataDocumentHelper.CreateIdParameter());

            parameterList.Add(CreateIfMatchParameter("PUT from updating"));
            parameterList.Add(CreateBodyParameter(openApiMetadataResource));

            return(parameterList);
        }
 private PathItem CreatePathItemForAccessByIdsOperations(OpenApiMetadataPathsResource openApiMetadataResource)
 => new PathItem
 {
     get = openApiMetadataResource.Readable
             ? CreateGetByIdOperation(openApiMetadataResource)
             : null,
     put = openApiMetadataResource.Writable
             ? CreatePutByIdOperation(openApiMetadataResource)
             : null,
     delete = openApiMetadataResource.Writable
             ? CreateDeleteByIdOperation(openApiMetadataResource)
             : null
 };
Exemplo n.º 10
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)
            });
        }
Exemplo n.º 11
0
        private IList <Parameter> CreateGetByExampleParameters(OpenApiMetadataPathsResource openApiMetadataResource,
                                                               bool isCompositeContext)
        {
            var parameterList = CreateQueryParameters(isCompositeContext)
                                .Concat(
                openApiMetadataResource.DefaultGetByExampleParameters.Select(
                    p => new Parameter {
                @ref = OpenApiMetadataDocumentHelper.GetParameterReference(p)
            }))
                                .ToList();

            IEnumerableExtensions.ForEach(
                openApiMetadataResource.RequestProperties, x =>
            {
                parameterList.Add(
                    new Parameter
                {
                    name = StringExtensions.ToCamelCase(x.PropertyName),
                    @in  = openApiMetadataResource.IsPathParameter(x)
                                ? "path"
                                : "query",
                    description       = OpenApiMetadataDocumentHelper.PropertyDescription(x),
                    type              = OpenApiMetadataDocumentHelper.PropertyType(x),
                    format            = x.PropertyType.ToOpenApiFormat(),
                    required          = openApiMetadataResource.IsPathParameter(x),
                    isIdentity        = OpenApiMetadataDocumentHelper.GetIsIdentity(x),
                    maxLength         = OpenApiMetadataDocumentHelper.GetMaxLength(x),
                    isDeprecated      = OpenApiMetadataDocumentHelper.GetIsDeprecated(x),
                    deprecatedReasons = OpenApiMetadataDocumentHelper.GetDeprecatedReasons(x)
                });
            });

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

            return(parameterList);
        }
        private Parameter CreateBodyParameter(OpenApiMetadataPathsResource openApiMetadataPathsResource)
        {
            var camelCaseName = openApiMetadataPathsResource.Resource.Name.ToCamelCase();

            var referenceName =
                _pathsFactoryNamingStrategy.GetResourceName(openApiMetadataPathsResource, ContentTypeUsage.Writable);

            return(new Parameter
            {
                name = camelCaseName,
                description =
                    $"The JSON representation of the \"{camelCaseName}\" resource to be created or updated.",
                @in = "body",
                required = true,
                schema = new Schema {
                    @ref = OpenApiMetadataDocumentHelper.GetDefinitionReference(referenceName)
                }
            });
        }
Exemplo n.º 13
0
        private Dictionary <string, Response> CreateReadResponses(OpenApiMetadataPathsResource openApiMetadataResource, bool isArray)
        {
            var responses = OpenApiMetadataDocumentHelper.GetReadOperationResponses(
                _pathsFactoryNamingStrategy.GetResourceName(openApiMetadataResource, ContentTypeUsage.Readable),
                isArray);

            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)."
                });
            }

            return(responses);
        }
 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)
     });
 }
Exemplo n.º 17
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)
     });
 }
 private IList <Parameter> CreatePostParameters(OpenApiMetadataPathsResource openApiMetadataResource)
 {
     return(new List <Parameter> {
         CreateBodyParameter(openApiMetadataResource)
     });
 }
Exemplo n.º 20
0
 private string GetDescription(OpenApiMetadataPathsResource openApiMetadataResource)
 {
     return(openApiMetadataResource.Resource.Entity.Identifier.IsUpdatable
         ? "The PUT operation is used to update a resource by identifier. If the resource identifier (\"id\") is provided in the JSON body, it will be ignored. Additionally, if natural key values are being updated by the JSON body, those changes will be applied to the resource and will also cascade through to dependent resources."
         : "The PUT operation is used to update a resource by identifier. If the resource identifier (\"id\") is provided in the JSON body, it will be ignored. Additionally, this API resource is not configured for cascading natural key updates. Natural key values for this resource cannot be changed using PUT operation and will not be modified in the database, and so recommendation is to use POST as that supports upsert behavior.");
 }
Exemplo n.º 21
0
 private bool?GetIsUpdatableCustomMetadataValue(OpenApiMetadataPathsResource openApiMetadataResource)
 => openApiMetadataResource.Resource.Entity.Identifier.IsUpdatable ? (bool?)true : null;
Exemplo n.º 22
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
            });
        }