feat: variables in nested records and arrays#854
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for using {{variables}} inside nested payload structures (records and arrays) in @targetd/api’s rule parsing/validation layer, with tests to lock in the behavior.
Changes:
- Extend
attachVariableResolverto recurse intoarrayandrecordZod schemas. - Add test coverage + snapshots for variables inside records and arrays.
- Fix missing
awaitusage for async snapshot assertions in existing variables tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/api/src/parsers/attachVariableResolver.ts | Adds recursive variable resolver attachment for Zod arrays/records. |
| packages/api/test/Data.test.ts | Adds new tests for variables in records/arrays; fixes snapshot assertions to be awaited. |
| packages/api/test/snapshots/Data.test.ts.snap | Updates snapshots for the new tests/behavior. |
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Adds support for variable placeholders ({{var}}) inside nested payload structures (records and arrays) in the core @targetd/api parsing pipeline, and updates downstream JSON Schema + API snapshots accordingly.
Changes:
- Extend
attachVariableResolverto recurse into Zodrecordandarrayschemas. - Add API tests/snapshots covering variables used inside record values and array elements.
- Update
@targetd/json-schemasnapshot output to reflect the new variable-capable schemas.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/api/src/parsers/attachVariableResolver.ts | Recursively attaches variable resolvers to array elements and record value types. |
| packages/api/test/Data.test.ts | Adds tests for variables inside records/arrays; fixes missing await on snapshot assertions. |
| packages/api/test/snapshots/Data.test.ts.snap | New snapshots for added variable-in-record/array tests. |
| packages/json-schema/test/snapshots/index.test.ts.snap | Updates expected JSON Schema output after variable resolver recursion changes. |
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds support for using {{variable}} placeholders inside nested payload shapes (records and arrays) and updates JSON Schema generation to understand the new ZodSwitch implementation used by variable resolvers.
Changes:
- Extend variable resolver attachment and runtime resolution to traverse arrays and records (not just objects).
- Refactor
zodSwitchto store its union metadata directly on the schema instance and exposeisZodSwitchfor detection. - Update json-schema fixtures/snapshots and add API tests/snapshots covering nested variable cases.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/api/src/parsers/attachVariableResolver.ts | Recursively attaches variable resolvers through array/record element/value schemas. |
| packages/api/src/parsers/DataItemVariableResolver.ts | Allows resolving variable resolvers within arrays; makes the variable string parser a factory. |
| packages/api/src/parsers/switch.ts | Reworks zodSwitch into a constructed schema that carries its union for downstream consumers. |
| packages/api/test/Data.test.ts | Adds tests for variables in records/arrays; fixes missing await on snapshot assertions. |
| packages/api/test/snapshots/Data.test.ts.snap | Updates snapshots for new nested-variable tests. |
| packages/json-schema/src/index.ts | Updates JSON Schema override logic to inline ZodSwitch unions using isZodSwitch. |
| packages/json-schema/test/fixtures/data.ts | Adds record payload (car) and uses zod/mini in fixture. |
| packages/json-schema/test/snapshots/index.test.ts.snap | Snapshot updates reflecting record/variables schema output changes. |
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds support for using {{variables}} inside nested array and record payload structures across the targeting/data pipeline, and updates JSON Schema generation to correctly represent the underlying union types used for variable-enabled parsing.
Changes:
- Extend variable-resolver attachment and runtime resolution to support arrays and records (in addition to objects).
- Refactor
zodSwitchto store its computed union metadata on the schema instance (removing the external registry) and expose anisZodSwitchhelper. - Update JSON Schema generation + fixtures/snapshots/tests to cover the new behaviors.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/api/src/parsers/attachVariableResolver.ts | Adds recursive variable-resolver support for $ZodArray and $ZodRecord payload schemas. |
| packages/api/src/parsers/DataItemVariableResolver.ts | Enables variable resolution within arrays (and broadens object recursion). |
| packages/api/src/parsers/switch.ts | Replaces registry-based switch metadata with a constructor-backed ZodSwitch that carries its union. |
| packages/api/test/Data.test.ts | Adds tests for variables in records and arrays; fixes async snapshot usage. |
| packages/api/test/snapshots/Data.test.ts.snap | Updates snapshots for new array-variable test coverage. |
| packages/json-schema/src/index.ts | Updates schema override handling to inline the ZodSwitch union during JSON Schema generation. |
| packages/json-schema/test/fixtures/data.ts | Extends JSON-schema fixture payloads to include record/array shapes and adjusts Zod import. |
| packages/json-schema/test/snapshots/index.test.ts.snap | Snapshot updates reflecting new schema shapes/definitions. |
You can also share your feedback on Copilot code review. Take the survey.
| Object.assign( | ||
| ctx.jsonSchema, | ||
| toJSONSchema(ctx.zodSchema._zod.def.union, { | ||
| ...toJSONSchemaParams(), |
No description provided.