From ccce414825827615b9f18bbfe65d344d6f828257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 21 Feb 2026 09:21:27 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Add=20bytes=20JSON=20Schem?= =?UTF-8?q?a=20for=20base64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/_compat/v2.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fastapi/_compat/v2.py b/fastapi/_compat/v2.py index 6c3cf2af4c..777a22281f 100644 --- a/fastapi/_compat/v2.py +++ b/fastapi/_compat/v2.py @@ -44,6 +44,8 @@ evaluate_forwardref = eval_type_lenient class GenerateJsonSchema(_GenerateJsonSchema): def bytes_schema(self, schema: CoreSchema) -> JsonSchemaValue: json_schema = {"type": "string", "contentMediaType": "application/octet-stream"} + if self._config.ser_json_bytes == "base64": + json_schema["contentEncoding"] = "base64" self.update_with_validations(json_schema, schema, self.ValidationsMapping.bytes) return json_schema