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: skipping isOverridden flag in distinctResponseModels #611

Merged
merged 11 commits into from
Sep 18, 2024
Merged
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
7 changes: 5 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,15 @@ protected Set<CodegenProperty> getDistinctResponseModel(List<CodegenModel> respo
for (CodegenModel codegenModel : responseModels) {
for (CodegenProperty property : codegenModel.vars) {
property.nameInCamelCase = StringHelper.camelize(property.nameInSnakeCase);
Boolean isOverriden = property.isOverridden;
property.isOverridden = null;
if (Arrays
.stream(Operation.values())
.anyMatch(value -> value.getValue().equals(property.nameInCamelCase))) {
property.nameInCamelCase = "_" + property.nameInCamelCase;
}
distinctResponseModels.add(property);
property.isOverridden = isOverriden;
}
}
return distinctResponseModels;
Expand Down
25 changes: 16 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,15 @@ public Set<CodegenProperty> getDistinctResponseModel(List<CodegenModel> response
for (CodegenModel codegenModel: responseModels) {
for (CodegenProperty property: codegenModel.vars) {
property.nameInCamelCase = StringHelper.camelize(property.nameInSnakeCase);
Boolean isOverriden = property.isOverridden;
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 = isOverriden;
}
}
return distinctResponseModels;
Expand Down Expand Up @@ -298,7 +305,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
10 changes: 8 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,14 @@ 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 isOverriden = var.isOverridden;
var.isOverridden = null;
if(!codegenProperties.contains(var))
codegenProperties.add(var);
var.isOverridden = isOverriden;
});
// resModel.vars.stream().filter(Predicate.not(codegenProperties::contains)).forEach(codegenProperties::add);
}

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