Skip to content

Commit

Permalink
Accept header fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AsabuHere committed Dec 12, 2024
1 parent fbc18e7 commit 1f07156
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 31 deletions.
2 changes: 1 addition & 1 deletion scripts/build_twilio_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'php': 'Rest'
}
generateForLanguages = {
'twilio_iam_organizations.json' : ['java', 'csharp']
'twilio_iam_organizations.json' : ['java', 'csharp', 'python']
}
dynamic_languages = ['node', 'python', 'ruby']
CLEANUP_IMPORT_LANGUAGES = ['java', 'php']
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/twilio/oai/DirectoryStructureService.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,19 @@ public List<CodegenOperation> processOperations(final OperationsMap results) {
final CodegenOperation firstOperation = operations.stream().findFirst().orElseThrow();
final String version = PathUtils.getFirstPathPart(firstOperation.path);

for(CodegenOperation co : operations){
for(Map<String, String> map : co.produces){
Map.Entry<String, String> firstEntry = map.entrySet().iterator().next();
List<Map<String, String>> successProduce = new ArrayList<>();
Map<String, String> successMap = new HashMap<>();
successMap.put(firstEntry.getKey(), firstEntry.getValue());
successProduce.add(successMap);
co.vendorExtensions.put("successProduce", successProduce);
break;

}
}

additionalProperties.put("version", version);
additionalProperties.put("apiVersionPath", getRelativeRoot(firstOperation.baseName));
additionalProperties.put("apiFilename",
Expand Down
24 changes: 12 additions & 12 deletions src/main/resources/twilio-python/context.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class {{apiName}}Context(InstanceContext):
{{#consumes}}
headers["Content-Type"] = "{{{mediaType}}}"
{{/consumes}}
{{#produces}}
{{#vendorExtensions.successProduce}}
headers["Accept"] = "{{{mediaType}}}"
{{/produces}}
{{/vendorExtensions.successProduce}}

payload = self._version.update(method='{{vendorExtensions.x-http-method}}', uri=self._uri, data=data, headers=headers)

Expand Down Expand Up @@ -72,9 +72,9 @@ class {{apiName}}Context(InstanceContext):
{{#consumes}}
headers["Content-Type"] = "{{{mediaType}}}"
{{/consumes}}
{{#produces}}
{{#vendorExtensions.successProduce}}
headers["Accept"] = "{{{mediaType}}}"
{{/produces}}
{{/vendorExtensions.successProduce}}

payload = await self._version.update_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri, data=data, headers=headers)

Expand Down Expand Up @@ -104,9 +104,9 @@ class {{apiName}}Context(InstanceContext):
{{#consumes}}
headers["Content-Type"] = "{{{mediaType}}}"
{{/consumes}}
{{#produces}}
{{#vendorExtensions.successProduce}}
headers["Accept"] = "{{{mediaType}}}"
{{/produces}}
{{/vendorExtensions.successProduce}}
payload = self._version.fetch(method='{{vendorExtensions.x-http-method}}', uri=self._uri {{#if allParams}}, params=data{{/if}} , headers=headers)

return {{instanceName}}(
Expand Down Expand Up @@ -136,9 +136,9 @@ class {{apiName}}Context(InstanceContext):
{{#consumes}}
headers["Content-Type"] = "{{{mediaType}}}"
{{/consumes}}
{{#produces}}
{{#vendorExtensions.successProduce}}
headers["Accept"] = "{{{mediaType}}}"
{{/produces}}
{{/vendorExtensions.successProduce}}
payload = await self._version.fetch_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri {{#if allParams}}, params=data{{/if}}, headers=headers)

return {{instanceName}}(
Expand All @@ -165,9 +165,9 @@ class {{apiName}}Context(InstanceContext):
{{#consumes}}
headers["Content-Type"] = "{{{mediaType}}}"
{{/consumes}}
{{#produces}}
{{#vendorExtensions.successProduce}}
headers["Accept"] = "{{{mediaType}}}"
{{/produces}}
{{/vendorExtensions.successProduce}}
return self._version.delete(method='{{vendorExtensions.x-http-method}}', uri=self._uri, headers=headers)

async def {{vendorExtensions.x-name-lower}}_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> bool:
Expand All @@ -186,9 +186,9 @@ class {{apiName}}Context(InstanceContext):
{{#consumes}}
headers["Content-Type"] = "{{{mediaType}}}"
{{/consumes}}
{{#produces}}
{{#vendorExtensions.successProduce}}
headers["Accept"] = "{{{mediaType}}}"
{{/produces}}
{{/vendorExtensions.successProduce}}
return await self._version.delete_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri, headers=headers)
{{/vendorExtensions.x-twilio.ignoreOperation}}{{/vendorExtensions.x-is-delete-operation}}{{#vendorExtensions.x-is-create-operation}}{{^vendorExtensions.x-twilio.ignoreOperation}}
def {{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> {{instanceName}}:
Expand Down
36 changes: 18 additions & 18 deletions src/main/resources/twilio-python/listOperations.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
{{#consumes}}
headers["Content-Type"] = "{{{mediaType}}}"
{{/consumes}}
{{#produces}}
{{#vendorExtensions.successProduce}}
headers["Accept"] = "{{{mediaType}}}"
{{/produces}}
{{/vendorExtensions.successProduce}}
{{#queryParams.0}}params = values.of({
{{#queryParams}}'{{{baseName}}}': {{paramName}},
{{/queryParams}}
Expand Down Expand Up @@ -50,9 +50,9 @@
{{#consumes}}
headers["Content-Type"] = "{{{mediaType}}}"
{{/consumes}}
{{#produces}}
{{#vendorExtensions.successProduce}}
headers["Accept"] = "{{{mediaType}}}"
{{/produces}}
{{/vendorExtensions.successProduce}}
{{#queryParams.0}}params = values.of({
{{#queryParams}}'{{{baseName}}}': {{paramName}},
{{/queryParams}}
Expand All @@ -76,9 +76,9 @@
{{#consumes}}
headers["Content-Type"] = "{{{mediaType}}}"
{{/consumes}}
{{#produces}}
{{#vendorExtensions.successProduce}}
headers["Accept"] = "{{{mediaType}}}"
{{/produces}}
{{/vendorExtensions.successProduce}}
{{#queryParams.0}}params = values.of({
{{#queryParams}}'{{{baseName}}}': {{paramName}},
{{/queryParams}}
Expand All @@ -102,9 +102,9 @@
{{#consumes}}
headers["Content-Type"] = "{{{mediaType}}}"
{{/consumes}}
{{#produces}}
{{#vendorExtensions.successProduce}}
headers["Accept"] = "{{{mediaType}}}"
{{/produces}}
{{/vendorExtensions.successProduce}}
{{#queryParams.0}}params = values.of({
{{#queryParams}}'{{{baseName}}}': {{paramName}},
{{/queryParams}}
Expand All @@ -127,9 +127,9 @@
{{#consumes}}
headers["Content-Type"] = "{{{mediaType}}}"
{{/consumes}}
{{#produces}}
{{#vendorExtensions.successProduce}}
headers["Accept"] = "{{{mediaType}}}"
{{/produces}}
{{/vendorExtensions.successProduce}}
{{#queryParams.0}}params = values.of({
{{#queryParams}}'{{{baseName}}}': {{paramName}},
{{/queryParams}}
Expand All @@ -150,9 +150,9 @@
{{#consumes}}
headers["Content-Type"] = "{{{mediaType}}}"
{{/consumes}}
{{#produces}}
{{#vendorExtensions.successProduce}}
headers["Accept"] = "{{{mediaType}}}"
{{/produces}}
{{/vendorExtensions.successProduce}}
{{#queryParams.0}}params = values.of({
{{#queryParams}}'{{{baseName}}}': {{paramName}},
{{/queryParams}}
Expand All @@ -178,9 +178,9 @@
{{#consumes}}
headers["Content-Type"] = "{{{mediaType}}}"
{{/consumes}}
{{#produces}}
{{#vendorExtensions.successProduce}}
headers["Accept"] = "{{{mediaType}}}"
{{/produces}}
{{/vendorExtensions.successProduce}}
{{#queryParams.0}}params = values.of({
{{#queryParams}}'{{{baseName}}}': {{paramName}},
{{/queryParams}}
Expand Down Expand Up @@ -209,9 +209,9 @@
{{#consumes}}
headers["Content-Type"] = "{{{mediaType}}}"
{{/consumes}}
{{#produces}}
{{#vendorExtensions.successProduce}}
headers["Accept"] = "{{{mediaType}}}"
{{/produces}}
{{/vendorExtensions.successProduce}}
{{#queryParams.0}}params = values.of({
{{#queryParams}}'{{{baseName}}}': {{paramName}},
{{/queryParams}}
Expand Down Expand Up @@ -361,9 +361,9 @@
{{#consumes}}
headers["Content-Type"] = "{{{mediaType}}}"
{{/consumes}}
{{#produces}}
{{#vendorExtensions.successProduce}}
headers["Accept"] = "{{{mediaType}}}"
{{/produces}}
{{/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}})
Expand Down

0 comments on commit 1f07156

Please sign in to comment.