swagger-codegen-ts

从 swagger 生成 ts 代码。

Usage no npm install needed!

<script type="module">
  import swaggerCodegenTs from 'https://cdn.skypack.dev/swagger-codegen-ts';
</script>

README

swagger-codegen-ts

从 swagger 生成 ts 代码。

使用

  1. 安装
yarn add -D swagger-codegen-ts
  1. 从 url 生成:
swagger2ts url http://xxx/v2/api-docs
  1. 从本地生成:
swagger2ts data ./json/openapi.json

使用配置文件

swagger2ts config ./xxx.js

swagger2ts config ./xxx.json

配置

interface CliConfig {
  api: string;

  /** 生成目录 */
  outputDir: string;

  /** Service 模板文件路径 */
  templateDir?: string;

  /** 生成类型,默认为 ts */
  type?: 'ts' | 'js' = 'ts';

  /** 接口类型定义文件的 namespace */
  namespace?: string = 'API';

  /** 自动清除旧文件时忽略列表 */
  ignoreDelete: string[] = [];

  /** 数据处理钩子 */
  hook?: {
    /** 自定义函数名称 */
    customFunctionName?: (data: OperationObject) => string;

    /** 自定义文件名 */
    customfileName?: (tagName: string) => string;
  } = {};
}

备注

tokenAuthorization 的 headers 值从 localStorage 中获取。

备注

本项目基于 openapi-generator 开发。