Repository navigation
feat(terraform): honor const values on array and map properties - #132
AshGodfrey wants to merge 26 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.
All reported issues were addressed across 39 files
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-6914899500 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
… to end Reject container consts whose value is null, whose array has uniqueItems (the server may return the elements in any order), or whose items are bigint, decimal or string-serialized numbers (the const JSON would not match the field's wire form). The mockserver's unmarshaler compares received const values structurally like the SDK does. Parser tests capture validation warnings and cover sets, nested arrays, null, mixed and bigint items, uuid items, default plus const, free-form and array-valued maps, and value type mismatches. Terraform acceptance tests assert the create request body carries only name and the four const values, that a read accepting differently formatted const values refreshes cleanly, and that the data source reads it.
There was a problem hiding this comment.
All reported issues were addressed across 8 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 18 files (changes from recent commits).
Shadow auto-approve: would not auto-approve. Auto-approval blocked by 3 unresolved issues from previous reviews.
View guided diff | Turn on auto-fix | Re-trigger cubic
…low string items with a string format Only a const tag that holds a JSON array or object is compared structurally, so a scalar string const such as 1.0 no longer accepts the JSON number 1 in either the SDK or the mockserver. The string-serialized-number guard applies to numeric item types only. The review const container gains a two-key map so the acceptance test covers key-order-insensitive comparison on read.
There was a problem hiding this comment.
0 issues found across 29 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. Adds feature-gated const handling for array/map properties: parser metadata plus warnings for unsupported shapes, Go const tags/literals and structural JSON comparison, Terraform hides const attributes; parser and acceptance tests cover the behavior.
View guided diff | Turn on auto-fix | Re-trigger cubic
Const values decoded from the document reach the templates as Go maps whose key order is unstable, so the const struct tag, the getter literal and the request body examples changed between generation runs. Rebuild map values with sorted keys where they are rendered.
There was a problem hiding this comment.
All reported issues were addressed across 7 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 1 file (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 not auto-approve. Auto-approval blocked by 1 unresolved issue from previous reviews.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 1 file (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. Adds feature-gated const support for array/map properties across parsing, Go models, and Terraform, with tests for unsupported shapes and JSON comparison.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 2 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. Adds feature-gated const handling for array/map properties in the schema parser, Go models, and Terraform generation; unsupported shapes are dropped with validation warnings and container consts are compared structurally with tests.
View guided diff | Turn on auto-fix | Re-trigger cubic
…ck enum const items Unmarshaling used the const tag text to detect container consts, so a JSON string whose text matched the tag was accepted for a slice or map field, and a string const beginning with a bracket could be satisfied by an equivalent array body. The structural comparison now applies only when the Go field is a slice or map, and scalar fields keep the exact-text check. Enum items in a container const must match the enum's underlying type before the value is looked up in the enum's members. The go/cli changeset now describes the unmarshaling change those targets actually receive.
There was a problem hiding this comment.
0 issues found across 27 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. Feature-gated const support for Terraform array/map properties plus structural const comparison in generated Go SDKs; unsupported const shapes are dropped with validation warnings and pinned by parser/acceptance tests, keeping the change bounded.
View guided diff | Turn on auto-fix | Re-trigger cubic
ThomasRooney
left a comment
There was a problem hiding this comment.
- Requesting an e2e test with an example/actual customer scenario using a mocked http server in a fork of their provider that we convert into a terraform test using the public rules (abstract it so no signal [ACME corp] etc). Specifically I'm thinking about multi-api scenarios too.
- There are some really weird subtypes that can be created with container types : let's try and have a few tests around the boundaries of this so that we:
- Ensure we match existing semantics around
constapplied to request vs response types - Ensure we limit the boundaries of this to things we test (e.g. maps of primitives, arrays of primitives etc)
An array declared with `format: set` or `uniqueItems: true` and `const: []` had its const dropped, because set types were rejected outright. Element order cannot matter for an empty list, so an empty const is now accepted on those arrays regardless of item type; a non-empty const on them is still rejected. This covers request bodies that must send an empty set, such as a teardown operation that replaces a collection of object items with `[]`. The review Terraform ConstContainer entity gains an `empty_set` property (a set of objects with `const: []`) and its acceptance test asserts the request body carries it.
There was a problem hiding this comment.
All reported issues were addressed across 8 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
…late delimiters in const map keys
A const array or map declared on a property of a list item's object schema
made Terraform generation fail: the list-item field loop in the TF-to-SDK
builder matched hidden const fields positionally against the Terraform type,
hit the wrong field and raised "Unexpected type detected". The loop now skips
const fields, as the object-level loop already did; the SDK model injects the
value.
A const map whose key contains `{{` broke template parsing when rendering the
Go literal for the field's getter. Keys are now escaped the same way string
values are.
The review fixture gains a list-of-objects property with a nested const array
and a map const with a `{{` key; the lifecycle test asserts both reach the
request body and round-trip through a read.
There was a problem hiding this comment.
All reported issues were addressed across 19 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
…prefixes The review fixture gains a ConstEmptySetDelete entity shaped like an API whose desired state is a set of objects: one PUT serves create and update, and delete is a separate PUT under another API version prefix whose body declares the same set with `format: set` and `const: []`. The response carries a readOnly const array. The acceptance test drives create, a no-op plan, an update and destroy against the mock server and asserts the replace bodies carry the configured group while the teardown body carries `scope_id` and an empty `groups` array, never the groups held in state. The readOnly const never appears in a request body and decodes from every response. The mock server's delete handler now captures a JSON request body when one is sent, so tests can assert delete bodies like create and update bodies.
|
Re the review asks:
|
There was a problem hiding this comment.
All reported issues were addressed across 22 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
…den mock delete body capture A new acceptance case returns a wrong value for the response-only const array and asserts the apply fails with the const mismatch error, so the lifecycle test's claim that the const is checked on decode is exercised. The mock server's delete handler reads the whole body and decodes it only when non-empty, so a chunked request without a body is not rejected, and a malformed body is still recorded in the request log before the 400, as the create and update handlers do.
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
The mock server's delete handler ignored the body read error, so a failed or partial read could still delete the stored resource. A read error is now handled like a decode error: the request is logged with a nil body and answered with 400 before the store changes.
There was a problem hiding this comment.
0 issues found across 1 file (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 not auto-approve. Auto-approval blocked by 1 unresolved issue from previous reviews.
View guided diff | Turn on auto-fix | Re-trigger cubic
An array with `const: []` and `minItems: 1` cannot be satisfied by any value, so the const is now dropped with a validation warning like the other unsupported container const shapes, instead of being emitted on the model.
There was a problem hiding this comment.
0 issues found across 2 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. Feature-gated Terraform const support for arrays/maps: unsupported shapes dropped with validation warnings, Go SDKs compare container consts structurally, nested-list builder fixed; parser/acceptance tests pin behavior with no default exposure.
View guided diff | Turn on auto-fix | Re-trigger cubic
…for optional container consts A non-empty array const that falls outside the schema's own minItems or maxItems is dropped with a validation warning instead of being baked into every request. JSON unmarshaling treats null as absent for a container const field that is optional or nullable, so a response that sends null for such a field no longer fails to decode.
There was a problem hiding this comment.
All reported issues were addressed across 19 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
Match omitempty and omitzero as exact comma-separated options rather than a substring of the tag, so a property whose name contains omitempty is not treated as optional and omitzero fields accept null.
There was a problem hiding this comment.
All reported issues were addressed across 24 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
…iner consts OptionalNullable[T] is a map kind, so a wrapped scalar const was compared structurally and a wrapped container const rejected null. Classify by the wrapped type and treat the wrapper as nullable.
There was a problem hiding this comment.
0 issues found across 24 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. Feature-gated const arrays/maps for Terraform: parser drops unsupported shapes behind experimental flags, Go SDKs compare container consts structurally and accept optional null, list-item builder skips consts; tests pin behavior.
View guided diff | Turn on auto-fix | Re-trigger cubic
A required nullable const list returned as null now decodes as absent, so null is treated as absent for every container const rather than only optional ones. Map const keys and values with quotes, backslashes and newlines round-trip through the struct tag and the Go literal. A const array on a query parameter is dropped with a validation warning instead of being serialized as its JSON text, keeping container consts to body properties.
There was a problem hiding this comment.
1 issue found across 40 files (changes from recent commits).
Confidence score: 3/5
- In
constcontainer_resource.go, the extra GET can fail after the POST succeeds, leaving the remote resource created while Terraform reports creation failure. Remove the extra GET.
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/internal/provider/constcontainer_resource.go">
<violation number="1" location="zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource.go:177">
P2: This extra GET makes a successful Create depend on a second read returning 200 immediately. A transient 404 or 5xx after the POST leaves the remote resource created while Terraform reports creation failure; remove this post-create GET or retry it with read semantics.</violation>
</file>
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
| request1, request1Diags := data.ToOperationsGetConstContainerRequest(ctx) |
There was a problem hiding this comment.
P2: This extra GET makes a successful Create depend on a second read returning 200 immediately. A transient 404 or 5xx after the POST leaves the remote resource created while Terraform reports creation failure; remove this post-create GET or retry it with read semantics.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. 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. At zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource.go, line 177:
<comment>This extra GET makes a successful Create depend on a second read returning 200 immediately. A transient 404 or 5xx after the POST leaves the remote resource created while Terraform reports creation failure; remove this post-create GET or retry it with read semantics.</comment>
<file context>
@@ -171,6 +171,43 @@ func (r *ConstContainerResource) Create(ctx context.Context, req resource.Create
+ if resp.Diagnostics.HasError() {
+ return
+ }
+ request1, request1Diags := data.ToOperationsGetConstContainerRequest(ctx)
+ resp.Diagnostics.Append(request1Diags...)
+
</file context>
There was a problem hiding this comment.
Not from this PR: the read-after-create is the generator's standard pattern whenever a resource's read operation takes parameters, and three other review resources already carry it. It surfaced here only because the fixture added a query parameter to the read operation to pin container consts on parameters. Changing the create flow belongs in its own change.
Content-based path and query parameters now carry the parameter type into the schema parser, so an array or map const on them is dropped with the same validation warning as on plain parameters.
There was a problem hiding this comment.
0 issues found across 1 file (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. Experimental feature-gated Terraform const support for arrays/maps: parser attaches/drops container consts with warnings, Go unmarshal compares structurally and treats null as absent, TF builder skips const fields; tests pin behavior.
View guided diff | Turn on auto-fix | Re-trigger cubic
…roperties # Conflicts: # zSDKs/sdk-cli/.speakeasy/gen.lock # zSDKs/sdk-go/.speakeasy/gen.lock # zSDKs/terraform-provider-testing/.speakeasy/gen.lock
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). A const is dropped with a validation warning when it isnull, when a non-empty const is on an array withuniqueItemsorformat: set(the server may return the elements in any order, and the comparison is positional; an empty const is accepted on these, with any item type), when an element is not a scalar of the declared item type, when the items are bigint, decimal or string-serialized numbers (the const JSON would not match the field's wire form), or when the container is an object with properties. Accepted item types: boolean, integer, number, string, date, date-time, uuid, duration and enums.conststruct tag carrying the JSON encoding for container fields, render Go literals for their getters, and compare received const values structurally when unmarshaling (whitespace, map key order and number formatting such as10vs1e1do not fail decoding; values are compared numerically). The mockserver's unmarshaler applies the same comparison.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.A server that returns
nullfor an optional const container now fails decoding, as it already did for scalar consts; before this change the field was a plain optional field andnulldecoded fine.Testing
internal/schemas/handle_array_test.go,handle_object_test.go) capture validation warnings and assert exactly one for every rejected shape: item type mismatch, nullable items,uniqueItems, nested arrays,null, mixed and bigint items, objects with properties, free-form and array-valued maps, and map value type mismatches. Accepted shapes covered: string, empty, uuid items, empty const withuniqueItems, empty const withformat: set, default plus const on one container, feature off. A non-empty const on a set is rejected.ConstContainerentity in the review Terraform spec with acceptance tests (zSDKs/terraform-provider-testing/internal/provider/constcontainer_resource_test.go,constcontainer_data_source_test.go): the create request body carries onlynameand the five const values ([],["read","write"], an empty set of objects,{},{"max":10}); a read returning the consts with different whitespace, key order and1e1refreshes and imports cleanly; the data source reads the entity.make lint, and template type checks pass. Review Go, CLI and Terraform fixtures regenerated.Adversarial coverage
A throwaway provider was generated from a spec that puts const containers in every shape the gate could plausibly let through, then exercised at the SDK level (marshal, unmarshal, delete body) and compiled as a provider.
Accepted and verified end to end: strings containing
",\, backticks,{{, newlines and non-ASCII (both the struct tag and the getter literal escape correctly, and the backtick case switches the whole struct to double-quoted tags); map keys with the same characters; strings that look like JSON ("[1,2]","null") stay strings; mixed number forms (2.5,1e3,-0.0); float, int64, date, date-time, boolean, integer-enum and open-enum items; duplicate items; empty const on an untyped array, a free-form map, auniqueItemslist of objects and aformat: setlist of objects;nullable: trueandtype: [array, "null"](accepted, the field becomes a non-nullable slice);readOnly/writeOnlyconsts land only on the response/request model; a const query parameter is sent by the Go param serializer; consts nested in a plain object, a list item's object, anallOfmember and aoneOfmember are hidden from the Terraform schema and injected per item.Rejected with a validation warning:
[1, 2.0]on integer items (no float-to-int coercion for container items),[string, "null"]items with anullelement,prefixItemstuples, map of maps, a non-array const on an array, a non-object const on a map, decimal items.Unmarshal behaviour pinned: reordered map keys, whitespace,
1.0/1e3/-0.0, and\u00e9escapes decode; a missing const field decodes; a wrong value, reordered array elements,null,[]for a map const, and a JSON-looking string returned as a real array all fail withconst field ... does not match.Known limitation, pre-existing for scalar consts too: integer consts above 2^53 lose precision when rendered (
9007199254740993becomes9007199254740992).