Skip to content

Commit d7c18c9

Browse files
Don't double encode application/json requestBody examples (#1100)
1 parent bbe2fc0 commit d7c18c9

File tree

1 file changed

+10
-1
lines changed
  • packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Body

1 file changed

+10
-1
lines changed

packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Body/index.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,18 @@ function Body({
233233
}
234234
if (examples) {
235235
for (const [key, example] of Object.entries(examples)) {
236+
let body = example.value;
237+
try {
238+
// If the value is already valid JSON we shouldn't double encode the value
239+
JSON.parse(example.value);
240+
}
241+
catch (e) {
242+
body = JSON.stringify(example.value, null, 2);
243+
}
244+
236245
examplesBodies.push({
237246
label: key,
238-
body: JSON.stringify(example.value, null, 2),
247+
body,
239248
summary: example.summary,
240249
});
241250
}

0 commit comments

Comments
 (0)