Is it possible to create a recursive schema definition?
I stumbled on this issue when implementing a hierarchical scheme using recursion schemas.
To define our JSON schemas we use sinclair/typebox like so:
export const ArticleCategorySchemaTest = Type.Array(
Type.Rec(
(Self) =>
Type.Object({
sequenceNumber: Type.Number({ minimum: 1 }),
subCategories: Type.Optional(Type.Array(Self)),
}),
{ $id: 'ArticleCategoryTest' },
),
);
This generates following schema:
{
kind: Symbol(ArrayKind),
type: 'array',
items: {
'$id': 'ArticleCategoryTest',
'$ref': 'ArticleCategoryTest#/$defs/self',
'$defs': {
self: {
kind: Symbol(ObjectKind),
type: 'object',
properties: {
sequenceNumber: { minimum: 1, kind: Symbol(NumberKind), type: 'number' },
subCategories: {
kind: Symbol(ArrayKind),
type: 'array',
items: { '$ref': 'ArticleCategoryTest#/$defs/self' },
modifier: Symbol(OptionalModifier)
}
},
required: [ 'sequenceNumber' ]
}
}
}
}
When starting up the fastify server i get following error:
Failed building the serialization schema for ..., due to error Maximum call stack size exceeded
I've seen following issues:
I'm just not sure what casues this error.
Your Environment
- node version: 16.13.0
- fastify version: 3.23.0
- os: Mac
- fast-json-stringify: 2.7.13
- sinclair/typebox: 0.21.2
Is it possible to create a recursive schema definition?
I stumbled on this issue when implementing a hierarchical scheme using recursion schemas.
To define our JSON schemas we use
sinclair/typeboxlike so:This generates following schema:
When starting up the fastify server i get following error:
I've seen following issues:
These issues should be solved according to the comments and pull requests.
I'm just not sure what casues this error.
Your Environment