-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Fix generation for methods with abnormal page token conventions #330
Fix generation for methods with abnormal page token conventions #330
Conversation
Note this fix should be submitted in concert with googleapis/gapic-generator#880. |
googleapiclient/discovery.py
Outdated
"""Creates any _next methods for attaching to a Resource. | ||
|
||
The _next methods allow for easy iteration through list() responses. | ||
|
||
Args: | ||
methodName: string, name of the method to use. | ||
pageToken: string, name of request page token field. | ||
nextPageToken: string, name of response page token field. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
googleapiclient/discovery.py
Outdated
|
||
if isPageTokenParameter: | ||
# Replace pageToken value in URI | ||
parsed = list(urlparse(request.uri)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
googleapiclient/discovery.py
Outdated
# Add _next() methods | ||
# Look for response bodies in schema that contain nextPageToken, and methods | ||
# that take a pageToken parameter. | ||
# Add _next() methods iff one of the names 'pageToken' or 'nextPageToken' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
googleapiclient/discovery.py
Outdated
hasPageToken = 'pageToken' in methodDesc.get('parameters', {}) | ||
if hasNextPageToken and hasPageToken: | ||
fixedMethodName, method = createNextMethod(methodName + '_next') | ||
nextPageToken = pageTokenName( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
googleapiclient/discovery.py
Outdated
self._set_dynamic_attr(fixedMethodName, | ||
method.__get__(self, self.__class__)) | ||
|
||
|
||
pageTokenNames = ('pageToken', 'nextPageToken') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
googleapiclient/discovery.py
Outdated
|
||
pageTokenNames = ('pageToken', 'nextPageToken') | ||
|
||
def pageTokenName(fields): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
googleapiclient/discovery.py
Outdated
method.__get__(self, self.__class__)) | ||
|
||
|
||
def findPageTokenName(fields): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
googleapiclient/discovery.py
Outdated
return next((tokenName for tokenName in _PAGE_TOKEN_NAMES | ||
if tokenName in fields), None) | ||
|
||
def methodProperties(methodDesc, schema, name): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
googleapiclient/model.py
Outdated
@@ -348,7 +348,7 @@ def no_content_response(self): | |||
def makepatch(original, modified): | |||
"""Create a patch object. | |||
|
|||
Some methods support PATCH, an efficient way to send updates to a resource. | |||
Some methods support PATCH, an efficient way to send updates to a presource. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -161,13 +161,13 @@ def prettyPrintSchema(self, schema): | |||
# Return with trailing comma and newline removed. | |||
return self._prettyPrintSchema(schema, dent=1)[:-2] | |||
|
|||
def get(self, name): | |||
def get(self, name, default=None): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@lukesneeringer @landrito I'd love to have one of you take a look. Large changes like this on this ancient codebase make me uneasy. |
raise TypeError('Missing required parameter "%s"' % name) | ||
# temporary workaround for non-paging methods incorrectly requiring | ||
# page token parameter (cf. drive.changes.watch vs. drive.changes.list) | ||
if name not in _PAGE_TOKEN_NAMES or _findPageTokenName( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
googleapiclient/discovery.py
Outdated
@@ -945,24 +957,26 @@ def methodNext(self, previous_request, previous_response): | |||
# Retrieve nextPageToken from previous_response | |||
# Use as pageToken in previous_request to create new request. | |||
|
|||
if 'nextPageToken' not in previous_response or not previous_response['nextPageToken']: | |||
if (nextPageTokenName not in previous_response or | |||
not previous_response[nextPageTokenName]): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
First name that is either 'pageToken' or 'nextPageToken' if one exists, | ||
otherwise None. | ||
""" | ||
return next((tokenName for tokenName in _PAGE_TOKEN_NAMES |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ping |
Any further comments on this? |
No further comments. Thanks! |
@jonparrott @lukesneeringer can you please approve changes to enable submission? Thanks! |
Addresses googleapis/gapic-generator#692.