Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PUT operations that return 204 No content #283

Closed
2 tasks done
dikhan opened this issue Mar 26, 2021 · 0 comments · Fixed by #284
Closed
2 tasks done

Add support for PUT operations that return 204 No content #283

dikhan opened this issue Mar 26, 2021 · 0 comments · Fixed by #284

Comments

@dikhan
Copy link
Owner

dikhan commented Mar 26, 2021

Describe the bug

Currently attempting to update a resource that supports the PUT operation and return a successful response 204 with no content in the response body fails.

As per the PUT specification:

If the target resource does have a current representation and that representation is successfully modified in accordance with the state of the enclosed representation, then the origin server must send either a 200 (OK) or a 204 (No Content) response to indicate successful completion of the request.

To Reproduce

A clear and concise description on how does it work now and what's the current behaviour.

Steps to reproduce the behavior:

  1. Given the OpenAPI spec below
  2. And having already provisioned the resource through terraform:
$ cat main.tf
resource "openapi_authority" "my_authority"   {
  label   = "some label"
}
  1. Attempting to update the resource will result into the following error:
$ cat main.tf
resource "openapi_authority" "my_authority"   {
  label   = "some updated label"
}
$ terraform apply
....
    Error: expected a response body but response body received was empty for request = 'PUT https://some-domain.com/authorities/3b2f5849-5282-4b83-981b-5731cd8e6228 HTTP/1.1'. Response = '204 No Content'

Expected behaviour

Example:

Scenario: Update works for resources where the PUT operation returns 204 with no content in the body
Given a compatible OpenAPI Terraform resource (as shown below) that exposes a PUT operation and the successful response is 204 with no content in the response body
When updating the resource after a successful creation in terraform
Then the apply should work as expected and the resulted state should contain the updated properties values as well as any other computed properties that were already in the state file for the resource updated.
  • Example OpenAPI document:
swagger: '2.0'
paths:
    post:
      x-terraform-resource-name: authority
      tags:
        - authorities
      summary: Create a Authority
      description: Allows the creation of a Authority
      operationId: createAuthority
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - in: body
          name: Authority
          required: true
          schema:
            $ref: '#/definitions/Authority'
      responses:
        '200':
          description: 200 OK
          schema:
            $ref: '#/definitions/Authority'
        '404':
          description: 404 NotFound
          schema:
            $ref: '#/definitions/Error'
        '500':
          description: 500 InternalError
          schema:
            $ref: '#/definitions/Error'

  /authorities/{id}:
    get:
      tags:
        - authorities
      summary: Get an existing Authority
      description: Get an already existing Authority
      operationId: getAuthority
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - type: string
          description: The authority id to be fetched
          name: id
          in: path
          required: true
      responses:
        '200':
          description: 200 OK
          schema:
            $ref: '#/definitions/Authority'
        '404':
          description: 404 NotFound
          schema:
            $ref: '#/definitions/Error'
        '500':
          description: 500 InternalError
          schema:
            $ref: '#/definitions/Error'
    put:
      tags:
        - authorities
      summary: Update an existing Authority
      description: Update an already existing Authority
      operationId: updateAuthorityUsingPut
      parameters:
        - type: string
          description: The authority id to be fetched
          name: id
          in: path
          required: true
        - in: body
          name: data
          required: true
          schema:
            $ref: '#/definitions/Authority'
      responses:
        '204':
          description: 204 No Content
        '404':
          description: 404 NotFound
          schema:
            $ref: '#/definitions/Error'
        '500':
          description: 500 InternalError
          schema:
            $ref: '#/definitions/Error'
  Authority:
    type: object
    required:
      - label
    description: Authority model
    properties:
      id:
        type: string
        readOnly: true
        description: Autogenerated UUID that identifies this authority
        example: "9662edf7-bdf4-40b5-9b6e-614baa816da9"
      label:
        type: string
        pattern: '^[a-zA-Z0-9_:\-\s]{1,64}$'
        description: Friendly label to help identify the authority
        example: "demo-authority"

Additional context

Add any other context about the problem here.

Checklist (for admin only)

Don't forget to go through the checklist to make sure the issue is created properly:

  • I have added a corresponding label (bug) to the issue (right side menu)
  • I have added this issue to the 'API Terraform Provider' GitHub project (right side menu)
@dikhan dikhan added the bug label Mar 26, 2021
@dikhan dikhan self-assigned this Mar 26, 2021
@dikhan dikhan added this to Backlog in API Terraform Provider (OpenAPI 2.0) via automation Mar 26, 2021
API Terraform Provider (OpenAPI 2.0) automation moved this from Backlog to Done Mar 29, 2021
dikhan added a commit that referenced this issue Mar 29, 2021
[BugFix: Issue #283] Add support for PUT operations that return 204 No Content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 participant