Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>lua-swaggerNew to Visual Studio Code? Get it now.
lua-swagger

lua-swagger

jin_sun

|
66 installs
| (0) | Free
lua-swagger注释插件
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

lua-swagger

在lua项目快速生成swagger注释,一键生成route代码,发布到yapi。

Features

  • ⚙️ Supports一键生成swagger注释[右键->swagger-comment]
  • 🔍 Supports代码跳转
  • 🦺 Supports-Swagger注释提示
  • 🖊️ Supports-Swagger注释补全

准备工作

For Mac

# 本插件自带一个可执行文件,对于Mac需要开启 “隐私权限里面的未知来源”

I. 项目目录里新建main.lua文件(项目全局配置)

    # 在main.lua里 右键 -> swagger-main 生成初始化配置
    # 修改项目title,description

II. lua-swagger需要配置多个配置。

需要在本地vscode项目,在lua-swagger插件页面,打开settting,在每个项目生成setting.json,不同项目,配置也不同 setting.json文件,需要根据下面的“setting.json配置字段解释”配合修改

{
    "dto_dir": "./ngx_conf/dto",
    "swagger.docs.path": "./docs",
    "swagger.excludes": "./client",
    "swagger.file.type": "json",
    "swagger.main.lua.path": "./main.lua",
    "swagger.name": "swagger",
    "swagger.search_dirs": "./ngx_conf,./config/cn/online",
    "validator_dir": "./ngx_conf/validator",
    "yapi.config.file": "docs/swagger-yapi.json",
    "yapi.config.mode": "mergin",
    "yapi.config.server": "https://api.yapi.net",
    "yapi.config.token": "xxxxxxxxxxxxxxxx"
}

setting.json配置字段解释

配置选项 Description
swagger.comment.tpl 自动生成的swagger注释模版
swagger.main.tpl 自动生成的main.lua注释模版
dto_dir dto_dir,dto的目录
validator_dir 自动生成的validator的目录
swagger.search_dirs 生成swagger文档,搜索的目录列表,可以用逗号隔开
swagger.excludes 需要排除的目录[不会被lua-swagger代码分析],比如./client
swagger.main.lua.path main.lua的相对路径
swagger.docs.path 生成swagger文档的目录
swagger.name 生成swagger文档的文件名
swagger.file.type 生成swagger文档的文件类型,json or yaml
yapi.config.token yapi项目的个人token,打开yapi项目->设置->复制token
yapi.config.file 导入的swagger文档路径
yapi.config.mode yapi导入的模式,merge: 普通模式(normal):不导入已存在的接口,智能合并(good):已存在的接口,完全覆盖(mergin):不保留旧数据
yapi.config.server yapi的url,yapi的地址

III. 如若需要使用自动生成route代码自动效验功能。

# 安装 jsonschema (https://github.com/api7/jsonschema/tree/master)

Use

一键生成swagger-router注释

avatar

一键生成swagger-router代码 && 上传到YAPI

avatar

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft