Add header in path for pageable method (#1215)

* add header in path

* rush lint
This commit is contained in:
Beisi Zhou 2023-08-23 10:31:10 +08:00 коммит произвёл GitHub
Родитель 7c334570e1
Коммит e94785698f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 33 добавлений и 2 удалений

Просмотреть файл

@ -224,7 +224,30 @@ function addNormalMethodParameterDeclaration(operation: Operation, state: State)
}
function addPageableMethodParameterDeclaration(operation: Operation) {
const pageableMethodDeclarations: Array<string> = ['string nextPageLink'];
const optionalDeclarations: Array<string> = [];
const requiredDeclarations: Array<string> = [];
const requiredArgs: Array<string> = [];
const optionalArgs: Array<string> = [];
const headerParameters: Array<Parameter> = (operation.parameters || []).filter(p => p.implementation != 'Client' && !(p.extensions && p.extensions['x-ms-parameter-grouping'])
&& !(p.required && p.schema.type === SchemaType.Choice && (<ChoiceSchema>p.schema).choices.length === 1)
&& !(p.required && p.schema.type === SchemaType.SealedChoice && (<SealedChoiceSchema>p.schema).choices.length === 1)
&& p.protocol.http?.in === ParameterLocation.Header);
headerParameters.forEach(function (parameter) {
let type = parameter.schema.language.csharp?.fullname || parameter.schema.language.csharp?.name || '';
if (parameter.extensions && parameter.extensions['x-ms-odata']) {
type = `Microsoft.Rest.Azure.OData.ODataQuery<${type}>`;
}
const postfix = typePostfix(parameter.schema, parameter.nullable != false);
if (!(parameter.required && parameter.schema.type === SchemaType.Constant)) {
// skip required const parameter
parameter.required ? requiredDeclarations.push(`${type} ${parameter.language.default.name}`) : optionalDeclarations.push(`${type}${postfix} ${parameter.language.default.name} = default(${type}${postfix})`);
parameter.required ? requiredArgs.push(parameter.language.default.name) : optionalArgs.push(parameter.language.default.name);
}
});
const pageableMethodDeclarations: Array<string> = ['string nextPageLink', ...requiredDeclarations, ...optionalDeclarations];
operation.language.default.syncMethodParameterDeclaration = pageableMethodDeclarations.join(', ');
pageableMethodDeclarations.push('System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)');
@ -237,12 +260,17 @@ function addPageableMethodParameterDeclaration(operation: Operation) {
pageableMethodDeclarations.push('System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)');
operation.language.default.asyncMethodParameterDeclarationWithCustomHeader = pageableMethodDeclarations.join(', ');
const pageableMethodArgs: Array<string> = ['nextPageLink'];
const pageableMethodArgs: Array<string> = ['nextPageLink', ...requiredArgs, ...optionalArgs];
operation.language.default.syncMethodInvocationArgs = pageableMethodArgs.join(', ');
const pageableMethodArgsWithCustomerHeaders: Array<string> = [...pageableMethodArgs];
pageableMethodArgs.push('null');
pageableMethodArgs.push('cancellationToken');
operation.language.default.asyncMethodInvocationArgs = pageableMethodArgs.join(', ');
pageableMethodArgsWithCustomerHeaders.push('customHeaders');
pageableMethodArgsWithCustomerHeaders.push('cancellationToken');
operation.language.default.asyncMethodInvocationArgsWithCustomerHeaders = pageableMethodArgsWithCustomerHeaders.join(', ');
}
function tweakGlobalParameter(globalParameters: Array<Parameter>) {

Просмотреть файл

@ -74,6 +74,9 @@ if (method.extensions && method.extensions['x-ms-request-id']) {
System.Collections.Generic.Dictionary<string, object> tracingParameters = new System.Collections.Generic.Dictionary<string, object>();
<% if(method.language.default.pageable?.nextPageOperation) {-%>
tracingParameters.Add("nextPageLink", nextPageLink);
<% (method.parameters || []).filter(p => p.protocol.http.in == 'header').forEach(function(p) {-%>
tracingParameters.Add("<%-p.language.default.name%>", <%-p.language.default.name%>);
<%});-%>
<% }else{-%>
<%# ToDo: add support for Model.LogicalParameters.Where(p => !p.IsClientProperty)-%>
<%method.parameters.filter(p => p.implementation != 'Client' && p.protocol.http.in != 'complex').forEach(function(p) {-%>