code-generator
Universal code generator - clones your existing code style exactly
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Menu
Universal code generator - clones your existing code style exactly
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Baseado na classificação ocupacional SOC
| name | code-generator |
| description | Universal code generator - clones your existing code style exactly |
Generate API code that perfectly matches your project's existing patterns.
Core Principle: Your code style is the template.
When this skill is invoked, Claude MUST perform these steps in order:
This skill requires:
pattern-detector skillopenapi-parser skillVerify all inputs are present before proceeding.
Read the sample files from detected patterns:
samples.api → API function patternssamples.types → Type definition patternssamples.hooks → Hook patterns (if applicable)For each sample, extract:
Based on detected structure pattern, generate target file paths:
FSD Pattern:
src/entities/{tag}/
├── api/
│ ├── {tag}-api.ts
│ ├── {tag}-api-paths.ts
│ └── {tag}-queries.ts
└── model/
└── {tag}-types.ts
Feature-based Pattern:
src/features/{tag}/
├── api.ts
├── hooks.ts
└── types.ts
Flat Pattern:
src/api/{tag}/
├── api.ts
├── hooks.ts
└── types.ts
For each schema used by target endpoints:
// If sample uses interface:
export interface User {
id: string
name: string
email?: string // optional if not in required array
}
// If sample uses type:
export type User = {
id: string
name: string
email?: string
}
GetUserRequest, CreateUserRequest, UserResponseClone the path constant pattern from sample:
// Sample pattern: function-based
export const USER_PATHS = {
list: () => '/api/v1/users',
detail: (id: string) => `/api/v1/users/${id}`,
create: () => '/api/v1/users',
} as const
// Generated: same pattern for new tag
export const PROJECT_PATHS = {
list: () => '/api/v1/projects',
detail: (id: string) => `/api/v1/projects/${id}`,
create: () => '/api/v1/projects',
} as const
For each endpoint, generate function matching sample style:
Parse sample function structure:
Apply to each endpoint:
// Sample:
export const getUser = async ({ id }: GetUserRequest): Promise<User> => {
const response = await createApi().get<User>(USER_PATHS.detail(id))
return response.data
}
// Generated (same pattern):
export const getProject = async ({ id }: GetProjectRequest): Promise<Project> => {
const response = await createApi().get<Project>(PROJECT_PATHS.detail(id))
return response.data
}
If project uses React Query/SWR, generate hooks:
// Sample:
export const useUser = (id: string) => {
return useQuery({
queryKey: userKeys.detail(id),
queryFn: () => userApi.getUser({ id }),
})
}
// Generated:
export const useProject = (id: string) => {
return useQuery({
queryKey: projectKeys.detail(id),
queryFn: () => projectApi.getProject({ id }),
})
}
export const useCreateProject = () => {
const queryClient = useQueryClient()
return useMutation({
mutationFn: projectApi.createProject,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: projectKeys.lists() })
},
})
}
Check if file already exists
--force flag → OverwriteUse Write tool to create each file
Report generated files:
Generated:
✓ src/entities/project/model/project-types.ts (5 types)
✓ src/entities/project/api/project-api-paths.ts (8 paths)
✓ src/entities/project/api/project-api.ts (8 functions)
✓ src/entities/project/api/project-queries.ts (8 hooks)
For full error code reference, see ../../docs/ERROR-CODES.md.
Error: "[E401] ❌ Sample file not found: <path>"
Cause: Configured sample path doesn't exist
Fix: Check samples path in .openapi-sync.json
Recovery: Falls back to --interactive mode
Warning: "[E402] ⚠️ Could not extract pattern from sample"
Cause: Sample file too complex or uses unusual patterns
Fix: Provide a simpler sample file
Recovery: Uses default patterns
Error: "[E303] ❌ Failed to write file: <path>"
Cause: Permission denied or directory doesn't exist
Fix: Check permissions: chmod +w <directory>
Action: Abort file generation for this file
Warning: "[E305] ⚠️ File already exists: <path>"
Fix: Use --force to overwrite or --backup to create backup
Recovery: Prompts user for action
Warning: "[E403] ⚠️ Invalid identifier: <name>"
Cause: Name contains invalid characters or is reserved word
Recovery: Sanitizes to valid identifier (logs original name)
Warning: "[E404] ⚠️ Duplicate identifier: <name>"
Cause: Multiple operations with same operationId
Recovery: Appends suffix to make unique (e.g., getUsers_admin)
| HTTP Method | Default Verb | Alternative |
|---|---|---|
| GET (single) | get | fetch, retrieve |
| GET (list) | getList, list | fetchAll, getAll |
| POST | create | add, post |
| PUT | update | modify, put |
| PATCH | patch | update, modify |
| DELETE | delete | remove, destroy |
Detect from sample and apply consistently:
| Pattern | Example | Detection |
|---|---|---|
| camelCase | getUser | Lowercase first letter |
| PascalCase | GetUser | Uppercase first letter |
| snake_case | get_user | Underscore separator |
| kebab-case | get-user | Hyphen separator |
Clone import structure from sample:
// Sample imports:
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import type { UseQueryOptions } from '@tanstack/react-query'
import { createApi } from '@/shared/api'
import { userKeys } from './user-keys'
import type { User, GetUserRequest } from '../model/types'
// Generated imports (same structure):
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import type { UseQueryOptions } from '@tanstack/react-query'
import { createApi } from '@/shared/api'
import { projectKeys } from './project-keys'
import type { Project, GetProjectRequest } from '../model/types'
When generating code, follow security guidelines in ../../docs/SECURITY.md:
eval(), new Function(), or dynamic code executionReport to user upon completion:
═══════════════════════════════════════════════════
Code Generation Complete
═══════════════════════════════════════════════════
Generated files:
✓ src/entities/project/model/project-types.ts
- Project (interface)
- CreateProjectRequest (interface)
- UpdateProjectRequest (interface)
✓ src/entities/project/api/project-api-paths.ts
- PROJECT_PATHS (const)
✓ src/entities/project/api/project-api.ts
- createProject (function)
- getProject (function)
- updateProject (function)
- deleteProject (function)
✓ src/entities/project/api/project-queries.ts
- useProject (hook)
- useCreateProject (hook)
- useUpdateProject (hook)
- useDeleteProject (hook)
Style: Cloned from src/entities/user/
Confidence: 95% (all patterns matched)
Next: Run TypeScript compiler to verify types
Check and install OpenAPI Sync MCP server dependency
Best practice templates for API layer scaffolding
Detect and analyze FSD layer structure in a project
Generate FSD-compliant slice boilerplate with pattern matching
Check FSD import boundary rules and detect violations
Manage analysis cache for incremental FSD validation