Whether the field should be marked as required in the generated JSON schema. (Note that this is irrelevant if the field is not present in the JSON schema.). Args: field: The schema for the field itself. total: Only applies to `TypedDictField`s.
(
self,
field: core_schema.ModelField | core_schema.DataclassField | core_schema.TypedDictField,
total: bool,
)
| 1765 | assert_never(self.mode) |
| 1766 | |
| 1767 | def field_is_required( |
| 1768 | self, |
| 1769 | field: core_schema.ModelField | core_schema.DataclassField | core_schema.TypedDictField, |
| 1770 | total: bool, |
| 1771 | ) -> bool: |
| 1772 | """Whether the field should be marked as required in the generated JSON schema. |
| 1773 | (Note that this is irrelevant if the field is not present in the JSON schema.). |
| 1774 | |
| 1775 | Args: |
| 1776 | field: The schema for the field itself. |
| 1777 | total: Only applies to `TypedDictField`s. |
| 1778 | Indicates if the `TypedDict` this field belongs to is total, in which case any fields that don't |
| 1779 | explicitly specify `required=False` are required. |
| 1780 | |
| 1781 | Returns: |
| 1782 | `True` if the field should be marked as required in the generated JSON schema, `False` otherwise. |
| 1783 | """ |
| 1784 | if field['type'] == 'typed-dict-field': |
| 1785 | required = field.get('required', total) |
| 1786 | else: |
| 1787 | required = field['schema']['type'] != 'default' |
| 1788 | |
| 1789 | if self.mode == 'serialization': |
| 1790 | has_exclude_if = field.get('serialization_exclude_if') is not None |
| 1791 | if self._config.json_schema_serialization_defaults_required: |
| 1792 | return not has_exclude_if |
| 1793 | else: |
| 1794 | return required and not has_exclude_if |
| 1795 | else: |
| 1796 | return required |
| 1797 | |
| 1798 | def dataclass_args_schema(self, schema: core_schema.DataclassArgsSchema) -> JsonSchemaValue: |
| 1799 | """Generates a JSON schema that matches a schema that defines a dataclass's constructor arguments. |
no test coverage detected