Skip to content

Commit cd1e1ef

Browse files
committed
Add Parameter.object() factory for object type parameters
1 parent 8716d00 commit cd1e1ef

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
Allow manually specifying the desired band mapping.
2222
([#485](https://github.com/Open-EO/openeo-python-client/issues/485), [#501](https://github.com/Open-EO/openeo-python-client/issues/501))
2323
- Also attempt to automatically refresh OIDC access token on a `401 TokenInvalid` response (in addition to `403 TokenInvalid`) ([#508](https://github.com/Open-EO/openeo-python-client/issues/508))
24-
24+
- Add `Parameter.object()` factory for `object` type parameters
2525

2626
### Changed
2727

openeo/api/process.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def array(
107107
"""
108108
Helper to create an 'array' type parameter.
109109
110-
:parameter item_schema: Schema of the array items given in JSON Schema style, e.g. ``{"type": "string"}``.
110+
:param item_schema: Schema of the array items given in JSON Schema style, e.g. ``{"type": "string"}``.
111111
Simple schemas can also be specified as single string:
112112
e.g. ``"string"`` will be expanded to ``{"type": "string"}``.
113113
@@ -120,3 +120,19 @@ def array(
120120
item_schema = {"type": item_schema}
121121
schema["items"] = item_schema
122122
return cls(name=name, description=description, schema=schema, default=default)
123+
124+
@classmethod
125+
def object(
126+
cls, name: str, description: Optional[str] = None, default=_DEFAULT_UNDEFINED, *, subtype: Optional[str] = None
127+
) -> Parameter:
128+
"""
129+
Helper to create an 'object' type parameter
130+
131+
:param subtype: subtype of the 'object' schema
132+
133+
.. versionadded:: 0.26.0
134+
"""
135+
schema = {"type": "object"}
136+
if subtype:
137+
schema["subtype"] = subtype
138+
return cls(name=name, description=description, schema=schema, default=default)

tests/api/test_process.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,26 @@ def test_parameter_array():
125125
}
126126

127127

128+
def test_parameter_object():
129+
assert Parameter.object("bbox").to_dict() == {"name": "bbox", "description": "bbox", "schema": {"type": "object"}}
130+
assert Parameter.object("bbox", description="Spatial").to_dict() == {
131+
"name": "bbox",
132+
"description": "Spatial",
133+
"schema": {"type": "object"},
134+
}
135+
assert Parameter.object("bbox", default={"west": 4}).to_dict() == {
136+
"name": "bbox",
137+
"description": "bbox",
138+
"schema": {"type": "object"},
139+
"optional": True,
140+
"default": {"west": 4},
141+
}
142+
assert Parameter.object("cube", subtype="datacube").to_dict() == {
143+
"name": "cube",
144+
"description": "cube",
145+
"schema": {"type": "object", "subtype": "datacube"},
146+
}
147+
128148

129149
@pytest.mark.parametrize(["kwargs", "expected"], [
130150
({"name": "x"}, {"name": "x", "description": "x", "schema": {}}),

0 commit comments

Comments
 (0)