Exemplo n.º 1
0
        private IList <Parameter> CreateGetByExampleParameters(SwaggerPathsResource swaggerResource)
        {
            var parameterList = CreateQueryParameters()
                                .Concat(
                swaggerResource.DefaultGetByExampleParameters.Select(
                    p => new Parameter {
                @ref = SwaggerDocumentHelper.GetParameterReference(p)
            }))
                                .ToList();

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

            return(parameterList);
        }
Exemplo n.º 2
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)
     });
 }
Exemplo n.º 3
0
 private PathItem CreatePathItemForChangeQueryOperation(SwaggerPathsResource swaggerResource)
 => new PathItem
 {
     get = swaggerResource.Writable
             ? CreateDeletesOperation(swaggerResource)
             : null
 };
Exemplo n.º 4
0
 private PathItem CreatePathItemForNonIdAccessedOperations(SwaggerPathsResource swaggerResource)
 => new PathItem
 {
     get = swaggerResource.Readable
             ? CreateGetOperation(swaggerResource)
             : null,
     post = swaggerResource.Writable
             ? CreatePostOperation(swaggerResource)
             : null
 };
Exemplo n.º 5
0
        private IList <Parameter> CreatePutParameters(SwaggerPathsResource swaggerResource)
        {
            IList <Parameter> parameterList = new List <Parameter>();

            parameterList.Add(SwaggerDocumentHelper.CreateIdParameter());

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

            return(parameterList);
        }
Exemplo n.º 6
0
 private PathItem CreatePathItemForAccessByIdsOperations(SwaggerPathsResource swaggerResource)
 => new PathItem
 {
     get = swaggerResource.Readable
             ? CreateGetByIdOperation(swaggerResource)
             : null,
     put = swaggerResource.Writable
             ? CreatePutByIdOperation(swaggerResource)
             : null,
     delete = swaggerResource.Writable
             ? CreateDeleteByIdOperation(swaggerResource)
             : null
 };
Exemplo n.º 7
0
        private Parameter CreateBodyParameter(SwaggerPathsResource swaggerPathsResource)
        {
            var camelCaseName = swaggerPathsResource.Resource.Name.ToCamelCase();

            var referenceName =
                _pathsFactoryNamingStrategy.GetResourceName(swaggerPathsResource, 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 = SwaggerDocumentHelper.GetDefinitionReference(referenceName)
                }
            });
        }
Exemplo n.º 8
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)
     });
 }
Exemplo n.º 9
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)
     });
 }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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)
     });
 }
Exemplo n.º 12
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)
     });
 }
Exemplo n.º 13
0
 private IList <Parameter> CreatePostParameters(SwaggerPathsResource swaggerResource)
 {
     return(new List <Parameter> {
         CreateBodyParameter(swaggerResource)
     });
 }