59 lines
3.0 KiB
Markdown
59 lines
3.0 KiB
Markdown
# API contracts
|
|
|
|
[Русский](README.md) | 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/](core/openapi.yml) | Public Go API under `/api/v1` |
|
|
| [ml/](ml/openapi.yml) | Internal ML API |
|
|
| [runner/](runner/openapi.yml) | Code execution |
|
|
| [labd/](labd/openapi.yml) | Lab environment provisioning |
|
|
| [testdata/](testdata/openapi-3.2.0.yml) | Generator compatibility fixture |
|
|
|
|
Each contract's `openapi.yml` references `routes/` and `components/`. [merge-schemas.py](../scripts/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:
|
|
|
|
```sh
|
|
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/](../backend/codegen/) |
|
|
| Go runner and labd | ogen, each service's `codegen/` directory |
|
|
| React | Orval: client, query hooks, Zod schemas, and MSW; [frontend/codegen/](../frontend/codegen/) |
|
|
| Python ML | datamodel-code-generator: Pydantic; [ml/codegen/](../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`, stable `code`, and safe messages. The `Problem` schema 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-Key` where the operation requires it. Reuse the key when retrying the same action; use a new key for different content.
|
|
- Concurrent updates use `If-Match` or `expected_version` as 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](../docs/en/DEVELOPMENT.md) for contract changes and [TESTING.md](../docs/en/TESTING.md) for checks.
|