Skip to content

Commit

Permalink
fix colander schema type for OpenAPI generation
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault committed Nov 9, 2024
1 parent 552949b commit 0c005e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion tests/wps_restapi/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
if TYPE_CHECKING:
from typing import List, Tuple

from weaver.typedefs import JSON # noqa


@pytest.mark.functional
class GenericApiRoutesTestCase(WpsConfigBase):
Expand All @@ -34,7 +36,7 @@ class GenericApiRoutesTestCase(WpsConfigBase):
def test_frontpage_format(self):
resp = self.app.get(sd.api_frontpage_service.path, headers=self.json_headers)
assert resp.status_code == 200
body = resp.json
body = cast("JSON", resp.json)
try:
sd.FrontpageSchema().deserialize(body)
except colander.Invalid as ex:
Expand Down
14 changes: 7 additions & 7 deletions weaver/wps_restapi/colander_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
IntegerTypeConverter,
NumberTypeConverter,
ObjectTypeConverter,
StringTypeConverter,
TimeTypeConverter,
TypeConversionDispatcher,
TypeConverter,
Expand Down Expand Up @@ -138,7 +139,7 @@ def convert_type(self, schema_node):
return result


class ExtendedStringTypeConverter(MetadataTypeConverter, BaseStringTypeConverter):
class ExtendedStringTypeConverter(MetadataTypeConverter, StringTypeConverter):
pass


Expand Down Expand Up @@ -197,12 +198,11 @@ class ExtendedMoneyTypeConverter(ExtendedDecimalTypeConverter):
URI_REGEX = rf"{URL_REGEX[:-1]}(?:#?|[#?]\S+)$"
URI = colander.Regex(URI_REGEX, msg=colander._("Must be a URI"), flags=re.IGNORECASE)
STRING_FORMATTERS.update({
"uri": {"converter": ExtendedStringTypeConverter, "validator": URI},
"url": {"converter": ExtendedStringTypeConverter, "validator": URL},
"file": {"converter": ExtendedStringTypeConverter, "validator": FILE_URI},
"date": {"converter": ExtendedDateTimeTypeConverter},
"time": {"converter": ExtendedDateTimeTypeConverter},
"date-time": {"converter": ExtendedDateTimeTypeConverter},
# following MUST NOT use the 'StringTypeConverter' or 'ExtendedStringTypeConverter'
# otherwise, it causes a recursion error when 'StringTypeConverter' tries to dispatch their parameter handling
"uri": {"converter": BaseStringTypeConverter, "validator": URI},
"url": {"converter": BaseStringTypeConverter, "validator": URL},
"file": {"converter": BaseStringTypeConverter, "validator": FILE_URI},
})


Expand Down

0 comments on commit 0c005e4

Please sign in to comment.