Apidocs

From arbazkhan971/godmode · View interactive version

Apidocs is an AI agent skill from the GitHub repository arbazkhan971/godmode. API documentation. OpenAPI, Swagger, Redoc, contract-first development, spec-first, code-first, interactive docs.

How to use this skill

Skill file

APIDocs — Documentation Generation & Interactive Specs

Activate When

Workflow

Step 1: Discovery & Approach Selection

Determine the documentation strategy before generating anything:

APIDOCS DISCOVERY:
Project: <name and purpose>
Language/Framework: <Node/Express, Python/FastAPI, Java/Spring, Go, NestJS, etc.>

If the user hasn't specified, ask: "Do you want to write the spec first and generate code from it

(spec-first), or generate the spec from existing code (code-first)?"

Step 2: Spec-First — Writing OpenAPI from Scratch

For spec-first (contract-first) development, produce a complete OpenAPI document:

# Template: OpenAPI 3.1 Spec-First
openapi: "3.1.0"
info:

Rules for spec-first:

Step 3: Code-First — Auto-Generate Spec from Code

For code-first, configure the framework's doc generation:

CODE-FIRST SETUP BY FRAMEWORK:

Framework-specific setup:

Step 4: Schema Reuse with $ref and Components

Enforce DRY specs by extracting shared schemas:

SCHEMA REUSE CHECKLIST:
| Pattern | Extract to |

Rules:

# Composition with allOf
CreateUserRequest:
  allOf:

Step 5: Examples and Mocking

Every operation must have realistic examples for documentation and mocking:

# Inline examples in schema
properties:
  email:

Mock server setup:

# Prism — mock server from OpenAPI spec
npm install -g @stoplight/prism-cli
prism mock openapi.yaml                     # Start mock server on :4010

Step 6: Documentation Renderers

Set up interactive documentation from the OpenAPI spec:

Swagger UI
npm install swagger-ui-express
# or standalone
docker run -p 8080:8080 -e SWAGGER_JSON=/spec/openapi.yaml \
// Express integration
const swaggerUi = require("swagger-ui-express");
const spec = require("./openapi.json");
Redoc
<!-- Static HTML — zero dependencies -->
<!DOCTYPE html>
<html>
# Build static docs
npx @redocly/cli build-docs openapi.yaml -o docs/index.html
Stoplight Elements
<!-- Embed in any HTML page -->
<script src="https://unpkg.com/@stoplight/elements/web-components.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@stoplight/elements/styles.min.css">

Step 7: Versioning in Specs

Handle API versioning within OpenAPI specs:

SPEC VERSIONING STRATEGIES:
| Strategy | How to Represent in OpenAPI |

Step 8: CI Validation & Linting

Validate specs in CI to prevent regressions:

# .github/workflows/api-docs.yml
name: API Docs CI
on:
# .spectral.yaml — custom linting rules
extends: ["spectral:oas"]
# Optic — track breaking changes over time
npx @useoptic/optic diff openapi.yaml --base main --check

Step 9: SDK Generation

Generate client SDKs from the OpenAPI spec:

# openapi-generator — supports 50+ languages
npm install -g @openapitools/openapi-generator-cli
# Alternative: openapi-typescript (lightweight, type-only)
# Generates TypeScript types from OpenAPI — no runtime, types only
npx openapi-typescript openapi.yaml -o src/api/schema.d.ts
# CI workflow for SDK generation
name: Generate SDKs
on:

Step 10: Changelog Generation from Spec Diffs

Automatically generate API changelogs from spec differences:

# oasdiff — diff two OpenAPI specs and generate changelog
npm install -g oasdiff
# or
CHANGELOG OUTPUT EXAMPLE:
  API Changelog: v1.0.0 → v2.0.0
# CI: auto-generate changelog on spec changes
name: API Changelog
on:

Step 11: Validation & Quality Gate

Validate the documentation setup against completeness standards:

APIDOCS VALIDATION:
| Check | Status |

Step 12: Deliverables

Generate the final artifacts:

APIDOCS COMPLETE:

Artifacts:

Commit: "apidocs: <service> — OpenAPI spec, <renderer> setup, CI validation configured"

