decorators
make_mandatory ¶
make_mandatory(*names: str)
Make a field inherited from a base class mandatory if it is optional.
The field must exist in a base class and must not be defined in the decorated class.
Use this decorator instead of manually declaring an annotation, if all you need to do is making an existing field mandatory.
Source code in src/metador_core/schema/decorators.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
add_const_fields ¶
add_const_fields(
consts: Dict[str, Any], *, override: bool = False
)
Add constant fields to pydantic models.
Must be passed a dict of field names and the constant values (only JSON-like types).
Constant fields are optional during input.
If present during parsing, they are be ignored and overriden with the constant.
Constant fields are included in serialization, unless exclude_defaults
is set.
This can be used e.g. to attach JSON-LD annotations to schemas.
Constant fields are inherited and may only be overridden by other constant fields using this decorator, they cannot become normal fields again.
Source code in src/metador_core/schema/decorators.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
override ¶
override(*names: str)
Declare fields that are overridden (and not valid as subtypes).
These are checked during plugin loading, in order to catch accidental overridden fields in schemas.
Source code in src/metador_core/schema/decorators.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|