Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Subclassed Lists marked as string type #433
I am using a tool to generate a Marshmallow schema that I then present as a RESTful API. In order to override some of the methods of marshmallow.fields.List, the generated schema can have generated classes that subclass List. The resulting APISpec is almost perfect because openapi.py mostly uses isinstance to see if the field is a list. For example:
However, when working out the field type the mapping is looked up using a concrete type:
It isn't straightforward for me to add the new types using map_to_openapi_type because of the generated nature of my marshmallow and the way the presentation layer is kept separate. However, instead of falling back to
Thinking about this further, I think the correct thing to do is improve the behaviour of field2type_and_format when the type isn't explicitly found in the field_mapping. It currently always falls back
Note, things seem to work for subclassed Nested fields because they get fixed up after the fact in field2property. IMO, the type specific fix ups could be combined with field2type_and_format to put all the class/type specific properties in one place.