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

chore: setting contentType correctly in java #608

Merged
merged 7 commits into from
Sep 5, 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 @@ -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
Loading