Schema definition circular references #3473
Unanswered
EmileSpecs
asked this question in
Q&A
Replies: 2 comments 11 replies
-
It seems to me like the most simple solution here is just to use JSON Schema instead, as it doesn't give any errors when doing the same circular relations. Any opinions, as I know TypeBox is the preferred option? |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can always fall back fall back to JSON schema directly with Type.Unsafe. const userSchema = Type.Object(
{
id: Type.String({ format: 'uuid' }),
email: Type.String({ format: 'email' }),
account: Type.Ref(accountSchema)
},
{ $id: 'User', additionalProperties: false }
)
const accountSchema = Type.Object(
{
id: Type.String({ format: 'uuid' }),
name: Type.String(),
users: Type.Array(Type.Unsafe<User>({ $ref: 'User' })),
locations: Type.Array(Type.Ref(locationSchema))
},
{ $id: 'Account', additionalProperties: false }
) |
Beta Was this translation helpful? Give feedback.
11 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi
Please see sinclairzx81/typebox#844 for reference.
The solution offered unfortunately won't work in the context of feathers since none of the other functions like the
TReference
type produced for schema.For example
getValidator
wants schema:schema: TObject<TProperties> | TIntersect<TObject<TProperties>[]> | TUnion<TObject<TProperties>[]>
Is there any other suggested way of defining references to other schemas that reference each other that will work?
Reference to my definitions as mentioned in the post above:
The provided solution that does not solve the issue for me in feathers:
Would appreciate some help on how to make this work!
Beta Was this translation helpful? Give feedback.
All reactions