Skip to content

Commit

Permalink
fix the response map issue in the emitter (#4307)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcturusZhang authored Sep 3, 2024
1 parent bc1c599 commit a5546ca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 8 additions & 2 deletions packages/http-client-csharp/emitter/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export async function $onEmit(context: EmitContext<NetEmitterOptions>) {

await program.host.writeFile(
resolvePath(outputFolder, tspOutputFileName),
prettierOutput(stringifyRefs(root, convertUsageNumbersToStrings, 1, PreserveType.Objects))
prettierOutput(stringifyRefs(root, transformJSONProperties, 1, PreserveType.Objects))
);

//emit configuration.json
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ export function fromSdkHttpExamples(

function fromSdkOperationResponses(
responses: Map<number, SdkHttpResponseExample>
): Map<number, OperationResponseExample> {
const result = new Map<number, OperationResponseExample>();
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface InputExampleBase {
export interface InputHttpOperationExample extends InputExampleBase {
kind: "http";
parameters: InputParameterExampleValue[];
responses: Map<number, OperationResponseExample>;
responses: OperationResponseExample[];
}

export interface InputParameterExampleValue {
Expand Down

0 comments on commit a5546ca

Please sign in to comment.