
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
@cerios/openapi-to-typescript
Advanced tools
Generate TypeScript types from OpenAPI specifications.
type declarations from OpenAPI schemasenum, union, or const object from OpenAPI enumsnpm install @cerios/openapi-to-typescript
# Initialize a config file
npx openapi-to-typescript init
# Generate types
npx openapi-to-typescript generate
Create a openapi-to-typescript.config.ts file:
import { defineConfig } from "@cerios/openapi-to-typescript";
export default defineConfig({
input: "./openapi.yaml",
outputTypes: "./src/types.ts",
// Output format for enums: 'enum', 'union' (default), or 'const-object'
enumFormat: "union",
});
import { TypeScriptGenerator } from "@cerios/openapi-to-typescript";
const generator = new TypeScriptGenerator({
input: "./openapi.yaml",
outputTypes: "./src/types.ts",
enumFormat: "union",
});
// Generate and write to file
generator.generate();
// Or generate as string
const code = generator.generateString();
| Option | Type | Default | Description |
|---|---|---|---|
input | string | - | Path to OpenAPI specification (YAML or JSON) |
outputTypes | string | - | Output file path for generated types |
enumFormat | 'enum' | 'union' | 'const-object' | 'union' | How to generate enums |
includeDescriptions | boolean | true | Include JSDoc comments |
defaultNullable | boolean | false | Treat properties as nullable by default |
stripSchemaPrefix | string | string[] | - | Remove prefix from schema names (supports glob) |
stripPathPrefix | string | - | Remove prefix from paths |
useOperationId | boolean | true | Use operationId for operation-derived type names when available |
prefix | string | - | Add prefix to generated type names |
suffix | string | - | Add suffix to generated type names |
operationFilters | object | - | Filter operations by tags, paths, methods |
showStats | boolean | true | Include generation statistics |
batchSize | number | 10 | Parallel processing batch size |
union (default):
export type Status = "active" | "inactive" | "pending";
enum:
export enum Status {
Active = "active",
Inactive = "inactive",
Pending = "pending",
}
const-object:
export const Status = {
Active: "active",
Inactive: "inactive",
Pending: "pending",
} as const;
export type Status = (typeof Status)[keyof typeof Status];
MIT
FAQs
Generate TypeScript types from OpenAPI specifications
We found that @cerios/openapi-to-typescript demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.