SPB Git

Repository Public

openapi.ts 4.1 KB 61 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : MacLustr Social Engine & Remote Navigator8 * File             : services/control-api/src/openapi.ts9 * Module           : services10 * Repository       : https://git.spboucher.ai/maclustr-social11 * Project Website  : https://social.spboucher.ai12 * Created          : 2026-12-0113 * Last Modified    : 2026-12-0114 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import { z } from '@mls/contracts';43import type { RouteDoc } from './app.ts';44export function buildOpenApi(docs: RouteDoc[], includeInternal = false) {45  const paths: Record<string, any> = {};46  for (const d of docs) {47    if (!includeInternal && d.tag === 'internal') continue;48    const path = d.path.replace(/:(\w+)/g, '{$1}');49    const params = [...d.path.matchAll(/:(\w+)/g)].map((m) => ({ name: m[1], in: 'path', required: true, schema: { type: 'string' } }));50    const op: any = { summary: d.summary, tags: [d.tag], parameters: params, 'x-auth': d.auth, ...(d.role ? { 'x-min-role': d.role } : {}),51      security: d.auth === 'user' ? [{ sessionCookie: [], csrfHeader: [] }] : d.auth === 'worker' ? [{ workerToken: [] }] : d.auth === 'service' ? [{ serviceToken: [] }] : [],52      responses: { 200: { description: 'OK' }, 400: { $ref: '#/components/responses/Error' }, 401: { $ref: '#/components/responses/Error' }, 403: { $ref: '#/components/responses/Error' }, 404: { $ref: '#/components/responses/Error' }, 409: { $ref: '#/components/responses/Error' }, 429: { $ref: '#/components/responses/Error' } } };53    if (d.body) { try { op.requestBody = { required: true, content: { 'application/json': { schema: z.toJSONSchema(d.body, { unrepresentable: 'any', io: 'input' }) } } }; } catch { op.requestBody = { required: true, content: { 'application/json': { schema: {} } } }; } }54    (paths[path] ??= {})[d.method.toLowerCase()] = op;55  }56  return { openapi: '3.1.0', info: { title: 'MacLustr Social Engine & Remote Navigator — API interne', version: '0.1.0', description: 'API MacLustr (pas une API Meta). Sessions par cookie HttpOnly lié à l’hôte ; toute requête mutante exige l’en-tête x-csrf. Aucune route n’accepte de JavaScript, de shell, de XPath ou de sélecteur CSS.' },57    servers: [{ url: 'https://social.spboucher.ai' }, { url: 'https://navigator.spboucher.ai' }], paths,58    components: { securitySchemes: { sessionCookie: { type: 'apiKey', in: 'cookie', name: '__Host-mls' }, csrfHeader: { type: 'apiKey', in: 'header', name: 'x-csrf' }, workerToken: { type: 'http', scheme: 'bearer' }, serviceToken: { type: 'http', scheme: 'bearer' } },59      responses: { Error: { description: 'Erreur structurée', content: { 'application/json': { schema: { type: 'object', required: ['error'], properties: { error: { type: 'object', required: ['code', 'message'], properties: { code: { type: 'string' }, message: { type: 'string' }, correlationId: { type: 'string' }, details: {} } } } } } } } } } };60}61
Files main
Menu

Theme