marshmallow-sqlalchemy icon indicating copy to clipboard operation
marshmallow-sqlalchemy copied to clipboard

Question: Ability to return classname for custom type (TypeDecorator) in metadata

Open jdimmerman opened this issue 3 years ago • 0 comments

Hey! Thanks for the library. I have what may be a naive question:

I have a scenario in which I'm

  • using marshmallow-sqlalchemy SQLAlchemySchema along with auto_field
  • using a custom type, defined creating a class that inherits from sql alchemy's TypeDecorator
  • using apispec to publish a swagger doc based on the marshmallow schemas
  • using apispec's marshmallow_plugin.converter.add_attribute_function to add middleware which modifies the openapi spec in certain circumstances. add_attribute_function takes an argument of the marshmallow field (of type Field).

For the most part, this works great. However, I'd like to modify the openapi schema docs when I encounter one of my custom sql alchemy types. However, the following code seems to hide the original type from the downstream consumers when auto_field() is used. Is it possible to somehow identify what the source TypeDecorator class is for an auto_field?

https://github.com/marshmallow-code/marshmallow-sqlalchemy/pull/83/files

                if hasattr(data_type, 'impl'):
                    return self._get_field_class_for_data_type(data_type.impl)

For now, I can stop using auto_field in these cases.

Thanks!

jdimmerman avatar Mar 15 '22 12:03 jdimmerman