mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
Add Content-Type header & method option to OpenAPI JavaScript code example (#2096)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user