Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ export interface FeedbackCallSummaryContextSolution {
sid: string;
}

export class FeedbackCallSummaryContextImpl
implements FeedbackCallSummaryContext
{
export class FeedbackCallSummaryContextImpl implements FeedbackCallSummaryContext {
protected _solution: FeedbackCallSummaryContextSolution;
protected _uri: string;

Expand Down
28 changes: 25 additions & 3 deletions src/main/java/com/twilio/oai/TwilioCodegenAdapter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.twilio.oai;

import com.twilio.oai.java.cache.ResourceCache2;
import com.twilio.oai.java.cache.ResourceCacheContext;
import java.io.File;
import java.io.IOException;
import java.util.*;
Expand All @@ -18,7 +20,6 @@

import static com.twilio.oai.common.ApplicationConstants.CONFIG_PATH;

@RequiredArgsConstructor
public class TwilioCodegenAdapter {

private static final String INPUT_SPEC_PATTERN = "[^_]+_(?<domain>.+?)(_(?<version>[^_]+))?\\..+";
Expand All @@ -32,6 +33,14 @@ public class TwilioCodegenAdapter {
private File toggleFile;

private String originalOutputDir;
private final ResourceCache2 resourceCache2 = new ResourceCache2();

public TwilioCodegenAdapter(DefaultCodegen codegen, String name) {
this.codegen = codegen;
this.name = name;
ResourceCacheContext.clear();
ResourceCacheContext.set(resourceCache2);
}

public void processOpts() {
// Find the templates in the local resources dir.
Expand Down Expand Up @@ -65,7 +74,7 @@ public void processOpts() {
e.printStackTrace();
}
}

public String getVersionFromOpenAPI(final OpenAPI openAPI) {
String version = "";
version = StringHelper.camelize(getInputSpecVersion(), true);
Expand All @@ -83,14 +92,27 @@ public String getVersionFromOpenAPI(final OpenAPI openAPI) {
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.
String apiStdVersion = null;
if (openAPI.getInfo().getExtensions() != null && openAPI.getInfo().getExtensions().containsKey("x-twilio")) {
Object xTwilioObj = openAPI.getInfo().getExtensions().get("x-twilio");
if (xTwilioObj instanceof Map) {
Map<String, Object> xTwilio = (Map<String, Object>) xTwilioObj;
apiStdVersion = (String) xTwilio.get("apiStandards");
}
}
boolean isV1 = ApplicationConstants.isV1.test(apiStdVersion);
ResourceCacheContext.get().setV1(isV1);
}

public void setDomain(final String domain) {
final String domainPackage = domain.replaceAll("[-.]", "");
setOutputDir(domainPackage, getInputSpecVersion());

codegen.additionalProperties().put("domainName", StringHelper.camelize(domain));
codegen.additionalProperties().put("domainPackage", domainPackage);
}

public void setVersion(final String version) {
codegen.additionalProperties().put("clientVersion", version);
codegen.additionalProperties().put(DirectoryStructureService.API_VERSION, version);
Expand Down
15 changes: 1 addition & 14 deletions src/main/java/com/twilio/oai/TwilioPhpGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@


public class TwilioPhpGenerator extends PhpClientCodegen {

ResourceCache2 resourceCache2 = new ResourceCache2();
public static final String VALUES = "values";
public static final String JSON_INGRESS = "json_ingress";
private static final String PHP_CONVENTIONAL_MAP_PATH = "config/" + EnumConstants.Generator.TWILIO_PHP.getValue() + ".json";
Expand All @@ -55,8 +53,6 @@ protected ImmutableMap.Builder<String, Mustache.Lambda> addMustacheLambdas() {

public TwilioPhpGenerator() {
super();
ResourceCacheContext.clear();
ResourceCacheContext.set(resourceCache2); // initialize the resource cache context to avoid null pointer exceptions
twilioCodegen = new TwilioCodegenAdapter(this, getName());
}

Expand All @@ -81,22 +77,13 @@ public void processOpts() {
@Override
@SuppressWarnings("unchecked")
public void processOpenAPI(final OpenAPI openAPI) {
String apiStdVersion = null;
if (openAPI.getInfo().getExtensions() != null && openAPI.getInfo().getExtensions().containsKey("x-twilio")) {
Object xTwilioObj = openAPI.getInfo().getExtensions().get("x-twilio");
if (xTwilioObj instanceof Map) {
Map<String, Object> xTwilio = (Map<String, Object>) xTwilioObj;
apiStdVersion = (String) xTwilio.get("apiStandards");
}
}
boolean isV1 = ApplicationConstants.isV1.test(apiStdVersion);
ResourceCacheContext.get().setV1(isV1);

String domain = StringHelper.camelize(twilioCodegen.getDomainFromOpenAPI(openAPI));
String version = StringHelper.camelize(twilioCodegen.getVersionFromOpenAPI(openAPI));
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

setSrcBasePath("");

directoryStructureService.configureResourceFamily(openAPI);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/twilio/oai/TwilioPythonGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void processOpenAPI(final OpenAPI openAPI) {
String version = StringHelper.toSnakeCase(twilioCodegen.getVersionFromOpenAPI(openAPI));
twilioCodegen.setDomain(domain);
twilioCodegen.setVersion(version);
twilioCodegen.setIsV1ApiStandard(openAPI);
twilioCodegen.setOutputDir(domain, version);

openAPI.getPaths().forEach(resourceTree::addResource);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/twilio-python/api-single.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from twilio.base import deserialize, serialize, values
{{#responseModel}}from twilio.base.instance_resource import InstanceResource{{/responseModel}}
from twilio.base.list_resource import ListResource
from twilio.base.version import Version
{{#hasPaginationOperation}}from twilio.base.page import Page{{/hasPaginationOperation}}
{{#hasPaginationOperation}}{{#isApiV1}}from twilio.base.token_pagination import TokenPagination{{/isApiV1}}{{^isApiV1}}from twilio.base.page import Page{{/isApiV1}}{{/hasPaginationOperation}}
{{#dependents}}from twilio.rest.{{domainPackage}}.{{apiVersion}}.{{namespaceSubPart}}.{{filename}} import {{resourceName}}List
{{/dependents}}

Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/twilio-python/listOperations.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@
)]

def page(self, {{#allParams}}
{{#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}}
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
Expand Down Expand Up @@ -365,8 +365,9 @@
headers["Accept"] = "{{{mediaType}}}"
{{/vendorExtensions.successProduce}}

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

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.
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/twilio-python/pagination.handlebars
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{#operations}}
{{#vendorExtensions.x-is-read-operation}}
class {{apiName}}Page(Page):
class {{apiName}}Page({{#isApiV1}}TokenPagination{{/isApiV1}}{{^isApiV1}}Page{{/isApiV1}}):

def get_instance(self, payload: Dict[str, Any]) -> {{instanceName}}:
"""
Expand Down