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

Nested optional objects skip parent objects when omitted #330

Open
2 tasks
arjunrajinstaclustr opened this issue Mar 8, 2022 · 0 comments
Open
2 tasks

Comments

@arjunrajinstaclustr
Copy link

arjunrajinstaclustr commented Mar 8, 2022

Describe the bug

If you have an optional object that is located under a nested object, omitting the optional object through the terraform code omits the parent object on the request body too.

To Reproduce

With the following swagger YAML -

paths:
  /v1/characters:
    post:
      parameters:
        -
          name: body
          schema:
            $ref: '#/definitions/Character'
          in: body
          required: true
      responses:
        '200':
          description: Character created
          schema:
            $ref: '#/definitions/Character'
      summary: Create character
  '/v1/characters/{characterId}':
    get:
      parameters:
        -
          name: characterId
          in: path
          required: true
          type: string
      responses:
        '200':
          description: Character fetched.
          schema:
            $ref: '#/definitions/Character'
      summary: Retrieve character

definitions:
  Position:
    title: Root Type for Position
    description: ''
    type: object
    properties:
      x:
        type: integer
      'y':
        type: integer
  Character:
    title: Root Type for Character
    description: ''
    required:
      - health
    type: object
    properties:
      id:
        type: string
        readOnly: true
      health:
        type: integer
      position:
        $ref: '#/definitions/Position'
      pet:
        $ref: '#/definitions/Pet'
  Pet:
    title: Root Type for Pet
    description: ''
    required:
      - health
    type: object
    properties:
      id:
        type: string
        readOnly: true
      health:
        type: integer
      position:
        $ref: '#/definitions/Position'

the following terraform code works fine -

resource "myprovider_characters_v1" "mychar" {
  health = 10
  position {
    x = 1
    y = 1
  }
  pet {
    health = 30
    position {
      x = 2
      y = 2
    }
  }
}

The request body is {"health":10,"pet":{"health":30,"position":{"x":2,"y":2}},"position":{"x":1,"y":1}}

However the following terraform code runs into a problem -

resource "myprovider_characters_v1" "mychar" {
  health = 10
  position {
    x = 1
    y = 1
  }
  pet {
    health = 30
  }
}

The problematic request body - {"health":10,"position":{"x":1,"y":1}} - skips the pet object because the optional position object is omitted from the terraform code.

Expected behaviour

Omitting optional nested objects continues to include the parent object in the request body.

Additional context

Interestingly, omitting position on the Character level does not cause an issue. This is only a problem for optional objects under nested objects.

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant