New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

swagger-codegen-next

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-codegen-next

根据swagger.json生成api文件

latest
Source
npmnpm
Version
0.1.9
Version published
Maintainers
1
Created
Source

Swagger Codegen Next

generate .ts api files by swagger.json

📦 Install

npm install swagger-codegen-next -g
yarn global add swagger-codegen-next

🔨 Usage

Configuration File

swagger-codegen.config.js

// swagger-codegen.config.js
const path = require("path");
const cwd = process.cwd();

module.exports = {
  // swagger文件地址
  url: "http://***/swagger.json",
  // 输出目录
  output: {
    path: path.join(cwd, "services"), // default
  },
  // 获取接口模块名称
  getModuleName(url) {
    return /api\/([^\/]*)/.exec(url)[1];
  },
  // 获取接口名
  getMethodName(operationId) {
    return operationId;
  },
  // 需要跳过生成的接口
  exclude: [],
  template: {
    http: 'import http from "../http";'
  }
};

Now you can run the swagger-codegen-next:

swagger-codegen-next

Config

*url

  • support HTTP/HTTPS

    {
      "url": "http://***.swaggger.json" // https://***.swagger.json
    }
    
  • support absolute path

    {
      "url": path.resolve(__dirname, "./swagger.json")
    }
    

*output

The output property tells swagger-codegen-next where to emit the api files .

{
    output: {
        path: path.join(cwd, 'services') // default
    },
}

*getModuleName

The getModuleName method can help swagger-codegen-next to group the APIs.

{
  getModuleName(url){
    return /api\/([^\/]*)/.exec(url)[1]
  }
}

getMethodName

add getMethodName to support to customize the name of a method.

exclude

skip target swagger paths

eg:

exclude: ["/api/user/add"]

LICENSE

MIT

Keywords

swagger

FAQs

Package last updated on 29 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts