jsonma / swagger-egg Goto Github PK
View Code? Open in Web Editor NEWEggjs Swagger-UI API文档自动生成插件(如果喜欢请点赞支持)。Egg swagger documentation generator(welcome to star this project).
License: MIT License
Eggjs Swagger-UI API文档自动生成插件(如果喜欢请点赞支持)。Egg swagger documentation generator(welcome to star this project).
License: MIT License
[swagger-egg] [egg-core] load file: xxx\app\router.js, error: ENOENT: no such file or directory, open 'xxx\app\router.js'
@description #parameters {PrameterName} {In} {ParameterSchema} {Required} - {Description}
目前在controller中,是否可以直接在{ParameterSchema}处 直接配置参数的类型,比如常用的 string ,number,object,file 等?
例如:
*@description#parameters obj query {number} false - obj
因为 swagger-egg 是自己用正则解析 app/router.ts
文件内容,获取路由信息。
参考 node_modules/swagger-egg/lib/router_loader.js 中的 getRouter() 方法。
导致很多情况解析不出来,比如
egg-router-plus
'path-match'
不是字符串字面量,而是一个表达式或变量router.verb('path-match', app.controller.action);
router.verb('router-name', 'path-match', app.controller.action);
router.verb('path-match', middleware1, ..., middlewareN, app.controller.action);
router.verb('router-name', 'path-match', middleware1, ..., middlewareN, app.controller.action);
eggjs新建 TS 项目。 [email protected]
, [email protected]
正常写 app/schema/definitions.ts
。
先 yarn run tsc
,再 yarn start
。
[egg-scripts] File '<egg-app>/app/schema/definitions.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
[egg-scripts] The file is in the program because:
[egg-scripts] Root file specified for compilation
奇怪为什么 app/schema/definitions.js
会成为 root file。
在 egg-scripts 中断点拿到的此异常的信息 error TS6504: File '*.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
eggjs为TS应用生成的 tsconfig.json 中为 compilerOptions.allowJs: false
,不确定eggjs是否对此强依赖。如果改成 true
,那么在 yarn run tsc
时会报错,或许是强依赖,没继续深入研究。
error TS2347: Untyped function calls may not accept type arguments.
error TS2339: Property 'mongoose' does not exist on type 'MockApplication'.
const invalidAccountAppId = (new app.mongoose.Types.ObjectId()).toString();
大部分接口都是需要token等头信息验证才能访问的,该如何设置呢?
估计是内网域名。导致按照 package-lock.json
无法安装 node_modules
。
报错的大概信息是:
error: ENOENT: no such file or directory, open '/Users/xxxx/Documents/my-gitlab-project/egg-project-example/hello-tegg/app/router.ts
tegg 的写法是将路由放在 controller里面了,类似midway 写法了
schema如何支持array类型,则其下元素为object
我想在apifox里配置post请求,一般我的post请求都是用的json格式,不是x-www-form-urlencoded的格式,现在我在controller里配置
* @description #parameters userid formData string true - 用户id
导入到Apifox以后变成了x-www-form-urlencoded的参数,这样的参数拿到格式不对,请教一下怎么配置
目前我在项目中用的是 ts 来开发,目前支持 ts 项目上有什么问题吗?
destory 写错了 应该是 destroy
当配置 typescriptJsonSchema: true
时, app/schema/**/*.ts
中会编译成 schemaObject
,虽然可以在注释中引用 schemaObject
进行声明,但看起来没法在 app/controller/**/*.ts
的代码中引用 schemaObject
。
建议插件把 schemaObject
挂载到 app
或 ctx
,以便复用于 ctx.valudate(rules, data)
的规则中,否则需要在 rules
中重复声明参数类型等信息。
注意: 若controller、schema文件名中包含短横线:"-" 或者下划线:"_",为了保持与Eggjs特性一致,文件名将会自动转换成驼峰命形式。
// router.js
router.resources('xxx-test', '/api/xxx-test', controller.xxxTest);
// controller/xxx-test.js
class XxxTestController extends Controller {
/**
* #swagger-api
* @function index
* @summary 查询
* @description #tags xxx-test
*/
async index() {
this.ctx.body = 'select!!!';
}
有多个 in body
的 #parameters
时 ,将所生成的 app/public/swagger/*.json
返回给前端用于 @rtk-query/codegen-openapi
,会报错 has multiple requestBodies
按照OpenAPI 2.0示例,in body的 parameters 只有1个,用 properties 表示其中不同的参数。
但 swagger-egg 会生成多个 in body的 parameters
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.