in powershell/plugins/cs-namer-v2.ts [170:238]
async function setOperationNames(state: State, resolver: SchemaDefinitionResolver) {
// keep a list of operation names that we've assigned.
const operationNames = new Set<string>();
for (const operationGroup of values(state.model.operationGroups)) {
for (const operation of values(operationGroup.operations)) {
const details = operation.language.default;
// come up with a name
const oName = getPascalIdentifier(operationGroup.$key + '_' + details.name);
let i = 1;
let operationName = oName;
while (operationNames.has(operationName)) {
// if we have used that name, try again.
operationName = `${oName}${i++}`;
}
operationNames.add(operationName);
operation.language.csharp = {
...details, // inherit
name: operationName,
};
// parameters are camelCased.
for (const parameter of values(operation.parameters)) {
const parameterDetails = parameter.language.default;
let propName = camelCase(fixLeadingNumber(deconstruct(parameterDetails.serializedName)));
if (propName === 'default') {
propName = '@default';
}
parameter.language.csharp = {
...parameterDetails,
name: propName
};
}
const responses = [...values(operation.responses), ...values(operation.exceptions)];
for (const rsp of responses) {
// per responseCode
const response = <SchemaResponse>rsp;
const responseTypeDefinition = response.schema ? resolver.resolveTypeDeclaration(<any>response.schema, true, state, await state.getValue('fixed-array', false)) : undefined;
const headerSchema = response.language.default.headerSchema;
const headerTypeDefinition = headerSchema ? resolver.resolveTypeDeclaration(<any>headerSchema, true, state.path('schemas', headerSchema.language.default.name), await state.getValue('fixed-array', false)) : undefined;
let code = (System.Net.HttpStatusCode[response.protocol.http?.statusCodes[0]] ? System.Net.HttpStatusCode[response.protocol.http?.statusCodes[0]].value : (response.protocol.http?.statusCodes[0] || '')).replace('global::System.Net.HttpStatusCode', '');
let rawValue = code.replace(/\./, '');
if (response.protocol.http?.statusCodes[0] === 'default' || rawValue === 'default' || '') {
rawValue = 'any response code not handled elsewhere';
code = 'default';
response.language.default.isErrorResponse = true;
}
response.language.csharp = {
...response.language.default,
responseType: responseTypeDefinition ? responseTypeDefinition.declaration : '',
headerType: headerTypeDefinition ? headerTypeDefinition.declaration : '',
name: (length(response.protocol.http?.mimeTypes) <= 1) ?
camelCase(fixLeadingNumber(deconstruct(`on ${code}`))) : // the common type (or the only one.)
camelCase(fixLeadingNumber(deconstruct(`on ${code} ${response.protocol.http?.mimeTypes[0]}`))),
description: (length(response.protocol.http?.mimeTypes) <= 1) ?
`a delegate that is called when the remote service returns ${response.protocol.http?.statusCodes[0]} (${rawValue}).` :
`a delegate that is called when the remote service returns ${response.protocol.http?.statusCodes[0]} (${rawValue}) with a Content-Type matching ${response.protocol.http?.mimeTypes.join(',')}.`
};
}
}
}
}