Skip to content

[T] ExtensionDecorator

type ExtensionDecorator: (context, target, key, value) => void;

Specify a custom property to add to the emitted schema. Useful for adding custom keywords and other vendor-specific extensions. Scalar values need to be specified using typeof to be converted to a schema.

For example, @extension("x-schema", typeof "foo") will emit a JSON schema value for x-schema, whereas @extension("x-schema", "foo") will emit the raw code "foo".

The value will be treated as a raw value if any of the following are true:

  1. The value is a scalar value (e.g. string, number, boolean, etc.)
  2. The value is wrapped in the Json<Data> template
  3. The value is provided using the value syntax (e.g. #{}, #[])

For example, @extension("x-schema", { x: "value" }) will emit a JSON schema value for x-schema, whereas @extension("x-schema", #{x: "value"}) and @extension("x-schema", Json<{x: "value"}>) will emit the raw JSON code {x: "value"}.

Parameters

ParameterTypeDescription
contextDecoratorContext-
targetType-
keystringthe name of the keyword of vendor extension, e.g. x-custom.
valueType | unknownthe value of the keyword.

Returns

void