MCPcopy
hub / github.com/pydantic/pydantic / model_process_schema

Function model_process_schema

pydantic/v1/schema.py:551–598  ·  view source on GitHub ↗

Used by ``model_schema()``, you probably should be using that function. Take a single ``model`` and generate its schema. Also return additional schema definitions, from sub-models. The sub-models of the returned schema will be referenced, but their definitions will not be included in t

(
    model: TypeModelOrEnum,
    *,
    by_alias: bool = True,
    model_name_map: Dict[TypeModelOrEnum, str],
    ref_prefix: Optional[str] = None,
    ref_template: str = default_ref_template,
    known_models: Optional[TypeModelSet] = None,
    field: Optional[ModelField] = None,
)

Source from the content-addressed store, hash-verified

549
550
551def model_process_schema(
552 model: TypeModelOrEnum,
553 *,
554 by_alias: bool = True,
555 model_name_map: Dict[TypeModelOrEnum, str],
556 ref_prefix: Optional[str] = None,
557 ref_template: str = default_ref_template,
558 known_models: Optional[TypeModelSet] = None,
559 field: Optional[ModelField] = None,
560) -> Tuple[Dict[str, Any], Dict[str, Any], Set[str]]:
561 """
562 Used by ``model_schema()``, you probably should be using that function.
563
564 Take a single ``model`` and generate its schema. Also return additional schema definitions, from sub-models. The
565 sub-models of the returned schema will be referenced, but their definitions will not be included in the schema. All
566 the definitions are returned as the second value.
567 """
568 from inspect import getdoc, signature
569
570 known_models = known_models or set()
571 if lenient_issubclass(model, Enum):
572 model = cast(Type[Enum], model)
573 s = enum_process_schema(model, field=field)
574 return s, {}, set()
575 model = cast(Type['BaseModel'], model)
576 s = {'title': model.__config__.title or model.__name__}
577 doc = getdoc(model)
578 if doc:
579 s['description'] = doc
580 known_models.add(model)
581 m_schema, m_definitions, nested_models = model_type_schema(
582 model,
583 by_alias=by_alias,
584 model_name_map=model_name_map,
585 ref_prefix=ref_prefix,
586 ref_template=ref_template,
587 known_models=known_models,
588 )
589 s.update(m_schema)
590 schema_extra = model.__config__.schema_extra
591 if callable(schema_extra):
592 if len(signature(schema_extra).parameters) == 1:
593 schema_extra(s)
594 else:
595 schema_extra(s, model)
596 else:
597 s.update(schema_extra)
598 return s, m_definitions, nested_models
599
600
601def model_type_schema(

Callers 3

schemaFunction · 0.85
model_schemaFunction · 0.85
field_singleton_schemaFunction · 0.85

Calls 4

lenient_issubclassFunction · 0.90
enum_process_schemaFunction · 0.85
model_type_schemaFunction · 0.85
updateMethod · 0.45

Tested by

no test coverage detected