@webpieces/openapi-generator 0.4.937 → 0.4.939

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/README.md CHANGED
@@ -223,6 +223,39 @@ one name meet, when the other package's is qualified (`myorg.lang-api-dtos.Local
223
223
  **`mcp-openapi.json` and the MCP tool catalogs never reference anything** — they inline every schema
224
224
  from any package, exactly as before, and require no components document anywhere.
225
225
 
226
+ ## Single-use request/response wrappers are inline (#1303)
227
+
228
+ A class used ONLY as one operation's request body or one operation's success response is written
229
+ inline at that operation instead of as `components.schemas.<Name>` + `$ref`:
230
+
231
+ ```json
232
+ "schema": {
233
+ "type": "object",
234
+ "title": "FetchReportCoverageRequest",
235
+ "description": "Which report's coverage to fetch.",
236
+ "properties": {}
237
+ }
238
+ ```
239
+
240
+ `title` is the published name, which client generators (openapi-generator, NSwag, Kiota) name the
241
+ inline model from, so a partner's SDK keeps `FetchOrdersRequest` rather than `FetchOrders200Response`.
242
+ An empty class keeps `"properties": {}`, which a client generator needs to emit an empty class.
243
+
244
+ "Only" is counted over every route and webhook of every contract in the manifest — not per document —
245
+ so a wrapper a public method shares with a hidden one stays a component in both. A wrapper used by two
246
+ or more operations, nested in any other schema, used as the error body, or declared in ANOTHER package
247
+ (which owns its schema in its own `components.openapi.json`) stays a component, as do enums, unions and
248
+ every shared noun. The split documents and their `*.bundled.json` siblings inline; `mcp-openapi.json`
249
+ keeps every wrapper a component. An inlined wrapper still needs its JSDoc description.
250
+
251
+ ## The public document carries no `x-webpieces-*` key (#1303)
252
+
253
+ `public-openapi.json` and `public-openapi.bundled.json` are the partner's contract, so they carry only
254
+ standard OpenAPI: a partner's authentication is `components.securitySchemes` + `security`, and a
255
+ webhook is an entry of `webhooks:`. `x-webpieces-authentication` — whose `arguments` are the TypeScript
256
+ identifiers passed to `@WpAuth`, private names a partner cannot use — and `x-webpieces-webhook` appear
257
+ in `full-private-openapi.json` and `mcp-openapi.json` only.
258
+
226
259
  ## MCP
227
260
 
228
261
  `MCP` in `@ApiType` requires `@WpMcpTool` on at least one method, and `@WpMcpTool` on a contract that
@@ -260,7 +293,7 @@ file. `--format` does not apply to them.
260
293
  | a method | `operation.description` (and the MCP tool's `description`, unless an `@mcp` tag overrides it) |
261
294
  | its `@summary` tag | `operation.summary` — the docs page heading and sidebar label — and the MCP tool's `title` and `annotations.title` (#1296) |
262
295
  | its `@returns` tag | the success response's `description`, and the MCP catalog's `outputSchema.description` |
263
- | a DTO class / interface / enum / union alias | `components.schemas.<Name>.description` (and the MCP catalog's `inputSchema.description` for the request DTO) |
296
+ | a DTO class / interface / enum / union alias | `components.schemas.<Name>.description` — or, for a single-use request/response wrapper, the inline body schema's `description` beside its `title` (#1303) — (and the MCP catalog's `inputSchema.description` for the request DTO) |
264
297
  | a field | the property's `description` |
265
298
  | the contract class that OWNS a tag | `tags[<tag>].description` |
266
299
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/openapi-generator",
3
- "version": "0.4.937",
3
+ "version": "0.4.939",
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.937",
27
- "@webpieces/core-util": "0.4.937",
26
+ "@webpieces/api-doc-model": "0.4.939",
27
+ "@webpieces/core-util": "0.4.939",
28
28
  "typescript": "5.9.3"
29
29
  },
