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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

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

sonarcloud bot commented Jul 23, 2024

@@ -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.

Copy link

sonarcloud bot commented Sep 17, 2024

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.

2 participants