lovasoa / marshmallow_dataclass

Automatic generation of marshmallow schemas from dataclasses.
https://lovasoa.github.io/marshmallow_dataclass/html/marshmallow_dataclass.html
MIT License
456 stars 78 forks source link

Ability to configure custom Nested field class #238

Open npalmius opened 1 year ago

npalmius commented 1 year ago

I have been using marshmallow-dataclass to improve the typing of Python input and output, and overall this has been excellent.

However, it would be great to have some way to configure a custom subclass of the marshmallow Nested field to use for nested dataclass properties when converted to a Schema.

For most other types, I have been able to customise the field type using the TYPE_MAPPING property in the base_schema, but this doesn't seem to be possible for Nested schema fields created from object properties in the dataclass as it looks to me like it's hard-coded in field_for_schema, and anyway the call signature for Nested fields is different to other fields because it takes the schema as a positional argument.

Ideally, I'd like to be able to configure this as a property on the base_schema (similar to TYPE_MAPPING) so that it propagates automatically.

I'd be happy to submit a pull request if it would help.