links¶
LinksMapper
¶
Source code in optimade/server/mappers/links.py
class LinksMapper(BaseResourceMapper):
ENDPOINT = "links"
ENTRY_RESOURCE_CLASS = LinksResource
@classmethod
def map_back(cls, doc: dict) -> dict:
"""Map properties from MongoDB to OPTIMADE
:param doc: A resource object in MongoDB format
:type doc: dict
:return: A resource object in OPTIMADE format
:rtype: dict
"""
type_ = doc["type"]
newdoc = super().map_back(doc)
newdoc["type"] = type_
return newdoc
ENTRY_RESOURCE_CLASS
pydantic-model
¶
A Links endpoint resource object
Source code in optimade/server/mappers/links.py
class LinksResource(EntryResource):
"""A Links endpoint resource object"""
type: str = StrictField(
"links",
const="links",
description="These objects are described in detail in the section Links Endpoint",
pattern="^links$",
)
attributes: LinksResourceAttributes = StrictField(
...,
description="A dictionary containing key-value pairs representing the Links resource's properties.",
)
@root_validator(pre=True)
def relationships_must_not_be_present(cls, values):
if values.get("relationships", None) is not None:
raise ValueError('"relationships" is not allowed for links resources')
return values
map_back(doc)
classmethod
¶
Map properties from MongoDB to OPTIMADE
:param doc: A resource object in MongoDB format :type doc: dict
:return: A resource object in OPTIMADE format :rtype: dict
Source code in optimade/server/mappers/links.py
@classmethod
def map_back(cls, doc: dict) -> dict:
"""Map properties from MongoDB to OPTIMADE
:param doc: A resource object in MongoDB format
:type doc: dict
:return: A resource object in OPTIMADE format
:rtype: dict
"""
type_ = doc["type"]
newdoc = super().map_back(doc)
newdoc["type"] = type_
return newdoc