You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bundle things outside JSON Schema namespace by default (microsoft#2085)
I think it's somewhat unexpected that you might get schemas for types
outside of a JSON Schema namespace merely because they are referenced.
With this PR, by default we will not emit schemas for such types, and
instead bundle them into the referencing schema. As a result, you will
only get schemas for things you have explicitly annotated with
`@jsonSchema`, either on the declaration or on its containing namespace.
For example:
```
@jsonschema
model Pet { toy: Toy }
model Toy { }
```
will emit a single schema - `Pet.json`, with a `$defs` with Toy.
In order to restore the old behavior, you can pass `emitAllRefs`. This
is technically a breaking change, but I don't expect this is a common
scenario.
It's worth thinking about the behavior here when you are importing a
library of interesting types that you actually WANT to emit as json
schema. There are a few options:
* Pass the `emitAllRefs` option.
* Model-is the things you want into your JSON Schema namespace.
* Use augment decorators on the library's namespace.
* Ask the library to add the necessary JSON Schema metadata.
The latter three options seem like actually good options since it allows
you to provide the namespace/base URI of the schemas, which is
considered a best practice.
In order to implement this change, a new `TypeEmitter` member is
required - `writeOutput` - which lets you customize how you write assets
to disk. For this PR, it is used to skip emitting source files that we
don't actually need on disk. Another scenario this gets used for is when
an emitter composes another emitter and needs to write that emitters
output when its own output is needed. An example is a JSON-RPC emitter
that has an internal JSON Schema emitter and needs to write JSON Schema
to disk.
Additionally, `meta` properties were added to declarations and source
files to allow for arbitrary metadata to be added. This is far more
convenient than establishing maps to maintain this metadata yourself in
your emitter, although at the cost of type safety.
Fixesmicrosoft#2022
---------
Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
"comment": "By default, types that are not marked with @jsonSchema or are within a namespace with @jsonSchema are bundled into the schemas that reference them. Set the `emitAllRefs` option to true to get the previous behavior of emitting all types referenced as JSON Schema.",
0 commit comments