-
Notifications
You must be signed in to change notification settings - Fork 702
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
feat: Add ApiVersion Support #2462
Conversation
@@ -62,7 +63,8 @@ public abstract class AbstractGoogleClientRequest<T> extends GenericData { | |||
*/ | |||
public static final String USER_AGENT_SUFFIX = "Google-API-Java-Client"; | |||
|
|||
private static final String API_VERSION_HEADER = "X-Goog-Api-Client"; | |||
private static final String API_CLIENT_HEADER = "X-Goog-Api-Client"; | |||
protected static final String API_VERSION_HEADER = "X-Google-Api-Version"; |
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.
protected access as this will be used in the generated client classes.
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.
Can you add that (the generated code uses this field to set the header) in the source code comment?
Also if there's any public document available for API versions in https://google.aip.dev, reference it from here.
/** | ||
* @param client Google client | ||
* @param method HTTP Method | ||
* @param uriTemplate URI template for the path relative to the base URL. If it starts with a "/" | ||
* the base path from the base URL will be stripped out. The URI template can also be a full | ||
* URL. URI template expansion is done using {@link UriTemplate#expand(String, String, Object, | ||
* boolean)} | ||
* @param content HTTP content or {@code null} for none | ||
* @param responseClass response class to parse into | ||
* @param apiVersion ApiVersion to be passed to the header | ||
*/ | ||
public MockGoogleClientRequest( | ||
AbstractGoogleClient client, | ||
String method, | ||
String uriTemplate, | ||
HttpContent content, | ||
Class<T> responseClass, | ||
String apiVersion) { | ||
super(client, method, uriTemplate, content, responseClass); | ||
// Matches generator code: Null or Empty String is not set to the header | ||
if (!Strings.isNullOrEmpty(apiVersion)) { | ||
getRequestHeaders().set(API_VERSION_HEADER, apiVersion); | ||
} |
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.
Add a constructor with new ApiVersion param. This allows us to mimic the behavior where the generated clients pass the apiVersion to the AbstractGoogleClientRequest class.
@@ -62,7 +63,8 @@ public abstract class AbstractGoogleClientRequest<T> extends GenericData { | |||
*/ | |||
public static final String USER_AGENT_SUFFIX = "Google-API-Java-Client"; | |||
|
|||
private static final String API_VERSION_HEADER = "X-Goog-Api-Client"; | |||
private static final String API_CLIENT_HEADER = "X-Goog-Api-Client"; | |||
protected static final String API_VERSION_HEADER = "X-Google-Api-Version"; |
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.
Can you add that (the generated code uses this field to set the header) in the source code comment?
Also if there's any public document available for API versions in https://google.aip.dev, reference it from here.
Will do, thanks! |
Changes:
X-Google-Api-Version
as a header as part of requests if apiVersion exists in the Discovery DocCorresponding generator change googleapis/google-api-java-client-services#20930
This PR will go in first then merge in the generator change once this is released and in maven central.
Logs: