Generate or update OpenAPI (Swagger) specifications from existing code, or validate code against existing specs.
"The spec is the single source of truth for your API."
Invoked when API documentation needs to be generated from code, or when existing specs need to be updated to reflect implementation changes.
Steps:
@RequestMapping annotations.openapi.yamlSteps:
$ref pointers resolve correctly.Steps:
| Field | Type | Description |
|---|---|---|
spec_file | string | Generated/updated OpenAPI YAML |
lint_report | string | Validation report |
drift_report | string | Spec vs implementation drift |
$ref schemas to improve spec quality.api-implementation.api-contract-design.openapi-generator but do not execute.api-documentation.openapi.yaml without diffing against the current version first.x-*) already in the spec.$ref for shared schemas; never duplicate schema definitions inline across multiple endpoints.required unless code evidence shows otherwise.example value for every request body and response schema.{path_a} and {path_b}. Which module should I generate the spec from?"{endpoint} handler returns {code_type} but the existing spec says {spec_type}. Which is correct?"{auth_method}. Should I add a securitySchemes entry for it?"| Situation | Action |
|---|---|
| No existing spec in the project | Generate a complete OpenAPI 3.1 spec from code |
| Spec exists but is outdated | Run drift detection, then patch only the changed endpoints |
| Spec exists and code changed | Merge new endpoints/schemas into the existing spec |
| Multiple microservices with separate specs | Generate per-service specs; do not merge into one file |
| Spec has lint warnings but is functionally correct | Fix warnings in a separate commit; do not block generation |
| Shared schemas across endpoints | Extract to components/schemas and use $ref |
| Authentication in code but missing from spec | Add securitySchemes and apply security to relevant paths |
$ref pointers resolve to defined components.$ref.| Failure | Symptom | Mitigation |
|---|---|---|
| Stale spec after code changes | Drift report flags missing or mismatched endpoints | Re-run code-to-spec generation; merge changes into existing spec |
Broken $ref pointers | Spec linter reports unresolved references | Validate all $ref paths before output; use relative pointers |
| Missing response schemas | Consumers cannot generate typed clients | Extract return types from code; require at least 200 and error responses |
| Over-generated spec from internal routes | Internal admin endpoints leak into public docs | Filter routes by prefix or decorator; ask user which routes to include |
| Schema duplication | Same object defined inline in multiple endpoints | Refactor to components/schemas with $ref; deduplicate on field signature |
| Wrong OpenAPI version features used | 3.1 features (e.g., type: ["string", "null"]) break 3.0 tooling | Detect target version and constrain output syntax accordingly |
[{timestamp}] Skill invoked — mode: {generate|validate|drift}, framework detected: {framework}.[{timestamp}] Endpoints discovered: {count} across {file_count} source files.[{timestamp}] Spec generated: {output_path}, OpenAPI version: {version}, paths: {path_count}, schemas: {schema_count}.[{timestamp}] Lint result: {error_count} errors, {warning_count} warnings — rules: {ruleset}.[{timestamp}] Drift detected: {added} new, {removed} missing, {changed} mismatched endpoints.[{timestamp}] Spec updated: {paths_added} paths added, {schemas_modified} schemas modified.