You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When generating Pydantic models from a jsonschema, the type uri is mapped to AnyUrl, which is incorrect as URL is a subset of URI. A URI string with no host field (like something://) is a valid URI but not a valid URL.
To Reproduce
Generate Pydantic models from a schema containing a uri type field
Try to set that field to a host-less URI like something://
An exception is thrown:
pydantic_core._pydantic_core.ValidationError: 1 validation error for TestModel
field_name
Input should be a valid URL, empty host [type=url_parsing, input_value='something://', input_type=str]
For further information visit https://errors.pydantic.dev/2.10/v/url_parsing
uri fields should allow any valid URI, not just URLs.
Version:
Python version: 3.12.6
datamodel-code-generator version: 0.26.3
Additional context
My use-case is handling data in the GBFS format, which is an open standard format for exchanging data about bike-sharing, car-sharing and other similar micromobility systems. This issue occurs with the rental_apps.android.discovery_uri field of the system_information endpoint, which comes with this explanation:
URI that can be used to discover if the rental Android app is installed on the device (for example, using PackageManager.queryIntentActivities()). This intent is used by viewing apps to prioritize rental apps for a particular user based on whether they already have a particular rental app installed.
Example value: com.example.android://
I've constructed this model to handle such URIs and confirmed it works:
Describe the bug
When generating Pydantic models from a jsonschema, the type
uri
is mapped toAnyUrl
, which is incorrect as URL is a subset of URI. A URI string with nohost
field (likesomething://
) is a valid URI but not a valid URL.To Reproduce
uri
type fieldsomething://
Example schema:
Used commandline:
Expected behavior
uri
fields should allow any valid URI, not just URLs.Version:
Additional context
My use-case is handling data in the GBFS format, which is an open standard format for exchanging data about bike-sharing, car-sharing and other similar micromobility systems. This issue occurs with the
rental_apps.android.discovery_uri
field of thesystem_information
endpoint, which comes with this explanation:I've constructed this model to handle such URIs and confirmed it works:
Ideally something like this would be implemented in Pydantic itself, but it could also be put into this library.
The text was updated successfully, but these errors were encountered: