Jsyro / untp-models

Pydantic Python Models that represent the UN Transparency Protocol
GNU General Public License v3.0
0 stars 0 forks source link

URI validation #1

Open Jsyro opened 4 months ago

Jsyro commented 4 months ago

AnyURL pydantic types are not json serializable, so urls are validated as str.

I've tried defining a custom json_encoder, but the pydantic type is not actually an AnyURL object, so I was not able to detect the right class.

A solution to this would properly leverage pydantic's url validation, but also allow for a successful json.dumps(<model>.dict()) of a class with a URI field.

Jsyro commented 2 months ago

pydantic has a new model_dump() method with the mode="json" parameter, does what we want.