mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-20 17:43:24 +00:00
Fix Python code sample "null vs None" (#3215)
This commit is contained in:
@@ -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',
|
key: 'value',
|
||||||
truethy: true,
|
truethy: true,
|
||||||
falsey: false,
|
falsey: false,
|
||||||
|
nullish: null,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
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})\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()'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -362,12 +362,15 @@ const BodyGenerators = {
|
|||||||
return '$$__TRUE__$$';
|
return '$$__TRUE__$$';
|
||||||
case false:
|
case false:
|
||||||
return '$$__FALSE__$$';
|
return '$$__FALSE__$$';
|
||||||
|
case null:
|
||||||
|
return '$$__NULL__$$';
|
||||||
default:
|
default:
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.replaceAll('"$$__TRUE__$$"', 'True')
|
.replaceAll('"$$__TRUE__$$"', 'True')
|
||||||
.replaceAll('"$$__FALSE__$$"', 'False');
|
.replaceAll('"$$__FALSE__$$"', 'False')
|
||||||
|
.replaceAll('"$$__NULL__$$"', 'None');
|
||||||
}
|
}
|
||||||
|
|
||||||
return { body, code, headers };
|
return { body, code, headers };
|
||||||
|
|||||||
Reference in New Issue
Block a user