Skip to content

feat: variables in nested records and arrays#854

Merged
johngeorgewright merged 10 commits into
masterfrom
nested-variable
Mar 14, 2026
Merged

feat: variables in nested records and arrays#854
johngeorgewright merged 10 commits into
masterfrom
nested-variable

Conversation

@johngeorgewright

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings March 13, 2026 15:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 attachVariableResolver to recurse into array and record Zod schemas.
  • Add test coverage + snapshots for variables inside records and arrays.
  • Fix missing await usage 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.

Comment thread packages/api/src/parsers/attachVariableResolver.ts Outdated
Comment thread packages/api/src/parsers/attachVariableResolver.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 attachVariableResolver to recurse into Zod record and array schemas.
  • Add API tests/snapshots covering variables used inside record values and array elements.
  • Update @targetd/json-schema snapshot 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.

Comment thread packages/api/src/parsers/attachVariableResolver.ts Outdated
Comment thread packages/api/test/Data.test.ts
Comment thread packages/api/test/Data.test.ts Outdated
Copilot AI review requested due to automatic review settings March 14, 2026 12:14
johngeorgewright and others added 4 commits March 14, 2026 12:16
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 zodSwitch to store its union metadata directly on the schema instance and expose isZodSwitch for 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.

Comment thread packages/json-schema/src/index.ts Outdated
Comment thread packages/json-schema/src/index.ts
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 14, 2026 12:20
@johngeorgewright johngeorgewright merged commit 8e4e4d2 into master Mar 14, 2026
7 checks passed
@johngeorgewright johngeorgewright deleted the nested-variable branch March 14, 2026 12:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 zodSwitch to store its computed union metadata on the schema instance (removing the external registry) and expose an isZodSwitch helper.
  • 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(),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants