Serialize an object to UTF-8 encoded JSON bytes. Extends the standard json.dumps with support for additional types commonly used in the SDK, such as `datetime`, `pydantic.BaseModel`, etc.
(obj: Any)
| 9 | |
| 10 | |
| 11 | def openapi_dumps(obj: Any) -> bytes: |
| 12 | """ |
| 13 | Serialize an object to UTF-8 encoded JSON bytes. |
| 14 | |
| 15 | Extends the standard json.dumps with support for additional types |
| 16 | commonly used in the SDK, such as `datetime`, `pydantic.BaseModel`, etc. |
| 17 | """ |
| 18 | return json.dumps( |
| 19 | obj, |
| 20 | cls=_CustomEncoder, |
| 21 | # Uses the same defaults as httpx's JSON serialization |
| 22 | ensure_ascii=False, |
| 23 | separators=(",", ":"), |
| 24 | allow_nan=False, |
| 25 | ).encode() |
| 26 | |
| 27 | |
| 28 | class _CustomEncoder(json.JSONEncoder): |
no outgoing calls