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

feat: Organizations Api Uptake for twilio-csharp and support for bearer token/ no token authentication #595

Merged
merged 39 commits into from
Sep 24, 2024

Conversation

AsabuHere
Copy link
Contributor

Fixes

A short description of what this PR does.

Checklist

  • I acknowledge that all my contributions will be made under the project's license
  • Run make test-docker
  • Verify affected language:
    • Generate twilio-go from our OpenAPI specification using the 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 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.

@AsabuHere AsabuHere requested a review from sbansla July 23, 2024 03:24
Copy link

@@ -62,6 +66,13 @@ public IApiResourceBuilder setImports(DirectoryStructureService directoryStructu
metaAPIProperties.put("array-exists-options", true);
}
});

if(this.authMethod == "BearerToken"){
metaAPIProperties.put("auth_method-bearer-token", true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Authmethod can be basic and bearer token. We need to handle that as well.

@@ -62,6 +66,13 @@ public IApiResourceBuilder setImports(DirectoryStructureService directoryStructu
metaAPIProperties.put("array-exists-options", true);
}
});

if(this.authMethod == "BearerToken"){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store'BearerToken' in enum and refer from there


public void processAuthMethods(List<CodegenOperation> opList) {
if(opList != null){
List<CodegenSecurity> authMethods = opList.get(0).authMethods;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to decide rest client on operation not on group of operations.

if(authMethods != null){
for(CodegenSecurity c : authMethods){
if(c.isOAuth == true){
this.authMethod = "BearerToken";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public apis will have basic and token based authentication, We don't want to re-write this code again for OAuth for public APIs.

Copy link
Contributor

@sbansla sbansla Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Oauth is added to public(Non Orgs) APIs, This code will break existing public APIs by modifying its rest client.
This code should not break existing written code if OAuth is added to public APIs.

@@ -175,7 +203,7 @@ public ApiResourceBuilder updateResponseModel(Resolver<CodegenProperty> codegenP
modelName = response.baseType;
}
Optional<CodegenModel> responseModel = Utility.getModel(allModels, modelName, recordKey, codegenOperation);
if (responseModel.isEmpty()) {
if ((responseModel == null) || responseModel.isEmpty() || (Integer.parseInt(response.code) >= 400)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed before that, all twilio APIs uses common exception models and Orgs API follows the same exception model.
Exception Model: https://www.twilio.com/docs/usage/twilios-response#response-formats-exceptions
(Athira has tested that this exception model is used by Orgs API as well)
So we can ignore all error models from generating.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will think about it and we can re-visit it later.

@@ -118,7 +118,7 @@ public Optional<CodegenModel> getModel(final List<CodegenModel> models,
.map(CodegenProperty::getComplexType)
.map(classname -> getModelByClassname(models, classname))
.findFirst()
.orElseThrow();
.orElse(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we are changing to orElse(null) ?

? Utility.removeEnumName(property.complexType) + ApplicationConstants.ENUM
if(property.complexType != null){
property.enumName = property.complexType.contains("Enum") || property.complexType.contains("enum")
? Utility.removeEnumName(property.complexType) + ApplicationConstants.ENUM
Copy link
Contributor

@sbansla sbansla Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if it is not breaking existing code.
Also test if an Enum defined as referenced and is used at multiple places as a property or property and parameter.
For Example:
Enum is defined under component.schema
component.schema.UpdateStatusEnum

And above enum is referenced at 2 or more places.

{
client = client ?? TwilioClient.GetRestClient();
client = client ?? Twilio{{domainClassPrefix}}Client.Get{{restClientClassName}}RestClient();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use similar to {{clientName}}


var request = new Request(
var request = new {{requestName}}Request(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to have different request model ?
What if we use AuthStrategy class as discussed.
AuthStrategy can have child classes which will handle different types of Authentication mechanism
For Example
BasicAuthStrategy, TokenAuthStrategy, NoAuthStrategy.

AsabuHere and others added 7 commits September 17, 2024 10:44
<!--
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 #

In twilio-node, read operation does not handle required query params
correctly, see
[here](https://github.com/twilio/twilio-oai-generator/blob/main/src/main/resources/twilio-node/api-single.mustache#L139).
Till now, the existing APIs do not have such use case, but now some APIs
are trying to pass required query params. This needs to be supported in
twilio-node.

### 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.
# Fixes #

In python, the instancePathParams were not being used to initialize
response models in constructors. So removing those unused params.
<!--
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 #

Removing local file paths

### 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.
manisha1997 and others added 21 commits September 23, 2024 15:52
Removing run_openapi_generator from for loop which was causing too much
delay with pipelines
# Fixes #
Added a null check for content_v1 file before removing it.

### 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.
Copy link

Copy link

Copy link

Quality Gate Passed Quality Gate passed for 'twilio-oai-generator-python'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link

@AsabuHere AsabuHere merged commit c483d12 into main Sep 24, 2024
16 of 20 checks passed
@AsabuHere AsabuHere deleted the csharp_orgs_api_uptake branch September 24, 2024 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants