Help us improve
Share bugs, ideas, or general feedback.
From oas
Initialize OpenAPI sync - auto-learns patterns OR scaffolds from best practice templates
npx claudepluginhub jhlee0409/claude-plugins --plugin oasHow this command is triggered — by the user, by Claude, or both
Slash command
/oas:initFiles this command reads when invoked
The summary Claude sees in its command listing — used to decide when to auto-load this command
# OpenAPI Sync Initialization **One command for all scenarios:** - Have existing API code? → Auto-learns your patterns - Starting fresh? → Scaffolds from best practice templates Works with ANY codebase, ANY framework. ## Usage **Examples:** --- ## EXECUTION INSTRUCTIONS When `/oas:init` is invoked, Claude MUST perform these steps in order: ### Step 0: MCP Dependency Check **Invoke skill: mcp-dependency** - Verify OpenAPI Sync MCP server is installed - If not available, offer to install via `npm install -g @jhlee0409/openapi-sync-mcp` - Only proceed after MCP is confirmed availabl...
/hatch3r-api-specGenerates an OpenAPI 3.1 specification from codebase route definitions, or detects drift between an existing spec and live code. Supports validate mode for spec-vs-code comparison.
/generate-specGenerates or updates an OpenAPI 3.0 YAML spec by analyzing API routes in Express, FastAPI, Django, NestJS, Go, Java, and Ruby codebases. Validates output and reports changes.
/generate-openapiGenerates OpenAPI 3.1 specification from existing API codebase by scanning routes/handlers and extracting schemas from types/models. Outputs to openapi.yaml.
/openapi-expertScans Go REST API in internal/api and synchronizes openapi.yml by adding/updating endpoints, schemas from DTOs/struct tags, parameters, responses, and documentation.
/initInitializes beads issue tracking database in current directory with optional prefix (defaults to dir name). Shows DB location, prefix, workflow overview, next steps; displays stats if already set up.
/initInitializes guided UI design for dashboards, apps, and tools. Assesses intent, proposes styles with rationale, builds components, and offers to save patterns.
Share bugs, ideas, or general feedback.
One command for all scenarios:
Works with ANY codebase, ANY framework.
/oas:init <spec-url-or-path>
Examples:
# From URL
/oas:init https://api.example.com/openapi.json
# From local file
/oas:init ./docs/openapi.yaml
When /oas:init is invoked, Claude MUST perform these steps in order:
Invoke skill: mcp-dependency
npm install -g @jhlee0409/openapi-sync-mcp.openapi-sync.jsonIMPORTANT: Always start by asking the user for the OpenAPI spec location.
🚀 OpenAPI Sync Initialization
Please enter the OpenAPI spec URL or file path:
Examples:
• https://api.example.com/openapi.json
• ./openapi.json
• ./docs/swagger.yaml
If user provided argument with command, use that directly. If not, prompt for input before proceeding.
┌─────────────────────────────────────────────────────────────┐
│ /oas:init │
├─────────────────────────────────────────────────────────────┤
│ │
│ 1. Get OpenAPI spec location │
│ 2. Fetch & cache spec (cache-manager) │
│ 3. Validate spec (openapi-parser) │
│ 4. Detect framework (package.json) │
│ 5. Find existing API code │
│ │ │
│ ├─ FOUND ──────────────────────────────────────┐ │
│ │ │ │ │
│ │ ▼ │ │
│ │ 6a. Analyze samples (pattern-detector) │ │
│ │ │ │ │
│ │ ▼ │ │
│ │ Use existing code as sample │ │
│ │ │ │
│ └─ NOT FOUND ──────────────────────────────┐ │ │
│ │ │ │ │
│ ▼ │ │ │
│ 6b. Select template (scaffold-templates)│ │ │
│ │ │ │ │
│ ▼ │ │ │
│ Generate scaffold → becomes sample │ │ │
│ │ │ │
│ ◄──────────────────────────────────────────┴───┘ │
│ │ │
│ 7. Generate .openapi-sync.json (samples point to code) │
│ 8. Security check (.gitignore) │
│ 9. Show summary │
│ │
└─────────────────────────────────────────────────────────────┘
Key insight: Whether you have existing code or start fresh, the result is the same:
.openapi-sync.json with samples pointing to real code/oas:sync uses these samples for future code generationSupported sources:
File: ./openapi.json, ./docs/swagger.yaml
URL: https://api.example.com/openapi.json
If argument provided:
http:// or https:// → Fetch from URL
Otherwise → Read as local file
If no argument:
1. Search for openapi.json, swagger.json locally
2. If found, ask to confirm usage
3. If not found, request path/URL input
Use cache-manager skill to fetch and cache:
Invoke skill: cache-manager
1. Fetch spec from source (URL or local file)
2. Validate basic structure (has openapi/swagger field)
3. Write .openapi-sync.cache.json immediately
This ensures /oas:sync doesn't need to refetch.
Output:
📥 Fetching spec from https://api.example.com/openapi.json...
✅ Spec cached (150 endpoints, 45 schemas)
Use openapi-parser skill:
Invoke skill: openapi-parser
- Verify OpenAPI 3.x or Swagger 2.x structure
- Extract title, version, endpoints
- Parse schemas and validate references
Read package.json:
// Detect ecosystem
const framework = detectFramework(packageJson)
// Output example:
{
framework: "react", // react, vue, angular, svelte, etc.
language: "typescript", // typescript or javascript
httpClient: "axios", // from dependencies
dataFetching: "react-query" // from dependencies
}
Report:
📦 package.json analysis:
Framework: React + TypeScript
HTTP Client: axios
Data Fetching: @tanstack/react-query v5
Use pattern-detector skill:
Invoke skill: pattern-detector
Search for existing API code:
Possible outcomes:
OUTCOME A: Samples found
→ "Found 5 API files in src/entities/*/api/"
→ Proceed to sample analysis
OUTCOME B: No samples found
→ "No existing API code found"
→ Go to interactive mode
Analyze discovered files:
Analyzing samples...
📂 Structure detected:
Pattern: src/entities/{domain}/api/
Samples: user, project, clip (3 domains)
🔌 HTTP Client:
Type: Custom wrapper (createApi)
Location: src/shared/api/create-api.ts
Pattern: createApi().{method}<T>(path)
📦 Data Fetching:
Library: React Query v5
Pattern: Query Key Factory
Hooks: Separate file (queries.ts)
📝 Types:
Location: src/entities/{domain}/model/types.ts
Style: interface
Naming: {Entity}, {Operation}Request, {Operation}Response
🏷️ Naming:
Functions: get{Entity}, create{Entity}
Hooks: use{Entity}, useCreate{Entity}
Files: {domain}-api.ts, queries.ts, types.ts
Ask confirmation:
Generate code using these patterns?
(Let me know if you'd like any changes)
When no existing API code is found, offer best practice templates:
🎨 No existing API code found. Let's set up a best practice structure!
Based on your stack (React + TypeScript + React Query), I recommend:
┌─────────────────────────────────────────────────────────────┐
│ 1. react-query-fsd (Recommended) │
│ Feature-Sliced Design with React Query v5 │
│ ├── Separate types, api, hooks per domain │
│ ├── Query key factory pattern │
│ └── Best for: Medium-large apps, team projects │
├─────────────────────────────────────────────────────────────┤
│ 2. react-query-flat │
│ Flat structure - all API code in src/api/ │
│ └── Best for: Small apps, prototypes │
├─────────────────────────────────────────────────────────────┤
│ 3. react-query-feature │
│ Feature-based - API co-located with features │
│ └── Best for: Feature-focused teams │
├─────────────────────────────────────────────────────────────┤
│ 4. Custom - Paste sample code to replicate │
└─────────────────────────────────────────────────────────────┘
Select template (1-4):
After template selection:
Invoke skill: scaffold-templates
1. Load template definition
2. Generate shared API layer (create-api.ts, etc.)
3. For each tag in OpenAPI spec:
- Generate types from schemas
- Generate API functions
- Generate path constants
- Generate query hooks (if applicable)
- Generate query key factory (if applicable)
4. Create barrel exports (index.ts)
Report scaffold progress:
🏗️ Scaffolding API layer...
✓ src/shared/api/create-api.ts
✓ src/shared/api/api-error.ts
✓ src/shared/api/index.ts
✓ src/entities/users/
├── api/users-api.ts (5 functions)
├── api/users-paths.ts
├── api/users-keys.ts
├── api/users-queries.ts (5 hooks)
└── model/types.ts (3 types)
✓ src/entities/projects/
└── ... (12 endpoints)
✓ src/entities/billing/
└── ... (8 endpoints)
The generated code becomes the sample for future syncs.
This means .openapi-sync.json will point to the scaffolded code:
{
"samples": {
"api": "src/entities/users/api/users-api.ts",
"types": "src/entities/users/model/types.ts",
"hooks": "src/entities/users/api/users-queries.ts"
}
}
Now /oas:sync will use these generated files as the pattern source.
Create .openapi-sync.json:
Note:
project.*andpatterns.*are auto-detected from samples and stored internally. Only essential fields are saved to the config file.
{
"version": "1.0.0",
"openapi": {
"source": "./openapi.json"
},
"samples": {
"api": "src/entities/user/api/user-api.ts",
"types": "src/entities/user/model/types.ts",
"hooks": "src/entities/user/api/queries.ts",
"keys": "src/entities/user/api/user-keys.ts"
},
"tagMapping": {},
"ignore": [
"/health",
"/metrics",
"/internal/*"
],
"validation": {
"ignorePaths": []
}
}
Check .gitignore for cache files:
1. Check if .gitignore exists
2. Check if cache files are in .gitignore:
- .openapi-sync.cache.json
- .openapi-sync.state.json
3. If not in .gitignore:
⚠️ Warning: Cache files should be in .gitignore
Add these lines to .gitignore:
# OpenAPI Sync cache files (contain potentially sensitive data)
.openapi-sync.cache.json
.openapi-sync.state.json
4. Ask user: "Add these entries to .gitignore? [y/n]"
- If yes → Append to .gitignore
- If no → Show warning and continue
For more security guidelines, see ../docs/SECURITY.md.
✅ OpenAPI Sync initialization complete
📄 OpenAPI Spec:
My API v2.0.0
25 endpoints, 8 tags
Source: ./openapi.json
🔍 Detected patterns:
Structure: FSD (Feature-Sliced Design)
HTTP: createApi() (custom Axios wrapper)
State: React Query v5 (factory pattern)
Types: interface, separate files
📁 Sample code:
API: src/entities/user/api/user-api.ts
Types: src/entities/user/model/types.ts
Hooks: src/entities/user/api/queries.ts
📝 Files created:
.openapi-sync.json (config)
.openapi-sync.cache.json (spec cache)
🚀 Next steps:
/oas:analyze - Detailed pattern analysis
/oas:sync - Start code generation
/oas:sync --dry-run - Preview files to generate
OpenAPI spec error:
→ "Invalid OpenAPI spec: {error}"
→ "Please check the spec path"
Pattern detection failed:
→ Switch to interactive mode
→ "Could not detect patterns automatically. Let me ask a few questions."
package.json not found:
→ "Cannot find package.json. Please run from project root."
Existing config file:
→ ".openapi-sync.json already exists."
→ Ask user: Overwrite or merge with existing config?
| Flag | Description |
|---|---|
--force | Overwrite existing config |
--scaffold | Skip sample detection, go directly to template selection |
--template=<name> | Use specific template (e.g., react-query-fsd) |
--sample=<path> | Specify a particular sample file to learn from |
--auto | Auto-select template based on stack (no prompts) |
Examples:
# Standard init (auto-detects or prompts)
/oas:init https://api.example.com/openapi.json
# Force scaffold mode (skip sample detection)
/oas:init --scaffold
# Use specific template without prompts
/oas:init --template=react-query-fsd
# Full auto mode (best for CI/CD or scripts)
/oas:init --auto