From 8ab48050cdcd2e28a9564ba288bbadb912f8f458 Mon Sep 17 00:00:00 2001 From: Shubham Date: Wed, 18 Sep 2024 12:27:17 +0530 Subject: [PATCH] chore: skipping isOverridden flag in distinctResponseModels (#611) --- examples/go/Dockerfile-goimports | 2 +- .../twilio/oai/api/ApiResourceBuilder.java | 9 +++++-- .../oai/api/CsharpApiResourceBuilder.java | 26 ++++++++++++------- .../oai/api/JavaApiResourceBuilder.java | 11 ++++++-- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/examples/go/Dockerfile-goimports b/examples/go/Dockerfile-goimports index 7747b9bfa..82ea98f65 100644 --- a/examples/go/Dockerfile-goimports +++ b/examples/go/Dockerfile-goimports @@ -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 diff --git a/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java index 36287c360..355268a87 100644 --- a/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java @@ -93,7 +93,7 @@ public ApiResourceBuilder updateOperations(Resolver codegenPar } public void updateHttpMethod(CodegenOperation co) { - + } protected void resolveParam(final Resolver codegenParameterIResolver, @@ -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 iterator = nestedModels.iterator(); @@ -290,12 +290,17 @@ protected Set getDistinctResponseModel(List 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; diff --git a/src/main/java/com/twilio/oai/api/CsharpApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/CsharpApiResourceBuilder.java index 5163292bd..3bfb70e19 100644 --- a/src/main/java/com/twilio/oai/api/CsharpApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/CsharpApiResourceBuilder.java @@ -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); } } @@ -191,12 +195,16 @@ public Set getDistinctResponseModel(List 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; @@ -298,7 +306,7 @@ private void rearrangeBeforeAfter(final List parameters) { } public boolean isNestedModelPresentWithPropertyName(final CodegenProperty property) { - if (nestedModels == null || nestedModels.size() < 1) return false; + if (nestedModels == null || nestedModels.size() < 1) return false; Optional foundModel = nestedModels.stream() .filter(model -> model.classname.equals(property.name)) .findFirst(); diff --git a/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java index 7c71de2ca..75b20d804 100644 --- a/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java @@ -610,8 +610,15 @@ private CodegenModel getConcatenatedResponseModel(List 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));