-
-
Notifications
You must be signed in to change notification settings - Fork 208
fix: passing null object to type array defaults to empty array (#249) #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
zekth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
RafaelGSS
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is unexpected behavior. The following snippet sent an empty array by default
const schema = {
type: 'object',
properties: {
arr: {
type: 'array',
items: {
type: 'number'
},
default: [],
}
}
}
const stringify = fastJson(schema)
const valueStr = stringify({}) // {"arr":[]}Although throwing an error doesn't look good.
|
@RafaelGSS Added a unit test with your case. |
|
No, I said the current implementation(master) seems to have expected behavior since Btw the last test case is not necessary, is already being tested here |
Oh ok. |
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure passing null for the array would validate this schema? Can you check with ajv?
My understanding is that null is not a valid array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const schema = {
type: 'object',
properties: {
foo: {
$id: '#/properties/foo',
type: 'array',
default: [],
items: {
$id: '#/properties/foo/items'
}
}
}
}
const obj = {
foo: null
}
var Ajv = require('ajv')
var ajv = new Ajv()
var validate = ajv.compile(schema)
var valid = validate(obj)
if (!valid) console.log(validate.errors)
// output
// [
// {
// keyword: 'type',
// dataPath: '.foo',
// schemaPath: '#/properties/foo/type',
// params: { type: 'array' },
// message: 'should be array'
// }
// ]Indeed
|
I followed the issue, too strictly actually. |
Yes, go for it! |
|
Updated the code. |
mcollina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
|
@mcollina Would you mind adding |
|
Thanks 😁 |
Checklist
npm run testandnpm run benchmarkand the [Code of conduct](https://github.com/fastify/.github/blob/master/CODE_OF_CONDUCT.