Reputation: 193
When adding a response schema to a fastify resource that leverages the $merge
keyword, an error
FST_ERR_SCH_BUILD: Failed building the schema for GET: /, due error undefined unsupported
is thrown.
Schema looks like the following, but the same error is thrown using the examples from ajv or fastify.
response: {
200: {
$merge: {
source: {
type: 'object',
properties: {
foo: { type: 'string' }
}
},
with: {
type: 'object',
properties: {
bar: { type: 'string' }
}
}
}
}
}
workaround described in own answer
Upvotes: 0
Views: 556
Reputation: 12870
The serializer doesn't implement the ajv's schema customization (as it is $merge
). Under the hood fast-json-stringify is used by default.
You should use standard JSON schema and its combining keywords.
In fastify v2 the serializer that uses the schemas is not customizable, so you should write your own serializer and set up it using setReplySerializer
.
Upvotes: 0
Reputation: 193
I have found a workaround for this:
it seems that unlike when using $merge
in any other schema, either fastify or ajv require the type
keyword to be present on $merge
level.
This might be a bug, as it can be deduced from the merged objects and the methodology works when using $merge
for other schemas.
Upvotes: 0