Skip to content

resourceconfig

Pydantic Resource Configuration Data Model.

HostlessAnyUrl = Annotated[Url, UrlConstraints(host_required=False)] module-attribute

ResourceConfig

Bases: GenericConfig, SecretConfig

Resource Strategy Data Configuration.

Important

Either of the pairs of attributes downloadUrl/mediaType or accessUrl/accessService MUST be specified.

Source code in oteapi/models/resourceconfig.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
class ResourceConfig(GenericConfig, SecretConfig):
    """Resource Strategy Data Configuration.

    Important:
        Either of the pairs of attributes `downloadUrl`/`mediaType` or
        `accessUrl`/`accessService` MUST be specified.

    """

    resourceType: Optional[str] = Field(
        None, description="Type of registered resource strategy."
    )

    downloadUrl: Optional[HostlessAnyUrl] = Field(
        None,
        description=(
            "Definition: The URL of the downloadable file in a given format. E.g. CSV "
            "file or RDF file.\n\nUsage: `downloadURL` *SHOULD* be used for the URL at"
            " which this distribution is available directly, typically through a HTTPS"
            " GET request or SFTP."
        ),
    )
    mediaType: Optional[str] = Field(
        None,
        description=(
            "The media type of the distribution as defined by IANA "
            "[[IANA-MEDIA-TYPES](https://www.w3.org/TR/vocab-dcat-2/#bib-iana-media-types)]"
            ".\n\nUsage: This property *SHOULD* be used when the media"
            " type of the distribution is defined in IANA "
            "[[IANA-MEDIA-TYPES](https://www.w3.org/TR/vocab-dcat-2/#bib-iana-media-types)]."
        ),
    )
    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.\n\nUsage: "
            "`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.\n`downloadURL` is preferred for direct links to "
            "downloadable resources."
        ),
    )
    accessService: Optional[str] = Field(
        None,
        description=(
            "A data service that gives access to the distribution of the dataset."
        ),
    )
    license: Optional[str] = Field(
        None,
        description=(
            "A legal document under which the distribution is made available."
        ),
    )
    accessRights: Optional[str] = Field(
        None,
        description=(
            "A rights statement that concerns how the distribution is accessed."
        ),
    )
    publisher: Optional[str] = Field(
        None,
        description="The entity responsible for making the resource/item available.",
    )

    @model_validator(mode="after")
    def ensure_unique_url_pairs(self) -> "ResourceConfig":
        """Ensure either downloadUrl/mediaType or accessUrl/accessService are defined.

        It's fine to define them all, but at least one complete pair MUST be specified.
        """
        if not (
            all(getattr(self, _) for _ in ["downloadUrl", "mediaType"])
            or all(getattr(self, _) for _ in ["accessUrl", "accessService"])
        ):
            raise ValueError(
                "Either of the pairs of attributes downloadUrl/mediaType or "
                "accessUrl/accessService MUST be specified."
            )
        return self

accessRights: Optional[str] = Field(None, description='A rights statement that concerns how the distribution is accessed.') class-attribute instance-attribute

accessService: Optional[str] = Field(None, description='A data service that gives access to the distribution of the dataset.') class-attribute instance-attribute

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.\n\nUsage: `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.\n`downloadURL` is preferred for direct links to downloadable resources.') class-attribute instance-attribute

downloadUrl: Optional[HostlessAnyUrl] = Field(None, description='Definition: The URL of the downloadable file in a given format. E.g. CSV file or RDF file.\n\nUsage: `downloadURL` *SHOULD* be used for the URL at which this distribution is available directly, typically through a HTTPS GET request or SFTP.') class-attribute instance-attribute

license: Optional[str] = Field(None, description='A legal document under which the distribution is made available.') class-attribute instance-attribute

mediaType: Optional[str] = Field(None, description='The media type of the distribution as defined by IANA [[IANA-MEDIA-TYPES](https://www.w3.org/TR/vocab-dcat-2/#bib-iana-media-types)].\n\nUsage: This property *SHOULD* be used when the media type of the distribution is defined in IANA [[IANA-MEDIA-TYPES](https://www.w3.org/TR/vocab-dcat-2/#bib-iana-media-types)].') class-attribute instance-attribute

publisher: Optional[str] = Field(None, description='The entity responsible for making the resource/item available.') class-attribute instance-attribute

resourceType: Optional[str] = Field(None, description='Type of registered resource strategy.') class-attribute instance-attribute

ensure_unique_url_pairs()

Ensure either downloadUrl/mediaType or accessUrl/accessService are defined.

It's fine to define them all, but at least one complete pair MUST be specified.

Source code in oteapi/models/resourceconfig.py
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
@model_validator(mode="after")
def ensure_unique_url_pairs(self) -> "ResourceConfig":
    """Ensure either downloadUrl/mediaType or accessUrl/accessService are defined.

    It's fine to define them all, but at least one complete pair MUST be specified.
    """
    if not (
        all(getattr(self, _) for _ in ["downloadUrl", "mediaType"])
        or all(getattr(self, _) for _ in ["accessUrl", "accessService"])
    ):
        raise ValueError(
            "Either of the pairs of attributes downloadUrl/mediaType or "
            "accessUrl/accessService MUST be specified."
        )
    return self