Skip to content
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

design, validate parameters in Builder #39889

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

weidongxu-microsoft
Copy link
Member

Description

Please add an informative description that covers that changes made by the pull request and link all relevant issues.

If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

@@ -283,8 +284,17 @@ private ContentSafetyClientImpl buildInnerClient() {
return client;
}

@Generated
private void validateBuilderParameters() {
Objects.requireNonNull(endpoint, "'endpoint' cannot be null.");
Copy link
Member Author

Choose a reason for hiding this comment

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

The change on endpoint would apply to any required client properties.

discussion

  1. Should we use a different exception, e.g. InvalidStateException?
  2. Do we put these "default validation" here, or in createHttpPipeline (so that the whole method is generated as empty and intended for customization)?

Copy link
Contributor

Choose a reason for hiding this comment

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

InvalidStateException seems most correct to me.

I think I'm in favor of leaving all of the validation in this method. Perhaps we generate a comment that these are the default requirements and others can be added? "Magic" other validation seems hard to understand.

@azure-sdk
Copy link
Collaborator

API change check

API changes are not detected in this pull request.

@Generated
private HttpPipeline createHttpPipeline() {
validateBuilderParameters();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why here and not in buildInnerClient? It doesn't matter much in this example; are there others where it might matter more?

Copy link
Member Author

Choose a reason for hiding this comment

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

An alternative code flow would be user setting the pipeline via

And builderInnerClient has this

private ContentSafetyClientImpl buildInnerClient() {
HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline();

(createHttpPipeline won't be called, if user provides the pipeline)

I think in that code flow, there is no need to verify anything (as user provides a pipeline and we cannot inspect it anyway).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants