安装 openapi 插件
pnpm add -D @umijs/max-plugin-openapi
修改umi配置文件
修改文件:.umirc.ts
添加配置:
export default defineConfig({
plugins: ['@umijs/max-plugin-openapi'],
openAPI: [
{
requestLibPath: "import { request } from '@umijs/max'",
schemaPath: 'http://localhost:8080/v3/api-docs', // openapi 接口地址
mock: false,
},
],
...
});
修改包配置
修改文件:package.json
添加 name
version
属性,否则可能报错。
添加 scripts
{
"name": "project-name",
"version": "1.0.0",
...
"scripts": {
...
"openapi": "max openapi"
},
"dependencies": {
...
},
"devDependencies": {
...
}
}
运行
pnpm openapi
可能出现的问题
如果出现: error - Can not resolve dependence : 'swagger-ui-dist', please install it
可以通过安装 swagger-ui-dist
解决
pnpm add -D swagger-ui-dist