fast-json-stringify: Failed building the serialization schema when it is a typebox object with an "any" type
🐛 Bug Report
When using a valid schema with a property define as an any
kind of type, {}
in json schema (without enforced type), fastify just crash
To Reproduce
Steps to reproduce the behavior:
Add a response schema with something like
{
schema: {
response: {
200: {type: "object", properties: {foo: {}}}
}
}
}
note the absence of type
for property foo
Expected behavior
A clear and concise description of what you expected to happen.
FastifyError [Error]: Failed building the serialization schema for GET: /foos, due to error undefined unsupported
, at Boot.emit (events.js:327:22)
, at Boot.<anonymous> (/project/node_modules/fastify/lib/route.js:280:19)
, at Object.onceWrapper (events.js:421:28)
, at /project/node_modules/avvio/boot.js:153:12
, at /project/node_modules/avvio/plugin.js:269:7
, at done (/project/node_modules/avvio/plugin.js:201:5)
, at check (/project/node_modules/avvio/plugin.js:225:9)
, at internal/process/task_queues.js:153:7
, at AsyncResource.runInAsyncScope (async_hooks.js:186:9)
, at AsyncResource.runMicrotask (internal/process/task_queues.js:150:8) {
, code: 'FST_ERR_SCH_SERIALIZATION_BUILD',
, statusCode: 500
,}
Ajv validation as input works fine, schema is valid, serialisation should be fine too.
Your Environment
- node version: 12 LTS
- fastify version: ^3.3.0
- os: Linux
- any other relevant information
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 15 (7 by maintainers)
Very similar to #253
Yes, we should manage this case as the issue you linked: when a type is missing the default should be
object
withadditionalProperties: true
(if is not defined)To fix it you should remove the
enum
check from this #254 PR, you could take inspiration from that one to add new tests 👍