🐛 Bug Report
Using some named schema as items in other schema cause exception when using first schema
To Reproduce
Steps to reproduce the behavior:
Add schema with simple item. Then add schema for items array and use first schema $id in items.
Then use the first schema in some route.
Paste your code here:
const fastify = require('fastify')();
(async () => {
const name = 'item';
const item = {type: 'object', properties: {foo: {type: 'string'}}};
fastify.addSchema({
$id: `${name}`,
...item,
});
fastify.addSchema({
$id: `${name}List`,
type: 'array',
items: `${name}#`,
});
fastify.get(
'/',
{
schema: {
response: {
200: `${name}#`,
},
},
},
async (req, res) => {
return {};
}
);
await fastify.ready();
await fastify.listen(3000);
console.log('app listens');
})();
(node:21665) UnhandledPromiseRejectionWarning: Error: schema is invalid: data.items should be object,boolean, data.items should be array, data.items should match some schema in anyOf
at Ajv.validateSchema (/tmp/xxx/node_modules/ajv/lib/ajv.js:177:16)
at Ajv._addSchema (/tmp/xxx/node_modules/ajv/lib/ajv.js:306:10)
at Ajv.addSchema (/tmp/xxx/node_modules/ajv/lib/ajv.js:136:29)
at Object.keys.forEach.key (/tmp/xxx/node_modules/fast-json-stringify/index.js:937:11)
at Array.forEach (<anonymous>)
at isValidSchema (/tmp/xxx/node_modules/fast-json-stringify/index.js:936:33)
at build (/tmp/xxx/node_modules/fast-json-stringify/index.js:39:3)
at getValidatorForStatusCodeSchema (/tmp/xxx/node_modules/fastify/lib/validation.js:13:10)
at /tmp/xxx/node_modules/fastify/lib/validation.js:19:21
at Array.reduce (<anonymous>)
Expected behavior
No exception thrown.
Your Environment
- node version: 11
- fastify version: 2.0.0
- os: Mac, Linux
🐛 Bug Report
Using some named schema as
itemsin other schema cause exception when using first schemaTo Reproduce
Steps to reproduce the behavior:
Add schema with simple item. Then add schema for items array and use first schema
$idinitems.Then use the first schema in some route.
Paste your code here:
Expected behavior
No exception thrown.
Your Environment