Docs
Sign in
Browse the docs

The SDLC pipeline

API contract

The OpenAPI 3.1 specification the test plan targets, with the document around it.

8 min read7 sections

The API Contract step turns the approved design into an OpenAPI 3.1 specification, with a short document around it. The agent, working as an API architect, writes one operation for every interface the design names, ties each operation to the design component that implements it and the requirements it serves, and describes how callers authenticate and how the API fails. The STS then writes its integration tests against these operations, and a team can generate clients and server stubs from the spec.

What you get

A Markdown document titled API Contract. The bridge adds the title block on top, then the agent's six sections, then the full spec as a section of its own, then the version history:

OrderSectionWritten by
1Title block: project, client, version, dateBridge
21. Overview: purpose and consumers, base URLs, the design components behind the API, the resource modelAgent
32. Authentication: the scheme, an authorization table (operation, permission module, action), public operationsAgent
43. Conventions: naming, request and response format, pagination, idempotency, concurrency and caching, rate limits, tracing, headersAgent
54. Endpoints: one table row per operation, with method, path, operationId, purpose, permission, design component and requirementsAgent
65. Error Model: the problem-details body, a status code table, an error code tableAgent
76. Versioning: version scheme, breaking and non-breaking changes, deprecation policyAgent
8OpenAPI Specification: the whole contract as one JSON blockBridge
9Version HistoryBridge

The bridge requires the headings Overview, Authentication, Conventions, Endpoints, Error Model and Versioning. There is no minimum number of diagrams, a resource-model diagram is optional.

The OpenAPI Specification section is owned by the bridge: editing the document keeps it as it is. To change the spec, request changes or run /api again.

Before you run it

  • The SDS must be approved. Until it is, /api is locked with "Approve System Design Spec to unlock this". The agent reads the approved SRS, TAD and SDS as source documents.
  • The project state must hold the SRS and the SDS. Otherwise the run stops with "Cannot write the API Contract: sds artifact is missing from state.json. Run /sds first."
  • The agent is given the requirements, the design components with their interfaces, the architecture decisions, the list of ids it may cite, today's date (so example values use the current year), and, on a revision, the contract as last written.

How it works

The contract is long, so the step does not ask for it in one reply. It asks the sdlc-api-designer skill for three parts and joins them.

Flow
  • Ask for the paths, without components to Ask for components and narrative together
  • Ask for components and narrative together to Any reference still undefined?
  • Any reference still undefined? to Ask once more, naming the missing targets, Yes
  • Any reference still undefined? to Run the contract checks, No
  • Ask once more, naming the missing targets to Run the contract checks
  • Run the contract checks to Hard problem found?
  • Hard problem found? to Draft awaits your review, No, notes only
  • Hard problem found? to Contract problem?, Yes
  • Contract problem? to Draft awaits your review, No
  • Contract problem? to Blocking draft: approve it, or press Fix failed checks, Yes
  • Draft awaits your review to Bridge appends the OpenAPI Specification section

Before the checks, the bridge repairs common slips in the reply at no token cost: paths or components that landed inside the wrong object, responses or media types nested inside each other, and header objects written like parameters.

The checks

CheckWhat it enforces
Version and infoopenapi is a 3.1.x string; info.title and info.version are present.
PathsAt least one path, every path starts with /, every path has at least one operation.
OperationsA unique operationId on every operation, and at least one response, including one error response (4xx, 5xx or default).
TraceabilityEvery operation names its design component in x-design-component, and that component exists in the SDS. Every id in x-requirements exists in the SRS.
SecurityAt least one scheme under components.securitySchemes, and every operation covered by a security requirement (top-level or its own), unless it is explicitly public with "security": [].
ReferencesEvery local $ref resolves inside the document.
ErrorsEvery 4xx and 5xx response uses one shared error schema. A schema that extends it with allOf still counts as the same one.
Schema typesEvery type is a JSON Schema type.
OpenAPI 3.1 validatorThe standard validator runs on a copy of the spec: no external reference is fetched, it is cut short after five seconds, and at most ten findings are listed, each with its path.
NarrativeThe six headings are present, and any DC-NNN the text cites exists in the SDS.

