Skip to content

Latest commit

 

History

History
83 lines (56 loc) · 2.17 KB

File metadata and controls

83 lines (56 loc) · 2.17 KB

Swagger TypeScript API

  • Support for OpenAPI 3.0, 2.0, JSON and YAML
  • Generate the API Client for Fetch, Axios, or Ky from an OpenAPI Specification

Any questions you can ask here: https://github.com/acacode/swagger-typescript-api/discussions

Examples

All examples you can find here: https://github.com/acacode/swagger-typescript-api/tree/main/tests

Usage

You can use this package in two ways:

CLI

npx swagger-typescript-api generate --path ./swagger.json

Using different HTTP clients

Generate an API client with Ky:

npx swagger-typescript-api generate --path ./swagger.json --ky

Generate an API client with Axios:

npx swagger-typescript-api generate --path ./swagger.json --axios

By default, the Fetch API is used.

Or install locally in your project:

npm install --save-dev swagger-typescript-api
npx swagger-typescript-api generate --path ./swagger.json

Library

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";

// Generate with default Fetch API
await generateApi({ input: path.resolve(process.cwd(), "./swagger.json") });

// Generate with Ky
await generateApi({ 
  input: path.resolve(process.cwd(), "./swagger.json"),
  httpClientType: "ky"
});

// Generate with Axios
await generateApi({ 
  input: path.resolve(process.cwd(), "./swagger.json"),
  httpClientType: "axios"
});

For more detailed configuration options, please consult the documentation.

Mass media

License

Licensed under the MIT License.