Generate extension for client there are API without group (#1239)
* Fixed several issues related to SDK * Add client exentions for the case that key is empty * Generate exentions for operation without group
This commit is contained in:
Родитель
6c57875cf0
Коммит
bb0308efc9
|
@ -44,6 +44,8 @@ async function generateMethodGroups(project: Project) {
|
|||
for (const operationGroup of values(project.state.model.operationGroups)) {
|
||||
if (operationGroup.$key === '') {
|
||||
// for operations with no operation group, they will be added in the client class directly.
|
||||
const clientExtensionContent = await ejs.renderFile(extensionPath, { methodGroup: operationGroup, project: project, clientName: project.state.model.info.title });
|
||||
project.state.writeFile(`${project.baseFolder}\\${project.state.model.info.title}Extensions.cs`, clientExtensionContent, undefined, 'source-file-csharp');
|
||||
continue;
|
||||
}
|
||||
// generate method group class
|
||||
|
@ -54,7 +56,7 @@ async function generateMethodGroups(project: Project) {
|
|||
const interfaceContent = await ejs.renderFile(interfacePath, { methodGroup: operationGroup, project: project });
|
||||
project.state.writeFile(`${project.baseFolder}\\I${key}Operations.cs`, interfaceContent, undefined, 'source-file-csharp');
|
||||
// generate method group extensions
|
||||
const extensionContent = await ejs.renderFile(extensionPath, { methodGroup: operationGroup, project: project });
|
||||
const extensionContent = await ejs.renderFile(extensionPath, { methodGroup: operationGroup, project: project, clientName: '' });
|
||||
project.state.writeFile(`${project.baseFolder}\\${key}OperationsExtensions.cs`, extensionContent, undefined, 'source-file-csharp');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<% var key = methodGroup.$key == 'Operations' ? '' : methodGroup.$key-%>
|
||||
<% var OperationsName = clientName != '' ? clientName : project.helper.PascalCase(key) + 'Operations'-%>
|
||||
<%# ToDo: currently assume the SyncMethodsGenerationMode is Essential type, and need to add support for other types -%>
|
||||
/// <summary>
|
||||
/// <%=method.language.default.description%>
|
||||
|
@ -20,13 +21,13 @@
|
|||
<% } -%>
|
||||
<%# ToDo: add support for GetObsoleteAttribute-%>
|
||||
<%# ToDo: add support for AccessModifier, assume public for the time being-%>
|
||||
public static <%-method.language.default.returnType%> <%-method.language.default.name%>(this I<%-project.helper.PascalCase(key)%>Operations operations<%- method.language.default.syncMethodParameterDeclaration ? ', ' + method.language.default.syncMethodParameterDeclaration: '' %>)
|
||||
public static <%-method.language.default.returnType%> <%-method.language.default.name%>(this I<%-OperationsName%> operations<%- method.language.default.syncMethodParameterDeclaration ? ', ' + method.language.default.syncMethodParameterDeclaration: '' %>)
|
||||
{
|
||||
<%# ToDo: need to handle different return type, body, header and the others including no return type-%>
|
||||
<% if(method.language.default.returnType != 'void') {-%>
|
||||
return ((I<%-project.helper.PascalCase(key)%>Operations)operations).<%-method.language.default.name%>Async(<%-method.language.default.syncMethodInvocationArgs%>).GetAwaiter().GetResult();
|
||||
return ((I<%-OperationsName%>)operations).<%-method.language.default.name%>Async(<%-method.language.default.syncMethodInvocationArgs%>).GetAwaiter().GetResult();
|
||||
<% } else { -%>
|
||||
((I<%-project.helper.PascalCase(key)%>Operations)operations).<%-method.language.default.name%>Async(<%-method.language.default.syncMethodInvocationArgs%>).GetAwaiter().GetResult();
|
||||
((I<%-OperationsName%>)operations).<%-method.language.default.name%>Async(<%-method.language.default.syncMethodInvocationArgs%>).GetAwaiter().GetResult();
|
||||
<% } -%>
|
||||
}
|
||||
|
||||
|
@ -53,7 +54,7 @@
|
|||
/// </param>
|
||||
<%# ToDo: add support for GetObsoleteAttribute-%>
|
||||
<%# ToDo: add support for AccessModifier, assume public for the time being-%>
|
||||
public static async System.Threading.Tasks.Task<%- method.language.default.returnType != 'void' ? '<' + method.language.default.returnType + '>' : ''%> <%-method.language.default.name%>Async(this I<%-project.helper.PascalCase(key)%>Operations operations<%- method.language.default.asyncMethodParameterDeclaration ? ', ' + method.language.default.asyncMethodParameterDeclaration: '' %>)
|
||||
public static async System.Threading.Tasks.Task<%- method.language.default.returnType != 'void' ? '<' + method.language.default.returnType + '>' : ''%> <%-method.language.default.name%>Async(this I<%-OperationsName%> operations<%- method.language.default.asyncMethodParameterDeclaration ? ', ' + method.language.default.asyncMethodParameterDeclaration: '' %>)
|
||||
{
|
||||
<%# ToDo: need to handle different return type, body, header and the others including no return type-%>
|
||||
<% if(method.language.default.returnType != 'void') {-%>
|
||||
|
|
|
@ -6,14 +6,21 @@ namespace <%- project.namespace %>
|
|||
using <%- using %>;
|
||||
<% }); -%>
|
||||
|
||||
<%if (clientName != '') {-%>
|
||||
/// <summary>
|
||||
/// Extension methods for <%- clientName %>
|
||||
/// </summary>
|
||||
public static partial class <%- clientName %>Extensions
|
||||
<% } else {-%>
|
||||
/// <summary>
|
||||
/// Extension methods for <%- project.helper.PascalCase(key) %>Operations
|
||||
/// </summary>
|
||||
public static partial class <%- project.helper.PascalCase(key) %>OperationsExtensions
|
||||
<% }-%>
|
||||
{
|
||||
<% methodGroup.operations.forEach(function(method){ -%>
|
||||
<%# ToDo: add support for ExcludeFromInterface-%>
|
||||
<%- include('extensionMethod', {method: method, group: methodGroup, project: project}) %>
|
||||
<%- include('extensionMethod', {method: method, group: methodGroup, project: project, clientName: clientName}) %>
|
||||
<% }); -%>
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче