Skip to content

Commit

Permalink
Introduce Parameters type (using RootModel), equivalent to edr-pydant…
Browse files Browse the repository at this point in the history
…ic Parameters
  • Loading branch information
PaulVanSchayck committed Dec 10, 2024
1 parent d1bc2c8 commit 155a26a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/covjson_pydantic/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .ndarray import NdArrayInt
from .ndarray import NdArrayStr
from .ndarray import TiledNdArrayFloat
from .parameter import Parameter
from .parameter import Parameters
from .parameter import ParameterGroup
from .reference_system import ReferenceSystemConnectionObject

Expand All @@ -32,7 +32,7 @@ class Coverage(CovJsonBaseModel, extra="allow"):
id: Optional[str] = None
type: Literal["Coverage"] = "Coverage"
domain: Domain
parameters: Optional[Dict[str, Parameter]] = None
parameters: Optional[Parameters] = None
parameterGroups: Optional[List[ParameterGroup]] = None # noqa: N815
ranges: Dict[str, Union[NdArrayTypes, TiledNdArrayFloat, AnyUrl]]

Expand All @@ -41,6 +41,6 @@ class CoverageCollection(CovJsonBaseModel, extra="allow"):
type: Literal["CoverageCollection"] = "CoverageCollection"
domainType: Optional[DomainType] = None # noqa: N815
coverages: List[Coverage]
parameters: Optional[Dict[str, Parameter]] = None
parameters: Optional[Parameters] = None
parameterGroups: Optional[List[ParameterGroup]] = None # noqa: N815
referencing: Optional[List[ReferenceSystemConnectionObject]] = None
4 changes: 4 additions & 0 deletions src/covjson_pydantic/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Union

from pydantic import model_validator
from pydantic import RootModel

from .base_models import CovJsonBaseModel
from .i18n import i18n
Expand Down Expand Up @@ -32,6 +33,9 @@ def must_not_have_unit_if_observed_property_has_categories(self):
return self


Parameters = RootModel[Dict[str, Parameter]]


class ParameterGroup(CovJsonBaseModel, extra="allow"):
type: Literal["ParameterGroup"] = "ParameterGroup"
id: Optional[str] = None
Expand Down

0 comments on commit 155a26a

Please sign in to comment.