API contracts
Русский | English
OpenAPI 3.2.0 is the shared source for HTTP contracts. Change the specification first, then generate server adapters, clients, and models.
Structure
| Directory | API |
|---|---|
| core/ | Public Go API under /api/v1 |
| ml/ | Internal ML API |
| runner/ | Code execution |
| labd/ | Lab environment provisioning |
| testdata/ | Generator compatibility fixture |
Each contract's openapi.yml references routes/ and components/. merge-schemas.py merges schemas grouped by subject, then Redocly builds openapi.bundle.yml. Do not edit derived files by hand.
Generation
Run these commands from the repository root:
make -C api install
make -C api check
make generate
make check-generated
check builds and validates contracts. generate updates every consumer. check-generated detects differences from committed output; it does not run generation itself.
| Consumer | Generator and configuration |
|---|---|
| Go backend | ogen, backend/codegen/ |
| Go runner and labd | ogen, each service's codegen/ directory |
| React | Orval: client, query hooks, Zod schemas, and MSW; frontend/codegen/ |
| Python ML | datamodel-code-generator: Pydantic; ml/codegen/ |
make -C api check-toolchain checks the OpenAPI 3.2 features in a dedicated fixture. It verifies the current toolchain, not every feature of the standard.
Compare the public contract with an existing Git ref using make -C api check-compat API_BASE_REF=<ref>.
Contract conventions
- Errors: RFC 9457,
application/problem+json, stablecode, and safe messages. TheProblemschema defines the response fields. - Sessions: an HttpOnly cookie; mutating session requests also send
X-CSRF-Token. The origin must match the application configuration. - Send
Idempotency-Keywhere the operation requires it. Reuse the key when retrying the same action; use a new key for different content. - Concurrent updates use
If-Matchorexpected_versionas specified by the operation. On conflict, reload server state and preserve the user's draft. - Lists use bounded cursor pagination. Identifiers are UUIDs and timestamps are UTC date-times. An absent field may differ from
null. - Read exact codes, limits, required headers, and examples from each operation and its shared components.
Boundaries
An operation in the specification does not prove its handler is complete. Check backend/internal/adapter/primary/http/v1/ and its tests. An unimplemented operation can return 501 not_implemented.
Internal ML, runner, and labd APIs are not browser entry points. The public health route is /api/v1/healthz; service guides cover operational /healthz, /readyz, and metrics.
See DEVELOPMENT.md for contract changes and TESTING.md for checks.