Key Behaviors

IF Spectral lint errors > 0: fix before merging.

WHEN breaking changes detected by oasdiff: block PR, require migration plan.

IF schema coverage < 100% (fields without descriptions): add descriptions.

  1. Every field gets a description and example. No guessing.
  2. $ref everything shared. No duplicated schemas.
  3. Validate in CI. Spectral + Optic + Redocly on every PR.
  4. Realistic examples. "jane.doe@example.com" not "string".
  5. Generate from code when code exists. Spec-first for greenfield.
  6. Publish docs automatically. Deploy on every merge.
  7. Track breaking changes. Spec diff in CI catches regressions.

HARD RULES

Never ask to continue. Loop autonomously until spec validates and all endpoints have examples.

  1. NEVER write endpoint docs without realistic examples. A schema without examples is a guessing game.

Every request and response must have at least one realistic example.

  1. NEVER duplicate schemas. Extract shared shapes to components/schemas and use $ref. Duplicated schemas drift.
  2. NEVER skip CI validation. Lint and validate the OpenAPI spec on every PR. A spec valid last week can break today.
  3. NEVER hand-edit generated specs in code-first workflows. Modify annotations in code instead. The

generator overwrites manual edits.

  1. NEVER ignore breaking changes. Use Optic or oasdiff in CI to catch removed endpoints, renamed

parameters, and type changes.

  1. NEVER skip security scheme documentation. Undocumented auth forces every consumer to reverse-engineer

your auth flow.

  1. ALWAYS serve docs in all environments or publish static docs. Docs behind if (env === 'development')

are invisible to production consumers.

  1. ALWAYS use example: with realistic values -- "jane.doe@example.com" not "string".

TSV Logging

Log every invocation to .godmode/ as TSV. Create on first run.

timestamp	skill	action	endpoints	schemas	lint_errors	breaking_changes	status
2026-03-20T14:00:00Z	apidocs	generate_spec	12	8	0	0	pass
2026-03-20T14:10:00Z	apidocs	validate	12	8	2	1	needs_fix

<!-- tier-3 -->

Quality Targets

Success Criteria

The apidocs skill is complete when ALL of the following are true:

  1. Valid OpenAPI 3.0/3.1 spec that parses without errors
  2. All operations have descriptions, tags, and at least one example
  3. All schemas have field descriptions and realistic examples
  4. $ref is used for all shared schemas (no duplicated definitions)
  5. Error responses defined on all endpoints (401, 400, 500 at minimum)
  6. Security schemes documented and applied to endpoints
  7. Spectral lint passes with zero errors
  8. No breaking changes vs main branch (or breaking changes are documented)
  9. Doc renderer builds and displays correctly

Iterative Loop Protocol

max_iterations = 12
WHILE doc_tasks remain:
  1. MEASURE: validate spec, check examples
  2. KEEP if: 0 lint errors AND 0 breaking changes
  3. DISCARD if: validation fails OR examples broken
  4. COMMIT kept changes. Revert discarded.

Keep/Discard

KEEP if: improvement verified. DISCARD if: regression or no change. Revert discards immediately.

Stop Conditions

STOP when ANY of these are true:
  - All identified tasks are complete and validated
  - User explicitly requests stop
  - Max iterations reached — report partial results with remaining items listed

DO NOT STOP only because:
  - One item is complex (complete the simpler ones first)
  - A non-critical check is pending (handle that in a follow-up pass)

Error Recovery

| Failure | Action |

|--|--|

| OpenAPI spec validation fails | Run swagger-cli validate to get specific errors. Fix schema references, missing required fields, and invalid types. |

| Generated docs drift from implementation | Add CI check: compare spec against route handlers. Use spec-first or code-first consistently, never mix. |

| Examples fail validation against schema | Verify example values match declared types, enums, and patterns. Auto-generate examples from schema as fallback. |

| Docs build breaks after API change | Pin docs generator version. Run docs build in CI on every PR that touches API routes. |

Output Format

Print: `APIDocs: {endpoints} endpoints documented. Schema valid: {yes|no}. Examples: {N}/{M} passing.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.