Skip to content

Support for JSONSchema custom annotations via arbitrary metadata fields #1301

@jagregory

Description

@jagregory

The JSONSchema spec has support for arbitrary additional properties, called Custom Annotations. It's recommended these only be x- prefixed because a yet-to-exist future draft will enforce the prefix, but historically these annotations could be any non-reserved keyword. These custom annotations are typically used to provide additional tool-specific metadata about fields or schemas, extra validation or type hints etc. OpenAPI, AsyncAPI encourage the use of x- prefixed annotations.

Right now convertAction specifically picks only a handful of well-known annotations:

case 'metadata': {
if (typeof valibotAction.metadata.title === 'string') {
jsonSchema.title = valibotAction.metadata.title;
}
if (typeof valibotAction.metadata.description === 'string') {
jsonSchema.description = valibotAction.metadata.description;
}
if (Array.isArray(valibotAction.metadata.examples)) {
jsonSchema.examples = valibotAction.metadata.examples;
}
break;
}

It would be useful if any arbitary annotations would just be passed-through to the JSONSchema.

So something like this:

pipe(blah, metadata({
  'x-my-annotation': true
});

Would result in a JSONSchema with the annotations included:

"name": {
  "type": "string",
  "x-my-annotation": true
}

See also:

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions