Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -364,6 +371,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -378,6 +392,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -392,6 +413,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -406,6 +434,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -420,6 +455,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -415,6 +422,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -429,6 +443,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -443,6 +464,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -457,6 +485,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -471,6 +506,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -487,6 +529,13 @@
}
},
"then": {
"properties": {
"parent_division_id": {
"not": {
"type": "null"
}
}
},
"required": [
"parent_division_id"
]
Expand All @@ -502,6 +551,13 @@
},
"then": {
"not": {
"properties": {
"parent_division_id": {
"not": {
"type": "null"
}
}
},
"required": [
"parent_division_id"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -245,6 +252,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -259,6 +273,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -273,6 +294,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -287,6 +315,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -301,6 +336,13 @@
}
},
"then": {
"properties": {
"admin_level": {
"not": {
"type": "null"
}
}
},
"required": [
"admin_level"
]
Expand All @@ -317,6 +359,13 @@
}
},
"then": {
"properties": {
"country": {
"not": {
"type": "null"
}
}
},
"required": [
"country"
]
Expand All @@ -332,6 +381,13 @@
},
"then": {
"not": {
"properties": {
"country": {
"not": {
"type": "null"
}
}
},
"required": [
"country"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,19 @@
MyModel(foo=42, bar=None)
>>> MyModel(bar="hello") # validates OK
MyModel(foo=None, bar='hello')
>>> MyModel(foo=None, bar=None) # validates OK because foo and bar are explicitly set to `None`
MyModel(foo=None, bar=None)
>>>
>>> try:
... MyModel()
... except ValidationError as e:
... assert "at least one of these fields must be explicitly set, but none are: foo, bar" in str(e)
... print("Validation failed")
Validation failed
... assert "at least one of these fields must be set to a value other than None, but none are: foo, bar" in str(e)
... print("Validation failed (no fields set)")
Validation failed (no fields set)
>>> try:
... MyModel(foo=None, bar=None)
... except ValidationError as e:
... assert "at least one of these fields must be set to a value other than None, but none are: foo, bar" in str(e)
... print("Validation failed (all fields None)")
Validation failed (all fields None)

Describe a foreign key relationship between two models where one model has a field that contains the
unique identifier of another model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,30 @@ def try_move(key: str, src: JsonSchemaValue, dst: JsonSchemaValue) -> None:
pass


def required_non_null(aliases: list[str]) -> JsonSchemaValue:
"""
Build a JSON Schema requiring listed properties to be present and non-null.

Combines `"required"` (property must exist) with a per-property
constraint `{"not": {"type": "null"}}` (value must not be null).

Parameters
----------
aliases : list[str]
Non-empty list of JSON Schema property names to constrain

Returns
-------
JsonSchemaValue
Schema requiring each property to be present and non-null
"""
_verify_operands_not_empty(str, aliases)
return {
"required": aliases,
"properties": {a: {"not": {"type": "null"}} for a in aliases},
}


T = TypeVar("T", JsonSchemaValue, str)


Expand Down
Loading