https://github.com/geopython/pygeoapi/pull/1353

Index: pygeoapi/models/cql.py
--- pygeoapi/models/cql.py.orig
+++ pygeoapi/models/cql.py
@@ -33,13 +33,14 @@
 # =================================================================
 
 from datetime import date, datetime
-from typing import Any, List, Literal, Optional, Union
+from typing import Any, List, Optional, Union
+from typing_extensions import Literal
 
-from pydantic import BaseModel, Field
+from pydantic import BaseModel, Field, RootModel
 
 
-class CQLModel(BaseModel):
-    __root__: 'Union[\n        ComparisonPredicate,\n        SpatialPredicate,\n        TemporalPredicate,\n        AndExpression\n    ]'
+class CQLModel(RootModel):
+    root: 'Union[\n        ComparisonPredicate,\n        SpatialPredicate,\n        TemporalPredicate,\n        AndExpression\n    ]'
 
 
 class AndExpression(BaseModel):
@@ -58,16 +59,16 @@ class PropertyRef(BaseModel):
     property: 'Optional[str]' = None
 
 
-class ScalarLiteral(BaseModel):
-    __root__: 'Union[str, float, bool]'
+class ScalarLiteral(RootModel):
+    root: 'Union[str, float, bool]'
 
 
-class Bbox(BaseModel):
-    __root__: 'List[float]'
+class Bbox(RootModel):
+    root: 'List[float]'
 
 
-class LinestringCoordinate(BaseModel):
-    __root__: 'List[Any]'
+class LinestringCoordinate(RootModel):
+    root: 'List[Any]'
 
 
 class Linestring(BaseModel):
@@ -76,8 +77,8 @@ class Linestring(BaseModel):
     bbox: 'Optional[List[float]]' = Field(None)
 
 
-class MultilineStringCoordinate(BaseModel):
-    __root__: 'List[Any]'
+class MultilineStringCoordinate(RootModel):
+    root: 'List[Any]'
 
 
 class Multilinestring(BaseModel):
@@ -92,8 +93,8 @@ class Multipoint(BaseModel):
     bbox: 'Optional[List[float]]' = Field(None)
 
 
-class MultipolygonCoordinateItem(BaseModel):
-    __root__: 'List[Any]'
+class MultipolygonCoordinateItem(RootModel):
+    root: 'List[Any]'
 
 
 class Multipolygon(BaseModel):
@@ -108,8 +109,8 @@ class Point(BaseModel):
     bbox: 'Optional[List[float]]' = Field(None)
 
 
-class PolygonCoordinatesItem(BaseModel):
-    __root__: 'List[Any]'
+class PolygonCoordinatesItem(RootModel):
+    root: 'List[Any]'
 
 
 class Polygon(BaseModel):
@@ -118,56 +119,56 @@ class Polygon(BaseModel):
     bbox: 'Optional[List[float]]' = Field(None)
 
 
-class TimeString(BaseModel):
-    __root__: 'Union[date, datetime]'
+class TimeString(RootModel):
+    root: 'Union[date, datetime]'
 
 
 class EnvelopeLiteral(BaseModel):
     bbox: 'Bbox'
 
 
-class GeometryLiteral(BaseModel):
-    __root__: 'Union[\n        Point,\n        Linestring,\n        Polygon,\n        Multipoint,\n        Multilinestring,\n        Multipolygon\n    ]'
+class GeometryLiteral(RootModel):
+    root: 'Union[\n        Point, Linestring, Polygon, Multipoint, Multilinestring, Multipolygon\n    ]'
 
 
 class TypedTimeString(BaseModel):
     datetime: 'TimeString'
 
 
-class PeriodString(BaseModel):
-    __root__: 'List[Union[TimeString, str]]' = Field(...)
+class PeriodString(RootModel):
+    root: 'List[Union[TimeString, str]]' = Field(...)
 
 
-class SpatialLiteral(BaseModel):
-    __root__: 'Union[GeometryLiteral, EnvelopeLiteral]'
+class SpatialLiteral(RootModel):
+    root: 'Union[GeometryLiteral, EnvelopeLiteral]'
 
 
-class TemporalLiteral(BaseModel):
-    __root__: 'Union[TimeString, PeriodString]'
+class TemporalLiteral(RootModel):
+    root: 'Union[TimeString, PeriodString]'
 
 
 class TypedPeriodString(BaseModel):
     datetime: 'PeriodString'
 
 
