code-generator
Universal code generator - clones your existing code style exactly
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Universal code generator - clones your existing code style exactly
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
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
| 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