Skip to content

Emitter usage

  1. Via the command line
Terminal window
tsp compile . --emit=@typespec/json-schema
  1. Via the config
emit:
- "@typespec/json-schema"

The config can be extended with options as follows:

emit:
- "@typespec/json-schema"
options:
"@typespec/json-schema":
option: value

Type: absolutePath

Defines the emitter output directory. Defaults to {output-dir}/@typespec/json-schema See Configuring output directory for more info

Type: "yaml" | "json"

Serialize the schema as either yaml or json.

Type: "string" | "number"

How to handle 64 bit integers on the wire. Options are:

  • string: serialize as a string (widely interoperable)
  • number: serialize as a number (not widely interoperable)

Type: string

When provided, bundle all the schemas into a single json schema document with schemas under $defs. The provided id is the id of the root document and is also used for the file name.

Type: boolean

When true, emit all model declarations to JSON Schema without requiring the @jsonSchema decorator.

Type: boolean

When true, emit all references as json schema files, even if the referenced type does not have the @jsonSchema decorator or is not within a namespace with the @jsonSchema decorator.

Type: boolean

If true, then for models emitted as object schemas we default unevaluatedProperties to { not: {} }, if not explicitly specified elsewhere. Default: false

Type: "ignore" | "oneOf" | "anyOf"

Strategy for emitting models with the @discriminator decorator:

  • ignore: Emit as regular object schema (default). Derived models use allOf to reference their base model.
  • oneOf: Emit a oneOf schema with references to all derived models (closed union)
  • anyOf: Emit an anyOf schema with references to all derived models (open union)

When using oneOf or anyOf, derived models will inline all properties from their base model instead of using allOf references. This avoids circular references in the generated schemas, since the base model references derived models via oneOf/anyOf.