Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/typespec-ts/src/modular/emitSamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,16 @@ function getParameterValue(value: SdkExampleValue): string {
retValue = `new Date("${value.value}")`;
break;
default:
retValue = `"${value.value}"`;
retValue = `"${value.value
?.toString()
.replace(/\\/g, "\\\\")
.replace(/"/g, '\\"')
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r")
.replace(/\t/g, "\\t")
.replace(/\f/g, "\\f")
.replace(/>/g, ">")
.replace(/</g, "<")}"`;
break;
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ model Widget {
utcDateTimeProp: utcDateTime;
offsetDateTimeProp: offsetDateTime;
durationProp: duration;
withEscapeChars: string;
}

@doc("show example demo")
Expand Down Expand Up @@ -64,7 +65,8 @@ op read(@bodyRoot body: Widget): { @body body: {}};
"plainTimeProp": "13:06:12",
"utcDateTimeProp": "2022-08-26T18:38:00Z",
"offsetDateTimeProp": "2022-08-26T18:38:00Z",
"durationProp": "P123DT22H14M12.011S"
"durationProp": "P123DT22H14M12.011S",
"withEscapeChars": "\"Tag 10\".Value"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kazrael2119 could you add more escape cases here? I believe we met some in swagger gen.

}
},
"responses": {
Expand Down Expand Up @@ -107,7 +109,8 @@ async function read() {
utcDateTimeProp: new Date("2022-08-26T18:38:00Z"),
offsetDateTimeProp: "2022-08-26T18:38:00Z",
durationProp: "P123DT22H14M12.011S",
additionalProp: "additional prop",
withEscapeChars: '"Tag 10".Value',
additionalProp: "additional prop"
});
console.log(result);
}
Expand Down