Skip to content

Commit

Permalink
Support "subtype" and "format" schema options in Parameter.string()
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Oct 2, 2023
1 parent 702bea8 commit 9e62255
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 14 additions & 3 deletions openeo/api/process.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import warnings
from typing import Union, Optional
from typing import Union, Optional, List


class Parameter:
Expand Down Expand Up @@ -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."""
Expand Down
16 changes: 16 additions & 0 deletions tests/api/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down

0 comments on commit 9e62255

Please sign in to comment.