-
Notifications
You must be signed in to change notification settings - Fork 17
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
base: main
Are you sure you want to change the base?
Changes from all commits
35d2736
29f595e
c6f0eea
0541dc7
c4eee19
d4e7086
d0e0933
3bfe21d
b3eeb87
55364db
622f931
e3bc20b
a53ecc6
0441b5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
import org.openapitools.codegen.CodegenOperation; | ||
import org.openapitools.codegen.CodegenParameter; | ||
import org.openapitools.codegen.CodegenProperty; | ||
import org.openapitools.codegen.CodegenSecurity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
@@ -34,9 +35,12 @@ | |
|
||
public class CsharpApiResourceBuilder extends ApiResourceBuilder { | ||
|
||
public String authMethod = ""; | ||
|
||
public CsharpApiResourceBuilder(IApiActionTemplate template, List<CodegenOperation> codegenOperations, | ||
List<CodegenModel> allModels) { | ||
super(template, codegenOperations, allModels); | ||
processAuthMethods(codegenOperations); | ||
} | ||
|
||
public IApiResourceBuilder updateTemplate() { | ||
|
@@ -62,6 +66,13 @@ public IApiResourceBuilder setImports(DirectoryStructureService directoryStructu | |
metaAPIProperties.put("array-exists-options", true); | ||
} | ||
}); | ||
|
||
if(this.authMethod == EnumConstants.AuthType.BEARER_TOKEN.getValue()){ | ||
metaAPIProperties.put("auth_method-bearer-token", true); | ||
} | ||
else if(this.authMethod == EnumConstants.AuthType.NOAUTH.getValue()){ | ||
metaAPIProperties.put("auth_method-no-auth", true); | ||
} | ||
if (OperationStore.getInstance().isEnumPresentInOptions()) | ||
metaAPIProperties.put("enum-exists-options", true); | ||
|
||
|
@@ -78,14 +89,31 @@ public CsharpApiResources build() { | |
@Override | ||
public ApiResourceBuilder updateOperations(Resolver<CodegenParameter> codegenParameterIResolver) { // CsharpParameterResolver | ||
super.updateOperations(codegenParameterIResolver); | ||
processAuthMethods(this.codegenOperationList); | ||
this.codegenOperationList.forEach(co -> { | ||
co.headerParams.forEach(e -> codegenParameterIResolver.resolve(e, this)); | ||
populateRequestBodyArgument(co); | ||
resolveIngressModel(co); | ||
}); | ||
|
||
return this; | ||
} | ||
|
||
public void processAuthMethods(List<CodegenOperation> opList) { | ||
if(opList != null){ | ||
List<CodegenSecurity> authMethods = opList.get(0).authMethods; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = EnumConstants.AuthType.BEARER_TOKEN.getValue(); | ||
} | ||
} | ||
} | ||
else{ | ||
this.authMethod = EnumConstants.AuthType.NOAUTH.getValue(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void updateHttpMethod(CodegenOperation co) { | ||
switch (co.httpMethod) { | ||
|
@@ -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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will think about it and we can re-visit it later. |
||
return; | ||
} | ||
codegenModelResolver.resolve(responseModel.get(), this); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,7 +118,7 @@ public Optional<CodegenModel> getModel(final List<CodegenModel> models, | |
.map(CodegenProperty::getComplexType) | ||
.map(classname -> getModelByClassname(models, classname)) | ||
.findFirst() | ||
.orElseThrow(); | ||
.orElse(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we are changing to orElse(null) ? |
||
} | ||
|
||
return getModelByClassname(models, className); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,9 +73,12 @@ private void resolveEnum(CodegenProperty property) { | |
} | ||
String className = OperationStore.getInstance().getClassName(); | ||
property.isEnum = true; | ||
property.enumName = property.complexType.contains("Enum") || property.complexType.contains("enum") | ||
? 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check if it is not breaking existing code. And above enum is referenced at 2 or more places. |
||
: Utility.removeEnumName(property.complexType); | ||
} | ||
|
||
// In case enum is an array | ||
if (property.items != null) { | ||
property.items.enumName = property.enumName; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,11 @@ | |
/// <param name="targetUrl"> API-generated URL for the requested results page </param> | ||
/// <param name="client"> Client to make requests to Twilio </param> | ||
/// <returns> The target page of records </returns> | ||
public static Page<{{apiName}}{{resourceConstant}}> GetPage(string targetUrl, ITwilioRestClient client) | ||
public static Page<{{apiName}}{{resourceConstant}}> GetPage(string targetUrl, {{clientName}} client) | ||
{ | ||
client = client ?? TwilioClient.GetRestClient(); | ||
client = client ?? {{domainClass}}.{{restClientMethodName}}(); | ||
|
||
var request = new Request( | ||
var request = new {{requestName}}Request( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to have different request model ? |
||
HttpMethod.Get, | ||
targetUrl | ||
); | ||
|
@@ -20,9 +20,9 @@ | |
/// <param name="page"> current page of records </param> | ||
/// <param name="client"> Client to make requests to Twilio </param> | ||
/// <returns> The next page of records </returns> | ||
public static Page<{{apiName}}{{resourceConstant}}> NextPage(Page<{{apiName}}{{resourceConstant}}> page, ITwilioRestClient client) | ||
public static Page<{{apiName}}{{resourceConstant}}> NextPage(Page<{{apiName}}{{resourceConstant}}> page, {{clientName}} client) | ||
{ | ||
var request = new Request( | ||
var request = new {{requestName}}Request( | ||
HttpMethod.Get, | ||
page.GetNextPageUrl(Rest.Domain.Api) | ||
); | ||
|
@@ -35,9 +35,9 @@ | |
/// <param name="page"> current page of records </param> | ||
/// <param name="client"> Client to make requests to Twilio </param> | ||
/// <returns> The previous page of records </returns> | ||
public static Page<{{apiName}}{{resourceConstant}}> PreviousPage(Page<{{apiName}}{{resourceConstant}}> page, ITwilioRestClient client) | ||
public static Page<{{apiName}}{{resourceConstant}}> PreviousPage(Page<{{apiName}}{{resourceConstant}}> page, {{clientName}} client) | ||
{ | ||
var request = new Request( | ||
var request = new {{requestName}}Request( | ||
HttpMethod.Get, | ||
page.GetPreviousPageUrl(Rest.Domain.Api) | ||
); | ||
|
There was a problem hiding this comment.
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.