mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Indent JSON python code sample (#3260)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Indent JSON python code sample
|
||||||
@@ -400,7 +400,7 @@ describe('python code sample generator', () => {
|
|||||||
const output = generator?.generate(input);
|
const output = generator?.generate(input);
|
||||||
|
|
||||||
expect(output).toBe(
|
expect(output).toBe(
|
||||||
'import requests\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"application/x-www-form-urlencoded"},\n data={"key":"value"}\n)\n\ndata = response.json()'
|
'import requests\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"application/x-www-form-urlencoded"},\n data={\n "key": "value"\n }\n)\n\ndata = response.json()'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -422,7 +422,7 @@ describe('python code sample generator', () => {
|
|||||||
const output = generator?.generate(input);
|
const output = generator?.generate(input);
|
||||||
|
|
||||||
expect(output).toBe(
|
expect(output).toBe(
|
||||||
'import requests\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"application/json"},\n data=json.dumps({"key":"value","truethy":True,"falsey":False,"nullish":None})\n)\n\ndata = response.json()'
|
'import requests\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"application/json"},\n data=json.dumps({\n "key": "value",\n "truethy": True,\n "falsey": False,\n "nullish": None\n })\n)\n\ndata = response.json()'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -356,18 +356,22 @@ const BodyGenerators = {
|
|||||||
// Convert JSON to XML if needed
|
// Convert JSON to XML if needed
|
||||||
body = JSON.stringify(convertBodyToXML(body));
|
body = JSON.stringify(convertBodyToXML(body));
|
||||||
} else {
|
} else {
|
||||||
body = stringifyOpenAPI(body, (_key, value) => {
|
body = stringifyOpenAPI(
|
||||||
switch (value) {
|
body,
|
||||||
case true:
|
(_key, value) => {
|
||||||
return '$$__TRUE__$$';
|
switch (value) {
|
||||||
case false:
|
case true:
|
||||||
return '$$__FALSE__$$';
|
return '$$__TRUE__$$';
|
||||||
case null:
|
case false:
|
||||||
return '$$__NULL__$$';
|
return '$$__FALSE__$$';
|
||||||
default:
|
case null:
|
||||||
return value;
|
return '$$__NULL__$$';
|
||||||
}
|
default:
|
||||||
})
|
return value;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
2
|
||||||
|
)
|
||||||
.replaceAll('"$$__TRUE__$$"', 'True')
|
.replaceAll('"$$__TRUE__$$"', 'True')
|
||||||
.replaceAll('"$$__FALSE__$$"', 'False')
|
.replaceAll('"$$__FALSE__$$"', 'False')
|
||||||
.replaceAll('"$$__NULL__$$"', 'None');
|
.replaceAll('"$$__NULL__$$"', 'None');
|
||||||
|
|||||||
Reference in New Issue
Block a user