@webpieces/openapi-generator 0.4.939 → 0.4.941

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
@@ -302,6 +302,20 @@ and the `mcp-<Contract>-tools.json` catalogs — and each refusal names every of
302
302
  writes nothing. None has an off switch.
303
303
 
304
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 storeId}` — a field written BARE, in a field's JSDoc | `` `storeId` `` — the field's own name, no class prefix: the reader is already on that schema (#1308). A sibling and an inherited field both resolve; a bare name of ANOTHER class's field resolves to nothing in the compiler and is refused |
312
+ | `{@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` |
313
+ | `{@link OrdersApi.fetchOrders \| the order list}` / `{@link X label}` | `the order list (`` `fetchOrders` ``)` — the label, then the identity |
314
+ | `{@link https://…}` / `{@link https://… \| label}` | `<https://…>` / `[label](https://…)` — an ordinary markdown link |
315
+
316
+ A link the compiler cannot resolve, one to something that is not a type or an `@Endpoint` method of
317
+ an `@ApiPath` contract, and one to a type or operation the document does not publish are refused,
318
+ naming every `file:line` in one run. `@webpieces/docs-site` links each such code span to its page.
305
319
  - **`@summary` is REQUIRED** on every published operation, route and webhook alike (#1296): one line,
306
320
  at most 100 characters. It is the endpoint's short title — the OpenAPI `summary` (which used to be
307
321
  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.939",
3
+ "version": "0.4.941",
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.939",
27
- "@webpieces/core-util": "0.4.939",
26
+ "@webpieces/api-doc-model": "0.4.941",
27
+ "@webpieces/core-util": "0.4.941",
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":["../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,CAAC,IAAuB;QACpC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC5C,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO,MAAM,CAAC;QAClB,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,+CAAsB,CAC5B,WAAW,MAAM,KAAK,QAAQ,GAAG,EACjC,YAAY,EACZ,GAAG,MAAM,kBAAkB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACnD,CAAC;QACN,CAAC;QACD,OAAO,QAAwB,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACK,OAAO,CAAC,IAAuB,EAAE,IAAY;QACjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC;YAC1B,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;gBACpB,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACvB,CAAC;YACD,IAAI,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACzD,MAAM,IAAI,+CAAsB,CAC5B,iBAAiB,QAAQ,GAAG,EAC5B,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":";;;;AAAA,wDAAkC;AAClC,oDAA+D;AAC/D,4DAMkC;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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AAC,EAAE,CAAC;YAC9B,MAAM,IAAI,+CAAsB,CAC5B,WAAW,MAAM,KAAK,QAAQ,GAAG,EACjC,YAAY,EACZ,GAAG,MAAM,kBAAkB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACnD,CAAC;QACN,CAAC;QACD,OAAO,QAAwB,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACK,OAAO,CAAC,IAAuB,EAAE,IAAY;QACjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC;YAC1B,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;gBACpB,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACvB,CAAC;YACD,IAAI,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACzD,MAAM,IAAI,+CAAsB,CAC5B,iBAAiB,QAAQ,GAAG,EAC5B,YAAY,EACZ,oBAAoB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAC5D,CAAC;YACN,CAAC;QACL,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AAhJD,gCAgJC","sourcesContent":["import * as path from 'node:path';\nimport { MCP, McpToolCatalogFile } from '@webpieces/core-util';\nimport {\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/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AW,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,EAC1C,OAAuB,EACvB,SAA0B;IAC3C,oFAAoF;IACnE,YAAyC;QAJzC,UAAK,GAAL,KAAK,CAAqC;QAC1C,YAAO,GAAP,OAAO,CAAgB;QACvB,cAAS,GAAT,SAAS,CAAiB;QAE1B,iBAAY,GAAZ,YAAY,CAA6B;IAC3D,CAAC;IAEJ,aAAa,CAAC,IAAa;QACvB,IAAI,IAAI,CAAC,IAAI,KAAK,2BAAW,CAAC,SAAS,EAAE,CA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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"]}
@@ -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,6 +76,11 @@ 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;
79
86
  /** The operation renderer, carrying what this selection stamps on each operation. */
@@ -102,6 +109,8 @@ export declare class OpenApiGenerator {
102
109
  * published value cannot disagree.
103
110
  */
104
111
  private refuseDuplicateOperationIds;
112
+ /** `Contract.method` -> operationId, for every operation this document publishes. */
113
+ private publishedOperationIds;
105
114
  /**
106
115
  * FAIL CLOSED (#1058): every type this document references in another package must be a schema
107
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");
@@ -81,6 +82,8 @@ const OPENAPI_VERSION = '3.1.0';
81
82
  * schema with no JSDoc description ({@link UndocumentedSchemaGuard}) — each naming every offender in
82
83
  * one run (#1292). Likewise an operation with no valid `@summary` ({@link SummaryGuard}) and an MCP
83
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).
84
87
  */
85
88
  class OpenApiGenerator {
86
89
  security = new SecurityDeriver_1.SecurityDeriver();
@@ -112,6 +115,7 @@ class OpenApiGenerator {
112
115
  // Collected across EVERY OpenAPI document of the run and refused once, after them all, so an
113
116
  // author is handed every undocumented schema at once rather than one document at a time.
114
117
  const undocumented = new UndocumentedSchemaGuard_1.UndocumentedSchemaGuard();
118
+ const links = new DocLinkGuard_1.DocLinkGuard();
115
119
  const documents = [];
116
120
  for (const selection of DocumentSelection_1.DocumentSelection.all()) {
117
121
  const contracts = inputs.contracts.filter((each) => selection.acceptsContract(each.model));
@@ -119,19 +123,22 @@ class OpenApiGenerator {
119
123
  continue;
120
124
  }
121
125
  if (selection.inlinesEveryPackage) {
122
- 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)));
123
127
  continue;
124
128
  }
125
129
  this.refuseCollisions(this.collisionsOf(inputs, contracts), inputs.manifestPath);
126
- 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);
127
133
  this.refuseUnpublished(split.schemas, this.mergedTypes(inputs), inputs.upstream, selection.fileName, inputs.manifestPath);
128
134
  undocumented.collect(split.schemas.reachedTypes(), this.mergedTypes(inputs));
129
135
  // An inlined wrapper is still a published schema, so it still needs its description.
130
136
  undocumented.collect(split.schemas.inlinedTypes(), this.mergedTypes(inputs));
131
137
  documents.push(new GenerationInputs_1.GeneratedDocument(selection.fileName, split.document));
132
- 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)));
133
139
  }
134
140
  undocumented.refuse(inputs.manifestPath);
141
+ links.refuse(inputs.manifestPath);
135
142
  return new GenerationInputs_1.GeneratedDocuments(documents);
136
143
  }
137
144
  /**
@@ -160,6 +167,9 @@ class OpenApiGenerator {
160
167
  const undocumented = new UndocumentedSchemaGuard_1.UndocumentedSchemaGuard();
161
168
  undocumented.collect(schemas.reachedTypes(), model.types);
162
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);
163
173
  if (rendered.isEmpty()) {
164
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".');
165
175
  }
@@ -180,14 +190,27 @@ class OpenApiGenerator {
180
190
  * second renders with the names {@link BundledNames} assigns from it. Rendering is a pure walk of
181
191
  * the model, so the second pass reaches exactly what the first did.
182
192
  */
183
- 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.
184
196
  const discovery = this.render(inputs, contracts, selection, new SchemaPlacement_1.DiscoveryPlacement());
185
197
  // The MCP projection inlines every type it reaches, from any package, so it is judged here
186
198
  // over that whole set (#1292). A split document's bundled sibling is not: each type in it is
187
199
  // judged by the document — or the components document — that defines it.
188
200
  undocumented?.collect(discovery.schemas.reachedTypes(), this.mergedTypes(inputs));
189
201
  const names = SchemaPlacement_1.BundledNames.assign(discovery.schemas.reachedTypes(), this.mergedTypes(inputs), inputs.homePackage);
190
- 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);
191
214
  }
192
215
  /** ONE document, from the operations this selection accepts and nothing else. */
193
216
  render(inputs, contracts, selection, placement) {
@@ -305,6 +328,20 @@ class OpenApiGenerator {
305
328
  'manifest, which prefixes every id with its contract name (this renames every method ' +
306
329
  "in partners' generated clients).", duplicates);
307
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
+ }
308
345
  /**
309
346
  * FAIL CLOSED (#1058): every type this document references in another package must be a schema
310
347
  * of that package's published components document. A package that publishes none is refused —