@typespec/tspd 0.70.0-dev.2 → 0.70.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/cli.js +85 -103
- package/dist/src/gen-extern-signatures/components/decorator-signature-tests.d.ts +8 -0
- package/dist/src/gen-extern-signatures/components/decorator-signature-tests.d.ts.map +1 -0
- package/dist/src/gen-extern-signatures/components/decorator-signature-tests.js +16 -0
- package/dist/src/gen-extern-signatures/components/decorator-signature-tests.jsx +12 -0
- package/dist/src/gen-extern-signatures/components/decorator-signature-tests.jsx.map +1 -0
- package/dist/src/gen-extern-signatures/components/decorator-signature-type.d.ts +16 -0
- package/dist/src/gen-extern-signatures/components/decorator-signature-type.d.ts.map +1 -0
- package/dist/src/gen-extern-signatures/components/decorator-signature-type.js +404 -0
- package/dist/src/gen-extern-signatures/components/decorator-signature-type.jsx +316 -0
- package/dist/src/gen-extern-signatures/components/decorator-signature-type.jsx.map +1 -0
- package/dist/src/gen-extern-signatures/components/decorators-signatures.d.ts +12 -0
- package/dist/src/gen-extern-signatures/components/decorators-signatures.d.ts.map +1 -0
- package/dist/src/gen-extern-signatures/components/decorators-signatures.js +107 -0
- package/dist/src/gen-extern-signatures/components/decorators-signatures.jsx +60 -0
- package/dist/src/gen-extern-signatures/components/decorators-signatures.jsx.map +1 -0
- package/dist/src/gen-extern-signatures/components/dollar-decorators-type.d.ts +10 -0
- package/dist/src/gen-extern-signatures/components/dollar-decorators-type.d.ts.map +1 -0
- package/dist/src/gen-extern-signatures/components/dollar-decorators-type.js +39 -0
- package/dist/src/gen-extern-signatures/components/dollar-decorators-type.jsx +18 -0
- package/dist/src/gen-extern-signatures/components/dollar-decorators-type.jsx.map +1 -0
- package/dist/src/gen-extern-signatures/components/tspd-context.d.ts +10 -0
- package/dist/src/gen-extern-signatures/components/tspd-context.d.ts.map +1 -0
- package/dist/src/gen-extern-signatures/components/tspd-context.js +22 -0
- package/dist/src/gen-extern-signatures/components/tspd-context.js.map +1 -0
- package/dist/src/gen-extern-signatures/doc-builder.js +10 -12
- package/dist/src/gen-extern-signatures/external-packages/compiler.d.ts +17 -0
- package/dist/src/gen-extern-signatures/external-packages/compiler.d.ts.map +1 -0
- package/dist/src/gen-extern-signatures/external-packages/compiler.js +10 -0
- package/dist/src/gen-extern-signatures/external-packages/compiler.js.map +1 -0
- package/dist/src/gen-extern-signatures/gen-extern-signatures.d.ts.map +1 -1
- package/dist/src/gen-extern-signatures/gen-extern-signatures.js +109 -102
- package/dist/src/gen-extern-signatures/gen-extern-signatures.js.map +1 -1
- package/dist/src/gen-extern-signatures/types.js +1 -2
- package/dist/src/ref-doc/api-docs.js +56 -56
- package/dist/src/ref-doc/emitters/docusaurus.js +156 -209
- package/dist/src/ref-doc/emitters/markdown.js +278 -327
- package/dist/src/ref-doc/emitters/starlight.js +154 -190
- package/dist/src/ref-doc/experimental.js +48 -45
- package/dist/src/ref-doc/extractor.js +486 -449
- package/dist/src/ref-doc/index.js +1 -2
- package/dist/src/ref-doc/lib.js +29 -26
- package/dist/src/ref-doc/types.js +1 -2
- package/dist/src/ref-doc/utils/markdown.js +37 -44
- package/dist/src/ref-doc/utils/type-signature.js +89 -98
- package/package.json +12 -9
- package/dist/src/gen-extern-signatures/decorators-signatures.d.ts +0 -5
- package/dist/src/gen-extern-signatures/decorators-signatures.d.ts.map +0 -1
- package/dist/src/gen-extern-signatures/decorators-signatures.js +0 -338
- package/dist/src/gen-extern-signatures/decorators-signatures.js.map +0 -1
|
@@ -1,339 +1,290 @@
|
|
|
1
|
-
import { getEntityName, isType, resolvePath
|
|
1
|
+
import { getEntityName, isType, resolvePath } from "@typespec/compiler";
|
|
2
2
|
import { readFile } from "fs/promises";
|
|
3
3
|
import { stringify } from "yaml";
|
|
4
|
-
import { codeblock, inlinecode, link, renderMarkdowDoc, section, table
|
|
4
|
+
import { codeblock, inlinecode, link, renderMarkdowDoc, section, table } from "../utils/markdown.js";
|
|
5
5
|
async function loadTemplate(projectRoot, name) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
6
|
+
try {
|
|
7
|
+
const content = await readFile(resolvePath(projectRoot, `.tspd/docs/${name}.md`));
|
|
8
|
+
return content.toString();
|
|
9
|
+
} catch (e) {
|
|
10
|
+
if (typeof e === "object" && e?.code === "ENOENT") {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
throw e;
|
|
14
|
+
}
|
|
16
15
|
}
|
|
17
16
|
export async function renderReadme(refDoc, projectRoot) {
|
|
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
|
-
|
|
17
|
+
const content = [];
|
|
18
|
+
const renderer = new MarkdownRenderer(refDoc);
|
|
19
|
+
const headerTemplate = await loadTemplate(projectRoot, "header");
|
|
20
|
+
if (headerTemplate) {
|
|
21
|
+
content.push(headerTemplate);
|
|
22
|
+
}
|
|
23
|
+
if (refDoc.description) {
|
|
24
|
+
content.push(refDoc.description);
|
|
25
|
+
}
|
|
26
|
+
content.push(renderer.install(refDoc));
|
|
27
|
+
const usageTemplate = await loadTemplate(projectRoot, "usage");
|
|
28
|
+
if (usageTemplate) {
|
|
29
|
+
content.push(section("Usage", [usageTemplate]));
|
|
30
|
+
}
|
|
31
|
+
if (refDoc.emitter?.options) {
|
|
32
|
+
content.push(renderer.emitterUsage(refDoc));
|
|
33
|
+
}
|
|
34
|
+
if (refDoc.linter) {
|
|
35
|
+
content.push(renderer.linterUsage(refDoc));
|
|
36
|
+
}
|
|
37
|
+
if (refDoc.namespaces.some(x => x.decorators.length > 0)) {
|
|
38
|
+
content.push(section("Decorators", renderer.decoratorsSection(refDoc, {
|
|
39
|
+
includeToc: true
|
|
40
|
+
})));
|
|
41
|
+
}
|
|
42
|
+
const footerTemplate = await loadTemplate(projectRoot, "footer");
|
|
43
|
+
if (footerTemplate) {
|
|
44
|
+
content.push(footerTemplate);
|
|
45
|
+
}
|
|
46
|
+
return renderMarkdowDoc(section(refDoc.name, content));
|
|
46
47
|
}
|
|
47
48
|
export function groupByNamespace(namespaces, callback) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
const content = [];
|
|
50
|
+
for (const namespace of namespaces) {
|
|
51
|
+
const contentForNamespace = callback(namespace);
|
|
52
|
+
if (contentForNamespace) {
|
|
53
|
+
content.push(section(namespace.id, contentForNamespace));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return content;
|
|
56
57
|
}
|
|
58
|
+
|
|
57
59
|
/**
|
|
58
60
|
* Github flavored markdown renderer.
|
|
59
61
|
*/
|
|
60
62
|
export class MarkdownRenderer {
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
const content = [];
|
|
290
|
-
content.push(section(`${inlinecode("emitter-output-dir")}`, [
|
|
291
|
-
`**Type:** ${inlinecode("absolutePath")}`,
|
|
292
|
-
"",
|
|
293
|
-
`Defines the emitter output directory. Defaults to \`{output-dir}/${this.refDoc.name}\``,
|
|
294
|
-
`See [Configuring output directory for more info](https://typespec.io/docs/handbook/configuration/configuration/#configuring-output-directory)`,
|
|
295
|
-
]));
|
|
296
|
-
for (const option of options) {
|
|
297
|
-
content.push(section(`${inlinecode(option.name)}`, [
|
|
298
|
-
`**Type:** ${inlinecode(option.type)}`,
|
|
299
|
-
"",
|
|
300
|
-
option.doc,
|
|
301
|
-
]));
|
|
302
|
-
}
|
|
303
|
-
return section("Emitter options", content);
|
|
304
|
-
}
|
|
305
|
-
linterUsage(refDoc) {
|
|
306
|
-
if (refDoc.linter === undefined) {
|
|
307
|
-
return [];
|
|
308
|
-
}
|
|
309
|
-
const setupExample = stringify({
|
|
310
|
-
linter: refDoc.linter.ruleSets
|
|
311
|
-
? { extends: [refDoc.linter.ruleSets[0].name] }
|
|
312
|
-
: { rules: {} },
|
|
313
|
-
});
|
|
314
|
-
return [
|
|
315
|
-
section("Usage", ["Add the following in `tspconfig.yaml`:", codeblock(setupExample, "yaml")]),
|
|
316
|
-
refDoc.linter.ruleSets
|
|
317
|
-
? section("RuleSets", [
|
|
318
|
-
"Available ruleSets:",
|
|
319
|
-
refDoc.linter.ruleSets.map((item) => ` - ${inlinecode(item.name)}`),
|
|
320
|
-
])
|
|
321
|
-
: [],
|
|
322
|
-
section("Rules", this.linterRuleToc(refDoc.linter.rules)),
|
|
323
|
-
];
|
|
324
|
-
}
|
|
325
|
-
linterRuleToc(rules) {
|
|
326
|
-
return table([
|
|
327
|
-
["Name", "Description"],
|
|
328
|
-
...rules.map((rule) => {
|
|
329
|
-
const name = inlinecode(rule.name);
|
|
330
|
-
const nameCell = rule.rule.url ? link(name, this.linterRuleLink(rule.rule.url)) : name;
|
|
331
|
-
return [nameCell, rule.rule.description];
|
|
332
|
-
}),
|
|
333
|
-
]);
|
|
334
|
-
}
|
|
335
|
-
linterRuleLink(url) {
|
|
336
|
-
return url;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
//# sourceMappingURL=markdown.js.map
|
|
63
|
+
constructor(refDoc) {
|
|
64
|
+
this.refDoc = refDoc;
|
|
65
|
+
}
|
|
66
|
+
headingTitle(item) {
|
|
67
|
+
return inlinecode(item.name);
|
|
68
|
+
}
|
|
69
|
+
anchorId(item) {
|
|
70
|
+
return `${item.name.toLowerCase().replace(/ /g, "-")}`;
|
|
71
|
+
}
|
|
72
|
+
deprecationNotice(notice) {
|
|
73
|
+
return `_Deprecated: ${notice.message}_`;
|
|
74
|
+
}
|
|
75
|
+
typeSection(type, content) {
|
|
76
|
+
const deprecated = type.deprecated ? this.deprecationNotice(type.deprecated) : [];
|
|
77
|
+
return section(this.headingTitle(type), [deprecated, content]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#region TypeSpec types
|
|
81
|
+
operation(op) {
|
|
82
|
+
const content = ["", op.doc, codeblock(op.signature, "typespec"), ""];
|
|
83
|
+
if (op.templateParameters) {
|
|
84
|
+
content.push(this.templateParameters(op.templateParameters));
|
|
85
|
+
}
|
|
86
|
+
content.push(this.examples(op.examples));
|
|
87
|
+
return this.typeSection(op, content);
|
|
88
|
+
}
|
|
89
|
+
interface(iface) {
|
|
90
|
+
const content = ["", iface.doc, codeblock(iface.signature, "typespec"), ""];
|
|
91
|
+
if (iface.templateParameters) {
|
|
92
|
+
content.push(this.templateParameters(iface.templateParameters));
|
|
93
|
+
}
|
|
94
|
+
if (iface.interfaceOperations.length > 0) {
|
|
95
|
+
for (const op of iface.interfaceOperations) {
|
|
96
|
+
content.push(this.operation(op));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
content.push(this.examples(iface.examples));
|
|
100
|
+
return this.typeSection(iface, content);
|
|
101
|
+
}
|
|
102
|
+
model(model) {
|
|
103
|
+
const content = ["", model.doc, codeblock(model.signature, "typespec"), ""];
|
|
104
|
+
if (model.templateParameters) {
|
|
105
|
+
content.push(this.templateParameters(model.templateParameters));
|
|
106
|
+
}
|
|
107
|
+
content.push(this.examples(model.examples));
|
|
108
|
+
content.push(this.modelProperties(model));
|
|
109
|
+
return this.typeSection(model, content);
|
|
110
|
+
}
|
|
111
|
+
modelProperties(model) {
|
|
112
|
+
const content = [];
|
|
113
|
+
if (model.properties.size === 0 && model.type.indexer === undefined) {
|
|
114
|
+
return section("Properties", "None");
|
|
115
|
+
}
|
|
116
|
+
const rows = [{
|
|
117
|
+
name: "Name",
|
|
118
|
+
type: "Type",
|
|
119
|
+
doc: "Description"
|
|
120
|
+
}];
|
|
121
|
+
for (const prop of model.properties.values()) {
|
|
122
|
+
const propRows = this.modelPropertyRows(prop);
|
|
123
|
+
for (const row of propRows) {
|
|
124
|
+
rows.push(row);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (model.type.indexer) {
|
|
128
|
+
rows.push({
|
|
129
|
+
name: "",
|
|
130
|
+
type: this.ref(model.type.indexer.value),
|
|
131
|
+
doc: "Additional properties"
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
content.push(table(rows.map(x => [x.name, x.type, x.doc])));
|
|
135
|
+
return section("Properties", content);
|
|
136
|
+
}
|
|
137
|
+
modelPropertyRows(prop) {
|
|
138
|
+
const name = `${prop.name}${prop.type.optional ? "?" : ""}`;
|
|
139
|
+
const base = {
|
|
140
|
+
name: prop.deprecated ? `~~${name}~~ _DEPRECATED_` : name,
|
|
141
|
+
type: this.ref(prop.type.type),
|
|
142
|
+
doc: prop.doc
|
|
143
|
+
};
|
|
144
|
+
if (prop.type.type.kind === "Model" && prop.type.type.name === "") {
|
|
145
|
+
return [base, ...[...prop.type.type.properties.values()].map(x => ({
|
|
146
|
+
name: `${prop.name}.${x.name}${x.optional ? "?" : ""}`,
|
|
147
|
+
type: this.ref(x.type),
|
|
148
|
+
doc: ""
|
|
149
|
+
}))];
|
|
150
|
+
}
|
|
151
|
+
return [base];
|
|
152
|
+
}
|
|
153
|
+
ref(type, prefix = "") {
|
|
154
|
+
const namedType = isType(type) && this.refDoc.getNamedTypeRefDoc(type);
|
|
155
|
+
if (namedType) {
|
|
156
|
+
return link(prefix + inlinecode(namedType.name), `${this.filename(namedType)}#${this.anchorId(namedType)}`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// So we don't show (anonymous model) until this gets improved.
|
|
160
|
+
if ("kind" in type && type.kind === "Model" && type.name === "" && type.properties.size > 0) {
|
|
161
|
+
return inlinecode(prefix + "{...}");
|
|
162
|
+
}
|
|
163
|
+
return inlinecode(prefix + getEntityName(type, {
|
|
164
|
+
namespaceFilter: ns => !this.refDoc.namespaces.some(x => x.name === ns.name)
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
enum(e) {
|
|
168
|
+
const content = ["", e.doc, codeblock(e.signature, "typespec"), "", this.enumMembers(e), this.examples(e.examples)];
|
|
169
|
+
return this.typeSection(e, content);
|
|
170
|
+
}
|
|
171
|
+
enumMembers(e) {
|
|
172
|
+
const rows = [...e.members.values()].map(x => {
|
|
173
|
+
return [x.name, x.type.value ? inlinecode(typeof x.type.value === "string" ? `"${x.type.value}"` : x.type.value.toString()) : "", x.doc];
|
|
174
|
+
});
|
|
175
|
+
return table([["Name", "Value", "Description"], ...rows]);
|
|
176
|
+
}
|
|
177
|
+
union(union) {
|
|
178
|
+
const content = ["", union.doc, codeblock(union.signature, "typespec"), ""];
|
|
179
|
+
if (union.templateParameters) {
|
|
180
|
+
content.push(this.templateParameters(union.templateParameters));
|
|
181
|
+
}
|
|
182
|
+
content.push(this.examples(union.examples));
|
|
183
|
+
return this.typeSection(union, content);
|
|
184
|
+
}
|
|
185
|
+
scalar(scalar) {
|
|
186
|
+
const content = ["", scalar.doc, codeblock(scalar.signature, "typespec"), ""];
|
|
187
|
+
if (scalar.templateParameters) {
|
|
188
|
+
content.push(this.templateParameters(scalar.templateParameters));
|
|
189
|
+
}
|
|
190
|
+
content.push(this.examples(scalar.examples));
|
|
191
|
+
return this.typeSection(scalar, content);
|
|
192
|
+
}
|
|
193
|
+
templateParameters(templateParameters) {
|
|
194
|
+
const paramTable = [["Name", "Description"]];
|
|
195
|
+
for (const param of templateParameters) {
|
|
196
|
+
paramTable.push([param.name, param.doc]);
|
|
197
|
+
}
|
|
198
|
+
return section("Template Parameters", [table(paramTable), ""]);
|
|
199
|
+
}
|
|
200
|
+
decorator(dec) {
|
|
201
|
+
const content = ["", dec.doc, codeblock(dec.signature, "typespec"), ""];
|
|
202
|
+
content.push(section("Target", [dec.target.doc, this.ref(dec.target.type.type), ""]));
|
|
203
|
+
if (dec.parameters.length > 0) {
|
|
204
|
+
const paramTable = [["Name", "Type", "Description"]];
|
|
205
|
+
for (const param of dec.parameters) {
|
|
206
|
+
paramTable.push([param.name, this.MixedParameterConstraint(param.type.type), param.doc]);
|
|
207
|
+
}
|
|
208
|
+
content.push(section("Parameters", [table(paramTable), ""]));
|
|
209
|
+
} else {
|
|
210
|
+
content.push(section("Parameters", ["None", ""]));
|
|
211
|
+
}
|
|
212
|
+
content.push(this.examples(dec.examples));
|
|
213
|
+
return this.typeSection(dec, content);
|
|
214
|
+
}
|
|
215
|
+
MixedParameterConstraint(constraint) {
|
|
216
|
+
return [...(constraint.type ? [this.ref(constraint.type)] : []), ...(constraint.valueType ? [this.ref(constraint.valueType, "valueof ")] : [])].join(" | ");
|
|
217
|
+
}
|
|
218
|
+
examples(examples) {
|
|
219
|
+
const content = [];
|
|
220
|
+
if (examples.length === 0) {
|
|
221
|
+
return "";
|
|
222
|
+
}
|
|
223
|
+
for (const example of examples) {
|
|
224
|
+
const exampleContent = ["", example.content, ""];
|
|
225
|
+
if (example.title) {
|
|
226
|
+
content.push(section(example.title, exampleContent));
|
|
227
|
+
} else {
|
|
228
|
+
content.push(exampleContent);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return section("Examples", content);
|
|
232
|
+
}
|
|
233
|
+
// #endregion TypeSpec types
|
|
234
|
+
|
|
235
|
+
/** Render all decorators */
|
|
236
|
+
decoratorsSection(refDoc, options = {}) {
|
|
237
|
+
return groupByNamespace(refDoc.namespaces, namespace => {
|
|
238
|
+
if (namespace.decorators.length === 0) {
|
|
239
|
+
return undefined;
|
|
240
|
+
}
|
|
241
|
+
return [options.includeToc ? this.toc(namespace.decorators) : [], namespace.decorators.map(x => [this.decorator(x), ""])];
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
toc(items) {
|
|
245
|
+
return items.map(item => ` - [${inlinecode(item.name)}](${this.filename(item)}#${this.anchorId(item)})`);
|
|
246
|
+
}
|
|
247
|
+
filename(type) {
|
|
248
|
+
return "";
|
|
249
|
+
}
|
|
250
|
+
install(refDoc) {
|
|
251
|
+
return section("Install", [codeblock(`npm install ${refDoc.name}`, "bash")]);
|
|
252
|
+
}
|
|
253
|
+
emitterUsage(refDoc) {
|
|
254
|
+
if (refDoc.emitter?.options === undefined) {
|
|
255
|
+
return [];
|
|
256
|
+
}
|
|
257
|
+
return [section("Usage", ["1. Via the command line", codeblock(`tsp compile . --emit=${refDoc.name}`, "bash"), "2. Via the config", codeblock(`emit:\n - "${refDoc.name}" `, "yaml"), "The config can be extended with options as follows:", codeblock(`emit:\n - "${refDoc.name}"\noptions:\n "${refDoc.name}":\n option: value`, "yaml")]), this.emitterOptions(refDoc.emitter.options)];
|
|
258
|
+
}
|
|
259
|
+
emitterOptions(options) {
|
|
260
|
+
const content = [];
|
|
261
|
+
content.push(section(`${inlinecode("emitter-output-dir")}`, [`**Type:** ${inlinecode("absolutePath")}`, "", `Defines the emitter output directory. Defaults to \`{output-dir}/${this.refDoc.name}\``, `See [Configuring output directory for more info](https://typespec.io/docs/handbook/configuration/configuration/#configuring-output-directory)`]));
|
|
262
|
+
for (const option of options) {
|
|
263
|
+
content.push(section(`${inlinecode(option.name)}`, [`**Type:** ${inlinecode(option.type)}`, "", option.doc]));
|
|
264
|
+
}
|
|
265
|
+
return section("Emitter options", content);
|
|
266
|
+
}
|
|
267
|
+
linterUsage(refDoc) {
|
|
268
|
+
if (refDoc.linter === undefined) {
|
|
269
|
+
return [];
|
|
270
|
+
}
|
|
271
|
+
const setupExample = stringify({
|
|
272
|
+
linter: refDoc.linter.ruleSets ? {
|
|
273
|
+
extends: [refDoc.linter.ruleSets[0].name]
|
|
274
|
+
} : {
|
|
275
|
+
rules: {}
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
return [section("Usage", ["Add the following in `tspconfig.yaml`:", codeblock(setupExample, "yaml")]), refDoc.linter.ruleSets ? section("RuleSets", ["Available ruleSets:", refDoc.linter.ruleSets.map(item => ` - ${inlinecode(item.name)}`)]) : [], section("Rules", this.linterRuleToc(refDoc.linter.rules))];
|
|
279
|
+
}
|
|
280
|
+
linterRuleToc(rules) {
|
|
281
|
+
return table([["Name", "Description"], ...rules.map(rule => {
|
|
282
|
+
const name = inlinecode(rule.name);
|
|
283
|
+
const nameCell = rule.rule.url ? link(name, this.linterRuleLink(rule.rule.url)) : name;
|
|
284
|
+
return [nameCell, rule.rule.description];
|
|
285
|
+
})]);
|
|
286
|
+
}
|
|
287
|
+
linterRuleLink(url) {
|
|
288
|
+
return url;
|
|
289
|
+
}
|
|
290
|
+
}
|