30
30
  "bin": {
@@ -5,8 +5,10 @@ export declare const INTERNAL_ONLY_LINE = "INTERNAL \u2014 service-to-service us
5
5
  /**
6
6
  * The retry contract, published ONCE per document rather than as booleans stamped on every operation.
7
7
  *
8
- * Each operation's own `description` ends with one derived sentence saying whether it is safe to
9
- * retry; this table says where that sentence comes from. Three vendor-extension booleans per
8
+ * Each route's own `description` ends with one derived sentence saying whether it is safe to
9
+ * retry; this table says where that sentence comes from. Webhooks are excluded (#1302): the sentence
10
+ * tells a CALLER whether to repeat a call, and a webhook's caller is us — so a document holding only
11
+ * webhooks states no table at all (see {@link DocumentSelection.description}). Three vendor-extension booleans per
10
12
  * operation would have been invisible to a human — Swagger UI and most themes do not render `x-`
11
13
  * extensions, and no standard generator reads `x-webpieces-*` — and would have tripled golden churn
12
14
  * the day the mapping changed.
@@ -75,6 +77,20 @@ export declare class DocumentSelection {
75
77
  * `$ref` every other package's schema, and fail closed when that package publishes none.
76
78
  */
77
79
  readonly inlinesEveryPackage: boolean;
80
+ /**
81
+ * Define a single-use request/response wrapper INLINE at its operation, with its published
82
+ * name as `title`, rather than in `components.schemas` (#1303) — see `InlinedWrappers`. The
83
+ * split documents and their bundled siblings do; the MCP projection keeps every wrapper a
84
+ * component, unchanged.
85
+ */
86
+ readonly inlinesWrappers: boolean;
87
+ /**
88
+ * Stamp the `x-webpieces-*` operation extensions (`x-webpieces-authentication`,
89
+ * `x-webpieces-webhook`). False for the PUBLIC document alone (#1303): they carry source
90
+ * identifiers and internal tooling's facts, and everything a partner needs is already in the
91
+ * standard `security` / `securitySchemes` and `webhooks:` keys.
92
+ */
93
+ readonly includeWebpiecesExtensions: boolean;
78
94
  private constructor();
79
95
  /** Every contract declaring `SVC_TO_SVC` — which, by the fail-closed default, is every contract. */
80
96
  static internal(): DocumentSelection;
@@ -99,6 +115,11 @@ export declare class DocumentSelection {
99
115
  * than omitting it, because a reader would reasonably try to call it.
100
116
  */
101
117
  acceptsEndpoint(endpoint: DocumentedEndpoint): boolean;
102
- /** `info.description`: the manifest's prose, plus whatever this document adds to it. */
103
- description(manifestDescription: string | undefined): string | undefined;
118
+ /**
119
+ * `info.description`: the manifest's prose, plus whatever this document adds to it.
120
+ *
121
+ * `hasRoutes` is false when every operation in the document is a webhook. The retry table then
122
+ * describes a sentence no operation carries, so it is left out (#1302).
123
+ */
124
+ description(manifestDescription: string | undefined, hasRoutes: boolean): string | undefined;
104
125
  }
@@ -7,15 +7,18 @@ exports.INTERNAL_ONLY_LINE = 'INTERNAL — service-to-service use only. This doc
7
7
  /**
8
8
  * The retry contract, published ONCE per document rather than as booleans stamped on every operation.
9
9
  *
10
- * Each operation's own `description` ends with one derived sentence saying whether it is safe to
11
- * retry; this table says where that sentence comes from. Three vendor-extension booleans per
10
+ * Each route's own `description` ends with one derived sentence saying whether it is safe to
11
+ * retry; this table says where that sentence comes from. Webhooks are excluded (#1302): the sentence
12
+ * tells a CALLER whether to repeat a call, and a webhook's caller is us — so a document holding only
13
+ * webhooks states no table at all (see {@link DocumentSelection.description}). Three vendor-extension booleans per
12
14
  * operation would have been invisible to a human — Swagger UI and most themes do not render `x-`
13
15
  * extensions, and no standard generator reads `x-webpieces-*` — and would have tripled golden churn
14
16
  * the day the mapping changed.
15
17
  */
16
18
  exports.OPERATION_SEMANTICS = [
17
- "Every operation states whether it is safe to retry, derived from the endpoint's declared",
18
- 'side-effect contract:',
19
+ "Every route under `paths` states whether it is safe to retry, derived from the endpoint's",
20
+ 'declared side-effect contract. It covers routes only: a webhook is a call we send, and we',
21
+ 'retry its delivery ourselves, so a webhook carries no retry sentence.',
19
22
  '',
20
23
  '| declared operation | read-only | destructive | idempotent |',
21
24
  '|---|---|---|---|',
@@ -70,6 +73,8 @@ class DocumentSelection {
70
73
  includeMcpExtensions;
71
74
  internalNotice;
72
75
  inlinesEveryPackage;
76
+ inlinesWrappers;
77
+ includeWebpiecesExtensions;
73
78
  constructor(
74
79
  /** The file name this document is written to, and the name a failure uses for it. */
75
80
  fileName,
@@ -92,23 +97,39 @@ class DocumentSelection {
92
97
  * MCP-only consumer is not forced to tag anything. The other two documents are SPLIT — they
93
98
  * `$ref` every other package's schema, and fail closed when that package publishes none.
94
99
  */
95
- inlinesEveryPackage) {
100
+ inlinesEveryPackage,
101
+ /**
102
+ * Define a single-use request/response wrapper INLINE at its operation, with its published
103
+ * name as `title`, rather than in `components.schemas` (#1303) — see `InlinedWrappers`. The
104
+ * split documents and their bundled siblings do; the MCP projection keeps every wrapper a
105
+ * component, unchanged.
106
+ */
107
+ inlinesWrappers,
108
+ /**
109
+ * Stamp the `x-webpieces-*` operation extensions (`x-webpieces-authentication`,
110
+ * `x-webpieces-webhook`). False for the PUBLIC document alone (#1303): they carry source
111
+ * identifiers and internal tooling's facts, and everything a partner needs is already in the
112
+ * standard `security` / `securitySchemes` and `webhooks:` keys.
113
+ */
114
+ includeWebpiecesExtensions) {
96
115
  this.fileName = fileName;
97
116
  this.apiType = apiType;
98
117
  this.dropHidden = dropHidden;
99
118
  this.includeMcpExtensions = includeMcpExtensions;
100
119
  this.internalNotice = internalNotice;
101
120
  this.inlinesEveryPackage = inlinesEveryPackage;
121
+ this.inlinesWrappers = inlinesWrappers;
122
+ this.includeWebpiecesExtensions = includeWebpiecesExtensions;
102
123
  }
103
124
  /** Every contract declaring `SVC_TO_SVC` — which, by the fail-closed default, is every contract. */
104
125
  // webpieces-disable no-function-outside-class -- static factory; the private constructor is what stops a fourth, unnamed selection being invented at a call site
105
126
  static internal() {
106
- return new DocumentSelection('full-private-openapi', core_util_1.SVC_TO_SVC, false, false, true, false);
127
+ return new DocumentSelection('full-private-openapi', core_util_1.SVC_TO_SVC, false, false, true, false, true, true);
107
128
  }
108
129
  /** Every contract declaring `EXTERNAL_CUSTOMER`, minus its hidden methods. */
109
130
  // webpieces-disable no-function-outside-class -- static factory of this class
110
131
  static customer() {
111
- return new DocumentSelection('public-openapi', core_util_1.EXTERNAL_CUSTOMER, true, false, false, false);
132
+ return new DocumentSelection('public-openapi', core_util_1.EXTERNAL_CUSTOMER, true, false, false, false, true, false);
112
133
  }
113
134
  /**
114
135
  * Every contract declaring `MCP`. A HIDDEN method is kept — an internal endpoint that is an agent
@@ -117,7 +138,7 @@ class DocumentSelection {
117
138
  */
118
139
  // webpieces-disable no-function-outside-class -- static factory of this class
119
140
  static mcp() {
120
- return new DocumentSelection('mcp-openapi', core_util_1.MCP, false, true, false, true);
141
+ return new DocumentSelection('mcp-openapi', core_util_1.MCP, false, true, false, true, false, true);
121
142
  }
122
143
  /** Every document this generator knows how to write, in the order it writes them. */
123
144
  // webpieces-disable no-function-outside-class -- static factory of this class
@@ -146,8 +167,13 @@ class DocumentSelection {
146
167
  }
147
168
  return !this.dropHidden || !endpoint.hidden;
148
169
  }
149
- /** `info.description`: the manifest's prose, plus whatever this document adds to it. */
150
- description(manifestDescription) {
170
+ /**
171
+ * `info.description`: the manifest's prose, plus whatever this document adds to it.
172
+ *
173
+ * `hasRoutes` is false when every operation in the document is a webhook. The retry table then
174
+ * describes a sentence no operation carries, so it is left out (#1302).
175
+ */
176
+ description(manifestDescription, hasRoutes) {
151
177
  const parts = [];
152
178
  if (this.internalNotice) {
153
179
  parts.push(exports.INTERNAL_ONLY_LINE);
@@ -155,8 +181,10 @@ class DocumentSelection {
155
181
  if (manifestDescription !== undefined) {
156
182
  parts.push(manifestDescription);
157
183
  }
158
- parts.push(exports.OPERATION_SEMANTICS);
159
- return parts.join('\n\n');
184
+ if (hasRoutes) {
185
+ parts.push(exports.OPERATION_SEMANTICS);
186
+ }
187
+ return parts.length === 0 ? undefined : parts.join('\n\n');
160
188
  }
161
189
  }
162
190
  exports.DocumentSelection = DocumentSelection;
@@ -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;;;;;;;;GAQG;AACU,QAAA,mBAAmB,GAAG;IAC/B,0FAA0F;IAC1F,uBAAuB;IACvB,EAAE;IACF,+DAA+D;IAC/D,mBAAmB;IACnB,2BAA2B;IAC3B,uCAAuC;IACvC,2BAA2B;CAC9B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAC,QAAQ,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,wFAAwF;IACxF,WAAW,CAAC,mBAAuC;QAC/C,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,KAAK,CAAC,IAAI,CAAC,2BAAmB,CAAC,CAAC;QAChC,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACJ;AA1FD,8CA0FC","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 operation's own `description` ends with one derived sentence saying whether it is safe to\n * retry; this table says where that sentence comes from. 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 operation states whether it is safe to retry, derived from the endpoint's declared\",\n 'side-effect contract:',\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 * 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-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 /** Drop methods marked `{ hidden: true }`. True for the customer document alone. */\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\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('full-private-openapi', SVC_TO_SVC, false, false, true, false);\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('public-openapi', EXTERNAL_CUSTOMER, true, false, false, false);\n }\n\n /**\n * Every contract declaring `MCP`. A HIDDEN method is kept — 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);\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 /** `info.description`: the manifest's prose, plus whatever this document adds to it. */\n description(manifestDescription: string | undefined): 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 parts.push(OPERATION_SEMANTICS);\n return 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAa,iBAAiB;IAGb;IAEA;IAEA;IAEA;IAMA;IAQA;IAOA;IAOA;IApCb;IACI,qFAAqF;IAC5E,QAAgB;IACzB,yEAAyE;IAChE,OAAoB;IAC7B,oFAAoF;I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AC;IAED,eAAe,CAAC,KAAkB;QAC9B,OAAO,KAAK,CAAC,QAAQ,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;AAjID,8CAiIC","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 * 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-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 /** Drop methods marked `{ hidden: true }`. True for the customer document alone. */\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 — 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"]}
@@ -0,0 +1,34 @@
1
+ import { DocumentedType } from '@webpieces/api-doc-model';
2
+ import { ContractModel } from './GenerationInputs';
3
+ /**
4
+ * WHICH request/response wrappers an operation defines INLINE instead of in `components.schemas`
5
+ * (#1303).
6
+ *
7
+ * A `…Request` body or `…Response` reply belongs to its one method: it changes when that method
8
+ * changes, and nothing else may refer to it without tying two methods together. As a component it got
9
+ * a schema page of its own on the docs site that nothing linked to. So a wrapper is inlined at its
10
+ * operation — keeping `title: "<PublishedName>"`, which is what client generators (openapi-generator,
11
+ * NSwag, Kiota) name an inline model from — when ALL of these hold:
12
+ *
13
+ * - it is the TOP-LEVEL type of exactly ONE request body or ONE success response, counted over every
14
+ * operation of every contract in the manifest (routes and webhooks, every document — not per
15
+ * document: a wrapper two operations share is shared, whichever documents each lands in);
16
+ * - no named type in the model refers to it — as a field, an array item, a map value or a union
17
+ * branch — and it is not the manifest's error body;
18
+ * - it is an OBJECT (an enum or a union alias is a shared noun, not a wrapper);
19
+ * - it is declared in the document's OWN package. A type another package declares is defined by that
20
+ * package's `components.openapi.json` and referenced from here (#1058's one-owner rule); inlining it
21
+ * would define one schema in two documents.
22
+ *
23
+ * Everything else — a wrapper two operations share, one nested in another schema, every shared noun —
24
+ * stays a component exactly as before.
25
+ */
26
+ export declare class InlinedWrappers {
27
+ private readonly keys;
28
+ private constructor();
29
+ /** No wrapper is inlined — the MCP projection and a DTO library's components document. */
30
+ static none(): InlinedWrappers;
31
+ /** The wrappers of a manifest, by model key (`DocumentedType.keyOf`). */
32
+ static of(contracts: readonly ContractModel[], types: ReadonlyMap<string, DocumentedType>, homePackage: string | undefined, errorTypeKey: string | undefined): InlinedWrappers;
33
+ has(key: string): boolean;
34
+ }
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InlinedWrappers = void 0;
4
+ const SuccessBody_1 = require("./SuccessBody");
5
+ /**
6
+ * WHICH request/response wrappers an operation defines INLINE instead of in `components.schemas`
7
+ * (#1303).
8
+ *
9
+ * A `…Request` body or `…Response` reply belongs to its one method: it changes when that method
10
+ * changes, and nothing else may refer to it without tying two methods together. As a component it got
11
+ * a schema page of its own on the docs site that nothing linked to. So a wrapper is inlined at its
12
+ * operation — keeping `title: "<PublishedName>"`, which is what client generators (openapi-generator,
13
+ * NSwag, Kiota) name an inline model from — when ALL of these hold:
14
+ *
15
+ * - it is the TOP-LEVEL type of exactly ONE request body or ONE success response, counted over every
16
+ * operation of every contract in the manifest (routes and webhooks, every document — not per
17
+ * document: a wrapper two operations share is shared, whichever documents each lands in);
18
+ * - no named type in the model refers to it — as a field, an array item, a map value or a union
19
+ * branch — and it is not the manifest's error body;
20
+ * - it is an OBJECT (an enum or a union alias is a shared noun, not a wrapper);
21
+ * - it is declared in the document's OWN package. A type another package declares is defined by that
22
+ * package's `components.openapi.json` and referenced from here (#1058's one-owner rule); inlining it
23
+ * would define one schema in two documents.
24
+ *
25
+ * Everything else — a wrapper two operations share, one nested in another schema, every shared noun —
26
+ * stays a component exactly as before.
27
+ */
28
+ class InlinedWrappers {
29
+ keys;
30
+ constructor(keys) {
31
+ this.keys = keys;
32
+ }
33
+ /** No wrapper is inlined — the MCP projection and a DTO library's components document. */
34
+ // webpieces-disable no-function-outside-class -- static factory of this class
35
+ static none() {
36
+ return new InlinedWrappers(new Set());
37
+ }
38
+ /** The wrappers of a manifest, by model key (`DocumentedType.keyOf`). */
39
+ // webpieces-disable no-function-outside-class -- static factory of this class
40
+ static of(contracts, types, homePackage, errorTypeKey) {
41
+ const counter = new WrapperUseCounter(types);
42
+ counter.countOperations(contracts);
43
+ counter.countSchemas();
44
+ if (errorTypeKey !== undefined) {
45
+ counter.markNested(errorTypeKey);
46
+ }
47
+ return new InlinedWrappers(counter.singleUse(homePackage));
48
+ }
49
+ has(key) {
50
+ return this.keys.has(key);
51
+ }
52
+ }
53
+ exports.InlinedWrappers = InlinedWrappers;
54
+ /** The tally {@link InlinedWrappers.of} decides from: top-level uses per key, and every nested one. */
55
+ class WrapperUseCounter {
56
+ types;
57
+ topLevel = new Map();
58
+ nested = new Set();
59
+ body = new SuccessBody_1.SuccessBody();
60
+ constructor(types) {
61
+ this.types = types;
62
+ }
63
+ /**
64
+ * Every body an operation of any document can render: a POST's request (the only method a body is
65
+ * published for — see `OperationRenderer.requestBody`) and a non-void success response. A
66
+ * `@WpLocalOnly` endpoint is in no document, so it uses nothing.
67
+ */
68
+ countOperations(contracts) {
69
+ for (const contract of contracts) {
70
+ for (const endpoint of contract.model.endpoints) {
71
+ this.countEndpoint(endpoint);
72
+ }
73
+ }
74
+ }
75
+ /** Every reference one named type makes to another — which makes the target a shared noun. */
76
+ countSchemas() {
77
+ for (const type of Array.from(this.types.values())) {
78
+ for (const field of type.fields) {
79
+ this.walk(field.type);
80
+ }
81
+ if (type.indexSignatureValue !== undefined) {
82
+ this.walk(type.indexSignatureValue);
83
+ }
84
+ for (const branch of type.unionRefNames) {
85
+ this.markNested(branch);
86
+ }
87
+ }
88
+ }
89
+ markNested(key) {
90
+ this.nested.add(key);
91
+ }
92
+ singleUse(homePackage) {
93
+ const keys = new Set();
94
+ for (const key of Array.from(this.topLevel.keys())) {
95
+ const type = this.types.get(key);
96
+ if (this.topLevel.get(key) === 1 &&
97
+ !this.nested.has(key) &&
98
+ type !== undefined &&
99
+ type.packageName === homePackage &&
100
+ type.enumValues.length === 0 &&
101
+ type.unionRefNames.length === 0) {
102
+ keys.add(key);
103
+ }
104
+ }
105
+ return keys;
106
+ }
107
+ countEndpoint(endpoint) {
108
+ if (endpoint.localOnly) {
109
+ return;
110
+ }
111
+ if (endpoint.httpMethod === 'POST' && endpoint.request !== undefined) {
112
+ this.countBody(endpoint.request);
113
+ }
114
+ if (!this.body.isVoid(endpoint.response)) {
115
+ this.countBody(endpoint.response);
116
+ }
117
+ }
118
+ /** A body that IS a named type is a top-level use; anything else (`X[]`, a map) nests it. */
119
+ countBody(ref) {
120
+ if (ref.kind === 'ref') {
121
+ const key = ref.refName;
122
+ this.topLevel.set(key, (this.topLevel.get(key) ?? 0) + 1);
123
+ return;
124
+ }
125
+ this.walk(ref);
126
+ }
127
+ walk(ref) {
128
+ switch (ref.kind) {
129
+ case 'ref':
130
+ this.markNested(ref.refName);
131
+ return;
132
+ case 'array':
133
+ this.walk(ref.items);
134
+ return;
135
+ case 'openMap':
136
+ this.walk(ref.values);
137
+ return;
138
+ case 'union':
139
+ for (const branch of ref.unionRefNames) {
140
+ this.markNested(branch);
141
+ }
142
+ return;
143
+ default:
144
+ return;
145
+ }
146
+ }
147
+ }
148
+ //# sourceMappingURL=InlinedWrappers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InlinedWrappers.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/InlinedWrappers.ts"],"names":[],"mappings":";;;AAEA,+CAA4C;AAE5C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,eAAe;IACa;IAArC,YAAqC,IAAyB;QAAzB,SAAI,GAAJ,IAAI,CAAqB;IAAG,CAAC;IAElE,0FAA0F;IAC1F,8EAA8E;IAC9E,MAAM,CAAC,IAAI;QACP,OAAO,IAAI,eAAe,CAAC,IAAI,GAAG,EAAU,CAAC,CAAC;IAClD,CAAC;IAED,yEAAyE;IACzE,8EAA8E;IAC9E,MAAM,CAAC,EAAE,CACL,SAAmC,EACnC,KAA0C,EAC1C,WAA+B,EAC/B,YAAgC;QAEhC,MAAM,OAAO,GAAG,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAC7C,OAAO,CAA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,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAS,CAAC,CAAC;QACvC,CAAC;IACL,CAAC;IAED,6FAA6F;IACrF,SAAS,CAAC,GAAY;QAC1B,IAAI,GAAG,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YACrB,MAAM,GAAG,GAAG,GAAG,CAAC,OAAQ,CAAC;YACzB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC1D,OAAO;QACX,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IAEO,IAAI,CAAC,GAAY;QACrB,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC;YACf,KAAK,KAAK;gBACN,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAQ,CAAC,CAAC;gBAC9B,OAAO;YACX,KAAK,OAAO;gBACR,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAM,CAAC,CAAC;gBACtB,OAAO;YACX,KAAK,SAAS;gBACV,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAO,CAAC,CAAC;gBACvB,OAAO;YACX,KAAK,OAAO;gBACR,KAAK,MAAM,MAAM,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC;oBACrC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;gBAC5B,CAAC;gBACD,OAAO;YACX;gBACI,OAAO;QACf,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { DocumentedEndpoint, DocumentedType, TypeRef } from '@webpieces/api-doc-model';\nimport { ContractModel } from './GenerationInputs';\nimport { SuccessBody } from './SuccessBody';\n\n/**\n * WHICH request/response wrappers an operation defines INLINE instead of in `components.schemas`\n * (#1303).\n *\n * A `…Request` body or `…Response` reply belongs to its one method: it changes when that method\n * changes, and nothing else may refer to it without tying two methods together. As a component it got\n * a schema page of its own on the docs site that nothing linked to. So a wrapper is inlined at its\n * operation — keeping `title: \"<PublishedName>\"`, which is what client generators (openapi-generator,\n * NSwag, Kiota) name an inline model from — when ALL of these hold:\n *\n * - it is the TOP-LEVEL type of exactly ONE request body or ONE success response, counted over every\n * operation of every contract in the manifest (routes and webhooks, every document — not per\n * document: a wrapper two operations share is shared, whichever documents each lands in);\n * - no named type in the model refers to it — as a field, an array item, a map value or a union\n * branch — and it is not the manifest's error body;\n * - it is an OBJECT (an enum or a union alias is a shared noun, not a wrapper);\n * - it is declared in the document's OWN package. A type another package declares is defined by that\n * package's `components.openapi.json` and referenced from here (#1058's one-owner rule); inlining it\n * would define one schema in two documents.\n *\n * Everything else — a wrapper two operations share, one nested in another schema, every shared noun —\n * stays a component exactly as before.\n */\nexport class InlinedWrappers {\n private constructor(private readonly keys: ReadonlySet<string>) {}\n\n /** No wrapper is inlined — the MCP projection and a DTO library's components document. */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static none(): InlinedWrappers {\n return new InlinedWrappers(new Set<string>());\n }\n\n /** The wrappers of a manifest, by model key (`DocumentedType.keyOf`). */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static of(\n contracts: readonly ContractModel[],\n types: ReadonlyMap<string, DocumentedType>,\n homePackage: string | undefined,\n errorTypeKey: string | undefined,\n ): InlinedWrappers {\n const counter = new WrapperUseCounter(types);\n counter.countOperations(contracts);\n counter.countSchemas();\n if (errorTypeKey !== undefined) {\n counter.markNested(errorTypeKey);\n }\n return new InlinedWrappers(counter.singleUse(homePackage));\n }\n\n has(key: string): boolean {\n return this.keys.has(key);\n }\n}\n\n/** The tally {@link InlinedWrappers.of} decides from: top-level uses per key, and every nested one. */\nclass WrapperUseCounter {\n private readonly topLevel = new Map<string, number>();\n private readonly nested = new Set<string>();\n private readonly body = new SuccessBody();\n\n constructor(private readonly types: ReadonlyMap<string, DocumentedType>) {}\n\n /**\n * Every body an operation of any document can render: a POST's request (the only method a body is\n * published for — see `OperationRenderer.requestBody`) and a non-void success response. A\n * `@WpLocalOnly` endpoint is in no document, so it uses nothing.\n */\n countOperations(contracts: readonly ContractModel[]): void {\n for (const contract of contracts) {\n for (const endpoint of contract.model.endpoints) {\n this.countEndpoint(endpoint);\n }\n }\n }\n\n /** Every reference one named type makes to another — which makes the target a shared noun. */\n countSchemas(): void {\n for (const type of Array.from(this.types.values())) {\n for (const field of type.fields) {\n this.walk(field.type);\n }\n if (type.indexSignatureValue !== undefined) {\n this.walk(type.indexSignatureValue);\n }\n for (const branch of type.unionRefNames) {\n this.markNested(branch);\n }\n }\n }\n\n markNested(key: string): void {\n this.nested.add(key);\n }\n\n singleUse(homePackage: string | undefined): ReadonlySet<string> {\n const keys = new Set<string>();\n for (const key of Array.from(this.topLevel.keys())) {\n const type = this.types.get(key);\n if (\n this.topLevel.get(key) === 1 &&\n !this.nested.has(key) &&\n type !== undefined &&\n type.packageName === homePackage &&\n type.enumValues.length === 0 &&\n type.unionRefNames.length === 0\n ) {\n keys.add(key);\n }\n }\n return keys;\n }\n\n private countEndpoint(endpoint: DocumentedEndpoint): void {\n if (endpoint.localOnly) {\n return;\n }\n if (endpoint.httpMethod === 'POST' && endpoint.request !== undefined) {\n this.countBody(endpoint.request);\n }\n if (!this.body.isVoid(endpoint.response)) {\n this.countBody(endpoint.response!);\n }\n }\n\n /** A body that IS a named type is a top-level use; anything else (`X[]`, a map) nests it. */\n private countBody(ref: TypeRef): void {\n if (ref.kind === 'ref') {\n const key = ref.refName!;\n this.topLevel.set(key, (this.topLevel.get(key) ?? 0) + 1);\n return;\n }\n this.walk(ref);\n }\n\n private walk(ref: TypeRef): void {\n switch (ref.kind) {\n case 'ref':\n this.markNested(ref.refName!);\n return;\n case 'array':\n this.walk(ref.items!);\n return;\n case 'openMap':\n this.walk(ref.values!);\n return;\n case 'union':\n for (const branch of ref.unionRefNames) {\n this.markNested(branch);\n }\n return;\n default:\n return;\n }\n }\n}\n"]}
@@ -76,6 +76,13 @@ export declare class OpenApiGenerator {
76
76
  private bundled;
77
77
  /** ONE document, from the operations this selection accepts and nothing else. */
78
78
  private render;
79
+ /** The operation renderer, carrying what this selection stamps on each operation. */
80
+ private operationRenderer;
81
+ /**
82
+ * The single-use request/response wrappers this document defines inline (#1303), counted over
83
+ * EVERY contract of the manifest so a wrapper is inline or a component in every document alike.
84
+ */
85
+ private wrappers;
79
86
  private renderSecuritySchemes;
80
87
  /** Same-named, different declarations in one package, across every contract a document reads. */
81
88
  private collisionsOf;
@@ -16,6 +16,7 @@ const SummaryGuard_1 = require("./SummaryGuard");
16
16
  const StackedJsDocGuard_1 = require("./StackedJsDocGuard");
17
17
  const TagOwnership_1 = require("./TagOwnership");
18
18
  const UndocumentedSchemaGuard_1 = require("./UndocumentedSchemaGuard");
19
+ const InlinedWrappers_1 = require("./InlinedWrappers");
19
20
  /** One rendered document, and the renderer that built its schemas — what it defined and referenced. */
20
21
  class RenderedDocument {
21
22
  document;
@@ -125,6 +126,8 @@ class OpenApiGenerator {
125
126
  const split = this.render(inputs, contracts, selection, new SchemaPlacement_1.SplitPlacement(inputs.homePackage));
126
127
  this.refuseUnpublished(split.schemas, this.mergedTypes(inputs), inputs.upstream, selection.fileName, inputs.manifestPath);
127
128
  undocumented.collect(split.schemas.reachedTypes(), this.mergedTypes(inputs));
129
+ // An inlined wrapper is still a published schema, so it still needs its description.
130
+ undocumented.collect(split.schemas.inlinedTypes(), this.mergedTypes(inputs));
128
131
  documents.push(new GenerationInputs_1.GeneratedDocument(selection.fileName, split.document));
129
132
  documents.push(new GenerationInputs_1.GeneratedDocument(`${selection.fileName}${BUNDLED_SUFFIX}`, this.bundled(inputs, contracts, selection)));
130
133
  }
@@ -147,7 +150,7 @@ class OpenApiGenerator {
147
150
  const where = inputs.manifestPath;
148
151
  this.stackedJsDoc.refuse(model.stackedJsDoc, where);
149
152
  this.refuseCollisions(model.collisions, where);
150
- const schemas = new SchemaRenderer_1.SchemaRenderer(model.types, new SchemaPlacement_1.SplitPlacement(model.packageName));
153
+ const schemas = new SchemaRenderer_1.SchemaRenderer(model.types, new SchemaPlacement_1.SplitPlacement(model.packageName), InlinedWrappers_1.InlinedWrappers.none());
151
154
  for (const key of model.exported) {
152
155
  schemas.define(key);
153
156
  }
@@ -189,8 +192,8 @@ class OpenApiGenerator {
189
192
  /** ONE document, from the operations this selection accepts and nothing else. */
190
193
  render(inputs, contracts, selection, placement) {
191
194
  const types = this.mergedTypes(inputs);
192
- const schemas = new SchemaRenderer_1.SchemaRenderer(types, placement);
193
- const operations = new OperationRenderer_1.OperationRenderer(schemas, selection.includeMcpExtensions, selection.internalNotice, inputs.manifest.operationIds);
195
+ const schemas = new SchemaRenderer_1.SchemaRenderer(types, placement, this.wrappers(inputs, selection, types));
196
+ const operations = this.operationRenderer(inputs, selection, schemas);
194
197
  this.refuseDuplicateOperationIds(contracts, selection, operations, inputs.manifestPath);
195
198
  const apiKey = this.singleApiKey(inputs, contracts, selection);
196
199
  const schemeNames = inputs.manifest.securitySchemeNames;
@@ -215,7 +218,7 @@ class OpenApiGenerator {
215
218
  .set('headers', this.headers(inputs));
216
219
  const document = new JsonObject_1.JsonObject()
217
220
  .set('openapi', OPENAPI_VERSION)
218
- .set('info', this.info(inputs, selection))
221
+ .set('info', this.info(inputs, selection, !paths.isEmpty()))
219
222
  .set('servers', this.servers(inputs))
220
223
  .set('tags', this.tagList(tags, contracts))
221
224
  .set('security', hoisted === undefined ? undefined : hoisted.slice())
@@ -224,6 +227,21 @@ class OpenApiGenerator {
224
227
  .set('components', components.orUndefined());
225
228
  return new RenderedDocument(document, schemas);
226
229
  }
230
+ /** The operation renderer, carrying what this selection stamps on each operation. */
231
+ operationRenderer(inputs, selection, schemas) {
232
+ return new OperationRenderer_1.OperationRenderer(schemas, selection.includeMcpExtensions, selection.internalNotice, selection.includeWebpiecesExtensions, inputs.manifest.operationIds);
233
+ }
234
+ /**
235
+ * The single-use request/response wrappers this document defines inline (#1303), counted over
236
+ * EVERY contract of the manifest so a wrapper is inline or a component in every document alike.
237
+ */
238
+ wrappers(inputs, selection, types) {
239
+ if (!selection.inlinesWrappers) {
240
+ return InlinedWrappers_1.InlinedWrappers.none();
241
+ }
242
+ const errorKey = inputs.errorType === undefined ? undefined : inputs.manifest.errors?.type;
243
+ return InlinedWrappers_1.InlinedWrappers.of(inputs.contracts, types, inputs.homePackage, errorKey);
244
+ }
227
245
  renderSecuritySchemes(inputs, contracts, selection, apiKey) {
228
246
  const schemes = apiKey === undefined
229
247
  ? new JsonObject_1.JsonObject()
@@ -457,12 +475,12 @@ class OpenApiGenerator {
457
475
  return served;
458
476
  }
459
477
  /** `info`, whose `description` is the ONE piece of prose that differs between the documents. */
460
- info(inputs, selection) {
478
+ info(inputs, selection, hasRoutes) {
461
479
  return new JsonObject_1.JsonObject()
462
480
  .set('title', inputs.manifest.title)
463
481
  .set('summary', inputs.manifest.summary)
464
482
  .set('version', inputs.manifest.version)
465
- .set('description', selection.description(inputs.description));
483
+ .set('description', selection.description(inputs.description, hasRoutes));
466
484
  }
467
485
  servers(inputs) {
468
486
  if (inputs.manifest.servers.length === 0) {