Giter Club home page Giter Club logo

swagger2ts's Introduction

中文简体 | English

Build Status

从 swagger(v3) 的 JSON 文件生成 typescript 代码。

它会生成 typescript 的声明和基于 fetch 的运行时。几乎开箱即用。

它能够适用于绝大多数场景,强健你的接口调用,省去烦人的类型声明。

这里有一些生成好的精美例子,看看是否符合您的胃口

安装

通过 Deno 安装

deno install \
  -A \
  --no-check \
  --reload \
  -f \
  https://github.com/axetroy/swagger2ts/raw/v0.2.24/swagger2ts.ts

或者通过 npm 安装

npm install -g @axetroy/swagger2ts

使用

使用命令行工具

swagger2ts swagger.json > api.ts
swagger2ts https://example.com/swagger.json > api.ts

通过 nodejs 函数调用

import { generate } from "@axetroy/swagger2ts";

const output = await generate("/path/to/swagger.json");
// const output = await generate("https://example.com/swagger.json");

console.log(output);

通过 Deno 函数调用

import { generate } from "https://github.com/axetroy/swagger2ts/raw/v0.2.24/generate.ts";

const output = await generate("/path/to/swagger.json");
// const output = await generate("https://example.com/swagger.json");

console.log(output);

开源许可

The MIT License

swagger2ts's People

Contributors

axetroy avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

maoxiaomeng2021

swagger2ts's Issues

How to use

请问生成过后的代码,如何使用呢?
//export type IClient = SwaggerApi & IRuntime
//export const defaultApi = new Runtime("http://localhost", "") as unknown as IClient
defaultApi 点不出来任何东西哎?请大佬讲一下楠

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.