hashicorp / terraform-plugin-codegen-openapi

OpenAPI to Terraform Provider Code Generation Specification

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Maps that utilize `allOf` or `oneOf` result in an empty single nested attribute

austinvalle opened this issue · comments

tfplugingen-openapi CLI version

tfplugingen-openapi module: v0.2.0

OpenAPI Spec File

openapi: 3.1.0
info:
  title: EdgeCase API
  version: 1.0.0
paths:
  /map_test:
    get:
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  map_stringified:
                    $ref: "#/components/schemas/map_allof_oneof_stringified"
    post:
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                map_stringified:
                  $ref: "#/components/schemas/map_allof_oneof_stringified"
components:
  schemas:
    map_allof_oneof_stringified:
      description: This is a map with a stringifed value
      type: object
      additionalProperties:
        allOf:
        - $ref: "#/components/schemas/stringable_number"
    stringable_number:
      oneOf:
      - type: string
      - type: number

Generator Config

provider:
  name: edgecase

resources:
  map_test:
    create:
      path: /map_test
      method: POST
    read:
      path: /map_test
      method: GET

Expected Behavior

Maps (using the additionalProperties property) should be able to leverage nullable and stringable types

{
  "provider": {
    "name": "edgecase"
  },
  "resources": [
    {
      "name": "map_test",
      "schema": {
        "attributes": [
          {
            "name": "map_stringified",
            "map": {
              "computed_optional_required": "computed_optional",
              "element_type": {
                "string": {}
              },
              "description": "This is a map with a stringifed value"
            }
          }
        ]
      }
    }
  ],
  "version": "0.1"
}

Actual Behavior

The map is returned in the IR output as a single nested attribute with no attributes

{
  "provider": {
    "name": "edgecase"
  },
  "resources": [
    {
      "name": "map_test",
      "schema": {
        "attributes": [
          {
            "name": "map_stringified",
            "single_nested": {
              "computed_optional_required": "computed_optional",
              "description": "This is a map with a stringifed value"
            }
          }
        ]
      }
    }
  ],
  "version": "0.1"
}

Additional Information

This bug was originally discovered in the Kubernetes code generation effort

Code of Conduct

  • I agree to follow this project's Code of Conduct

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.