Skip to content

Commit

Permalink
Updated pydantic examples such that they work for pydantic > 2.10.0 (#…
Browse files Browse the repository at this point in the history
…1054)

Updated pydantic models such that they work for pydantic > 2.10.0
  • Loading branch information
jesper-friis authored Jan 21, 2025
1 parent a47165d commit 39e966d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
56 changes: 25 additions & 31 deletions examples/datamodel_as_rdf/dataresource_pydantic2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
print("This example requires pydantic v2")
raise SystemExit(44)

HostlessAnyUrl = Annotated[AnyUrl, UrlConstraints(host_required=False)]


class ResourceConfig(BaseModel):
"""Resource Strategy Data Configuration.
Expand All @@ -25,21 +27,17 @@ class ResourceConfig(BaseModel):
`accessUrl`/`accessService` MUST be specified.
"""

downloadUrl: Annotated[
Optional[AnyUrl],
UrlConstraints(host_required=False),
Field(
None,
description=(
"""Definition: The URL of the downloadable file in a given
format. E.g. CSV " "file or RDF file.
downloadUrl: Optional[HostlessAnyUrl] = Field(
None,
description=(
"""Definition: The URL of the downloadable file in a given
format. E.g. CSV " "file or RDF file.
Usage: `downloadURL` *SHOULD* be used for the URL at which
this distribution is available directly, typically through a
HTTPS GET request or SFTP."""
),
Usage: `downloadURL` *SHOULD* be used for the URL at which
this distribution is available directly, typically through a
HTTPS GET request or SFTP."""
),
]
)
mediaType: Annotated[
Optional[str],
Field(
Expand All @@ -55,25 +53,21 @@ class ResourceConfig(BaseModel):
),
),
]
accessUrl: Annotated[
Optional[AnyUrl],
UrlConstraints(host_required=False),
Field(
None,
description=(
"""A URL of the resource that gives access to a distribution of
the dataset. E.g. landing page, feed, SPARQL endpoint.
Usage: `accessURL` *SHOULD* be used for the URL of a
service or location that can provide access to this
distribution, typically through a Web form, query or API
call.
`downloadURL` is preferred for direct links to downloadable
resources."""
),
accessUrl: Optional[HostlessAnyUrl] = Field(
None,
description=(
"""A URL of the resource that gives access to a distribution of
the dataset. E.g. landing page, feed, SPARQL endpoint.
Usage: `accessURL` *SHOULD* be used for the URL of a
service or location that can provide access to this
distribution, typically through a Web form, query or API
call.
`downloadURL` is preferred for direct links to downloadable
resources."""
),
]
)
accessService: Annotated[
Optional[str],
Field(
Expand Down
4 changes: 2 additions & 2 deletions requirements_full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ urllib3>=1.0.0,<2
#psycopg2>=2,<3

# Utilities
# Bug in pydantic 2.10.1, see https://github.com/pydantic/pydantic/issues/9898
pydantic>=1.10.0,!=2.10.0,!=2.10.1,<2.10.2
# Bug in pydantic 2.10.0, see https://github.com/pydantic/pydantic/issues/9898
pydantic>=1.10.0,!=2.10.0,<2.10.4
typing_extensions>=4.1,<5; python_version<'3.9'
fortran-language-server>=1.12.0,<1.13

Expand Down

0 comments on commit 39e966d

Please sign in to comment.