From 81057f933b2082ac46b7c64cae619a7671ca0cb1 Mon Sep 17 00:00:00 2001 From: sbansla <104902068+sbansla@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:15:05 +0530 Subject: [PATCH] fix property datatype in language resolver (#582) # Fixes # 1. Property was not getting properly resolved if it was resolved by LanguageResolver for java Java Code change because of this: Object data type will be replaced by Map 2. Added json body in update operation in csharp generation. ### Checklist - [x] I acknowledge that all my contributions will be made under the project's license - [ ] Run `make test-docker` - [ ] Verify affected language: - [ ] Generate [twilio-go](https://github.com/twilio/twilio-go) from our [OpenAPI specification](https://github.com/twilio/twilio-oai) using the [build_twilio_go.py](./examples/build_twilio_go.py) using `python examples/build_twilio_go.py path/to/twilio-oai/spec/yaml path/to/twilio-go` and inspect the diff - [ ] Run `make test` in `twilio-go` - [ ] Create a pull request in `twilio-go` - [ ] Provide a link below to the pull request - [ ] I have made a material change to the repo (functionality, testing, spelling, grammar) - [ ] I have read the [Contribution Guidelines](https://github.com/twilio/twilio-oai-generator/blob/main/CONTRIBUTING.md) and my PR follows them - [ ] I have titled the PR appropriately - [ ] I have updated my branch with the main branch - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have added the necessary documentation about the functionality in the appropriate .md file - [ ] I have added inline documentation to the code I modified If you have questions, please create a GitHub Issue in this repository. --------- Co-authored-by: Shubham --- .../java/com/twilio/oai/api/CsharpApiResourceBuilder.java | 3 +++ .../com/twilio/oai/resolver/LanguagePropertyResolver.java | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/twilio/oai/api/CsharpApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/CsharpApiResourceBuilder.java index aef54ceba..5163292bd 100644 --- a/src/main/java/com/twilio/oai/api/CsharpApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/CsharpApiResourceBuilder.java @@ -171,6 +171,9 @@ public ApiResourceBuilder updateResponseModel(Resolver codegenP codegenOperationList.forEach(codegenOperation -> { codegenOperation.responses.forEach(response -> { String modelName = response.dataType; + if (response.dataType != null && response.dataType.startsWith(EnumConstants.CsharpDataTypes.LIST.getValue())){ + modelName = response.baseType; + } Optional responseModel = Utility.getModel(allModels, modelName, recordKey, codegenOperation); if (responseModel.isEmpty()) { return; diff --git a/src/main/java/com/twilio/oai/resolver/LanguagePropertyResolver.java b/src/main/java/com/twilio/oai/resolver/LanguagePropertyResolver.java index 2ddea50dd..28020f6b9 100644 --- a/src/main/java/com/twilio/oai/resolver/LanguagePropertyResolver.java +++ b/src/main/java/com/twilio/oai/resolver/LanguagePropertyResolver.java @@ -35,9 +35,10 @@ public CodegenProperty resolve(CodegenProperty codegenProperty, ApiResourceBuild protected void resolveProperties(CodegenProperty codegenProperty, ApiResourceBuilder apiResourceBuilder) { mapper - .properties() - .getString(codegenProperty.dataFormat) - .ifPresent(dataType -> codegenProperty.dataType = dataType); + .properties() + .getString(codegenProperty.dataFormat) + .or(() -> mapper.properties().getString(codegenProperty.dataType)) + .ifPresent(dataType -> codegenProperty.dataType = dataType); } protected void resolveSerialize(CodegenProperty codegenProperty) {