-
Notifications
You must be signed in to change notification settings - Fork 79
Filtering out optional parameters when generating sample code #3619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| { | ||
| onClientOnly: true | ||
| onClientOnly: true, | ||
| requiredOnly: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not filter out the optional client params at the begining and we should handle optional client params during constructing the statement.
MaryGao
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not filter out the optional client params at the begining and we should handle optional client params during constructing the statement.
There was a problem hiding this comment.
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 fixes issue #3610 by preventing optional client-level parameters from appearing as standalone parameters in generated sample code. The fix ensures that when client parameters have default values (making them optional), they are not included in the client constructor call in samples.
Key changes:
- Added
requiredOnly: trueoption when retrieving client parameters for sample generation - Added a comprehensive unit test case demonstrating the expected behavior for optional parameters
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/typespec-ts/src/modular/emitSamples.ts | Added requiredOnly: true option to filter out optional client-level parameters when preparing example parameters for sample generation |
| packages/typespec-ts/test/modularUnit/scenarios/samples/parameters/optionalParameter.md | Added new test case validating that optional client parameters (like endpoint with default value) and optional operation parameters are handled correctly in generated samples |
fixes #3610