-class TypedTemporalLiteral(BaseModel):
-    __root__: 'Union[TypedTimeString, TypedPeriodString]'
+class TypedTemporalLiteral(RootModel):
+    root: 'Union[TypedTimeString, TypedPeriodString]'
 
 
-class ArrayPredicate(BaseModel):
-    __root__: 'Union[\n        AequalsExpression,\n        AcontainsExpression,\n        AcontainedByExpression,\n        AoverlapsExpression,\n    ]'
+class ArrayPredicate(RootModel):
+    root: 'Union[\n        AequalsExpression,\n        AcontainsExpression,\n        AcontainedByExpression,\n        AoverlapsExpression,\n    ]'
 
 
-class ComparisonPredicate(BaseModel):
-    __root__: 'Union[\n        BinaryComparisonPredicate,\n        IsLikePredicate,\n        IsBetweenPredicate,\n        IsInListPredicate,\n        IsNullPredicate,\n    ]'
+class ComparisonPredicate(RootModel):
+    root: 'Union[\n        BinaryComparisonPredicate,\n        IsLikePredicate,\n        IsBetweenPredicate,\n        IsInListPredicate,\n        IsNullPredicate,\n    ]'
 
 
-class SpatialPredicate(BaseModel):
-    __root__: 'Union[\n        IntersectsExpression,\n        EqualsExpression,\n        DisjointExpression,\n        TouchesExpression,\n        WithinExpression,\n        OverlapsExpression,\n        CrossesExpression,\n        ContainsExpression,\n    ]'
+class SpatialPredicate(RootModel):
+    root: 'Union[\n        IntersectsExpression,\n        EqualsExpression,\n        DisjointExpression,\n        TouchesExpression,\n        WithinExpression,\n        OverlapsExpression,\n        CrossesExpression,\n        ContainsExpression,\n    ]'
 
 
-class TemporalPredicate(BaseModel):
-    __root__: 'Union[\n        BeforeExpression,\n        AfterExpression,\n        MeetsExpression,\n        MetbyExpression,\n        ToverlapsExpression,\n        OverlappedbyExpression,\n        BeginsExpression,\n        BegunbyExpression,\n        DuringExpression,\n        TcontainsExpression,\n        EndsExpression,\n        EndedbyExpression,\n        TequalsExpression,\n        AnyinteractsExpression,\n    ]'
+class TemporalPredicate(RootModel):
+    root: 'Union[\n        BeforeExpression,\n        AfterExpression,\n        MeetsExpression,\n        MetbyExpression,\n        ToverlapsExpression,\n        OverlappedbyExpression,\n        BeginsExpression,\n        BegunbyExpression,\n        DuringExpression,\n        TcontainsExpression,\n        EndsExpression,\n        EndedbyExpression,\n        TequalsExpression,\n        AnyinteractsExpression,\n    ]'
 
 
 class AcontainedByExpression(BaseModel):
@@ -206,8 +207,8 @@ class BegunbyExpression(BaseModel):
     begunby: 'TemporalOperands'
 
 
-class BinaryComparisonPredicate(BaseModel):
-    __root__: 'Union[\n        EqExpression, LtExpression, GtExpression, LteExpression, GteExpression\n    ]'
+class BinaryComparisonPredicate(RootModel):
+    root: 'Union[\n        EqExpression, LtExpression, GtExpression, LteExpression, GteExpression\n    ]'
 
 
 class ContainsExpression(BaseModel):
@@ -244,8 +245,8 @@ class IntersectsExpression(BaseModel):
 
 class Between(BaseModel):
     value: 'ValueExpression'
-    lower: 'ScalarExpression' = Field(None)
-    upper: 'ScalarExpression' = Field(None)
+    lower: 'Optional[ScalarExpression]' = Field(None)
+    upper: 'Optional[ScalarExpression]' = Field(None)
 
 
 class IsBetweenPredicate(BaseModel):
@@ -310,8 +311,8 @@ class WithinExpression(BaseModel):
     within: 'SpatialOperands'
 
 
