@webpieces/openapi-generator 0.4.1003 → 0.4.1005
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/openapi-generator",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1005",
|
|
4
4
|
"description": "Render an ApiDocModel to OpenAPI 3.1.0 — the canonical internal document and the customer-published one, JSON and YAML, from one generation pass. Ships the wp-openapi bin.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@webpieces/api-doc-model": "0.4.
|
|
27
|
-
"@webpieces/core-util": "0.4.
|
|
26
|
+
"@webpieces/api-doc-model": "0.4.1005",
|
|
27
|
+
"@webpieces/core-util": "0.4.1005",
|
|
28
28
|
"typescript": "5.9.3"
|
|
29
29
|
},
|
|
30
30
|
"bin": {
|
|
@@ -122,6 +122,11 @@ export declare class DocumentSelection {
|
|
|
122
122
|
* exists nowhere any reader of any of these documents could call it. Publishing it even in the
|
|
123
123
|
* private one would document a route that does not exist in any deployed environment — worse
|
|
124
124
|
* than omitting it, because a reader would reasonably try to call it.
|
|
125
|
+
*
|
|
126
|
+
* `@InvalidEndpointForMcp` subtracts a method from the MCP document ONLY (#1447). The method is
|
|
127
|
+
* declared permanently unusable as an agent tool — typically because its shape cannot be an MCP
|
|
128
|
+
* schema at all — so the agent-facing projection must not carry it, while the private and
|
|
129
|
+
* customer documents still publish it exactly as before.
|
|
125
130
|
*/
|
|
126
131
|
acceptsEndpoint(endpoint: DocumentedEndpoint): boolean;
|
|
127
132
|
/**
|
|
@@ -169,11 +169,19 @@ class DocumentSelection {
|
|
|
169
169
|
* exists nowhere any reader of any of these documents could call it. Publishing it even in the
|
|
170
170
|
* private one would document a route that does not exist in any deployed environment — worse
|
|
171
171
|
* than omitting it, because a reader would reasonably try to call it.
|
|
172
|
+
*
|
|
173
|
+
* `@InvalidEndpointForMcp` subtracts a method from the MCP document ONLY (#1447). The method is
|
|
174
|
+
* declared permanently unusable as an agent tool — typically because its shape cannot be an MCP
|
|
175
|
+
* schema at all — so the agent-facing projection must not carry it, while the private and
|
|
176
|
+
* customer documents still publish it exactly as before.
|
|
172
177
|
*/
|
|
173
178
|
acceptsEndpoint(endpoint) {
|
|
174
179
|
if (endpoint.localOnly) {
|
|
175
180
|
return false;
|
|
176
181
|
}
|
|
182
|
+
if (this.apiType === core_util_1.MCP && endpoint.invalidForMcp !== undefined) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
177
185
|
return !this.dropHidden || !endpoint.hidden;
|
|
178
186
|
}
|
|
179
187
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentSelection.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/DocumentSelection.ts"],"names":[],"mappings":";;;AACA,oDAK8B;AAE9B,iGAAiG;AACpF,QAAA,kBAAkB,GAC3B,+MAA+M,CAAC;AAEpN;;;;;;;;;;GAUG;AACU,QAAA,mBAAmB,GAAG;IAC/B,2FAA2F;IAC3F,2FAA2F;IAC3F,uEAAuE;IACvE,EAAE;IACF,+DAA+D;IAC/D,mBAAmB;IACnB,2BAA2B;IAC3B,uCAAuC;IACvC,2BAA2B;CAC9B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAa,iBAAiB;IAGb;IAEA;IAMA;IAEA;IAMA;IAQA;IAOA;IAOA;IAxCb;IACI,qFAAqF;IAC5E,QAAgB;IACzB,yEAAyE;IAChE,OAAoB;IAC7B;;;;OAIG;IACM,UAAmB;IAC5B,wFAAwF;IAC/E,oBAA6B;IACtC;;;;O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AQ,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC;IAED;;;;;;;;OAQG;IACH,eAAe,CAAC,QAA4B;QACxC,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;YACrB,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAChD,CAAC;IAED;;;;;OAKG;IACH,WAAW,CAAC,mBAAuC,EAAE,SAAkB;QACnE,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,KAAK,CAAC,IAAI,CAAC,0BAAkB,CAAC,CAAC;QACnC,CAAC;QACD,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;YACpC,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACpC,CAAC;QACD,IAAI,SAAS,EAAE,CAAC;YACZ,KAAK,CAAC,IAAI,CAAC,2BAAmB,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/D,CAAC;CACJ;AArID,8CAqIC","sourcesContent":["import { ApiDocModel, DocumentedEndpoint } from '@webpieces/api-doc-model';\nimport {\n ApiTypeKind,\n EXTERNAL_CUSTOMER,\n MCP,\n SVC_TO_SVC,\n} from '@webpieces/core-util';\n\n/** The one line that says a document is not the customer contract. It appears in exactly one. */\nexport const INTERNAL_ONLY_LINE =\n 'INTERNAL — service-to-service use only. This document lists every endpoint these services serve, including ones no customer is meant to see. It is not the customer contract and must never be handed to one.';\n\n/**\n * The retry contract, published ONCE per document rather than as booleans stamped on every operation.\n *\n * Each route's own `description` ends with one derived sentence saying whether it is safe to\n * retry; this table says where that sentence comes from. Webhooks are excluded (#1302): the sentence\n * tells a CALLER whether to repeat a call, and a webhook's caller is us — so a document holding only\n * webhooks states no table at all (see {@link DocumentSelection.description}). Three vendor-extension booleans per\n * operation would have been invisible to a human — Swagger UI and most themes do not render `x-`\n * extensions, and no standard generator reads `x-webpieces-*` — and would have tripled golden churn\n * the day the mapping changed.\n */\nexport const OPERATION_SEMANTICS = [\n \"Every route under `paths` states whether it is safe to retry, derived from the endpoint's\",\n 'declared side-effect contract. It covers routes only: a webhook is a call we send, and we',\n 'retry its delivery ourselves, so a webhook carries no retry sentence.',\n '',\n '| declared operation | read-only | destructive | idempotent |',\n '|---|---|---|---|',\n '| read | yes | no | yes |',\n '| write-idempotent | no | yes | yes |',\n '| write | no | yes | no |',\n].join('\\n');\n\n/**\n * WHICH contracts and operations a document contains, and what prose it stamps. The ONLY thing that\n * differs between the three generated documents.\n *\n * ## Two orthogonal decisions, at two levels\n *\n * - `@ApiType(SVC_TO_SVC, EXTERNAL_CUSTOMER)` on the CONTRACT selects which FILES it feeds. A document\n * is written at all only when some contract declares its type, so no contract declaring `MCP` means\n * no `mcp-openapi.json` — there is no second emptiness rule to keep in step with that one.\n * - `{ hidden: true }` on ONE `@Endpoint` subtracts that method from the CUSTOMER document only. It\n * stays in the private document, and in the MCP document when it is a tool.\n *\n * - `@hidden` in ONE field's JSDoc subtracts that field from the CUSTOMER document only (#1246),\n * with exactly the audience of `{ hidden: true }`: kept in the private document, and in the MCP\n * document and tool catalogs.\n *\n * The per-method case is real and cannot be said at class level: a NEW endpoint on an\n * already-published API, built on main before it is announced. The per-field case is the same thing\n * one level down: a new field on an already-published DTO. The per-contract case is the one that\n * must not default to permissive, and at class level naming it costs one token per contract.\n *\n * ## Select, then render — never render, then filter\n *\n * One render function takes one of these and is called once per document. It builds\n * `components.schemas` by walking OUTWARD from the operations this selection accepted, so an\n * unselected operation's DTOs are never constructed at all.\n *\n * That asymmetry is about what a BUG does. Build-then-filter puts an unreleased feature's full\n * request and response schemas into the document and then relies on a removal pass to take them out\n * again — so a defect in the visibility logic SHIPS them, named and fully shaped, with only the URL\n * missing, to customers who were told the feature was withheld. Select-then-render cannot do that:\n * no code path can emit a schema that was never built.\n *\n * The usual objection to rendering more than once — that the passes drift in how each renders the\n * same endpoint — applies to separate code paths. This is ONE function, so same code, same input,\n * same output.\n *\n * ## The thing that bites: map ordering\n *\n * Collecting schemas during a walk makes the key order of `components.schemas` depend on which\n * operations were walked, so two documents would list identical schemas in different orders and the\n * goldens would churn on unrelated changes. The renderer SORTS the schema keys before emitting.\n * Orders that carry MEANING are left alone and said so where they are built: `apis[]` order is the\n * published sidebar, and the security-scheme order is the order the credentials are declared in.\n */\nexport class DocumentSelection {\n private constructor(\n /** The file name this document is written to, and the name a failure uses for it. */\n readonly fileName: string,\n /** The `@ApiType` a contract must declare to appear in this document. */\n readonly apiType: ApiTypeKind,\n /**\n * Drop methods marked `{ hidden: true }` AND fields marked `@hidden` (#1246). True for the\n * customer document alone — one flag, because the two are one audience decision at two\n * levels, and a second flag could only ever disagree with the first.\n */\n readonly dropHidden: boolean,\n /** Stamp `x-mcp-tool` and its siblings. Only the MCP document has a reader for them. */\n readonly includeMcpExtensions: boolean,\n /**\n * Prepend {@link INTERNAL_ONLY_LINE} to `info.description`, and say what TRIGGERS each\n * operation. Both are internal facts: a customer calls what they are given a url for, and\n * whether ours fires on a clock or off a queue is our business.\n */\n readonly internalNotice: boolean,\n /**\n * Define EVERY reached schema locally, whichever package declares it, and write no bundled\n * sibling — the MCP projection (#1058). The MCP document is the agent-facing view our own MCP\n * tooling reads, and MCP never requires a DTO library to publish a components document: an\n * MCP-only consumer is not forced to tag anything. The other two documents are SPLIT — they\n * `$ref` every other package's schema, and fail closed when that package publishes none.\n */\n readonly inlinesEveryPackage: boolean,\n /**\n * Define a single-use request/response wrapper INLINE at its operation, with its published\n * name as `title`, rather than in `components.schemas` (#1303) — see `InlinedWrappers`. The\n * split documents and their bundled siblings do; the MCP projection keeps every wrapper a\n * component, unchanged.\n */\n readonly inlinesWrappers: boolean,\n /**\n * Stamp the `x-webpieces-*` operation extensions (`x-webpieces-authentication`,\n * `x-webpieces-webhook`). False for the PUBLIC document alone (#1303): they carry source\n * identifiers and internal tooling's facts, and everything a partner needs is already in the\n * standard `security` / `securitySchemes` and `webhooks:` keys.\n */\n readonly includeWebpiecesExtensions: boolean,\n ) {}\n\n /** Every contract declaring `SVC_TO_SVC` — which, by the fail-closed default, is every contract. */\n // webpieces-disable no-function-outside-class -- static factory; the private constructor is what stops a fourth, unnamed selection being invented at a call site\n static internal(): DocumentSelection {\n return new DocumentSelection(\n 'full-private-openapi',\n SVC_TO_SVC,\n false,\n false,\n true,\n false,\n true,\n true,\n );\n }\n\n /** Every contract declaring `EXTERNAL_CUSTOMER`, minus its hidden methods. */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static customer(): DocumentSelection {\n return new DocumentSelection(\n 'public-openapi',\n EXTERNAL_CUSTOMER,\n true,\n false,\n false,\n false,\n true,\n false,\n );\n }\n\n /**\n * Every contract declaring `MCP`. A HIDDEN method is kept, and so is a `@hidden` field (#1246) — an internal endpoint that is an agent\n * tool is still a tool, and requiring it to be published to customers in order to be one would be\n * exactly the wrong coupling.\n */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static mcp(): DocumentSelection {\n return new DocumentSelection('mcp-openapi', MCP, false, true, false, true, false, true);\n }\n\n /** Every document this generator knows how to write, in the order it writes them. */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static all(): readonly DocumentSelection[] {\n return [\n DocumentSelection.internal(),\n DocumentSelection.customer(),\n DocumentSelection.mcp(),\n ];\n }\n\n acceptsContract(model: ApiDocModel): boolean {\n return model.apiTypes.includes(this.apiType);\n }\n\n /**\n * `{ hidden: true }` subtracts a method from the CUSTOMER document, and `@WpLocalOnly`\n * subtracts it from ALL of them.\n *\n * A local-only endpoint is not registered as a route at all once the process is deployed, so it\n * exists nowhere any reader of any of these documents could call it. Publishing it even in the\n * private one would document a route that does not exist in any deployed environment — worse\n * than omitting it, because a reader would reasonably try to call it.\n */\n acceptsEndpoint(endpoint: DocumentedEndpoint): boolean {\n if (endpoint.localOnly) {\n return false;\n }\n return !this.dropHidden || !endpoint.hidden;\n }\n\n /**\n * `info.description`: the manifest's prose, plus whatever this document adds to it.\n *\n * `hasRoutes` is false when every operation in the document is a webhook. The retry table then\n * describes a sentence no operation carries, so it is left out (#1302).\n */\n description(manifestDescription: string | undefined, hasRoutes: boolean): string | undefined {\n const parts: string[] = [];\n if (this.internalNotice) {\n parts.push(INTERNAL_ONLY_LINE);\n }\n if (manifestDescription !== undefined) {\n parts.push(manifestDescription);\n }\n if (hasRoutes) {\n parts.push(OPERATION_SEMANTICS);\n }\n return parts.length === 0 ? undefined : parts.join('\\n\\n');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DocumentSelection.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/DocumentSelection.ts"],"names":[],"mappings":";;;AACA,oDAK8B;AAE9B,iGAAiG;AACpF,QAAA,kBAAkB,GAC3B,+MAA+M,CAAC;AAEpN;;;;;;;;;;GAUG;AACU,QAAA,mBAAmB,GAAG;IAC/B,2FAA2F;IAC3F,2FAA2F;IAC3F,uEAAuE;IACvE,EAAE;IACF,+DAA+D;IAC/D,mBAAmB;IACnB,2BAA2B;IAC3B,uCAAuC;IACvC,2BAA2B;CAC9B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAa,iBAAiB;IAGb;IAEA;IAMA;IAEA;IAMA;IAQA;IAOA;IAOA;IAxCb;IACI,qFAAqF;IAC5E,QAAgB;IACzB,yEAAyE;IAChE,OAAoB;IAC7B;;;;OAIG;IACM,UAAmB;IAC5B,wFAAwF;IAC/E,oBAA6B;IACtC;;;;OAIG;IACM,cAAuB;IAChC;;;;;;OAMG;IACM,mBAA4B;IACrC;;;;;OAKG;IACM,eAAwB;IACjC;;;;;OAKG;IACM,0BAA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AAC,QAA4B;QACxC,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;YACrB,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,KAAK,eAAG,IAAI,QAAQ,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;YAC/D,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAChD,CAAC;IAED;;;;;OAKG;IACH,WAAW,CAAC,mBAAuC,EAAE,SAAkB;QACnE,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,KAAK,CAAC,IAAI,CAAC,0BAAkB,CAAC,CAAC;QACnC,CAAC;QACD,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;YACpC,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACpC,CAAC;QACD,IAAI,SAAS,EAAE,CAAC;YACZ,KAAK,CAAC,IAAI,CAAC,2BAAmB,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/D,CAAC;CACJ;AA7ID,8CA6IC","sourcesContent":["import { ApiDocModel, DocumentedEndpoint } from '@webpieces/api-doc-model';\nimport {\n ApiTypeKind,\n EXTERNAL_CUSTOMER,\n MCP,\n SVC_TO_SVC,\n} from '@webpieces/core-util';\n\n/** The one line that says a document is not the customer contract. It appears in exactly one. */\nexport const INTERNAL_ONLY_LINE =\n 'INTERNAL — service-to-service use only. This document lists every endpoint these services serve, including ones no customer is meant to see. It is not the customer contract and must never be handed to one.';\n\n/**\n * The retry contract, published ONCE per document rather than as booleans stamped on every operation.\n *\n * Each route's own `description` ends with one derived sentence saying whether it is safe to\n * retry; this table says where that sentence comes from. Webhooks are excluded (#1302): the sentence\n * tells a CALLER whether to repeat a call, and a webhook's caller is us — so a document holding only\n * webhooks states no table at all (see {@link DocumentSelection.description}). Three vendor-extension booleans per\n * operation would have been invisible to a human — Swagger UI and most themes do not render `x-`\n * extensions, and no standard generator reads `x-webpieces-*` — and would have tripled golden churn\n * the day the mapping changed.\n */\nexport const OPERATION_SEMANTICS = [\n \"Every route under `paths` states whether it is safe to retry, derived from the endpoint's\",\n 'declared side-effect contract. It covers routes only: a webhook is a call we send, and we',\n 'retry its delivery ourselves, so a webhook carries no retry sentence.',\n '',\n '| declared operation | read-only | destructive | idempotent |',\n '|---|---|---|---|',\n '| read | yes | no | yes |',\n '| write-idempotent | no | yes | yes |',\n '| write | no | yes | no |',\n].join('\\n');\n\n/**\n * WHICH contracts and operations a document contains, and what prose it stamps. The ONLY thing that\n * differs between the three generated documents.\n *\n * ## Two orthogonal decisions, at two levels\n *\n * - `@ApiType(SVC_TO_SVC, EXTERNAL_CUSTOMER)` on the CONTRACT selects which FILES it feeds. A document\n * is written at all only when some contract declares its type, so no contract declaring `MCP` means\n * no `mcp-openapi.json` — there is no second emptiness rule to keep in step with that one.\n * - `{ hidden: true }` on ONE `@Endpoint` subtracts that method from the CUSTOMER document only. It\n * stays in the private document, and in the MCP document when it is a tool.\n *\n * - `@hidden` in ONE field's JSDoc subtracts that field from the CUSTOMER document only (#1246),\n * with exactly the audience of `{ hidden: true }`: kept in the private document, and in the MCP\n * document and tool catalogs.\n *\n * The per-method case is real and cannot be said at class level: a NEW endpoint on an\n * already-published API, built on main before it is announced. The per-field case is the same thing\n * one level down: a new field on an already-published DTO. The per-contract case is the one that\n * must not default to permissive, and at class level naming it costs one token per contract.\n *\n * ## Select, then render — never render, then filter\n *\n * One render function takes one of these and is called once per document. It builds\n * `components.schemas` by walking OUTWARD from the operations this selection accepted, so an\n * unselected operation's DTOs are never constructed at all.\n *\n * That asymmetry is about what a BUG does. Build-then-filter puts an unreleased feature's full\n * request and response schemas into the document and then relies on a removal pass to take them out\n * again — so a defect in the visibility logic SHIPS them, named and fully shaped, with only the URL\n * missing, to customers who were told the feature was withheld. Select-then-render cannot do that:\n * no code path can emit a schema that was never built.\n *\n * The usual objection to rendering more than once — that the passes drift in how each renders the\n * same endpoint — applies to separate code paths. This is ONE function, so same code, same input,\n * same output.\n *\n * ## The thing that bites: map ordering\n *\n * Collecting schemas during a walk makes the key order of `components.schemas` depend on which\n * operations were walked, so two documents would list identical schemas in different orders and the\n * goldens would churn on unrelated changes. The renderer SORTS the schema keys before emitting.\n * Orders that carry MEANING are left alone and said so where they are built: `apis[]` order is the\n * published sidebar, and the security-scheme order is the order the credentials are declared in.\n */\nexport class DocumentSelection {\n private constructor(\n /** The file name this document is written to, and the name a failure uses for it. */\n readonly fileName: string,\n /** The `@ApiType` a contract must declare to appear in this document. */\n readonly apiType: ApiTypeKind,\n /**\n * Drop methods marked `{ hidden: true }` AND fields marked `@hidden` (#1246). True for the\n * customer document alone — one flag, because the two are one audience decision at two\n * levels, and a second flag could only ever disagree with the first.\n */\n readonly dropHidden: boolean,\n /** Stamp `x-mcp-tool` and its siblings. Only the MCP document has a reader for them. */\n readonly includeMcpExtensions: boolean,\n /**\n * Prepend {@link INTERNAL_ONLY_LINE} to `info.description`, and say what TRIGGERS each\n * operation. Both are internal facts: a customer calls what they are given a url for, and\n * whether ours fires on a clock or off a queue is our business.\n */\n readonly internalNotice: boolean,\n /**\n * Define EVERY reached schema locally, whichever package declares it, and write no bundled\n * sibling — the MCP projection (#1058). The MCP document is the agent-facing view our own MCP\n * tooling reads, and MCP never requires a DTO library to publish a components document: an\n * MCP-only consumer is not forced to tag anything. The other two documents are SPLIT — they\n * `$ref` every other package's schema, and fail closed when that package publishes none.\n */\n readonly inlinesEveryPackage: boolean,\n /**\n * Define a single-use request/response wrapper INLINE at its operation, with its published\n * name as `title`, rather than in `components.schemas` (#1303) — see `InlinedWrappers`. The\n * split documents and their bundled siblings do; the MCP projection keeps every wrapper a\n * component, unchanged.\n */\n readonly inlinesWrappers: boolean,\n /**\n * Stamp the `x-webpieces-*` operation extensions (`x-webpieces-authentication`,\n * `x-webpieces-webhook`). False for the PUBLIC document alone (#1303): they carry source\n * identifiers and internal tooling's facts, and everything a partner needs is already in the\n * standard `security` / `securitySchemes` and `webhooks:` keys.\n */\n readonly includeWebpiecesExtensions: boolean,\n ) {}\n\n /** Every contract declaring `SVC_TO_SVC` — which, by the fail-closed default, is every contract. */\n // webpieces-disable no-function-outside-class -- static factory; the private constructor is what stops a fourth, unnamed selection being invented at a call site\n static internal(): DocumentSelection {\n return new DocumentSelection(\n 'full-private-openapi',\n SVC_TO_SVC,\n false,\n false,\n true,\n false,\n true,\n true,\n );\n }\n\n /** Every contract declaring `EXTERNAL_CUSTOMER`, minus its hidden methods. */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static customer(): DocumentSelection {\n return new DocumentSelection(\n 'public-openapi',\n EXTERNAL_CUSTOMER,\n true,\n false,\n false,\n false,\n true,\n false,\n );\n }\n\n /**\n * Every contract declaring `MCP`. A HIDDEN method is kept, and so is a `@hidden` field (#1246) — an internal endpoint that is an agent\n * tool is still a tool, and requiring it to be published to customers in order to be one would be\n * exactly the wrong coupling.\n */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static mcp(): DocumentSelection {\n return new DocumentSelection('mcp-openapi', MCP, false, true, false, true, false, true);\n }\n\n /** Every document this generator knows how to write, in the order it writes them. */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static all(): readonly DocumentSelection[] {\n return [\n DocumentSelection.internal(),\n DocumentSelection.customer(),\n DocumentSelection.mcp(),\n ];\n }\n\n acceptsContract(model: ApiDocModel): boolean {\n return model.apiTypes.includes(this.apiType);\n }\n\n /**\n * `{ hidden: true }` subtracts a method from the CUSTOMER document, and `@WpLocalOnly`\n * subtracts it from ALL of them.\n *\n * A local-only endpoint is not registered as a route at all once the process is deployed, so it\n * exists nowhere any reader of any of these documents could call it. Publishing it even in the\n * private one would document a route that does not exist in any deployed environment — worse\n * than omitting it, because a reader would reasonably try to call it.\n *\n * `@InvalidEndpointForMcp` subtracts a method from the MCP document ONLY (#1447). The method is\n * declared permanently unusable as an agent tool — typically because its shape cannot be an MCP\n * schema at all — so the agent-facing projection must not carry it, while the private and\n * customer documents still publish it exactly as before.\n */\n acceptsEndpoint(endpoint: DocumentedEndpoint): boolean {\n if (endpoint.localOnly) {\n return false;\n }\n if (this.apiType === MCP && endpoint.invalidForMcp !== undefined) {\n return false;\n }\n return !this.dropHidden || !endpoint.hidden;\n }\n\n /**\n * `info.description`: the manifest's prose, plus whatever this document adds to it.\n *\n * `hasRoutes` is false when every operation in the document is a webhook. The retry table then\n * describes a sentence no operation carries, so it is left out (#1302).\n */\n description(manifestDescription: string | undefined, hasRoutes: boolean): string | undefined {\n const parts: string[] = [];\n if (this.internalNotice) {\n parts.push(INTERNAL_ONLY_LINE);\n }\n if (manifestDescription !== undefined) {\n parts.push(manifestDescription);\n }\n if (hasRoutes) {\n parts.push(OPERATION_SEMANTICS);\n }\n return parts.length === 0 ? undefined : parts.join('\\n\\n');\n }\n}\n"]}
|
|
@@ -266,6 +266,10 @@ class SchemaRenderer {
|
|
|
266
266
|
}
|
|
267
267
|
return schema.set('type', [declared, 'null']);
|
|
268
268
|
}
|
|
269
|
+
if (Array.isArray(declared)) {
|
|
270
|
+
// A type that is already a LIST (`JsonValueDto`'s, #1447) gains `null` once, in place.
|
|
271
|
+
return declared.includes('null') ? schema : schema.set('type', [...declared, 'null']);
|
|
272
|
+
}
|
|
269
273
|
return new JsonObject_1.JsonObject().set('anyOf', [schema, new JsonObject_1.JsonObject().set('type', 'null')]);
|
|
270
274
|
}
|
|
271
275
|
/** One resolved type, with no field-level prose or constraints on it. */
|
|
@@ -311,6 +315,13 @@ class SchemaRenderer {
|
|
|
311
315
|
return new JsonObject_1.JsonObject().set('oneOf', ref.unionRefNames.map((each) => this.reference(each)));
|
|
312
316
|
}
|
|
313
317
|
primitive(ref) {
|
|
318
|
+
if (ref.primitive === 'json') {
|
|
319
|
+
// `JsonValueDto` (#1447): any JSON value, nested to any depth — the same open schema the
|
|
320
|
+
// MCP catalogs publish, with `additionalProperties: true` stated rather than implied.
|
|
321
|
+
return new JsonObject_1.JsonObject()
|
|
322
|
+
.set('type', ['string', 'number', 'boolean', 'object', 'array', 'null'])
|
|
323
|
+
.set('additionalProperties', true);
|
|
324
|
+
}
|
|
314
325
|
if (ref.primitive === 'unknown') {
|
|
315
326
|
// No `type` at all: JSON Schema's honest spelling of "any shape". It is only ever reached
|
|
316
327
|
// by a `void` return, which is why it is not the unmapped refusal.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaRenderer.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/SchemaRenderer.ts"],"names":[],"mappings":";;;AACA,mDAA2D;AAI3D,qGAAqG;AACrG,MAAa,aAAa;IAGT;IAEA;IAJb;IACI,qEAAqE;IAC5D,OAAe;IACxB,qFAAqF;IAC5E,QAAgB;QAFhB,YAAO,GAAP,OAAO,CAAQ;QAEf,aAAQ,GAAR,QAAQ,CAAQ;IAC1B,CAAC;CACP;AAPD,sCAOC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAa,cAAc;IAQF;IACA;IAEA;IAMA;IAhBJ,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAC5B,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAC5B,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IAC7B,cAAc,GAAoB,EAAE,CAAC;IAEtD;IACI,gEAAgE;IAC/C,KAA0C,EAC1C,SAA0B;IAC3C,8EAA8E;IAC7D,QAAyB;IAC1C;;;;OAIG;IACc,iBAA0B;QAT1B,UAAK,GAAL,KAAK,CAAqC;QAC1C,cAAS,GAAT,SAAS,CAAiB;QAE1B,aAAQ,GAAR,QAAQ,CAAiB;QAMzB,sBAAiB,GAAjB,iBAAiB,CAAS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AC;IAC7D,CAAC;IAEO,SAAS,CAAC,GAAW;QACzB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACrB,yFAAyF;YACzF,gEAAgE;YAChE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACtB,OAAO,wBAAwB,GAAG,EAAE,CAAC;QACzC,CAAC;QACD,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,+FAA+F;IACvF,KAAK,CAAC,IAAwB;QAClC,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IACvE,CAAC;CACJ;AArUD,wCAqUC","sourcesContent":["import { DocumentedField, DocumentedType, TypeRef } from '@webpieces/api-doc-model';\nimport { JsonObject, JsonValue } from '../json/JsonObject';\nimport { InlinedWrappers } from './InlinedWrappers';\nimport { SchemaPlacement } from './SchemaPlacement';\n\n/** ONE field the renderer could not give a shape to, and WHERE in the document it would have sat. */\nexport class UnmappedField {\n constructor(\n /** A JSON pointer into the document that would have been written. */\n readonly pointer: string,\n /** The verbatim TypeScript type text, so the cure names the thing to go and type. */\n readonly typeText: string,\n ) {}\n}\n\n/**\n * {@link TypeRef} / {@link DocumentedType} -> JSON Schema 2020-12, which IS OpenAPI 3.1's schema\n * dialect and IS what MCP `tools/list` speaks. That identity is the reason #982 specifies 3.1 rather\n * than 3.0: the two are not \"similar dialects\", they are the same schemas, so the MCP projection\n * (#984) is a selection and an inline pass, not a translation.\n *\n * ## Three things 3.1 lets this renderer state HONESTLY that 3.0 could not\n *\n * - `type: [T, \"null\"]` for a nullable field, instead of 3.0's `nullable: true` keyword, which is not\n * JSON Schema at all.\n * - `description` BESIDE a `$ref`. In 3.0 a sibling of `$ref` is ignored, so a documented field whose\n * type is a named DTO simply lost its prose.\n * - OPTIONAL and NULLABLE as separate facts — absent from `required` versus `\"null\"` in `type`. `{}`\n * and `{x: null}` are different wire documents and a schema that conflates them rejects one.\n *\n * ## It records what it cannot map rather than emitting an untyped field\n *\n * An unmapped type yields an EMPTY schema, which in JSON Schema means \"anything\". That is precisely\n * the green-build-publishes-a-shapeless-field defect the guard exists to stop, so every one is\n * recorded with the pointer it would have occupied and {@link OpenApiGenerator} refuses on the set.\n *\n * ## WHERE a schema is defined is the placement's answer, not this class's (#1058)\n *\n * The {@link SchemaPlacement} decides, per type, whether its schema is defined in THIS document's\n * `components.schemas` (and under which name) or referenced in another package's components\n * document. Every `$ref` — a field, an array item, a union branch, a discriminator `mapping` entry —\n * is written through it, so the split, the bundled and the MCP document are one renderer.\n *\n * ## A single-use request/response wrapper is written INLINE at its operation (#1303)\n *\n * {@link body} is how an operation asks for its request or success-response schema. A wrapper\n * {@link InlinedWrappers} names is rendered right there — `title` set to its published name, its\n * description, and `properties` even when empty — instead of as a `$ref`; it is never added to\n * `components.schemas`. It is recorded in {@link inlinedTypes} so the description guard still judges\n * it: inlining is never a way around a missing JSDoc.\n *\n * ## A `@hidden` field is never rendered into the customer document (#1246)\n *\n * With `dropsHiddenFields`, an object schema simply skips the field — its property, its prose, its\n * `required` entry — wherever that schema is written: a component, an inlined wrapper, a webhook\n * payload, a nested `$ref` target. Nothing is built and then removed.\n */\nexport class SchemaRenderer {\n private readonly reached = new Set<string>();\n private readonly inlined = new Set<string>();\n private readonly external = new Set<string>();\n private readonly unmappedFields: UnmappedField[] = [];\n\n constructor(\n /** The model's named types, by key (`DocumentedType.keyOf`). */\n private readonly types: ReadonlyMap<string, DocumentedType>,\n private readonly placement: SchemaPlacement,\n /** The wrappers an operation defines inline rather than by `$ref` (#1303). */\n private readonly wrappers: InlinedWrappers,\n /**\n * Omit every `@hidden` field (#1246) — the customer document alone. The field is never\n * rendered, so a type reached ONLY through it is never reached either: select-then-render,\n * exactly as for a hidden method (see `DocumentSelection`).\n */\n private readonly dropsHiddenFields: boolean,\n ) {}\n\n /** Keys of the named types this document DEFINES, reached directly or through another schema. */\n reachedTypes(): ReadonlySet<string> {\n return this.reached;\n }\n\n /** Keys of the wrappers this document defined INLINE at their one operation (#1303). */\n inlinedTypes(): ReadonlySet<string> {\n return this.inlined;\n }\n\n /** Keys of the named types this document REFERENCES in another package's components document. */\n externalTypes(): ReadonlySet<string> {\n return this.external;\n }\n\n /** Every field with no shape, with its pointer. Empty means the document is fully typed. */\n unmapped(): readonly UnmappedField[] {\n return this.unmappedFields;\n }\n\n /**\n * `components.schemas` for everything reachable from whatever has been rendered so far, expanded\n * to a FIXPOINT.\n *\n * A worklist and not recursion-with-a-guard because rendering a type reaches more types, and the\n * set has to close over that. It terminates for the same reason the extractor's walk does: a\n * named type is registered once, so the worklist strictly shrinks.\n */\n components(): JsonObject {\n const rendered = new Map<string, JsonObject | undefined>();\n let grew = true;\n while (grew) {\n grew = false;\n for (const key of Array.from(this.reached)) {\n const type = this.types.get(key);\n const name = type === undefined ? key : this.placement.localName(key, type);\n if (rendered.has(name)) {\n continue;\n }\n // Rendering it can add MORE names to `reached`, which is what the outer loop is for.\n rendered.set(\n name,\n type === undefined\n ? undefined\n : this.namedType(\n type,\n `#/components/schemas/${this.placement.localName(key, type)}`,\n ),\n );\n grew = true;\n }\n }\n const schemas = new JsonObject();\n // Alphabetical, because `components.schemas` is a lookup table and nothing reads it in order\n // — whereas discovery order would move every time an operation was added above another.\n for (const name of Array.from(rendered.keys()).sort()) {\n schemas.set(name, rendered.get(name));\n }\n return schemas;\n }\n\n /**\n * Mark `key` as DEFINED by this document even when nothing in it refers to the type — the\n * components document of a DTO library publishes every type the library exports (#1058).\n */\n define(key: string): void {\n const type = this.types.get(key);\n if (type !== undefined && this.placement.isLocal(key, type)) {\n this.reached.add(key);\n }\n }\n\n /**\n * An operation's request body or success-response schema: the wrapper itself, INLINE, when\n * {@link InlinedWrappers} names it — else exactly what {@link type} writes.\n *\n * The inline form is an object schema carrying `title` (the PUBLISHED name, which client\n * generators name the model from) and `properties` even when the class is empty, which a client\n * generator needs in order to emit an empty class rather than an untyped map.\n */\n body(ref: TypeRef, pointer: string): JsonObject {\n const key = ref.kind === 'ref' ? ref.refName! : undefined;\n const type = key === undefined ? undefined : this.types.get(key);\n if (key === undefined || type === undefined || !this.wrappers.has(key)) {\n return this.type(ref, pointer);\n }\n this.inlined.add(key);\n return this.objectType(type, pointer, type.schemaName);\n }\n\n /** One named type: an object DTO, a string enum, or a union with its DERIVED discriminator. */\n private namedType(type: DocumentedType, pointer: string): JsonObject {\n if (type.enumValues.length > 0) {\n return new JsonObject()\n .set('type', 'string')\n .set('description', this.prose(type.description))\n .set('enum', type.enumValues.slice());\n }\n if (type.unionRefNames.length > 0) {\n return this.union(type);\n }\n return this.objectType(type, pointer, undefined);\n }\n\n /**\n * An object DTO. `title` is set only on an INLINED wrapper, and then `properties` is written even\n * when empty (#1303); a component keeps its name as its key and omits an empty `properties`.\n */\n private objectType(type: DocumentedType, pointer: string, title: string | undefined): JsonObject {\n const properties = new JsonObject();\n const required: string[] = [];\n for (const field of type.fields) {\n if (this.dropsHiddenFields && field.hidden) {\n continue;\n }\n properties.set(field.name, this.field(field, `${pointer}/properties/${field.name}`));\n if (!field.optional) {\n required.push(field.name);\n }\n }\n return new JsonObject()\n .set('type', 'object')\n .set('title', title)\n .set('description', this.prose(type.description))\n .set('properties', properties.isEmpty() && title === undefined ? undefined : properties)\n .set('required', required.length === 0 ? undefined : required)\n .set(\n 'additionalProperties',\n type.indexSignatureValue === undefined\n ? undefined\n : this.type(type.indexSignatureValue, `${pointer}/additionalProperties`),\n );\n }\n\n /**\n * A union, with a `discriminator` ONLY when the model derived one — which it does only when every\n * branch carries the same property typed as string values (a literal, a string-enum member, or a\n * union of them) that no two branches share. An invented discriminator\n * would claim a narrowing TypeScript itself cannot do.\n */\n private union(type: DocumentedType): JsonObject {\n const branches: JsonValue[] = type.unionRefNames.map((name: string) =>\n this.reference(name),\n );\n const schema = new JsonObject()\n .set('description', this.prose(type.description))\n .set('oneOf', branches);\n if (type.discriminator === undefined) {\n return schema;\n }\n const mapping = new JsonObject();\n // EVERY value a branch's property may hold maps to that branch — `mode: 'a' | 'b'` is two\n // entries pointing at one schema, which OpenAPI's mapping allows (#1023).\n for (const branch of type.unionRefNames) {\n for (const value of type.discriminator.branchValues.get(branch) ?? []) {\n mapping.set(value, this.pointerTo(branch));\n }\n }\n return schema.set(\n 'discriminator',\n new JsonObject()\n .set('propertyName', type.discriminator.propertyName)\n .set('mapping', mapping),\n );\n }\n\n /**\n * One FIELD: its type, plus the prose and the constraints that hang off the field rather than the\n * type. `@format`, `@WpMin` and `@WpMax` land on the SCALAR — on an array, on the ITEM — because\n * `minimum` on an array means nothing and a reader would have to guess which half was meant.\n */\n field(field: DocumentedField, pointer: string): JsonObject {\n const isArray = field.type.kind === 'array';\n const leafPointer = isArray ? `${pointer}/items` : pointer;\n const leaf = this.constrain(\n isArray ? this.type(field.type.items!, leafPointer) : this.type(field.type, pointer),\n field,\n );\n const schema = isArray\n ? new JsonObject().set('type', 'array').set('items', leaf)\n : this.nullable(leaf, field.nullable);\n if (isArray && field.nullable) {\n return this.described(this.nullable(schema, true), field);\n }\n return this.described(schema, field);\n }\n\n /** `description`, and the `@mcp` override as `x-mcp-description` when the author wrote one. */\n private described(schema: JsonObject, field: DocumentedField): JsonObject {\n return schema\n .set('description', this.prose(field.description))\n .set('x-mcp-description', this.prose(field.mcpDescription));\n }\n\n private constrain(leaf: JsonObject, field: DocumentedField): JsonObject {\n return leaf.set('format', field.format).set('minimum', field.min).set('maximum', field.max);\n }\n\n /** `type: [T, \"null\"]` where there is a type to widen; `anyOf` where the shape is a `$ref`. */\n private nullable(schema: JsonObject, isNullable: boolean): JsonObject {\n if (!isNullable) {\n return schema;\n }\n const declared = schema.get('type');\n if (typeof declared === 'string') {\n const values = schema.get('enum');\n if (Array.isArray(values) && !values.includes(null)) {\n // `enum` is checked independently of `type`, so a nullable inline enum\n // (`'a' | 'b' | null`) must list `null` too or the document rejects it (#1197).\n schema.set('enum', [...values, null]);\n }\n return schema.set('type', [declared, 'null']);\n }\n return new JsonObject().set('anyOf', [schema, new JsonObject().set('type', 'null')]);\n }\n\n /** One resolved type, with no field-level prose or constraints on it. */\n type(ref: TypeRef, pointer: string): JsonObject {\n switch (ref.kind) {\n case 'primitive':\n return this.primitive(ref);\n case 'ref':\n return this.reference(ref.refName!);\n case 'array':\n return new JsonObject()\n .set('type', 'array')\n .set('items', this.type(ref.items!, `${pointer}/items`));\n case 'openMap':\n return new JsonObject()\n .set('type', 'object')\n .set(\n 'additionalProperties',\n this.type(ref.values!, `${pointer}/additionalProperties`),\n );\n case 'enum':\n return new JsonObject().set('type', 'string').set('enum', ref.enumValues.slice());\n case 'union':\n return this.namedUnion(ref);\n default:\n this.unmappedFields.push(\n new UnmappedField(pointer, ref.unmappedText ?? '<unknown>'),\n );\n return new JsonObject();\n }\n }\n\n /**\n * A union, as a `$ref` at the NAMED alias when the model registered one.\n *\n * The model records a `type X = A | B` alias as its own entry — carrying the DERIVED\n * discriminator — while the FIELD that used it holds a bare union of branch names. Rendering the\n * field's union inline would therefore publish the `oneOf` and silently drop the discriminator,\n * which is the one part of a union a client actually needs to narrow on. So the alias is looked\n * up by its branch list and referenced.\n */\n private namedUnion(ref: TypeRef): JsonObject {\n const branches = ref.unionRefNames.join(',');\n for (const name of Array.from(this.types.keys())) {\n if (this.types.get(name)!.unionRefNames.join(',') === branches) {\n return this.reference(name);\n }\n }\n return new JsonObject().set(\n 'oneOf',\n ref.unionRefNames.map((each: string) => this.reference(each)),\n );\n }\n\n private primitive(ref: TypeRef): JsonObject {\n if (ref.primitive === 'unknown') {\n // No `type` at all: JSON Schema's honest spelling of \"any shape\". It is only ever reached\n // by a `void` return, which is why it is not the unmapped refusal.\n return new JsonObject();\n }\n return new JsonObject().set('type', ref.integer ? 'integer' : ref.primitive!);\n }\n\n /**\n * A `$ref` to the type registered under `key`, recording whether this document defines it or\n * references it in its declaring package's components document.\n */\n private reference(key: string): JsonObject {\n return new JsonObject().set('$ref', this.pointerTo(key));\n }\n\n private pointerTo(key: string): string {\n const type = this.types.get(key);\n if (type === undefined) {\n // Not in the model at all (a manifest naming an error type that does not exist): keep it\n // local so `components()` writes the hole the guards then name.\n this.reached.add(key);\n return `#/components/schemas/${key}`;\n }\n if (this.placement.isLocal(key, type)) {\n this.reached.add(key);\n } else {\n this.external.add(key);\n }\n return this.placement.pointer(key, type);\n }\n\n /** Empty prose is ABSENT prose. An empty `description` key is noise in every rendered page. */\n private prose(text: string | undefined): string | undefined {\n return text === undefined || text.trim() === '' ? undefined : text;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SchemaRenderer.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/SchemaRenderer.ts"],"names":[],"mappings":";;;AACA,mDAA2D;AAI3D,qGAAqG;AACrG,MAAa,aAAa;IAGT;IAEA;IAJb;IACI,qEAAqE;IAC5D,OAAe;IACxB,qFAAqF;IAC5E,QAAgB;QAFhB,YAAO,GAAP,OAAO,CAAQ;QAEf,aAAQ,GAAR,QAAQ,CAAQ;IAC1B,CAAC;CACP;AAPD,sCAOC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAa,cAAc;IAQF;IACA;IAEA;IAMA;IAhBJ,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAC5B,OAAO,GAAG,IAAI,GAAG,EAAU,CAA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CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,+FAA+F;IACvF,KAAK,CAAC,IAAwB;QAClC,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IACvE,CAAC;CACJ;AAhVD,wCAgVC","sourcesContent":["import { DocumentedField, DocumentedType, TypeRef } from '@webpieces/api-doc-model';\nimport { JsonObject, JsonValue } from '../json/JsonObject';\nimport { InlinedWrappers } from './InlinedWrappers';\nimport { SchemaPlacement } from './SchemaPlacement';\n\n/** ONE field the renderer could not give a shape to, and WHERE in the document it would have sat. */\nexport class UnmappedField {\n constructor(\n /** A JSON pointer into the document that would have been written. */\n readonly pointer: string,\n /** The verbatim TypeScript type text, so the cure names the thing to go and type. */\n readonly typeText: string,\n ) {}\n}\n\n/**\n * {@link TypeRef} / {@link DocumentedType} -> JSON Schema 2020-12, which IS OpenAPI 3.1's schema\n * dialect and IS what MCP `tools/list` speaks. That identity is the reason #982 specifies 3.1 rather\n * than 3.0: the two are not \"similar dialects\", they are the same schemas, so the MCP projection\n * (#984) is a selection and an inline pass, not a translation.\n *\n * ## Three things 3.1 lets this renderer state HONESTLY that 3.0 could not\n *\n * - `type: [T, \"null\"]` for a nullable field, instead of 3.0's `nullable: true` keyword, which is not\n * JSON Schema at all.\n * - `description` BESIDE a `$ref`. In 3.0 a sibling of `$ref` is ignored, so a documented field whose\n * type is a named DTO simply lost its prose.\n * - OPTIONAL and NULLABLE as separate facts — absent from `required` versus `\"null\"` in `type`. `{}`\n * and `{x: null}` are different wire documents and a schema that conflates them rejects one.\n *\n * ## It records what it cannot map rather than emitting an untyped field\n *\n * An unmapped type yields an EMPTY schema, which in JSON Schema means \"anything\". That is precisely\n * the green-build-publishes-a-shapeless-field defect the guard exists to stop, so every one is\n * recorded with the pointer it would have occupied and {@link OpenApiGenerator} refuses on the set.\n *\n * ## WHERE a schema is defined is the placement's answer, not this class's (#1058)\n *\n * The {@link SchemaPlacement} decides, per type, whether its schema is defined in THIS document's\n * `components.schemas` (and under which name) or referenced in another package's components\n * document. Every `$ref` — a field, an array item, a union branch, a discriminator `mapping` entry —\n * is written through it, so the split, the bundled and the MCP document are one renderer.\n *\n * ## A single-use request/response wrapper is written INLINE at its operation (#1303)\n *\n * {@link body} is how an operation asks for its request or success-response schema. A wrapper\n * {@link InlinedWrappers} names is rendered right there — `title` set to its published name, its\n * description, and `properties` even when empty — instead of as a `$ref`; it is never added to\n * `components.schemas`. It is recorded in {@link inlinedTypes} so the description guard still judges\n * it: inlining is never a way around a missing JSDoc.\n *\n * ## A `@hidden` field is never rendered into the customer document (#1246)\n *\n * With `dropsHiddenFields`, an object schema simply skips the field — its property, its prose, its\n * `required` entry — wherever that schema is written: a component, an inlined wrapper, a webhook\n * payload, a nested `$ref` target. Nothing is built and then removed.\n */\nexport class SchemaRenderer {\n private readonly reached = new Set<string>();\n private readonly inlined = new Set<string>();\n private readonly external = new Set<string>();\n private readonly unmappedFields: UnmappedField[] = [];\n\n constructor(\n /** The model's named types, by key (`DocumentedType.keyOf`). */\n private readonly types: ReadonlyMap<string, DocumentedType>,\n private readonly placement: SchemaPlacement,\n /** The wrappers an operation defines inline rather than by `$ref` (#1303). */\n private readonly wrappers: InlinedWrappers,\n /**\n * Omit every `@hidden` field (#1246) — the customer document alone. The field is never\n * rendered, so a type reached ONLY through it is never reached either: select-then-render,\n * exactly as for a hidden method (see `DocumentSelection`).\n */\n private readonly dropsHiddenFields: boolean,\n ) {}\n\n /** Keys of the named types this document DEFINES, reached directly or through another schema. */\n reachedTypes(): ReadonlySet<string> {\n return this.reached;\n }\n\n /** Keys of the wrappers this document defined INLINE at their one operation (#1303). */\n inlinedTypes(): ReadonlySet<string> {\n return this.inlined;\n }\n\n /** Keys of the named types this document REFERENCES in another package's components document. */\n externalTypes(): ReadonlySet<string> {\n return this.external;\n }\n\n /** Every field with no shape, with its pointer. Empty means the document is fully typed. */\n unmapped(): readonly UnmappedField[] {\n return this.unmappedFields;\n }\n\n /**\n * `components.schemas` for everything reachable from whatever has been rendered so far, expanded\n * to a FIXPOINT.\n *\n * A worklist and not recursion-with-a-guard because rendering a type reaches more types, and the\n * set has to close over that. It terminates for the same reason the extractor's walk does: a\n * named type is registered once, so the worklist strictly shrinks.\n */\n components(): JsonObject {\n const rendered = new Map<string, JsonObject | undefined>();\n let grew = true;\n while (grew) {\n grew = false;\n for (const key of Array.from(this.reached)) {\n const type = this.types.get(key);\n const name = type === undefined ? key : this.placement.localName(key, type);\n if (rendered.has(name)) {\n continue;\n }\n // Rendering it can add MORE names to `reached`, which is what the outer loop is for.\n rendered.set(\n name,\n type === undefined\n ? undefined\n : this.namedType(\n type,\n `#/components/schemas/${this.placement.localName(key, type)}`,\n ),\n );\n grew = true;\n }\n }\n const schemas = new JsonObject();\n // Alphabetical, because `components.schemas` is a lookup table and nothing reads it in order\n // — whereas discovery order would move every time an operation was added above another.\n for (const name of Array.from(rendered.keys()).sort()) {\n schemas.set(name, rendered.get(name));\n }\n return schemas;\n }\n\n /**\n * Mark `key` as DEFINED by this document even when nothing in it refers to the type — the\n * components document of a DTO library publishes every type the library exports (#1058).\n */\n define(key: string): void {\n const type = this.types.get(key);\n if (type !== undefined && this.placement.isLocal(key, type)) {\n this.reached.add(key);\n }\n }\n\n /**\n * An operation's request body or success-response schema: the wrapper itself, INLINE, when\n * {@link InlinedWrappers} names it — else exactly what {@link type} writes.\n *\n * The inline form is an object schema carrying `title` (the PUBLISHED name, which client\n * generators name the model from) and `properties` even when the class is empty, which a client\n * generator needs in order to emit an empty class rather than an untyped map.\n */\n body(ref: TypeRef, pointer: string): JsonObject {\n const key = ref.kind === 'ref' ? ref.refName! : undefined;\n const type = key === undefined ? undefined : this.types.get(key);\n if (key === undefined || type === undefined || !this.wrappers.has(key)) {\n return this.type(ref, pointer);\n }\n this.inlined.add(key);\n return this.objectType(type, pointer, type.schemaName);\n }\n\n /** One named type: an object DTO, a string enum, or a union with its DERIVED discriminator. */\n private namedType(type: DocumentedType, pointer: string): JsonObject {\n if (type.enumValues.length > 0) {\n return new JsonObject()\n .set('type', 'string')\n .set('description', this.prose(type.description))\n .set('enum', type.enumValues.slice());\n }\n if (type.unionRefNames.length > 0) {\n return this.union(type);\n }\n return this.objectType(type, pointer, undefined);\n }\n\n /**\n * An object DTO. `title` is set only on an INLINED wrapper, and then `properties` is written even\n * when empty (#1303); a component keeps its name as its key and omits an empty `properties`.\n */\n private objectType(type: DocumentedType, pointer: string, title: string | undefined): JsonObject {\n const properties = new JsonObject();\n const required: string[] = [];\n for (const field of type.fields) {\n if (this.dropsHiddenFields && field.hidden) {\n continue;\n }\n properties.set(field.name, this.field(field, `${pointer}/properties/${field.name}`));\n if (!field.optional) {\n required.push(field.name);\n }\n }\n return new JsonObject()\n .set('type', 'object')\n .set('title', title)\n .set('description', this.prose(type.description))\n .set('properties', properties.isEmpty() && title === undefined ? undefined : properties)\n .set('required', required.length === 0 ? undefined : required)\n .set(\n 'additionalProperties',\n type.indexSignatureValue === undefined\n ? undefined\n : this.type(type.indexSignatureValue, `${pointer}/additionalProperties`),\n );\n }\n\n /**\n * A union, with a `discriminator` ONLY when the model derived one — which it does only when every\n * branch carries the same property typed as string values (a literal, a string-enum member, or a\n * union of them) that no two branches share. An invented discriminator\n * would claim a narrowing TypeScript itself cannot do.\n */\n private union(type: DocumentedType): JsonObject {\n const branches: JsonValue[] = type.unionRefNames.map((name: string) =>\n this.reference(name),\n );\n const schema = new JsonObject()\n .set('description', this.prose(type.description))\n .set('oneOf', branches);\n if (type.discriminator === undefined) {\n return schema;\n }\n const mapping = new JsonObject();\n // EVERY value a branch's property may hold maps to that branch — `mode: 'a' | 'b'` is two\n // entries pointing at one schema, which OpenAPI's mapping allows (#1023).\n for (const branch of type.unionRefNames) {\n for (const value of type.discriminator.branchValues.get(branch) ?? []) {\n mapping.set(value, this.pointerTo(branch));\n }\n }\n return schema.set(\n 'discriminator',\n new JsonObject()\n .set('propertyName', type.discriminator.propertyName)\n .set('mapping', mapping),\n );\n }\n\n /**\n * One FIELD: its type, plus the prose and the constraints that hang off the field rather than the\n * type. `@format`, `@WpMin` and `@WpMax` land on the SCALAR — on an array, on the ITEM — because\n * `minimum` on an array means nothing and a reader would have to guess which half was meant.\n */\n field(field: DocumentedField, pointer: string): JsonObject {\n const isArray = field.type.kind === 'array';\n const leafPointer = isArray ? `${pointer}/items` : pointer;\n const leaf = this.constrain(\n isArray ? this.type(field.type.items!, leafPointer) : this.type(field.type, pointer),\n field,\n );\n const schema = isArray\n ? new JsonObject().set('type', 'array').set('items', leaf)\n : this.nullable(leaf, field.nullable);\n if (isArray && field.nullable) {\n return this.described(this.nullable(schema, true), field);\n }\n return this.described(schema, field);\n }\n\n /** `description`, and the `@mcp` override as `x-mcp-description` when the author wrote one. */\n private described(schema: JsonObject, field: DocumentedField): JsonObject {\n return schema\n .set('description', this.prose(field.description))\n .set('x-mcp-description', this.prose(field.mcpDescription));\n }\n\n private constrain(leaf: JsonObject, field: DocumentedField): JsonObject {\n return leaf.set('format', field.format).set('minimum', field.min).set('maximum', field.max);\n }\n\n /** `type: [T, \"null\"]` where there is a type to widen; `anyOf` where the shape is a `$ref`. */\n private nullable(schema: JsonObject, isNullable: boolean): JsonObject {\n if (!isNullable) {\n return schema;\n }\n const declared = schema.get('type');\n if (typeof declared === 'string') {\n const values = schema.get('enum');\n if (Array.isArray(values) && !values.includes(null)) {\n // `enum` is checked independently of `type`, so a nullable inline enum\n // (`'a' | 'b' | null`) must list `null` too or the document rejects it (#1197).\n schema.set('enum', [...values, null]);\n }\n return schema.set('type', [declared, 'null']);\n }\n if (Array.isArray(declared)) {\n // A type that is already a LIST (`JsonValueDto`'s, #1447) gains `null` once, in place.\n return declared.includes('null') ? schema : schema.set('type', [...declared, 'null']);\n }\n return new JsonObject().set('anyOf', [schema, new JsonObject().set('type', 'null')]);\n }\n\n /** One resolved type, with no field-level prose or constraints on it. */\n type(ref: TypeRef, pointer: string): JsonObject {\n switch (ref.kind) {\n case 'primitive':\n return this.primitive(ref);\n case 'ref':\n return this.reference(ref.refName!);\n case 'array':\n return new JsonObject()\n .set('type', 'array')\n .set('items', this.type(ref.items!, `${pointer}/items`));\n case 'openMap':\n return new JsonObject()\n .set('type', 'object')\n .set(\n 'additionalProperties',\n this.type(ref.values!, `${pointer}/additionalProperties`),\n );\n case 'enum':\n return new JsonObject().set('type', 'string').set('enum', ref.enumValues.slice());\n case 'union':\n return this.namedUnion(ref);\n default:\n this.unmappedFields.push(\n new UnmappedField(pointer, ref.unmappedText ?? '<unknown>'),\n );\n return new JsonObject();\n }\n }\n\n /**\n * A union, as a `$ref` at the NAMED alias when the model registered one.\n *\n * The model records a `type X = A | B` alias as its own entry — carrying the DERIVED\n * discriminator — while the FIELD that used it holds a bare union of branch names. Rendering the\n * field's union inline would therefore publish the `oneOf` and silently drop the discriminator,\n * which is the one part of a union a client actually needs to narrow on. So the alias is looked\n * up by its branch list and referenced.\n */\n private namedUnion(ref: TypeRef): JsonObject {\n const branches = ref.unionRefNames.join(',');\n for (const name of Array.from(this.types.keys())) {\n if (this.types.get(name)!.unionRefNames.join(',') === branches) {\n return this.reference(name);\n }\n }\n return new JsonObject().set(\n 'oneOf',\n ref.unionRefNames.map((each: string) => this.reference(each)),\n );\n }\n\n private primitive(ref: TypeRef): JsonObject {\n if (ref.primitive === 'json') {\n // `JsonValueDto` (#1447): any JSON value, nested to any depth — the same open schema the\n // MCP catalogs publish, with `additionalProperties: true` stated rather than implied.\n return new JsonObject()\n .set('type', ['string', 'number', 'boolean', 'object', 'array', 'null'])\n .set('additionalProperties', true);\n }\n if (ref.primitive === 'unknown') {\n // No `type` at all: JSON Schema's honest spelling of \"any shape\". It is only ever reached\n // by a `void` return, which is why it is not the unmapped refusal.\n return new JsonObject();\n }\n return new JsonObject().set('type', ref.integer ? 'integer' : ref.primitive!);\n }\n\n /**\n * A `$ref` to the type registered under `key`, recording whether this document defines it or\n * references it in its declaring package's components document.\n */\n private reference(key: string): JsonObject {\n return new JsonObject().set('$ref', this.pointerTo(key));\n }\n\n private pointerTo(key: string): string {\n const type = this.types.get(key);\n if (type === undefined) {\n // Not in the model at all (a manifest naming an error type that does not exist): keep it\n // local so `components()` writes the hole the guards then name.\n this.reached.add(key);\n return `#/components/schemas/${key}`;\n }\n if (this.placement.isLocal(key, type)) {\n this.reached.add(key);\n } else {\n this.external.add(key);\n }\n return this.placement.pointer(key, type);\n }\n\n /** Empty prose is ABSENT prose. An empty `description` key is noise in every rendered page. */\n private prose(text: string | undefined): string | undefined {\n return text === undefined || text.trim() === '' ? undefined : text;\n }\n}\n"]}
|