@@ -5964,27 +5964,38 @@ class GenericHTMLResponse(ExtendedMappingSchema):
5964
5964
header = HtmlHeader ()
5965
5965
body = ExtendedMappingSchema ()
5966
5966
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
5969
5969
"""
5970
5970
Generates a derived HTML response schema with direct forwarding of custom parameters to the body's schema.
5971
5971
5972
5972
This strategy allows the quicker definition of schema variants without duplicating class definitions only
5973
5973
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.
5974
5979
"""
5975
5980
if not isinstance (name , str ) or not re .match (r"^[A-Z][A-Z0-9_-]*$" , name , re .I ):
5976
5981
raise ValueError (
5977
5982
"New schema name must be provided to avoid invalid mixed use of $ref pointers. "
5978
5983
f"Name '{ name } ' is invalid."
5979
5984
)
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 = [
5983
5989
child
5984
5990
if child .name != "body" else
5985
5991
ExtendedMappingSchema (name = "body" , ** kwargs )
5986
- for child in self .children
5992
+ for child in obj .children
5987
5993
]
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 )
5988
5999
5989
6000
5990
6001
class ErrorDetail (ExtendedMappingSchema ):
0 commit comments