2.0.4 • Published 1 year ago
swagger-to-apis v2.0.4
swagger-to-apis
Installing
Package manager
Using npm:
$ npm install swagger-to-apisUsing yarn:
$ yarn add swagger-to-apisGenerate
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 apiChange baseURL
View src/apis/http.ts, on the 11 line;
const baseURL = '/'; // change to your base urlChange 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
1 year ago
2.0.2
1 year ago
2.0.4
1 year ago
2.0.1
1 year ago
2.0.0
1 year ago
1.0.21
1 year ago
1.0.20
2 years ago
1.0.19
2 years ago
1.0.18
2 years ago
1.0.17
2 years ago
1.0.16
2 years ago
1.0.15
2 years 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