From c7e220086d642a70cb13a6c7f20f73d0e02b20d1 Mon Sep 17 00:00:00 2001 From: derek Date: Wed, 22 Jul 2020 16:57:17 +0800 Subject: [PATCH] Add support for default response and fix an issue related to model --- powershell/cmdlets/class.ts | 2 +- powershell/llcsharp/operation/method.ts | 4 ++-- powershell/plugins/cs-namer-v2.ts | 15 +++++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/powershell/cmdlets/class.ts b/powershell/cmdlets/class.ts index cf021f9190..471b9d41b6 100644 --- a/powershell/cmdlets/class.ts +++ b/powershell/cmdlets/class.ts @@ -1872,7 +1872,7 @@ export class NewCmdletClass extends Class { } // create the response handlers - const responses = [...values(apiCall.responses)]; + const responses = [...values(apiCall.responses), ...values(apiCall.exceptions)]; const callbackMethods = values(responses).toArray().map(each => new LiteralExpression(each.language.csharp?.name || '')); diff --git a/powershell/llcsharp/operation/method.ts b/powershell/llcsharp/operation/method.ts index 35f9f09ed7..cdc12a501e 100644 --- a/powershell/llcsharp/operation/method.ts +++ b/powershell/llcsharp/operation/method.ts @@ -356,7 +356,7 @@ export class NewOperationMethod extends Method { // this.addParameter(this.bodyParameter); // } - for (const response of values(this.operation.responses)) { + for (const response of [...values(this.operation.responses), ...values(this.operation.exceptions)]) { const responseType = (response).schema ? state.project.modelsNamespace.NewResolveTypeDeclaration(((response).schema), true, state) : null; //skip-for-time-being @@ -887,7 +887,7 @@ export class NewCallMethod extends Method { // add response handlers yield Switch(`${response}.StatusCode`, function* () { - for (const responses of values(opMethod.operation.responses)) { + for (const responses of [...values(opMethod.operation.responses), ...values(opMethod.operation.exceptions)]) { if (responses.protocol.http?.statusCodes[0] !== 'default') { const responseCode = responses.protocol.http?.statusCodes[0]; // will use enum when it can, fall back to casting int when it can't diff --git a/powershell/plugins/cs-namer-v2.ts b/powershell/plugins/cs-namer-v2.ts index c39262b7b4..c4932fe2f8 100644 --- a/powershell/plugins/cs-namer-v2.ts +++ b/powershell/plugins/cs-namer-v2.ts @@ -65,17 +65,17 @@ function setSchemaNames(schemaGroups: Dictionary>, azure: boolean, // create the namespace if required if (azure) { - const metadata = schema.extensions && schema.extensions['x-ms-metadata']; - if (metadata) { - const apiVersions = | undefined>metadata.apiVersions; - if (apiVersions && length(apiVersions) > 0) { - thisApiversion = minimum(apiVersions); + const versions = [...values(schema.apiVersions).select(v => v.version)]; + if (schema.language.default?.uid !== 'universal-parameter-type') { + if (versions && length(versions) > 0) { + thisApiversion = minimum(versions); thisNamespace = subNamespace.get(thisApiversion) || new Set(); subNamespace.set(thisApiversion, thisNamespace); } } } + // for each schema, we're going to set the name // to the suggested name, unless we have collisions // at which point, we're going to add a number (for now?) @@ -195,7 +195,9 @@ async function setOperationNames(state: State, resolver: NewSchemaDefinitionReso }; } - for (const rsp of values(operation.responses)) { + const responses = [...values(operation.responses), ...values(operation.exceptions)]; + + for (const rsp of responses) { // per responseCode const response = rsp; const responseTypeDefinition = response.schema ? resolver.resolveTypeDeclaration(response.schema, true, state) : undefined; @@ -205,6 +207,7 @@ async function setOperationNames(state: State, resolver: NewSchemaDefinitionReso 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,