hashicorp / terraform-plugin-codegen-openapi

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

Improve error messaging for property names that aren't valid Framework identifiers #71

Closed austinvalle closed 10 months ago

austinvalle commented 10 months ago

Context

Per: https://github.com/hashicorp/terraform-plugin-codegen-openapi/blob/main/DESIGN.md#attribute-names

Not all OAS properties can be automatically converted into a valid framework identifier, however the conversion process can leave some property names empty and cause confusing error messages.

Example:

"FakeResource": {
    "type": "object",
    "properties": {
        "+1": {
            "type": "integer"
            "description": "Number of upvotes"
        },
        "-1": {
            "type": "integer"
            "description": "Number of upvotes"
        },
    },
},

Resulting IR:

{
    // completely empty because there were no valid characters!
    "name": "",
    "int64": {
        "computed_optional_required": "computed"
    }
},
{
    // completely empty because there were no valid characters!
    "name": "",
    "int64": {
        "computed_optional_required": "computed"
    }
},

Error message:

time=2023-10-11T16:45:49.690-04:00 level=WARN msg="generated provider code spec failed validation" validationmsg="resources.0.schema.attributes.1.name: Does not match pattern '^[a-z][a-z0-9_]*$'"

Solutions

While we can't generate a valid framework name for this property, a better error message should be displayed with a reference to the offending property in the OAS

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.