Skip to content

Commit a3ec264

Browse files
authored
Fix Python code sample "null vs None" (#3215)
1 parent 5d504ff commit a3ec264

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

.changeset/twelve-news-joke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@gitbook/react-openapi": patch
3+
---
4+
5+
Fix Python code sample "null vs None"

packages/react-openapi/src/code-samples.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,14 @@ describe('python code sample generator', () => {
415415
key: 'value',
416416
truethy: true,
417417
falsey: false,
418+
nullish: null,
418419
},
419420
};
420421

421422
const output = generator?.generate(input);
422423

423424
expect(output).toBe(
424-
'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()'
425+
'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()'
425426
);
426427
});
427428

packages/react-openapi/src/code-samples.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,15 @@ const BodyGenerators = {
362362
return '$$__TRUE__$$';
363363
case false:
364364
return '$$__FALSE__$$';
365+
case null:
366+
return '$$__NULL__$$';
365367
default:
366368
return value;
367369
}
368370
})
369371
.replaceAll('"$$__TRUE__$$"', 'True')
370-
.replaceAll('"$$__FALSE__$$"', 'False');
372+
.replaceAll('"$$__FALSE__$$"', 'False')
373+
.replaceAll('"$$__NULL__$$"', 'None');
371374
}
372375

373376
return { body, code, headers };

0 commit comments

Comments
 (0)