Closed j4mie closed 5 months ago
Nice idea.
…providing label and help_text separately feels a bit awkward.
That seems right to me. Too many functions.
I might feel the same about kwargs
too 🤔
I wonder if out
could be adjusted to something like, def out(field_or_dict=None, *, **kwargs)
so that field_or_dict
remains positional but optional, and then arbitrary kwargs
could be passed if it were not provided?
The advantage there is just having one, familiar, but flexible function to learn, import, and use.
I like that suggestion @carltongibson. Thanks!
For our schema generation support, we currently support automatic generation of serializer fields via model introspection:
We also support overriding the auto-generated serializer field, using
out
:However, in a large spec, if you wish to provide
label
and/orhelp_text
(which are extremely useful during schema generation, as drf-spectacular uses them for the "title" and "description" OpenAPI attributes) to multiple fields in a large spec, usingout
is tedious, because you are essentially throwing away all of the clever automatic generation of serializer fields, and doing everything manually.It would be nice if it were possible to provide extra keyword arguments to the default (automatically created) serializer fields.
As we already use the
>>
syntax forout
, we could use the same idea. A couple of possibilities:Or perhaps just:
kwargs
feels a little awkward because it implies that other kwargs than justlabel
andhelp_text
can be supplied - which is technically true, but none of the others are used by drf-spectacular in a read-only context, and remember the serializer we're generating here is only used for schema generation, not for actually serializing the objects (but then nothing else here is specifically tied to drf-spectacular, so maybe we should be thinking more generally?). On the other hand, providinglabel
andhelp_text
separately feels a bit awkward. Any other ideas? Any other arguments we might want to provide?