agentsclimarketplace

Api contract

Skill Marycka9/oh-my-claude-obsidian/skills/api-contract

Derive an OpenAPI 3.1 contract for a feature from its data model, sequence flows, and plan - saved as YAML in the vault _data/api/ plus a companion topic with an endpoint table and a drift-check section comparing the contract against the routes actually implemented in the repo. Use for "API contract for X", "openapi for X", locking an interface before integration, or checking contract vs code drift. Do not use for schema design (data-model), general feature docs (obsidian-topic), or auto-fixing code to match a contract.From its SKILL.md

Install
npx -y skills add Marycka9/oh-my-claude-obsidian --skill api-contract

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

7.3 KB, as published. Nobody here has run it

api-contract

Projects the feature's upstream artifacts into one interface contract. The contract is derived, never hand-invented: fields come from the data model (or the existing repo schema), error branches from sequence flows, the endpoint list from the plan's user stories. Output: {base_path}/_data/api/<feature-slug>-openapi.yaml + topics/<Feature> — API Contract.md. Drift between contract and implemented routes is reported, never auto-fixed — the human decides which side is wrong.

Shared references: config-resolution, vault-structure, obsidian-format, hot-md, handoff, self-check. Skill references: references/drift-check.md, templates/openapi.yaml.

Arguments

/api-contract "Feature Name"
/api-contract "Feature Name" drift    (drift check only — re-compare existing contract vs code, no regeneration)

Step 1 — Resolve configuration

Per config-resolution. Not initialized -> stop: Run /obsidian-init first. Resolve base_path, language, repo root (needed for the drift check).

Step 2 — Gather inputs (soft prerequisites)

Read what exists; note found/missing in the report — none is a hard gate:

  1. topics/<Feature> — Data Model.md — the source of typed fields and constraints. Missing and the feature clearly changes the schema -> recommend /data-model "<Feature>" first, but proceed if the user insists (derive from the existing repo schema and say so loudly).
  2. Sequence flows — sequenceDiagram blocks in the feature/SAD topic. Their alt/else branches become error responses (the usual blind spot: authorization and concurrent-state branches the plan omits). An async actor on a mutating flow -> mark that endpoint Idempotency-Key-required.
  3. The plan/feature topic — user stories/steps give the endpoint list and happy-path shapes.
  4. Related ADRs — override defaults (auth scheme, versioning, error format) when one mandates it.

Nothing at all -> interview: which operations, on which entities, who calls them.

Step 3 — Derive the contract

Start from templates/openapi.yaml. Rules:

  • One endpoint (or more) per user story; every request/response field traces to a data-model column or an explicitly stated plan field. Never invent a field with no origin — ask.
  • Copy constraints across: maxLength from VARCHAR(N), enum from closed sets, nullable columns as type: [string, "null"] (3.1 style — never nullable: true).
  • $ref every shared schema; no inline duplication.
  • Defaults (deviate only when an ADR or the repo's existing API says otherwise — match the repo's real conventions first): error envelope {code, message, details?} with code as module.error_name; cursor pagination wrapped in {items, has_next, has_prev, next_cursor}; BearerAuth global with public endpoints declaring security: []; URL versioning.
  • Every operation carries request/success/error examples with placeholder data only ([email protected]) — never real PII.

Step 4 — Save the YAML

Write to {base_path}/_data/api/<feature-slug>-openapi.yaml (create _data/api/ if missing). Existing file -> diff and update in place, never overwrite whole-cloth; keep manually added fields with a # manual-addition comment and flag them.

Validate: the file must parse as YAML (python3 -c "import yaml,sys; yaml.safe_load(open(sys.argv[1]))" <file>; if PyYAML is unavailable, npx --yes yaml or a careful structural read). Suggest spectral lint if the repo has it wired.

Step 5 — Companion topic

{base_path}/topics/<Feature> — API Contract.md. Frontmatter: type: topic, status: active, tags: [topic, api-contract, backend], related -> the feature topic and the data model topic (quoted wikilinks). Body in language (paths, operationIds, status codes stay English):

  1. Context — why this API exists, link to the YAML: `_data/api/<feature-slug>-openapi.yaml` (backtick path — Obsidian does not wikilink YAML usefully).

  2. Endpoints pipe table:

    MethodPathOperationIdPurposeAuthSource

    Source = the story/flow it came from.

  3. Field origins — only the non-obvious rows: fields with medium/low confidence origins (see references/drift-check.md); a low row is declared incompleteness, not an error.

  4. Drift check section — per Step 6.

  5. History.

Step 6 — Drift check (report, never auto-fix)

Compare the contract against the routes actually implemented in the repo — see references/drift-check.md for the procedure and statuses. Summary: detect the framework's route registration pattern, enumerate implemented method+path pairs, match against the contract, and write the results table into the topic's Drift check section with a dated header. Statuses: match, missing-in-code (fine pre-implementation — say so), missing-in-contract, mismatch.

Never edit repo code, and never silently edit the contract to match the code — surface each finding; regenerating the contract happens only on explicit user choice.

Step 7 — Integrate

  1. Feature topic: add [[<Feature> — API Contract]] to its related links/frontmatter.
  2. A contract decision with blast radius beyond the feature (project-wide error envelope, versioning scheme, auth change) -> propose /obsidian-decision.
  3. topics/_index.md row; registry Last touched; refresh hot.md per hot-md.

Step 8 — Report

Endpoints derived, fields with low-confidence origins, drift findings count, YAML path. Then the handoff block (Next: /delivery-planning or the implementation step; after implementation: /api-contract "<Feature>" drift) and the self-check line.

Self-check items: YAML parses; every endpoint appears in the topic table; every table row exists in the YAML; wikilinks resolve; _index.md row present; hot.md under ~500 words.

Anti-patterns

  • Hand-writing the contract, then bending the model to fit it — the arrow is one-way: model + flows + plan -> contract.
  • Deriving error responses from the happy path only — the sequence alt branches hold the authorization/conflict cases.
  • Auto-editing code or contract on drift; silently dropping a field that left the data model (keep it with a # stale note and surface it).
  • nullable: true, offset pagination, free-text error bodies, real PII in examples — unless the repo's existing API genuinely uses those conventions (match reality over doctrine, and note it).

Keep looking

Skills are one crate of 607,533. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.