11from __future__ import annotations
22
33from numbers import Real
4- from typing import Union
4+ from typing import Union , Any
55
6- from pydantic import BaseModel , Field , field_validator
6+ from pydantic import BaseModel , Field , field_validator , SerializeAsAny
77
88from conSys import GeometryTypes
99from conSys .datamodels .api_utils import UCUMCode , URI
10+ from conSys .datamodels .geometry import Geometry
1011
1112"""
1213 NOTE: The following classes are used to represent the Record Schemas that are required for use with Datastreams
2324
2425
2526class AnyComponentSchema (BaseModel ):
27+ type : str = Field (...)
2628 id : str = Field (None )
2729 label : str = Field (None )
2830 description : str = Field (None )
29- type : str = Field (...)
3031 updatable : bool = Field (False )
3132 optional : bool = Field (False )
3233 definition : str = Field (None )
3334
3435
3536class DataRecordSchema (AnyComponentSchema ):
3637 type : str = "DataRecord"
37- fields : list [AnyComponentSchema ] = Field (...)
38+ fields : SerializeAsAny [ list [AnyComponentSchema ] ] = Field (...)
3839
3940
4041class VectorSchema (AnyComponentSchema ):
@@ -44,21 +45,21 @@ class VectorSchema(AnyComponentSchema):
4445 reference_frame : str = Field (...)
4546 local_frame : str = Field (None )
4647 # TODO: VERIFY might need to be moved further down when these are defined
47- coordinates : Union [list [CountSchema ], list [QuantitySchema ], list [TimeSchema ]] = Field (...)
48+ coordinates : SerializeAsAny [ Union [list [CountSchema ], list [QuantitySchema ], list [TimeSchema ] ]] = Field (...)
4849
4950
5051class DataArraySchema (AnyComponentSchema ):
5152 type : str = "DataArray"
5253 element_count : int = Field (..., serialization_alias = 'elementCount' ) # Should type of Count
53- element_type : list [AnyComponentSchema ] = Field (..., serialization_alias = 'elementType' )
54+ element_type : SerializeAsAny [ list [AnyComponentSchema ] ] = Field (..., serialization_alias = 'elementType' )
5455 encoding : str = Field (...) # TODO: implement an encodings class
5556 values : list = Field (None )
5657
5758
5859class MatrixSchema (AnyComponentSchema ):
5960 type : str = "Matrix"
6061 element_count : int = Field (..., serialization_alias = 'elementCount' ) # Should be type of Count
61- element_type : list [AnyComponentSchema ] = Field (..., serialization_alias = 'elementType' )
62+ element_type : SerializeAsAny [ list [AnyComponentSchema ] ] = Field (..., serialization_alias = 'elementType' )
6263 encoding : str = Field (...) # TODO: implement an encodings class
6364 values : list = Field (None )
6465 reference_frame : str = Field (None )
@@ -70,7 +71,7 @@ class DataChoiceSchema(AnyComponentSchema):
7071 updatable : bool = Field (False )
7172 optional : bool = Field (False )
7273 choice_value : CategorySchema = Field (..., serialization_alias = 'choiceValue' ) # TODO: Might be called "choiceValues"
73- items : list [AnyComponentSchema ] = Field (...)
74+ items : SerializeAsAny [ list [AnyComponentSchema ] ] = Field (...)
7475
7576
7677class GeometrySchema (AnyComponentSchema ):
@@ -85,23 +86,23 @@ class GeometrySchema(AnyComponentSchema):
8586 GeometryTypes .MULTI_POLYGON .value ]}
8687 nil_values : list = Field (None , serialization_alias = 'nilValues' )
8788 srs : str = Field (...)
88- value = Field (None )
89+ value : Geometry = Field (None )
8990
9091
9192class AnySimpleComponentSchema (AnyComponentSchema ):
9293 label : str = Field (...)
93- description = Field (None )
94+ description : str = Field (None )
9495 type : str = Field (...)
95- updatable = Field (False )
96- optional = Field (False )
96+ updatable : bool = Field (False )
97+ optional : bool = Field (False )
9798 definition : str = Field (...)
9899 reference_frame : str = Field (None , serialization_alias = 'referenceFrame' )
99100 axis_id : str = Field (None , serialization_alias = 'axisID' )
100101 quality : Union [list [QuantitySchema ], list [QuantityRangeSchema ], list [CategorySchema ], list [TextSchema ]] = Field (
101102 None ) # TODO: Union[Quantity, QuantityRange, Category, Text]
102103 nil_values : list = Field (None , serialization_alias = 'nilValues' )
103- constraint = Field (None )
104- value = Field (None )
104+ constraint : Any = Field (None )
105+ value : Any = Field (None )
105106
106107
107108class AnyScalarComponentSchema (AnySimpleComponentSchema ):
@@ -123,7 +124,7 @@ class CountSchema(AnyScalarComponentSchema):
123124
124125class QuantitySchema (AnyScalarComponentSchema ):
125126 type : str = "Quantity"
126- value : Union [Real , str ] = Field (None )
127+ value : Union [float , str ] = Field (None )
127128 uom : Union [UCUMCode , URI ] = Field (...)
128129
129130 @field_validator ('value' )
@@ -172,7 +173,7 @@ class CountRangeSchema(AnySimpleComponentSchema):
172173
173174class QuantityRangeSchema (AnySimpleComponentSchema ):
174175 type : str = "QuantityRange"
175- value : list [Union [Real , str ]] = Field (None )
176+ value : list [Union [float , str ]] = Field (None )
176177 uom : Union [UCUMCode , URI ] = Field (...)
177178
178179
0 commit comments