@@ -840,8 +840,17 @@ def _model_schema(self, cls: type[BaseModel]) -> core_schema.CoreSchema:
840840 generic_origin : type [BaseModel ] | None = getattr (cls , '__pydantic_generic_metadata__' , {}).get ('origin' )
841841
842842 if cls .__pydantic_root_model__ :
843- # FIXME: should the common field metadata be used here?
844- inner_schema , _ = self ._common_field_schema ('root' , fields ['root' ], decorators )
843+ inner_schema , metadata = self ._common_field_schema ('root' , fields ['root' ], decorators )
844+ if cls .__doc__ and metadata .get ('pydantic_js_updates' , {}).get ('description' ):
845+ # This is a bit of a leaky abstraction, but as the model docstring takes priority
846+ # over the root field's description, we need to override it here. This can't be done
847+ # in the JSON Schema generation logic because the metadata's `pydantic_js_updates` are
848+ # applied last, and overrides any value previously set (so the description set from the
849+ # docstring in `GenerateJsonSchema._update_class_schema()` is overridden):
850+ update_core_metadata (
851+ metadata , pydantic_js_updates = {'description' : inspect .cleandoc (cls .__doc__ )}
852+ )
853+
845854 inner_schema = apply_model_validators (inner_schema , model_validators , 'inner' )
846855 model_schema = core_schema .model_schema (
847856 cls ,
@@ -852,6 +861,7 @@ def _model_schema(self, cls: type[BaseModel]) -> core_schema.CoreSchema:
852861 post_init = getattr (cls , '__pydantic_post_init__' , None ),
853862 config = core_config ,
854863 ref = model_ref ,
864+ metadata = metadata ,
855865 )
856866 else :
857867 fields_schema : core_schema .CoreSchema = core_schema .model_fields_schema (
0 commit comments