@typespec/json-schema 0.46.0-dev.11 → 0.46.0-dev.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# TypeSpec JSON Schema Emitter
|
|
2
|
+
|
|
3
|
+
This package provides [TypeSpec](https://github.com/microsoft/TypeSpec) support for emitting JSON Schema version `2020-12` from TypeSpec definitions. It also provides [decorators for adding JSON Schema constraints](https://microsoft.github.io/typespec/standard-library/json-schema/reference/decorators). The emitter supports either YAML or JSON output and can be configured to emit one file per schema or bundle all schemas in to a single file.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @typespec/json-schema
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Add the `@jsonSchema` decorator to any types or namespaces you want to emit as JSON Schema.
|
|
14
|
+
|
|
15
|
+
```TypeSpec
|
|
16
|
+
import "@typespec/json-schema";
|
|
17
|
+
|
|
18
|
+
using TypeSpec.JsonSchema;
|
|
19
|
+
|
|
20
|
+
@jsonSchema
|
|
21
|
+
namespace Example;
|
|
22
|
+
|
|
23
|
+
model Car {
|
|
24
|
+
make: string;
|
|
25
|
+
model: string;
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
To emit JSON Schema, use either of the following:
|
|
30
|
+
|
|
31
|
+
1. Via the command line
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
tsp compile . --emit @typespec/json-schema
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
2. Via the config
|
|
38
|
+
|
|
39
|
+
Add the following to the `tspconfig.yaml` file.
|
|
40
|
+
|
|
41
|
+
```yaml
|
|
42
|
+
emitters:
|
|
43
|
+
@typespec/json-schema: true
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
For more information, consult the [JSON Schema documentation](https://microsoft.github.io/typespec/standard-library/json-schema/reference).
|
|
47
|
+
|
|
48
|
+
## Emitter options
|
|
49
|
+
|
|
50
|
+
### `file-type`
|
|
51
|
+
|
|
52
|
+
**Type:** `"yaml" | "json"`
|
|
53
|
+
|
|
54
|
+
Serialize the schema as either yaml or json.
|
|
55
|
+
|
|
56
|
+
### `int64-strategy`
|
|
57
|
+
|
|
58
|
+
**Type:** `"string" | "number"`
|
|
59
|
+
|
|
60
|
+
How to handle 64 bit integers on the wire. Options are:
|
|
61
|
+
|
|
62
|
+
- string: serialize as a string (widely interoperable)
|
|
63
|
+
- number: serialize as a number (not widely interoperable)
|
|
64
|
+
|
|
65
|
+
### `bundleId`
|
|
66
|
+
|
|
67
|
+
**Type:** `string`
|
|
68
|
+
|
|
69
|
+
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.
|
|
70
|
+
|
|
71
|
+
### `emitAllModels`
|
|
72
|
+
|
|
73
|
+
**Type:** `boolean`
|
|
74
|
+
|
|
75
|
+
When true, emit all model declarations to JSON Schema without requiring the @jsonSchema decorator.
|
|
76
|
+
|
|
77
|
+
### `emitAllRefs`
|
|
78
|
+
|
|
79
|
+
**Type:** `boolean`
|
|
80
|
+
|
|
81
|
+
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.
|
|
82
|
+
|
|
83
|
+
## See also
|
|
84
|
+
|
|
85
|
+
- [Json Schema Emitter Documentation](https://microsoft.github.io/typespec/standard-library/json-schema/reference)
|
|
86
|
+
- [TypeSpec Getting Started](https://github.com/microsoft/typespec#getting-started)
|
|
87
|
+
- [TypeSpec Website](https://microsoft.github.io/typespec)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/json-schema",
|
|
3
|
-
"version": "0.46.0-dev.
|
|
3
|
+
"version": "0.46.0-dev.12",
|
|
4
4
|
"author": "Microsoft Corporation",
|
|
5
5
|
"description": "TypeSpec library for emitting TypeSpec to JSON Schema and converting JSON Schema to TypeSpec",
|
|
6
6
|
"homepage": "https://github.com/microsoft/typespec",
|