Skip to content

Commit

Permalink
fix invalid WPS->OAS literal data integer conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault committed Sep 6, 2023
1 parent a0b3d21 commit c999170
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Changes:
Fixes:
------
- Fix broken `OpenAPI` schema link references to `OGC API - Processes` repository.
- Fix `WPS` I/O ``integer`` literal data conversion to `OpenAPI` I/O ``schema`` definition injecting an
invalid ``format: double`` property due to type checking with ``float`` succeeding against ``int`` values.

.. _changes_4.30.1:

Expand Down
44 changes: 44 additions & 0 deletions tests/processes/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
get_cwl_io_type,
get_io_type_category,
is_cwl_complex_type,
json2oas_io,
json2wps_allowed_values,
json2wps_datatype,
merge_io_formats,
Expand Down Expand Up @@ -270,6 +271,49 @@ def test_any2cwl_io_from_oas():
assert cwl_ns == OGC_NAMESPACE_DEFINITION


@pytest.mark.parametrize(
["test_io", "expect"],
[
(
{
"literalDataDomains": [
{"default": True, "dataType": {"name": "integer"}, "valueDefinition": [1, 2, 3]}
],
"any_value": False,
"min_occurs": 1,
"max_occurs": 1,
},
{
"type": "integer",
"enum": [1, 2, 3],
},
),
(
{
"literalDataDomains": [
{"default": True, "dataType": {"name": "integer"}, "valueDefinition": [1, 2, 3]}
],
"any_value": False,
"min_occurs": 0,
"max_occurs": 2,
},
{
"type": "array",
"items": {
"type": "integer",
"enum": [1, 2, 3],
},
"minItems": 0,
"maxItems": 2,
},
)
]
)
def test_json2oas_io(test_io, expect):
copy_io = deepcopy(test_io) # can get modified by function
assert json2oas_io(test_io) == expect, f"Failed for [{copy_io}]"


@pytest.mark.parametrize("expect, test_io", [
("float", {"type": WPS_LITERAL, "data_type": "float"}), # noqa: E241
("integer", {"type": WPS_LITERAL, "data_type": "integer"}), # noqa: E241
Expand Down
4 changes: 2 additions & 2 deletions weaver/processes/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -1973,10 +1973,10 @@ def json2oas_io_allowed_values(io_base, io_allowed):
if vals:
data_enum = {"type": _typ, "enum": vals}
data_enum.update(io_base)
if _typ == "number" and all(val for val in io_allowed if isinstance(val, float)):
data_enum.update(json2oas_io_literal_data_type("double"))
if _typ == "number" and all(val for val in io_allowed if isinstance(val, int)):
data_enum.update(json2oas_io_literal_data_type("integer"))
elif _typ == "number" and all(val for val in io_allowed if isinstance(val, float)):
data_enum.update(json2oas_io_literal_data_type("double"))
item_variation.append(data_enum)
return item_variation
if isinstance(io_allowed, list) and all(isinstance(val_def, dict) for val_def in io_allowed):
Expand Down

0 comments on commit c999170

Please sign in to comment.