66 lines
1.6 KiB
Python
66 lines
1.6 KiB
Python
"""
|
|
Models used for validation and OpenAPI responses
|
|
"""
|
|
|
|
from pydantic import BaseModel, StrictStr
|
|
from fastapi import Response
|
|
|
|
class Link(BaseModel):
|
|
"""
|
|
Describes an entry in the JRD `link` array
|
|
"""
|
|
rel: StrictStr
|
|
type: StrictStr | None
|
|
href: StrictStr | None
|
|
titles: StrictStr | None
|
|
properties: dict[StrictStr, StrictStr] | None
|
|
|
|
class Config: # pylint: disable=too-few-public-methods
|
|
"""
|
|
Provide an example `link` item
|
|
"""
|
|
schema_extra = {
|
|
"example": r'''{
|
|
"rel": "https://webfinger.net/rel/profile-page/",
|
|
"type": "text/html",
|
|
"href": "https://trwnh.com/~a"
|
|
}'''
|
|
}
|
|
|
|
class JRD(BaseModel):
|
|
"""
|
|
Describes a JSON Resource Descriptor document
|
|
"""
|
|
subject: StrictStr
|
|
aliases: list[StrictStr] | None
|
|
links: list[Link] | None
|
|
properties: dict[StrictStr, StrictStr] | None
|
|
|
|
class Config: # pylint: disable=too-few-public-methods
|
|
"""
|
|
Provide an example JRD document
|
|
"""
|
|
schema_extra = {
|
|
"example": r'''{
|
|
"subject": "acct:a@trwnh.com",
|
|
"aliases": ["https://ap.trwnh.com/actors/7057bc10-db1c-4ebe-9e00-22cf04be4e5e", "https://trwnh.com/~a", "acct:trwnh@ap.trwnh.com"],
|
|
"links": [
|
|
{
|
|
"rel": "self",
|
|
"type": "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
|
|
"href": "https://trwnh.com/actors/7057bc10-db1c-4ebe-9e00-22cf04be4e5e"
|
|
},
|
|
{
|
|
"rel": "https://webfinger.net/rel/profile-page/",
|
|
"type": "text/html",
|
|
"href": "https://trwnh.com/~a"
|
|
}
|
|
]
|
|
}'''
|
|
}
|
|
|
|
class JRDResponse(Response):
|
|
"""
|
|
Specify JRD Content-Type for responding to WebFinger lookup requests
|
|
"""
|
|
media_type = "application/jrd+json" |