From a5546cafea259effdeeaf6180f6c6945c0769cd9 Mon Sep 17 00:00:00 2001 From: Dapeng Zhang Date: Tue, 3 Sep 2024 16:42:31 +0800 Subject: [PATCH] fix the response map issue in the emitter (#4307) Fixes https://github.com/Azure/autorest.csharp/issues/5027 --- packages/http-client-csharp/emitter/src/emitter.ts | 10 ++++++++-- .../emitter/src/lib/example-converter.ts | 8 ++++---- .../emitter/src/type/input-examples.ts | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/http-client-csharp/emitter/src/emitter.ts b/packages/http-client-csharp/emitter/src/emitter.ts index 9b8dbba1f3..159fdf033f 100644 --- a/packages/http-client-csharp/emitter/src/emitter.ts +++ b/packages/http-client-csharp/emitter/src/emitter.ts @@ -78,7 +78,7 @@ export async function $onEmit(context: EmitContext) { await program.host.writeFile( resolvePath(outputFolder, tspOutputFileName), - prettierOutput(stringifyRefs(root, convertUsageNumbersToStrings, 1, PreserveType.Objects)) + prettierOutput(stringifyRefs(root, transformJSONProperties, 1, PreserveType.Objects)) ); //emit configuration.json @@ -215,7 +215,8 @@ async function execAsync( }); } -function convertUsageNumbersToStrings(this: any, key: string, value: any): any { +function transformJSONProperties(this: any, key: string, value: any): any { + // convertUsageNumbersToStrings if (this["Kind"] === "model" || this["Kind"] === "enum") { if (key === "Usage" && typeof value === "number") { if (value === 0) { @@ -233,6 +234,11 @@ function convertUsageNumbersToStrings(this: any, key: string, value: any): any { } } + // omit the `rawExample` property from the examples + if (key === "rawExample") { + return undefined; + } + return value; } diff --git a/packages/http-client-csharp/emitter/src/lib/example-converter.ts b/packages/http-client-csharp/emitter/src/lib/example-converter.ts index 6fef236f29..3d834d4aa6 100644 --- a/packages/http-client-csharp/emitter/src/lib/example-converter.ts +++ b/packages/http-client-csharp/emitter/src/lib/example-converter.ts @@ -78,10 +78,10 @@ export function fromSdkHttpExamples( function fromSdkOperationResponses( responses: Map - ): Map { - const result = new Map(); - for (const [status, response] of responses) { - result.set(status, fromSdkOperationResponse(response)); + ): OperationResponseExample[] { + const result: OperationResponseExample[] = []; + for (const [_, response] of responses) { + result.push(fromSdkOperationResponse(response)); } return result; } diff --git a/packages/http-client-csharp/emitter/src/type/input-examples.ts b/packages/http-client-csharp/emitter/src/type/input-examples.ts index b86edd83bb..719c19caf6 100644 --- a/packages/http-client-csharp/emitter/src/type/input-examples.ts +++ b/packages/http-client-csharp/emitter/src/type/input-examples.ts @@ -25,7 +25,7 @@ interface InputExampleBase { export interface InputHttpOperationExample extends InputExampleBase { kind: "http"; parameters: InputParameterExampleValue[]; - responses: Map; + responses: OperationResponseExample[]; } export interface InputParameterExampleValue {