Skip to content

Commit

Permalink
fix: adding exception for v2010 apis (#572)
Browse files Browse the repository at this point in the history
<!--
We appreciate the effort for this pull request but before that please
make sure you read the contribution guidelines, then fill out the blanks
below.

Please format the PR title appropriately based on the type of change:
  <type>[!]: <description>
Where <type> is one of: docs, chore, feat, fix, test, misc.
Add a '!' after the type for breaking changes (e.g. feat!: new breaking
feature).

**All third-party contributors acknowledge that any contributions they
provide will be made under the same open-source license that the
open-source project is provided under.**

Please enter each Issue number you are resolving in your PR after one of
the following words [Fixes, Closes, Resolves]. This will auto-link these
issues and close them when this PR is merged!
e.g.
Fixes #1
Closes #2
-->

# Fixes #

Skips ApiV2010 from removing status code in models

### 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.
  • Loading branch information
tiwarishubham635 authored Apr 4, 2024
1 parent 9a05890 commit 5a56ab0
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/main/java/com/twilio/oai/TwilioGoGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ String removeStatusCode(String modelName) {
}

String removeDigits(String modelName) {
if(modelName == null || modelName.isEmpty())
if(modelName == null || modelName.isEmpty() || modelName.contains("2010"))
return modelName;
return modelName.replaceFirst("\\d{3}", "");
}
Expand Down Expand Up @@ -169,17 +169,17 @@ public OperationsMap postProcessOperationsWithModels(final OperationsMap objs, L
final List<CodegenOperation> opList = ops.getOperation();

final Map<String, CodegenModel> models = allModels
.stream()
.map(m -> m.get("model"))
.map(CodegenModel.class::cast)
.collect(Collectors.toMap(CodegenModel::getName, Function.identity()));
.stream()
.map(m -> m.get("model"))
.map(CodegenModel.class::cast)
.collect(Collectors.toMap(CodegenModel::getName, Function.identity()));

// get the model for the return type
final Optional<CodegenModel> returnModel = opList
.stream()
.filter(op -> models.containsKey(op.returnType))
.map(op -> models.get(op.returnType))
.findFirst();
.stream()
.filter(op -> models.containsKey(op.returnType))
.map(op -> models.get(op.returnType))
.findFirst();

for (final CodegenOperation co : opList) {
Utility.populateCrudOperations(co);
Expand All @@ -193,9 +193,9 @@ public OperationsMap postProcessOperationsWithModels(final OperationsMap objs, L
// filter the fields in the model and get only the array typed field. Also, make sure there is only one field of type list/array
if (returnModel.isPresent()) {
CodegenProperty field = returnModel.get().allVars
.stream()
.filter(v -> v.dataType.startsWith("[]"))
.collect(toSingleton());
.stream()
.filter(v -> v.dataType.startsWith("[]"))
.collect(toSingleton());

co.returnContainer = co.returnType;
co.returnType = field.dataType;
Expand All @@ -209,9 +209,9 @@ public OperationsMap postProcessOperationsWithModels(final OperationsMap objs, L
CodegenModel model = (CodegenModel) modelMap.get("model");
final Optional<CodegenModel> returnModelOther = Optional.ofNullable(model);
CodegenProperty field = returnModelOther.get().allVars
.stream()
.filter(v -> v.dataType.startsWith("[]"))
.collect(toSingleton());
.stream()
.filter(v -> v.dataType.startsWith("[]"))
.collect(toSingleton());

co.returnContainer = co.returnType;
co.returnType = field.dataType;
Expand Down

0 comments on commit 5a56ab0

Please sign in to comment.