hashicorp / terraform-plugin-codegen-openapi

OpenAPI to Terraform Provider Code Generation Specification
Mozilla Public License 2.0
49 stars 9 forks source link

Unconfigurable Data Source Attributes Output as Optional #36

Closed bflad closed 1 year ago

bflad commented 1 year ago

Given the following configuration:

data_sources:
  pet:
    read:
      path: /pet/{petId}
      method: GET

And OpenAPI specification:

    "paths": {
        "/pet/{petId}": {
            "get": {
                "tags": [
                    "pet"
                ],
                "summary": "Find pet by ID",
                "description": "Returns a single pet",
                "operationId": "getPetById",
                "parameters": [
                    {
                        "name": "petId",
                        "in": "path",
                        "description": "ID of pet to return",
                        "required": true,
                        "schema": {
                            "type": "integer",
                            "format": "int64"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "successful operation",
                        "content": {
                            "application/xml": {
                                "schema": {
                                    "$ref": "#/components/schemas/Pet"
                                }
                            },
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Pet"
                                }
                            }
                        }
                    },

Currently the generated specification is:

    "datasources": [
        {
            "name": "pet",
            "schema": {
                "attributes": [
                    {
                        "name": "petId",
                        "int64": {
                            "computed_optional_required": "required",
                            "description": "ID of pet to return"
                        }
                    },
                    {
                        "name": "category",
                        "single_nested": {
                            "computed_optional_required": "computed_optional",
                            "attributes": [
                                {
                                    "name": "id",
                                    "int64": {
                                        "computed_optional_required": "computed_optional",
                                        "description": ""
                                    }
                                },
                                {
                                    "name": "name",
                                    "string": {
                                        "computed_optional_required": "computed_optional",
                                        "description": "",
                                        "sensitive": false
                                    }
                                }
                            ],
                            "description": ""
                        }
                    },
                    {
                        "name": "id",
                        "int64": {
                            "computed_optional_required": "computed_optional",
                            "description": ""
                        }
                    },
                    {
                        "name": "name",
                        "string": {
                            "computed_optional_required": "computed_optional",
                            "description": "",
                            "sensitive": false
                        }
                    },
                    {
                        "name": "photoUrls",
                        "list": {
                            "computed_optional_required": "computed_optional",
                            "element_type": {
                                "string": {}
                            },
                            "description": ""
                        }
                    },
                    {
                        "name": "status",
                        "string": {
                            "computed_optional_required": "computed_optional",
                            "description": "pet status in the store",
                            "sensitive": false
                        }
                    },
                    {
                        "name": "tags",
                        "list_nested": {
                            "computed_optional_required": "computed_optional",
                            "nested_object": {
                                "attributes": [
                                    {
                                        "name": "id",
                                        "int64": {
                                            "computed_optional_required": "computed_optional",
                                            "description": ""
                                        }
                                    },
                                    {
                                        "name": "name",
                                        "string": {
                                            "computed_optional_required": "computed_optional",
                                            "description": "",
                                            "sensitive": false
                                        }
                                    }
                                ]
                            },
                            "description": ""
                        }
                    }
                ]
            }
        },

The attributes outside petId (e.g. from the response) should all be Computed-only, not Optional and Computed, since Optional means the generated code will not return an error if a practitioner attempts to configure a value. This would also affect the documentation for these attributes by putting them in the incorrect section.

github-actions[bot] commented 3 months ago

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.