Skip to content

Conversation

@kridai
Copy link
Contributor

@kridai kridai commented Dec 4, 2025

Fixes

PR for python twilio/twilio-python#896
As part of this PR

Added method setIsV1ApiStandard to TwilioCodegenAdapter, so that it is accessible across different generators
Added inheriting TokenPagination class when IsV1Api is true

Checklist

  • I acknowledge that all my contributions will be made under the project's license
  • Run make test-docker
  • Verify affected language according to the code change:
    • Generate twilio-java from our OpenAPI specification using the scripts/build_twilio_library.py using python scripts/build_twilio_library.py path/to/twilio-oai/spec/yaml path/to/twilio-java -l java and inspect the diff
    • Run make test in twilio-java
    • Create a pull request in twilio-java
    • Provide a link below to the pull request, this ensures that the generated code has been verified
  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the Contribution Guidelines and my PR follows them
  • I have titled the PR appropriately
  • I have updated my branch with the main branch
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation about the functionality in the appropriate .md file
  • I have added inline documentation to the code I modified

If you have questions, please create a GitHub Issue in this repository.

Copy link
Contributor

Copilot AI left a 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 adds token pagination support for the twilio-python SDK by introducing conditional logic to use TokenPagination base class for V1 API standard resources instead of the standard Page class. The changes centralize V1 API detection logic in TwilioCodegenAdapter and apply it across Python and PHP generators.

Key changes:

  • Refactored V1 API standard detection into a shared setIsV1ApiStandard method in TwilioCodegenAdapter
  • Updated Python templates to conditionally inherit from TokenPagination and pass uri parameter for V1 APIs
  • Modified Python templates to exclude page_token from method parameters when explicitly defined

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/main/resources/twilio-python/pagination.handlebars Conditionally inherits from TokenPagination for V1 APIs
src/main/resources/twilio-python/listOperations.handlebars Filters page_token parameter and adds uri parameter to V1 API page constructors
src/main/resources/twilio-python/api-single.mustache Conditionally imports TokenPagination instead of Page for V1 APIs
src/main/java/com/twilio/oai/TwilioPythonGenerator.java Calls setIsV1ApiStandard to detect V1 API standard
src/main/java/com/twilio/oai/TwilioPhpGenerator.java Refactored to use shared setIsV1ApiStandard method
src/main/java/com/twilio/oai/TwilioCodegenAdapter.java Added setIsV1ApiStandard method and explicit constructor, removed Lombok annotation
examples/node/src/rest/api/v2010/account/call/feedbackCallSummary.ts Formatting change to class declaration (unrelated to main feature)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return {{apiName}}Page(self._version, response{{#if listPathParams}}, self._solution{{/if}}){{/isApiV1}}

async def page_async(self, {{#allParams}}
{{#startsWith paramName text='page_size'}}{{else}}{{paramName}}: Union[{{{dataType}}}, object] = values.unset,{{/startsWith}}{{/allParams}}
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

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

The page_async method is missing the same page_token parameter filtering that was added to the page method at line 334. For consistency, this line should also exclude page_token from the parameter list:

{{#startsWith paramName text='page_size'}}{{else}}{{#startsWith paramName text='page_token'}}{{else}}{{paramName}}: Union[{{{dataType}}}, object] = values.unset,{{/startsWith}}{{/startsWith}}{{/allParams}}
Suggested change
{{#startsWith paramName text='page_size'}}{{else}}{{paramName}}: Union[{{{dataType}}}, object] = values.unset,{{/startsWith}}{{/allParams}}
{{#startsWith paramName text='page_size'}}{{else}}{{#startsWith paramName text='page_token'}}{{else}}{{paramName}}: Union[{{{dataType}}}, object] = values.unset,{{/startsWith}}{{/startsWith}}{{/allParams}}

Copilot uses AI. Check for mistakes.
return version;
}

public void setIsV1ApiStandard (final OpenAPI openAPI) {
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

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

There's an extra space before the opening parenthesis in the method name. It should be setIsV1ApiStandard(final OpenAPI openAPI) instead of setIsV1ApiStandard (final OpenAPI openAPI).

Suggested change
public void setIsV1ApiStandard (final OpenAPI openAPI) {
public void setIsV1ApiStandard(final OpenAPI openAPI) {

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@tiwarishubham635 tiwarishubham635 left a comment

Choose a reason for hiding this comment

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

LGTM! Added a few comments for discussion

twilioCodegen.setDomain(domain);
twilioCodegen.setVersion(version);
twilioCodegen.setOutputDir(domain, version);
twilioCodegen.setIsV1ApiStandard(openAPI);
Copy link
Contributor

Choose a reason for hiding this comment

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

This design looks much better to keep the resource cache code in adapter. Have you checked if this is present in all languages except java?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, we can support this in all generators

response = self._version.page(method='{{vendorExtensions.x-http-method}}', uri=self._uri, params=data, headers=headers)
return {{apiName}}Page(self._version, response{{#if listPathParams}}, self._solution{{/if}})
response = self._version.page(method='{{vendorExtensions.x-http-method}}', uri=self._uri, params=data, headers=headers){{#isApiV1}}
return {{apiName}}Page(self._version, response, uri=self._uri{{#if listPathParams}}, self._solution{{/if}}){{/isApiV1}}{{^isApiV1}}
Copy link
Contributor

Choose a reason for hiding this comment

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

i think the only difference is that we are passing the url as well when it's token pagination right?

Copy link
Contributor Author

@kridai kridai Dec 8, 2025

Choose a reason for hiding this comment

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

yes

@kridai kridai merged commit b39f18a into twilio_api_standards_changes Dec 8, 2025
16 checks passed
@kridai kridai deleted the pyhon-pagination-support branch December 8, 2025 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants