Skip to content
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: correctly adding contentType in java #588

Merged
merged 3 commits into from
Jun 27, 2024
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 @@ -68,6 +68,7 @@ public boolean delete(final TwilioRestClient client) {
Domains.API.toString(),
path
);
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
Response response = client.request(request);

if (response == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public Account fetch(final TwilioRestClient client) {
Domains.API.toString(),
path
);
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
Response response = client.request(request);

if (response == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public Page<Account> firstPage(final TwilioRestClient client) {
);

addQueryParams(request);
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
return pageForRequest(client, request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public boolean delete(final TwilioRestClient client) {
Domains.API.toString(),
path
);
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
Response response = client.request(request);

if (response == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public Call fetch(final TwilioRestClient client) {
Domains.API.toString(),
path
);
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
Response response = client.request(request);

if (response == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public Call update(final TwilioRestClient client){
Domains.FLEXAPI.toString(),
path
);
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
Response response = client.request(request);
if (response == null) {
throw new ApiConnectionException("Call update failed: Unable to connect to server");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public boolean delete(final TwilioRestClient client) {
Domains.FLEXAPI.toString(),
path
);
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
Response response = client.request(request);

if (response == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public Aws fetch(final TwilioRestClient client) {
Domains.FLEXAPI.toString(),
path
);
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
Response response = client.request(request);

if (response == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public Page<Aws> firstPage(final TwilioRestClient client) {
);

addQueryParams(request);
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
return pageForRequest(client, request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public History fetch(final TwilioRestClient client) {
path
);
addQueryParams(request);
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
Response response = client.request(request);

if (response == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public Fleet fetch(final TwilioRestClient client) {
Domains.VERSIONLESS.toString(),
path
);
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
Response response = client.request(request);

if (response == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public Page<Assistant> firstPage(final TwilioRestClient client) {
);

addQueryParams(request);
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
return pageForRequest(client, request);
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/twilio-java/creator.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,16 @@ public class {{apiName}}Creator extends Creator<{{apiName}}>{
{{#queryParams.0}}
addQueryParams(request);
{{/queryParams.0}}
{{#formParams.0}}
{{^vendorExtensions.x-is-json}}
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
{{/vendorExtensions.x-is-json}}
{{#vendorExtensions.x-is-json}}
request.setContentType(EnumConstants.ContentType.JSON);
{{/vendorExtensions.x-is-json}}
{{#formParams.0}}
addPostParams(request);
{{/formParams.0}}
{{#bodyParams.0}}
request.setContentType(EnumConstants.ContentType.JSON);
addPostParams(request, client);
{{/bodyParams.0}}
{{#headerParams.0}}
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/twilio-java/deleter.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ public class {{apiName}}Deleter extends Deleter<{{apiName}}> {
{{#queryParams.0}}
addQueryParams(request);
{{/queryParams.0}}
{{#formParams.0}}
{{^vendorExtensions.x-is-json}}
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
{{/vendorExtensions.x-is-json}}
{{#vendorExtensions.x-is-json}}
request.setContentType(EnumConstants.ContentType.JSON);
{{/vendorExtensions.x-is-json}}
{{#formParams.0}}
addPostParams(request);
{{/formParams.0}}
{{#bodyParams.0}}
request.setContentType(EnumConstants.ContentType.JSON);
addPostParams(request, client);
{{/bodyParams.0}}
{{#headerParams.0}}
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/twilio-java/fetcher.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,16 @@ public class {{apiName}}Fetcher extends Fetcher<{{apiName}}> {
{{#queryParams.0}}
addQueryParams(request);
{{/queryParams.0}}
{{#formParams.0}}
{{^vendorExtensions.x-is-json}}
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
{{/vendorExtensions.x-is-json}}
{{#vendorExtensions.x-is-json}}
request.setContentType(EnumConstants.ContentType.JSON);
{{/vendorExtensions.x-is-json}}
{{#formParams.0}}
addPostParams(request);
{{/formParams.0}}
{{#bodyParams.0}}
request.setContentType(EnumConstants.ContentType.JSON);
addPostParams(request, client);
{{/bodyParams.0}}
{{#headerParams.0}}
Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/twilio-java/reader.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,18 @@ public class {{apiName}}Reader extends Reader<{{apiName}}> {
{{#queryParams.0}}
addQueryParams(request);
{{/queryParams.0}}
{{#formParams.0}}
{{^vendorExtensions.x-is-json}}
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
{{/vendorExtensions.x-is-json}}
{{#vendorExtensions.x-is-json}}
request.setContentType(EnumConstants.ContentType.JSON);
{{/vendorExtensions.x-is-json}}
{{#formParams.0}}
addPostParams(request);
{{/formParams.0}}
{{#bodyParams.0}}
addPostParams(request, client);
{{/bodyParams.0}}
{{#headerParams.0}}
addHeaderParams(request);
{{/headerParams.0}}
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/twilio-java/updater.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,16 @@ public class {{apiName}}Updater extends Updater<{{apiName}}>{
{{#queryParams.0}}
addQueryParams(request);
{{/queryParams.0}}
{{#formParams.0}}
{{^vendorExtensions.x-is-json}}
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
{{/vendorExtensions.x-is-json}}
{{#vendorExtensions.x-is-json}}
request.setContentType(EnumConstants.ContentType.JSON);
{{/vendorExtensions.x-is-json}}
{{#formParams.0}}
addPostParams(request);
{{/formParams.0}}
{{#bodyParams.0}}
request.setContentType(EnumConstants.ContentType.JSON);
addPostParams(request, client);
{{/bodyParams.0}}
{{#headerParams.0}}
Expand Down
17 changes: 4 additions & 13 deletions src/test/java/com/twilio/oai/TwilioGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@
public class TwilioGeneratorTest {
@Parameterized.Parameters
public static Collection<Generator> generators() {
return Arrays.asList(Generator.TWILIO_CSHARP,
Generator.TWILIO_GO,
Generator.TWILIO_JAVA,
Generator.TWILIO_NODE,
Generator.TWILIO_PHP,
Generator.TWILIO_PYTHON,
Generator.TWILIO_RUBY,
Generator.TWILIO_TERRAFORM);
return Arrays.asList(Generator.TWILIO_PYTHON);
}

private final Generator generator;
Expand All @@ -48,7 +41,9 @@ public static void setUp() {
@Test
public void launchGenerator() {
final String pathname = "examples/spec/twilio_api_v2010.yaml";
// final String pathname = "examples/twilio_messaging_bulk_v1.yaml";
// final String pathname = "/Users/stiwari/di/github/twilio-oai/spec/json/twilio_accounts_v1.json";
// final String pathname = "/Users/stiwari/di/codehq/open-api-transpiler/twilio_api_v2010.json";
// final String pathname = "/Users/stiwari/di/codehq/open-api-transpiler/json/twilio_assistants_v1.json";
File filesList[] ;
File directoryPath = new File(pathname);
if (directoryPath.isDirectory()) {
Expand All @@ -69,9 +64,5 @@ public void launchGenerator() {
final List<File> output = generator.opts(clientOptInput).generate();
assertFalse(output.isEmpty());
}




}
}
Loading