Skip to content

Commit

Permalink
added regex validation and changed schema
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Sep 30, 2024
1 parent 6e76a35 commit 6ecc29e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
10 changes: 4 additions & 6 deletions event_model/documents/event_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Limits(TypedDict):
warning: NotRequired[Annotated[LimitsRange, Field(description="Warning limits.")]]
alarm: NotRequired[Annotated[LimitsRange, Field(description="Alarm limits.")]]


_ConstrainedDtype = Annotated[str, Field(description="A numpy dtype e.g `<U9` `<f16`" ,pattern="[|<>][tbiufcmMOSUV][0-9]+")]
class DataKey(TypedDict):
"""Describes the objects in the data property of Event documents"""

Expand All @@ -47,14 +47,12 @@ class DataKey(TypedDict):
dtype_numpy: NotRequired[
Annotated[
Union[
str, # e.g. "<u4",
List[Tuple[str, str]], # e.g. [("a", "<u4"), ("b", "<f8")]
_ConstrainedDtype,
List[Tuple[str, _ConstrainedDtype]],
],
Field(
description="The type of the data in the event, given as a numpy dtype string (or, for structured dtypes, array)",
pattern="[|<>][tbiufcmMOSUV][0-9]+",
description="The type of the data in the event, given as a numpy dtype string (or, for structured dtypes, array).",
),
# TODO Enforce the regex pattern.
]
]
external: NotRequired[
Expand Down
31 changes: 30 additions & 1 deletion event_model/schemas/event_descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
"dtype": {
"title": "Dtype",
"description": "The type of the data in the event.",
"description": "The type of the data in the event, given as a broad JSON schema type.",
"type": "string",
"enum": [
"string",
Expand All @@ -60,6 +60,35 @@
"integer"
]
},
"dtype_numpy": {
"title": "Dtype Numpy",
"description": "The type of the data in the event, given as a numpy dtype string (or, for structured dtypes, array).",
"anyOf": [
{
"description": "A numpy dtype e.g `<U9` `<f16`",
"pattern": "[|<>][tbiufcmMOSUV][0-9]+",
"type": "string"
},
{
"items": {
"maxItems": 2,
"minItems": 2,
"prefixItems": [
{
"type": "string"
},
{
"description": "A numpy dtype e.g `<U9` `<f16`",
"pattern": "[|<>][tbiufcmMOSUV][0-9]+",
"type": "string"
}
],
"type": "array"
},
"type": "array"
}
]
},
"external": {
"title": "External",
"description": "Where the data is stored if it is stored external to the events",
Expand Down

0 comments on commit 6ecc29e

Please sign in to comment.