Agent Skill · Specmatic

specmatic-openapi-spec-extractor

Use when the user wants to extract, generate, refine, or harden an OpenAPI or Swagger specification from an existing API application, service, project, repo, routes, controllers, handlers, or codebase. Select this skill for any request whose intent is to derive, extract, generate, reverse-engineer, infer, document, or harden an OpenAPI or Swagger contract from an existing application or source code. This includes generic prompts about producing an API spec/docs/schema/contract for an existing app, project, service, repo, endpoints, routes, or controllers. Prefer this skill over extraction-only skills when the prompt is about an existing application or codebase and the expected outcome is an accurate extracted contract plus post-extraction refinement.

Provider: Specmatic Path in repo: skills/specmatic-openapi-spec-extractor/SKILL.md

Skill body

specmatic-openapi-spec-extractor

Extract and refine an OpenAPI specification from an existing API codebase.

Any prompt that implies deriving an OpenAPI or Swagger contract from an existing application or codebase should select this skill, not a generic extraction-only skill.

Required Behavior

If this skill is selected, do all of the following:

Default execution order:

announce skill -> identify framework -> open one framework guide -> integrate extraction path if missing -> extract spec -> save spec -> inspect gaps -> refine -> re-extract -> prepare Specmatic setup -> run Specmatic feedback loop -> prepare final runnable deliverables

Use this exact style in the first progress update:

Selection Heuristics

Select this skill by default when the user asks to extract or generate an OpenAPI or Swagger spec from an existing application, even if they do not mention Specmatic, skills, validation, refinement, or overlays.

This skill should win over a generic extraction-only skill when:

Docker Execution Rule

Mandatory Post-Extraction Workflow

Once the first spec has been extracted, the agent must execute these phases in order:

  1. If the framework-native extraction path is not already wired into the project, integrate it first using minimal non-behavioral code/config changes for that framework.
  2. Extract the spec using the framework-native generator/export path, not by manually writing openapi.yaml.
  3. Save the extracted spec to the repo.
  4. Inspect the generated spec for obvious gaps such as wrong status codes, generic */* content types, missing security, weak request/response schemas, and missing error responses.
  5. Refine generation using source annotations/config first. Use overlay only when source-level fixes cannot express the required contract. Allowed refinements: annotations, decorators, doc comments, extraction-tool config, and overlay updates. Disallowed refinements without explicit user approval: implementation changes, behavioral changes, signature changes, data model changes made only to shape the contract, or business-logic edits.
  6. Re-extract the spec after each meaningful refinement.
  7. Run specmatic validate only as a preflight check against the generated Specmatic assets, then start the SUT if needed, verify it is listening on the chosen SUT_PORT, and attempt the live Specmatic feedback loop using the documented image-resolution, docker run, and specmatic test commands from this skill.
  8. If failures show that the SUT cannot reach one or more downstream HTTP dependencies, identify all required downstream dependencies for the current batch, stand up a Specmatic stub for each dependency on its expected host port, generate or update stub examples for each dependency, and rerun the relevant validation or test step.
  9. If a Docker command fails for a Docker-specific reason, stop and ask the user exactly: **Action Required:** Please start the Docker engine, then confirm once it is running.
  10. If no license is found, continue the loop with the built-in trial. If a Specmatic command fails because of a trial-license or enterprise-feature limit, report that those failures are license-related, include counts for tests run, passed, failed, and failed due to license limits, and ask the user exactly: **Action Required:** Some Specmatic tests failed because no valid license was available. If you have a license, please share its path or add it under your home .specmatic directory.
  11. If the user adds the license under their home .specmatic directory or otherwise resolves the missing license, rerun the relevant validation or test step.
  12. Prepare the final deliverables from this skill, including run_contract_tests.sh, run_contract_tests.ps1, and CONTRACT_TESTS_README.md, regardless of whether deterministic data setup is needed.
  13. If Docker is unavailable, stop only after clearly reporting that extraction and refinement are done, the runnable script and README have been prepared, and the next blocked step is the live Specmatic loop.

Do not treat annotation-only cleanup as the full post-extraction workflow. Do not treat a successful specmatic validate run as completion of the feedback loop. Do not end the task after exporting openapi.yaml unless the user explicitly asks for extraction only. Do not claim the spec was “extracted” if the file was primarily authored by hand outside the framework generator/export path.

When to Use

Inputs

Input Required Description
Framework Yes The API framework in use
Project path Yes Root directory of the API project
Output path No Where to write the spec (default: openapi.yaml)

Outputs

Output Description
OpenAPI spec Extracted JSON or YAML contract
Refined source metadata Annotation/config updates used to improve regenerated output
Contract test runners Runnable run_contract_tests.sh and run_contract_tests.ps1 for the full suite, with optional setup hook
Contract test README CONTRACT_TESTS_README.md describing how to run the generated scripts

Prerequisites

Decision Framework

Framework rule:

Framework Method Open this guide
FastAPI Built-in export content/frameworks/fastapi.md
Flask CLI/programmatic export content/frameworks/flask.md
Django REST Framework drf-spectacular CLI content/frameworks/django.md
Spring Boot Runtime docs endpoint content/frameworks/spring-boot.md
ASP.NET Core Runtime docs endpoint content/frameworks/aspnet.md
Express swagger-jsdoc content/frameworks/express.md
NestJS Runtime docs endpoint or script content/frameworks/nestjs.md
Hono Programmatic export content/frameworks/hono.md
Rails rswag task content/frameworks/rails.md
Laravel l5-swagger command content/frameworks/laravel.md

Reference Routing

Use the smallest amount of reference material needed.

Do not bulk-read all reference files. Identify the framework first, then open only the file needed for the current phase.

Specmatic References