Hi, I've started to use the new OpenAPI schema generation in DRF 3.10 and ran into a few things that would be worth discussing.
The first one relates to schema generation for custom field types. All the logic relating to field schema introspection is on the AutoSchema class in the _map_field method: https://github.com/encode/django-rest-framework/blob/f7c3220fdb74b904bd4534af68593aa8b711e978/rest_framework/schemas/openapi.py#L214 For field classes it does not know about, it defaults to an OpenAPI type of string. I have a custom field type that is actually an object (in OpenAPI terminology), and the properties vary by field instance. As it stands it's determined to be a string by AutoSchema (which is incorrect). Currently, the only option to get it relatively correct is to subclass AutoSchema. However, _map_field is an internal method, and overriding it would not be ideal. Neither would reimplementing it. Bearing in mind the previous points, a possible solution to me seems to be to add a new method to Field (get_schema or whatever) and let each field return its schema. It would also be useful to have the context of whether this is for a request or response there as well, as some fields can be more forgiving or flexible for requests. Happy to create an issue on GitHub (just came here from the link in the checklist). Thanks! -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/8c622ab0-0efa-4c1b-b0e5-bb4ea37d92d9%40googlegroups.com.
