Skip to content

Commit

Permalink
chore: setting contentType correctly in java (#608)
Browse files Browse the repository at this point in the history
fixed contentType for twilio-java
  • Loading branch information
tiwarishubham635 authored Sep 5, 2024
1 parent 88ab8cb commit e2245e0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public User create(final BearerTokenTwilioRestClient client){
Domains.PREVIEWIAM.toString(),
path
);
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
request.setContentType(EnumConstants.ContentType.JSON);
addPostParams(request, client);
Response response = client.request(request);
if (response == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public User update(final BearerTokenTwilioRestClient client){
Domains.PREVIEWIAM.toString(),
path
);
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
request.setContentType(EnumConstants.ContentType.JSON);
addPostParams(request, client);
addHeaderParams(request);
Response response = client.request(request);
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,24 @@ public IApiResourceBuilder updateTemplate() {
return this;
}

private void populateContentType(CodegenOperation co) {
if(co.consumes != null && !co.consumes.isEmpty())
co.consumes.forEach(consume -> {
if(consume.getOrDefault("mediaType", "").equals(CONTENT_TYPE_JSON))
co.vendorExtensions.put("x-is-json", true);
});
}

@Override
public ApiResourceBuilder updateOperations(Resolver<CodegenParameter> codegenParameterIResolver) {
headerParamModelList = new HashSet<>();
JsonRequestBodyResolver jsonRequestBodyResolver = new JsonRequestBodyResolver(this, codegenPropertyIResolver);
this.codegenOperationList.forEach(co -> {
updateNestedContent(co);
populateContentType(co);
updateHttpMethod(co);
List<String> filePathArray = new ArrayList<>(Arrays.asList(co.baseName.split(PATH_SEPARATOR_PLACEHOLDER)));
String resourceName = filePathArray.remove(filePathArray.size()-1);


co.allParams.stream()
.filter(item -> !(item.getContent() != null && item.getContent().get("application/json") != null))
Expand Down Expand Up @@ -631,7 +639,7 @@ public void addEnums(IJsonSchemaValidationProperties item) {
} else {
enumName = ((CodegenProperty) enumItem).enumName;
}

if (enumName.equals(newItemEnumName)) {
isDuplicate = true;
break; // No need to continue checking duplicates
Expand Down

0 comments on commit e2245e0

Please sign in to comment.