MCPcopy
hub / github.com/pydantic/pydantic / generate_schema

Method generate_schema

pydantic/_internal/_generate_schema.py:717–754  ·  view source on GitHub ↗

Generate core schema. Args: obj: The object to generate core schema for. Returns: The generated core schema. Raises: PydanticUndefinedAnnotation: If it is not possible to evaluate forward reference. PydanticSc

(
        self,
        obj: Any,
    )

Source from the content-addressed store, hash-verified

715 metadata_schema['metadata'] = metadata
716
717 def generate_schema(
718 self,
719 obj: Any,
720 ) -> core_schema.CoreSchema:
721 """Generate core schema.
722
723 Args:
724 obj: The object to generate core schema for.
725
726 Returns:
727 The generated core schema.
728
729 Raises:
730 PydanticUndefinedAnnotation:
731 If it is not possible to evaluate forward reference.
732 PydanticSchemaGenerationError:
733 If it is not possible to generate pydantic-core schema.
734 TypeError:
735 - If `alias_generator` returns a disallowed type (must be str, AliasPath or AliasChoices).
736 - If V1 style validator with `each_item=True` applied on a wrong field.
737 PydanticUserError:
738 - If `typing.TypedDict` is used instead of `typing_extensions.TypedDict` on Python < 3.12.
739 - If `__modify_schema__` method is used instead of `__get_pydantic_json_schema__`.
740 """
741 schema = self._generate_schema_from_get_schema_method(obj, obj)
742
743 if schema is None:
744 schema = self._generate_schema_inner(obj)
745
746 metadata_js_function = _extract_get_pydantic_json_schema(obj)
747 if metadata_js_function is not None:
748 metadata_schema = resolve_original_schema(schema, self.defs)
749 if metadata_schema:
750 self._add_js_function(metadata_schema, metadata_js_function)
751
752 schema = _add_custom_serialization_from_json_encoders(self._config_wrapper.json_encoders, obj, schema)
753
754 return schema
755
756 def _model_schema(self, cls: type[BaseModel]) -> core_schema.CoreSchema:
757 """Generate schema for a Pydantic model."""

Callers 15

_init_core_attrsMethod · 0.95
complete_model_classFunction · 0.95
complete_dataclassFunction · 0.95
_list_schemaMethod · 0.95
_dict_schemaMethod · 0.95
_set_schemaMethod · 0.95
_frozenset_schemaMethod · 0.95
_deque_schemaMethod · 0.95
_mapping_schemaMethod · 0.95
_model_schemaMethod · 0.95
match_typeMethod · 0.95

Tested by 2