koa-swagger-decorator icon indicating copy to clipboard operation
koa-swagger-decorator copied to clipboard

body参数校验失败

Open sunyf1 opened this issue 3 years ago • 3 comments

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

sunyf1 avatar Oct 22 '21 10:10 sunyf1

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 avatar Mar 31 '22 11:03 paoesco

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 avatar Mar 31 '22 11:03 paoesco

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

paoesco avatar Jul 01 '22 16:07 paoesco