Type Readonly purpose #465
-
|
HI, I wanted to define some readonly properties in our API definition schema, so we tried to use the Usage example: I was expecting the following schema to be generated: But the actual result is: Currently I had to use a Type.Unsafe type to get the desired result: Am I doing something wrong or is this type not supposed to do what I was expecting? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
@enzolupia Hi! TypeBox only provides Adding
|
Beta Was this translation helpful? Give feedback.
-
|
Hi @sinclairzx81 thanks for your quick and exhaustive response, I will definitely give a try to the solution you suggested. Just a little note, readOnly property is actually part of the draft 7 of the JSON schema 2020-12 specification. Thanks, E |
Beta Was this translation helpful? Give feedback.
-
|
@enzolupia Hi! :)
Ah, I actually meant to say "Isn't part of the JSON Schema Draft 6 specification" (noting TypeBox is based on draft 6 + partial 2019-09 support for intersect I have briefly looked these before, and it's difficult to know how best introduce them proper, particularly const T = Type.Object({
x: Type.Readonly(Type.String(), { readOnly: true }) // options added to readonly, not string
})But this could also be achieved with the following today. const T = Type.Object({
x: Type.Readonly(Type.String({ readOnly: true })) // this also works (albeit a bit superfluous)
})At this stage, given the inability to express Still, will give this some more thought, there's probably something that can be done here (if only to add |
Beta Was this translation helpful? Give feedback.
@enzolupia Hi! :)
Ah, I actually meant to say "Isn't part of the JSON Schema Draft 6 specification" (noting TypeBox is based on draft 6 + partial 2019-09 support for intersect
unevaluatedProperties), but yeah, you're quite right; thereadOnlyandwriteOnlyannotations are defined on draft 2012-12 as metadata (not necessarily related to validation though)I have briefly looked these before, and it's difficult to know how best introduce them proper, particularly
writeOnlyas there…