diff --git a/CHANGELOG.md b/CHANGELOG.md index dd2f32da6..0e5927821 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support year/month shorthand date notations in temporal extent arguments of `Connection.load_collection`, `DataCube.filter_temporal` and related ([#421](https://github.com/Open-EO/openeo-python-client/issues/421)) - Support parameterized `bands` in `load_collection` ([#471](https://github.com/Open-EO/openeo-python-client/issues/471)) - Allow specifying item schema in `Parameter.array()` +- Support "subtype" and "format" schema options in `Parameter.string()` ### Changed diff --git a/openeo/api/process.py b/openeo/api/process.py index 2d2a25f00..fc9265458 100644 --- a/openeo/api/process.py +++ b/openeo/api/process.py @@ -1,7 +1,7 @@ from __future__ import annotations import warnings -from typing import Union, Optional +from typing import Union, Optional, List class Parameter: @@ -61,14 +61,25 @@ def datacube(cls, name: str = "data", description: str = "A data cube.") -> Para return cls(name=name, description=description, schema={"type": "object", "subtype": "datacube"}) @classmethod - def string(cls, name: str, description: str = None, default=_DEFAULT_UNDEFINED, values=None) -> Parameter: + def string( + cls, + name: str, + description: str = None, + default=_DEFAULT_UNDEFINED, + values: Optional[List[str]] = None, + subtype: Optional[str] = None, + format: Optional[str] = None, + ) -> Parameter: """Helper to create a 'string' type parameter.""" schema = {"type": "string"} if values is not None: schema["enum"] = values + if subtype: + schema["subtype"] = subtype + if format: + schema["format"] = format return cls(name=name, description=description, schema=schema, default=default) - @classmethod def integer(cls, name: str, description: str = None, default=_DEFAULT_UNDEFINED) -> Parameter: """Helper to create a 'integer' type parameter.""" diff --git a/tests/api/test_process.py b/tests/api/test_process.py index 98f5f9f68..3d90e06cd 100644 --- a/tests/api/test_process.py +++ b/tests/api/test_process.py @@ -61,6 +61,22 @@ def test_parameter_string(): } +def test_parameter_string_subtype(): + assert Parameter.string("cid", subtype="collection-id").to_dict() == { + "name": "cid", + "description": "cid", + "schema": {"type": "string", "subtype": "collection-id"}, + } + + +def test_parameter_string_format(): + assert Parameter.string("date", subtype="date", format="date").to_dict() == { + "name": "date", + "description": "date", + "schema": {"type": "string", "subtype": "date", "format": "date"}, + } + + def test_parameter_integer(): assert Parameter.integer("iterations").to_dict() == { "name": "iterations", "description": "iterations", "schema": {"type": "integer"}