2.0.4 • Published 8 months ago

swagger-to-apis v2.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

swagger-to-apis

Installing

Package manager

Using npm:

$ npm install swagger-to-apis

Using yarn:

$ yarn add swagger-to-apis

Generate

create your swagger-to-apis.ts file

import { swaggerToApis } from "swagger-to-apis";

// Currently supports v2 and v3.0
swaggerToApis({
  url: "https://petstore.swagger.io/v2/swagger.json", // Change to your URL
  output: "./src",
});

Add the script in your package.json file.

    "api": "npx tsx swagger-to-apis.ts",

Run the script

$ npm run api

Change baseURL

View src/apis/http.ts, on the 11 line;

const baseURL = '/'; // change to your base url

Change Api.Response interface

View src/apis/api.d.ts, on the 11 line;

  // If your API does not have an outer wrapper
  type Response<T> = T;

  // Your API has an outer layer that can be customized to modify the current structure
  // interface Response<T> {
  //   code: number;
  //   msg: string;
  //   message: string;
  //   data: T;
  // }

Use

import { Api } from 'src/apis';

let pet_info: Api.SwaggerV2.Pet;

const res = await Api.SwaggerV2Api.get_pet_petId(1);
if (Api.isSuccess(res)) {
  pet_info = res.data
}

Examples

2.0.3

8 months ago

2.0.2

8 months ago

2.0.4

8 months ago

2.0.1

8 months ago

2.0.0

8 months ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago