@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.
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
 
@@ -269,6 +302,19 @@ and the `mcp-<Contract>-tools.json` catalogs — and each refusal names every of
269
302
  writes nothing. None has an off switch.
270
303
 
271
304
  - **`@privateRemarks` is dropped** with its text, everywhere. Write internal notes there.
305
+ - **`{@link X}` publishes X's PUBLISHED identity** as a markdown code span (#1284), in every output:
306
+
307
+ | JSDoc link | Published as (a markdown code span) |
308
+ |---|---|
309
+ | `{@link MenuDto}` | `` `Menu` `` — the type's published schema name, after `schemaNames` stripping (a bundled document's qualified name where it has one; an inlined single-use wrapper's `title`, #1303) |
310
+ | `{@link MenuDto.items}`, `{@link Gender.F}` | `` `Menu.items` ``, `` `Gender.F` `` — the `.member` tail kept as written |
311
+ | `{@link OrdersApi.fetchOrders}` | `` `fetchOrders` `` — its operationId in the manifest's `operationIds` style, never `OrdersApi.`; in an `mcp-<Contract>-tools.json` catalog, a method that IS a tool publishes its tool `name` |
312
+ | `{@link OrdersApi.fetchOrders \| the order list}` / `{@link X label}` | `the order list (`` `fetchOrders` ``)` — the label, then the identity |
313
+ | `{@link https://…}` / `{@link https://… \| label}` | `<https://…>` / `[label](https://…)` — an ordinary markdown link |
314
+
315
+ A link the compiler cannot resolve, one to something that is not a type or an `@Endpoint` method of
316
+ an `@ApiPath` contract, and one to a type or operation the document does not publish are refused,
317
+ naming every `file:line` in one run. `@webpieces/docs-site` links each such code span to its page.
272
318
  - **`@summary` is REQUIRED** on every published operation, route and webhook alike (#1296): one line,
273
319
  at most 100 characters. It is the endpoint's short title — the OpenAPI `summary` (which used to be
274
320
  the bare method name) and the MCP tool's `title` / `annotations.title` — and the tag and its text are
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/openapi-generator",
3
- "version": "0.4.938",
3
+ "version": "0.4.940",
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.938",
27
- "@webpieces/core-util": "0.4.938",
26
+ "@webpieces/api-doc-model": "0.4.940",
27
+ "@webpieces/core-util": "0.4.940",
28
28
  "typescript": "5.9.3"
29
29
  },
