phillipdupuis / pydantic-to-typescript

CLI Tool for converting pydantic models into typescript definitions
MIT License
285 stars 48 forks source link

Support for both Pydantic V1 and V2 #38

Open khalo-sa opened 1 year ago

khalo-sa commented 1 year ago

Hi @phillipdupuis, after switching to Pydantic V2 in one of my projects, this library stopped working. To make sure that my changes are compatible with both, Pydantic V1 and V2, I created two virtual environments with each respective Pydantic version, and this library installed. The initial goal was to keep the tests the same, but V2 requires slight adjustments to the inputs and generated outputs, which is why I created v1/v2-subdirectories for each type of test. The changes that made that necessary were:

The library seems to work now with both, V1 and V2, by dynamically determining the installed Pydantic version and using the appropriate functions.

khalo-sa commented 1 year ago

I just added support for computed fields, and a corresponding test.

nick-somebody commented 1 year ago

Just looking through pydantic docs. https://docs.pydantic.dev/latest/version-policy/#pydantic-v1

Active development of V1 has already stopped, however critical bug fixes and security vulnerabilities will be fixed in V1 for one year after the release of V2 (June 30, 2024).

The complexity of supporting both versions seems excessive to me. Wouldn't this library be better just releasing a v2 with support for pydantic v2?

Any reason I'm missing for supporting both pydantic major versions?

akx commented 11 months ago

Any reason I'm missing for supporting both pydantic major versions?

There's a lot of Pydantic 1 using code out there that's not necessarily going to update, but could use this library. It doesn't seem to be very much extra code to support both (the majority of this PR's changes are test fixtures).

nick-somebody commented 10 months ago

Any reason I'm missing for supporting both pydantic major versions?

There's a lot of Pydantic 1 using code out there that's not necessarily going to update, but could use this library. It doesn't seem to be very much extra code to support both (the majority of this PR's changes are test fixtures).

@akx pydantic 1 using code can use v1 of this library right?

voidus commented 10 months ago

What's the difference between this PR and https://github.com/phillipdupuis/pydantic-to-typescript/pull/40 or https://github.com/phillipdupuis/pydantic-to-typescript/pull/37 ?

Can they be consolidated?

atodniAr commented 6 months ago

In my project this MR worked. I'm using pydantic 2.6.4.

40 failed. I haven't try #37

seanwessmith commented 5 months ago

I created a fork with this merged so the community can easily install it via pip. The code is published to PyPI as pydantic-to-typescript2.

Phillip Dupuis is still included as an author.

Repository link: Darius-Labs/pydantic-to-typescript2