swagger-typescript-api Documentation

Generate the API Client for Fetch or Axios from an OpenAPI Specification

4,089 stars TypeScript TypeScript 1 file ยท ~1,244 tokens
RAW Doc

File: README.md

Swagger TypeScript API

  • Support for OpenAPI 3.0, 2.0, JSON and YAML
  • Generate the API Client for Fetch or Axios 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

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

Or install locally in your project:

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

Library

bash
npm install --save-dev swagger-typescript-api
typescript
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.

Mass media

License

Licensed under the MIT License.


File: templates/modular/README.md

swagger-typescript-api

templates/modular

This templates use for multiple api files (--modular option)

path prefix @modular


File: templates/default/README.md

swagger-typescript-api

templates/default

This templates use for single api file (without --modular option)

path prefix @default


File: templates/base/README.md

swagger-typescript-api

templates/base

This templates use both for multiple api files and single api file

path prefix @base


File: templates/README.md

swagger-typescript-api

templates

Templates:

  • api.ejs - (generates file) Api class module (locations: default, modular)
  • data-contracts.ejs - (generates file) all types (data contracts) from swagger schema (locations: base)
  • http-client.ejs - (generates file) HttpClient class module (locations: base)
  • procedure-call.ejs - (subtemplate) route in Api class (locations: default, modular)
  • route-docs.ejs - (generates file) documentation for route in Api class (locations: base)
  • route-name.ejs - (subtemplate) route name for route in Api class (locations: base)
  • route-type.ejs - (--route-types option) (subtemplate) (locations: base)
  • route-types.ejs - (--route-types option) (subtemplate) (locations: base) - data-contract-jsdoc.ejs - (subtemplate) generates JSDOC for data contract (locations: base)