in powershell/plugins/sdk-tweak-model.ts [162:229]
function addNormalMethodParameterDeclaration(operation: Operation, state: State) {
let declarations: Array<string> = [];
const optionalDeclarations: Array<string> = [];
const requiredDeclarations: Array<string> = [];
const requiredArgs: Array<string> = [];
const optionalArgs: Array<string> = [];
const args: Array<string> = [];
let bodyParameters: Array<Parameter> = [];
if (operation.requests && operation.requests.length > 0) {
bodyParameters = (operation.requests[0].parameters || []).filter(p => p.protocol.http?.in === ParameterLocation.Body);
}
(operation.parameters || []).filter(p => p.implementation != 'Client' && p.protocol.http?.in !== 'complexHeader' && !(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)).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);
}
});
bodyParameters.filter(p => !(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)).forEach(function (parameter) {
if (parameter.extensions && parameter.extensions['x-ms-client-flatten']) {
const constructorParametersDeclarationWithoutReadOnly = <string>parameter.schema.language.default.constructorParametersDeclarationWithoutReadOnly;
splitStringWithExclusion(constructorParametersDeclarationWithoutReadOnly, ',').forEach(function (p) {
requiredDeclarations.push(p);
requiredArgs.push(splitStringWithExclusion(p, ' ')[1]);
});
} else {
let type = parameter.schema.language.csharp && parameter.schema.language.csharp.fullname && parameter.schema.language.csharp.fullname != '<INVALID_FULLNAME>' ? parameter.schema.language.csharp.fullname : parameter.schema.language.default.name;
if (parameter.schema.type === SchemaType.Binary) {
//as response or request body, binary is always stream, otherwise it is string
type = 'System.IO.Stream';
}
const postfix = typePostfix(parameter.schema, parameter.nullable != false);
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);
}
});
declarations = [...requiredDeclarations, ...optionalDeclarations];
operation.language.default.syncMethodParameterDeclaration = declarations.join(', ');
declarations.push('System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)');
operation.language.default.asyncMethodParameterDeclaration = declarations.join(', ');
declarations.pop();
declarations.push('System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null');
operation.language.default.syncMethodParameterDeclarationWithCustomHeader = declarations.join(', ');
declarations.push('System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)');
operation.language.default.asyncMethodParameterDeclarationWithCustomHeader = declarations.join(', ');
args.push(...requiredArgs, ...optionalArgs);
operation.language.default.syncMethodInvocationArgs = args.join(', ');
const argsWithCustomerHeaders: Array<string> = [...args];
args.push('null');
args.push('cancellationToken');
argsWithCustomerHeaders.push('customHeaders');
argsWithCustomerHeaders.push('cancellationToken');
operation.language.default.asyncMethodInvocationArgs = args.join(', ');
operation.language.default.asyncMethodInvocationArgsWithCustomerHeaders = argsWithCustomerHeaders.join(', ');
}