@webpieces/openapi-generator 0.4.938 → 0.4.940

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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;Q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QACD,IAAI,CAAC,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"]}
@@ -35,6 +35,8 @@ import { ComponentsInputs, GeneratedDocument, GeneratedDocuments, GenerationInpu
35
35
  * schema with no JSDoc description ({@link UndocumentedSchemaGuard}) — each naming every offender in
36
36
  * one run (#1292). Likewise an operation with no valid `@summary` ({@link SummaryGuard}) and an MCP
37
37
  * tool whose name the Claude Connectors Directory would refuse ({@link McpToolNameGuard}) (#1296).
38
+ * And a JSDoc `{@link}` the document cannot publish under its target's published name
39
+ * ({@link DocLinkGuard}) (#1284).
38
40
  */
39
41
  export declare class OpenApiGenerator {
40
42
  private readonly security;
@@ -74,8 +76,20 @@ export declare class OpenApiGenerator {
74
76
  * the model, so the second pass reaches exactly what the first did.
75
77
  */
76
78
  private bundled;
79
+ /**
80
+ * Publish every `{@link}` in a rendered document under its target's name in THAT document (#1284),
81
+ * recording the ones it cannot name — see {@link DocLinkGuard}.
82
+ */
83
+ private resolveLinks;
77
84
  /** ONE document, from the operations this selection accepts and nothing else. */
78
85
  private render;
86
+ /** The operation renderer, carrying what this selection stamps on each operation. */
87
+ private operationRenderer;
88
+ /**
89
+ * The single-use request/response wrappers this document defines inline (#1303), counted over
90
+ * EVERY contract of the manifest so a wrapper is inline or a component in every document alike.
91
+ */
92
+ private wrappers;
79
93
  private renderSecuritySchemes;
80
94
  /** Same-named, different declarations in one package, across every contract a document reads. */
81
95
  private collisionsOf;
@@ -95,6 +109,8 @@ export declare class OpenApiGenerator {
95
109
  * published value cannot disagree.
96
110
  */
97
111
  private refuseDuplicateOperationIds;
112
+ /** `Contract.method` -> operationId, for every operation this document publishes. */
113
+ private publishedOperationIds;
98
114
  /**
99
115
  * FAIL CLOSED (#1058): every type this document references in another package must be a schema
100
116
  * of that package's published components document. A package that publishes none is refused —
@@ -5,6 +5,7 @@ const api_doc_model_1 = require("@webpieces/api-doc-model");
5
5
  const JsonObject_1 = require("../json/JsonObject");
6
6
  const OpenApiGenerationError_1 = require("../OpenApiGenerationError");
7
7
  const GenerationInputs_1 = require("./GenerationInputs");
8
+ const DocLinkGuard_1 = require("./DocLinkGuard");
8
9
  const DocumentSelection_1 = require("./DocumentSelection");
9
10
  const OperationRenderer_1 = require("./OperationRenderer");
10
11
  const SchemaPlacement_1 = require("./SchemaPlacement");
@@ -16,6 +17,7 @@ const SummaryGuard_1 = require("./SummaryGuard");
16
17
  const StackedJsDocGuard_1 = require("./StackedJsDocGuard");
17
18
  const TagOwnership_1 = require("./TagOwnership");
18
19
  const UndocumentedSchemaGuard_1 = require("./UndocumentedSchemaGuard");
20
+ const InlinedWrappers_1 = require("./InlinedWrappers");
19
21
  /** One rendered document, and the renderer that built its schemas — what it defined and referenced. */
20
22
  class RenderedDocument {
21
23
  document;
@@ -80,6 +82,8 @@ const OPENAPI_VERSION = '3.1.0';
80
82
  * schema with no JSDoc description ({@link UndocumentedSchemaGuard}) — each naming every offender in
81
83
  * one run (#1292). Likewise an operation with no valid `@summary` ({@link SummaryGuard}) and an MCP
82
84
  * tool whose name the Claude Connectors Directory would refuse ({@link McpToolNameGuard}) (#1296).
85
+ * And a JSDoc `{@link}` the document cannot publish under its target's published name
86
+ * ({@link DocLinkGuard}) (#1284).
83
87
  */
84
88
  class OpenApiGenerator {
85
89
  security = new SecurityDeriver_1.SecurityDeriver();
@@ -111,6 +115,7 @@ class OpenApiGenerator {
111
115
  // Collected across EVERY OpenAPI document of the run and refused once, after them all, so an
112
116
  // author is handed every undocumented schema at once rather than one document at a time.
113
117
  const undocumented = new UndocumentedSchemaGuard_1.UndocumentedSchemaGuard();
118
+ const links = new DocLinkGuard_1.DocLinkGuard();
114
119
  const documents = [];
115
120
  for (const selection of DocumentSelection_1.DocumentSelection.all()) {
116
121
  const contracts = inputs.contracts.filter((each) => selection.acceptsContract(each.model));
@@ -118,17 +123,22 @@ class OpenApiGenerator {
118
123
  continue;
119
124
  }
120
125
  if (selection.inlinesEveryPackage) {
121
- documents.push(new GenerationInputs_1.GeneratedDocument(selection.fileName, this.bundled(inputs, contracts, selection, undocumented)));
126
+ documents.push(new GenerationInputs_1.GeneratedDocument(selection.fileName, this.bundled(inputs, contracts, selection, links, undocumented)));
122
127
  continue;
123
128
  }
124
129
  this.refuseCollisions(this.collisionsOf(inputs, contracts), inputs.manifestPath);
125
- const split = this.render(inputs, contracts, selection, new SchemaPlacement_1.SplitPlacement(inputs.homePackage));
130
+ const placement = new SchemaPlacement_1.SplitPlacement(inputs.homePackage);
131
+ const split = this.render(inputs, contracts, selection, placement);
132
+ this.resolveLinks(links, split, inputs, contracts, selection, placement);
126
133
  this.refuseUnpublished(split.schemas, this.mergedTypes(inputs), inputs.upstream, selection.fileName, inputs.manifestPath);
127
134
  undocumented.collect(split.schemas.reachedTypes(), this.mergedTypes(inputs));
135
+ // An inlined wrapper is still a published schema, so it still needs its description.
136
+ undocumented.collect(split.schemas.inlinedTypes(), this.mergedTypes(inputs));
128
137
  documents.push(new GenerationInputs_1.GeneratedDocument(selection.fileName, split.document));
129
- documents.push(new GenerationInputs_1.GeneratedDocument(`${selection.fileName}${BUNDLED_SUFFIX}`, this.bundled(inputs, contracts, selection)));
138
+ documents.push(new GenerationInputs_1.GeneratedDocument(`${selection.fileName}${BUNDLED_SUFFIX}`, this.bundled(inputs, contracts, selection, links)));
130
139
  }
131
140
  undocumented.refuse(inputs.manifestPath);
141
+ links.refuse(inputs.manifestPath);
132
142
  return new GenerationInputs_1.GeneratedDocuments(documents);
133
143
  }
134
144
  /**
@@ -147,7 +157,7 @@ class OpenApiGenerator {
147
157
  const where = inputs.manifestPath;
148
158
  this.stackedJsDoc.refuse(model.stackedJsDoc, where);
149
159
  this.refuseCollisions(model.collisions, where);
150
- const schemas = new SchemaRenderer_1.SchemaRenderer(model.types, new SchemaPlacement_1.SplitPlacement(model.packageName));
160
+ const schemas = new SchemaRenderer_1.SchemaRenderer(model.types, new SchemaPlacement_1.SplitPlacement(model.packageName), InlinedWrappers_1.InlinedWrappers.none());
151
161
  for (const key of model.exported) {
152
162
  schemas.define(key);
153
163
  }
@@ -157,6 +167,9 @@ class OpenApiGenerator {
157
167
  const undocumented = new UndocumentedSchemaGuard_1.UndocumentedSchemaGuard();
158
168
  undocumented.collect(schemas.reachedTypes(), model.types);
159
169
  undocumented.refuse(where);
170
+ const links = new DocLinkGuard_1.DocLinkGuard();
171
+ links.resolve(rendered, new DocLinkGuard_1.DocumentLinkNaming(model.types, schemas, new SchemaPlacement_1.SplitPlacement(model.packageName), new Map()), COMPONENTS_DOCUMENT);
172
+ links.refuse(where);
160
173
  if (rendered.isEmpty()) {
161
174
  throw new OpenApiGenerationError_1.OpenApiGenerationError(`${model.packageName}'s entries export no type with a schema`, where, 'Name the entry files that export the library\'s DTOs and enums — usually "src/index.ts".');
162
175
  }
@@ -177,20 +190,33 @@ class OpenApiGenerator {
177
190
  * second renders with the names {@link BundledNames} assigns from it. Rendering is a pure walk of
178
191
  * the model, so the second pass reaches exactly what the first did.
179
192
  */
180
- bundled(inputs, contracts, selection, undocumented) {
193
+ bundled(inputs, contracts, selection, links, undocumented) {
194
+ // The discovery pass publishes nothing, so its links are not judged: the named pass below
195
+ // reaches exactly the same prose.
181
196
  const discovery = this.render(inputs, contracts, selection, new SchemaPlacement_1.DiscoveryPlacement());
182
197
  // The MCP projection inlines every type it reaches, from any package, so it is judged here
183
198
  // over that whole set (#1292). A split document's bundled sibling is not: each type in it is
184
199
  // judged by the document — or the components document — that defines it.
185
200
  undocumented?.collect(discovery.schemas.reachedTypes(), this.mergedTypes(inputs));
186
201
  const names = SchemaPlacement_1.BundledNames.assign(discovery.schemas.reachedTypes(), this.mergedTypes(inputs), inputs.homePackage);
187
- return this.render(inputs, contracts, selection, new SchemaPlacement_1.BundledPlacement(names)).document;
202
+ const placement = new SchemaPlacement_1.BundledPlacement(names);
203
+ const rendered = this.render(inputs, contracts, selection, placement);
204
+ this.resolveLinks(links, rendered, inputs, contracts, selection, placement);
205
+ return rendered.document;
206
+ }
207
+ /**
208
+ * Publish every `{@link}` in a rendered document under its target's name in THAT document (#1284),
209
+ * recording the ones it cannot name — see {@link DocLinkGuard}.
210
+ */
211
+ resolveLinks(links, rendered, inputs, contracts, selection, placement) {
212
+ const naming = new DocLinkGuard_1.DocumentLinkNaming(this.mergedTypes(inputs), rendered.schemas, placement, this.publishedOperationIds(contracts, selection, inputs));
213
+ links.resolve(rendered.document, naming, selection.fileName);
188
214
  }
189
215
  /** ONE document, from the operations this selection accepts and nothing else. */
190
216
  render(inputs, contracts, selection, placement) {
191
217
  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);
218
+ const schemas = new SchemaRenderer_1.SchemaRenderer(types, placement, this.wrappers(inputs, selection, types));
219
+ const operations = this.operationRenderer(inputs, selection, schemas);
194
220
  this.refuseDuplicateOperationIds(contracts, selection, operations, inputs.manifestPath);
195
221
  const apiKey = this.singleApiKey(inputs, contracts, selection);
196
222
  const schemeNames = inputs.manifest.securitySchemeNames;
@@ -224,6 +250,21 @@ class OpenApiGenerator {
224
250
  .set('components', components.orUndefined());
225
251
  return new RenderedDocument(document, schemas);
226
252
  }
253
+ /** The operation renderer, carrying what this selection stamps on each operation. */
254
+ operationRenderer(inputs, selection, schemas) {
255
+ return new OperationRenderer_1.OperationRenderer(schemas, selection.includeMcpExtensions, selection.internalNotice, selection.includeWebpiecesExtensions, inputs.manifest.operationIds);
256
+ }
257
+ /**
258
+ * The single-use request/response wrappers this document defines inline (#1303), counted over
259
+ * EVERY contract of the manifest so a wrapper is inline or a component in every document alike.
260
+ */
261
+ wrappers(inputs, selection, types) {
262
+ if (!selection.inlinesWrappers) {
263
+ return InlinedWrappers_1.InlinedWrappers.none();
264
+ }
265
+ const errorKey = inputs.errorType === undefined ? undefined : inputs.manifest.errors?.type;
266
+ return InlinedWrappers_1.InlinedWrappers.of(inputs.contracts, types, inputs.homePackage, errorKey);
267
+ }
227
268
  renderSecuritySchemes(inputs, contracts, selection, apiKey) {
228
269
  const schemes = apiKey === undefined
229
270
  ? new JsonObject_1.JsonObject()
@@ -287,6 +328,20 @@ class OpenApiGenerator {
287
328
  'manifest, which prefixes every id with its contract name (this renames every method ' +
288
329
  "in partners' generated clients).", duplicates);
289
330
  }
331
+ /** `Contract.method` -> operationId, for every operation this document publishes. */
332
+ publishedOperationIds(contracts, selection, inputs) {
333
+ const operationIds = new api_doc_model_1.OperationIds(inputs.manifest.operationIds);
334
+ const ids = new Map();
335
+ for (const contractModel of contracts) {
336
+ const model = contractModel.model;
337
+ for (const endpoint of model.endpoints) {
338
+ if (selection.acceptsEndpoint(endpoint)) {
339
+ ids.set(`${model.contractName}.${endpoint.methodName}`, operationIds.of(model.contractName, endpoint.methodName));
340
+ }
341
+ }
342
+ }
343
+ return ids;
344
+ }
290
345
  /**
291
346
  * FAIL CLOSED (#1058): every type this document references in another package must be a schema
292
347
  * of that package's published components document. A package that publishes none is refused —