Skip to content

Commit 031f3fc

Browse files
committed
fix resolution of HTML response schema name
1 parent f5dd70f commit 031f3fc

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

weaver/wps_restapi/processes/processes.py

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from pyramid.response import Response
1616
from pyramid.settings import asbool
1717
from werkzeug.wrappers.request import Request as WerkzeugRequest
18-
from webob.acceptparse import AcceptInvalidHeader
1918

2019
from weaver.database import get_db
2120
from weaver.exceptions import ProcessNotFound, ServiceException, log_unhandled_exceptions

weaver/wps_restapi/swagger_definitions.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -5964,27 +5964,38 @@ class GenericHTMLResponse(ExtendedMappingSchema):
59645964
header = HtmlHeader()
59655965
body = ExtendedMappingSchema()
59665966

5967-
def __init__(self, *, name, description, **kwargs):
5968-
# type: (*Any, str, str, **Any) -> None
5967+
def __new__(cls, *, name, description, **kwargs):
5968+
# type: (Type[GenericHTMLResponse], *Any, str, str, **Any) -> GenericHTMLResponse
59695969
"""
59705970
Generates a derived HTML response schema with direct forwarding of custom parameters to the body's schema.
59715971
59725972
This strategy allows the quicker definition of schema variants without duplicating class definitions only
59735973
providing alternate documentation parameters.
5974+
5975+
.. note::
5976+
Method ``__new__`` is used instead of ``__init__`` because some :mod:`cornice_swagger` operations will
5977+
look explicitly for ``schema_node.__class__.__name__``. If using ``__init__``, the first instance would
5978+
set the name value for all following instances instead of the intended reusable meta-schema class.
59745979
"""
59755980
if not isinstance(name, str) or not re.match(r"^[A-Z][A-Z0-9_-]*$", name, re.I):
59765981
raise ValueError(
59775982
"New schema name must be provided to avoid invalid mixed use of $ref pointers. "
59785983
f"Name '{name}' is invalid."
59795984
)
5980-
super().__init__(self, name=name, description=description)
5981-
self.__class__.__name__ = name
5982-
self.children = [
5985+
obj = super().__new__(cls)
5986+
obj.__init__(name=name, description=description)
5987+
obj.__class__.__name__ = name
5988+
obj.children = [
59835989
child
59845990
if child.name != "body" else
59855991
ExtendedMappingSchema(name="body", **kwargs)
5986-
for child in self.children
5992+
for child in obj.children
59875993
]
5994+
return obj
5995+
5996+
def __deepcopy__(self, *args, **kwargs):
5997+
# type: (*Any, *Any) -> GenericHTMLResponse
5998+
return GenericHTMLResponse(name=self.name, description=self.description, children=self.children)
59885999

59896000

59906001
class ErrorDetail(ExtendedMappingSchema):

0 commit comments

Comments
 (0)