From f9896d9666d8061ccd4e5abda48272c741ae600e Mon Sep 17 00:00:00 2001 From: Manisha Singh Date: Tue, 26 Nov 2024 12:38:50 +0530 Subject: [PATCH] bug: ruby to use url instead of mount_name for mapping (#622) # Fixes # This implementation stops using mount_name and uses url to do the mapping Validation check pipeline: https://buildkite.com/twilio/twilio-librarian-status-checks/builds/11963#_ ### Checklist - [x] I acknowledge that all my contributions will be made under the project's license - [x] Run `make test-docker` - [x] Verify affected language: - [x] 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 - [x] Run `make test` in `twilio-go` - [x] Create a pull request in `twilio-go` - [ ] Provide a link below to the pull request - [x] I have made a material change to the repo (functionality, testing, spelling, grammar) - [x] I have read the [Contribution Guidelines](https://github.com/twilio/twilio-oai-generator/blob/main/CONTRIBUTING.md) and my PR follows them - [x] I have titled the PR appropriately - [x] I have updated my branch with the main branch - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have added the necessary documentation about the functionality in the appropriate .md file - [x] I have added inline documentation to the code I modified If you have questions, please create a GitHub Issue in this repository. --- .../lib/twilio-ruby/rest/api/v2010/account.rb | 4 +-- .../rest/api/v2010/account/call.rb | 4 +-- .../flex_api/v1/credential/new_credentials.rb | 8 +++--- .../twilio/oai/DirectoryStructureService.java | 11 ++++++++ .../java/com/twilio/oai/StringHelper.java | 25 +++++++++++++++++++ .../oai/api/RubyApiResourceBuilder.java | 12 ++++----- 6 files changed, 50 insertions(+), 14 deletions(-) diff --git a/examples/ruby/lib/twilio-ruby/rest/api/v2010/account.rb b/examples/ruby/lib/twilio-ruby/rest/api/v2010/account.rb index bf8e72086..957169297 100644 --- a/examples/ruby/lib/twilio-ruby/rest/api/v2010/account.rb +++ b/examples/ruby/lib/twilio-ruby/rest/api/v2010/account.rb @@ -45,8 +45,8 @@ def create( data = Twilio::Values.of({ 'RecordingStatusCallback' => recording_status_callback, 'RecordingStatusCallbackEvent' => Twilio.serialize_list(recording_status_callback_event) { |e| - e - }, + e + }, 'Twiml' => twiml, }) diff --git a/examples/ruby/lib/twilio-ruby/rest/api/v2010/account/call.rb b/examples/ruby/lib/twilio-ruby/rest/api/v2010/account/call.rb index be5fad79f..0bd991e4b 100644 --- a/examples/ruby/lib/twilio-ruby/rest/api/v2010/account/call.rb +++ b/examples/ruby/lib/twilio-ruby/rest/api/v2010/account/call.rb @@ -49,8 +49,8 @@ def create( 'RequiredStringProperty' => required_string_property, 'TestMethod' => test_method, 'TestArrayOfStrings' => Twilio.serialize_list(test_array_of_strings) { |e| - e - }, + e + }, 'TestArrayOfUri' => Twilio.serialize_list(test_array_of_uri) { |e| e }, }) diff --git a/examples/ruby/lib/twilio-ruby/rest/flex_api/v1/credential/new_credentials.rb b/examples/ruby/lib/twilio-ruby/rest/flex_api/v1/credential/new_credentials.rb index 66b3106cc..a22123680 100644 --- a/examples/ruby/lib/twilio-ruby/rest/flex_api/v1/credential/new_credentials.rb +++ b/examples/ruby/lib/twilio-ruby/rest/flex_api/v1/credential/new_credentials.rb @@ -83,12 +83,12 @@ def create( 'TestDate' => Twilio.serialize_iso8601_date(test_date), 'TestEnum' => test_enum, 'TestObjectArray' => Twilio.serialize_list(test_object_array) { |e| - Twilio.serialize_object(e) - }, + Twilio.serialize_object(e) + }, 'TestAnyType' => Twilio.serialize_object(test_any_type), 'TestAnyArray' => Twilio.serialize_list(test_any_array) { |e| - Twilio.serialize_object(e) - }, + Twilio.serialize_object(e) + }, 'Permissions' => Twilio.serialize_list(permissions) { |e| e }, 'SomeA2PThing' => some_a2p_thing, }) diff --git a/src/main/java/com/twilio/oai/DirectoryStructureService.java b/src/main/java/com/twilio/oai/DirectoryStructureService.java index 09befc562..9b43e51c7 100644 --- a/src/main/java/com/twilio/oai/DirectoryStructureService.java +++ b/src/main/java/com/twilio/oai/DirectoryStructureService.java @@ -68,6 +68,7 @@ public static class ContextResource { private String mountName; private String parent; private String dependentProperties; + private String url; } public void configure(final OpenAPI openAPI) { @@ -186,12 +187,22 @@ public void addContextdependents(final List resourceList, final String p String parent = String.join("\\", resourceTree.ancestors(path, operation)); List pathParamsList = fetchNonParentPathParams(operation); List pathParamNamesList = pathParamsList.stream().map(Parameter::getName).collect(Collectors.toList()); + HashMap mapTagToListPath = new HashMap<>(); + this.getResourceTree().getResources().iterator().forEachRemaining(resource -> { + if (PathUtils.getTwilioExtension(resource.getPathItem(), "pathType").isPresent() && PathUtils.getTwilioExtension(resource.getPathItem(), "pathType").get().equals("list")) + mapTagToListPath.put(resource.getListTag(), resource.getName()); + }); + Optional tagNameOptional = this.getResourceTree().findResource(path); + String listTag = ""; + if( tagNameOptional.isPresent() ) + listTag = mapTagToListPath.get(tagNameOptional.get().getListTag()); final ContextResource dependent = new ContextResource.ContextResourceBuilder() .version(PathUtils.getFirstPathPart(path)) .params(pathParamNamesList) .mountName(caseResolver.pathOperation(resourceAliases.getMountName())) .filename(caseResolver.filenameOperation(resourceAliases.getClassName())) .parent(parent) + .url(pathParamNamesList.isEmpty()?StringHelper.convertUrlToCamelCase(path):StringHelper.convertUrlToCamelCase(listTag)) .build(); if (!resourceList.contains(dependent)) resourceList.add(dependent); diff --git a/src/main/java/com/twilio/oai/StringHelper.java b/src/main/java/com/twilio/oai/StringHelper.java index 44f047564..690559772 100644 --- a/src/main/java/com/twilio/oai/StringHelper.java +++ b/src/main/java/com/twilio/oai/StringHelper.java @@ -2,6 +2,8 @@ import java.util.Arrays; import java.util.function.UnaryOperator; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; import lombok.experimental.UtilityClass; @@ -48,4 +50,27 @@ private String convertFirstChar(final String inputWord, final UnaryOperator opList) { .filter(dependent -> dependentMethods.stream() .map(DirectoryStructureService.ContextResource.class::cast).anyMatch( methodDependent -> methodDependent.getMountName().equals(dependent.getMountName())) - - ).collect(Collectors.toList())); + ) + .collect(Collectors.toList())); if (PathUtils.isInstanceOperation(operation)) { metaAPIProperties.put("contextImportProperties", dependentPropertiesList); metaAPIProperties.put("contextImportMethods", dependentMethods); @@ -209,6 +209,7 @@ private void createContextParamsList(List opList) { } }); } + private void updateDependentProperties(List opList){ for (CodegenOperation operation : opList) { Map dependentsForOperation = mapOperationsDependents(operation); @@ -221,8 +222,7 @@ private void updateContextResourceDependents(Map dependentsForOp List listObjs = (List) listofContextResourceObjs; if(listObjs != null) { for (DirectoryStructureService.ContextResource cr : listObjs) { - String value = (dependentsForOperation.containsKey(cr.getFilename())) ? dependentsForOperation.get(cr.getFilename()) - : dependentsForOperation.get(cr.getMountName()); + String value = dependentsForOperation.get(cr.getUrl()); cr.setDependentProperties(value); } } @@ -243,7 +243,7 @@ private Map mapOperationsDependents(CodegenOperation operation){ for (Map.Entry mappingEntry : mapping.entrySet()) { String dependent = mappingEntry.getKey() + ": @solution[:" + mappingEntry.getValue()+ "], "; dependentParams += dependent; - depMap.put(mountName, dependentParams); + depMap.put(StringHelper.convertUrlToCamelCase((String) propertiesDetails.getValue().get("resource_url")), dependentParams); } } seenParams.add(mountName);