tefra/xsdata-pydantic

Hints for usage with fastapi

jensens opened this issue · 2 comments

I used this code to generate pydantic schemas intended for use with fastapi. Background is, I receive data from Exlibris Alma Webhooks. The schema is available as XSD only (no JSON schemas). With this great tool here I directly generate pydantic schemas for fastapi Thanks so much!
Anyway, they do not work out-of-the-box, some manual steps needed:

  • nested has to be set to false
  • the metadata, specifically the required=true in there, broke fastapis get_model_definitions. I manually removed the whole metadata, because Elements and Attributes are not needed in JSON.
  • I replaced XMLDate and XMLDateTime by datetime.date and datetime.datetime.

Now it at least loads the model and it seems incoming JSON data is validated as expected.

tefra commented

Yeah there are some blocking issues with pydantic and I can't really release this plugin yet.

Thanks for giving it a try and for your feedback!

tefra commented

The plugin is now released, as it was, one of the most major issues with pydantic was resolved in a recent release, if there are any more issues please let me know!