Skip to content

Commit 9e62255

Browse files
committed
Support "subtype" and "format" schema options in Parameter.string()
1 parent 702bea8 commit 9e62255

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- 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))
1414
- Support parameterized `bands` in `load_collection` ([#471](https://github.com/Open-EO/openeo-python-client/issues/471))
1515
- Allow specifying item schema in `Parameter.array()`
16+
- Support "subtype" and "format" schema options in `Parameter.string()`
1617

1718
### Changed
1819

openeo/api/process.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import warnings
4-
from typing import Union, Optional
4+
from typing import Union, Optional, List
55

66

77
class Parameter:
@@ -61,14 +61,25 @@ def datacube(cls, name: str = "data", description: str = "A data cube.") -> Para
6161
return cls(name=name, description=description, schema={"type": "object", "subtype": "datacube"})
6262

6363
@classmethod
64-
def string(cls, name: str, description: str = None, default=_DEFAULT_UNDEFINED, values=None) -> Parameter:
64+
def string(
65+
cls,
66+
name: str,
67+
description: str = None,
68+
default=_DEFAULT_UNDEFINED,
69+
values: Optional[List[str]] = None,
70+
subtype: Optional[str] = None,
71+
format: Optional[str] = None,
72+
) -> Parameter:
6573
"""Helper to create a 'string' type parameter."""
6674
schema = {"type": "string"}
6775
if values is not None:
6876
schema["enum"] = values
77+
if subtype:
78+
schema["subtype"] = subtype
79+
if format:
80+
schema["format"] = format
6981
return cls(name=name, description=description, schema=schema, default=default)
7082

71-
7283
@classmethod
7384
def integer(cls, name: str, description: str = None, default=_DEFAULT_UNDEFINED) -> Parameter:
7485
"""Helper to create a 'integer' type parameter."""

tests/api/test_process.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ def test_parameter_string():
6161
}
6262

6363

64+
def test_parameter_string_subtype():
65+
assert Parameter.string("cid", subtype="collection-id").to_dict() == {
66+
"name": "cid",
67+
"description": "cid",
68+
"schema": {"type": "string", "subtype": "collection-id"},
69+
}
70+
71+
72+
def test_parameter_string_format():
73+
assert Parameter.string("date", subtype="date", format="date").to_dict() == {
74+
"name": "date",
75+
"description": "date",
76+
"schema": {"type": "string", "subtype": "date", "format": "date"},
77+
}
78+
79+
6480
def test_parameter_integer():
6581
assert Parameter.integer("iterations").to_dict() == {
6682
"name": "iterations", "description": "iterations", "schema": {"type": "integer"}

0 commit comments

Comments
 (0)