
Research
Supply Chain Attack on Axios Pulls Malicious Dependency from npm
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.
swigger2api
Advanced tools
A powerful CLI tool to generate TypeScript/JavaScript API code from Swagger/OpenAPI documentation
🚀 A powerful CLI tool to generate TypeScript/JavaScript API code from Swagger/OpenAPI documentation.
npm install -g swigger2api
npm install swigger2api --save-dev
# Global installation
swigger2api init
# Local installation
npx swigger2api init
You'll be prompted to choose your preferred language:
This will create a swigger2api.config.js or swigger2api.config.ts file in your project root.
Edit the generated configuration file and update these essential settings:
import { defineConfig } from 'swigger2api';
export default defineConfig({
// 🎯 Required: Your project name
projectName: "my-awesome-project", // TODO: Change this
// 📡 Required: Your Swagger documentation source
source: "http://localhost:3000/api-docs", // TODO: Change this
// 📦 Required: Request library import (adjust for your project)
requestImport: "import axios from '@/utils/request'", // TODO: Adjust this
// Other settings have sensible defaults
language: "ts",
outputDir: "./src/api",
generateTypes: true,
// ... more options
});
# If installed globally
swigger2api generate
# If installed locally (use npx)
npx swigger2api generate
# Force regeneration (even if no changes detected)
swigger2api generate --force
# or with npx
npx swigger2api generate --force
# Use custom config file
swigger2api generate --config ./custom.config.js
# or with npx
npx swigger2api generate --config ./custom.config.js
Note: The
swigger2apicommand can be used directly only when installed globally. If installed locally as a project dependency, you need to prefix it withnpx.
| Option | Type | Default | Description |
|---|---|---|---|
projectName | string | "my-project" | Your project name |
language | "js" | "ts" | "ts" | Target language |
source | string | object | function | null | Swagger documentation source |
outputDir | string | "./src/api" | Output directory for generated files |
generateTypes | boolean | true | Whether to generate TypeScript types |
requestImport | string | "import axios from '@/utils/request'" | Request library import statement |
import { defineConfig } from 'swigger2api';
export default defineConfig({
// Update log configuration
updateLog: {
enabled: true,
outputPath: "./",
},
// Module naming strategy
moduleNaming: {
strategy: "tags", // "tags" | "custom"
customFunction: null, // Custom naming function
},
// API function naming strategy
apiNaming: {
strategy: "operationId", // "operationId" | "custom"
customFunction: null, // Custom naming function
},
});
The source configuration supports multiple types:
import { defineConfig } from 'swigger2api';
export default defineConfig({
source: "http://localhost:3000/api-docs"
// or
// source: "https://api.example.com/swagger.json"
});
import { defineConfig } from 'swigger2api';
export default defineConfig({
source: "./swagger.json"
// or
// source: "/path/to/swagger.json"
});
import { defineConfig } from 'swigger2api';
export default defineConfig({
source: {
openapi: "3.0.0",
info: { title: "My API", version: "1.0.0" },
paths: { /* ... */ }
}
});
import { defineConfig } from 'swigger2api';
export default defineConfig({
source: async () => {
const response = await fetch("http://api.example.com/docs");
return response.json();
}
});
src/api/
├── types/ # TypeScript type definitions
│ ├── common.ts
│ └── [module].ts
├── [module]/ # API modules grouped by tags
│ ├── index.ts
│ └── types.ts
└── index.ts # Main export file
swigger2api initInitialize a new configuration file.
Options:
-l, --language <language> - Specify language (js|ts), default: tsExamples:
swigger2api init
swigger2api init --language js
swigger2api generateGenerate API code from Swagger documentation.
Options:
-f, --force - Force regeneration even if no changes detected-c, --config <path> - Specify config file path, default: ./swigger2api.config.jsExamples:
swigger2api generate
swigger2api generate --force
swigger2api generate --config ./custom.config.js
// swigger2api.config.ts
import { defineConfig } from 'swigger2api';
export default defineConfig({
projectName: "my-app",
language: "ts" as const,
source: "http://localhost:8080/v3/api-docs",
requestImport: "import request from '@/utils/request'",
outputDir: "./src/api",
});
// swigger2api.config.js
import { defineConfig } from 'swigger2api';
export default defineConfig({
projectName: "my-app",
language: "js",
source: "https://petstore.swagger.io/v2/swagger.json",
requestImport: "const axios = require('./http-client')",
outputDir: "./api",
});
import { defineConfig } from 'swigger2api';
export default defineConfig({
projectName: "my-app",
source: "http://localhost:3000/api-docs",
moduleNaming: {
strategy: "custom",
customFunction: (apiPath, operationId, tags) => {
// Extract module name from API path
const pathParts = apiPath.split('/').filter(Boolean);
return pathParts[1] || 'default';
},
},
});
Configuration file not found
# Make sure you've run init first
swigger2api init
Source URL not accessible
# Check if your Swagger URL is accessible
curl http://localhost:3000/api-docs
Permission errors
# Make sure you have write permissions to the output directory
chmod 755 ./src/api
Set the DEBUG environment variable for verbose output:
DEBUG=swigger2api swigger2api generate
We welcome contributions! Please see our Contributing Guide for details.
MIT © Your Name
See CHANGELOG.md for release history.
Made with ❤️ by the swigger2api team
FAQs
A powerful CLI tool to generate TypeScript/JavaScript API code from Swagger/OpenAPI documentation
The npm package swigger2api receives a total of 0 weekly downloads. As such, swigger2api popularity was classified as not popular.
We found that swigger2api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.

Security News
TeamPCP is partnering with ransomware group Vect to turn open source supply chain attacks on tools like Trivy and LiteLLM into large-scale ransomware operations.