Skip to content

Migrate external commands to Zod#7369

Open
waldekmastykarz wants to merge 2 commits into
pnp:mainfrom
waldekmastykarz:waldekmastykarz/migrate-external-to-zod
Open

Migrate external commands to Zod#7369
waldekmastykarz wants to merge 2 commits into
pnp:mainfrom
waldekmastykarz:waldekmastykarz/migrate-external-to-zod

Conversation

@waldekmastykarz

Copy link
Copy Markdown
Member

Summary

Migrates all external commands from the legacy options/validators/telemetry pattern to Zod schema validation.

Closes #7302

Changes

Migrated the following commands:

  • connection-add — ID validation (length, alphanumeric, reserved words) via .min()/.max()/.refine()
  • connection-get — Option set (id/name) via getRefinedSchema()
  • connection-remove — Option set (id/name) + force boolean via getRefinedSchema()
  • connection-doctorux enum validation via z.enum()
  • connection-schema-add — External connection ID + JSON schema content validation via .refine()
  • connection-urltoitemresolver-add — Simple required options migration
  • item-add — ACL validation via .refine(), uses z.object (not z.strictObject) for allowUnknownOptions support, switched to addUnknownOptionsToPayloadZod

connection-list was already migrated to Zod.

Testing

  • All 15724 tests pass
  • Lint passes
  • 100% coverage on all changed files

Migrates all external commands (connection-add, connection-get,
connection-remove, connection-doctor, connection-schema-add,
connection-urltoitemresolver-add, item-add) from the legacy
options/validators pattern to Zod schema validation.

Closes pnp#7302

Co-authored-by: Copilot <223556219+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

This PR migrates the external workload commands shown in the diff from the legacy options/validators approach to schema-driven validation using Zod, aligning them with the CLI’s schema-based parsing/validation/telemetry pipeline.

Changes:

  • Introduces Zod schemas (schema + getRefinedSchema where needed) for multiple external connection/item commands.
  • Replaces legacy validator-based tests with direct schema safeParse(...) validation tests.
  • Updates unknown-option payload handling to the Zod-aware helper where applicable.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/m365/external/commands/item/item-add.ts Adds Zod schema for item creation options and switches to Zod-aware unknown-option payload helper.
src/m365/external/commands/item/item-add.spec.ts Updates validation tests to use schema safeParse.
src/m365/external/commands/connection/connection-urltoitemresolver-add.ts Adds Zod schema for URL-to-item resolver creation options.
src/m365/external/commands/connection/connection-urltoitemresolver-add.spec.ts Updates tests to validate via schema and adds unknown-option negative test.
src/m365/external/commands/connection/connection-schema-add.ts Adds Zod schema with refined validation for connection ID and schema JSON content.
src/m365/external/commands/connection/connection-schema-add.spec.ts Updates schema/id/schema JSON validation tests to use safeParse.
src/m365/external/commands/connection/connection-remove.ts Adds strict Zod schema + refined option-set validation (id xor name).
src/m365/external/commands/connection/connection-remove.spec.ts Adds schema-based option-set and unknown-option validation tests.
src/m365/external/commands/connection/connection-get.ts Adds strict Zod schema + refined option-set validation (id xor name).
src/m365/external/commands/connection/connection-get.spec.ts Adds schema-based option-set and unknown-option validation tests.
src/m365/external/commands/connection/connection-doctor.ts Adds strict Zod schema for id and ux (enum).
src/m365/external/commands/connection/connection-doctor.spec.ts Updates ux validation tests to schema safeParse and adds unknown-option negative test.
src/m365/external/commands/connection/connection-add.ts Adds strict Zod schema for connection creation, including reserved ID checks.
src/m365/external/commands/connection/connection-add.spec.ts Updates connection ID validation tests to use schema safeParse and adds unknown-option negative test.

Comment thread src/m365/external/commands/item/item-add.ts
Comment thread src/m365/external/commands/connection/connection-add.ts
Comment thread src/m365/external/commands/connection/connection-schema-add.ts
@MartinM85 MartinM85 marked this pull request as draft June 3, 2026 05:39
- connection-add: use message instead of error in refinement
- connection-schema-add: add separate JSON parse validation refinement
- item-add: add .passthrough() to z.object() for unknown options

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@waldekmastykarz waldekmastykarz marked this pull request as ready for review June 5, 2026 11:16
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.

Migrate external commands to Zod

2 participants