api.html was Swagger UI with the site's colors painted over it — a foreign layout in a black-and-green frame. It is now generated: scripts/build-api-docs.mjs reads api/openapi.yaml and emits the whole reference as static HTML, so the page needs no runtime rendering and no CDN bundle. One card per endpoint (method badge, path, one line of summary) that unfolds into the description, what authentication it wants, the parameter and body tables and the response codes; the named schemas live once in their own section and every type links to them. The chapter rail is the site's own .side markup — the hamburger sheet on a phone, a Contents drawer from 980px up. The generator is deterministic and re-runnable: node scripts/build-api-docs.mjs rewrites website/api.html, and the file says so in its first comment. js-yaml is a build-time devDependency in the repo root; nothing new ships to the browser. Also drops gym.duarte-santos.ch as an example server from the spec. That instance is semi-private, and the docs have no business pointing anyone at it: the servers are now the relative / and a neutral https://opengym.example.com ("your self-hosted instance").
671 lines
32 KiB
JavaScript
671 lines
32 KiB
JavaScript
#!/usr/bin/env node
|
|
// Builds website/api.html — the static API reference — from api/openapi.yaml.
|
|
//
|
|
// node scripts/build-api-docs.mjs
|
|
//
|
|
// Deterministic: the same spec always produces byte-identical output (no
|
|
// timestamps), so re-running it only dirties the file when the spec changed.
|
|
// The page is plain HTML in the site's own design (styles.css + site.js) with
|
|
// native <details> cards per endpoint — no Swagger UI, no runtime rendering.
|
|
//
|
|
// js-yaml lives in the repo-root package.json (devDependency, build-time only).
|
|
|
|
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import yaml from 'js-yaml'
|
|
|
|
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
const specPath = path.join(root, 'api', 'openapi.yaml')
|
|
const outPath = path.join(root, 'website', 'api.html')
|
|
const spec = yaml.load(fs.readFileSync(specPath, 'utf8'))
|
|
|
|
/* ------------------------------------------------------------------ helpers */
|
|
|
|
const esc = s => String(s)
|
|
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"')
|
|
|
|
// The subset of markdown the spec actually uses: `code`, **bold**, *italic*, links.
|
|
const mdInline = s => esc(String(s).trim())
|
|
.replace(/`([^`]+)`/g, '<code>$1</code>')
|
|
.replace(/\*\*([^*]+)\*\*/g, '<b>$1</b>')
|
|
.replace(/(^|[\s(—>])\*([^*\n]+)\*(?=[\s.,;:)—]|$)/g, '$1<i>$2</i>')
|
|
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" rel="noopener">$1</a>')
|
|
|
|
// One description onto one line (for table cells and card subtitles).
|
|
const mdCell = s => mdInline(String(s).replace(/\s*\n\s*/g, ' '))
|
|
|
|
// Block markdown: paragraphs and "- " lists (with wrapped continuation lines).
|
|
function mdBlock (src) {
|
|
const out = []
|
|
let para = [], list = null
|
|
const flushPara = () => { if (para.length) { out.push(`<p>${mdInline(para.join(' '))}</p>`); para = [] } }
|
|
const flushList = () => {
|
|
if (list) { out.push(`<ul>${list.map(li => `<li>${mdInline(li)}</li>`).join('')}</ul>`); list = null }
|
|
}
|
|
for (const raw of String(src).split('\n')) {
|
|
const line = raw.trimEnd()
|
|
if (!line.trim()) { flushPara(); flushList(); continue }
|
|
if (/^- /.test(line.trim()) && !para.length) {
|
|
flushPara()
|
|
list = list || []
|
|
list.push(line.trim().slice(2))
|
|
} else if (list && /^\s/.test(raw)) {
|
|
list[list.length - 1] += ' ' + line.trim()
|
|
} else {
|
|
flushList()
|
|
para.push(line.trim())
|
|
}
|
|
}
|
|
flushPara(); flushList()
|
|
return out.join('\n')
|
|
}
|
|
|
|
const refName = ref => ref.split('/').pop()
|
|
const schemaLink = ref => `<a href="#schema-${refName(ref)}">${esc(refName(ref))}</a>`
|
|
|
|
// A compact, human type for one JSON-schema node.
|
|
function fmtType (s) {
|
|
if (!s) return 'any'
|
|
if (s.$ref) return schemaLink(s.$ref)
|
|
if (s.oneOf) return s.oneOf.map(fmtType).join(' | ')
|
|
if (s.enum) return s.enum.map(v => esc(JSON.stringify(v))).join(' | ')
|
|
if (s.const !== undefined) return `always ${esc(JSON.stringify(s.const))}`
|
|
if (s.type === 'array') {
|
|
const it = s.items ? fmtType(s.items) : 'any'
|
|
return (/[ |]/.test(it.replace(/<[^>]*>/g, '')) ? `(${it})` : it) + '[]'
|
|
}
|
|
let t = Array.isArray(s.type) ? s.type.join(' | ') : (s.type || 'object')
|
|
const bits = []
|
|
if (s.format) bits.push(s.format)
|
|
if (s.maxLength) bits.push(`≤ ${s.maxLength} chars`)
|
|
if (s.minimum !== undefined || s.maximum !== undefined) bits.push(`${s.minimum ?? ''}–${s.maximum ?? ''}`)
|
|
if (s.default !== undefined) bits.push(`default ${esc(JSON.stringify(s.default))}`)
|
|
return esc(t) + (bits.length ? ` <span class="p-hint">(${bits.join(', ')})</span>` : '')
|
|
}
|
|
|
|
// One-line shape signature for a response body: { user: SessionUser }
|
|
function fmtSig (s) {
|
|
if (!s) return ''
|
|
if (s.$ref) return schemaLink(s.$ref)
|
|
if (s.properties) {
|
|
return '{ ' + Object.entries(s.properties)
|
|
.map(([k, v]) => `${esc(k)}: ${fmtType(v)}`).join(', ') + ' }'
|
|
}
|
|
return fmtType(s)
|
|
}
|
|
|
|
// Rows for a property table, nesting one level into objects and object arrays.
|
|
function * propRows (schema, prefix = '', depth = 0) {
|
|
const req = new Set(schema.required || [])
|
|
for (const [k, v] of Object.entries(schema.properties || {})) {
|
|
yield { name: prefix + k, required: req.has(k), type: fmtType(v), desc: v.description || '' }
|
|
if (depth < 2) {
|
|
if (v.type === 'object' && v.properties) yield * propRows(v, `${prefix}${k}.`, depth + 1)
|
|
else if (v.type === 'array' && v.items && v.items.properties) yield * propRows(v.items, `${prefix}${k}[].`, depth + 1)
|
|
}
|
|
}
|
|
}
|
|
|
|
function ptab (rows) {
|
|
if (!rows.length) return ''
|
|
return `<div class="ptab">` + rows.map(r => `
|
|
<div class="prow">
|
|
<span class="p-name">${esc(r.name)}${r.required ? '<em class="p-req" title="required">required</em>' : ''}</span>
|
|
<span class="p-type">${r.type}</span>
|
|
<span class="p-desc">${r.desc ? mdCell(r.desc) : ''}</span>
|
|
</div>`).join('') + `\n</div>`
|
|
}
|
|
|
|
/* ------------------------------------------------------------ endpoint cards */
|
|
|
|
const TAGS = {
|
|
meta: { title: 'Meta', side: 'Health & public config' },
|
|
auth: { title: 'Auth', side: 'Passkeys & sessions' },
|
|
pairing: { title: 'Pairing', side: 'Connect the mobile app' },
|
|
data: { title: 'Data', side: 'State sync' },
|
|
push: { title: 'Push', side: 'Notifications & rest timer' },
|
|
activity: { title: 'Activity', side: 'Live presence' },
|
|
admin: { title: 'Admin', side: 'Users, invites, audit log' }
|
|
}
|
|
|
|
// "Admin: list all users" → "List all users": the section heading and the ADMIN
|
|
// chip already say who may call it, so the prefix is noise on every admin card.
|
|
const sumText = s => {
|
|
const t = String(s || '').replace(/^Admin:\s*/, '')
|
|
return t.charAt(0).toUpperCase() + t.slice(1)
|
|
}
|
|
|
|
function authOf (op, tag) {
|
|
if (Array.isArray(op.security) && op.security.length === 0) {
|
|
return { chip: 'public', line: 'Public — no authentication required.' }
|
|
}
|
|
if (tag === 'admin') {
|
|
return {
|
|
chip: 'admin',
|
|
line: 'Admin only — a signed-in session whose user is an admin (<code>ADMIN_UIDS</code> or <code>admin:true</code>), as the session cookie or a Bearer token.'
|
|
}
|
|
}
|
|
return {
|
|
chip: null,
|
|
line: 'Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer <token></code> from mobile-app pairing.'
|
|
}
|
|
}
|
|
|
|
function responseRows (op) {
|
|
return Object.entries(op.responses || {}).map(([code, r]) => {
|
|
if (r.$ref) r = spec.components.responses[refName(r.$ref)]
|
|
const cls = 's' + code[0]
|
|
const content = r.content && r.content['application/json']
|
|
const extras = []
|
|
if (code.startsWith('2')) {
|
|
if (content && content.schema) extras.push(fmtSig(content.schema))
|
|
if (r.headers) extras.push(`sets <code>${Object.keys(r.headers).map(esc).join('</code>, <code>')}</code>`)
|
|
} else if (content) {
|
|
const exs = []
|
|
if (content.example) exs.push(content.example)
|
|
if (content.examples) for (const e of Object.values(content.examples)) exs.push(e.value)
|
|
if (content.schema && content.schema.example) exs.push(content.schema.example)
|
|
for (const e of exs) if (e && e.error) extras.push(`<code>${esc(JSON.stringify({ error: e.error }))}</code>`)
|
|
}
|
|
return `
|
|
<div class="prow rrow">
|
|
<span class="r-code ${cls}">${esc(code)}</span>
|
|
<span class="p-desc">${mdCell(r.description || '')}${extras.length ? `<span class="r-sig">${extras.join(' · ')}</span>` : ''}</span>
|
|
</div>`
|
|
}).join('')
|
|
}
|
|
|
|
function endpointCard (pathKey, method, op) {
|
|
const tag = (op.tags || [])[0] || 'meta'
|
|
const auth = authOf(op, tag)
|
|
const body = op.requestBody
|
|
const bodySchema = body && body.content && body.content['application/json'] && body.content['application/json'].schema
|
|
const example = bodySchema && (bodySchema.example ?? (body.content['application/json'].example))
|
|
|
|
let bodyHtml = ''
|
|
if (bodySchema) {
|
|
const optional = body.required === false ? ' <span class="p-hint">(optional)</span>' : ''
|
|
if (bodySchema.$ref) {
|
|
bodyHtml = `<p class="ep-h">Request body${optional}</p><p class="p-desc">${schemaLink(bodySchema.$ref)}</p>`
|
|
} else {
|
|
bodyHtml = `<p class="ep-h">Request body <span class="p-hint">(JSON)</span>${optional}</p>` +
|
|
ptab([...propRows(bodySchema)])
|
|
}
|
|
if (example) {
|
|
bodyHtml += `\n<pre><code>${esc(JSON.stringify(example, null, 2))}</code></pre>`
|
|
}
|
|
}
|
|
|
|
const params = (op.parameters || []).map(p => ({
|
|
name: p.name + (p.in && p.in !== 'query' ? ` <span class="p-hint">(${esc(p.in)})</span>` : ''),
|
|
required: !!p.required,
|
|
type: fmtType(p.schema),
|
|
desc: p.description || ''
|
|
}))
|
|
// p.name may contain markup now; ptab escapes r.name — build rows pre-escaped instead:
|
|
const paramTab = params.length
|
|
? `<p class="ep-h">Query parameters</p><div class="ptab">` + params.map(r => `
|
|
<div class="prow">
|
|
<span class="p-name">${r.name}${r.required ? '<em class="p-req" title="required">required</em>' : ''}</span>
|
|
<span class="p-type">${r.type}</span>
|
|
<span class="p-desc">${r.desc ? mdCell(r.desc) : ''}</span>
|
|
</div>`).join('') + `\n</div>`
|
|
: ''
|
|
|
|
return `
|
|
<details class="ep" id="op-${esc(op.operationId)}">
|
|
<summary>
|
|
<span class="m ${method}">${method.toUpperCase()}</span>
|
|
<span class="ep-path"><code>${esc(pathKey)}</code>${auth.chip ? `<span class="ep-chip ${auth.chip}">${auth.chip}</span>` : ''}</span>
|
|
<span class="ep-chev" aria-hidden="true"></span>
|
|
<span class="ep-sum">${mdCell(sumText(op.summary))}</span>
|
|
</summary>
|
|
<div class="ep-body">
|
|
${mdBlock(op.description || '')}
|
|
<p class="ep-auth">${lockSvg}<span>${auth.line}</span></p>
|
|
${paramTab}
|
|
${bodyHtml}
|
|
<p class="ep-h">Responses</p>
|
|
<div class="ptab">${responseRows(op)}
|
|
</div>
|
|
</div>
|
|
</details>`
|
|
}
|
|
|
|
/* -------------------------------------------------------------- schema cards */
|
|
|
|
// A schema has no summary of its own, so the collapsed row borrows the first
|
|
// sentence of its description — and the body then starts at the second, rather
|
|
// than repeating what the reader just read on the way in.
|
|
function schemaCard (name, s) {
|
|
const desc = (s.description || '').trim()
|
|
const flat = desc.replace(/\s*\n\s*/g, ' ')
|
|
const m = flat.match(/^(.+?[.!?])(\s|$)/)
|
|
const lead = m ? m[1] : flat
|
|
const rest = m ? flat.slice(m[0].length).trim() : ''
|
|
const rows = [...propRows(s)]
|
|
return `
|
|
<details class="ep sch" id="schema-${esc(name)}">
|
|
<summary>
|
|
<span class="sch-name"><code>${esc(name)}</code></span>
|
|
<span class="ep-chev" aria-hidden="true"></span>
|
|
<span class="ep-sum">${lead ? mdCell(lead) : ''}</span>
|
|
</summary>
|
|
<div class="ep-body">
|
|
${rest ? mdBlock(rest) : ''}
|
|
${rows.length ? ptab(rows) : '<p class="p-desc">Free-form object.</p>'}
|
|
</div>
|
|
</details>`
|
|
}
|
|
|
|
/* ----------------------------------------------------------------- overview */
|
|
|
|
// The spec's info.description carries "### Heading" sections — each becomes a card.
|
|
const infoParts = spec.info.description.split(/^### /m).slice(1).map(chunk => {
|
|
const nl = chunk.indexOf('\n')
|
|
return { title: chunk.slice(0, nl).trim(), body: chunk.slice(nl + 1) }
|
|
})
|
|
|
|
const serversHtml = spec.servers.map(s => `
|
|
<div class="srv-row"><code>${esc(s.url)}</code><span>${mdCell(s.description || '')}</span></div>`).join('')
|
|
|
|
const overviewCards = infoParts.map(p => `
|
|
<div class="ov">
|
|
<h3>${esc(p.title)}</h3>
|
|
${mdBlock(p.body)}
|
|
</div>`).join('')
|
|
|
|
/* ---------------------------------------------------------------- assemble */
|
|
|
|
const lockSvg = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg>'
|
|
|
|
const ops = []
|
|
for (const [p, methods] of Object.entries(spec.paths)) {
|
|
for (const [m, op] of Object.entries(methods)) ops.push({ path: p, method: m, op })
|
|
}
|
|
|
|
const tagSections = Object.keys(TAGS).map(tag => {
|
|
const t = spec.tags.find(x => x.name === tag) || {}
|
|
const cards = ops.filter(o => (o.op.tags || [])[0] === tag)
|
|
.map(o => endpointCard(o.path, o.method, o.op)).join('\n')
|
|
return `
|
|
<section class="api-sec" id="${tag}">
|
|
<h2>${TAGS[tag].title}</h2>
|
|
<p class="sub">${mdCell(t.description || '')}</p>
|
|
<div class="eps">
|
|
${cards}
|
|
</div>
|
|
</section>`
|
|
}).join('\n')
|
|
|
|
const schemaCards = Object.entries(spec.components.schemas)
|
|
.map(([n, s]) => schemaCard(n, s)).join('\n')
|
|
|
|
const railTags = Object.keys(TAGS).map(tag =>
|
|
` <a class="side-link" href="#${tag}"><b>${TAGS[tag].title}</b><span>${TAGS[tag].side}</span></a>`
|
|
).join('\n')
|
|
|
|
const css = `
|
|
/* ------------------------------------------------------------- API reference
|
|
Generated page — the reference itself is static HTML in the site's design.
|
|
Layout: one 880px column of per-endpoint <details> cards. */
|
|
main.api-main { max-width: 880px; margin: 0 auto; padding: clamp(44px, 7vw, 72px) var(--pad) 0; }
|
|
main.api-main h1 { font-size: clamp(36px, 6.5vw, 60px); letter-spacing: -.03em; }
|
|
main.api-main .lead { color: var(--fg-2); max-width: 58ch; margin: 14px 0 0; font-size: clamp(16.5px, 2vw, 19px); }
|
|
.api-actions { margin-top: 26px; }
|
|
.api-actions .btn svg { width: 17px; height: 17px; }
|
|
.api-facts { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-top: 20px; color: var(--fg-3); font-size: 13.5px; }
|
|
.api-facts span::after { content: "·"; margin-left: 10px; color: var(--fg-3); }
|
|
.api-facts span:last-child::after { content: ""; margin-left: 0; }
|
|
|
|
.api-sec { padding: 0; margin-top: clamp(46px, 7vw, 68px); }
|
|
.api-sec h2 { font-size: clamp(24px, 3.4vw, 32px); scroll-margin-top: 76px; }
|
|
.api-sec .sub { color: var(--fg-2); font-size: 15.5px; margin-top: 6px; max-width: 62ch; }
|
|
.api-sec .sub code, .ov code, .ep-auth code {
|
|
background: var(--surface-2); border-radius: 5px; padding: 1.5px 5px; font-size: .85em; color: #e4e4e8;
|
|
}
|
|
|
|
/* base URLs */
|
|
.srv { margin-top: 20px; border: 1px solid var(--hair-soft); border-radius: var(--r-s); background: var(--surface); overflow: hidden; }
|
|
.srv-row { display: flex; flex-wrap: wrap; gap: 2px 16px; align-items: baseline; padding: 12px 16px; }
|
|
.srv-row + .srv-row { border-top: 1px solid var(--hair-soft); }
|
|
.srv-row > code { font-size: 13.5px; color: var(--acc); }
|
|
.srv-row > span { color: var(--fg-3); font-size: 13.5px; }
|
|
|
|
/* overview cards (from the spec's info sections) */
|
|
/* align-items:start, so a short card stops at its own last line instead of
|
|
stretching to its neighbour's height and showing a panel of empty background. */
|
|
.ov-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 12px; margin-top: 18px; }
|
|
.ov { background: var(--surface); border: 1px solid var(--hair-soft); border-radius: var(--r-m); padding: 20px 22px; }
|
|
.ov h3 { font-size: 15.5px; margin-bottom: 8px; }
|
|
.ov p, .ov li { color: var(--fg-2); font-size: 14px; line-height: 1.55; }
|
|
.ov p + p, .ov p + ul { margin-top: 8px; }
|
|
.ov ul { padding-left: 18px; margin: 0; }
|
|
.ov li { margin: 5px 0; }
|
|
.ov li::marker { color: var(--fg-3); }
|
|
.ov:last-child:nth-child(odd) { grid-column: 1 / -1; }
|
|
@media (max-width: 720px) { .ov-grid { grid-template-columns: 1fr; } }
|
|
|
|
/* expand / collapse all */
|
|
.xall { display: flex; gap: 16px; justify-content: flex-end; margin: 30px 0 -34px; }
|
|
.xall button { color: var(--fg-3); font-size: 13px; cursor: pointer; padding: 4px 0; transition: color .2s var(--ease); }
|
|
.xall button:hover { color: var(--fg); }
|
|
|
|
/* endpoint + schema cards */
|
|
.eps { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
|
|
.ep { background: var(--surface); border: 1px solid var(--hair-soft); border-radius: var(--r-s); scroll-margin-top: 70px; transition: border-color .25s var(--ease); }
|
|
.ep:hover, .ep[open] { border-color: var(--hair); }
|
|
.ep > summary { list-style: none; cursor: pointer; padding: 12px 16px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; column-gap: 12px; row-gap: 2px; align-items: center; }
|
|
.ep > summary::-webkit-details-marker { display: none; }
|
|
.m { justify-self: start; min-width: 52px; text-align: center; padding: 3px 8px; border-radius: 7px; font-size: 11px; font-weight: 700; letter-spacing: .05em; font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace; }
|
|
.m.get { color: #6cb2ff; background: rgba(108, 178, 255, .12); }
|
|
.m.post { color: var(--acc); background: var(--acc-soft); }
|
|
.m.put { color: #ffb340; background: rgba(255, 159, 10, .14); }
|
|
.m.delete, .m.patch { color: #ff6b5e; background: rgba(255, 80, 60, .12); }
|
|
.ep-path { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
|
|
.ep-path code, .sch-name code { font-size: 13.5px; color: var(--fg); word-break: break-all; }
|
|
.ep-chip { font-size: 10px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; padding: 2px 7px; border-radius: 6px; }
|
|
.ep-chip.public { color: var(--fg-2); background: rgba(255, 255, 255, .07); }
|
|
.ep-chip.admin { color: #ffb340; background: rgba(255, 159, 10, .12); }
|
|
.ep-chev { width: 8px; height: 8px; border-right: 1.6px solid var(--fg-3); border-bottom: 1.6px solid var(--fg-3); transform: rotate(45deg) translate(-1px, -1px); transition: transform .25s var(--ease); }
|
|
.ep[open] > summary .ep-chev { transform: rotate(225deg); }
|
|
.ep-sum { grid-column: 2 / -1; color: var(--fg-3); font-size: 13.5px; line-height: 1.45; }
|
|
.ep-body { border-top: 1px solid var(--hair-soft); padding: 16px 16px 18px; }
|
|
/* WebAuthn type names run to 34 characters. On a phone they are wider than the
|
|
card, so every prose block in here is allowed to break inside a word. */
|
|
.ep-body > p, .ep-body > ul li, .ov p, .ov li, .p-desc, .api-sec .sub, .ep-auth,
|
|
.ep-path code, .sch-name code, .p-name, .p-type { overflow-wrap: break-word; }
|
|
.ep-body > p { color: var(--fg-2); font-size: 14.5px; line-height: 1.65; margin: 0 0 10px; max-width: 74ch; }
|
|
.ep-body > ul { margin: 0 0 10px; padding-left: 20px; }
|
|
.ep-body > ul li { color: var(--fg-2); font-size: 14.5px; line-height: 1.65; margin: 4px 0; }
|
|
/* Identifiers are half of every sentence in an API description: as full chips they
|
|
turn a paragraph into confetti, so here they are monospace with a hairline tint. */
|
|
.ep-body p code, .ep-body li code, .ov p code, .ov li code, .api-sec .sub code,
|
|
.ep-auth code, .p-desc code {
|
|
background: rgba(255, 255, 255, .05); border-radius: 4px; padding: 0 3px;
|
|
font-size: .9em; line-height: inherit; color: #d8dee2;
|
|
}
|
|
/* Grid, not flex: the sentence wraps around code chips, and a flex row would
|
|
centre the whole wrapped block against the padlock and stagger the lines. */
|
|
.ep-auth { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: 8px; color: var(--fg-3); font-size: 13px; line-height: 1.6; margin: 14px 0 0 !important; }
|
|
.ep-auth svg { width: 13px; height: 13px; margin-top: 3px; }
|
|
.ep-h { font-size: 11.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-3); margin: 18px 0 8px !important; }
|
|
.p-hint { color: var(--fg-3); font-weight: 400; text-transform: none; letter-spacing: 0; }
|
|
|
|
/* parameter / response tables */
|
|
.ptab { border: 1px solid var(--hair-soft); border-radius: 10px; overflow: hidden; }
|
|
.prow { display: grid; grid-template-columns: minmax(140px, 220px) minmax(110px, 200px) 1fr; gap: 3px 14px; padding: 10px 14px; font-size: 13.5px; }
|
|
.prow + .prow { border-top: 1px solid var(--hair-soft); }
|
|
.p-name { font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; color: var(--fg); word-break: break-all; }
|
|
.p-req { font-style: normal; color: #ffb340; font-size: 10.5px; margin-left: 7px; letter-spacing: .04em; }
|
|
.p-type { font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--fg-3); word-break: break-word; }
|
|
.p-type a, .r-sig a, .p-desc a { color: var(--acc); }
|
|
.p-desc { color: var(--fg-2); line-height: 1.5; }
|
|
.rrow { grid-template-columns: 44px 1fr; }
|
|
.r-code { font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; font-weight: 600; }
|
|
.r-code.s2 { color: var(--acc); } .r-code.s3 { color: #6cb2ff; }
|
|
.r-code.s4 { color: #ffb340; } .r-code.s5 { color: #ff6b5e; }
|
|
.r-sig { display: block; margin-top: 4px; font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace; font-size: 11.5px; color: var(--fg-3); word-break: break-word; line-height: 1.6; }
|
|
.r-sig code, .p-type code { background: none; padding: 0; color: inherit; font-size: inherit; }
|
|
.ep-body pre { margin: 8px 0 2px; padding: 12px 14px; font-size: 12.5px; }
|
|
@media (max-width: 680px) {
|
|
.prow { grid-template-columns: minmax(0, 1fr) auto; }
|
|
.prow .p-desc { grid-column: 1 / -1; margin-top: 1px; }
|
|
.rrow { grid-template-columns: 44px 1fr; }
|
|
.rrow .p-desc { grid-column: auto; margin-top: 0; }
|
|
}
|
|
|
|
/* schema cards */
|
|
.sch > summary { grid-template-columns: minmax(0, 1fr) auto; }
|
|
.sch .ep-sum { grid-column: 1 / -1; }
|
|
|
|
/* --------------------------------------------------- contents drawer (rail)
|
|
The chapter rail is closed by default. Below 980px it is the hamburger sheet
|
|
the whole site uses; from 980px up a quiet "Contents" pill opens it as a
|
|
drawer over the left edge, with a close button inside. The .toc-btn /
|
|
.rail-close / body.contents-open classes are the reusable pattern. */
|
|
.toc-btn { display: none; }
|
|
@media (min-width: 980px) {
|
|
.toc-btn {
|
|
position: fixed; left: 18px; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 62;
|
|
display: inline-flex; align-items: center; gap: 8px;
|
|
padding: 10px 17px 10px 15px; border-radius: 999px; cursor: pointer;
|
|
background: rgba(23, 24, 27, .85);
|
|
backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
|
|
border: 1px solid var(--hair); color: var(--fg-2);
|
|
font-size: 13.5px; font-weight: 500; letter-spacing: -.01em;
|
|
transition: color .2s var(--ease), border-color .2s var(--ease), background-color .2s var(--ease);
|
|
}
|
|
.toc-btn:hover { color: var(--fg); border-color: rgba(255, 255, 255, .25); background: rgba(32, 33, 37, .92); }
|
|
.toc-btn svg { width: 15px; height: 15px; }
|
|
|
|
body.topnav .side {
|
|
display: block; position: fixed; left: 0; right: auto; top: 0; bottom: 0; z-index: 80;
|
|
width: min(320px, 86vw); max-height: none;
|
|
padding: 58px 24px calc(34px + env(safe-area-inset-bottom)) calc(26px + env(safe-area-inset-left));
|
|
background: #0a0b0c; border-right: 1px solid var(--hair-soft); border-bottom: 0;
|
|
overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
|
|
box-shadow: 40px 0 80px rgba(0, 0, 0, .5);
|
|
transform: translateX(-102%); visibility: hidden; opacity: 1; pointer-events: auto;
|
|
transition: transform .32s var(--ease), visibility .32s;
|
|
}
|
|
body.topnav.contents-open .side { transform: none; visibility: visible; }
|
|
body.contents-open::after {
|
|
content: ""; position: fixed; inset: 0; z-index: 75;
|
|
background: rgba(0, 0, 0, .55);
|
|
backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
|
|
opacity: 1; pointer-events: auto;
|
|
}
|
|
.rail-close {
|
|
position: absolute; top: 14px; right: 12px; width: 34px; height: 34px;
|
|
display: flex; align-items: center; justify-content: center;
|
|
border-radius: 9px; color: var(--fg-3); cursor: pointer;
|
|
transition: color .2s var(--ease), background-color .2s var(--ease);
|
|
}
|
|
.rail-close:hover { color: var(--fg); background: rgba(255, 255, 255, .06); }
|
|
.rail-close svg { width: 15px; height: 15px; }
|
|
}
|
|
@media (max-width: 979.98px) { .rail-close { display: none; } }
|
|
/* Self-sufficiency: with the rail closed the page never reserves rail space. */
|
|
@media (min-width: 1300px) { body.topnav { padding-left: 0; } }
|
|
@media (prefers-reduced-motion: reduce) { body.topnav .side { transition-duration: .01ms; } }
|
|
`
|
|
|
|
const js = `
|
|
/* Contents drawer (>=980px; below that the hamburger sheet in site.js owns the rail). */
|
|
;(() => {
|
|
const body = document.body
|
|
const btn = document.querySelector('.toc-btn')
|
|
const menu = document.getElementById('menu')
|
|
if (!btn || !menu) return
|
|
const set = open => {
|
|
body.classList.toggle('contents-open', open)
|
|
btn.setAttribute('aria-expanded', String(open))
|
|
body.style.overflow = open ? 'hidden' : ''
|
|
}
|
|
btn.addEventListener('click', e => { e.stopPropagation(); set(!body.classList.contains('contents-open')) })
|
|
menu.querySelector('.rail-close')?.addEventListener('click', () => set(false))
|
|
document.addEventListener('click', e => {
|
|
if (!body.classList.contains('contents-open')) return
|
|
if (e.target.closest('#menu') || e.target.closest('.toc-btn')) return
|
|
set(false)
|
|
})
|
|
menu.addEventListener('click', e => { if (e.target.closest('a')) set(false) })
|
|
document.addEventListener('keydown', e => { if (e.key === 'Escape') set(false) })
|
|
addEventListener('resize', () => {
|
|
if (innerWidth < 980) set(false)
|
|
else {
|
|
// crossing up: make sure a hamburger-opened sheet doesn't linger
|
|
body.classList.remove('menu-open'); menu.classList.remove('open')
|
|
if (!body.classList.contains('contents-open')) body.style.overflow = ''
|
|
}
|
|
})
|
|
})()
|
|
|
|
/* Jumping to an anchor inside a collapsed card opens the card — and re-aligns, since
|
|
the browser scrolled to where the target was while it was still collapsed. */
|
|
;(() => {
|
|
const openTo = id => {
|
|
const el = id && document.getElementById(id)
|
|
if (!el) return
|
|
let opened = false
|
|
for (let d = el.closest('details'); d; d = d.parentElement && d.parentElement.closest('details')) {
|
|
if (!d.open) { d.open = true; opened = true }
|
|
}
|
|
// 'instant' on purpose: html has scroll-behavior:smooth, and an animated
|
|
// re-align races the jump the browser already started.
|
|
if (opened) requestAnimationFrame(() => el.scrollIntoView({ block: 'start', behavior: 'instant' }))
|
|
}
|
|
addEventListener('hashchange', () => openTo(location.hash.slice(1)))
|
|
document.addEventListener('click', e => {
|
|
const a = e.target.closest('a[href^="#"]')
|
|
if (a) openTo(a.getAttribute('href').slice(1))
|
|
})
|
|
openTo(location.hash.slice(1))
|
|
})()
|
|
|
|
/* Expand / collapse every card at once. */
|
|
document.querySelectorAll('[data-xall]').forEach(b => b.addEventListener('click', () => {
|
|
document.querySelectorAll('details.ep').forEach(d => { d.open = b.dataset.xall === '1' })
|
|
}))
|
|
`
|
|
|
|
const html = `<!DOCTYPE html>
|
|
<!-- GENERATED FILE - do not edit by hand.
|
|
Built by scripts/build-api-docs.mjs from api/openapi.yaml (openGym API v${spec.info.version}).
|
|
Regenerate with: node scripts/build-api-docs.mjs -->
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
|
|
<title>API — openGym</title>
|
|
<meta name="description" content="The complete openGym HTTP API, documented as an OpenAPI spec: passkey auth, state sync, push notifications, pairing and admin routes.">
|
|
<meta name="theme-color" content="#000000">
|
|
<meta property="og:title" content="openGym API reference">
|
|
<meta property="og:description" content="The complete openGym HTTP API as an OpenAPI spec: passkey auth, state sync, push notifications, pairing and admin routes.">
|
|
<meta property="og:image" content="https://opengym.duarte-santos.ch/img/banner.png">
|
|
<meta property="og:url" content="https://opengym.duarte-santos.ch/api.html">
|
|
<meta property="og:type" content="website">
|
|
<meta property="og:site_name" content="openGym">
|
|
<meta name="twitter:card" content="summary_large_image">
|
|
<meta name="twitter:title" content="openGym API reference">
|
|
<meta name="twitter:image" content="https://opengym.duarte-santos.ch/img/banner.png">
|
|
<link rel="canonical" href="https://opengym.duarte-santos.ch/api.html">
|
|
<link rel="icon" type="image/png" sizes="512x512" href="icon-512.png">
|
|
<link rel="icon" type="image/png" sizes="180x180" href="icon-180.png">
|
|
<link rel="apple-touch-icon" href="icon-180.png">
|
|
<link rel="stylesheet" href="styles.css?v=11">
|
|
<script>document.documentElement.className += ' js'</script>
|
|
<!-- Umami web analytics for opengym.duarte-santos.ch (self-hosted, cookieless). -->
|
|
<script defer src="https://stats.duarte-santos.ch/script.js" data-website-id="db36019e-50f4-453c-9c56-d0588aefe233"></script>
|
|
<style>${css}</style>
|
|
</head>
|
|
<body class="topnav">
|
|
|
|
<nav><div class="wrap nav-in">
|
|
<a class="brand" href="/">
|
|
<img src="icon-180.png" alt="" width="24" height="24">
|
|
openGym
|
|
</a>
|
|
<div class="nav-quick">
|
|
<a class="ql site" href="/#features">Features</a>
|
|
<a class="ql site" href="/#screens">Screenshots</a>
|
|
<a class="ql site" href="/#demo">Demo</a>
|
|
<a class="ql site" href="docs.html">Docs</a>
|
|
<a class="ql site" href="api.html">API</a>
|
|
<a class="ql site" href="about.html">About</a>
|
|
<a class="ql" href="https://gitlab.com/DuarteSantos8/opengym" rel="noopener">GitLab <span data-gh="stars"></span></a>
|
|
<a class="ql" href="https://discord.gg/e62jY6fwVb" rel="noopener">Discord</a>
|
|
<a class="cta" href="/#download">Download</a>
|
|
</div>
|
|
<button class="nav-toggle" aria-expanded="false" aria-controls="menu" aria-label="Menu">
|
|
<span></span><span></span>
|
|
</button>
|
|
</div></nav>
|
|
|
|
<!-- The chapter rail. Closed by default: the Contents pill opens it as a drawer
|
|
from 980px up; below that it is the hamburger sheet like everywhere else. -->
|
|
<aside class="side" id="menu" aria-label="API chapters">
|
|
<button class="rail-close" aria-label="Close contents"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M5 5l14 14M19 5L5 19"/></svg></button>
|
|
<p class="side-label">On this page</p>
|
|
<a class="side-link" href="#overview"><b>Overview</b><span>Auth model, sessions, conventions</span></a>
|
|
${railTags}
|
|
<a class="side-link" href="#schemas"><b>Schemas</b><span>The state blob, the error shape & co.</span></a>
|
|
<p class="side-label">More</p>
|
|
<a class="side-link" href="/"><b>Home</b><span>The tour, the demo, the download</span></a>
|
|
<a class="side-link" href="docs.html"><b>Docs</b><span>Install, self-host, import</span></a>
|
|
<a class="side-link" href="about.html"><b>About</b><span>The story and the milestones</span></a>
|
|
</aside>
|
|
|
|
<button class="toc-btn" aria-controls="menu" aria-expanded="false">
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M4 6h16M4 12h16M4 18h10"/></svg>
|
|
Contents
|
|
</button>
|
|
|
|
<main class="api-main">
|
|
<h1>API</h1>
|
|
<p class="lead">Every route the openGym backend serves — passkey auth, state sync,
|
|
push, pairing, admin — as one hand-written
|
|
OpenAPI spec. The same file lives
|
|
<a href="https://gitlab.com/DuarteSantos8/opengym/-/blob/main/api/openapi.yaml" rel="noopener">in the repository</a>
|
|
at <code>api/openapi.yaml</code>, next to the one server file it documents.</p>
|
|
<div class="actions api-actions">
|
|
<a class="btn" href="openapi.yaml" download>
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3v12m0 0l-5-5m5 5l5-5M4 19h16"/></svg>
|
|
Download openapi.yaml</a>
|
|
</div>
|
|
<p class="api-facts">
|
|
<span>OpenAPI ${esc(spec.openapi)}</span>
|
|
<span>openGym v${esc(spec.info.version)}</span>
|
|
<span>${ops.length} endpoints</span>
|
|
<span>${esc(spec.info.license.name)}</span>
|
|
</p>
|
|
|
|
<section class="api-sec" id="overview">
|
|
<h2>Overview</h2>
|
|
<p class="sub">${mdCell(spec.info.summary)}. One Node file, no framework, JSON-file
|
|
storage, HMAC-signed session cookies.</p>
|
|
<div class="srv">${serversHtml}
|
|
</div>
|
|
<div class="ov-grid">${overviewCards}
|
|
</div>
|
|
</section>
|
|
|
|
<div class="xall" aria-label="Card controls">
|
|
<button data-xall="1">Expand all</button>
|
|
<button data-xall="0">Collapse all</button>
|
|
</div>
|
|
${tagSections}
|
|
|
|
<section class="api-sec" id="schemas">
|
|
<h2>Schemas</h2>
|
|
<p class="sub">The named shapes the endpoints above link to. The <code>State</code> blob
|
|
is <b>representative, not enforced</b> — the server stores it opaquely and the app
|
|
grows it over time.</p>
|
|
<div class="eps">
|
|
${schemaCards}
|
|
</div>
|
|
</section>
|
|
</main>
|
|
|
|
<footer><div class="wrap foot">
|
|
<span class="c">openGym · AGPL-3.0 · © 2026 <a href="https://duarte-santos.ch" rel="noopener">Duarte Santos</a></span>
|
|
<div class="links">
|
|
<a href="docs.html">Docs</a>
|
|
<a href="about.html">About</a>
|
|
<a href="https://gitlab.com/DuarteSantos8/opengym" rel="noopener">GitLab</a>
|
|
<a href="https://discord.gg/e62jY6fwVb" rel="noopener">Discord</a>
|
|
<a href="/#download">Download</a>
|
|
</div>
|
|
</div></footer>
|
|
|
|
<script src="site.js?v=11" defer></script>
|
|
<script>${js}</script>
|
|
</body>
|
|
</html>
|
|
`
|
|
|
|
fs.writeFileSync(outPath, html)
|
|
console.log(`wrote ${path.relative(root, outPath)} — ${ops.length} endpoints, ${Object.keys(spec.components.schemas).length} schemas, ${(html.length / 1024).toFixed(1)} KB`)
|