Giter Club home page Giter Club logo

openapi2typescript's Introduction

使用说明

示例

在test目录下增加文件testgen.js

内容如下:

const openAPI = require('../dist/index');

openAPI.generateService({
  schemaPath: 'http://localhost:5000/ReleaseManager/swagger/v1/swagger.json',
  serversPath: './temp/relMgr-api',  
  namespace: 'relMgr',
  wrapResult: 'Api.Response'
});

package.jsonscript 中添加 api: "relMgr": "ts-node ./test/genSwagger.js",

生成api

npm run relMgr

参数

属性 必填 备注 类型 默认值
requestLibPath 自定义请求方法路径 string -
requestImportStatement 自定义请求方法表达式 string -
apiPrefix api 的前缀 string -
serversPath 生成的文件夹的路径 string -
schemaPath Swagger 2.0 或 OpenAPI 3.0 的地址 string -
projectName 项目名称 string -
namespace 命名空间名称 string API
mockFolder mock目录 string -
enumStyle 枚举样式 string-literal | enum string-literal
nullable 使用null代替可选 boolean false
dataFields response中数据字段 string[] -
wrapResult 用来包含response结果的对象 obj -

对于apiPrefix属性,默认是生成插入值变量,如果需要直接生成字符串,那么需要这样用apiPrefix:'"apiPrefix"'

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.