Skip to content

databases

Pydantic models/schemas for the LinksResource used in /databases

DatabaseCreate

Bases: EntryResourceCreate, LinksResourceAttributes

Model for creating new LinksResources representing /databases resources in the MongoDB.

Required fields:

  • name
  • base_url

Original required fields for a LinksResourceAttributes model:

  • name
  • description
  • link_type
Source code in optimade_gateway/models/databases.py
13
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
class DatabaseCreate(EntryResourceCreate, LinksResourceAttributes):
    """Model for creating new LinksResources representing `/databases` resources in the
    MongoDB.

    Required fields:

    - `name`
    - `base_url`

    Original required fields for a
    [`LinksResourceAttributes`](https://www.optimade.org/optimade-python-tools/api_reference/models/links/#optimade.models.links.LinksResourceAttributes)
    model:

    - `name`
    - `description`
    - `link_type`

    """

    description: Optional[str]
    base_url: Union[AnyUrl, Link]
    homepage: Optional[Union[AnyUrl, Link]] = StrictField(
        None,
        description=(
            "JSON API links object, pointing to a homepage URL for this implementation."
        ),
    )
    link_type: Optional[LinkType] = StrictField(
        None,
        title="Link Type",
        description=(
            "The type of the linked relation.\nMUST be one of these values: 'child', "
            "'root', 'external', 'providers'."
        ),
    )

    @validator("link_type")
    def ensure_database_link_type(cls, value: LinkType) -> LinkType:
        """Ensure databases are not index meta-database-only types

        I.e., ensure they're not of type `"root"` or `"providers"`.

        !!! note
            Both `"external"` and `"child"` can still represent index meta-dbs,
            but `"root"` and `"providers"` can not represent "regular" dbs.

        """
        if value in (LinkType.ROOT, LinkType.PROVIDERS):
            raise ValueError(
                "Databases with 'root' or 'providers' link_type is not allowed for "
                f"gateway-usable database resources. Given link_type: {value}"
            )
        return value

base_url: Union[AnyUrl, Link] class-attribute

description: Optional[str] class-attribute

homepage: Optional[Union[AnyUrl, Link]] = StrictField(None, description='JSON API links object, pointing to a homepage URL for this implementation.') class-attribute

Ensure databases are not index meta-database-only types

I.e., ensure they're not of type "root" or "providers".

Note

Both "external" and "child" can still represent index meta-dbs, but "root" and "providers" can not represent "regular" dbs.

Source code in optimade_gateway/models/databases.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
@validator("link_type")
def ensure_database_link_type(cls, value: LinkType) -> LinkType:
    """Ensure databases are not index meta-database-only types

    I.e., ensure they're not of type `"root"` or `"providers"`.

    !!! note
        Both `"external"` and `"child"` can still represent index meta-dbs,
        but `"root"` and `"providers"` can not represent "regular" dbs.

    """
    if value in (LinkType.ROOT, LinkType.PROVIDERS):
        raise ValueError(
            "Databases with 'root' or 'providers' link_type is not allowed for "
            f"gateway-usable database resources. Given link_type: {value}"
        )
    return value