swaxios
Swagger API client generator based on axios and TypeScript.
Last updated 2 months ago by bennyn .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install swaxios 
SYNC missed versions from official npm registry.

Swaxios

Swaxios

A Swagger API client generator based on axios and written in TypeScript.

Installation

You can install Swaxios globally (npm i -g swaxios) or add it to your devDependencies.

Your targeted project must also have a recent version of axios and TypeScript:

npm i axios
npm i -D typescript

Usage

Display all CLI options:

swaxios --help

If you pass an OpenAPI Specification (OAS) (v2.0; JSON or YAML) to Swaxios, then it generates an API client that uses axios under the hood and is written in TypeScript:

# Provide a Swagger input file (JSON or YAML)
swaxios -i ./path/to/swagger.json -o ./path/to/output/directory
swaxios -i ./path/to/swagger.yml -o ./path/to/output/directory

# Alternative: Provide a URL to a Swagger endpoint
swaxios -i http://127.0.0.1:3000/documentation-json -o ./path/to/output/directory

With the -f option, you can force Swaxios to overwrite existing files in the output path:

swaxios -i ./path/to/swagger.json -o ./path/to/output/directory -f

Examples

You can find many examples of generated API client code in our snapshots section.

Here is a basic example:

ExchangeService.ts

/* tslint:disable */

/**
 * This file was automatically generated by "Swaxios".
 * It should not be modified by hand.
 */

import {AxiosInstance, AxiosRequestConfig} from 'axios';

export class ExchangeService {
  private readonly apiClient: AxiosInstance;

  constructor(apiClient: AxiosInstance) {
    this.apiClient = apiClient;
  }

  deleteExchange = async (id: number): Promise<void> => {
    const config: AxiosRequestConfig = {
      method: 'delete',
      url: `/api/v1/exchange/${id}`,
    };
    await this.apiClient.request(config);
  };
}

It has been generated from the following path:

swagger.json

{
  // ...
  "paths": {
    "/api/v1/exchange/{id}": {
      "delete": {
        "consumes": ["application/json"],
        "operationId": "deleteExchange",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "type": "number"
          }
        ],
        "produces": ["application/json"],
        "responses": {
          "200": {
            "description": ""
          }
        }
      }
    }
  }
  // ...
}

Credits

This project is inspired by swagger-codegen.

Current Tags

  • 0.1.2                                ...           latest (2 months ago)

25 Versions

  • 0.1.2                                ...           2 months ago
  • 0.1.1                                ...           2 months ago
  • 0.1.0                                ...           2 months ago
  • 0.0.22                                ...           2 months ago
  • 0.0.21                                ...           2 months ago
  • 0.0.20                                ...           2 months ago
  • 0.0.19                                ...           2 months ago
  • 0.0.18                                ...           2 months ago
  • 0.0.17                                ...           3 months ago
  • 0.0.16                                ...           3 months ago
  • 0.0.15                                ...           3 months ago
  • 0.0.14                                ...           4 months ago
  • 0.0.13                                ...           4 months ago
  • 0.0.12                                ...           4 months ago
  • 0.0.11                                ...           4 months ago
  • 0.0.10                                ...           5 months ago
  • 0.0.9                                ...           5 months ago
  • 0.0.8                                ...           5 months ago
  • 0.0.7                                ...           5 months ago
  • 0.0.6                                ...           5 months ago
  • 0.0.5                                ...           5 months ago
  • 0.0.4                                ...           5 months ago
  • 0.0.3                                ...           5 months ago
  • 0.0.2                                ...           5 months ago
  • 0.0.1                                ...           5 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 25
Last Day 0
Last Week 0
Last Month 26
Dependencies (10)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |