Generates a JSON schema that matches a schema that defines a model. Args: schema: The core schema. Returns: The generated JSON schema.
(self, schema: core_schema.ModelSchema)
| 1602 | return self.generate_inner(schema['return_schema']) |
| 1603 | |
| 1604 | def model_schema(self, schema: core_schema.ModelSchema) -> JsonSchemaValue: |
| 1605 | """Generates a JSON schema that matches a schema that defines a model. |
| 1606 | |
| 1607 | Args: |
| 1608 | schema: The core schema. |
| 1609 | |
| 1610 | Returns: |
| 1611 | The generated JSON schema. |
| 1612 | """ |
| 1613 | # We do not use schema['model'].model_json_schema() here |
| 1614 | # because it could lead to inconsistent refs handling, etc. |
| 1615 | cls = cast('type[BaseModel]', schema['cls']) |
| 1616 | config = cls.model_config |
| 1617 | |
| 1618 | with self._config_wrapper_stack.push(config): |
| 1619 | json_schema = self.generate_inner(schema['schema']) |
| 1620 | |
| 1621 | self._update_class_schema(json_schema, cls, config) |
| 1622 | |
| 1623 | return json_schema |
| 1624 | |
| 1625 | def _update_class_schema(self, json_schema: JsonSchemaValue, cls: type[Any], config: ConfigDict) -> None: |
| 1626 | """Update json_schema with the following, extracted from `config` and `cls`: |