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,
)
| 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.""" |