Skip to content

Commit

Permalink
chore: skipping isOverridden flag in distinctResponseModels (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiwarishubham635 authored and AsabuHere committed Sep 20, 2024
1 parent 47d99b5 commit 8ab4805
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/go/Dockerfile-goimports
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM golang:1.18

ENV GOPATH /go
RUN go install golang.org/x/tools/cmd/goimports@latest
RUN go install golang.org/x/tools/cmd/goimports@v0.24.0

CMD goimports -w /local
9 changes: 7 additions & 2 deletions src/main/java/com/twilio/oai/api/ApiResourceBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public ApiResourceBuilder updateOperations(Resolver<CodegenParameter> codegenPar
}

public void updateHttpMethod(CodegenOperation co) {

}

protected void resolveParam(final Resolver<CodegenParameter> codegenParameterIResolver,
Expand Down Expand Up @@ -191,7 +191,7 @@ public CodegenModel getModel(String modelName ) {
}
return null;
}

public void addNestedModel(final CodegenModel codegenModel) {
// TODO: Temporary fix, planning to use hashmap, set is inserting duplicate values.
Iterator<CodegenModel> iterator = nestedModels.iterator();
Expand Down Expand Up @@ -290,12 +290,17 @@ protected Set<CodegenProperty> getDistinctResponseModel(List<CodegenModel> respo
for (CodegenModel codegenModel : responseModels) {
for (CodegenProperty property : codegenModel.vars) {
property.nameInCamelCase = StringHelper.camelize(property.nameInSnakeCase);
// When we have responseModel referencing a schema, isOverriden flag is set to false (which is null by default). This makes the property different. See assistants api ListAssistantResponse
Boolean isOverridden = property.isOverridden;
if(isOverridden != null && isOverridden == false)
property.isOverridden = null;
if (Arrays
.stream(Operation.values())
.anyMatch(value -> value.getValue().equals(property.nameInCamelCase))) {
property.nameInCamelCase = "_" + property.nameInCamelCase;
}
distinctResponseModels.add(property);
property.isOverridden = isOverridden;
}
}
return distinctResponseModels;
Expand Down
26 changes: 17 additions & 9 deletions src/main/java/com/twilio/oai/api/CsharpApiResourceBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,19 @@ public void updateHttpMethod(CodegenOperation co) {
}
}

private void setDataType(CodegenParameter codegenParameter) {
for (CodegenModel codegenModel : getAllModels())
if (codegenModel.classname.equals(codegenParameter.dataType))
codegenParameter.dataType = getApiName() + "Resource" + ApplicationConstants.DOT + codegenParameter.dataType;
}

private void resolveIngressModel(CodegenOperation codegenOperation) {
// Required params are used in parameters in C#, Check Params.mustache.
for (CodegenParameter codegenParameter: codegenOperation.requiredParams) {
for (CodegenModel codegenModel : getAllModels()) {
if (codegenModel.classname.equals(codegenParameter.paramName)) {
codegenParameter.dataType = getApiName() + "Resource" + ApplicationConstants.DOT + codegenParameter.dataType;
}
}

for (CodegenParameter codegenParameter: codegenOperation.requiredParams)
setDataType(codegenParameter);

for (CodegenParameter codegenParameter: codegenOperation.optionalParams) {
setDataType(codegenParameter);
}
}

Expand Down Expand Up @@ -191,12 +195,16 @@ public Set<CodegenProperty> getDistinctResponseModel(List<CodegenModel> response
for (CodegenModel codegenModel: responseModels) {
for (CodegenProperty property: codegenModel.vars) {
property.nameInCamelCase = StringHelper.camelize(property.nameInSnakeCase);
Boolean isOverridden = property.isOverridden;
if(isOverridden != null && isOverridden == false)
property.isOverridden = null;
if (Arrays.stream(EnumConstants.Operation.values())
.anyMatch(value -> value.getValue().equals(property.nameInCamelCase))
.anyMatch(value -> value.getValue().equals(property.nameInCamelCase))
|| isNestedModelPresentWithPropertyName(property)) {
property.nameInCamelCase = "_" + property.nameInCamelCase;
}
distinctResponseModels.add(property);
property.isOverridden = isOverridden;
}
}
return distinctResponseModels;
Expand Down Expand Up @@ -298,7 +306,7 @@ private void rearrangeBeforeAfter(final List<CodegenParameter> parameters) {
}

public boolean isNestedModelPresentWithPropertyName(final CodegenProperty property) {
if (nestedModels == null || nestedModels.size() < 1) return false;
if (nestedModels == null || nestedModels.size() < 1) return false;
Optional<CodegenModel> foundModel = nestedModels.stream()
.filter(model -> model.classname.equals(property.name))
.findFirst();
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,15 @@ private CodegenModel getConcatenatedResponseModel(List<CodegenModel> responseMod
resModel.vendorExtensions.forEach(
(key, value) -> codegenModel.vendorExtensions.merge(key, value, (oldValue, newValue) -> newValue));
}

resModel.vars.stream().filter(Predicate.not(codegenProperties::contains)).forEach(codegenProperties::add);
resModel.vars.forEach(var -> {
Boolean isOverridden = var.isOverridden;
if(isOverridden != null && isOverridden == false)
var.isOverridden = null;
if(!codegenProperties.contains(var))
codegenProperties.add(var);
var.isOverridden = isOverridden;
});
// resModel.vars.stream().filter(Predicate.not(codegenProperties::contains)).forEach(codegenProperties::add);
}

codegenProperties.forEach(prop -> prop.baseName = StringHelper.camelize(prop.baseName, true));
Expand Down

0 comments on commit 8ab4805

Please sign in to comment.