Fix Python code sample "null vs None" (#3215)

This commit is contained in:
Greg Bergé
2025-05-06 15:40:56 +02:00
committed by GitHub
parent 5d504ffa4c
commit a3ec264764
3 changed files with 11 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@gitbook/react-openapi": patch
---
Fix Python code sample "null vs None"
@@ -415,13 +415,14 @@ describe('python code sample generator', () => {
key: 'value',
truethy: true,
falsey: false,
nullish: null,
},
};
const output = generator?.generate(input);
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})\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({"key":"value","truethy":True,"falsey":False,"nullish":None})\n)\n\ndata = response.json()'
);
});
+4 -1
View File
@@ -362,12 +362,15 @@ const BodyGenerators = {
return '$$__TRUE__$$';
case false:
return '$$__FALSE__$$';
case null:
return '$$__NULL__$$';
default:
return value;
}
})
.replaceAll('"$$__TRUE__$$"', 'True')
.replaceAll('"$$__FALSE__$$"', 'False');
.replaceAll('"$$__FALSE__$$"', 'False')
.replaceAll('"$$__NULL__$$"', 'None');
}
return { body, code, headers };