]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
potato
authorMarcelo Trylesinski <marcelotryle@gmail.com>
Fri, 21 Jul 2023 13:44:14 +0000 (15:44 +0200)
committerMarcelo Trylesinski <marcelotryle@gmail.com>
Fri, 21 Jul 2023 13:49:24 +0000 (15:49 +0200)
fastapi/_compat.py

index a6d20270a130a65de7f85f12208a5183f1c5c6e5..a81394c00ef6e6fc9db6b4527594764566da03f6 100644 (file)
@@ -20,7 +20,9 @@ from typing import (
 from fastapi.exceptions import RequestErrorModel
 from fastapi.types import IncEx, ModelNameMap, UnionType
 from pydantic import BaseModel, create_model
+from pydantic.json_schema import JsonSchemaValue
 from pydantic.version import VERSION as PYDANTIC_VERSION
+from pydantic_core import core_schema
 from starlette.datastructures import UploadFile
 from typing_extensions import Annotated, Literal, get_args, get_origin
 
@@ -86,6 +88,12 @@ if PYDANTIC_V2:
                 return super().generate_inner(schema["schema"])
             return super().nullable_schema(schema)
 
+        def default_schema(self, schema: core_schema.WithDefaultSchema) -> JsonSchemaValue:
+            json_schema = super().default_schema(schema)
+            if self.skip_null_schema and json_schema.get("default", PydanticUndefined) is None:
+                json_schema.pop("default")
+            return json_schema
+
         def generate_definitions(
             self,
             inputs: Sequence[