@webpieces/api-doc-model 0.4.939 → 0.4.940
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/package.json +2 -2
- package/src/extract/DocLinkReader.d.ts +51 -0
- package/src/extract/DocLinkReader.js +154 -0
- package/src/extract/DocLinkReader.js.map +1 -0
- package/src/extract/JsDoc.d.ts +14 -12
- package/src/extract/JsDoc.js +17 -19
- package/src/extract/JsDoc.js.map +1 -1
- package/src/extract/TypeResolver.d.ts +2 -0
- package/src/extract/TypeResolver.js +5 -1
- package/src/extract/TypeResolver.js.map +1 -1
- package/src/index.d.ts +3 -0
- package/src/index.js +9 -1
- package/src/index.js.map +1 -1
- package/src/model/ApiDocModel.d.ts +4 -4
- package/src/model/ApiDocModel.js +2 -2
- package/src/model/ApiDocModel.js.map +1 -1
- package/src/model/DocLink.d.ts +128 -0
- package/src/model/DocLink.js +193 -0
- package/src/model/DocLink.js.map +1 -0
- package/src/model/EndpointSummary.js +5 -2
- package/src/model/EndpointSummary.js.map +1 -1
- package/src/model/OperationIds.d.ts +26 -0
- package/src/model/OperationIds.js +38 -0
- package/src/model/OperationIds.js.map +1 -0
- package/src/render/McpSchemaRenderer.d.ts +25 -2
- package/src/render/McpSchemaRenderer.js +67 -7
- package/src/render/McpSchemaRenderer.js.map +1 -1
- package/src/render/StreamingSchemaRenderer.d.ts +4 -0
- package/src/render/StreamingSchemaRenderer.js +13 -1
- package/src/render/StreamingSchemaRenderer.js.map +1 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocLinkText = exports.DocLinkProblem = exports.DocLink = exports.DocLinkKind = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* What a JSDoc `{@link X}` names, as the COMPILER resolved it at extraction (#1284).
|
|
6
|
+
*
|
|
7
|
+
* A link is a reference, and a reference is published under the target's PUBLISHED identity — never
|
|
8
|
+
* its source name. `{@link MenuDto}` must publish the schema name `Menu` when `schemaNames` strips
|
|
9
|
+
* `Dto`, and `{@link OrdersApi.fetchOrders}` must publish the operation, not leak the contract class
|
|
10
|
+
* name to a partner. Neither name is known where the JSDoc is read: the schema name of a type in a
|
|
11
|
+
* bundled document depends on what else that document reaches, the operationId on the manifest's
|
|
12
|
+
* `operationIds` style, and an MCP catalog names a tool by its `@WpMcpTool` name. So extraction
|
|
13
|
+
* records WHAT the link points at, as one of these, and each renderer names it — see
|
|
14
|
+
* {@link DocLinkText}.
|
|
15
|
+
*/
|
|
16
|
+
var DocLinkKind;
|
|
17
|
+
(function (DocLinkKind) {
|
|
18
|
+
/** A named type — class, interface, enum or alias — optionally with a `.member` tail. */
|
|
19
|
+
DocLinkKind["TYPE"] = "type";
|
|
20
|
+
/** A method of an `@ApiPath` contract: a published operation. */
|
|
21
|
+
DocLinkKind["OPERATION"] = "operation";
|
|
22
|
+
/** A target that names nothing any document publishes. Always refused by a renderer. */
|
|
23
|
+
DocLinkKind["UNRESOLVED"] = "unresolved";
|
|
24
|
+
})(DocLinkKind || (exports.DocLinkKind = DocLinkKind = {}));
|
|
25
|
+
/** One resolved `{@link}`. Data only: a renderer reads it through {@link DocLinkText}. */
|
|
26
|
+
class DocLink {
|
|
27
|
+
kind;
|
|
28
|
+
written;
|
|
29
|
+
label;
|
|
30
|
+
location;
|
|
31
|
+
owner;
|
|
32
|
+
ownerName;
|
|
33
|
+
member;
|
|
34
|
+
mcpToolName;
|
|
35
|
+
reason;
|
|
36
|
+
constructor(kind,
|
|
37
|
+
/** The target exactly as written — `MenuDto.items`, `OrdersApi.fetchOrders`. */
|
|
38
|
+
written,
|
|
39
|
+
/** `{@link X | the label}` / `{@link X the label}`'s label; undefined when there is none. */
|
|
40
|
+
label,
|
|
41
|
+
/** Pointer-style `path/to/File.ts:12:5` of the link itself, for a refusal that names it. */
|
|
42
|
+
location,
|
|
43
|
+
/**
|
|
44
|
+
* {@link DocLinkKind.TYPE}: the {@link ApiDocModel.types} key of the type, and its
|
|
45
|
+
* schemaNames-stripped published name. {@link DocLinkKind.OPERATION}: the contract class and
|
|
46
|
+
* method name. Empty for the other kinds.
|
|
47
|
+
*/
|
|
48
|
+
owner, ownerName,
|
|
49
|
+
/** {@link DocLinkKind.TYPE}: the `.member` tail exactly as written (`.items`), else empty. */
|
|
50
|
+
member,
|
|
51
|
+
/** {@link DocLinkKind.OPERATION}: the method's `@WpMcpTool` name, when it is a tool. */
|
|
52
|
+
mcpToolName,
|
|
53
|
+
/** {@link DocLinkKind.UNRESOLVED}: why it names nothing publishable, in one clause. */
|
|
54
|
+
reason) {
|
|
55
|
+
this.kind = kind;
|
|
56
|
+
this.written = written;
|
|
57
|
+
this.label = label;
|
|
58
|
+
this.location = location;
|
|
59
|
+
this.owner = owner;
|
|
60
|
+
this.ownerName = ownerName;
|
|
61
|
+
this.member = member;
|
|
62
|
+
this.mcpToolName = mcpToolName;
|
|
63
|
+
this.reason = reason;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.DocLink = DocLink;
|
|
67
|
+
/** One `{@link}` a rendered output could not name. A renderer refuses every one, in one run. */
|
|
68
|
+
class DocLinkProblem {
|
|
69
|
+
location;
|
|
70
|
+
written;
|
|
71
|
+
reason;
|
|
72
|
+
constructor(
|
|
73
|
+
/** Pointer-style `path/to/File.ts:12:5` of the link. */
|
|
74
|
+
location,
|
|
75
|
+
/** The target as written. */
|
|
76
|
+
written,
|
|
77
|
+
/** Why, in one clause. */
|
|
78
|
+
reason) {
|
|
79
|
+
this.location = location;
|
|
80
|
+
this.written = written;
|
|
81
|
+
this.reason = reason;
|
|
82
|
+
}
|
|
83
|
+
toString() {
|
|
84
|
+
return `${this.location} {@link ${this.written}} — ${this.reason}`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.DocLinkProblem = DocLinkProblem;
|
|
88
|
+
/** Brackets one encoded link inside a model string. Private-use code points: no author types them. */
|
|
89
|
+
const OPEN = '';
|
|
90
|
+
const CLOSE = '';
|
|
91
|
+
const ENCODED = /([^]*)/g;
|
|
92
|
+
/**
|
|
93
|
+
* The ONE grammar for a `{@link}` inside model prose (#1284).
|
|
94
|
+
*
|
|
95
|
+
* Every prose string the model carries — a description, a `@summary`, a `@returns`, an `@mcp` — holds
|
|
96
|
+
* each link ENCODED in place, so concatenation, trimming and joining by any renderer cannot separate a
|
|
97
|
+
* link from the sentence it sits in. A renderer resolves the string as it publishes it, with its own
|
|
98
|
+
* {@link DocLinkNaming}, and every renderer emits the SAME spelling:
|
|
99
|
+
*
|
|
100
|
+
* | written | published |
|
|
101
|
+
* |---|---|
|
|
102
|
+
* | `{@link MenuDto}` | `` `Menu` `` (the published schema name) |
|
|
103
|
+
* | `{@link MenuDto.items}` | `` `Menu.items` `` (the tail kept as written) |
|
|
104
|
+
* | `{@link OrdersApi.fetchOrders}` | `` `fetchOrders` `` (the operationId; an MCP tool's name in a tool catalog) |
|
|
105
|
+
* | `{@link OrdersApi.fetchOrders \| the order list}` | `the order list (`fetchOrders`)` |
|
|
106
|
+
*
|
|
107
|
+
* A markdown CODE SPAN, because OpenAPI descriptions are CommonMark: every renderer shows it as code,
|
|
108
|
+
* and a docs site can turn a code span naming a known operationId or schema into a link. A labelled
|
|
109
|
+
* link keeps the author's words AND the identity, so the reference survives into a site's hyperlink.
|
|
110
|
+
*
|
|
111
|
+
* A model string must never reach a published output unresolved; a renderer that forgets is caught by
|
|
112
|
+
* {@link hasLinks}, which every published output is checked with.
|
|
113
|
+
*/
|
|
114
|
+
class DocLinkText {
|
|
115
|
+
/** `link`, encoded for a place in a model string. */
|
|
116
|
+
// webpieces-disable no-function-outside-class -- static codec of the grammar this class owns
|
|
117
|
+
static encode(link) {
|
|
118
|
+
const fields = [
|
|
119
|
+
link.kind,
|
|
120
|
+
link.written,
|
|
121
|
+
link.label ?? null,
|
|
122
|
+
link.location,
|
|
123
|
+
link.owner,
|
|
124
|
+
link.ownerName,
|
|
125
|
+
link.member,
|
|
126
|
+
link.mcpToolName ?? null,
|
|
127
|
+
link.reason,
|
|
128
|
+
];
|
|
129
|
+
return `${OPEN}${JSON.stringify(fields)}${CLOSE}`;
|
|
130
|
+
}
|
|
131
|
+
/** True when `text` still holds an encoded link — a published output never may. */
|
|
132
|
+
// webpieces-disable no-function-outside-class -- static codec of the grammar this class owns
|
|
133
|
+
static hasLinks(text) {
|
|
134
|
+
return text.includes(OPEN);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Every link in `text` as WRITTEN, in the published spelling: for a measurement that must not count
|
|
138
|
+
* the encoding (a `@summary`'s length) and for a reader that publishes nothing.
|
|
139
|
+
*/
|
|
140
|
+
// webpieces-disable no-function-outside-class -- static codec of the grammar this class owns
|
|
141
|
+
static asWritten(text) {
|
|
142
|
+
return text.replace(ENCODED, (_all, body) => {
|
|
143
|
+
const link = DocLinkText.decode(body);
|
|
144
|
+
return DocLinkText.spell(link, link.written);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/** Every encoded link in `text`, in order. */
|
|
148
|
+
// webpieces-disable no-function-outside-class -- static codec of the grammar this class owns
|
|
149
|
+
static linksIn(text) {
|
|
150
|
+
const links = [];
|
|
151
|
+
for (const match of text.matchAll(ENCODED)) {
|
|
152
|
+
links.push(DocLinkText.decode(match[1] ?? ''));
|
|
153
|
+
}
|
|
154
|
+
return links;
|
|
155
|
+
}
|
|
156
|
+
/** `text` with every link published under the name `naming` gives it; misses go to `problems`. */
|
|
157
|
+
// webpieces-disable no-function-outside-class -- static codec of the grammar this class owns
|
|
158
|
+
static resolve(text, naming, output, problems) {
|
|
159
|
+
return text.replace(ENCODED, (_all, body) => {
|
|
160
|
+
const link = DocLinkText.decode(body);
|
|
161
|
+
const name = link.kind === DocLinkKind.UNRESOLVED ? undefined : naming.publishedName(link);
|
|
162
|
+
if (name === undefined) {
|
|
163
|
+
problems.push(new DocLinkProblem(link.location, link.written, DocLinkText.why(link, output)));
|
|
164
|
+
return DocLinkText.spell(link, link.written);
|
|
165
|
+
}
|
|
166
|
+
return DocLinkText.spell(link, link.kind === DocLinkKind.TYPE ? `${name}${link.member}` : name);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/** The one published spelling — see the class doc. */
|
|
170
|
+
// webpieces-disable no-function-outside-class -- private static helper of this class
|
|
171
|
+
static spell(link, name) {
|
|
172
|
+
const code = `\`${name}\``;
|
|
173
|
+
return link.label === undefined ? code : `${link.label} (${code})`;
|
|
174
|
+
}
|
|
175
|
+
// webpieces-disable no-function-outside-class -- private static helper of this class
|
|
176
|
+
static why(link, output) {
|
|
177
|
+
switch (link.kind) {
|
|
178
|
+
case DocLinkKind.TYPE:
|
|
179
|
+
return `type ${link.ownerName} is not published in ${output}`;
|
|
180
|
+
case DocLinkKind.OPERATION:
|
|
181
|
+
return `operation ${link.owner}.${link.ownerName} is not published in ${output}`;
|
|
182
|
+
default:
|
|
183
|
+
return link.reason;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// webpieces-disable no-function-outside-class -- private static helper of this class
|
|
187
|
+
static decode(body) {
|
|
188
|
+
const f = JSON.parse(body);
|
|
189
|
+
return new DocLink(f[0], f[1] ?? '', f[2] ?? undefined, f[3] ?? '', f[4] ?? '', f[5] ?? '', f[6] ?? '', f[7] ?? undefined, f[8] ?? '');
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.DocLinkText = DocLinkText;
|
|
193
|
+
//# sourceMappingURL=DocLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DocLink.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/model/DocLink.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;GAWG;AACH,IAAY,WAOX;AAPD,WAAY,WAAW;IACnB,yFAAyF;IACzF,4BAAa,CAAA;IACb,iEAAiE;IACjE,sCAAuB,CAAA;IACvB,wFAAwF;IACxF,wCAAyB,CAAA;AAC7B,CAAC,EAPW,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IAAa,EAAE,MAAc;QAC5C,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAChB,KAAK,WAAW,CAAC,IAAI;gBACjB,OAAO,QAAQ,IAAI,CAAC,SAAS,wBAAwB,MAAM,EAAE,CAAC;YAClE,KAAK,WAAW,CAAC,SAAS;gBACtB,OAAO,aAAa,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,SAAS,wBAAwB,MAAM,EAAE,CAAC;YACrF;gBACI,OAAO,IAAI,CAAC,MAAM,CAAC;QAC3B,CAAC;IACL,CAAC;IAED,qFAAqF;IAC7E,MAAM,CAAC,MAAM,CAAC,IAAY;QAC9B,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAsB,CAAC;QAChD,OAAO,IAAI,OAAO,CACd,CAAC,CAAC,CAAC,CAAgB,EACnB,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EACV,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,EACjB,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EACV,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EACV,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EACV,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EACV,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,EACjB,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CACb,CAAC;IACN,CAAC;CACJ;AAzGD,kCAyGC","sourcesContent":["/**\n * What a JSDoc `{@link X}` names, as the COMPILER resolved it at extraction (#1284).\n *\n * A link is a reference, and a reference is published under the target's PUBLISHED identity — never\n * its source name. `{@link MenuDto}` must publish the schema name `Menu` when `schemaNames` strips\n * `Dto`, and `{@link OrdersApi.fetchOrders}` must publish the operation, not leak the contract class\n * name to a partner. Neither name is known where the JSDoc is read: the schema name of a type in a\n * bundled document depends on what else that document reaches, the operationId on the manifest's\n * `operationIds` style, and an MCP catalog names a tool by its `@WpMcpTool` name. So extraction\n * records WHAT the link points at, as one of these, and each renderer names it — see\n * {@link DocLinkText}.\n */\nexport enum DocLinkKind {\n /** A named type — class, interface, enum or alias — optionally with a `.member` tail. */\n TYPE = 'type',\n /** A method of an `@ApiPath` contract: a published operation. */\n OPERATION = 'operation',\n /** A target that names nothing any document publishes. Always refused by a renderer. */\n UNRESOLVED = 'unresolved',\n}\n\n/** One resolved `{@link}`. Data only: a renderer reads it through {@link DocLinkText}. */\nexport class DocLink {\n constructor(\n readonly kind: DocLinkKind,\n /** The target exactly as written — `MenuDto.items`, `OrdersApi.fetchOrders`. */\n readonly written: string,\n /** `{@link X | the label}` / `{@link X the label}`'s label; undefined when there is none. */\n readonly label: string | undefined,\n /** Pointer-style `path/to/File.ts:12:5` of the link itself, for a refusal that names it. */\n readonly location: string,\n /**\n * {@link DocLinkKind.TYPE}: the {@link ApiDocModel.types} key of the type, and its\n * schemaNames-stripped published name. {@link DocLinkKind.OPERATION}: the contract class and\n * method name. Empty for the other kinds.\n */\n readonly owner: string,\n readonly ownerName: string,\n /** {@link DocLinkKind.TYPE}: the `.member` tail exactly as written (`.items`), else empty. */\n readonly member: string,\n /** {@link DocLinkKind.OPERATION}: the method's `@WpMcpTool` name, when it is a tool. */\n readonly mcpToolName: string | undefined,\n /** {@link DocLinkKind.UNRESOLVED}: why it names nothing publishable, in one clause. */\n readonly reason: string,\n ) {}\n}\n\n/** One `{@link}` a rendered output could not name. A renderer refuses every one, in one run. */\nexport class DocLinkProblem {\n constructor(\n /** Pointer-style `path/to/File.ts:12:5` of the link. */\n readonly location: string,\n /** The target as written. */\n readonly written: string,\n /** Why, in one clause. */\n readonly reason: string,\n ) {}\n\n toString(): string {\n return `${this.location} {@link ${this.written}} — ${this.reason}`;\n }\n}\n\n/**\n * How ONE rendered output names a link's target: the published schema name in THIS document, the\n * operationId, an MCP tool name. Undefined means the output does not publish the target, which the\n * resolver records as a {@link DocLinkProblem}.\n */\nexport interface DocLinkNaming {\n publishedName(link: DocLink): string | undefined;\n}\n\n/** Brackets one encoded link inside a model string. Private-use code points: no author types them. */\nconst OPEN = '';\nconst CLOSE = '';\nconst ENCODED = /([^]*)/g;\n\n/**\n * The ONE grammar for a `{@link}` inside model prose (#1284).\n *\n * Every prose string the model carries — a description, a `@summary`, a `@returns`, an `@mcp` — holds\n * each link ENCODED in place, so concatenation, trimming and joining by any renderer cannot separate a\n * link from the sentence it sits in. A renderer resolves the string as it publishes it, with its own\n * {@link DocLinkNaming}, and every renderer emits the SAME spelling:\n *\n * | written | published |\n * |---|---|\n * | `{@link MenuDto}` | `` `Menu` `` (the published schema name) |\n * | `{@link MenuDto.items}` | `` `Menu.items` `` (the tail kept as written) |\n * | `{@link OrdersApi.fetchOrders}` | `` `fetchOrders` `` (the operationId; an MCP tool's name in a tool catalog) |\n * | `{@link OrdersApi.fetchOrders \\| the order list}` | `the order list (`fetchOrders`)` |\n *\n * A markdown CODE SPAN, because OpenAPI descriptions are CommonMark: every renderer shows it as code,\n * and a docs site can turn a code span naming a known operationId or schema into a link. A labelled\n * link keeps the author's words AND the identity, so the reference survives into a site's hyperlink.\n *\n * A model string must never reach a published output unresolved; a renderer that forgets is caught by\n * {@link hasLinks}, which every published output is checked with.\n */\nexport class DocLinkText {\n /** `link`, encoded for a place in a model string. */\n // webpieces-disable no-function-outside-class -- static codec of the grammar this class owns\n static encode(link: DocLink): string {\n const fields = [\n link.kind,\n link.written,\n link.label ?? null,\n link.location,\n link.owner,\n link.ownerName,\n link.member,\n link.mcpToolName ?? null,\n link.reason,\n ];\n return `${OPEN}${JSON.stringify(fields)}${CLOSE}`;\n }\n\n /** True when `text` still holds an encoded link — a published output never may. */\n // webpieces-disable no-function-outside-class -- static codec of the grammar this class owns\n static hasLinks(text: string): boolean {\n return text.includes(OPEN);\n }\n\n /**\n * Every link in `text` as WRITTEN, in the published spelling: for a measurement that must not count\n * the encoding (a `@summary`'s length) and for a reader that publishes nothing.\n */\n // webpieces-disable no-function-outside-class -- static codec of the grammar this class owns\n static asWritten(text: string): string {\n return text.replace(ENCODED, (_all: string, body: string) => {\n const link = DocLinkText.decode(body);\n return DocLinkText.spell(link, link.written);\n });\n }\n\n /** Every encoded link in `text`, in order. */\n // webpieces-disable no-function-outside-class -- static codec of the grammar this class owns\n static linksIn(text: string): readonly DocLink[] {\n const links: DocLink[] = [];\n for (const match of text.matchAll(ENCODED)) {\n links.push(DocLinkText.decode(match[1] ?? ''));\n }\n return links;\n }\n\n /** `text` with every link published under the name `naming` gives it; misses go to `problems`. */\n // webpieces-disable no-function-outside-class -- static codec of the grammar this class owns\n static resolve(\n text: string,\n naming: DocLinkNaming,\n output: string,\n problems: DocLinkProblem[],\n ): string {\n return text.replace(ENCODED, (_all: string, body: string) => {\n const link = DocLinkText.decode(body);\n const name =\n link.kind === DocLinkKind.UNRESOLVED ? undefined : naming.publishedName(link);\n if (name === undefined) {\n problems.push(\n new DocLinkProblem(link.location, link.written, DocLinkText.why(link, output)),\n );\n return DocLinkText.spell(link, link.written);\n }\n return DocLinkText.spell(\n link,\n link.kind === DocLinkKind.TYPE ? `${name}${link.member}` : name,\n );\n });\n }\n\n /** The one published spelling — see the class doc. */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static spell(link: DocLink, name: string): string {\n const code = `\\`${name}\\``;\n return link.label === undefined ? code : `${link.label} (${code})`;\n }\n\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static why(link: DocLink, output: string): string {\n switch (link.kind) {\n case DocLinkKind.TYPE:\n return `type ${link.ownerName} is not published in ${output}`;\n case DocLinkKind.OPERATION:\n return `operation ${link.owner}.${link.ownerName} is not published in ${output}`;\n default:\n return link.reason;\n }\n }\n\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static decode(body: string): DocLink {\n const f = JSON.parse(body) as (string | null)[];\n return new DocLink(\n f[0] as DocLinkKind,\n f[1] ?? '',\n f[2] ?? undefined,\n f[3] ?? '',\n f[4] ?? '',\n f[5] ?? '',\n f[6] ?? '',\n f[7] ?? undefined,\n f[8] ?? '',\n );\n }\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EndpointSummary = void 0;
|
|
4
|
+
const DocLink_1 = require("./DocLink");
|
|
4
5
|
/**
|
|
5
6
|
* THE rule for an endpoint's `@summary` JSDoc tag (#1296): present, one line, at most 100 characters.
|
|
6
7
|
*
|
|
@@ -25,8 +26,10 @@ class EndpointSummary {
|
|
|
25
26
|
if (/[\r\n]/.test(summary)) {
|
|
26
27
|
return '@summary spans more than one line';
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
// A `{@link}` is measured as it reads, never as its encoding in the model (#1284).
|
|
30
|
+
const length = DocLink_1.DocLinkText.asWritten(summary).length;
|
|
31
|
+
if (length > EndpointSummary.MAX_LENGTH) {
|
|
32
|
+
return `@summary is ${length} characters, over the ${EndpointSummary.MAX_LENGTH}-character limit`;
|
|
30
33
|
}
|
|
31
34
|
return undefined;
|
|
32
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EndpointSummary.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/model/EndpointSummary.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;GAWG;AACH,MAAa,eAAe;IACxB,mEAAmE;IACnE,MAAM,CAAU,UAAU,GAAG,GAAG,CAAC;IAEjC,4FAA4F;IAC5F,oGAAoG;IACpG,MAAM,CAAC,WAAW,CAAC,OAA2B;QAC1C,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACjD,OAAO,iBAAiB,CAAC;QAC7B,CAAC;QACD,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACzB,OAAO,mCAAmC,CAAC;QAC/C,CAAC;QACD,
|
|
1
|
+
{"version":3,"file":"EndpointSummary.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/model/EndpointSummary.ts"],"names":[],"mappings":";;;AAAA,uCAAwC;AAExC;;;;;;;;;;;GAWG;AACH,MAAa,eAAe;IACxB,mEAAmE;IACnE,MAAM,CAAU,UAAU,GAAG,GAAG,CAAC;IAEjC,4FAA4F;IAC5F,oGAAoG;IACpG,MAAM,CAAC,WAAW,CAAC,OAA2B;QAC1C,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACjD,OAAO,iBAAiB,CAAC;QAC7B,CAAC;QACD,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACzB,OAAO,mCAAmC,CAAC;QAC/C,CAAC;QACD,mFAAmF;QACnF,MAAM,MAAM,GAAG,qBAAW,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;QACrD,IAAI,MAAM,GAAG,eAAe,CAAC,UAAU,EAAE,CAAC;YACtC,OAAO,eAAe,MAAM,yBAAyB,eAAe,CAAC,UAAU,kBAAkB,CAAC;QACtG,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,sDAAsD;IACtD,oGAAoG;IACpG,MAAM,CAAC,IAAI;QACP,OAAO,CACH,iFAAiF;YACjF,GAAG,eAAe,CAAC,UAAU,0DAA0D;YACvF,uFAAuF;YACvF,0FAA0F;YAC1F,cAAc,CACjB,CAAC;IACN,CAAC;;AA/BL,0CAgCC","sourcesContent":["import { DocLinkText } from './DocLink';\n\n/**\n * THE rule for an endpoint's `@summary` JSDoc tag (#1296): present, one line, at most 100 characters.\n *\n * The summary is the endpoint's short title. It is published as the OpenAPI operation `summary` — what\n * a docs site heads the page with and labels the sidebar with — and as MCP `Tool.title` and\n * `annotations.title`, which clients and the Claude Connectors Directory show. A heading and a sidebar\n * label is one line, so a second line is refused rather than joined, and 100 characters is a house\n * rule (no spec sets one) that keeps it a label rather than a sentence.\n *\n * It is here, beside the model, so the OpenAPI generator's guard, the MCP renderer and\n * `api-rules-for-mcp` all ask the SAME question of the same text.\n */\nexport class EndpointSummary {\n /** The longest summary a heading or sidebar label should carry. */\n static readonly MAX_LENGTH = 100;\n\n /** What is wrong with `summary`, in one clause, or undefined when it is a legal summary. */\n // webpieces-disable no-function-outside-class -- static helper of this class; the rule has no state\n static problemWith(summary: string | undefined): string | undefined {\n if (summary === undefined || summary.trim() === '') {\n return 'has no @summary';\n }\n if (/[\\r\\n]/.test(summary)) {\n return '@summary spans more than one line';\n }\n // A `{@link}` is measured as it reads, never as its encoding in the model (#1284).\n const length = DocLinkText.asWritten(summary).length;\n if (length > EndpointSummary.MAX_LENGTH) {\n return `@summary is ${length} characters, over the ${EndpointSummary.MAX_LENGTH}-character limit`;\n }\n return undefined;\n }\n\n /** The one cure every refusal of a summary prints. */\n // webpieces-disable no-function-outside-class -- static helper of this class; the rule has no state\n static cure(): string {\n return (\n \"Write a `@summary <short title>` line in the method's JSDoc: one line, at most \" +\n `${EndpointSummary.MAX_LENGTH} characters, e.g. \\`@summary Fetch your orders\\`. It is ` +\n \"published as the OpenAPI operation's summary (a docs site's page heading and sidebar \" +\n 'label) and as the MCP tool title and annotations.title; the rest of the JSDoc stays the ' +\n 'description.'\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How every operation's `operationId` is spelled (#1270). OPTIONAL in a contract manifest, defaulting
|
|
3
|
+
* to {@link CONTRACT_METHOD} (#1283) — the spelling every earlier release published, and the only one
|
|
4
|
+
* unique by construction. `operationId` is what openapi-generator, Kiota, NSwag and friends name the
|
|
5
|
+
* METHOD in every client a partner generates, so changing the spelling renames every method in every
|
|
6
|
+
* partner's SDK; {@link METHOD} is the opt-in for a document that already published bare names.
|
|
7
|
+
*
|
|
8
|
+
* It lives beside the model rather than in the OpenAPI generator because two renderers name an
|
|
9
|
+
* operation: the OpenAPI document, and an MCP tool catalog resolving a `{@link}` to a contract method
|
|
10
|
+
* that is not a tool (#1284). One rule, one place.
|
|
11
|
+
*/
|
|
12
|
+
export declare enum OperationIdStyle {
|
|
13
|
+
/** `OrdersApi_fetchOrders` — unique by construction across contracts. */
|
|
14
|
+
CONTRACT_METHOD = "contract_method",
|
|
15
|
+
/**
|
|
16
|
+
* `fetchOrders` — the bare method name. Two operations of one document sharing it is a HARD
|
|
17
|
+
* FAILURE naming both, so the id is still unique.
|
|
18
|
+
*/
|
|
19
|
+
METHOD = "method"
|
|
20
|
+
}
|
|
21
|
+
/** THE operationId of a contract method, in a manifest's chosen {@link OperationIdStyle}. */
|
|
22
|
+
export declare class OperationIds {
|
|
23
|
+
private readonly style;
|
|
24
|
+
constructor(style: OperationIdStyle);
|
|
25
|
+
of(contractName: string, methodName: string): string;
|
|
26
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OperationIds = exports.OperationIdStyle = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* How every operation's `operationId` is spelled (#1270). OPTIONAL in a contract manifest, defaulting
|
|
6
|
+
* to {@link CONTRACT_METHOD} (#1283) — the spelling every earlier release published, and the only one
|
|
7
|
+
* unique by construction. `operationId` is what openapi-generator, Kiota, NSwag and friends name the
|
|
8
|
+
* METHOD in every client a partner generates, so changing the spelling renames every method in every
|
|
9
|
+
* partner's SDK; {@link METHOD} is the opt-in for a document that already published bare names.
|
|
10
|
+
*
|
|
11
|
+
* It lives beside the model rather than in the OpenAPI generator because two renderers name an
|
|
12
|
+
* operation: the OpenAPI document, and an MCP tool catalog resolving a `{@link}` to a contract method
|
|
13
|
+
* that is not a tool (#1284). One rule, one place.
|
|
14
|
+
*/
|
|
15
|
+
var OperationIdStyle;
|
|
16
|
+
(function (OperationIdStyle) {
|
|
17
|
+
/** `OrdersApi_fetchOrders` — unique by construction across contracts. */
|
|
18
|
+
OperationIdStyle["CONTRACT_METHOD"] = "contract_method";
|
|
19
|
+
/**
|
|
20
|
+
* `fetchOrders` — the bare method name. Two operations of one document sharing it is a HARD
|
|
21
|
+
* FAILURE naming both, so the id is still unique.
|
|
22
|
+
*/
|
|
23
|
+
OperationIdStyle["METHOD"] = "method";
|
|
24
|
+
})(OperationIdStyle || (exports.OperationIdStyle = OperationIdStyle = {}));
|
|
25
|
+
/** THE operationId of a contract method, in a manifest's chosen {@link OperationIdStyle}. */
|
|
26
|
+
class OperationIds {
|
|
27
|
+
style;
|
|
28
|
+
constructor(style) {
|
|
29
|
+
this.style = style;
|
|
30
|
+
}
|
|
31
|
+
of(contractName, methodName) {
|
|
32
|
+
return this.style === OperationIdStyle.METHOD
|
|
33
|
+
? methodName
|
|
34
|
+
: `${contractName}_${methodName}`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.OperationIds = OperationIds;
|
|
38
|
+
//# sourceMappingURL=OperationIds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OperationIds.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/model/OperationIds.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACH,IAAY,gBAQX;AARD,WAAY,gBAAgB;IACxB,yEAAyE;IACzE,uDAAmC,CAAA;IACnC;;;OAGG;IACH,qCAAiB,CAAA;AACrB,CAAC,EARW,gBAAgB,gCAAhB,gBAAgB,QAQ3B;AAED,6FAA6F;AAC7F,MAAa,YAAY;IACQ;IAA7B,YAA6B,KAAuB;QAAvB,UAAK,GAAL,KAAK,CAAkB;IAAG,CAAC;IAExD,EAAE,CAAC,YAAoB,EAAE,UAAkB;QACvC,OAAO,IAAI,CAAC,KAAK,KAAK,gBAAgB,CAAC,MAAM;YACzC,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,GAAG,YAAY,IAAI,UAAU,EAAE,CAAC;IAC1C,CAAC;CACJ;AARD,oCAQC","sourcesContent":["/**\n * How every operation's `operationId` is spelled (#1270). OPTIONAL in a contract manifest, defaulting\n * to {@link CONTRACT_METHOD} (#1283) — the spelling every earlier release published, and the only one\n * unique by construction. `operationId` is what openapi-generator, Kiota, NSwag and friends name the\n * METHOD in every client a partner generates, so changing the spelling renames every method in every\n * partner's SDK; {@link METHOD} is the opt-in for a document that already published bare names.\n *\n * It lives beside the model rather than in the OpenAPI generator because two renderers name an\n * operation: the OpenAPI document, and an MCP tool catalog resolving a `{@link}` to a contract method\n * that is not a tool (#1284). One rule, one place.\n */\nexport enum OperationIdStyle {\n /** `OrdersApi_fetchOrders` — unique by construction across contracts. */\n CONTRACT_METHOD = 'contract_method',\n /**\n * `fetchOrders` — the bare method name. Two operations of one document sharing it is a HARD\n * FAILURE naming both, so the id is still unique.\n */\n METHOD = 'method',\n}\n\n/** THE operationId of a contract method, in a manifest's chosen {@link OperationIdStyle}. */\nexport class OperationIds {\n constructor(private readonly style: OperationIdStyle) {}\n\n of(contractName: string, methodName: string): string {\n return this.style === OperationIdStyle.METHOD\n ? methodName\n : `${contractName}_${methodName}`;\n }\n}\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ApiJsonSchema, McpToolCatalogFile, McpToolDefinition } from '@webpieces/core-util';
|
|
2
2
|
import { ApiDocModel, DocumentedEndpoint } from '../model/ApiDocModel';
|
|
3
|
+
import { DocLinkProblem } from '../model/DocLink';
|
|
4
|
+
import { OperationIds } from '../model/OperationIds';
|
|
3
5
|
import { TypeRef } from '../model/TypeRef';
|
|
4
6
|
/** ONE `@WpMcpTool` the build could not give a schema, and why. See {@link McpSchemaRenderer.catalogOf}. */
|
|
5
7
|
export declare class SkippedMcpTool {
|
|
@@ -53,7 +55,19 @@ export declare class McpCatalogRender {
|
|
|
53
55
|
export declare class McpSchemaRenderer {
|
|
54
56
|
private readonly model;
|
|
55
57
|
private readonly requireDescriptions;
|
|
56
|
-
|
|
58
|
+
private readonly naming;
|
|
59
|
+
private readonly problems;
|
|
60
|
+
constructor(model: ApiDocModel,
|
|
61
|
+
/**
|
|
62
|
+
* The manifest's operationId spelling — what a `{@link}` to a contract method that is NOT a
|
|
63
|
+
* tool publishes as (#1284).
|
|
64
|
+
*/
|
|
65
|
+
operationIds: OperationIds, requireDescriptions?: boolean);
|
|
66
|
+
/**
|
|
67
|
+
* Every `{@link}` this renderer could not name, so far. A caller that PUBLISHES what it rendered
|
|
68
|
+
* refuses when this is non-empty — {@link catalogOf} does.
|
|
69
|
+
*/
|
|
70
|
+
linkProblems(): readonly DocLinkProblem[];
|
|
57
71
|
/** The shared inline runtime schema projection, also used by streaming catalog generation. */
|
|
58
72
|
schemaFor(ref: TypeRef, where: string): ApiJsonSchema;
|
|
59
73
|
/** Every `@WpMcpTool` method of the contract, in declaration order. */
|
|
@@ -82,7 +96,16 @@ export declare class McpSchemaRenderer {
|
|
|
82
96
|
* which is the right place for that failure, because that is the process actually claiming to
|
|
83
97
|
* serve it.
|
|
84
98
|
*/
|
|
85
|
-
static catalogOf(models: readonly ApiDocModel[]): McpCatalogRender;
|
|
99
|
+
static catalogOf(models: readonly ApiDocModel[], operationIds: OperationIds): McpCatalogRender;
|
|
100
|
+
/**
|
|
101
|
+
* A `{@link}` no catalog can name is REFUSED, not skipped (#1284): it is a defect in prose, not a
|
|
102
|
+
* protocol limit, and a tool published with a dangling reference tells an agent about something it
|
|
103
|
+
* cannot find. Every offender is named in one run. `wp-openapi` refuses the same links in
|
|
104
|
+
* `mcp-openapi.json` first; this is the catalog's own backstop.
|
|
105
|
+
*/
|
|
106
|
+
private static refuseLinks;
|
|
107
|
+
/** `text` as published: every `{@link}` named, every miss recorded — see {@link linkProblems}. */
|
|
108
|
+
private prose;
|
|
86
109
|
/** Refuse a tool name some OTHER contract of this run already declared: the namespace is flat. */
|
|
87
110
|
private static claimNames;
|
|
88
111
|
/** ONE tool. Visible to {@link catalogOf}, which renders tool by tool so it can report one. */
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.McpSchemaRenderer = exports.McpCatalogRender = exports.SkippedMcpTool = void 0;
|
|
4
4
|
const core_util_1 = require("@webpieces/core-util");
|
|
5
|
+
const DocLink_1 = require("../model/DocLink");
|
|
5
6
|
const EndpointSummary_1 = require("../model/EndpointSummary");
|
|
6
7
|
const McpRenderError_1 = require("./McpRenderError");
|
|
7
8
|
/** RFC 9110 token, which is what an `Mcp-Param-{name}` header name has to be. */
|
|
@@ -25,6 +26,28 @@ class SkippedMcpTool {
|
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
exports.SkippedMcpTool = SkippedMcpTool;
|
|
29
|
+
/** The output name every MCP link refusal names. */
|
|
30
|
+
const MCP_OUTPUT = 'the MCP tool catalog';
|
|
31
|
+
/**
|
|
32
|
+
* How an MCP tool catalog names a `{@link}` target (#1284). A tool schema is fully inline, so a type
|
|
33
|
+
* is named by its published schema name; a contract method that IS a tool by its tool `name` — the
|
|
34
|
+
* one thing an MCP client can call — and any other method by its operationId.
|
|
35
|
+
*/
|
|
36
|
+
class McpLinkNaming {
|
|
37
|
+
operationIds;
|
|
38
|
+
constructor(operationIds) {
|
|
39
|
+
this.operationIds = operationIds;
|
|
40
|
+
}
|
|
41
|
+
publishedName(link) {
|
|
42
|
+
if (link.kind === DocLink_1.DocLinkKind.TYPE) {
|
|
43
|
+
return link.ownerName;
|
|
44
|
+
}
|
|
45
|
+
if (link.kind === DocLink_1.DocLinkKind.OPERATION) {
|
|
46
|
+
return link.mcpToolName ?? this.operationIds.of(link.owner, link.ownerName);
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
28
51
|
/**
|
|
29
52
|
* What one catalog render produced: ONE catalog per contract that has at least one renderable tool
|
|
30
53
|
* (`mcp-<ContractClass>-tools.json` each), and the tools it could not produce.
|
|
@@ -67,9 +90,24 @@ exports.McpCatalogRender = McpCatalogRender;
|
|
|
67
90
|
class McpSchemaRenderer {
|
|
68
91
|
model;
|
|
69
92
|
requireDescriptions;
|
|
70
|
-
|
|
93
|
+
naming;
|
|
94
|
+
problems = [];
|
|
95
|
+
constructor(model,
|
|
96
|
+
/**
|
|
97
|
+
* The manifest's operationId spelling — what a `{@link}` to a contract method that is NOT a
|
|
98
|
+
* tool publishes as (#1284).
|
|
99
|
+
*/
|
|
100
|
+
operationIds, requireDescriptions = true) {
|
|
71
101
|
this.model = model;
|
|
72
102
|
this.requireDescriptions = requireDescriptions;
|
|
103
|
+
this.naming = new McpLinkNaming(operationIds);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Every `{@link}` this renderer could not name, so far. A caller that PUBLISHES what it rendered
|
|
107
|
+
* refuses when this is non-empty — {@link catalogOf} does.
|
|
108
|
+
*/
|
|
109
|
+
linkProblems() {
|
|
110
|
+
return this.problems;
|
|
73
111
|
}
|
|
74
112
|
/** The shared inline runtime schema projection, also used by streaming catalog generation. */
|
|
75
113
|
schemaFor(ref, where) {
|
|
@@ -110,12 +148,13 @@ class McpSchemaRenderer {
|
|
|
110
148
|
* serve it.
|
|
111
149
|
*/
|
|
112
150
|
// webpieces-disable no-function-outside-class -- static factory over this class
|
|
113
|
-
static catalogOf(models) {
|
|
151
|
+
static catalogOf(models, operationIds) {
|
|
114
152
|
const catalogs = [];
|
|
115
153
|
const skipped = [];
|
|
116
154
|
const owners = new Map();
|
|
155
|
+
const problems = [];
|
|
117
156
|
for (const model of models) {
|
|
118
|
-
const renderer = new McpSchemaRenderer(model);
|
|
157
|
+
const renderer = new McpSchemaRenderer(model, operationIds);
|
|
119
158
|
const tools = [];
|
|
120
159
|
for (const endpoint of model.endpoints) {
|
|
121
160
|
if (endpoint.mcpTool === undefined) {
|
|
@@ -133,12 +172,33 @@ class McpSchemaRenderer {
|
|
|
133
172
|
}
|
|
134
173
|
}
|
|
135
174
|
McpSchemaRenderer.claimNames(owners, model.contractName, tools);
|
|
175
|
+
problems.push(...renderer.linkProblems());
|
|
136
176
|
if (tools.length > 0) {
|
|
137
177
|
catalogs.push(new core_util_1.McpToolCatalogFile(model.contractName, tools));
|
|
138
178
|
}
|
|
139
179
|
}
|
|
180
|
+
McpSchemaRenderer.refuseLinks(problems);
|
|
140
181
|
return new McpCatalogRender(catalogs, skipped);
|
|
141
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* A `{@link}` no catalog can name is REFUSED, not skipped (#1284): it is a defect in prose, not a
|
|
185
|
+
* protocol limit, and a tool published with a dangling reference tells an agent about something it
|
|
186
|
+
* cannot find. Every offender is named in one run. `wp-openapi` refuses the same links in
|
|
187
|
+
* `mcp-openapi.json` first; this is the catalog's own backstop.
|
|
188
|
+
*/
|
|
189
|
+
// webpieces-disable no-function-outside-class -- private static helper of this class
|
|
190
|
+
static refuseLinks(problems) {
|
|
191
|
+
if (problems.length === 0) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
throw new core_util_1.McpToolCatalogError(`${problems.length} {@link} reference(s) in MCP tool prose name nothing the catalog ` +
|
|
195
|
+
`publishes: ${problems.map((each) => each.toString()).join('; ')}.`, 'Point each {@link} at a published type or an @Endpoint method of an @ApiPath contract, ' +
|
|
196
|
+
'imported into the file the JSDoc is in, or write the name as plain text.');
|
|
197
|
+
}
|
|
198
|
+
/** `text` as published: every `{@link}` named, every miss recorded — see {@link linkProblems}. */
|
|
199
|
+
prose(text) {
|
|
200
|
+
return DocLink_1.DocLinkText.resolve(text, this.naming, MCP_OUTPUT, this.problems);
|
|
201
|
+
}
|
|
142
202
|
/** Refuse a tool name some OTHER contract of this run already declared: the namespace is flat. */
|
|
143
203
|
// webpieces-disable no-function-outside-class -- private static helper of this class
|
|
144
204
|
static claimNames(owners, contractName, tools) {
|
|
@@ -171,7 +231,7 @@ class McpSchemaRenderer {
|
|
|
171
231
|
if (nameProblem !== undefined) {
|
|
172
232
|
throw new McpRenderError_1.McpRenderError(`the MCP tool name '${endpoint.mcpTool.name}' ${nameProblem}`, where, core_util_1.McpToolName.cure());
|
|
173
233
|
}
|
|
174
|
-
return new core_util_1.McpToolDefinition(endpoint.mcpTool.name, endpoint.summary, endpoint.methodName, description, (0, core_util_1.mcpHintsForOperation)(McpSchemaRenderer.operationOf(endpoint, where), endpoint.openWorld), this.rootSchema(endpoint.request, where, 'request', undefined), this.rootSchema(endpoint.response, where, 'response', endpoint.returnsDescription), endpoint.mcpTool.profiles);
|
|
234
|
+
return new core_util_1.McpToolDefinition(endpoint.mcpTool.name, this.prose(endpoint.summary), endpoint.methodName, this.prose(description), (0, core_util_1.mcpHintsForOperation)(McpSchemaRenderer.operationOf(endpoint, where), endpoint.openWorld), this.rootSchema(endpoint.request, where, 'request', undefined), this.rootSchema(endpoint.response, where, 'response', endpoint.returnsDescription), endpoint.mcpTool.profiles);
|
|
175
235
|
}
|
|
176
236
|
/**
|
|
177
237
|
* `operation` verbatim from the model, mapped back onto the REAL constant.
|
|
@@ -221,7 +281,7 @@ class McpSchemaRenderer {
|
|
|
221
281
|
'request in the session.');
|
|
222
282
|
}
|
|
223
283
|
const schema = this.objectSchema(type, new Set());
|
|
224
|
-
McpSchemaRenderer.describeRoot(schema, returns ?? type.description);
|
|
284
|
+
McpSchemaRenderer.describeRoot(schema, this.prose(returns ?? type.description));
|
|
225
285
|
return schema;
|
|
226
286
|
}
|
|
227
287
|
/**
|
|
@@ -303,7 +363,7 @@ class McpSchemaRenderer {
|
|
|
303
363
|
const schema = new core_util_1.ApiJsonSchema();
|
|
304
364
|
schema.oneOf = type.unionRefNames.map((name) => this.objectSchema(this.namedType(name, type.name), nested));
|
|
305
365
|
if (type.description.trim() !== '') {
|
|
306
|
-
schema.description = type.description;
|
|
366
|
+
schema.description = this.prose(type.description);
|
|
307
367
|
}
|
|
308
368
|
if (type.discriminator !== undefined) {
|
|
309
369
|
const mapping = {};
|
|
@@ -358,7 +418,7 @@ class McpSchemaRenderer {
|
|
|
358
418
|
throw new McpRenderError_1.McpRenderError('a published DTO field has no documentation', where, 'Write a JSDoc sentence on the field. It is the only thing an agent is told about ' +
|
|
359
419
|
'that parameter.');
|
|
360
420
|
}
|
|
361
|
-
schema.description = description;
|
|
421
|
+
schema.description = this.prose(description);
|
|
362
422
|
const leaf = field.type.kind === 'array' ? schema.items : schema;
|
|
363
423
|
if (field.min !== undefined) {
|
|
364
424
|
leaf.minimum = field.min;
|