Add Content-Type header & method option to OpenAPI JavaScript code example (#2096)

This commit is contained in:
Nicholas
2025-07-19 13:22:23 +08:00
committed by GitHub
parent 06956bf446
commit ac33c3c877
3 changed files with 12 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-openapi': patch
---
Add method option and Content-Type header to generated JavaScript code examples
@@ -6,6 +6,11 @@ export const generator: SampleGenerator = (url, data, { mediaAdapters }) => {
const options = new Map<string, string>();
const headers: Record<string, string> = {};
options.set('method', JSON.stringify(data.method));
if (data.bodyMediaType) {
headers['Content-Type'] = data.bodyMediaType;
}
for (const [k, v] of Object.entries(data.header)) {
headers[k] = v.value as string;
}
+2
View File
@@ -3,7 +3,9 @@ const body = JSON.stringify({
})
fetch("http://localhost:8080/hello_world?search=ai", {
method: "GET",
headers: {
"Content-Type": "application/json",
"authorization": "Bearer",
"cookie": "mode=light"
},