function addPageableMethodParameterDeclaration()

in powershell/plugins/sdk-tweak-model.ts [231:279]


function addPageableMethodParameterDeclaration(operation: Operation) {
  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 || p.protocol.http?.in === 'complexHeader'));

  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)');
  operation.language.default.asyncMethodParameterDeclaration = pageableMethodDeclarations.join(', ');

  pageableMethodDeclarations.pop();
  pageableMethodDeclarations.push('System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null');
  operation.language.default.syncMethodParameterDeclarationWithCustomHeader = pageableMethodDeclarations.join(', ');

  pageableMethodDeclarations.push('System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)');
  operation.language.default.asyncMethodParameterDeclarationWithCustomHeader = pageableMethodDeclarations.join(', ');

  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(', ');
}