88from __future__ import annotations
99
1010from numbers import Real
11- from typing import Union , Any
11+ from typing import Union , Any , Literal
1212
1313from pydantic import BaseModel , Field , field_validator , SerializeAsAny
1414
@@ -41,14 +41,14 @@ class AnyComponentSchema(BaseModel):
4141
4242
4343class DataRecordSchema (AnyComponentSchema ):
44- type : str = "DataRecord"
44+ type : Literal [ "DataRecord" ] = "DataRecord"
4545 fields : SerializeAsAny [list [AnyComponentSchema ]] = Field (...)
4646
4747
4848class VectorSchema (AnyComponentSchema ):
4949 label : str = Field (...)
5050 name : str = Field (...)
51- type : str = "Vector"
51+ type : Literal [ "Vector" ] = "Vector"
5252 definition : str = Field (...)
5353 reference_frame : str = Field (..., serialization_alias = 'referenceFrame' )
5454 local_frame : str = Field (None , serialization_alias = 'localFrame' )
@@ -57,7 +57,7 @@ class VectorSchema(AnyComponentSchema):
5757
5858
5959class DataArraySchema (AnyComponentSchema ):
60- type : str = "DataArray"
60+ type : Literal [ "DataArray" ] = "DataArray"
6161 name : str = Field (...)
6262 element_count : dict | str | CountSchema = Field (..., serialization_alias = 'elementCount' ) # Should type of Count
6363 element_type : SerializeAsAny [AnyComponentSchema ] = Field (..., serialization_alias = 'elementType' )
@@ -66,7 +66,7 @@ class DataArraySchema(AnyComponentSchema):
6666
6767
6868class MatrixSchema (AnyComponentSchema ):
69- type : str = "Matrix"
69+ type : Literal [ "Matrix" ] = "Matrix"
7070 element_count : dict | str | CountSchema = Field (..., serialization_alias = 'elementCount' ) # Should be type of Count
7171 element_type : SerializeAsAny [list [AnyComponentSchema ]] = Field (..., serialization_alias = 'elementType' )
7272 encoding : str = Field (...) # TODO: implement an encodings class
@@ -76,7 +76,7 @@ class MatrixSchema(AnyComponentSchema):
7676
7777
7878class DataChoiceSchema (AnyComponentSchema ):
79- type : str = "DataChoice"
79+ type : Literal [ "DataChoice" ] = "DataChoice"
8080 updatable : bool = Field (False )
8181 optional : bool = Field (False )
8282 choice_value : CategorySchema = Field (..., serialization_alias = 'choiceValue' ) # TODO: Might be called "choiceValues"
@@ -85,7 +85,7 @@ class DataChoiceSchema(AnyComponentSchema):
8585
8686class GeometrySchema (AnyComponentSchema ):
8787 label : str = Field (...)
88- type : str = "Geometry"
88+ type : Literal [ "Geometry" ] = "Geometry"
8989 updatable : bool = Field (False )
9090 optional : bool = Field (False )
9191 definition : str = Field (...)
@@ -129,17 +129,17 @@ class AnyScalarComponentSchema(AnySimpleComponentSchema):
129129
130130
131131class BooleanSchema (AnyScalarComponentSchema ):
132- type : str = "Boolean"
132+ type : Literal [ "Boolean" ] = "Boolean"
133133 value : bool = Field (None )
134134
135135
136136class CountSchema (AnyScalarComponentSchema ):
137- type : str = "Count"
137+ type : Literal [ "Count" ] = "Count"
138138 value : int = Field (None )
139139
140140
141141class QuantitySchema (AnyScalarComponentSchema ):
142- type : str = "Quantity"
142+ type : Literal [ "Quantity" ] = "Quantity"
143143 value : Union [float , str ] = Field (None )
144144 uom : Union [UCUMCode , URI ] = Field (...)
145145
@@ -163,45 +163,45 @@ def validate_value(cls, v):
163163
164164
165165class TimeSchema (AnyScalarComponentSchema ):
166- type : str = "Time"
166+ type : Literal [ "Time" ] = "Time"
167167 value : str = Field (None )
168168 reference_time : str = Field (None , serialization_alias = 'referenceTime' )
169169 local_frame : str = Field (None )
170170 uom : Union [UCUMCode , URI ] = Field (...)
171171
172172
173173class CategorySchema (AnyScalarComponentSchema ):
174- type : str = "Category"
174+ type : Literal [ "Category" ] = "Category"
175175 value : str = Field (None )
176176 code_space : str = Field (None , serialization_alias = 'codeSpace' )
177177
178178
179179class TextSchema (AnyScalarComponentSchema ):
180- type : str = "Text"
180+ type : Literal [ "Text" ] = "Text"
181181 value : str = Field (None )
182182
183183
184184class CountRangeSchema (AnySimpleComponentSchema ):
185- type : str = "CountRange"
185+ type : Literal [ "CountRange" ] = "CountRange"
186186 value : list [int ] = Field (None )
187187 uom : Union [UCUMCode , URI ] = Field (...)
188188
189189
190190class QuantityRangeSchema (AnySimpleComponentSchema ):
191- type : str = "QuantityRange"
191+ type : Literal [ "QuantityRange" ] = "QuantityRange"
192192 value : list [Union [float , str ]] = Field (None )
193193 uom : Union [UCUMCode , URI ] = Field (...)
194194
195195
196196class TimeRangeSchema (AnySimpleComponentSchema ):
197- type : str = "TimeRange"
197+ type : Literal [ "TimeRange" ] = "TimeRange"
198198 value : list [str ] = Field (None )
199199 reference_time : str = Field (None , serialization_alias = 'referenceTime' )
200200 local_frame : str = Field (None )
201201 uom : Union [UCUMCode , URI ] = Field (...)
202202
203203
204204class CategoryRangeSchema (AnySimpleComponentSchema ):
205- type : str = "CategoryRange"
205+ type : Literal [ "CategoryRange" ] = "CategoryRange"
206206 value : list [str ] = Field (None )
207207 code_space : str = Field (None , serialization_alias = 'codeSpace' )
0 commit comments