Skip to content

Migrate pa commands to Zod schema validation#7411

Draft
waldekmastykarz wants to merge 1 commit into
pnp:mainfrom
waldekmastykarz:waldekmastykarz-migrate-pa-commands-to-zod
Draft

Migrate pa commands to Zod schema validation#7411
waldekmastykarz wants to merge 1 commit into
pnp:mainfrom
waldekmastykarz:waldekmastykarz-migrate-pa-commands-to-zod

Conversation

@waldekmastykarz

Copy link
Copy Markdown
Member

What's in this PR

Migrates all pa commands from the legacy #initOptions()/#initValidators()/#initTelemetry() pattern to Zod schema-based validation.

Commands migrated

  • pa app consent set
  • pa app export
  • pa app get
  • pa app list
  • pa app owner set
  • pa app permission ensure
  • pa app permission list
  • pa app permission remove
  • pa app remove
  • pa connector export
  • pa connector list

Changes per command

  • Replaced #initOptions(), #initValidators(), #initTelemetry(), #initTypes(), #initOptionSets() with exported options Zod schema
  • Added schema getter and getRefinedSchema() for cross-field validation
  • Updated spec files to use commandOptionsSchema.safeParse() for validation tests and commandOptionsSchema.parse() for action tests
  • Removed legacy "supports specifying" tests
  • Added "fails validation with unknown options" tests

Closes #7310

Migrates the following commands to use Zod schemas:
- pa app consent set
- pa app export
- pa app get
- pa app list
- pa app owner set
- pa app permission ensure
- pa app permission list
- pa app permission remove
- pa app remove
- pa connector export
- pa connector list

Closes pnp#7310

Co-authored-by: Copilot <[email protected]>
@MartinM85 MartinM85 self-assigned this Jun 19, 2026

@MartinM85 MartinM85 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.

I have a couple of small comments, nothing major. Great work @waldekmastykarz 🚀

Comment on lines 187 to 192
options: {
environmentName: environmentName,
name: name,
bypass: true,
force: true
}

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.

Missing commandOptionsSchema.parse.

Suggested change
options: commandOptionsSchema.parse({
environmentName: environmentName,
name: name,
bypass: true,
force: true
})

}
});

await assert.rejects(command.action(logger, { options: {} } as any),

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.

Suggested change
await assert.rejects(command.action(logger, { options: commandOptionsSchema.parse({}) }),

}
});

await assert.rejects(command.action(logger, { options: { environmentName: validEnvironmentName, appName: validAppName, userId: validUserId } } as any),

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.

Suggested change
await assert.rejects(command.action(logger, { options: commandOptionsSchema.parse({ environmentName: validEnvironmentName, appName: validAppName, userId: validUserId }) }),

}
});

await assert.rejects(command.action(logger, { options: { name: '3989cb59-ce1a-4a5c-bb78-257c5c39381d' } } as any),

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.

Suggested change
await assert.rejects(command.action(logger, { options: commandOptionsSchema.parse({ name: '3989cb59-ce1a-4a5c-bb78-257c5c39381d' }) }),

Comment on lines 737 to 741
options: {
verbose: true,
displayName: 'Playwright'
}
} as any), new CommandError('No apps found.'));

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.

Suggested change
options: commandOptionsSchema.parse({
verbose: true,
displayName: 'Playwright'
})
}), new CommandError('No apps found.'));

Comment on lines 721 to 725
options: {
verbose: true,
displayName: 'NoAppFound'
}
} as any), new CommandError(`No app found with displayName 'NoAppFound'.`));

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.

Suggested change
options: commandOptionsSchema.parse({
verbose: true,
displayName: 'NoAppFound'
})
}), new CommandError(`No app found with displayName 'NoAppFound'.`));

@MartinM85 MartinM85 marked this pull request as draft June 19, 2026 12:57
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 pa commands to Zod

2 participants