
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
swagger-typescript-api
Advanced tools
Generate the API client for Fetch or Axios from an OpenAPI Specification
The swagger-typescript-api npm package is a tool that generates TypeScript API client code from Swagger/OpenAPI definitions. It helps developers to create strongly-typed API clients, reducing the risk of runtime errors and improving the development experience.
Generate TypeScript API Client
This feature allows you to generate a TypeScript API client from a Swagger/OpenAPI definition. The `generateApi` function takes an object with configuration options such as the name of the output file, the URL of the Swagger definition, and the output directory.
const { generateApi } = require('swagger-typescript-api');
generateApi({
name: 'MyApi.ts',
url: 'http://api.example.com/swagger.json',
output: './src/api',
});
Custom Templates
This feature allows you to use custom templates for generating the TypeScript API client. By specifying the `templates` option, you can provide a path to your custom templates, giving you full control over the generated code's structure and style.
const { generateApi } = require('swagger-typescript-api');
generateApi({
name: 'MyApi.ts',
url: 'http://api.example.com/swagger.json',
output: './src/api',
templates: './my-custom-templates',
});
Generate API Client from Local File
This feature allows you to generate a TypeScript API client from a local Swagger/OpenAPI definition file. The `input` option specifies the path to the local Swagger file.
const { generateApi } = require('swagger-typescript-api');
generateApi({
name: 'MyApi.ts',
input: './swagger.json',
output: './src/api',
});
The swagger-codegen package is a tool that generates client libraries, server stubs, and API documentation from Swagger/OpenAPI definitions. It supports multiple languages and frameworks. While it is similar to swagger-typescript-api, it is more mature and widely used but may not be as focused on TypeScript-specific features.
The typescript-fetch package is a TypeScript client generator for OpenAPI/Swagger definitions that uses the Fetch API. It is similar to swagger-typescript-api in that it generates TypeScript clients, but it specifically targets the Fetch API for making HTTP requests.
Any questions you can ask here
All examples you can find here
You can use this package in two ways:
npx swagger-typescript-api generate --path ./swagger.json
Or install locally in your project:
npm install --save-dev swagger-typescript-api
npx swagger-typescript-api generate --path ./swagger.json
npm install --save-dev swagger-typescript-api
import * as path from "node:path";
import * as process from "node:process";
import { generateApi } from "swagger-typescript-api";
await generateApi({ input: path.resolve(process.cwd(), "./swagger.json") });
For more detailed configuration options, please consult the documentation.
Licensed under the MIT License.
FAQs
Generate the API client for Fetch or Axios from an OpenAPI Specification
The npm package swagger-typescript-api receives a total of 220,717 weekly downloads. As such, swagger-typescript-api popularity was classified as popular.
We found that swagger-typescript-api 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.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainer’s token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.