-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -228,6 +228,7 @@ public ContentSafetyClientBuilder credential(KeyCredential keyCredential) { | |||||||
@Generated | ||||||||
@Override | ||||||||
public ContentSafetyClientBuilder endpoint(String endpoint) { | ||||||||
Objects.requireNonNull(endpoint, "'endpoint' cannot be null."); | ||||||||
this.endpoint = endpoint; | ||||||||
return this; | ||||||||
} | ||||||||
|
@@ -283,8 +284,17 @@ private ContentSafetyClientImpl buildInnerClient() { | |||||||
return client; | ||||||||
} | ||||||||
|
||||||||
@Generated | ||||||||
private void validateBuilderParameters() { | ||||||||
Objects.requireNonNull(endpoint, "'endpoint' cannot be null."); | ||||||||
|
||||||||
// dev may customize and add more validation here | ||||||||
// in this module, maybe check either keyCredential or tokenCredential exists | ||||||||
} | ||||||||
|
||||||||
@Generated | ||||||||
private HttpPipeline createHttpPipeline() { | ||||||||
validateBuilderParameters(); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why here and not in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An alternative code flow would be user setting the Line 88 in 020a2a6
And Lines 278 to 279 in 020a2a6
( 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). |
||||||||
Configuration buildConfiguration | ||||||||
= (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; | ||||||||
HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions; | ||||||||
|
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.
The change on
endpoint
would apply to any required client properties.discussion
InvalidStateException
?createHttpPipeline
(so that the whole method is generated as empty and intended for customization)?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.
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.