GithubHelp home page GithubHelp logo

hanzhangyu / yapi-to-typescript Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fjc0k/yapi-to-typescript

0.0 1.0 0.0 881 KB

根据 YApi 的接口定义生成 TypeScript 的接口类型及其请求函数代码。

License: MIT License

JavaScript 5.08% TypeScript 94.92%

yapi-to-typescript's Introduction

这里是 v1 版本的文档,v0 版本的文档见:yapi-to-typescript/tree/v0

YApi to TypeScript Build Status codecov

根据 YApi 的接口定义生成 TypeScript 的接口类型及其请求函数代码。

环境要求

  • Node >= 8
  • YApi >= 1.5.12

特性

  • 支持多服务器、多项目、多分类
  • 支持预处理接口信息
  • 可自定义类型或函数名称
  • 完整的注释

安装

# yarn
yarn add yapi-to-typescript

# 或者,npm
npm i yapi-to-typescript --save

使用

yapi-to-typescript 基于当前目录下的 ytt.config.ts 配置文件进行相关操作。

生成配置文件

使用命令 ytt init 可在当前目录自动创建配置文件 ytt.config.ts,如果配置文件已存在,将会询问你是否覆盖:

# yarn
yarn ytt init

# 或者,npm
npm run ytt init

修改配置文件

打开当前目录下的 ytt.config.ts 配置文件,直接修改即可。查看配置说明

生成 TypeScript 的接口类型及其请求函数代码

直接执行命令 ytt 即可抓取 YApi 的接口定义并生成相应的 TypeScript 代码:

# yarn
yarn ytt

# 或者,npm
npm run ytt

配置

概论

从实质上而言,配置就是一个服务器列表,各个服务器又包含一个项目列表,各个项目下都有一个分类列表,其类型大致如此:

type Servers = Array<{
  projects: Array<{
    categories: Array<{
      // ...
    }>
  }>
}>

// 配置实质是一个服务器列表
type Config = Servers

因此,你可分别在 服务器级别项目级别分类级别 进行相关配置,如果不同级别存在相同的配置项,低级别的配置项会覆盖高级别的配置项,也就是说:

  • 如果存在相同的配置项,分类级别 的配置会覆盖 项目级别服务器级别 的配置项;
  • 如果存在相同的配置项,项目级别 的配置会覆盖 服务器级别 的配置项。

配置项

具体配置项见:API 文档

许可

MIT @ Jay Fong

yapi-to-typescript's People

Contributors

fjc0k avatar hanzhangyu avatar

Watchers

 avatar

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.