feat(api): add specialization catalog and candidate questionnaire contract
This commit is contained in:
1 parent
c338c0c188
commit
faeeb5f157
64 files changed
+8339
-47
No files matched your search
+31
-2
@@ -34,7 +34,7 @@ Every error is an RFC 9457 problem with the `application/problem+json` media typ
|
||||
| `method_not_allowed` | 405 | Unsupported method; see `Allow` |
|
||||
| `idempotency_in_progress` | 409 | A request with the same Idempotency-Key is still running |
|
||||
| `state_conflict` | 409 | The operation is not allowed in the current state of the resource |
|
||||
| `version_conflict` | 412 | If-Match does not match the current version |
|
||||
| `version_conflict` | 412 | If-Match, or a body `expected_version`, does not match the current version |
|
||||
| `payload_too_large` | 413 | The body exceeds the operation limit |
|
||||
| `unsupported_media_type` | 415 | The request Content-Type is not accepted |
|
||||
| `idempotency_key_reused` | 422 | The Idempotency-Key was used with a different request |
|
||||
@@ -73,7 +73,7 @@ Because the replay check comes before If-Match, a retry of a completed change re
|
||||
|
||||
### Versions: ETag and If-Match
|
||||
|
||||
A response with a versioned resource returns a strong `ETag`, for example `"v7"`. An operation that changes such a resource says in its description that it requires `If-Match` with that value. A missing value returns 428 `precondition_required`; a value that does not equal the current ETag returns 412 `version_conflict` and changes nothing. The parameter is optional in the schema so that a missing header reaches the application, which answers 428. Weak tags, lists, and `*` fail validation with 400.
|
||||
A response with a versioned resource returns a strong `ETag`, for example `"v7"`. An operation that changes such a resource says in its description that it requires `If-Match` with that value. A missing value returns 428 `precondition_required`; a value that does not equal the current ETag returns 412 `version_conflict` and changes nothing. The parameter is optional in the schema so that a missing header reaches the application, which answers 428. Weak tags, lists, and `*` fail validation with 400. The questionnaire carries its version as `expected_version` in the body instead; see Catalog and questionnaire below.
|
||||
|
||||
### Pagination
|
||||
|
||||
@@ -135,6 +135,34 @@ How the generated server (ogen v1.24.0) evaluates the schemes, and the mapping p
|
||||
- Any other handler error stops evaluation and reaches `NewError` as a `SecurityError` whose `Security` is `SessionCookie` or `SessionCsrf`. An unsatisfied requirement reaches `NewError` as a `SecurityError` with `ErrSecurityRequirementIsNotSatisfied` and no `Security` field.
|
||||
- Planned mapping: `HandleSessionCookie` skips a missing or invalid session; `HandleSessionCsrf` skips when the context has no principal (401) and returns a typed error for a wrong token. `NewError` maps a `SessionCsrf` error and an unsatisfied requirement with a principal in the context to 403 `csrf_check_failed`, and every other security failure to 401 `unauthenticated`. A 401 from `Logout` also clears the cookie.
|
||||
|
||||
### Catalog and questionnaire
|
||||
|
||||
The `catalog` and `candidate` tags cover the specialization catalog and the candidate questionnaire (PRD FR03). The operations are in the contract; their business logic is not implemented yet, so the catalog answers 501 `not_implemented` and the questionnaire answers 401 `unauthenticated` until sessions exist (`v1.DenyAllSecurity`).
|
||||
|
||||
| Method and path | operationId | Security | Success | Specific errors |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `GET /api/v1/specializations` | `GetSpecializationCatalog` | public | 200 `SpecializationCatalog` | none |
|
||||
| `GET /api/v1/me/questionnaire` | `GetMyQuestionnaire` | session | 200 `CandidateQuestionnaire`, `Cache-Control: no-store` | 401 `unauthenticated`, 403 `forbidden` |
|
||||
| `PUT /api/v1/me/questionnaire` | `SaveMyQuestionnaire` | session and CSRF | 200 `CandidateQuestionnaire`, `Cache-Control: no-store` | 400 `validation_failed`, 401, 403 `csrf_check_failed` or `forbidden`, 412 `version_conflict` |
|
||||
|
||||
Every operation also declares the `default` problem response.
|
||||
|
||||
Catalog:
|
||||
|
||||
- Five directions and nine specializations: Development (`backend`, `frontend`, `mobile`), Infrastructure (`network_engineer`, `devops_sre`), Data (`data_analyst`, `ds_ml`), Security (`information_security`), Quality (`qa`). The MVP grade scale is `intern`, `junior`, `middle`, `senior`; Lead and Architect come after the MVP. The codes are enums, so adding a value is a contract change. Titles are Russian plain text.
|
||||
- A category is a specialization together with a confirmed grade. Task languages (`python`, `go`) and stack tags are attributes of a chosen specialization and never form a category: Backend with Go is the category `backend`. Algorithms is a shared assessment module, not a specialization.
|
||||
- Each specialization has `test_availability`: `status` (`available` or `in_development`), the `grades` with a published task bank, and the `task_languages` that bank offers. The MVP opens an assessment only for a category with a published bank. The server derives the values from the published banks, so they change without a contract change; the example in the contract is illustrative and says nothing about a deployed bank.
|
||||
- The catalog is public (`security: []`): it is the same for every caller, contains no personal data, is shown before registration, and can be cached.
|
||||
|
||||
Questionnaire:
|
||||
|
||||
- The candidate comes from the session; an employer account answers 403 `forbidden`. A candidate without a saved questionnaire gets 200 with `version: 0`, no specializations, and null `work_context` and `updated_at` rather than 404, so the first save reads the version the same way as later ones.
|
||||
- Each chosen specialization has `self_assessed_grade`, `task_languages`, `stack`, and `experience` in months or null when not stated; `work_context` holds only the acceptable work formats and no personal data. The questionnaire never contains a confirmed grade or a category, and unknown fields such as `confirmed_grade` answer 400. The self-assessed grade is the expected grade that the `candidate_assessment` onboarding step offers first; it influences where the assessment starts but adds no points, and no self-assessed grade or stack tag such as "Senior" assigns a category. A real profile stays invisible to employers until an assessment confirms a category.
|
||||
- The schema allows one or two specializations on save and rejects an unknown specialization, grade, task language, or work format. JSON Schema `uniqueItems` cannot compare array items by one field, so the server rejects a repeated specialization with 400 and the pointer `/specializations/<index>/specialization`. It also rejects a task language that the specialization's published bank does not offer, with the pointer of that language. A specialization whose test is `in_development` can be chosen; no assessment starts for it.
|
||||
- Concurrency uses `expected_version` in the body instead of If-Match, because the generated client cannot read the `ETag` header yet. The first save sends 0. A stale value answers 412 `version_conflict`, the same status and code as a failed If-Match, because the client does the same thing: it reads the questionnaire again. `version_conflict` keeps its 412 status, so `state_conflict` (409) is not used here.
|
||||
- PUT replaces the whole questionnaire and needs no Idempotency-Key. A body equal to the stored state changes nothing, keeps the version, and answers 200 even with an older `expected_version`, so a retry after a lost response does not fail with 412.
|
||||
- Order of checks for a save: session (401), CSRF and Origin (403), request validation (400), account scenario (403 `forbidden`), domain rules (400), version (412). `TestQuestionnaireSchemaValidationPrecedesImplementation` checks the schema rejections through the generated server.
|
||||
|
||||
### Generator checks
|
||||
|
||||
`testdata/openapi-3.2.0.yml` contains test operations that use the components above: pagination, Idempotency-Key, If-Match, ETag, and problem responses. ogen does not resolve external references, so the fixture keeps copies of the api/core components; `scripts/test_contract_copies.py` (part of `make -C api check`) checks that they, the fixture responses, and the ML `Problem` copy match api/core.
|
||||
@@ -159,6 +187,7 @@ Known generator limitations:
|
||||
- ogen writes the header name in its canonical Go form (`Etag`); HTTP header names are case-insensitive.
|
||||
- ogen requires a `SecurityHandler` as soon as the contract has security schemes and evaluates the schemes in the order of their generated type names, so renaming a scheme can change the order; `TestGeneratedServerSecurityOrder` fails if it does. Security failures reach `NewError` without a response header, so clearing the cookie on a 401 from `Logout` needs handwritten code.
|
||||
- Orval does not expose security scheme values as typed arguments, so `X-CSRF-Token` is not a generated parameter; the shared API client is planned to attach it to mutating requests. Orval also generates no type for `Set-Cookie`, which the browser handles.
|
||||
- Orval Zod schemas ignore `uniqueItems` and do not reject unknown fields of `additionalProperties: false` objects; the server stays authoritative for both.
|
||||
- Orval clears `src/shared/api/endpoints/` and `src/shared/api/schemas/` before generation (`clean: true`), because a schema used by several tags moves from a tag directory to the schema root.
|
||||
|
||||
See the [development guide](../docs/en/DEVELOPMENT.md).
|
||||
Reference in new issue
Block a user