Repository navigation
feat(terraform): honor const values on array and map properties - #132
AshGodfrey wants to merge 3 commits into
Conversation
Array and map properties that declare a const value were parsed as ordinary fields: the schema parser only attached const/default metadata to containers when a default was present. Terraform therefore exposed them as configurable attributes and sent whatever was in state instead of the const value. - Parser: attach const metadata to arrays, sets and maps behind the new constArrays and constObjects features, and drop consts whose elements are not scalars with a validation warning. - Go models: emit a const struct tag carrying the JSON encoding for container fields, render Go literals for their getters, and compare received const values structurally when unmarshaling. - Terraform: declare the new features; the existing const handling already hides the fields from the resource schema and skips them when building requests, so the SDK model injects the value. Regenerates the review Go, CLI and Terraform fixtures and adds a ConstContainer entity with an acceptance test asserting the request body.
There was a problem hiding this comment.
2 issues found across 39 files
Confidence score: 4/5
- In
const_container.md,idis documented as read-only even though the schema requires it, which could lead users to omit a required field. Moveidto Required and leave onlynameunder Read-Only. - In
handle_array_test.go,ArrayWithConstItemTypeMismatchwould still pass if the required validation warning disappeared. Capture and assert the mismatch warning.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="zSDKs/terraform-provider-testing/docs/data-sources/const_container.md">
<violation number="1" location="zSDKs/terraform-provider-testing/docs/data-sources/const_container.md:24">
P2: `id` is required by `ConstContainerDataSource.Schema`, but this page documents it as read-only. Move `id` into a Required section and leave only `name` under Read-Only; otherwise users following the schema may omit an argument that Terraform rejects.</violation>
</file>
<file name="internal/schemas/handle_array_test.go">
<violation number="1" location="internal/schemas/handle_array_test.go:148">
P2: `ArrayWithConstItemTypeMismatch` verifies only that the const is omitted, so it would still pass if the required validation warning were removed or suppressed. Capture warnings for this case and assert the mismatch warning as well as the AST result.</violation>
</file>
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
- Gate container default and const metadata independently so a const cannot ride along on a target that only supports container defaults. - Reject consts on containers with nullable items, whose Go element type is a pointer the const renderer does not produce. - Accept uuid and duration items in container consts. - Compare received const values with exact JSON numbers instead of float64. - Record the cli target on the Go runtime changeset.
Generator Snapshot Testing
Snapshot results: https://github.com/speakeasy-api/openapi-generation-snapshots/issues/129#issuecomment-6345678600 Snapshot results are summarized above. Additional run context is linked for maintainers with access. |
There was a problem hiding this comment.
0 issues found across 10 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would auto-approve. Container consts for arrays/maps are now honored behind new experimental constArrays/constObjects feature gates, with guards for unsupported cases and acceptance tests covering emitted schemas and request bodies. Focused, tested bug fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
Summary
Array and map properties that declare a
constvalue were parsed as ordinary fields: the schema parser only attached const/default metadata to containers when adefaultwas present. Terraform therefore exposed them as configurable attributes and sent whatever was in state instead of the const value. Scalar consts were already handled correctly.constArraysandconstObjects(declared for the Terraform target). Consts whose elements are not scalars, or consts on objects with properties, are dropped with a validation warning.conststruct tag carrying the JSON encoding for container fields, render Go literals for their getters, and compare received const values structurally when unmarshaling so whitespace differences from the server do not fail decoding.Behavior change
For providers whose spec has
conston an array or map property, the attribute is removed from the resource schema. Configs that set it will need the line removed. Prior state is unaffected: the plugin framework drops attributes the schema no longer has.Testing
ConstContainerentity in the review spec with an acceptance test asserting the request body carries[],["read","write"],{}and{"max":10}while the config sets onlyname.make lint, and template type checks pass. Review Go, CLI and Terraform fixtures regenerated.Summary by cubic
Fixes
constvalues on array and map properties being parsed as configurable attributes, so Terraform sent whatever was in state instead of the const value. Consts on arrays, sets, and maps are now attached behind two new Experimental features,constArraysandconstObjects, hidden from the resource schema, and injected into request bodies. Scalar consts were already handled correctly.Behavior change
Written for commit 5bd87c0. Summary will update on new commits.