deno.land / x / typebox@0.32.21 / changelog / 0.17.4.md
Changes:
Type.Box()
and Type.Ref()
functions.Notes:
This update provides the Type.Box()
function to enable common related schemas to grouped under a common namespace; typically expressed as a URI
. This functionality is primarily geared towards allowing one to define a common set of domain objects that may be shared across application domains running over a network. The Type.Box()
is intended to be an analog to XML
xmlns
namespaces.
The Type.Ref()
function is limited to referencing from boxes only. The following is an example.
// Domain objects for the fruit service.
const Fruit = Type.Box('https://fruit.domain.com', {
Apple: Type.Object({ ... }),
Orange: Type.Object({ ... }),
})
// An order referencing types of the fruit service.
const Order = Type.Object({
id: Type.String(),
quantity: Type.Number(),
item: Type.Union([
Type.Ref(Fruit, 'Apple'),
Type.Ref(Fruit, 'Orange')
])
})
Note: As of this release, the
Type.Omit()
,Type.Pick()
,Type.Partial()
,Type.Readonly()
andType.Intersect()
functions do not work with Reference Types. This may change in later revisions.
For validation using Ajv
, its possible to apply the Box
directly as a schema.
ajv.addSchema(Fruit) // makes all boxed types known to Ajv
This functionality is flagged as EXPERIMENTAL
and awaits community feedback.
Version Info