30
30
  "bin": {
@@ -104,7 +104,7 @@ class OpenApiCli {
104
104
  streamingCatalogs(inputs) {
105
105
  const artifacts = [];
106
106
  for (const contract of inputs.contracts) {
107
- const catalog = new api_doc_model_1.StreamingSchemaRenderer().render(contract.model);
107
+ const catalog = new api_doc_model_1.StreamingSchemaRenderer(new api_doc_model_1.OperationIds(inputs.manifest.operationIds)).render(contract.model);
108
108
  if (Object.keys(catalog.methods).length === 0)
109
109
  continue;
110
110
  artifacts.push(new ArtifactWriter_1.GeneratedArtifact(`stream-${catalog.contractName}-schemas.json`, JSON.stringify(catalog, null, 2) + '\n'));
@@ -149,7 +149,7 @@ class OpenApiCli {
149
149
  if (models.length === 0) {
150
150
  return new McpArtifacts([], []);
151
151
  }
152
- const rendered = api_doc_model_1.McpSchemaRenderer.catalogOf(models);
152
+ const rendered = api_doc_model_1.McpSchemaRenderer.catalogOf(models, new api_doc_model_1.OperationIds(inputs.manifest.operationIds));
153
153
  const artifacts = rendered.catalogs.map((catalog) => new ArtifactWriter_1.GeneratedArtifact(catalog.fileName, catalog.toJsonText()));
154
154
  return new McpArtifacts(artifacts, rendered.skipped);
155
155
  }
@@ -1 +1 @@
1
- {"version":3,"file":"OpenApiCli.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/cli/OpenApiCli.ts"],"names":[],"mappings":";;;;AAAA,wDAAkC;AAClC,oDAA+D;AAC/D,4DAKkC;AAClC,2DAAyF;AACzF,mEAAmG;AACnG,mEAAgE;AAChE,uDAAoD;AACpD,sEAAmE;AAEnE,MAAM,QAAQ,GAAG,YAAY,CAAC;AAC9B,MAAM,GAAG,GAAG,OAAO,CAAC;AACpB,MAAM,MAAM,GAAG,UAAU,CAAC;AAC1B,MAAM,IAAI,GAAG,QAAQ,CAAC;AAEtB,MAAM,KAAK,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;AACtC,MAAM,OAAO,GAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE/C,QAAA,KAAK,GAAG;IACjB,qFAAqF;IACrF,EAAE;IACF,6FAA6F;IAC7F,+FAA+F;IAC/F,EAAE;IACF,uFAAuF;IACvF,qGAAqG;IACrG,mFAAmF;IACnF,EAAE;IACF,8FAA8F;IAC9F,gGAAgG;IAChG,0BAA0B;IAC1B,EAAE;IACF,4FAA4F;IAC5F,+FAA+F;IAC/F,iGAAiG;IACjG,8FAA8F;IAC9F,EAAE;IACF,mGAAmG;IACnG,4FAA4F;IAC5F,EAAE;IACF,wFAAwF;IACxF,yDAAyD;IACzD,EAAE;IACF,4FAA4F;IAC5F,wFAAwF;CAC3F,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,yFAAyF;AACzF,MAAa,SAAS;IAEL;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,YAAY,EACZ,oBAAoB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAC5D,CAAC;YACN,CAAC;QACL,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AA3ID,gCA2IC","sourcesContent":["import * as path from 'node:path';\nimport { MCP, McpToolCatalogFile } from '@webpieces/core-util';\nimport {\n McpCatalogRender,\n McpSchemaRenderer,\n SkippedMcpTool,\n StreamingSchemaRenderer,\n} from '@webpieces/api-doc-model';\nimport { ArtifactWriter, GeneratedArtifact, OutputFormat } from '../emit/ArtifactWriter';\nimport { ContractModel, GeneratedDocuments, GenerationInputs } from '../generate/GenerationInputs';\nimport { OpenApiGenerator } from '../generate/OpenApiGenerator';\nimport { InputsLoader } from '../load/InputsLoader';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\n\nconst MANIFEST = '--manifest';\nconst OUT = '--out';\nconst FORMAT = '--format';\nconst HELP = '--help';\n\nconst FLAGS = [MANIFEST, OUT, FORMAT];\nconst FORMATS: readonly string[] = ['json', 'yaml', 'both'];\n\nexport const USAGE = [\n 'wp-openapi --manifest <openapi.manifest.json> --out <dir> [--format json|yaml|both]',\n '',\n 'Renders the contracts a manifest names into OpenAPI 3.1.0. WHICH documents are written is a',\n \"property of the contracts themselves — each one's @ApiType(...) names the documents it feeds:\",\n '',\n ' full-private-openapi every contract declaring SVC_TO_SVC, hidden methods included',\n ' public-openapi contracts declaring EXTERNAL_CUSTOMER, minus every { hidden: true } method',\n ' mcp-openapi contracts declaring MCP, carrying the x-mcp-* extensions',\n '',\n 'Alongside them, one mcp-<ContractClass>-tools.json is written per contract that declares MCP',\n 'and has an @WpMcpTool: the RUNTIME catalogs WpMcpServer boots from. They are not documents, so',\n '--format does not apply.',\n '',\n \"Those documents are SPLIT: a schema another package declares is a $ref into that package's\",\n 'components.openapi.json, and generation FAILS when that package publishes none. Each one also',\n 'gets a <name>.bundled.json sibling with every schema defined locally and no external reference.',\n 'mcp-openapi and the MCP tool catalogs stay fully inlined and require no components document.',\n '',\n 'A manifest declaring \"kind\": \"components\" is a DTO LIBRARY\\'s: it writes components.openapi.json,',\n 'every type its \"entries\" export, versioned as the package. It needs --format json or both.',\n '',\n 'A document no contract asked for is not written. --format chooses the serialization of',\n 'whichever documents were written, and defaults to both.',\n '',\n 'It exits non-zero, naming the JSON pointer of every offending field, rather than writing a',\n 'document containing a field it has no schema for. There is no flag to switch that off.',\n].join('\\n');\n\n/** The result of one run: what was written, so a caller can print it or assert on it. */\nexport class CliResult {\n constructor(\n readonly written: readonly string[],\n readonly artifacts: readonly GeneratedArtifact[],\n /** `@WpMcpTool`s the MCP catalog could not carry, with the reason. Never silent. */\n readonly skippedMcpTools: readonly SkippedMcpTool[] = [],\n ) {}\n}\n\n/** The MCP half of one run: the per-contract catalogs to write, and what they could not carry. */\nclass McpArtifacts {\n constructor(\n readonly artifacts: readonly GeneratedArtifact[],\n readonly skipped: readonly SkippedMcpTool[],\n ) {}\n}\n\n/**\n * `wp-openapi`'s argument parsing and composition, with NO process-level concerns in it — no\n * `process.exit`, no `console` — so the whole command is exercised by the suite exactly as a user\n * runs it. The bin is the only thing that knows about the process.\n *\n * `--manifest` and `--out` are REQUIRED and have no defaults. A defaulted `--out` writes generated\n * documents somewhere the caller did not name, and a defaulted `--manifest` picks a service out of\n * whatever directory the command happened to start in.\n */\nexport class OpenApiCli {\n private readonly loader = new InputsLoader();\n private readonly generator = new OpenApiGenerator();\n private readonly writer = new ArtifactWriter();\n\n /** @param argv the arguments AFTER the program name. @param cwd what relative paths resolve against. */\n run(argv: readonly string[], cwd: string): CliResult {\n const manifest = this.valueOf(argv, MANIFEST);\n const out = this.valueOf(argv, OUT);\n if (manifest === undefined || out === undefined) {\n throw new OpenApiGenerationError(\n `wp-openapi needs both ${MANIFEST} and ${OUT}`,\n 'wp-openapi',\n `Run: wp-openapi ${MANIFEST} <openapi.manifest.json> ${OUT} <dir>`,\n );\n }\n const manifestPath = path.resolve(cwd, manifest);\n if (this.loader.isComponents(manifestPath)) {\n return this.components(manifestPath, path.resolve(cwd, out), this.formatOf(argv));\n }\n const inputs = this.loader.load(manifestPath);\n const documents = this.generator.generate(inputs);\n const mcp = OpenApiCli.mcpCatalog(inputs);\n const artifacts = [\n ...this.writer.artifacts(documents, this.formatOf(argv)),\n ...mcp.artifacts,\n ...this.streamingCatalogs(inputs),\n ];\n return new CliResult(\n this.writer.write(path.resolve(cwd, out), artifacts),\n artifacts,\n mcp.skipped,\n );\n }\n\n private streamingCatalogs(inputs: GenerationInputs): readonly GeneratedArtifact[] {\n const artifacts: GeneratedArtifact[] = [];\n for (const contract of inputs.contracts) {\n const catalog = new StreamingSchemaRenderer().render(contract.model);\n if (Object.keys(catalog.methods).length === 0) continue;\n artifacts.push(\n new GeneratedArtifact(\n `stream-${catalog.contractName}-schemas.json`,\n JSON.stringify(catalog, null, 2) + '\\n',\n ),\n );\n }\n return artifacts;\n }\n\n /**\n * A DTO library's `components.openapi.json` (#1058). JSON is required: downstream documents `$ref`\n * it by that file name, so a YAML-only run would publish a library nothing can reference.\n */\n private components(manifestPath: string, outDir: string, format: OutputFormat): CliResult {\n if (format === 'yaml') {\n throw new OpenApiGenerationError(\n `${FORMAT} yaml writes no components.openapi.json`,\n manifestPath,\n `A components document is referenced by its .json name — use ${FORMAT} json or both.`,\n );\n }\n const inputs = this.loader.loadComponents(manifestPath);\n const document = this.generator.components(inputs);\n const artifacts = this.writer.artifacts(new GeneratedDocuments([document]), format);\n return new CliResult(this.writer.write(outDir, artifacts), artifacts);\n }\n\n wantsHelp(argv: readonly string[]): boolean {\n return argv.includes(HELP);\n }\n\n /**\n * `mcp-<ContractClass>-tools.json` — the RUNTIME artifacts, one per contract, beside the three\n * documents.\n *\n * They are not documents and are not serialized by `--format`: `WpMcpServer` boots from them, and\n * `McpToolRegistry` checks every `McpApiBinding` against the file generated from exactly that\n * contract, failing fast at boot when one is missing (#1021). That is what took the MCP runtime off\n * reflect-metadata (#984) — the schema an agent is shown and the schema the server accepts are now\n * the same bytes, rather than two derivations of one contract.\n *\n * Written only for a contract that declares `MCP` and has at least one renderable tool, which is\n * the same rule `mcp-openapi.json` follows, for the same reason: an empty file is a claim that there\n * are no tools.\n */\n // webpieces-disable no-function-outside-class -- private static composition step of this class\n private static mcpCatalog(inputs: GenerationInputs): McpArtifacts {\n const models = inputs.contracts\n .filter((contract: ContractModel) => contract.model.apiTypes.includes(MCP))\n .map((contract: ContractModel) => contract.model);\n if (models.length === 0) {\n return new McpArtifacts([], []);\n }\n const rendered: McpCatalogRender = McpSchemaRenderer.catalogOf(models);\n const artifacts = rendered.catalogs.map(\n (catalog: McpToolCatalogFile) =>\n new GeneratedArtifact(catalog.fileName, catalog.toJsonText()),\n );\n return new McpArtifacts(artifacts, rendered.skipped);\n }\n\n /** `both` unless told otherwise: the second serialization comes free from the same document. */\n private formatOf(argv: readonly string[]): OutputFormat {\n const declared = this.valueOf(argv, FORMAT);\n if (declared === undefined) {\n return 'both';\n }\n if (!FORMATS.includes(declared)) {\n throw new OpenApiGenerationError(\n `unknown ${FORMAT} '${declared}'`,\n 'wp-openapi',\n `${FORMAT} takes one of: ${FORMATS.join(', ')}.`,\n );\n }\n return declared as OutputFormat;\n }\n\n /**\n * The value after a flag. An UNKNOWN flag is refused rather than ignored: a mistyped `--manifets`\n * would otherwise fall through to \"needs both flags\", which sends the reader looking at the wrong\n * thing.\n */\n private valueOf(argv: readonly string[], flag: string): string | undefined {\n for (let i = 0; i < argv.length; i++) {\n const argument = argv[i]!;\n if (argument === flag) {\n return argv[i + 1];\n }\n if (argument.startsWith('--') && !FLAGS.includes(argument)) {\n throw new OpenApiGenerationError(\n `unknown flag '${argument}'`,\n 'wp-openapi',\n `wp-openapi takes ${FLAGS.join(', ')}, and nothing else.`,\n );\n }\n }\n return undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"OpenApiCli.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/cli/OpenApiCli.ts"],"names":[],"mappings":";;;;A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n McpCatalogRender,\n McpSchemaRenderer,\n OperationIds,\n SkippedMcpTool,\n StreamingSchemaRenderer,\n} from '@webpieces/api-doc-model';\nimport { ArtifactWriter, GeneratedArtifact, OutputFormat } from '../emit/ArtifactWriter';\nimport { ContractModel, GeneratedDocuments, GenerationInputs } from '../generate/GenerationInputs';\nimport { OpenApiGenerator } from '../generate/OpenApiGenerator';\nimport { InputsLoader } from '../load/InputsLoader';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\n\nconst MANIFEST = '--manifest';\nconst OUT = '--out';\nconst FORMAT = '--format';\nconst HELP = '--help';\n\nconst FLAGS = [MANIFEST, OUT, FORMAT];\nconst FORMATS: readonly string[] = ['json', 'yaml', 'both'];\n\nexport const USAGE = [\n 'wp-openapi --manifest <openapi.manifest.json> --out <dir> [--format json|yaml|both]',\n '',\n 'Renders the contracts a manifest names into OpenAPI 3.1.0. WHICH documents are written is a',\n \"property of the contracts themselves — each one's @ApiType(...) names the documents it feeds:\",\n '',\n ' full-private-openapi every contract declaring SVC_TO_SVC, hidden methods included',\n ' public-openapi contracts declaring EXTERNAL_CUSTOMER, minus every { hidden: true } method',\n ' mcp-openapi contracts declaring MCP, carrying the x-mcp-* extensions',\n '',\n 'Alongside them, one mcp-<ContractClass>-tools.json is written per contract that declares MCP',\n 'and has an @WpMcpTool: the RUNTIME catalogs WpMcpServer boots from. They are not documents, so',\n '--format does not apply.',\n '',\n \"Those documents are SPLIT: a schema another package declares is a $ref into that package's\",\n 'components.openapi.json, and generation FAILS when that package publishes none. Each one also',\n 'gets a <name>.bundled.json sibling with every schema defined locally and no external reference.',\n 'mcp-openapi and the MCP tool catalogs stay fully inlined and require no components document.',\n '',\n 'A manifest declaring \"kind\": \"components\" is a DTO LIBRARY\\'s: it writes components.openapi.json,',\n 'every type its \"entries\" export, versioned as the package. It needs --format json or both.',\n '',\n 'A document no contract asked for is not written. --format chooses the serialization of',\n 'whichever documents were written, and defaults to both.',\n '',\n 'It exits non-zero, naming the JSON pointer of every offending field, rather than writing a',\n 'document containing a field it has no schema for. There is no flag to switch that off.',\n].join('\\n');\n\n/** The result of one run: what was written, so a caller can print it or assert on it. */\nexport class CliResult {\n constructor(\n readonly written: readonly string[],\n readonly artifacts: readonly GeneratedArtifact[],\n /** `@WpMcpTool`s the MCP catalog could not carry, with the reason. Never silent. */\n readonly skippedMcpTools: readonly SkippedMcpTool[] = [],\n ) {}\n}\n\n/** The MCP half of one run: the per-contract catalogs to write, and what they could not carry. */\nclass McpArtifacts {\n constructor(\n readonly artifacts: readonly GeneratedArtifact[],\n readonly skipped: readonly SkippedMcpTool[],\n ) {}\n}\n\n/**\n * `wp-openapi`'s argument parsing and composition, with NO process-level concerns in it — no\n * `process.exit`, no `console` — so the whole command is exercised by the suite exactly as a user\n * runs it. The bin is the only thing that knows about the process.\n *\n * `--manifest` and `--out` are REQUIRED and have no defaults. A defaulted `--out` writes generated\n * documents somewhere the caller did not name, and a defaulted `--manifest` picks a service out of\n * whatever directory the command happened to start in.\n */\nexport class OpenApiCli {\n private readonly loader = new InputsLoader();\n private readonly generator = new OpenApiGenerator();\n private readonly writer = new ArtifactWriter();\n\n /** @param argv the arguments AFTER the program name. @param cwd what relative paths resolve against. */\n run(argv: readonly string[], cwd: string): CliResult {\n const manifest = this.valueOf(argv, MANIFEST);\n const out = this.valueOf(argv, OUT);\n if (manifest === undefined || out === undefined) {\n throw new OpenApiGenerationError(\n `wp-openapi needs both ${MANIFEST} and ${OUT}`,\n 'wp-openapi',\n `Run: wp-openapi ${MANIFEST} <openapi.manifest.json> ${OUT} <dir>`,\n );\n }\n const manifestPath = path.resolve(cwd, manifest);\n if (this.loader.isComponents(manifestPath)) {\n return this.components(manifestPath, path.resolve(cwd, out), this.formatOf(argv));\n }\n const inputs = this.loader.load(manifestPath);\n const documents = this.generator.generate(inputs);\n const mcp = OpenApiCli.mcpCatalog(inputs);\n const artifacts = [\n ...this.writer.artifacts(documents, this.formatOf(argv)),\n ...mcp.artifacts,\n ...this.streamingCatalogs(inputs),\n ];\n return new CliResult(\n this.writer.write(path.resolve(cwd, out), artifacts),\n artifacts,\n mcp.skipped,\n );\n }\n\n private streamingCatalogs(inputs: GenerationInputs): readonly GeneratedArtifact[] {\n const artifacts: GeneratedArtifact[] = [];\n for (const contract of inputs.contracts) {\n const catalog = new StreamingSchemaRenderer(\n new OperationIds(inputs.manifest.operationIds),\n ).render(contract.model);\n if (Object.keys(catalog.methods).length === 0) continue;\n artifacts.push(\n new GeneratedArtifact(\n `stream-${catalog.contractName}-schemas.json`,\n JSON.stringify(catalog, null, 2) + '\\n',\n ),\n );\n }\n return artifacts;\n }\n\n /**\n * A DTO library's `components.openapi.json` (#1058). JSON is required: downstream documents `$ref`\n * it by that file name, so a YAML-only run would publish a library nothing can reference.\n */\n private components(manifestPath: string, outDir: string, format: OutputFormat): CliResult {\n if (format === 'yaml') {\n throw new OpenApiGenerationError(\n `${FORMAT} yaml writes no components.openapi.json`,\n manifestPath,\n `A components document is referenced by its .json name — use ${FORMAT} json or both.`,\n );\n }\n const inputs = this.loader.loadComponents(manifestPath);\n const document = this.generator.components(inputs);\n const artifacts = this.writer.artifacts(new GeneratedDocuments([document]), format);\n return new CliResult(this.writer.write(outDir, artifacts), artifacts);\n }\n\n wantsHelp(argv: readonly string[]): boolean {\n return argv.includes(HELP);\n }\n\n /**\n * `mcp-<ContractClass>-tools.json` — the RUNTIME artifacts, one per contract, beside the three\n * documents.\n *\n * They are not documents and are not serialized by `--format`: `WpMcpServer` boots from them, and\n * `McpToolRegistry` checks every `McpApiBinding` against the file generated from exactly that\n * contract, failing fast at boot when one is missing (#1021). That is what took the MCP runtime off\n * reflect-metadata (#984) — the schema an agent is shown and the schema the server accepts are now\n * the same bytes, rather than two derivations of one contract.\n *\n * Written only for a contract that declares `MCP` and has at least one renderable tool, which is\n * the same rule `mcp-openapi.json` follows, for the same reason: an empty file is a claim that there\n * are no tools.\n */\n // webpieces-disable no-function-outside-class -- private static composition step of this class\n private static mcpCatalog(inputs: GenerationInputs): McpArtifacts {\n const models = inputs.contracts\n .filter((contract: ContractModel) => contract.model.apiTypes.includes(MCP))\n .map((contract: ContractModel) => contract.model);\n if (models.length === 0) {\n return new McpArtifacts([], []);\n }\n const rendered: McpCatalogRender = McpSchemaRenderer.catalogOf(\n models,\n new OperationIds(inputs.manifest.operationIds),\n );\n const artifacts = rendered.catalogs.map(\n (catalog: McpToolCatalogFile) =>\n new GeneratedArtifact(catalog.fileName, catalog.toJsonText()),\n );\n return new McpArtifacts(artifacts, rendered.skipped);\n }\n\n /** `both` unless told otherwise: the second serialization comes free from the same document. */\n private formatOf(argv: readonly string[]): OutputFormat {\n const declared = this.valueOf(argv, FORMAT);\n if (declared === undefined) {\n return 'both';\n }\n if (!FORMATS.includes(declared)) {\n throw new OpenApiGenerationError(\n `unknown ${FORMAT} '${declared}'`,\n 'wp-openapi',\n `${FORMAT} takes one of: ${FORMATS.join(', ')}.`,\n );\n }\n return declared as OutputFormat;\n }\n\n /**\n * The value after a flag. An UNKNOWN flag is refused rather than ignored: a mistyped `--manifets`\n * would otherwise fall through to \"needs both flags\", which sends the reader looking at the wrong\n * thing.\n */\n private valueOf(argv: readonly string[], flag: string): string | undefined {\n for (let i = 0; i < argv.length; i++) {\n const argument = argv[i]!;\n if (argument === flag) {\n return argv[i + 1];\n }\n if (argument.startsWith('--') && !FLAGS.includes(argument)) {\n throw new OpenApiGenerationError(\n `unknown flag '${argument}'`,\n 'wp-openapi',\n `wp-openapi takes ${FLAGS.join(', ')}, and nothing else.`,\n );\n }\n }\n return undefined;\n }\n}\n"]}
@@ -4,6 +4,8 @@ exports.ArtifactWriter = exports.GeneratedArtifact = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs = tslib_1.__importStar(require("node:fs"));
6
6
  const path = tslib_1.__importStar(require("node:path"));
7
+ const api_doc_model_1 = require("@webpieces/api-doc-model");
8
+ const OpenApiGenerationError_1 = require("../OpenApiGenerationError");
7
9
  const JsonWriter_1 = require("../json/JsonWriter");
8
10
  const YamlWriter_1 = require("../json/YamlWriter");
9
11
  /** One file this generation pass produces: its name, and its exact bytes. */
@@ -59,6 +61,13 @@ class ArtifactWriter {
59
61
  }
60
62
  /** Write them all, creating `outDir` if it does not exist. Returns the absolute paths written. */
61
63
  write(outDir, artifacts) {
64
+ // The backstop for #1284: a renderer that forgot to resolve a `{@link}` would publish its
65
+ // model encoding. Checked over the exact bytes, before ANY file is written.
66
+ const leaked = artifacts.filter((artifact) => api_doc_model_1.DocLinkText.hasLinks(artifact.text));
67
+ if (leaked.length > 0) {
68
+ throw new OpenApiGenerationError_1.OpenApiGenerationError(`${leaked.length} generated file(s) still carry an unresolved {@link}`, leaked.map((artifact) => artifact.fileName).join(', '), 'This is a wp-openapi defect, not a contract one: the renderer that wrote this ' +
69
+ 'file must resolve its prose with DocLinkText. Report it with the file named here.');
70
+ }
62
71
  fs.mkdirSync(outDir, { recursive: true });
63
72
  return artifacts.map((artifact) => {
64
73
  const file = path.join(outDir, artifact.fileName);
@@ -1 +1 @@
1
- {"version":3,"file":"ArtifactWriter.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/emit/ArtifactWriter.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAElC,mDAAgD;AAChD,mDAAgD;AAEhD,6EAA6E;AAC7E,MAAa,iBAAiB;IAEb;IACA;IAFb,YACa,QAAgB,EAChB,IAAY;QADZ,aAAQ,GAAR,QAAQ,CAAQ;QAChB,SAAI,GAAJ,IAAI,CAAQ;IACtB,CAAC;CACP;AALD,8CAKC;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,cAAc;IACN,IAAI,GAAG,IAAI,uBAAU,EAAE,CAAC;IACxB,IAAI,GAAG,IAAI,uBAAU,EAAE,CAAC;IAEzC,SAAS,CAAC,SAA6B,EAAE,MAAoB;QACzD,MAAM,SAAS,GAAwB,EAAE,CAAC;QAC1C,KAAK,MAAM,SAAS,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC;YAC1C,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;gBACpB,SAAS,CAAC,IAAI,CACV,IAAI,iBAAiB,CACjB,GAAG,SAAS,CAAC,QAAQ,OAAO,EAC5B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CACtC,CACJ,CAAC;YACN,CAAC;YACD,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;gBACpB,SAAS,CAAC,IAAI,CACV,IAAI,iBAAiB,CACjB,GAAG,SAAS,CAAC,QAAQ,OAAO,EAC5B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CACtC,CACJ,CAAC;YACN,CAAC;QACL,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,kGAAkG;IAClG,KAAK,CAAC,MAAc,EAAE,SAAuC;QACzD,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1C,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,QAA2B,EAAE,EAAE;YACjD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAClD,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC9C,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,kFAAkF;IAClF,WAAW,CAAC,SAA6B;QACrC,OAAO,SAAS,CAAC,SAAS,CAAC;IAC/B,CAAC;CACJ;AAzCD,wCAyCC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { GeneratedDocument, GeneratedDocuments } from '../generate/GenerationInputs';\nimport { JsonWriter } from '../json/JsonWriter';\nimport { YamlWriter } from '../json/YamlWriter';\n\n/** One file this generation pass produces: its name, and its exact bytes. */\nexport class GeneratedArtifact {\n constructor(\n readonly fileName: string,\n readonly text: string,\n ) {}\n}\n\n/** Which serializations to write. Orthogonal to WHICH documents `@ApiType` selected. */\nexport type OutputFormat = 'json' | 'yaml' | 'both';\n\n/**\n * The generated documents, serialized.\n *\n * | file | audience |\n * |---|---|\n * | `full-private-openapi.json` | internal. Every contract declaring `SVC_TO_SVC`, hidden methods included. Nothing renders it for humans |\n * | `public-openapi.json` | customers. Contracts declaring `EXTERNAL_CUSTOMER`, minus every `{ hidden: true }` method |\n * | `mcp-openapi.json` | agents. Contracts declaring `MCP`, carrying the `x-mcp-*` extensions |\n *\n * A document is written only when some contract declared its type, which is decided by the generator\n * — this class writes what it is given. `--format` then chooses `.json`, `.yaml` or both from the\n * SAME in-memory document, so the two serializations cannot disagree.\n *\n * ## Why the goldens commit JSON only\n *\n * Committing both would double the review surface every decorator change has to be diffed against,\n * for a second file that is the first one restated. One spec parses each emitted YAML and asserts\n * deep equality with its JSON counterpart instead, which proves the YAML is correct without asking\n * anybody to read it.\n *\n * ## Why the JSON documents ARE committed\n *\n * `diff full-private-openapi.json public-openapi.json` is the complete list of what these contracts\n * do not show a customer. That only works as a review device if both files are in the tree, so hiding\n * a method shows up as a diff in the PR that hides it.\n */\nexport class ArtifactWriter {\n private readonly json = new JsonWriter();\n private readonly yaml = new YamlWriter();\n\n artifacts(documents: GeneratedDocuments, format: OutputFormat): readonly GeneratedArtifact[] {\n const artifacts: GeneratedArtifact[] = [];\n for (const generated of documents.documents) {\n if (format !== 'yaml') {\n artifacts.push(\n new GeneratedArtifact(\n `${generated.fileName}.json`,\n this.json.write(generated.document),\n ),\n );\n }\n if (format !== 'json') {\n artifacts.push(\n new GeneratedArtifact(\n `${generated.fileName}.yaml`,\n this.yaml.write(generated.document),\n ),\n );\n }\n }\n return artifacts;\n }\n\n /** Write them all, creating `outDir` if it does not exist. Returns the absolute paths written. */\n write(outDir: string, artifacts: readonly GeneratedArtifact[]): readonly string[] {\n fs.mkdirSync(outDir, { recursive: true });\n return artifacts.map((artifact: GeneratedArtifact) => {\n const file = path.join(outDir, artifact.fileName);\n fs.writeFileSync(file, artifact.text, 'utf8');\n return file;\n });\n }\n\n /** The document objects, for a caller that wants them rather than their bytes. */\n documentsOf(documents: GeneratedDocuments): readonly GeneratedDocument[] {\n return documents.documents;\n }\n}\n"]}
1
+ {"version":3,"file":"ArtifactWriter.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/emit/ArtifactWriter.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAClC,4DAAuD;AAEvD,sEAAmE;AACnE,mDAAgD;AAChD,mDAAgD;AAEhD,6EAA6E;AAC7E,MAAa,iBAAiB;IAEb;IACA;IAFb,YACa,QAAgB,EAChB,IAAY;QADZ,aAAQ,GAAR,QAAQ,CAAQ;QAChB,SAAI,GAAJ,IAAI,CAAQ;IACtB,CAAC;CACP;AALD,8CAKC;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,cAAc;IACN,IAAI,GAAG,IAAI,uBAAU,EAAE,CAAC;IACxB,IAAI,GAAG,IAAI,uBAAU,EAAE,CAAC;IAEzC,SAAS,CAAC,SAA6B,EAAE,MAAoB;QACzD,MAAM,SAAS,GAAwB,EAAE,CAAC;QAC1C,KAAK,MAAM,SAAS,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC;YAC1C,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;gBACpB,SAAS,CAAC,IAAI,CACV,IAAI,iBAAiB,CACjB,GAAG,SAAS,CAAC,QAAQ,OAAO,EAC5B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CACtC,CACJ,CAAC;YACN,CAAC;YACD,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;gBACpB,SAAS,CAAC,IAAI,CACV,IAAI,iBAAiB,CACjB,GAAG,SAAS,CAAC,QAAQ,OAAO,EAC5B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CACtC,CACJ,CAAC;YACN,CAAC;QACL,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,kGAAkG;IAClG,KAAK,CAAC,MAAc,EAAE,SAAuC;QACzD,0FAA0F;QAC1F,4EAA4E;QAC5E,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,QAA2B,EAAE,EAAE,CAC5D,2BAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CACtC,CAAC;QACF,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,MAAM,IAAI,+CAAsB,CAC5B,GAAG,MAAM,CAAC,MAAM,sDAAsD,EACtE,MAAM,CAAC,GAAG,CAAC,CAAC,QAA2B,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EACzE,gFAAgF;gBAC5E,mFAAmF,CAC1F,CAAC;QACN,CAAC;QACD,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1C,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,QAA2B,EAAE,EAAE;YACjD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAClD,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC9C,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,kFAAkF;IAClF,WAAW,CAAC,SAA6B;QACrC,OAAO,SAAS,CAAC,SAAS,CAAC;IAC/B,CAAC;CACJ;AAtDD,wCAsDC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { DocLinkText } from '@webpieces/api-doc-model';\nimport { GeneratedDocument, GeneratedDocuments } from '../generate/GenerationInputs';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\nimport { JsonWriter } from '../json/JsonWriter';\nimport { YamlWriter } from '../json/YamlWriter';\n\n/** One file this generation pass produces: its name, and its exact bytes. */\nexport class GeneratedArtifact {\n constructor(\n readonly fileName: string,\n readonly text: string,\n ) {}\n}\n\n/** Which serializations to write. Orthogonal to WHICH documents `@ApiType` selected. */\nexport type OutputFormat = 'json' | 'yaml' | 'both';\n\n/**\n * The generated documents, serialized.\n *\n * | file | audience |\n * |---|---|\n * | `full-private-openapi.json` | internal. Every contract declaring `SVC_TO_SVC`, hidden methods included. Nothing renders it for humans |\n * | `public-openapi.json` | customers. Contracts declaring `EXTERNAL_CUSTOMER`, minus every `{ hidden: true }` method |\n * | `mcp-openapi.json` | agents. Contracts declaring `MCP`, carrying the `x-mcp-*` extensions |\n *\n * A document is written only when some contract declared its type, which is decided by the generator\n * — this class writes what it is given. `--format` then chooses `.json`, `.yaml` or both from the\n * SAME in-memory document, so the two serializations cannot disagree.\n *\n * ## Why the goldens commit JSON only\n *\n * Committing both would double the review surface every decorator change has to be diffed against,\n * for a second file that is the first one restated. One spec parses each emitted YAML and asserts\n * deep equality with its JSON counterpart instead, which proves the YAML is correct without asking\n * anybody to read it.\n *\n * ## Why the JSON documents ARE committed\n *\n * `diff full-private-openapi.json public-openapi.json` is the complete list of what these contracts\n * do not show a customer. That only works as a review device if both files are in the tree, so hiding\n * a method shows up as a diff in the PR that hides it.\n */\nexport class ArtifactWriter {\n private readonly json = new JsonWriter();\n private readonly yaml = new YamlWriter();\n\n artifacts(documents: GeneratedDocuments, format: OutputFormat): readonly GeneratedArtifact[] {\n const artifacts: GeneratedArtifact[] = [];\n for (const generated of documents.documents) {\n if (format !== 'yaml') {\n artifacts.push(\n new GeneratedArtifact(\n `${generated.fileName}.json`,\n this.json.write(generated.document),\n ),\n );\n }\n if (format !== 'json') {\n artifacts.push(\n new GeneratedArtifact(\n `${generated.fileName}.yaml`,\n this.yaml.write(generated.document),\n ),\n );\n }\n }\n return artifacts;\n }\n\n /** Write them all, creating `outDir` if it does not exist. Returns the absolute paths written. */\n write(outDir: string, artifacts: readonly GeneratedArtifact[]): readonly string[] {\n // The backstop for #1284: a renderer that forgot to resolve a `{@link}` would publish its\n // model encoding. Checked over the exact bytes, before ANY file is written.\n const leaked = artifacts.filter((artifact: GeneratedArtifact) =>\n DocLinkText.hasLinks(artifact.text),\n );\n if (leaked.length > 0) {\n throw new OpenApiGenerationError(\n `${leaked.length} generated file(s) still carry an unresolved {@link}`,\n leaked.map((artifact: GeneratedArtifact) => artifact.fileName).join(', '),\n 'This is a wp-openapi defect, not a contract one: the renderer that wrote this ' +\n 'file must resolve its prose with DocLinkText. Report it with the file named here.',\n );\n }\n fs.mkdirSync(outDir, { recursive: true });\n return artifacts.map((artifact: GeneratedArtifact) => {\n const file = path.join(outDir, artifact.fileName);\n fs.writeFileSync(file, artifact.text, 'utf8');\n return file;\n });\n }\n\n /** The document objects, for a caller that wants them rather than their bytes. */\n documentsOf(documents: GeneratedDocuments): readonly GeneratedDocument[] {\n return documents.documents;\n }\n}\n"]}
@@ -0,0 +1,46 @@
1
+ import { DocLink, DocLinkNaming, DocumentedType } from '@webpieces/api-doc-model';
2
+ import { JsonObject } from '../json/JsonObject';
3
+ import { SchemaPlacement } from './SchemaPlacement';
4
+ import { SchemaRenderer } from './SchemaRenderer';
5
+ /**
6
+ * How ONE rendered OpenAPI document names a `{@link}` target (#1284): a type by the name its schema
7
+ * carries in THIS document — the stripped schema name, or a bundled document's qualified one — and a
8
+ * contract method by its operationId. A target the document does not publish has no name here.
9
+ */
10
+ export declare class DocumentLinkNaming implements DocLinkNaming {
11
+ private readonly types;
12
+ private readonly schemas;
13
+ private readonly placement;
14
+ /** `Contract.method` -> operationId, for every operation the document publishes. */
15
+ private readonly operationIds;
16
+ constructor(types: ReadonlyMap<string, DocumentedType>, schemas: SchemaRenderer, placement: SchemaPlacement,
17
+ /** `Contract.method` -> operationId, for every operation the document publishes. */
18
+ operationIds: ReadonlyMap<string, string>);
19
+ publishedName(link: DocLink): string | undefined;
20
+ }
21
+ /**
22
+ * Resolves every `{@link}` in a rendered document, and REFUSES the ones it cannot name (#1284).
23
+ *
24
+ * A link is resolved AFTER the document is built, over every string in it, rather than at each place
25
+ * a description is written: prose reaches a document through a dozen slots — operation and schema
26
+ * descriptions, `@returns`, `@summary`, tag descriptions, `x-mcp-*` — and one walk cannot miss a slot
27
+ * the next change adds.
28
+ *
29
+ * ## Why an unnameable link is a refusal
30
+ *
31
+ * A link the compiler cannot resolve, or one to a type or operation this document does not publish,
32
+ * is the same silent leak #1284 was filed about: the prose names something a partner cannot find. So
33
+ * generation fails, naming every offender with its `file:line` in ONE run across every document — the
34
+ * same shape as the stacked-JSDoc and missing-`@returns` guards. A URL link is never one: it was
35
+ * written out as a markdown link at extraction.
36
+ */
37
+ export declare class DocLinkGuard {
38
+ /** By `location written`, so one link refused in several documents is named once. */
39
+ private readonly problems;
40
+ /** Resolve every string in `document` in place. */
41
+ resolve(document: JsonObject, naming: DocLinkNaming, fileName: string): void;
42
+ /** Refuse when any link of any document resolved so far could not be named. */
43
+ refuse(manifestPath: string): void;
44
+ private walkObject;
45
+ private walk;
46
+ }
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocLinkGuard = exports.DocumentLinkNaming = void 0;
4
+ const api_doc_model_1 = require("@webpieces/api-doc-model");
5
+ const JsonObject_1 = require("../json/JsonObject");
6
+ const OpenApiGenerationError_1 = require("../OpenApiGenerationError");
7
+ /**
8
+ * How ONE rendered OpenAPI document names a `{@link}` target (#1284): a type by the name its schema
9
+ * carries in THIS document — the stripped schema name, or a bundled document's qualified one — and a
10
+ * contract method by its operationId. A target the document does not publish has no name here.
11
+ */
12
+ class DocumentLinkNaming {
13
+ types;
14
+ schemas;
15
+ placement;
16
+ operationIds;
17
+ constructor(types, schemas, placement,
18
+ /** `Contract.method` -> operationId, for every operation the document publishes. */
19
+ operationIds) {
20
+ this.types = types;
21
+ this.schemas = schemas;
22
+ this.placement = placement;
23
+ this.operationIds = operationIds;
24
+ }
25
+ publishedName(link) {
26
+ if (link.kind === api_doc_model_1.DocLinkKind.OPERATION) {
27
+ return this.operationIds.get(`${link.owner}.${link.ownerName}`);
28
+ }
29
+ const type = this.types.get(link.owner);
30
+ if (link.kind !== api_doc_model_1.DocLinkKind.TYPE || type === undefined) {
31
+ return undefined;
32
+ }
33
+ // A single-use request/response wrapper is defined INLINE at its operation (#1303), with its
34
+ // published name as the schema's `title` — so the link names that title. No schema page
35
+ // exists for it, which a docs site sees because `components.schemas` has no entry.
36
+ if (this.schemas.inlinedTypes().has(link.owner)) {
37
+ return type.schemaName;
38
+ }
39
+ if (this.schemas.reachedTypes().has(link.owner)) {
40
+ return this.placement.localName(link.owner, type);
41
+ }
42
+ // A schema `$ref`d into another package's components document is published THERE, under
43
+ // its own schema name, so the reference is still a real one.
44
+ return this.schemas.externalTypes().has(link.owner) ? type.schemaName : undefined;
45
+ }
46
+ }
47
+ exports.DocumentLinkNaming = DocumentLinkNaming;
48
+ /**
49
+ * Resolves every `{@link}` in a rendered document, and REFUSES the ones it cannot name (#1284).
50
+ *
51
+ * A link is resolved AFTER the document is built, over every string in it, rather than at each place
52
+ * a description is written: prose reaches a document through a dozen slots — operation and schema
53
+ * descriptions, `@returns`, `@summary`, tag descriptions, `x-mcp-*` — and one walk cannot miss a slot
54
+ * the next change adds.
55
+ *
56
+ * ## Why an unnameable link is a refusal
57
+ *
58
+ * A link the compiler cannot resolve, or one to a type or operation this document does not publish,
59
+ * is the same silent leak #1284 was filed about: the prose names something a partner cannot find. So
60
+ * generation fails, naming every offender with its `file:line` in ONE run across every document — the
61
+ * same shape as the stacked-JSDoc and missing-`@returns` guards. A URL link is never one: it was
62
+ * written out as a markdown link at extraction.
63
+ */
64
+ class DocLinkGuard {
65
+ /** By `location written`, so one link refused in several documents is named once. */
66
+ problems = new Map();
67
+ /** Resolve every string in `document` in place. */
68
+ resolve(document, naming, fileName) {
69
+ const found = [];
70
+ this.walkObject(document, naming, `${fileName}.json`, found);
71
+ for (const problem of found) {
72
+ const key = `${problem.location} ${problem.written}`;
73
+ if (!this.problems.has(key)) {
74
+ this.problems.set(key, problem);
75
+ }
76
+ }
77
+ }
78
+ /** Refuse when any link of any document resolved so far could not be named. */
79
+ refuse(manifestPath) {
80
+ if (this.problems.size === 0) {
81
+ return;
82
+ }
83
+ throw new OpenApiGenerationError_1.OpenApiGenerationError(`${this.problems.size} {@link} reference(s) name nothing the generated document publishes`, manifestPath, 'Point each {@link} at a type the document publishes or an @Endpoint method of a ' +
84
+ 'contract it publishes, imported into the file the JSDoc is in — or write the name as ' +
85
+ "plain text. A link is published as the target's published name, so it must have one.", Array.from(this.problems.values()).map((each) => each.toString()));
86
+ }
87
+ walkObject(object, naming, output, found) {
88
+ for (const key of object.keys()) {
89
+ object.set(key, this.walk(object.get(key), naming, output, found));
90
+ }
91
+ }
92
+ walk(value, naming, output, found) {
93
+ if (typeof value === 'string') {
94
+ return api_doc_model_1.DocLinkText.hasLinks(value)
95
+ ? api_doc_model_1.DocLinkText.resolve(value, naming, output, found)
96
+ : value;
97
+ }
98
+ if (value instanceof JsonObject_1.JsonObject) {
99
+ this.walkObject(value, naming, output, found);
100
+ return value;
101
+ }
102
+ if (Array.isArray(value)) {
103
+ return value.map((each) => this.walk(each, naming, output, found));
104
+ }
105
+ return value;
106
+ }
107
+ }
108
+ exports.DocLinkGuard = DocLinkGuard;
109
+ //# sourceMappingURL=DocLinkGuard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DocLinkGuard.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/DocLinkGuard.ts"],"names":[],"mappings":";;;AAAA,4DAOkC;AAClC,mDAA2D;AAC3D,sEAAmE;AAInE;;;;GAIG;AACH,MAAa,kBAAkB;IAEN;IACA;IACA;IAEA;IALrB,YACqB,KAA0C,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C9B,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAE,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QACxE,CAAC;IACL,CAAC;IAEO,IAAI,CACR,KAAgB,EAChB,MAAqB,EACrB,MAAc,EACd,KAAuB;QAEvB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO,2BAAW,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAC9B,CAAC,CAAC,2BAAW,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC;gBACnD,CAAC,CAAC,KAAK,CAAC;QAChB,CAAC;QACD,IAAI,KAAK,YAAY,uBAAU,EAAE,CAAC;YAC9B,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;YAC9C,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAe,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QAClF,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AA9DD,oCA8DC","sourcesContent":["import {\n DocLink,\n DocLinkKind,\n DocLinkNaming,\n DocLinkProblem,\n DocLinkText,\n DocumentedType,\n} from '@webpieces/api-doc-model';\nimport { JsonObject, JsonValue } from '../json/JsonObject';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\nimport { SchemaPlacement } from './SchemaPlacement';\nimport { SchemaRenderer } from './SchemaRenderer';\n\n/**\n * How ONE rendered OpenAPI document names a `{@link}` target (#1284): a type by the name its schema\n * carries in THIS document — the stripped schema name, or a bundled document's qualified one — and a\n * contract method by its operationId. A target the document does not publish has no name here.\n */\nexport class DocumentLinkNaming implements DocLinkNaming {\n constructor(\n private readonly types: ReadonlyMap<string, DocumentedType>,\n private readonly schemas: SchemaRenderer,\n private readonly placement: SchemaPlacement,\n /** `Contract.method` -> operationId, for every operation the document publishes. */\n private readonly operationIds: ReadonlyMap<string, string>,\n ) {}\n\n publishedName(link: DocLink): string | undefined {\n if (link.kind === DocLinkKind.OPERATION) {\n return this.operationIds.get(`${link.owner}.${link.ownerName}`);\n }\n const type = this.types.get(link.owner);\n if (link.kind !== DocLinkKind.TYPE || type === undefined) {\n return undefined;\n }\n // A single-use request/response wrapper is defined INLINE at its operation (#1303), with its\n // published name as the schema's `title` — so the link names that title. No schema page\n // exists for it, which a docs site sees because `components.schemas` has no entry.\n if (this.schemas.inlinedTypes().has(link.owner)) {\n return type.schemaName;\n }\n if (this.schemas.reachedTypes().has(link.owner)) {\n return this.placement.localName(link.owner, type);\n }\n // A schema `$ref`d into another package's components document is published THERE, under\n // its own schema name, so the reference is still a real one.\n return this.schemas.externalTypes().has(link.owner) ? type.schemaName : undefined;\n }\n}\n\n/**\n * Resolves every `{@link}` in a rendered document, and REFUSES the ones it cannot name (#1284).\n *\n * A link is resolved AFTER the document is built, over every string in it, rather than at each place\n * a description is written: prose reaches a document through a dozen slots — operation and schema\n * descriptions, `@returns`, `@summary`, tag descriptions, `x-mcp-*` — and one walk cannot miss a slot\n * the next change adds.\n *\n * ## Why an unnameable link is a refusal\n *\n * A link the compiler cannot resolve, or one to a type or operation this document does not publish,\n * is the same silent leak #1284 was filed about: the prose names something a partner cannot find. So\n * generation fails, naming every offender with its `file:line` in ONE run across every document — the\n * same shape as the stacked-JSDoc and missing-`@returns` guards. A URL link is never one: it was\n * written out as a markdown link at extraction.\n */\nexport class DocLinkGuard {\n /** By `location written`, so one link refused in several documents is named once. */\n private readonly problems = new Map<string, DocLinkProblem>();\n\n /** Resolve every string in `document` in place. */\n resolve(document: JsonObject, naming: DocLinkNaming, fileName: string): void {\n const found: DocLinkProblem[] = [];\n this.walkObject(document, naming, `${fileName}.json`, found);\n for (const problem of found) {\n const key = `${problem.location} ${problem.written}`;\n if (!this.problems.has(key)) {\n this.problems.set(key, problem);\n }\n }\n }\n\n /** Refuse when any link of any document resolved so far could not be named. */\n refuse(manifestPath: string): void {\n if (this.problems.size === 0) {\n return;\n }\n throw new OpenApiGenerationError(\n `${this.problems.size} {@link} reference(s) name nothing the generated document publishes`,\n manifestPath,\n 'Point each {@link} at a type the document publishes or an @Endpoint method of a ' +\n 'contract it publishes, imported into the file the JSDoc is in — or write the name as ' +\n \"plain text. A link is published as the target's published name, so it must have one.\",\n Array.from(this.problems.values()).map((each: DocLinkProblem) => each.toString()),\n );\n }\n\n private walkObject(\n object: JsonObject,\n naming: DocLinkNaming,\n output: string,\n found: DocLinkProblem[],\n ): void {\n for (const key of object.keys()) {\n object.set(key, this.walk(object.get(key)!, naming, output, found));\n }\n }\n\n private walk(\n value: JsonValue,\n naming: DocLinkNaming,\n output: string,\n found: DocLinkProblem[],\n ): JsonValue {\n if (typeof value === 'string') {\n return DocLinkText.hasLinks(value)\n ? DocLinkText.resolve(value, naming, output, found)\n : value;\n }\n if (value instanceof JsonObject) {\n this.walkObject(value, naming, output, found);\n return value;\n }\n if (Array.isArray(value)) {\n return value.map((each: JsonValue) => this.walk(each, naming, output, found));\n }\n return value;\n }\n}\n"]}
@@ -77,6 +77,20 @@ export declare class DocumentSelection {
77
77
  * `$ref` every other package's schema, and fail closed when that package publishes none.
78
78
  */
79
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;
80
94
  private constructor();
81
95
  /** Every contract declaring `SVC_TO_SVC` — which, by the fail-closed default, is every contract. */
82
96
  static internal(): DocumentSelection;
@@ -73,6 +73,8 @@ class DocumentSelection {
73
73
  includeMcpExtensions;
74
74
  internalNotice;
75
75
  inlinesEveryPackage;
76
+ inlinesWrappers;
77
+ includeWebpiecesExtensions;
76
78
  constructor(
77
79
  /** The file name this document is written to, and the name a failure uses for it. */
78
80
  fileName,
@@ -95,23 +97,39 @@ class DocumentSelection {
95
97
  * MCP-only consumer is not forced to tag anything. The other two documents are SPLIT — they
96
98
  * `$ref` every other package's schema, and fail closed when that package publishes none.
97
99
  */
98
- 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) {
99
115
  this.fileName = fileName;
100
116
  this.apiType = apiType;
101
117
  this.dropHidden = dropHidden;
102
118
  this.includeMcpExtensions = includeMcpExtensions;
103
119
  this.internalNotice = internalNotice;
104
120
  this.inlinesEveryPackage = inlinesEveryPackage;
121
+ this.inlinesWrappers = inlinesWrappers;
122
+ this.includeWebpiecesExtensions = includeWebpiecesExtensions;
105
123
  }
106
124
  /** Every contract declaring `SVC_TO_SVC` — which, by the fail-closed default, is every contract. */
107
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
108
126
  static internal() {
109
- 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);
110
128
  }
111
129
  /** Every contract declaring `EXTERNAL_CUSTOMER`, minus its hidden methods. */
112
130
  // webpieces-disable no-function-outside-class -- static factory of this class
113
131
  static customer() {
114
- 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);
115
133
  }
116
134
  /**
117
135
  * Every contract declaring `MCP`. A HIDDEN method is kept — an internal endpoint that is an agent
@@ -120,7 +138,7 @@ class DocumentSelection {
120
138
  */
121
139
  // webpieces-disable no-function-outside-class -- static factory of this class
122
140
  static mcp() {
123
- 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);
124
142
  }
125
143
  /** Every document this generator knows how to write, in the order it writes them. */
126
144
  // webpieces-disable no-function-outside-class -- static factory of this class
@@ -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,CAA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ACN,CAAC;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;AAjGD,8CAiGC","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\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 /**\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,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C,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
+ }