mirror of
https://github.com/siop-spelev/siop2.git
synced 2026-08-08 12:41:54 +00:00
- 3 routes publiques /portal (les seules @Public métier), throttlées
(@nestjs/throttler : 10 signalements/min, 60 lectures/min) : résolution
du QR, signalement (retourne un jeton de suivi opaque), suivi par
référence + jeton — pas de jeton, pas de lecture, jamais de liste
- migration r2_portail : Request.publicToken (unique)
- page /q/{réf} fidèle à l'écran 6 validé R0 (mobile d'abord) : équipement
prérempli « détecté par le QR », interrupteur personne bloquée,
suivi sans jargon Reçu → Intervention → Résolu (dérivé de l'OT lié),
rejet affiché « Sans suite : {motif} », photo annoncée (upload R3) ;
signalements gardés sur le téléphone (localStorage, 10 max)
- e2e : LA boucle produit — gardien sans compte → traitement → ✓ Résolu ;
11 tests Playwright verts, 50 tests API, 52 opérations au contrat
- générateur OpenAPI : paramètres non-« id » plus typés uuid
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
99 lines
3.0 KiB
TypeScript
99 lines
3.0 KiB
TypeScript
/**
|
||
* Règle d'or (ADR-001) : Zod → OpenAPI → clients typés.
|
||
* Génère docs/openapi.json (COMMITTÉE) depuis src/contract.ts.
|
||
* Usage : pnpm --filter @siop/shared contract (raccourci racine : pnpm contract)
|
||
* La CI (ci-contract, R0.12) échoue si le fichier committé diffère de la génération.
|
||
*/
|
||
import { mkdirSync, writeFileSync } from 'node:fs';
|
||
import { dirname, resolve } from 'node:path';
|
||
import { z } from 'zod';
|
||
import { API_CONTRACT } from '../src/contract';
|
||
|
||
const OUT = resolve(__dirname, '../../../docs/openapi.json');
|
||
|
||
const schemas: Record<string, unknown> = {};
|
||
|
||
function register(name: string, schema: z.ZodType): { $ref: string } {
|
||
if (!(name in schemas)) {
|
||
schemas[name] = z.toJSONSchema(schema, { target: 'draft-2020-12' });
|
||
}
|
||
return { $ref: `#/components/schemas/${name}` };
|
||
}
|
||
|
||
const paths: Record<string, Record<string, unknown>> = {};
|
||
|
||
for (const op of API_CONTRACT) {
|
||
const responses: Record<string, unknown> = {};
|
||
for (const [status, res] of Object.entries(op.responses)) {
|
||
responses[status] = {
|
||
description: res.description,
|
||
...(res.schema && res.name
|
||
? { content: { 'application/json': { schema: register(res.name, res.schema) } } }
|
||
: {}),
|
||
};
|
||
}
|
||
paths[op.path] = {
|
||
...(paths[op.path] ?? {}),
|
||
[op.method]: {
|
||
operationId: op.operationId,
|
||
summary: op.summary,
|
||
tags: op.tags,
|
||
...(op.pathParams?.length
|
||
? {
|
||
parameters: op.pathParams.map((name) => ({
|
||
name,
|
||
in: 'path',
|
||
required: true,
|
||
// Convention : « id » / «…Id » sont des UUID, le reste est libre
|
||
schema:
|
||
name === 'id' || name.endsWith('Id')
|
||
? { type: 'string', format: 'uuid' }
|
||
: { type: 'string' },
|
||
})),
|
||
}
|
||
: {}),
|
||
...(op.isPublic ? {} : { security: [{ bearerAuth: [] }] }),
|
||
...(op.demoOnly
|
||
? {
|
||
'x-demo-only': true,
|
||
description:
|
||
'ADR-002 : cette route est absente (404) quand DEMO_MODE n’est pas actif.',
|
||
}
|
||
: {}),
|
||
...(op.request
|
||
? {
|
||
requestBody: {
|
||
required: true,
|
||
content: {
|
||
'application/json': { schema: register(op.request.name, op.request.schema) },
|
||
},
|
||
},
|
||
}
|
||
: {}),
|
||
responses,
|
||
},
|
||
};
|
||
}
|
||
|
||
const doc = {
|
||
openapi: '3.1.0',
|
||
info: {
|
||
title: 'SIOP V2 API',
|
||
version: '0.1.0',
|
||
description:
|
||
'GMAO ascenseurs — contrat R0 (auth, démo-login ADR-002, profil, santé). ' +
|
||
'Généré depuis packages/shared/src/contract.ts — NE PAS ÉDITER À LA MAIN.',
|
||
},
|
||
paths,
|
||
components: {
|
||
schemas,
|
||
securitySchemes: {
|
||
bearerAuth: { type: 'http', scheme: 'bearer', bearerFormat: 'JWT' },
|
||
},
|
||
},
|
||
};
|
||
|
||
mkdirSync(dirname(OUT), { recursive: true });
|
||
writeFileSync(OUT, JSON.stringify(doc, null, 2) + '\n');
|
||
console.log(`OpenAPI générée : ${OUT} (${API_CONTRACT.length} opérations)`);
|