57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
# retoor <retoor@molodetz.nl>
|
|
ROLE_BY_AUTH = {"public": "guest", "member": "Member", "admin": "Admin"}
|
|
|
|
TARGET_TYPES = ("post", "join_request", "user")
|
|
|
|
|
|
def field(name, type="string", required=False, description="", enum=None, example=None, location="body"):
|
|
return {
|
|
"name": name,
|
|
"type": type,
|
|
"required": required,
|
|
"description": description,
|
|
"enum": list(enum or []),
|
|
"example": example,
|
|
"location": location,
|
|
}
|
|
|
|
|
|
def endpoint(
|
|
method,
|
|
path,
|
|
title,
|
|
description="",
|
|
auth="public",
|
|
fields=None,
|
|
sample=None,
|
|
negotiation="negotiable",
|
|
destructive=False,
|
|
interactive=True,
|
|
probe_path=None,
|
|
probe_body=None,
|
|
):
|
|
return {
|
|
"method": method,
|
|
"path": path,
|
|
"title": title,
|
|
"description": description,
|
|
"auth": auth,
|
|
"min_role": ROLE_BY_AUTH[auth],
|
|
"fields": list(fields or []),
|
|
"sample": sample,
|
|
"negotiation": negotiation,
|
|
"destructive": destructive,
|
|
"interactive": interactive,
|
|
"probe_path": probe_path or path,
|
|
"probe_body": probe_body,
|
|
}
|
|
|
|
|
|
def substitute(text, base="", username="", api_key="", app_reference="molodetz-docs-v-1-0-0"):
|
|
return (
|
|
text.replace("{{base}}", base)
|
|
.replace("{{username}}", username)
|
|
.replace("{{api_key}}", api_key)
|
|
.replace("{{app_reference}}", app_reference)
|
|
)
|