Skip to content

Can schemas be extended? #602

Answered by sinclairzx81
Ghirigoro asked this question in Q&A
Discussion options

You must be logged in to vote

@Ghirigoro Hi,

Extra Metadata

You're free to add additional metadata (including functions) to a schema by passing them on schema options.

const T = Type.String({
  foo: () => 'hello world'
})

TypeBox doesn't limit additional metadata passed via options on a schema, but adding additional properties or functions may render that schema at odds with the specification (so is generally advised against). However it can be useful in documentation generators, form design time metadata, etc, but it's up to the developer to trade off specification alignment for more pragmatic constructs embedded in the schema (for example built in check functions)

Check, Cast, Etc

Generally, it's not recommended to …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Ghirigoro
Comment options

Answer selected by Ghirigoro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants