我使用侏儒作为基于阿杰夫的验证程序包,设置jsonschema如下所示
serviceDate: {
type: 'string',
format: 'date-time'
},我的request是这样的,它与date-time基本一致
{
"serviceDate":"2022-03-06T00:00:00"
}但是它在错误响应之后返回。我完全搞不懂那是怎么回事。如果有人有意见,请告诉我。谢谢
{
"errorMessage": "Request body validation failed: does not conform to the \"date-time\" format, is not of a type(s) number, is not of a type(s) number, is not of a type(s) number",
"errorType": "Error",
"offlineInfo": "If you believe this is an issue with serverless-offline please submit it, thanks. https://github.com/dherault/serverless-offline/issues",
"stackTrace": [
"Error: Request body validation failed: does not conform to the \"date-time\" format, is not of a type(s) number, is not of a type(s) number, is not of a type(s) number",
"at payloadSchemaValidator (file:///Users/h.miyashita/post-pricing/packages/presentation/rest-api/shop-api/node_modules/serverless-offline/src/events/http/payloadSchemaValidator.js:7:11)",
"at hapiHandler (file:///Users/h.miyashita/post-pricing/packages/presentation/rest-api/shop-api/node_modules/serverless-offline/src/events/http/HttpServer.js:638:11)",
"at exports.Manager.execute (/Users/h.miyashita/post-pricing/node_modules/@hapi/hapi/lib/toolkit.js:57:29)",
"at Object.internals.handler (/Users/h.miyashita/post-pricing/node_modules/@hapi/hapi/lib/handler.js:46:48)",
"at exports.execute (/Users/h.miyashita/post-pricing/node_modules/@hapi/hapi/lib/handler.js:31:36)",
"at Request._lifecycle (/Users/h.miyashita/post-pricing/node_modules/@hapi/hapi/lib/request.js:371:68)",
"at processTicksAndRejections (node:internal/process/task_queues:95:5)"
]
}我发现了来自验证包的以下列表,但我仍未找到根本原因
'date-time': /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(3[01]|0[1-9]|[12][0-9])[tT ](2[0-4]|[01][0-9]):([0-5][0-9]):(60|[0-5][0-9])(\.\d+)?([zZ]|[+-]([0-5][0-9]):(60|[0-5][0-9]))$/,
'date': /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(3[01]|0[1-9]|[12][0-9])$/,
'time': /^(2[0-4]|[01][0-9]):([0-5][0-9]):(60|[0-5][0-9])$/,
'duration': /P(T\d+(H(\d+M(\d+S)?)?|M(\d+S)?|S)|\d+(D|M(\d+D)?|Y(\d+M(\d+D)?)?)(T\d+(H(\d+M(\d+S)?)?|M(\d+S)?|S))?|\d+W)/i,发布于 2022-07-26 08:42:20
输入的"2022-03-06T00:00:00"与date-time正则表达式不匹配
^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(3[01]|0[1-9]|[12][0-9])[tT ](2[0-4]|[01][0-9]):([0-5][0-9]):(60|[0-5][0-9])(\.\d+)?([zZ]|[+-]([0-5][0-9]):(60|[0-5][0-9]))$差不多可以了。它与regex的这一部分相匹配:
^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(3[01]|0[1-9]|[12][0-9])[tT ](2[0-4]|[01][0-9]):([0-5][0-9]):(60|[0-5][0-9])(\.\d+)?你错过了另一部分:
([zZ]|[+-]([0-5][0-9]):(60|[0-5][0-9]))$迫使你提供一个时区。有几个例子:
2022-03-06T00:00:00z
2022-03-06T00:00:00Z
2022-03-06T00:00:00+03:00https://stackoverflow.com/questions/73119471
复制相似问题