@typespec/json-schema 0.44.0
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/dist/src/index.d.ts +36 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +132 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/json-schema-emitter.d.ts +34 -0
- package/dist/src/json-schema-emitter.d.ts.map +1 -0
- package/dist/src/json-schema-emitter.js +495 -0
- package/dist/src/json-schema-emitter.js.map +1 -0
- package/dist/src/lib.d.ts +45 -0
- package/dist/src/lib.d.ts.map +1 -0
- package/dist/src/lib.js +43 -0
- package/dist/src/lib.js.map +1 -0
- package/dist/src/testing/index.d.ts +3 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +8 -0
- package/dist/src/testing/index.js.map +1 -0
- package/lib/main.tsp +131 -0
- package/package.json +71 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { DecoratorContext, EmitContext, Enum, Model, ModelProperty, Namespace, Program, Scalar, StringLiteral, Tuple, Type, Union } from "@typespec/compiler";
|
|
2
|
+
import "./lib.js";
|
|
3
|
+
import { JSONSchemaEmitterOptions } from "./lib.js";
|
|
4
|
+
export declare const namespace = "JsonSchema";
|
|
5
|
+
export type JsonSchemaDeclaration = Model | Union | Enum | Scalar;
|
|
6
|
+
export declare function $onEmit(context: EmitContext<JSONSchemaEmitterOptions>): Promise<void>;
|
|
7
|
+
export declare function $jsonSchema(context: DecoratorContext, target: JsonSchemaDeclaration | Namespace, baseUriOrId?: string): void;
|
|
8
|
+
export declare function $baseUri(context: DecoratorContext, target: Namespace, baseUri: string): void;
|
|
9
|
+
export declare function getBaseUri(program: Program, target: Type): any;
|
|
10
|
+
export declare function findBaseUri(program: Program, target: JsonSchemaDeclaration | Namespace): string | undefined;
|
|
11
|
+
export declare function getJsonSchemaTypes(program: Program): (Namespace | Model)[];
|
|
12
|
+
export declare function $multipleOf(context: DecoratorContext, target: Model, value: number): void;
|
|
13
|
+
export declare function getMultipleOf(program: Program, target: Type): any;
|
|
14
|
+
export declare function $id(context: DecoratorContext, target: Model | Union | Enum | Scalar, value: string): void;
|
|
15
|
+
export declare function getId(program: Program, target: Type): any;
|
|
16
|
+
export declare function $contains(context: DecoratorContext, target: Model | ModelProperty, value: Type): void;
|
|
17
|
+
export declare function getContains(program: Program, target: Type): any;
|
|
18
|
+
export declare function $minContains(context: DecoratorContext, target: Model | ModelProperty, value: number): void;
|
|
19
|
+
export declare function getMinContains(program: Program, target: Type): any;
|
|
20
|
+
export declare function $maxContains(context: DecoratorContext, target: Model | ModelProperty, value: number): void;
|
|
21
|
+
export declare function getMaxContains(program: Program, target: Type): any;
|
|
22
|
+
export declare function $uniqueItems(context: DecoratorContext, target: Model | ModelProperty): void;
|
|
23
|
+
export declare function getUniqueItems(program: Program, target: Type): any;
|
|
24
|
+
export declare function $minProperties(context: DecoratorContext, target: Model | ModelProperty, value: number): void;
|
|
25
|
+
export declare function getMinProperties(program: Program, target: Type): any;
|
|
26
|
+
export declare function $maxProperties(context: DecoratorContext, target: Model | ModelProperty, value: number): void;
|
|
27
|
+
export declare function getMaxProperties(program: Program, target: Type): any;
|
|
28
|
+
export declare function $contentEncoding(context: DecoratorContext, target: StringLiteral | ModelProperty, value: string): void;
|
|
29
|
+
export declare function getContentEncoding(program: Program, target: Type): string;
|
|
30
|
+
export declare function $contentMediaType(context: DecoratorContext, target: StringLiteral | ModelProperty, value: string): void;
|
|
31
|
+
export declare function getContentMediaType(program: Program, target: Type): string;
|
|
32
|
+
export declare function $contentSchema(context: DecoratorContext, target: StringLiteral | ModelProperty, value: Type): void;
|
|
33
|
+
export declare function getContentSchema(program: Program, target: Type): any;
|
|
34
|
+
export declare function $prefixItems(context: DecoratorContext, target: Model | ModelProperty, value: Tuple): void;
|
|
35
|
+
export declare function getPrefixItems(program: Program, target: Type): Tuple | undefined;
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0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,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,OAE9D;AAGD,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,aAAa,GAAG,aAAa,EACrC,KAAK,EAAE,MAAM,QAGd;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAG,MAAM,CAEzE;AAGD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,aAAa,GAAG,aAAa,EACrC,KAAK,EAAE,MAAM,QAGd;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAG,MAAM,CAE1E;AAGD,wBAAgB,cAAc,CAC5B,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,aAAa,GAAG,aAAa,EACrC,KAAK,EAAE,IAAI,QAGZ;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,OAE9D;AAGD,wBAAgB,YAAY,CAC1B,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,KAAK,GAAG,aAAa,EAC7B,KAAK,EAAE,KAAK,QAGb;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAG,KAAK,GAAG,SAAS,CAEhF"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { JsonSchemaEmitter } from "./json-schema-emitter.js";
|
|
2
|
+
import "./lib.js";
|
|
3
|
+
import { createStateSymbol } from "./lib.js";
|
|
4
|
+
export const namespace = "JsonSchema";
|
|
5
|
+
const jsonSchemaKey = createStateSymbol("JsonSchema");
|
|
6
|
+
export async function $onEmit(context) {
|
|
7
|
+
const emitter = context.getAssetEmitter(JsonSchemaEmitter);
|
|
8
|
+
if (emitter.getOptions().emitAllModels) {
|
|
9
|
+
emitter.emitProgram({ emitTypeSpecNamespace: false });
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
for (const item of getJsonSchemaTypes(context.program)) {
|
|
13
|
+
emitter.emitType(item);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
await emitter.writeOutput();
|
|
17
|
+
}
|
|
18
|
+
export function $jsonSchema(context, target, baseUriOrId) {
|
|
19
|
+
context.program.stateSet(jsonSchemaKey).add(target);
|
|
20
|
+
if (baseUriOrId) {
|
|
21
|
+
if (target.kind === "Namespace") {
|
|
22
|
+
context.call($baseUri, target, baseUriOrId);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
context.call($id, target, baseUriOrId);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const baseUriKey = createStateSymbol("JsonSchema.baseURI");
|
|
30
|
+
export function $baseUri(context, target, baseUri) {
|
|
31
|
+
context.program.stateMap(baseUriKey).set(target, baseUri);
|
|
32
|
+
}
|
|
33
|
+
export function getBaseUri(program, target) {
|
|
34
|
+
return program.stateMap(baseUriKey).get(target);
|
|
35
|
+
}
|
|
36
|
+
export function findBaseUri(program, target) {
|
|
37
|
+
let baseUrl;
|
|
38
|
+
let current = target;
|
|
39
|
+
do {
|
|
40
|
+
baseUrl = getBaseUri(program, current);
|
|
41
|
+
current = current.namespace;
|
|
42
|
+
} while (!baseUrl && current);
|
|
43
|
+
return baseUrl;
|
|
44
|
+
}
|
|
45
|
+
export function getJsonSchemaTypes(program) {
|
|
46
|
+
return [...(program.stateSet(jsonSchemaKey) || [])];
|
|
47
|
+
}
|
|
48
|
+
const multipleOfKey = createStateSymbol("JsonSchema.multipleOf");
|
|
49
|
+
export function $multipleOf(context, target, value) {
|
|
50
|
+
context.program.stateMap(multipleOfKey).set(target, value);
|
|
51
|
+
}
|
|
52
|
+
export function getMultipleOf(program, target) {
|
|
53
|
+
return program.stateMap(multipleOfKey).get(target);
|
|
54
|
+
}
|
|
55
|
+
const idKey = createStateSymbol("JsonSchema.id");
|
|
56
|
+
export function $id(context, target, value) {
|
|
57
|
+
context.program.stateMap(idKey).set(target, value);
|
|
58
|
+
}
|
|
59
|
+
export function getId(program, target) {
|
|
60
|
+
return program.stateMap(idKey).get(target);
|
|
61
|
+
}
|
|
62
|
+
const containsKey = createStateSymbol("JsonSchema.contains");
|
|
63
|
+
export function $contains(context, target, value) {
|
|
64
|
+
context.program.stateMap(containsKey).set(target, value);
|
|
65
|
+
}
|
|
66
|
+
export function getContains(program, target) {
|
|
67
|
+
return program.stateMap(containsKey).get(target);
|
|
68
|
+
}
|
|
69
|
+
const minContainsKey = createStateSymbol("JsonSchema.minContains");
|
|
70
|
+
export function $minContains(context, target, value) {
|
|
71
|
+
context.program.stateMap(minContainsKey).set(target, value);
|
|
72
|
+
}
|
|
73
|
+
export function getMinContains(program, target) {
|
|
74
|
+
return program.stateMap(minContainsKey).get(target);
|
|
75
|
+
}
|
|
76
|
+
const maxContainsKey = createStateSymbol("JsonSchema.maxContains");
|
|
77
|
+
export function $maxContains(context, target, value) {
|
|
78
|
+
context.program.stateMap(maxContainsKey).set(target, value);
|
|
79
|
+
}
|
|
80
|
+
export function getMaxContains(program, target) {
|
|
81
|
+
return program.stateMap(maxContainsKey).get(target);
|
|
82
|
+
}
|
|
83
|
+
const uniqueItemsKey = createStateSymbol("JsonSchema.uniqueItems");
|
|
84
|
+
export function $uniqueItems(context, target) {
|
|
85
|
+
context.program.stateMap(uniqueItemsKey).set(target, true);
|
|
86
|
+
}
|
|
87
|
+
export function getUniqueItems(program, target) {
|
|
88
|
+
return program.stateMap(uniqueItemsKey).get(target);
|
|
89
|
+
}
|
|
90
|
+
const minPropertiesKey = createStateSymbol("JsonSchema.minProperties");
|
|
91
|
+
export function $minProperties(context, target, value) {
|
|
92
|
+
context.program.stateMap(minPropertiesKey).set(target, value);
|
|
93
|
+
}
|
|
94
|
+
export function getMinProperties(program, target) {
|
|
95
|
+
return program.stateMap(minPropertiesKey).get(target);
|
|
96
|
+
}
|
|
97
|
+
const maxPropertiesKey = createStateSymbol("JsonSchema.maxProperties");
|
|
98
|
+
export function $maxProperties(context, target, value) {
|
|
99
|
+
context.program.stateMap(maxPropertiesKey).set(target, value);
|
|
100
|
+
}
|
|
101
|
+
export function getMaxProperties(program, target) {
|
|
102
|
+
return program.stateMap(maxPropertiesKey).get(target);
|
|
103
|
+
}
|
|
104
|
+
const contentEncodingKey = createStateSymbol("JsonSchema.contentEncoding");
|
|
105
|
+
export function $contentEncoding(context, target, value) {
|
|
106
|
+
context.program.stateMap(contentEncodingKey).set(target, value);
|
|
107
|
+
}
|
|
108
|
+
export function getContentEncoding(program, target) {
|
|
109
|
+
return program.stateMap(contentEncodingKey).get(target);
|
|
110
|
+
}
|
|
111
|
+
const contentMediaType = createStateSymbol("JsonSchema.contentMediaType");
|
|
112
|
+
export function $contentMediaType(context, target, value) {
|
|
113
|
+
context.program.stateMap(contentMediaType).set(target, value);
|
|
114
|
+
}
|
|
115
|
+
export function getContentMediaType(program, target) {
|
|
116
|
+
return program.stateMap(contentMediaType).get(target);
|
|
117
|
+
}
|
|
118
|
+
const contentSchemaKey = createStateSymbol("JsonSchema.contentSchema");
|
|
119
|
+
export function $contentSchema(context, target, value) {
|
|
120
|
+
context.program.stateMap(contentSchemaKey).set(target, value);
|
|
121
|
+
}
|
|
122
|
+
export function getContentSchema(program, target) {
|
|
123
|
+
return program.stateMap(contentSchemaKey).get(target);
|
|
124
|
+
}
|
|
125
|
+
const prefixItemsKey = createStateSymbol("JsonSchema.prefixItems");
|
|
126
|
+
export function $prefixItems(context, target, value) {
|
|
127
|
+
context.program.stateMap(prefixItemsKey).set(target, value);
|
|
128
|
+
}
|
|
129
|
+
export function getPrefixItems(program, target) {
|
|
130
|
+
return program.stateMap(prefixItemsKey).get(target);
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.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,gBAAgB,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,cAAc,GAAG,iBAAiB,CAAC,wBAAwB,CAAC,CAAC;AACnE,MAAM,UAAU,YAAY,CAC1B,OAAyB,EACzB,MAA6B,EAC7B,KAAY;IAEZ,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAgB,EAAE,MAAY;IAC3D,OAAO,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BooleanLiteral, Enum, IntrinsicType, Model, ModelProperty, NumericLiteral, Program, Scalar, StringLiteral, Type, Union, UnionVariant } from "@typespec/compiler";
|
|
2
|
+
import { Context, Declaration, EmitEntity, EmittedSourceFile, EmitterOutput, Scope, SourceFile, TypeEmitter } from "@typespec/compiler/emitter-framework";
|
|
3
|
+
import { JSONSchemaEmitterOptions } from "./lib.js";
|
|
4
|
+
export declare class JsonSchemaEmitter extends TypeEmitter<Record<string, any>, JSONSchemaEmitterOptions> {
|
|
5
|
+
#private;
|
|
6
|
+
modelDeclaration(model: Model, name: string): EmitterOutput<object>;
|
|
7
|
+
modelLiteral(model: Model): EmitterOutput<object>;
|
|
8
|
+
modelInstantiation(model: Model, name: string): EmitterOutput<Record<string, any>>;
|
|
9
|
+
arrayDeclaration(array: Model, name: string, elementType: Type): EmitterOutput<object>;
|
|
10
|
+
arrayLiteral(array: Model, elementType: Type): EmitterOutput<object>;
|
|
11
|
+
modelProperties(model: Model): EmitterOutput<object>;
|
|
12
|
+
modelPropertyLiteral(property: ModelProperty): EmitterOutput<object>;
|
|
13
|
+
booleanLiteral(boolean: BooleanLiteral): EmitterOutput<object>;
|
|
14
|
+
stringLiteral(string: StringLiteral): EmitterOutput<object>;
|
|
15
|
+
numericLiteral(number: NumericLiteral): EmitterOutput<object>;
|
|
16
|
+
enumDeclaration(en: Enum, name: string): EmitterOutput<object>;
|
|
17
|
+
unionDeclaration(union: Union, name: string): EmitterOutput<object>;
|
|
18
|
+
unionLiteral(union: Union): EmitterOutput<object>;
|
|
19
|
+
unionVariants(union: Union): EmitterOutput<object>;
|
|
20
|
+
unionVariant(variant: UnionVariant): EmitterOutput<object>;
|
|
21
|
+
modelPropertyReference(property: ModelProperty): EmitterOutput<object>;
|
|
22
|
+
reference(targetDeclaration: Declaration<Record<string, unknown>>, pathUp: Scope<Record<string, unknown>>[], pathDown: Scope<Record<string, unknown>>[], commonScope: Scope<Record<string, unknown>> | null): object | EmitEntity<Record<string, unknown>>;
|
|
23
|
+
scalarDeclaration(scalar: Scalar, name: string): EmitterOutput<object>;
|
|
24
|
+
intrinsic(intrinsic: IntrinsicType, name: string): EmitterOutput<object>;
|
|
25
|
+
sourceFile(sourceFile: SourceFile<object>): EmittedSourceFile;
|
|
26
|
+
programContext(program: Program): Context;
|
|
27
|
+
modelDeclarationContext(model: Model, name: string): Context;
|
|
28
|
+
modelInstantiationContext(model: Model): Context;
|
|
29
|
+
arrayDeclarationContext(array: Model): Context;
|
|
30
|
+
enumDeclarationContext(en: Enum): Context;
|
|
31
|
+
unionDeclarationContext(union: Union): Context;
|
|
32
|
+
scalarDeclarationContext(scalar: Scalar): Context;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=json-schema-emitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema-emitter.d.ts","sourceRoot":"","sources":["../../src/json-schema-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,IAAI,EAgBJ,aAAa,EACb,KAAK,EACL,aAAa,EACb,cAAc,EACd,OAAO,EACP,MAAM,EACN,aAAa,EACb,IAAI,EACJ,KAAK,EACL,YAAY,EACb,MAAM,oBA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,GAAG,OAAO;IAQ9C,sBAAsB,CAAC,EAAE,EAAE,IAAI,GAAG,OAAO;IAQzC,uBAAuB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAQ9C,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;CAsBlD"}
|
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var _JsonSchemaEmitter_instances, _JsonSchemaEmitter_seenIds, _JsonSchemaEmitter_requiredModelProperties, _JsonSchemaEmitter_applyConstraints, _JsonSchemaEmitter_scalarBuiltinBaseType, _JsonSchemaEmitter_isStdType, _JsonSchemaEmitter_getCurrentSourceFile, _JsonSchemaEmitter_getDeclId, _JsonSchemaEmitter_checkForDuplicateId, _JsonSchemaEmitter_newFileScope, _JsonSchemaEmitter_fileExtension;
|
|
7
|
+
import { getDeprecated, getDirectoryPath, getDoc, getFormat, getMaxItems, getMaxLength, getMaxValue, getMaxValueExclusive, getMinItems, getMinLength, getMinValue, getMinValueExclusive, getPattern, getRelativePathFromDirectory, getSummary, } from "@typespec/compiler";
|
|
8
|
+
import { ArrayBuilder, ObjectBuilder, Placeholder, TypeEmitter, } from "@typespec/compiler/emitter-framework";
|
|
9
|
+
import yaml from "js-yaml";
|
|
10
|
+
import { findBaseUri, getContains, getContentEncoding, getContentMediaType, getContentSchema, getId, getMaxContains, getMaxProperties, getMinContains, getMinProperties, getMultipleOf, getPrefixItems, getUniqueItems, } from "./index.js";
|
|
11
|
+
export class JsonSchemaEmitter extends TypeEmitter {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
_JsonSchemaEmitter_instances.add(this);
|
|
15
|
+
_JsonSchemaEmitter_seenIds.set(this, new Set());
|
|
16
|
+
// #endregion
|
|
17
|
+
}
|
|
18
|
+
modelDeclaration(model, name) {
|
|
19
|
+
const schema = new ObjectBuilder({
|
|
20
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
21
|
+
$id: __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_getDeclId).call(this, model),
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: this.emitter.emitModelProperties(model),
|
|
24
|
+
required: __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_requiredModelProperties).call(this, model),
|
|
25
|
+
});
|
|
26
|
+
if (model.baseModel) {
|
|
27
|
+
const allOf = new ArrayBuilder();
|
|
28
|
+
allOf.push(this.emitter.emitTypeReference(model.baseModel));
|
|
29
|
+
schema.set("allOf", allOf);
|
|
30
|
+
}
|
|
31
|
+
__classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_applyConstraints).call(this, model, schema);
|
|
32
|
+
return this.emitter.result.declaration(name, schema);
|
|
33
|
+
}
|
|
34
|
+
modelLiteral(model) {
|
|
35
|
+
const schema = new ObjectBuilder({
|
|
36
|
+
type: "object",
|
|
37
|
+
properties: this.emitter.emitModelProperties(model),
|
|
38
|
+
required: __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_requiredModelProperties).call(this, model),
|
|
39
|
+
});
|
|
40
|
+
return schema;
|
|
41
|
+
}
|
|
42
|
+
modelInstantiation(model, name) {
|
|
43
|
+
return this.modelDeclaration(model, name);
|
|
44
|
+
}
|
|
45
|
+
arrayDeclaration(array, name, elementType) {
|
|
46
|
+
const schema = new ObjectBuilder({
|
|
47
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
48
|
+
$id: __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_getDeclId).call(this, array),
|
|
49
|
+
type: "array",
|
|
50
|
+
items: this.emitter.emitTypeReference(elementType),
|
|
51
|
+
});
|
|
52
|
+
__classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_applyConstraints).call(this, array, schema);
|
|
53
|
+
return this.emitter.result.declaration(name, schema);
|
|
54
|
+
}
|
|
55
|
+
arrayLiteral(array, elementType) {
|
|
56
|
+
return new ObjectBuilder({
|
|
57
|
+
type: "array",
|
|
58
|
+
items: this.emitter.emitTypeReference(elementType),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
modelProperties(model) {
|
|
62
|
+
const props = new ObjectBuilder();
|
|
63
|
+
for (const [name, prop] of model.properties) {
|
|
64
|
+
const result = this.emitter.emitModelProperty(prop);
|
|
65
|
+
props.set(name, result);
|
|
66
|
+
}
|
|
67
|
+
return props;
|
|
68
|
+
}
|
|
69
|
+
modelPropertyLiteral(property) {
|
|
70
|
+
const result = this.emitter.emitTypeReference(property.type);
|
|
71
|
+
if (result.kind !== "code") {
|
|
72
|
+
throw new Error("Unexpected non-code result from emit reference");
|
|
73
|
+
}
|
|
74
|
+
const withConstraints = new ObjectBuilder(result.value);
|
|
75
|
+
__classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_applyConstraints).call(this, property, withConstraints);
|
|
76
|
+
return withConstraints;
|
|
77
|
+
}
|
|
78
|
+
booleanLiteral(boolean) {
|
|
79
|
+
return { type: "boolean", const: boolean.value };
|
|
80
|
+
}
|
|
81
|
+
stringLiteral(string) {
|
|
82
|
+
return { type: "string", const: string.value };
|
|
83
|
+
}
|
|
84
|
+
numericLiteral(number) {
|
|
85
|
+
return { type: "number", const: number.value };
|
|
86
|
+
}
|
|
87
|
+
enumDeclaration(en, name) {
|
|
88
|
+
var _a;
|
|
89
|
+
const enumTypes = new Set();
|
|
90
|
+
const enumValues = new Set();
|
|
91
|
+
for (const member of en.members.values()) {
|
|
92
|
+
// ???: why do we let emitters decide what the default type of an enum is
|
|
93
|
+
enumTypes.add(member.value ? typeof member.value : "string");
|
|
94
|
+
enumValues.add((_a = member.value) !== null && _a !== void 0 ? _a : member.name);
|
|
95
|
+
}
|
|
96
|
+
const enumTypesArray = [...enumTypes];
|
|
97
|
+
return this.emitter.result.declaration(name, new ObjectBuilder({
|
|
98
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
99
|
+
$id: __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_getDeclId).call(this, en),
|
|
100
|
+
type: enumTypesArray.length === 1 ? enumTypesArray[0] : enumTypesArray,
|
|
101
|
+
enum: [...enumValues],
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
unionDeclaration(union, name) {
|
|
105
|
+
return this.emitter.result.declaration(name, new ObjectBuilder({
|
|
106
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
107
|
+
$id: __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_getDeclId).call(this, union),
|
|
108
|
+
anyOf: this.emitter.emitUnionVariants(union),
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
unionLiteral(union) {
|
|
112
|
+
this.emitter.getProgram().resolveTypeReference("Cadl.Foo");
|
|
113
|
+
return new ObjectBuilder({
|
|
114
|
+
anyOf: this.emitter.emitUnionVariants(union),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
unionVariants(union) {
|
|
118
|
+
const variants = new ArrayBuilder();
|
|
119
|
+
for (const variant of union.variants.values()) {
|
|
120
|
+
variants.push(this.emitter.emitType(variant));
|
|
121
|
+
}
|
|
122
|
+
return variants;
|
|
123
|
+
}
|
|
124
|
+
unionVariant(variant) {
|
|
125
|
+
return this.emitter.emitTypeReference(variant.type);
|
|
126
|
+
}
|
|
127
|
+
modelPropertyReference(property) {
|
|
128
|
+
// this is interesting - model property references will generally need to inherit
|
|
129
|
+
// the relevant decorators from the property they are referencing. I wonder if this
|
|
130
|
+
// could be made easier, as it's a bit subtle.
|
|
131
|
+
const refSchema = this.emitter.emitTypeReference(property.type);
|
|
132
|
+
if (refSchema.kind !== "code") {
|
|
133
|
+
throw new Error("Unexpected non-code result from emit reference");
|
|
134
|
+
}
|
|
135
|
+
const schema = new ObjectBuilder(refSchema.value);
|
|
136
|
+
__classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_applyConstraints).call(this, property, schema);
|
|
137
|
+
return schema;
|
|
138
|
+
}
|
|
139
|
+
reference(targetDeclaration, pathUp, pathDown, commonScope) {
|
|
140
|
+
if (targetDeclaration.value instanceof Placeholder) {
|
|
141
|
+
// I don't think this is possible, confirm.
|
|
142
|
+
throw new Error("Can't form reference to declaration that hasn't been created yet");
|
|
143
|
+
}
|
|
144
|
+
if (targetDeclaration.value.$id) {
|
|
145
|
+
return { $ref: targetDeclaration.value.$id };
|
|
146
|
+
}
|
|
147
|
+
if (!commonScope) {
|
|
148
|
+
const currentSfScope = pathUp[pathUp.length - 1];
|
|
149
|
+
const targetSfScope = pathDown[0];
|
|
150
|
+
const resolved = getRelativePathFromDirectory(getDirectoryPath(currentSfScope.sourceFile.path), targetSfScope.sourceFile.path, false);
|
|
151
|
+
return { $ref: resolved };
|
|
152
|
+
}
|
|
153
|
+
throw new Error("$ref to $defs not yet supported.");
|
|
154
|
+
}
|
|
155
|
+
scalarDeclaration(scalar, name) {
|
|
156
|
+
var _a, _b;
|
|
157
|
+
const baseBuiltIn = __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_scalarBuiltinBaseType).call(this, scalar);
|
|
158
|
+
if (baseBuiltIn === null) {
|
|
159
|
+
throw new Error(`Can't emit custom scalar type ${scalar.name}`);
|
|
160
|
+
}
|
|
161
|
+
let schema;
|
|
162
|
+
switch (baseBuiltIn.name) {
|
|
163
|
+
case "uint8":
|
|
164
|
+
schema = { type: "integer", minimum: 0, maximum: 255 };
|
|
165
|
+
break;
|
|
166
|
+
case "uint16":
|
|
167
|
+
schema = { type: "integer", minimum: 0, maximum: 65535 };
|
|
168
|
+
break;
|
|
169
|
+
case "uint32":
|
|
170
|
+
schema = { type: "integer", minimum: 0, maximum: 4294967295 };
|
|
171
|
+
break;
|
|
172
|
+
case "int8":
|
|
173
|
+
schema = { type: "integer", minimum: -128, maximum: 127 };
|
|
174
|
+
break;
|
|
175
|
+
case "int16":
|
|
176
|
+
schema = { type: "integer", minimum: -32768, maximum: 32767 };
|
|
177
|
+
break;
|
|
178
|
+
case "int32":
|
|
179
|
+
schema = { type: "integer", minimum: -2147483648, maximum: 2147483647 };
|
|
180
|
+
break;
|
|
181
|
+
case "int64":
|
|
182
|
+
const int64Strategy = (_a = this.emitter.getOptions()["int64-strategy"]) !== null && _a !== void 0 ? _a : "string";
|
|
183
|
+
if (int64Strategy === "string") {
|
|
184
|
+
schema = { type: "string" };
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
// can't use minimum and maximum because we can't actually encode these values as literals
|
|
188
|
+
// without losing precision.
|
|
189
|
+
schema = { type: "integer" };
|
|
190
|
+
}
|
|
191
|
+
break;
|
|
192
|
+
case "uint64":
|
|
193
|
+
const uint64Strategy = (_b = this.emitter.getOptions()["int64-strategy"]) !== null && _b !== void 0 ? _b : "string";
|
|
194
|
+
if (uint64Strategy === "string") {
|
|
195
|
+
schema = { type: "string" };
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
// can't use minimum and maximum because we can't actually encode these values as literals
|
|
199
|
+
// without losing precision.
|
|
200
|
+
schema = { type: "integer" };
|
|
201
|
+
}
|
|
202
|
+
break;
|
|
203
|
+
case "integer":
|
|
204
|
+
schema = { type: "integer" };
|
|
205
|
+
break;
|
|
206
|
+
case "safeint":
|
|
207
|
+
schema = { type: "integer" };
|
|
208
|
+
break;
|
|
209
|
+
case "float":
|
|
210
|
+
schema = { type: "number" };
|
|
211
|
+
break;
|
|
212
|
+
case "float32":
|
|
213
|
+
schema = { type: "number" };
|
|
214
|
+
break;
|
|
215
|
+
case "float64":
|
|
216
|
+
schema = { type: "number" };
|
|
217
|
+
break;
|
|
218
|
+
case "numeric":
|
|
219
|
+
schema = { type: "number" };
|
|
220
|
+
break;
|
|
221
|
+
case "string":
|
|
222
|
+
schema = { type: "string" };
|
|
223
|
+
break;
|
|
224
|
+
case "boolean":
|
|
225
|
+
schema = { type: "boolean" };
|
|
226
|
+
break;
|
|
227
|
+
case "plainDate":
|
|
228
|
+
schema = { type: "string", format: "date" };
|
|
229
|
+
break;
|
|
230
|
+
case "plainTime":
|
|
231
|
+
schema = { type: "string", format: "time" };
|
|
232
|
+
break;
|
|
233
|
+
case "offsetDateTime":
|
|
234
|
+
case "utcDateTime":
|
|
235
|
+
schema = { type: "string", format: "date-time" };
|
|
236
|
+
break;
|
|
237
|
+
case "duration":
|
|
238
|
+
schema = { type: "string", format: "duration" };
|
|
239
|
+
break;
|
|
240
|
+
case "url":
|
|
241
|
+
schema = { type: "string", format: "uri" };
|
|
242
|
+
break;
|
|
243
|
+
case "bytes":
|
|
244
|
+
schema = { type: "string", contentEncoding: "base64" };
|
|
245
|
+
break;
|
|
246
|
+
default:
|
|
247
|
+
throw new Error("Unknown scalar type " + baseBuiltIn.name);
|
|
248
|
+
}
|
|
249
|
+
const builderSchema = new ObjectBuilder(schema);
|
|
250
|
+
// avoid creating declarations for built-in TypeSpec types
|
|
251
|
+
if (baseBuiltIn === scalar) {
|
|
252
|
+
return builderSchema;
|
|
253
|
+
}
|
|
254
|
+
builderSchema.$schema = "https://json-schema.org/draft/2020-12/schema";
|
|
255
|
+
builderSchema.$id = __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_getDeclId).call(this, scalar);
|
|
256
|
+
__classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_applyConstraints).call(this, scalar, builderSchema);
|
|
257
|
+
return this.emitter.result.declaration(name, builderSchema);
|
|
258
|
+
}
|
|
259
|
+
intrinsic(intrinsic, name) {
|
|
260
|
+
switch (name) {
|
|
261
|
+
case "null":
|
|
262
|
+
return { type: "null" };
|
|
263
|
+
case "unknown":
|
|
264
|
+
return {};
|
|
265
|
+
}
|
|
266
|
+
throw new Error("Unknown intrinsic type " + name);
|
|
267
|
+
}
|
|
268
|
+
sourceFile(sourceFile) {
|
|
269
|
+
let serializedContent;
|
|
270
|
+
const decls = sourceFile.globalScope.declarations;
|
|
271
|
+
let content;
|
|
272
|
+
if (this.emitter.getOptions().bundleId) {
|
|
273
|
+
const base = this.emitter.getOptions().emitterOutputDir;
|
|
274
|
+
const file = sourceFile.path;
|
|
275
|
+
const id = getRelativePathFromDirectory(base, file, false);
|
|
276
|
+
content = {
|
|
277
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
278
|
+
$id: id,
|
|
279
|
+
$defs: decls.reduce((prev, decl) => {
|
|
280
|
+
prev[decl.name] = decl.value;
|
|
281
|
+
return prev;
|
|
282
|
+
}, {}),
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
if (decls.length > 1) {
|
|
287
|
+
throw new Error("Emit error - multiple decls in single schema per file mode");
|
|
288
|
+
}
|
|
289
|
+
content = decls[0].value;
|
|
290
|
+
}
|
|
291
|
+
if (this.emitter.getOptions()["file-type"] === "json") {
|
|
292
|
+
serializedContent = JSON.stringify(content, null, 4);
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
serializedContent = yaml.dump(content);
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
contents: serializedContent,
|
|
299
|
+
path: sourceFile.path,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
// #region context emitters
|
|
303
|
+
programContext(program) {
|
|
304
|
+
if (this.emitter.getOptions().bundleId) {
|
|
305
|
+
const sourceFile = this.emitter.createSourceFile(this.emitter.getOptions().bundleId);
|
|
306
|
+
return { scope: sourceFile.globalScope };
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
return {};
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
modelDeclarationContext(model, name) {
|
|
313
|
+
if (this.emitter.getOptions().bundleId) {
|
|
314
|
+
return {};
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
if (__classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_isStdType).call(this, model) && model.name === "object") {
|
|
318
|
+
return {};
|
|
319
|
+
}
|
|
320
|
+
return __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_newFileScope).call(this, model.name);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
modelInstantiationContext(model) {
|
|
324
|
+
if (this.emitter.getOptions().bundleId) {
|
|
325
|
+
return {};
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
return __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_newFileScope).call(this, this.declarationName(model));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
arrayDeclarationContext(array) {
|
|
332
|
+
if (this.emitter.getOptions().bundleId) {
|
|
333
|
+
return {};
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
return __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_newFileScope).call(this, array.name);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
enumDeclarationContext(en) {
|
|
340
|
+
if (this.emitter.getOptions().bundleId) {
|
|
341
|
+
return {};
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
return __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_newFileScope).call(this, en.name);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
unionDeclarationContext(union) {
|
|
348
|
+
if (this.emitter.getOptions().bundleId) {
|
|
349
|
+
return {};
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
return __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_newFileScope).call(this, union.name);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
scalarDeclarationContext(scalar) {
|
|
356
|
+
if (this.emitter.getOptions().bundleId) {
|
|
357
|
+
return {};
|
|
358
|
+
}
|
|
359
|
+
else if (__classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_isStdType).call(this, scalar)) {
|
|
360
|
+
return {};
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
return __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_newFileScope).call(this, scalar.name);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
_JsonSchemaEmitter_seenIds = new WeakMap(), _JsonSchemaEmitter_instances = new WeakSet(), _JsonSchemaEmitter_requiredModelProperties = function _JsonSchemaEmitter_requiredModelProperties(model) {
|
|
368
|
+
const requiredProps = [];
|
|
369
|
+
for (const prop of model.properties.values()) {
|
|
370
|
+
if (!prop.optional) {
|
|
371
|
+
requiredProps.push(prop.name);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return requiredProps.length > 0 ? requiredProps : undefined;
|
|
375
|
+
}, _JsonSchemaEmitter_applyConstraints = function _JsonSchemaEmitter_applyConstraints(type, schema) {
|
|
376
|
+
const applyConstraint = (fn, key) => {
|
|
377
|
+
const value = fn(this.emitter.getProgram(), type);
|
|
378
|
+
if (value !== undefined) {
|
|
379
|
+
schema[key] = value;
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
const applyTypeConstraint = (fn, key) => {
|
|
383
|
+
const constraintType = fn(this.emitter.getProgram(), type);
|
|
384
|
+
if (constraintType) {
|
|
385
|
+
const ref = this.emitter.emitTypeReference(constraintType);
|
|
386
|
+
if (ref.kind !== "code") {
|
|
387
|
+
throw new Error("Couldn't get reference to contains type");
|
|
388
|
+
}
|
|
389
|
+
schema.set(key, ref.value);
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
applyConstraint(getMinLength, "minLength");
|
|
393
|
+
applyConstraint(getMaxLength, "maxLength");
|
|
394
|
+
applyConstraint(getMinValue, "minimum");
|
|
395
|
+
applyConstraint(getMinValueExclusive, "exclusiveMinimum");
|
|
396
|
+
applyConstraint(getMaxValue, "maximum");
|
|
397
|
+
applyConstraint(getMaxValueExclusive, "exclusiveMinimum");
|
|
398
|
+
applyConstraint(getPattern, "pattern");
|
|
399
|
+
applyConstraint(getMinItems, "minItems");
|
|
400
|
+
applyConstraint(getMaxItems, "maxItems");
|
|
401
|
+
// the stdlib applies a format of "url" but json schema wants "uri",
|
|
402
|
+
// so ignore this format if it's the built-in type.
|
|
403
|
+
if (!__classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_isStdType).call(this, type) || type.name !== "url") {
|
|
404
|
+
applyConstraint(getFormat, "format");
|
|
405
|
+
}
|
|
406
|
+
applyConstraint(getMultipleOf, "multipleOf");
|
|
407
|
+
applyTypeConstraint(getContains, "contains");
|
|
408
|
+
applyConstraint(getMinContains, "minContains");
|
|
409
|
+
applyConstraint(getMaxContains, "maxContains");
|
|
410
|
+
applyConstraint(getUniqueItems, "uniqueItems");
|
|
411
|
+
applyConstraint(getMinProperties, "minProperties");
|
|
412
|
+
applyConstraint(getMaxProperties, "maxProperties");
|
|
413
|
+
applyConstraint(getContentEncoding, "contentEncoding");
|
|
414
|
+
applyConstraint(getContentMediaType, "contentMediaType");
|
|
415
|
+
applyTypeConstraint(getContentSchema, "contentSchema");
|
|
416
|
+
applyConstraint(getDoc, "description");
|
|
417
|
+
applyConstraint(getSummary, "title");
|
|
418
|
+
applyConstraint((p, t) => (getDeprecated(p, t) !== undefined ? true : undefined), "deprecated");
|
|
419
|
+
const prefixItems = getPrefixItems(this.emitter.getProgram(), type);
|
|
420
|
+
if (prefixItems) {
|
|
421
|
+
const prefixItemsSchema = new ArrayBuilder();
|
|
422
|
+
for (const item of prefixItems.values) {
|
|
423
|
+
prefixItemsSchema.push(this.emitter.emitTypeReference(item));
|
|
424
|
+
}
|
|
425
|
+
schema.set("prefixItems", prefixItemsSchema);
|
|
426
|
+
}
|
|
427
|
+
}, _JsonSchemaEmitter_scalarBuiltinBaseType = function _JsonSchemaEmitter_scalarBuiltinBaseType(scalar) {
|
|
428
|
+
let current = scalar;
|
|
429
|
+
while (current.baseScalar && !__classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_isStdType).call(this, current)) {
|
|
430
|
+
current = current.baseScalar;
|
|
431
|
+
}
|
|
432
|
+
if (__classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_isStdType).call(this, current)) {
|
|
433
|
+
return current;
|
|
434
|
+
}
|
|
435
|
+
return null;
|
|
436
|
+
}, _JsonSchemaEmitter_isStdType = function _JsonSchemaEmitter_isStdType(type) {
|
|
437
|
+
return this.emitter.getProgram().checker.isStdType(type);
|
|
438
|
+
}, _JsonSchemaEmitter_getCurrentSourceFile = function _JsonSchemaEmitter_getCurrentSourceFile() {
|
|
439
|
+
let scope = this.emitter.getContext().scope;
|
|
440
|
+
if (!scope)
|
|
441
|
+
throw new Error("need scope");
|
|
442
|
+
while (scope && scope.kind !== "sourceFile") {
|
|
443
|
+
scope = scope.parentScope;
|
|
444
|
+
}
|
|
445
|
+
if (!scope)
|
|
446
|
+
throw new Error("Didn't find source file scope");
|
|
447
|
+
return scope.sourceFile;
|
|
448
|
+
}, _JsonSchemaEmitter_getDeclId = function _JsonSchemaEmitter_getDeclId(type) {
|
|
449
|
+
const baseUri = findBaseUri(this.emitter.getProgram(), type);
|
|
450
|
+
const explicitId = getId(this.emitter.getProgram(), type);
|
|
451
|
+
if (explicitId) {
|
|
452
|
+
return __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_checkForDuplicateId).call(this, idWithBaseURI(explicitId, baseUri));
|
|
453
|
+
}
|
|
454
|
+
// generate an id
|
|
455
|
+
if (this.emitter.getOptions().bundleId) {
|
|
456
|
+
if (!type.name) {
|
|
457
|
+
throw new Error("Type needs a name to emit a declaration id");
|
|
458
|
+
}
|
|
459
|
+
return __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_checkForDuplicateId).call(this, idWithBaseURI(this.declarationName(type), baseUri));
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
// generate the ID based on the file path
|
|
463
|
+
const base = this.emitter.getOptions().emitterOutputDir;
|
|
464
|
+
const file = __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_getCurrentSourceFile).call(this).path;
|
|
465
|
+
const relative = getRelativePathFromDirectory(base, file, false);
|
|
466
|
+
if (baseUri) {
|
|
467
|
+
return __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_checkForDuplicateId).call(this, new URL(relative, baseUri).href);
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
return __classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_checkForDuplicateId).call(this, relative);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
function idWithBaseURI(id, baseUri) {
|
|
474
|
+
if (baseUri) {
|
|
475
|
+
return new URL(id, baseUri).href;
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
return id;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}, _JsonSchemaEmitter_checkForDuplicateId = function _JsonSchemaEmitter_checkForDuplicateId(id) {
|
|
482
|
+
if (__classPrivateFieldGet(this, _JsonSchemaEmitter_seenIds, "f").has(id)) {
|
|
483
|
+
throw new Error(`Duplicate id: ${id}`);
|
|
484
|
+
}
|
|
485
|
+
__classPrivateFieldGet(this, _JsonSchemaEmitter_seenIds, "f").add(id);
|
|
486
|
+
return id;
|
|
487
|
+
}, _JsonSchemaEmitter_newFileScope = function _JsonSchemaEmitter_newFileScope(name) {
|
|
488
|
+
const sourceFile = this.emitter.createSourceFile(`${name}.${__classPrivateFieldGet(this, _JsonSchemaEmitter_instances, "m", _JsonSchemaEmitter_fileExtension).call(this)}`);
|
|
489
|
+
return {
|
|
490
|
+
scope: sourceFile.globalScope,
|
|
491
|
+
};
|
|
492
|
+
}, _JsonSchemaEmitter_fileExtension = function _JsonSchemaEmitter_fileExtension() {
|
|
493
|
+
return this.emitter.getOptions()["file-type"] === "json" ? "json" : "yaml";
|
|
494
|
+
};
|
|
495
|
+
//# sourceMappingURL=json-schema-emitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema-emitter.js","sourceRoot":"","sources":["../../src/json-schema-emitter.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAGL,aAAa,EACb,gBAAgB,EAChB,MAAM,EACN,SAAS,EACT,WAAW,EACX,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,UAAU,EACV,4BAA4B,EAC5B,UAAU,GAWX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,YAAY,EAMZ,aAAa,EACb,WAAW,EAIX,WAAW,GACZ,MAAM,sCAAsC,CAAC;AAC9C,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EACL,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,KAAK,EACL,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,cAAc,GAEf,MAAM,YAAY,CAAC;AAEpB,MAAM,OAAO,iBAAkB,SAAQ,WAA0D;IAAjG;;;QACE,qCAAW,IAAI,GAAG,EAAE,EAAC;QAojBrB,aAAa;IACf,CAAC;IAnjBC,gBAAgB,CAAC,KAAY,EAAE,IAAY;QACzC,MAAM,MA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iBAAiB,EAAE,EAAE,CAAC,CAAC;KACxC;IAED,uBAAA,IAAI,kCAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACtB,OAAO,EAAE,CAAC;AACZ,CAAC,6EAiEa,IAAY;IACxB,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,IAAI,IAAI,uBAAA,IAAI,sEAAe,MAAnB,IAAI,CAAiB,EAAE,CAAC,CAAC;IACrF,OAAO;QACL,KAAK,EAAE,UAAU,CAAC,WAAW;KAC9B,CAAC;AACJ,CAAC;IAGC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,WAAW,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { JSONSchemaType } from "@typespec/compiler";
|
|
2
|
+
export type FileType = "yaml" | "json";
|
|
3
|
+
export type Int64Strategy = "string" | "number";
|
|
4
|
+
export interface JSONSchemaEmitterOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Serialize the schema as either yaml or json.
|
|
7
|
+
* @default yaml, it not specified infer from the `output-file` extension
|
|
8
|
+
*/
|
|
9
|
+
"file-type"?: FileType;
|
|
10
|
+
/**
|
|
11
|
+
* How to handle 64 bit integers on the wire. Options are:
|
|
12
|
+
*
|
|
13
|
+
* * string: serialize as a string (widely interoperable)
|
|
14
|
+
* * number: serialize as a number (not widely interoperable)
|
|
15
|
+
*/
|
|
16
|
+
"int64-strategy"?: Int64Strategy;
|
|
17
|
+
/**
|
|
18
|
+
* When provided, bundle all the schemas into a single json schema document
|
|
19
|
+
* with schemas under $defs. The provided id is the id of the root document
|
|
20
|
+
* and is also used for the file name.
|
|
21
|
+
*/
|
|
22
|
+
bundleId?: string;
|
|
23
|
+
/**
|
|
24
|
+
* When true, emit all model declarations to JSON Schema without requiring
|
|
25
|
+
* the @jsonSchema decorator.
|
|
26
|
+
*/
|
|
27
|
+
emitAllModels?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare const libDef: {
|
|
30
|
+
readonly name: "@typespec/json-schema";
|
|
31
|
+
readonly diagnostics: {};
|
|
32
|
+
readonly emitter: {
|
|
33
|
+
readonly options: JSONSchemaType<JSONSchemaEmitterOptions>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export declare const $lib: import("@typespec/compiler").TypeSpecLibrary<{
|
|
37
|
+
[code: string]: import("@typespec/compiler").DiagnosticMessages;
|
|
38
|
+
}, JSONSchemaEmitterOptions>;
|
|
39
|
+
export declare const reportDiagnostic: <C extends string | number, M extends keyof {
|
|
40
|
+
[code: string]: import("@typespec/compiler").DiagnosticMessages;
|
|
41
|
+
}[C]>(program: import("@typespec/compiler").Program, diag: import("@typespec/compiler").DiagnosticReport<{
|
|
42
|
+
[code: string]: import("@typespec/compiler").DiagnosticMessages;
|
|
43
|
+
}, C, M>) => void, createStateSymbol: (name: string) => symbol;
|
|
44
|
+
export type JsonSchemaLibrary = typeof $lib;
|
|
45
|
+
//# sourceMappingURL=lib.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE3E,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AACvC,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEhD,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,WAAW,CAAC,EAAE,QAAQ,CAAC;IAEvB;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,aAAa,CAAC;IAEjC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAqCD,eAAO,MAAM,MAAM;;;;;;CAMT,CAAC;AAEX,eAAO,MAAM,IAAI;;4BAAgC,CAAC;AAClD,eAAO,MAAQ,gBAAgB;;;;mBAAE,iBAAiB,0BAAS,CAAC;AAE5D,MAAM,MAAM,iBAAiB,GAAG,OAAO,IAAI,CAAC"}
|
package/dist/src/lib.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createTypeSpecLibrary } from "@typespec/compiler";
|
|
2
|
+
const EmitterOptionsSchema = {
|
|
3
|
+
type: "object",
|
|
4
|
+
additionalProperties: false,
|
|
5
|
+
properties: {
|
|
6
|
+
"file-type": {
|
|
7
|
+
type: "string",
|
|
8
|
+
enum: ["yaml", "json"],
|
|
9
|
+
nullable: true,
|
|
10
|
+
description: "Serialize the schema as either yaml or json.",
|
|
11
|
+
},
|
|
12
|
+
"int64-strategy": {
|
|
13
|
+
type: "string",
|
|
14
|
+
enum: ["string", "number"],
|
|
15
|
+
nullable: true,
|
|
16
|
+
description: `How to handle 64 bit integers on the wire. Options are:
|
|
17
|
+
|
|
18
|
+
* string: serialize as a string (widely interoperable)
|
|
19
|
+
* number: serialize as a number (not widely interoperable)`,
|
|
20
|
+
},
|
|
21
|
+
bundleId: {
|
|
22
|
+
type: "string",
|
|
23
|
+
nullable: true,
|
|
24
|
+
description: "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.",
|
|
25
|
+
},
|
|
26
|
+
emitAllModels: {
|
|
27
|
+
type: "boolean",
|
|
28
|
+
nullable: true,
|
|
29
|
+
description: "When true, emit all model declarations to JSON Schema without requiring the @jsonSchema decorator.",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
required: [],
|
|
33
|
+
};
|
|
34
|
+
export const libDef = {
|
|
35
|
+
name: "@typespec/json-schema",
|
|
36
|
+
diagnostics: {},
|
|
37
|
+
emitter: {
|
|
38
|
+
options: EmitterOptionsSchema,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
export const $lib = createTypeSpecLibrary(libDef);
|
|
42
|
+
export const { reportDiagnostic, createStateSymbol } = $lib;
|
|
43
|
+
//# sourceMappingURL=lib.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAkB,MAAM,oBAAoB,CAAC;AAkC3E,MAAM,oBAAoB,GAA6C;IACrE,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;YACtB,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,8CAA8C;SAC5D;QACD,gBAAgB,EAAE;YAChB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;YAC1B,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE;;;2DAGwC;SACtD;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,WAAW,EACT,uLAAuL;SAC1L;QACD,aAAa,EAAE;YACb,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,IAAI;YACd,WAAW,EACT,oGAAoG;SACvG;KACF;IACD,QAAQ,EAAE,EAAE;CACb,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,IAAI,EAAE,uBAAuB;IAC7B,WAAW,EAAE,EAAE;IACf,OAAO,EAAE;QACP,OAAO,EAAE,oBAAgE;KAC1E;CACO,CAAC;AAEX,MAAM,CAAC,MAAM,IAAI,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAClD,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/testing/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGpF,eAAO,MAAM,qBAAqB,EAAE,mBAGlC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { resolvePath } from "@typespec/compiler";
|
|
2
|
+
import { createTestLibrary } from "@typespec/compiler/testing";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
export const JsonSchemaTestLibrary = createTestLibrary({
|
|
5
|
+
name: "@typespec/json-schema",
|
|
6
|
+
packageRoot: resolvePath(fileURLToPath(import.meta.url), "../../../../"),
|
|
7
|
+
});
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAuB,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,CAAC,MAAM,qBAAqB,GAAwB,iBAAiB,CAAC;IAC1E,IAAI,EAAE,uBAAuB;IAC7B,WAAW,EAAE,WAAW,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,cAAc,CAAC;CACzE,CAAC,CAAC"}
|
package/lib/main.tsp
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import "../dist/src/index.js";
|
|
2
|
+
|
|
3
|
+
namespace JsonSchema;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Add to namespaces to emit models within that namespace to JSON schema.
|
|
7
|
+
* Add to another declaration to emit that declaration to JSON schema.
|
|
8
|
+
*
|
|
9
|
+
* Optionally, for namespaces, you can provide a baseUri, and for other declarations,
|
|
10
|
+
* you can provide the id.
|
|
11
|
+
*
|
|
12
|
+
* @param baseUri Schema IDs are interpreted as relative to this URI.
|
|
13
|
+
*/
|
|
14
|
+
extern dec jsonSchema(target: unknown, baseUri?: valueof string);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Set the base URI for any schemas emitted from types within this namespace.
|
|
18
|
+
*
|
|
19
|
+
* @param baseUri the base URI. Schema IDs inside this namespace are relative to this URI.
|
|
20
|
+
*/
|
|
21
|
+
extern dec baseUri(target: Reflection.Namespace, baseUri: valueof string);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Specify the JSON Schema id. If this model or a parent namespace has a base URI,
|
|
25
|
+
* the provided ID will be relative to that base URI.
|
|
26
|
+
*
|
|
27
|
+
* By default, the id will be constructed based on the declaration's name.
|
|
28
|
+
*
|
|
29
|
+
* @param id the id of the JSON schema for this declaration.
|
|
30
|
+
*/
|
|
31
|
+
extern dec id(target: unknown, id: valueof string);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Specify that the numeric type must be a multiple of some numeric value.
|
|
35
|
+
*
|
|
36
|
+
* @param value The numeric type must be a multiple of this value.
|
|
37
|
+
*/
|
|
38
|
+
extern dec multipleOf(target: numeric | Reflection.ModelProperty, value: valueof numeric);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Specify that the array must contain at least one instance of the provided type.
|
|
42
|
+
* Use `@minContains` and `@maxContains` to customize how many instances to expect.
|
|
43
|
+
*
|
|
44
|
+
* @param value The type the array must contain.
|
|
45
|
+
*/
|
|
46
|
+
extern dec contains(target: unknown[] | Reflection.ModelProperty, value: unknown);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Specify that the array must contain at least some number of the types provided
|
|
50
|
+
* by the contains decorator.
|
|
51
|
+
*
|
|
52
|
+
* @param value The minimum number of instances the array must contain
|
|
53
|
+
*/
|
|
54
|
+
extern dec minContains(target: unknown[] | Reflection.ModelProperty, value: valueof int32);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Specify that the array must contain at most some number of the types provided
|
|
58
|
+
* by the contains decorator.
|
|
59
|
+
*
|
|
60
|
+
* @param value The maximum number of instances the array must contain
|
|
61
|
+
*/
|
|
62
|
+
extern dec maxContains(target: unknown[] | Reflection.ModelProperty, value: valueof int32);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Specify that every item in the array must be unique.
|
|
66
|
+
*/
|
|
67
|
+
extern dec uniqueItems(target: unknown[] | Reflection.ModelProperty);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Specify the minimum number of properties this object can have.
|
|
71
|
+
*
|
|
72
|
+
* @param value The minimum number of properties this object can have.
|
|
73
|
+
*/
|
|
74
|
+
extern dec minProperties(target: Record<unknown> | Reflection.ModelProperty, value: valueof int32);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Specify the maximum number of properties this object can have.
|
|
78
|
+
*
|
|
79
|
+
* @param value The maximum number of properties this object can have.
|
|
80
|
+
*/
|
|
81
|
+
extern dec maxProperties(target: Record<unknown> | Reflection.ModelProperty, value: valueof int32);
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Specify the encoding used for the contents of a string.
|
|
85
|
+
* @param value
|
|
86
|
+
*/
|
|
87
|
+
extern dec contentEncoding(target: string | Reflection.ModelProperty, value: valueof string);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Specify that the target array must begin with the provided types.
|
|
91
|
+
*
|
|
92
|
+
* @param value a tuple containing the types that must be present at the start of the array
|
|
93
|
+
*/
|
|
94
|
+
extern dec prefixItems(target: unknown[] | Reflection.ModelProperty, value: unknown[]);
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Specify the content type of content stored in a string.
|
|
98
|
+
*
|
|
99
|
+
* @param the media type of the string contents
|
|
100
|
+
*
|
|
101
|
+
*/
|
|
102
|
+
extern dec contentMediaType(target: string | Reflection.ModelProperty, value: valueof string);
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Specify the schema for the contents of a string when interpreted according to the content's
|
|
106
|
+
* media type and encoding.
|
|
107
|
+
*
|
|
108
|
+
* @param value the schema of the string contents
|
|
109
|
+
*/
|
|
110
|
+
extern dec contentSchema(target: string | Reflection.ModelProperty, value: unknown);
|
|
111
|
+
|
|
112
|
+
enum Format {
|
|
113
|
+
dateTime: "date-time",
|
|
114
|
+
date: "date",
|
|
115
|
+
time: "time",
|
|
116
|
+
duration: "duration",
|
|
117
|
+
email: "email",
|
|
118
|
+
idnEmail: "idn-email",
|
|
119
|
+
hostname: "hostname",
|
|
120
|
+
idnHostname: "idn-hostname",
|
|
121
|
+
ipv4: "ipv4",
|
|
122
|
+
ipv6: "ipv6",
|
|
123
|
+
uri: "uri",
|
|
124
|
+
uriReference: "uri-reference",
|
|
125
|
+
iri: "iri",
|
|
126
|
+
iriReference: "iri-reference",
|
|
127
|
+
uuid: "uuid",
|
|
128
|
+
jsonPointer: "json-pointer",
|
|
129
|
+
relativeJsonPointer: "relative-json-pointer",
|
|
130
|
+
regex: "regex",
|
|
131
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@typespec/json-schema",
|
|
3
|
+
"version": "0.44.0",
|
|
4
|
+
"author": "Microsoft Corporation",
|
|
5
|
+
"description": "TypeSpec library for emitting TypeSpec to JSON Schema and converting JSON Schema to TypeSpec",
|
|
6
|
+
"homepage": "https://github.com/Microsoft/TypeSpec",
|
|
7
|
+
"readme": "https://github.com/Microsoft/TypeSpec/blob/master/README.md",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Microsoft/TypeSpec.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/Microsoft/TypeSpec/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"TypeSpec",
|
|
18
|
+
"json schema"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "dist/src/index.js",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": "./dist/src/index.js"
|
|
24
|
+
},
|
|
25
|
+
"tspMain": "lib/main.tsp",
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=16.0.0"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"lib/*.tsp",
|
|
31
|
+
"dist/**",
|
|
32
|
+
"!dist/test/**"
|
|
33
|
+
],
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@typespec/compiler": "~0.44.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/mocha": "~10.0.0",
|
|
39
|
+
"@types/node": "~18.11.9",
|
|
40
|
+
"@typespec/compiler": "~0.44.0",
|
|
41
|
+
"@typespec/library-linter": "~0.44.0",
|
|
42
|
+
"@typespec/eslint-plugin": "~0.44.0",
|
|
43
|
+
"@typespec/eslint-config-typespec": "~0.7.0",
|
|
44
|
+
"eslint": "^8.36.0",
|
|
45
|
+
"mocha": "~10.2.0",
|
|
46
|
+
"mocha-junit-reporter": "~2.2.0",
|
|
47
|
+
"mocha-multi-reporters": "~1.5.1",
|
|
48
|
+
"c8": "~7.13.0",
|
|
49
|
+
"rimraf": "~5.0.0",
|
|
50
|
+
"typescript": "~5.0.2",
|
|
51
|
+
"ajv": "~8.12.0",
|
|
52
|
+
"@types/js-yaml": "~4.0.1",
|
|
53
|
+
"@typespec/internal-build-utils": "~0.4.1",
|
|
54
|
+
"js-yaml": "~4.1.0",
|
|
55
|
+
"ajv-formats": "~2.1.1"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"js-yaml": "~4.1.0"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"clean": "rimraf ./dist ./temp",
|
|
62
|
+
"build": "tsc -p . && npm run lint-typespec-library",
|
|
63
|
+
"watch": "tsc -p . --watch",
|
|
64
|
+
"lint-typespec-library": "tsp compile . --warn-as-error --import @typespec/library-linter --no-emit",
|
|
65
|
+
"test": "mocha",
|
|
66
|
+
"test-official": "c8 mocha --forbid-only --reporter mocha-multi-reporters",
|
|
67
|
+
"lint": "eslint . --ext .ts --max-warnings=0",
|
|
68
|
+
"lint:fix": "eslint . --fix --ext .ts",
|
|
69
|
+
"compile-samples": "tsp compile "
|
|
70
|
+
}
|
|
71
|
+
}
|