-class ArrayExpression(BaseModel):
-    __root__: 'List[Union[PropertyRef, FunctionRef, ArrayLiteral]]' = Field(
+class ArrayExpression(RootModel):
+    root: 'List[Union[PropertyRef, FunctionRef, ArrayLiteral]]' = Field(
         ...  # , max_items=2, min_items=2
     )
 
@@ -336,45 +337,45 @@ class LteExpression(BaseModel):
     lte: 'ScalarOperands'
 
 
-class ScalarExpression(BaseModel):
-    __root__: 'Union[ScalarLiteral,\n        PropertyRef,\n        FunctionRef,\n        ArithmeticExpression]'
+class ScalarExpression(RootModel):
+    root: 'Union[ScalarLiteral, PropertyRef,\n                    FunctionRef, ArithmeticExpression]'
 
 
-class ScalarOperands(BaseModel):
-    __root__: 'List[ScalarExpression]' = Field(...)
+class ScalarOperands(RootModel):
+    root: 'List[ScalarExpression]' = Field(...)
 
 
-class SpatialOperands(BaseModel):
-    __root__: 'List[GeomExpression]' = Field(...)
+class SpatialOperands(RootModel):
+    root: 'List[GeomExpression]' = Field(...)
 
 
-class TemporalOperands(BaseModel):
-    __root__: 'List[TemporalExpression]' = Field(...)
+class TemporalOperands(RootModel):
+    root: 'List[TemporalExpression]' = Field(...)
     # , max_items=2, min_items=2)
 
 
-class ValueExpression(BaseModel):
-    __root__: 'Union[ScalarExpression, SpatialLiteral, TypedTemporalLiteral]'
+class ValueExpression(RootModel):
+    root: 'Union[ScalarExpression, SpatialLiteral, TypedTemporalLiteral]'
 
 
-class ArithmeticExpression(BaseModel):
-    __root__: 'Union[AddExpression, SubExpression, MulExpression, DivExpression]'
+class ArithmeticExpression(RootModel):
+    root: 'Union[AddExpression, SubExpression, MulExpression, DivExpression]'
 
 
-class ArrayLiteral(BaseModel):
-    __root__: 'List[\n        Union[\n            ScalarLiteral,\n            SpatialLiteral,\n            TypedTemporalLiteral,\n            PropertyRef,\n            FunctionRef,\n            ArithmeticExpression,\n            ArrayLiteral,\n        ]\n    ]'
+class ArrayLiteral(RootModel):
+    root: 'List[\n        Union[\n            ScalarLiteral,\n            SpatialLiteral,\n            TypedTemporalLiteral,\n            PropertyRef,\n            FunctionRef,\n            ArithmeticExpression,\n            ArrayLiteral,\n        ]\n    ]'
 
 
 class FunctionRef(BaseModel):
     function: 'Function'
 
 
-class GeomExpression(BaseModel):
-    __root__: 'Union[SpatialLiteral, PropertyRef, FunctionRef]'
+class GeomExpression(RootModel):
+    root: 'Union[SpatialLiteral, PropertyRef, FunctionRef]'
 
 
-class TemporalExpression(BaseModel):
-    __root__: 'Union[TemporalLiteral, PropertyRef, FunctionRef]'
+class TemporalExpression(RootModel):
+    root: 'Union[TemporalLiteral, PropertyRef, FunctionRef]'
 
 
 # here
@@ -384,7 +385,7 @@ class AddExpression(BaseModel):
 
 # here
 class DivExpression(BaseModel):
-    div_: 'ArithmeticOperands' = Field(None, alias='/')
+    div_: 'Optional[ArithmeticOperands]' = Field(None, alias='/')
 
 
 class Function(BaseModel):
@@ -402,68 +403,68 @@ class SubExpression(BaseModel):
     sub_: 'ArithmeticOperands' = Field(..., alias='-')
 
 
-class ArithmeticOperands(BaseModel):
-    __root__: 'List[\n        Union[ArithmeticExpression, PropertyRef, FunctionRef, float]\n    ]' = Field(...)
+class ArithmeticOperands(RootModel):
+    root: 'List[\n        Union[ArithmeticExpression, PropertyRef, FunctionRef, float]\n    ]' = Field(...)
 
 
-CQLModel.update_forward_refs()
-AndExpression.update_forward_refs()
-ArrayPredicate.update_forward_refs()
-ComparisonPredicate.update_forward_refs()
-SpatialPredicate.update_forward_refs()
-TemporalPredicate.update_forward_refs()
-AcontainedByExpression.update_forward_refs()
-AcontainsExpression.update_forward_refs()
-AequalsExpression.update_forward_refs()
-AfterExpression.update_forward_refs()
-AnyinteractsExpression.update_forward_refs()
-AoverlapsExpression.update_forward_refs()
-BeforeExpression.update_forward_refs()
-BeginsExpression.update_forward_refs()
-BegunbyExpression.update_forward_refs()
-BinaryComparisonPredicate.update_forward_refs()
-ContainsExpression.update_forward_refs()
-CrossesExpression.update_forward_refs()
-DisjointExpression.update_forward_refs()
-DuringExpression.update_forward_refs()
-EndedbyExpression.update_forward_refs()
-EndsExpression.update_forward_refs()
-EqualsExpression.update_forward_refs()
-IntersectsExpression.update_forward_refs()
-Between.update_forward_refs()
-In.update_forward_refs()
-IsBetweenPredicate.update_forward_refs()
-IsLikePredicate.update_forward_refs()
-IsNullPredicate.update_forward_refs()
-ValueExpression.update_forward_refs()
-MeetsExpression.update_forward_refs()
-MetbyExpression.update_forward_refs()
-OverlappedbyExpression.update_forward_refs()
-OverlapsExpression.update_forward_refs()
-TcontainsExpression.update_forward_refs()
-TequalsExpression.update_forward_refs()
-TouchesExpression.update_forward_refs()
-ToverlapsExpression.update_forward_refs()
-WithinExpression.update_forward_refs()
-ArrayExpression.update_forward_refs()
-EqExpression.update_forward_refs()
-GtExpression.update_forward_refs()
-GteExpression.update_forward_refs()
-LtExpression.update_forward_refs()
-LteExpression.update_forward_refs()
-ScalarExpression.update_forward_refs()
-ScalarOperands.update_forward_refs()
-SpatialOperands.update_forward_refs()
-TemporalOperands.update_forward_refs()
-ArithmeticExpression.update_forward_refs()
-ArrayLiteral.update_forward_refs()
-ScalarLiteral.update_forward_refs()
-PropertyRef.update_forward_refs()
-FunctionRef.update_forward_refs()
-AddExpression.update_forward_refs()
-DivExpression.update_forward_refs()
-MulExpression.update_forward_refs()
-SubExpression.update_forward_refs()
+CQLModel.model_rebuild()
+AndExpression.model_rebuild()
+ArrayPredicate.model_rebuild()
+ComparisonPredicate.model_rebuild()
+SpatialPredicate.model_rebuild()
+TemporalPredicate.model_rebuild()
+AcontainedByExpression.model_rebuild()
+AcontainsExpression.model_rebuild()
+AequalsExpression.model_rebuild()
+AfterExpression.model_rebuild()
+AnyinteractsExpression.model_rebuild()
+AoverlapsExpression.model_rebuild()
+BeforeExpression.model_rebuild()
+BeginsExpression.model_rebuild()
+BegunbyExpression.model_rebuild()
+BinaryComparisonPredicate.model_rebuild()
+ContainsExpression.model_rebuild()
+CrossesExpression.model_rebuild()
+DisjointExpression.model_rebuild()
+DuringExpression.model_rebuild()
+EndedbyExpression.model_rebuild()
+EndsExpression.model_rebuild()
+EqualsExpression.model_rebuild()
+IntersectsExpression.model_rebuild()
+Between.model_rebuild()
+In.model_rebuild()
+IsBetweenPredicate.model_rebuild()
+IsLikePredicate.model_rebuild()
+IsNullPredicate.model_rebuild()
+ValueExpression.model_rebuild()
+MeetsExpression.model_rebuild()
+MetbyExpression.model_rebuild()
+OverlappedbyExpression.model_rebuild()
+OverlapsExpression.model_rebuild()
+TcontainsExpression.model_rebuild()
+TequalsExpression.model_rebuild()
+TouchesExpression.model_rebuild()
+ToverlapsExpression.model_rebuild()
+WithinExpression.model_rebuild()
+ArrayExpression.model_rebuild()
+EqExpression.model_rebuild()
+GtExpression.model_rebuild()
+GteExpression.model_rebuild()
+LtExpression.model_rebuild()
+LteExpression.model_rebuild()
+ScalarExpression.model_rebuild()
+ScalarOperands.model_rebuild()
+SpatialOperands.model_rebuild()
+TemporalOperands.model_rebuild()
+ArithmeticExpression.model_rebuild()
+ArrayLiteral.model_rebuild()
+ScalarLiteral.model_rebuild()
+PropertyRef.model_rebuild()
+FunctionRef.model_rebuild()
+AddExpression.model_rebuild()
+DivExpression.model_rebuild()
+MulExpression.model_rebuild()
+SubExpression.model_rebuild()
 
 
 def get_next_node(obj):
@@ -478,25 +479,25 @@ def get_next_node(obj):
         next_node = obj.not_
         logical_op = 'not'
     elif obj.__repr_name__() == 'ComparisonPredicate':
-        next_node = obj.__root__
+        next_node = obj.root
     elif obj.__repr_name__() == 'SpatialPredicate':
-        next_node = obj.__root__
+        next_node = obj.root
     elif obj.__repr_name__() == 'TemporalPredicate':
-        next_node = obj.__root__
+        next_node = obj.root
     elif obj.__repr_name__() == 'IsBetweenPredicate':
         next_node = obj.between
     elif obj.__repr_name__() == 'Between':
         next_node = obj.value
     elif obj.__repr_name__() == 'ValueExpression':
-        next_node = obj.__root__ or obj.lower or obj.upper
+        next_node = obj.root or obj.lower or obj.upper
     elif obj.__repr_name__() == 'ScalarExpression':
-        next_node = obj.__root__
+        next_node = obj.root
     elif obj.__repr_name__() == 'ScalarLiteral':
-        next_node = obj.__root__
+        next_node = obj.root
     elif obj.__repr_name__() == 'PropertyRef':
         next_node = obj.property
     elif obj.__repr_name__() == 'BinaryComparisonPredicate':
-        next_node = obj.__root__
+        next_node = obj.root
     elif obj.__repr_name__() == 'EqExpression':
         next_node = obj.eq
         logical_op = 'eq'
