API Documentation (Scalar + Swagger UI)
Version: 1.1.0 Date: 2026-07-15
Goal: Expose the neo-backend HTTP API as browsable, interactive documentation so developers (and AI agents) can discover routes, read schemas, paste a Bearer token, and fire real requests.
Solution: Code-first OpenAPI via @nestjs/swagger (CLI plugin with introspectComments). Scalar on /docs, Swagger UI on /swagger. Raw spec at /openapi.json and /openapi.yaml (no /api/v2 prefix, no auth). Doc routes excluded from auth middleware.
Features:
/docs— Scalar UI;/swagger— Swagger UI (persisted authorization)/openapi.json,/openapi.yaml— raw OpenAPI 3 export (Postman, Retool, Scalar MCP)- Bearer token authentication preselected; global security requirement on all protected routes
@ApiStandardErrors()— every documented route declares400/401/403/404/500with realErrorResponseenvelope- Typed
2xxresponses on flagship document endpoints (were empty200before) npm run openapi:generate— offline dump without live DBAPI_PUBLIC_URL— absoluteserversentry for off-origin consumers (Scalar hosted MCP)
Implementation Details:
- Plugin
dtoFileNameSuffixextended to.controller.ts/.type.tsso inline DTOs get schemas @IsOptional()fields marked optional in TS (?) — plugin derivesrequiredfrom optionality, not class-validatorbson/bsonmodule-load redirect inmain.tsfor@nestjs/swagger+ bson@6ObjectIdfieldsnormalizeObjectIdSchema()— 24-hex string instead of empty object in spec- Removed hardcoded
addServer('/api/v2')that double-prefixed Try-it-out requests - Object-array DTO fields (
targetAutoAttributes) expose{code, value}item schemas (Scalar MCP strict clients)
Files Modified:
package.json/package-lock.json-@nestjs/swagger,@scalar/nestjs-api-referencenest-cli.json- Swagger CLI plugin + extended suffix scansrc/main.ts- Spec build, Scalar/Swagger mount, Bearer security, bson redirectsrc/generate-openapi.ts- Offline generator with matching server entry (new)src/app.module.ts- Exclude/docs,/swagger,/openapi.*from auth middlewaresrc/shared/openapi/error-response.dto.ts- Shared error schema (new)src/shared/openapi/api-standard-errors.decorator.ts-@ApiStandardErrors()(new)src/domains/document/document.responses.ts- Document response models (new)src/domains/document/document.controller.ts- Typed responses + query paramssrc/domains/stat/stat.controller.ts- Typed@Query/@Paramsrc/domains/platform/*/*.controller.ts- Standard errors on platform surface.env.example-API_PUBLIC_URL,PROOF_WATCHER_ENABLEDREADME.md- Docs setup and annotation gotchas
Release fragment: feat-api-docs-swagger-scalar