forked from microsoft/typespec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tsp
164 lines (145 loc) · 5.41 KB
/
main.tsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import "../dist/src/index.js";
namespace TypeSpec.JsonSchema;
/**
* Add to namespaces to emit models within that namespace to JSON schema.
* Add to another declaration to emit that declaration to JSON schema.
*
* Optionally, for namespaces, you can provide a baseUri, and for other declarations,
* you can provide the id.
*
* @param baseUri Schema IDs are interpreted as relative to this URI.
*/
extern dec jsonSchema(target: unknown, baseUri?: valueof string);
/**
* Set the base URI for any schemas emitted from types within this namespace.
*
* @param baseUri the base URI. Schema IDs inside this namespace are relative to this URI.
*/
extern dec baseUri(target: Reflection.Namespace, baseUri: valueof string);
/**
* Specify the JSON Schema id. If this model or a parent namespace has a base URI,
* the provided ID will be relative to that base URI.
*
* By default, the id will be constructed based on the declaration's name.
*
* @param id the id of the JSON schema for this declaration.
*/
extern dec id(target: unknown, id: valueof string);
/**
* Specify that the numeric type must be a multiple of some numeric value.
*
* @param value The numeric type must be a multiple of this value.
*/
extern dec multipleOf(target: numeric | Reflection.ModelProperty, value: valueof numeric);
/**
* Specify that the array must contain at least one instance of the provided type.
* Use `@minContains` and `@maxContains` to customize how many instances to expect.
*
* @param value The type the array must contain.
*/
extern dec contains(target: unknown[] | Reflection.ModelProperty, value: unknown);
/**
* Specify that the array must contain at least some number of the types provided
* by the contains decorator.
*
* @param value The minimum number of instances the array must contain
*/
extern dec minContains(target: unknown[] | Reflection.ModelProperty, value: valueof int32);
/**
* Specify that the array must contain at most some number of the types provided
* by the contains decorator.
*
* @param value The maximum number of instances the array must contain
*/
extern dec maxContains(target: unknown[] | Reflection.ModelProperty, value: valueof int32);
/**
* Specify that every item in the array must be unique.
*/
extern dec uniqueItems(target: unknown[] | Reflection.ModelProperty);
/**
* Specify the minimum number of properties this object can have.
*
* @param value The minimum number of properties this object can have.
*/
extern dec minProperties(target: Record<unknown> | Reflection.ModelProperty, value: valueof int32);
/**
* Specify the maximum number of properties this object can have.
*
* @param value The maximum number of properties this object can have.
*/
extern dec maxProperties(target: Record<unknown> | Reflection.ModelProperty, value: valueof int32);
/**
* Specify the encoding used for the contents of a string.
* @param value
*/
extern dec contentEncoding(target: string | Reflection.ModelProperty, value: valueof string);
/**
* Specify that the target array must begin with the provided types.
*
* @param value a tuple containing the types that must be present at the start of the array
*/
extern dec prefixItems(target: unknown[] | Reflection.ModelProperty, value: unknown[]);
/**
* Specify the content type of content stored in a string.
*
* @param value the media type of the string contents
*
*/
extern dec contentMediaType(target: string | Reflection.ModelProperty, value: valueof string);
/**
* Specify the schema for the contents of a string when interpreted according to the content's
* media type and encoding.
*
* @param value the schema of the string contents
*/
extern dec contentSchema(target: string | Reflection.ModelProperty, value: unknown);
/**
* Specify a custom property to add to the emitted schema. Useful for adding custom keywords
* and other vendor-specific extensions. The value will be converted to a schema unless the parameter
* is wrapped in the `Json<Data>` template. For example, `@extension("x-schema", { x: "value" })` will
* emit a JSON schema value for `x-schema`, whereas `@extension("x-schema", Json<{x: "value"}>)` will
* emit the raw JSON code `{x: "value"}`.
*
* @param key the name of the keyword of vendor extension, e.g. `x-custom`.
* @param value the value of the keyword. Will be converted to a schema unless wrapped in `Json<Data>`.
*/
extern dec extension(target: unknown, key: valueof string, value: unknown);
/**
* Well-known JSON Schema formats.
*/
enum Format {
dateTime: "date-time",
date: "date",
time: "time",
duration: "duration",
email: "email",
idnEmail: "idn-email",
hostname: "hostname",
idnHostname: "idn-hostname",
ipv4: "ipv4",
ipv6: "ipv6",
uri: "uri",
uriReference: "uri-reference",
iri: "iri",
iriReference: "iri-reference",
uuid: "uuid",
jsonPointer: "json-pointer",
relativeJsonPointer: "relative-json-pointer",
regex: "regex",
}
/**
* Specify that the provided template argument should be emitted as raw JSON or YAML
* as opposed to a schema. Use in combination with the @extension decorator. For example,
* `@extension("x-schema", { x: "value" })` will emit a JSON schema value for `x-schema`,
* whereas `@extension("x-schema", Json<{x: "value"}>)` will emit the raw JSON code
* `{x: "value"}`.
*
* @template Data the type to convert to raw JSON
*/
@Private.validatesRawJson(Data)
model Json<Data> {
value: Data;
}
namespace Private {
extern dec validatesRawJson(target: Reflection.Model, value: unknown);
}