Skip to content

Commit

Permalink
fix: correctly adding contentType in java (#588)
Browse files Browse the repository at this point in the history
<!--
We appreciate the effort for this pull request but before that please
make sure you read the contribution guidelines, then fill out the blanks
below.

Please format the PR title appropriately based on the type of change:
  <type>[!]: <description>
Where <type> is one of: docs, chore, feat, fix, test, misc.
Add a '!' after the type for breaking changes (e.g. feat!: new breaking
feature).

**All third-party contributors acknowledge that any contributions they
provide will be made under the same open-source license that the
open-source project is provided under.**

Please enter each Issue number you are resolving in your PR after one of
the following words [Fixes, Closes, Resolves]. This will auto-link these
issues and close them when this PR is merged!
e.g.
Fixes #1
Closes #2
-->

# Fixes #

Earlier contentType was set in java only when formParam or bodyParam was
present in the operation. However, the check should be about json-type
body or else. Corrected the mustache file.

### Checklist
- [x] I acknowledge that all my contributions will be made under the
project's license
- [ ] Run `make test-docker`
- [ ] Verify affected language:
- [ ] Generate [twilio-go](https://github.com/twilio/twilio-go) from our
[OpenAPI specification](https://github.com/twilio/twilio-oai) using the
[build_twilio_go.py](./examples/build_twilio_go.py) using `python
examples/build_twilio_go.py path/to/twilio-oai/spec/yaml
path/to/twilio-go` and inspect the diff
    - [ ] Run `make test` in `twilio-go`
    - [ ] Create a pull request in `twilio-go`
    - [ ] Provide a link below to the pull request
- [ ] I have made a material change to the repo (functionality, testing,
spelling, grammar)
- [ ] I have read the [Contribution
Guidelines](https://github.com/twilio/twilio-oai-generator/blob/main/CONTRIBUTING.md)
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.
  • Loading branch information
tiwarishubham635 authored Jun 27, 2024
1 parent 4fca828 commit aebb808
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 22 deletions.
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());
}




}
}

0 comments on commit aebb808

Please sign in to comment.