Each list in a finding is capped (25 operations, 8 undefined reference targets), so a long contract stays readable.

What blocks and what is a note

Most findings are notes: the draft is kept and the reviewer sees the list. A few are hard: the draft is kept with them listed, and Fix failed checks asks the agent to change only what is wrong. The bridge makes no repair call by itself. An operator who allows more attempts (ALARA_CORRECTION_MAX_ATTEMPTS) gets up to two automatic repair calls back; when the only problems are undefined references or a missing security scheme, that call asks just for the components part, with the missing targets named.

SeverityFindings
Blocking (kept for you to approve or fix)No contract object at all, no paths, no security scheme, an undefined $ref, any OpenAPI 3.1 validator finding.
Hard (kept with a note, fixed when you ask)A missing required heading, an unknown DC-NNN in the text, an unknown design component or requirement on an operation.
NoteA wrong version string, a missing or duplicate operationId, an operation with no error response, an operation with no x-design-component, two error shapes, an unsecured operation, a bad schema type.

A blocking draft is written and registered like any other, and you can approve it as it is or request changes: no step is stuck on a failed check. The approval records how many checks were open. The apiContract in project state, which the next steps read, is saved from the draft; a draft that carries no contract at all leaves the earlier one alone.

The run panel shows: Checking project state, Writing the API contract, Writing the Markdown document.

Ids this step owns

The API Contract creates no id family of its own. It cites ids from earlier steps and adds two names that other documents use:

NameMeaning
x-design-componentThe DC-NNN that implements an operation. Checked against the SDS.
x-requirementsThe REQ- ids an operation serves. Checked against the SRS.
operationIdA unique camelCase name such as listInvoices. The test cases call operations by this name.

The skill also asks for an x-permission on each operation (the Poly-X module and action the caller needs, or public). The bridge does not check it, so read it yourself.

By default the skill authenticates with Poly-X (polyxBearer, with an organization-id header on tenant-scoped operations) and never designs sign-in, sign-up, password-reset or notification endpoints. The bridge adds a note if the contract designs those itself, or discusses sign-in without naming Poly-X.

Reviewing it

The API Contract is reviewed, and /sts stays locked until it is approved. A project whose STS was produced before this step existed counts its API Contract as approved. Check that:

  • every interface of kind "api" in the SDS has an operation, and nothing is invented: the bridge does not compare the two, you do;
  • the authentication scheme and the server list match the TAD, and no host name is made up;
  • "must" requirements are cited by at least one operation;
  • the Endpoints table, the Error Codes table and the contract agree path for path and code for code;
  • the notes on the draft, if any, are ones you accept.

Request changes sends the agent the draft and your change list. It returns only the sections it changes and a merge patch for the spec, and every operationId that still exists is kept. Name operations: "Add a POST /invoices/{invoiceId}/approve operation owned by DC-003" works better than "approval is missing".

When it fails

What you seeWhyWhat to do
/api locked: "Approve System Design Spec to unlock this"The SDS is not approved.Approve the SDS.
"Cannot write the API Contract: sds artifact is missing…"The project state has no SDS.Run /sds first.
"The agent could not fix N problems the next step reads" above ApproveThe draft is blocking: no paths, no security scheme, an undefined reference or a validator finding, still there on the draft.Approve it as it is, or press Fix failed checks.
"The agent did not return a usable reply."No attempt produced readable output.Run it again.
"The agent's reply still fails N check(s) the next step depends on…"The document was empty after the attempts.Run it again.

When a draft is kept as blocking, the agent's best reply is also saved at .sdlc/tmp/api-last-response.json.

Under the hood

  • The driver is bridge/src/services/apiPipeline.service.ts, the skill sdlc-api-designer; the checks are in bridge/src/lib/openApiCheck.ts.
  • The document is written to .sdlc/artifacts/api-vN.md and registered as artifacts.api. The parsed spec is also kept in the project state as apiContract, which the Prototype reads to know which operations a screen can call.
  • The gate sits in bridge/sdlc-engine/lib/sdlc/gate-rules.js. The correction loop is described in Document checks and versioning.