-
Hi - it seems common to have a list of objects of some type, in my case when parsing input from a JSON API. So the generator gave me this from the JSON schema:
However, this does not work to have the ThingList actually work as a list, with getitem and iter. So I got the hint to add this:
Is this a good way, or is something else recommended? It works fine for me but the problem is the manual addition of code to the generated model. Is there a way to do this automatically? I saw a hook to add custom Python code but maybe there is something else for this common case with containers. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I'm sorry for my too-late reply. |
Beta Was this translation helpful? Give feedback.
I'm sorry for my too-late reply.
We can use
--custom-template-dir
option for a custom jinja template.But I don't recommend it. The custom root type is common in pydantic.
https://docs.pydantic.dev/usage/models/#custom-root-types