swagger-chen
v1.0.1
Published
接口文档,swagger文档,js注释生成接口文档,js注释生成swagger文档
Downloads
4
Readme
安装
npm install swagger-chen
使用
const swagger,{ optionsType } = require('swagger-chen');
let swaggerOptions:optionsType = {
openapi: "3.0.3",
info: {
title: "koa-ts-api",
version: "1.0.0",
description: `koa-ts-jwt-sequelize-api`,
},
host: "localhost:3000",
basePath: "",
produces: ["application/json", "application/xml"],
schemes: ["http", "https"],
securityDefinitions: {
JWT: {
type: "apiKey",
in: "header",
name: "Authorization",
description: "JWT 认证,请在请求头中提供 Bearer 令牌",
},
},
}
new swagger(path.join(__dirname, './router'), app, router, swaggerOptions);
在路由中怎么使用注释生成swagger文档
/**
* 文字生成语音
* @param model_name 模型名称
* @param text 待合成文本
* @returns object<context:string>
*/
router.post('/textToAudio', async (ctx: Context, next: Next) => {...})
/**
* 获取轮播图列表
* @param {string} keyword? 关键字搜索
* @param {number} pageIndex 第几页
* @param {number} pageSize 每页条数
* @returns array<{show:integer,tenantId:integer,id:integer,name:string,pictureUrl:string,sort:integer}>
*/
router.get('/page', async (ctx: Context, next: Next) => {...})