Cody2333 / koa-swagger-decorator

using decorator to automatically generate swagger doc for koa-router
348 stars 81 forks source link

body参数校验失败 #136

Open sunyf1 opened 2 years ago

sunyf1 commented 2 years ago

ts项目中设置body中的参数为required:true,并没有生效

paoesco commented 2 years ago

Hello, I encountered the same problem. required in @body is skipped.

With debugger, I looked and in node-modules/koa-swagger-decorator/lib/validate/index.ts, line 19, the expect variable is:

{
  firstName: { type: "string" }
}

but my declared schema is

@body({
  firstName: { type: "string", required: true }
})

@query and @path are working correctly.

paoesco commented 2 years ago

Looking at previous PR, I believe this is the PR that actually strips required field in @body: https://github.com/Cody2333/koa-swagger-decorator/pull/112 and prevents the validation for required fields. Might need to reconstruct the correct expect object or for body validate based on required swagger definition

paoesco commented 2 years ago

This can be closed as the new version now correctly validates the body of the requests.