@webpieces/openapi-generator 0.4.828 → 0.4.830
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 +47 -1
- package/package.json +3 -3
- package/src/cli/OpenApiCli.d.ts +5 -0
- package/src/cli/OpenApiCli.js +27 -1
- package/src/cli/OpenApiCli.js.map +1 -1
- package/src/generate/DocumentSelection.d.ts +8 -0
- package/src/generate/DocumentSelection.js +14 -4
- package/src/generate/DocumentSelection.js.map +1 -1
- package/src/generate/GenerationInputs.d.ts +34 -3
- package/src/generate/GenerationInputs.js +33 -2
- package/src/generate/GenerationInputs.js.map +1 -1
- package/src/generate/OpenApiGenerator.d.ts +43 -4
- package/src/generate/OpenApiGenerator.js +142 -10
- package/src/generate/OpenApiGenerator.js.map +1 -1
- package/src/generate/SchemaPlacement.d.ts +82 -0
- package/src/generate/SchemaPlacement.js +126 -0
- package/src/generate/SchemaPlacement.js.map +1 -0
- package/src/generate/SchemaRenderer.d.ts +27 -2
- package/src/generate/SchemaRenderer.js +57 -11
- package/src/generate/SchemaRenderer.js.map +1 -1
- package/src/generate/UpstreamComponents.d.ts +43 -0
- package/src/generate/UpstreamComponents.js +68 -0
- package/src/generate/UpstreamComponents.js.map +1 -0
- package/src/index.d.ts +6 -2
- package/src/index.js +16 -1
- package/src/index.js.map +1 -1
- package/src/load/ComponentsLocator.d.ts +44 -0
- package/src/load/ComponentsLocator.js +127 -0
- package/src/load/ComponentsLocator.js.map +1 -0
- package/src/load/InputsLoader.d.ts +14 -1
- package/src/load/InputsLoader.js +79 -1
- package/src/load/InputsLoader.js.map +1 -1
- package/src/manifest/ManifestLoader.d.ts +10 -2
- package/src/manifest/ManifestLoader.js +53 -3
- package/src/manifest/ManifestLoader.js.map +1 -1
- package/src/manifest/OpenApiManifest.d.ts +17 -0
- package/src/manifest/OpenApiManifest.js +21 -1
- package/src/manifest/OpenApiManifest.js.map +1 -1
package/README.md
CHANGED
|
@@ -91,6 +91,50 @@ never reads, and nothing could contradict it.
|
|
|
91
91
|
is a copy that a rename leaves silently stale. The generator folds the const and hard-fails if it
|
|
92
92
|
cannot.
|
|
93
93
|
|
|
94
|
+
## DTO libraries: chained documents, one owner per schema (#1058)
|
|
95
|
+
|
|
96
|
+
A schema is defined in exactly ONE document: the one belonging to the package whose source declares
|
|
97
|
+
the TypeScript type (the nearest `package.json` above the declaration). A contract document defines its
|
|
98
|
+
own package's types and **references** every other package's with a package-qualified `$ref`:
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
{ "$ref": "@myorg/lang-api-dtos/components.openapi.json#/components/schemas/PassageItemDto" }
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
So a DTO library publishes a **components-only** document. Its manifest declares `"kind": "components"`
|
|
105
|
+
and names entry files instead of contracts:
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{ "kind": "components", "title": "Lang DTOs", "entries": ["src/index.ts"] }
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`wp-openapi` then writes `components.openapi.json` — `openapi`, `info` (whose `version` IS the package
|
|
112
|
+
version), `x-webpieces-id` (the URI above; OpenAPI 3.1's root admits no `$id`) and `components.schemas`
|
|
113
|
+
holding **every type the library exports and declares**. A DTO library that uses another DTO library
|
|
114
|
+
references it the same way, so chains have any depth. It needs `--format json` or `both`.
|
|
115
|
+
|
|
116
|
+
The referenced documents are found by the same package lookup `McpToolCatalog.fromPackages` uses:
|
|
117
|
+
node resolution from the manifest, then the file beside a built package's `package.json`, or — for a
|
|
118
|
+
workspace source directory — the `outputPath` of the target its `openapi-components-generate` dependsOn.
|
|
119
|
+
|
|
120
|
+
**It FAILS CLOSED.** A `full-private` / `public` document that reaches a type declared in a package
|
|
121
|
+
publishing no components document is refused, naming the type, its package and the fix: move the type
|
|
122
|
+
into a DTO library (as a `…Dto` string enum when it is a literal union), or give that package a
|
|
123
|
+
components document. There is no allow-list. A referenced schema missing from an existing document is
|
|
124
|
+
refused as stale. Two DIFFERENT types of one name in one package are refused too; two packages'
|
|
125
|
+
same-named types are simply two schemas in two documents.
|
|
126
|
+
|
|
127
|
+
Inheritance is FLATTENED in every form — a base declared in another package contributes its fields;
|
|
128
|
+
there is no `allOf`.
|
|
129
|
+
|
|
130
|
+
**Every split document has a `*.bundled.json` sibling** (`public-openapi.bundled.json`, …) with every
|
|
131
|
+
schema pulled into its own `components.schemas` and no external reference, for code generators,
|
|
132
|
+
gateways and docs sites that read one file. A schema keeps its name there unless two packages' types of
|
|
133
|
+
one name meet, when the other package's is qualified (`myorg.lang-api-dtos.LocalizedDescriptionsDto`).
|
|
134
|
+
|
|
135
|
+
**`mcp-openapi.json` and the MCP tool catalogs never reference anything** — they inline every schema
|
|
136
|
+
from any package, exactly as before, and require no components document anywhere.
|
|
137
|
+
|
|
94
138
|
## MCP
|
|
95
139
|
|
|
96
140
|
`MCP` in `@ApiType` requires `@WpMcpTool` on at least one method, and `@WpMcpTool` on a contract that
|
|
@@ -118,7 +162,9 @@ is no flag to switch that off — the cure is at the contract, by naming the typ
|
|
|
118
162
|
## Worked example
|
|
119
163
|
|
|
120
164
|
`apps/app-example/partner-api` in this repo: a real contract, its manifest, golden documents under
|
|
121
|
-
`src/__tests__/goldens/`, and a spec that regenerates and diffs them.
|
|
165
|
+
`src/__tests__/goldens/`, and a spec that regenerates and diffs them. The chained form is proven by
|
|
166
|
+
`src/__tests__/ChainedComponents.spec.ts` here: a three-level chain (contract → DTO library A → DTO
|
|
167
|
+
library B), every document checked by an OpenAPI 3.1 validator.
|
|
122
168
|
|
|
123
169
|
## In an nx workspace
|
|
124
170
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/openapi-generator",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.830",
|
|
4
4
|
"description": "Render an ApiDocModel to OpenAPI 3.1.0 — the canonical internal document and the customer-published one, JSON and YAML, from one generation pass. Ships the wp-openapi bin.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@webpieces/api-doc-model": "0.4.
|
|
27
|
-
"@webpieces/core-util": "0.4.
|
|
26
|
+
"@webpieces/api-doc-model": "0.4.830",
|
|
27
|
+
"@webpieces/core-util": "0.4.830",
|
|
28
28
|
"typescript": "5.9.3"
|
|
29
29
|
},
|
|
30
30
|
"bin": {
|
package/src/cli/OpenApiCli.d.ts
CHANGED
|
@@ -26,6 +26,11 @@ export declare class OpenApiCli {
|
|
|
26
26
|
private readonly writer;
|
|
27
27
|
/** @param argv the arguments AFTER the program name. @param cwd what relative paths resolve against. */
|
|
28
28
|
run(argv: readonly string[], cwd: string): CliResult;
|
|
29
|
+
/**
|
|
30
|
+
* A DTO library's `components.openapi.json` (#1058). JSON is required: downstream documents `$ref`
|
|
31
|
+
* it by that file name, so a YAML-only run would publish a library nothing can reference.
|
|
32
|
+
*/
|
|
33
|
+
private components;
|
|
29
34
|
wantsHelp(argv: readonly string[]): boolean;
|
|
30
35
|
/**
|
|
31
36
|
* `mcp-<ContractClass>-tools.json` — the RUNTIME artifacts, one per contract, beside the three
|
package/src/cli/OpenApiCli.js
CHANGED
|
@@ -6,6 +6,7 @@ const path = tslib_1.__importStar(require("node:path"));
|
|
|
6
6
|
const core_util_1 = require("@webpieces/core-util");
|
|
7
7
|
const api_doc_model_1 = require("@webpieces/api-doc-model");
|
|
8
8
|
const ArtifactWriter_1 = require("../emit/ArtifactWriter");
|
|
9
|
+
const GenerationInputs_1 = require("../generate/GenerationInputs");
|
|
9
10
|
const OpenApiGenerator_1 = require("../generate/OpenApiGenerator");
|
|
10
11
|
const InputsLoader_1 = require("../load/InputsLoader");
|
|
11
12
|
const OpenApiGenerationError_1 = require("../OpenApiGenerationError");
|
|
@@ -29,6 +30,14 @@ exports.USAGE = [
|
|
|
29
30
|
'and has an @WpMcpTool: the RUNTIME catalogs WpMcpServer boots from. They are not documents, so',
|
|
30
31
|
'--format does not apply.',
|
|
31
32
|
'',
|
|
33
|
+
'Those documents are SPLIT: a schema another package declares is a $ref into that package\'s',
|
|
34
|
+
'components.openapi.json, and generation FAILS when that package publishes none. Each one also',
|
|
35
|
+
'gets a <name>.bundled.json sibling with every schema defined locally and no external reference.',
|
|
36
|
+
'mcp-openapi and the MCP tool catalogs stay fully inlined and require no components document.',
|
|
37
|
+
'',
|
|
38
|
+
'A manifest declaring "kind": "components" is a DTO LIBRARY\'s: it writes components.openapi.json,',
|
|
39
|
+
'every type its "entries" export, versioned as the package. It needs --format json or both.',
|
|
40
|
+
'',
|
|
32
41
|
'A document no contract asked for is not written. --format chooses the serialization of',
|
|
33
42
|
'whichever documents were written, and defaults to both.',
|
|
34
43
|
'',
|
|
@@ -78,7 +87,11 @@ class OpenApiCli {
|
|
|
78
87
|
if (manifest === undefined || out === undefined) {
|
|
79
88
|
throw new OpenApiGenerationError_1.OpenApiGenerationError(`wp-openapi needs both ${MANIFEST} and ${OUT}`, 'wp-openapi', `Run: wp-openapi ${MANIFEST} <openapi.manifest.json> ${OUT} <dir>`);
|
|
80
89
|
}
|
|
81
|
-
const
|
|
90
|
+
const manifestPath = path.resolve(cwd, manifest);
|
|
91
|
+
if (this.loader.isComponents(manifestPath)) {
|
|
92
|
+
return this.components(manifestPath, path.resolve(cwd, out), this.formatOf(argv));
|
|
93
|
+
}
|
|
94
|
+
const inputs = this.loader.load(manifestPath);
|
|
82
95
|
const documents = this.generator.generate(inputs);
|
|
83
96
|
const mcp = OpenApiCli.mcpCatalog(inputs);
|
|
84
97
|
const artifacts = [
|
|
@@ -87,6 +100,19 @@ class OpenApiCli {
|
|
|
87
100
|
];
|
|
88
101
|
return new CliResult(this.writer.write(path.resolve(cwd, out), artifacts), artifacts, mcp.skipped);
|
|
89
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* A DTO library's `components.openapi.json` (#1058). JSON is required: downstream documents `$ref`
|
|
105
|
+
* it by that file name, so a YAML-only run would publish a library nothing can reference.
|
|
106
|
+
*/
|
|
107
|
+
components(manifestPath, outDir, format) {
|
|
108
|
+
if (format === 'yaml') {
|
|
109
|
+
throw new OpenApiGenerationError_1.OpenApiGenerationError(`${FORMAT} yaml writes no components.openapi.json`, manifestPath, `A components document is referenced by its .json name — use ${FORMAT} json or both.`);
|
|
110
|
+
}
|
|
111
|
+
const inputs = this.loader.loadComponents(manifestPath);
|
|
112
|
+
const document = this.generator.components(inputs);
|
|
113
|
+
const artifacts = this.writer.artifacts(new GenerationInputs_1.GeneratedDocuments([document]), format);
|
|
114
|
+
return new CliResult(this.writer.write(outDir, artifacts), artifacts);
|
|
115
|
+
}
|
|
90
116
|
wantsHelp(argv) {
|
|
91
117
|
return argv.includes(HELP);
|
|
92
118
|
}
|
|
@@ -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,4DAA+F;AAC/F,2DAAyF;AAEzF,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,8FAA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CAAC;YACN,CAAC;QACL,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AApGD,gCAoGC","sourcesContent":["import * as path from 'node:path';\nimport { MCP, McpToolCatalogFile } from '@webpieces/core-util';\nimport { McpCatalogRender, McpSchemaRenderer, SkippedMcpTool } from '@webpieces/api-doc-model';\nimport { ArtifactWriter, GeneratedArtifact, OutputFormat } from '../emit/ArtifactWriter';\nimport { ContractModel, 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 '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 inputs = this.loader.load(path.resolve(cwd, manifest));\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 ];\n return new CliResult(\n this.writer.write(path.resolve(cwd, out), artifacts),\n artifacts,\n mcp.skipped,\n );\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) => 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,4DAA+F;AAC/F,2DAAyF;AACzF,mEAIsC;AACtC,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,6FAA6F;IAC7F,+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;IACA;IAEA;IAJb,YACa,OAA0B,EAC1B,SAAuC;IAChD,oFAAoF;IAC3E,kBAA6C,EAAE;QAH/C,YAAO,GAAP,OAAO,CAAmB;QAC1B,cAAS,GAAT,SAAS,CAA8B;QAEvC,oBAAe,GAAf,eAAe,CAAgC;IACzD,CAAC;CACP;AAPD,8BAOC;AAED,kGAAkG;AAClG,MAAM,YAAY;IAED;IACA;IAFb,YACa,SA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AM,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;AA1HD,gCA0HC","sourcesContent":["import * as path from 'node:path';\nimport { MCP, McpToolCatalogFile } from '@webpieces/core-util';\nimport { McpCatalogRender, McpSchemaRenderer, SkippedMcpTool } from '@webpieces/api-doc-model';\nimport { ArtifactWriter, GeneratedArtifact, OutputFormat } from '../emit/ArtifactWriter';\nimport {\n ContractModel,\n GeneratedDocuments,\n GenerationInputs,\n} 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 ];\n return new CliResult(\n this.writer.write(path.resolve(cwd, out), artifacts),\n artifacts,\n mcp.skipped,\n );\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) => 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"]}
|
|
@@ -67,6 +67,14 @@ export declare class DocumentSelection {
|
|
|
67
67
|
* whether ours fires on a clock or off a queue is our business.
|
|
68
68
|
*/
|
|
69
69
|
readonly internalNotice: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Define EVERY reached schema locally, whichever package declares it, and write no bundled
|
|
72
|
+
* sibling — the MCP projection (#1058). The MCP document is the agent-facing view our own MCP
|
|
73
|
+
* tooling reads, and MCP never requires a DTO library to publish a components document: an
|
|
74
|
+
* MCP-only consumer is not forced to tag anything. The other two documents are SPLIT — they
|
|
75
|
+
* `$ref` every other package's schema, and fail closed when that package publishes none.
|
|
76
|
+
*/
|
|
77
|
+
readonly inlinesEveryPackage: boolean;
|
|
70
78
|
private constructor();
|
|
71
79
|
/** Every contract declaring `SVC_TO_SVC` — which, by the fail-closed default, is every contract. */
|
|
72
80
|
static internal(): DocumentSelection;
|
|
@@ -69,6 +69,7 @@ class DocumentSelection {
|
|
|
69
69
|
dropHidden;
|
|
70
70
|
includeMcpExtensions;
|
|
71
71
|
internalNotice;
|
|
72
|
+
inlinesEveryPackage;
|
|
72
73
|
constructor(
|
|
73
74
|
/** The file name this document is written to, and the name a failure uses for it. */
|
|
74
75
|
fileName,
|
|
@@ -83,22 +84,31 @@ class DocumentSelection {
|
|
|
83
84
|
* operation. Both are internal facts: a customer calls what they are given a url for, and
|
|
84
85
|
* whether ours fires on a clock or off a queue is our business.
|
|
85
86
|
*/
|
|
86
|
-
internalNotice
|
|
87
|
+
internalNotice,
|
|
88
|
+
/**
|
|
89
|
+
* Define EVERY reached schema locally, whichever package declares it, and write no bundled
|
|
90
|
+
* sibling — the MCP projection (#1058). The MCP document is the agent-facing view our own MCP
|
|
91
|
+
* tooling reads, and MCP never requires a DTO library to publish a components document: an
|
|
92
|
+
* MCP-only consumer is not forced to tag anything. The other two documents are SPLIT — they
|
|
93
|
+
* `$ref` every other package's schema, and fail closed when that package publishes none.
|
|
94
|
+
*/
|
|
95
|
+
inlinesEveryPackage) {
|
|
87
96
|
this.fileName = fileName;
|
|
88
97
|
this.apiType = apiType;
|
|
89
98
|
this.dropHidden = dropHidden;
|
|
90
99
|
this.includeMcpExtensions = includeMcpExtensions;
|
|
91
100
|
this.internalNotice = internalNotice;
|
|
101
|
+
this.inlinesEveryPackage = inlinesEveryPackage;
|
|
92
102
|
}
|
|
93
103
|
/** Every contract declaring `SVC_TO_SVC` — which, by the fail-closed default, is every contract. */
|
|
94
104
|
// webpieces-disable no-function-outside-class -- static factory; the private constructor is what stops a fourth, unnamed selection being invented at a call site
|
|
95
105
|
static internal() {
|
|
96
|
-
return new DocumentSelection('full-private-openapi', core_util_1.SVC_TO_SVC, false, false, true);
|
|
106
|
+
return new DocumentSelection('full-private-openapi', core_util_1.SVC_TO_SVC, false, false, true, false);
|
|
97
107
|
}
|
|
98
108
|
/** Every contract declaring `EXTERNAL_CUSTOMER`, minus its hidden methods. */
|
|
99
109
|
// webpieces-disable no-function-outside-class -- static factory of this class
|
|
100
110
|
static customer() {
|
|
101
|
-
return new DocumentSelection('public-openapi', core_util_1.EXTERNAL_CUSTOMER, true, false, false);
|
|
111
|
+
return new DocumentSelection('public-openapi', core_util_1.EXTERNAL_CUSTOMER, true, false, false, false);
|
|
102
112
|
}
|
|
103
113
|
/**
|
|
104
114
|
* Every contract declaring `MCP`. A HIDDEN method is kept — an internal endpoint that is an agent
|
|
@@ -107,7 +117,7 @@ class DocumentSelection {
|
|
|
107
117
|
*/
|
|
108
118
|
// webpieces-disable no-function-outside-class -- static factory of this class
|
|
109
119
|
static mcp() {
|
|
110
|
-
return new DocumentSelection('mcp-openapi', core_util_1.MCP, false, true, false);
|
|
120
|
+
return new DocumentSelection('mcp-openapi', core_util_1.MCP, false, true, false, true);
|
|
111
121
|
}
|
|
112
122
|
/** Every document this generator knows how to write, in the order it writes them. */
|
|
113
123
|
// 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.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AAC;IAED,qFAAqF;IACrF,8EAA8E;IAC9E,MAAM,CAAC,GAAG;QACN,OAAO;YACH,iBAAiB,CAAC,QAAQ,EAAE;YAC5B,iBAAiB,CAAC,QAAQ,EAAE;YAC5B,iBAAiB,CAAC,GAAG,EAAE;SAC1B,CAAC;IACN,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,IAAI,EAAE,SAAS,KAAK,2BAAe,CAAC,IAAI,EAAE,CAAC;YACpD,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAChD,CAAC;IAED,wFAAwF;IACxF,WAAW,CAAC,mBAAuC;QAC/C,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,KAAK,CAAC,IAAI,CAAC,0BAAkB,CAAC,CAAC;QACnC,CAAC;QACD,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;YACpC,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACpC,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,2BAAmB,CAAC,CAAC;QAChC,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACJ;AAlFD,8CAkFC","sourcesContent":["import { ApiDocModel, DocumentedEndpoint } from '@webpieces/api-doc-model';\nimport {\n ApiTypeKind,\n EXTERNAL_CUSTOMER,\n MCP,\n SVC_TO_SVC,\n WpAuthLocalOnly,\n} from '@webpieces/core-util';\n\n/** The one line that says a document is not the customer contract. It appears in exactly one. */\nexport const INTERNAL_ONLY_LINE =\n 'INTERNAL — service-to-service use only. This document lists every endpoint these services serve, including ones no customer is meant to see. It is not the customer contract and must never be handed to one.';\n\n/**\n * The retry contract, published ONCE per document rather than as booleans stamped on every operation.\n *\n * Each operation's own `description` ends with one derived sentence saying whether it is safe to\n * retry; this table says where that sentence comes from. Three vendor-extension booleans per\n * operation would have been invisible to a human — Swagger UI and most themes do not render `x-`\n * extensions, and no standard generator reads `x-webpieces-*` — and would have tripled golden churn\n * the day the mapping changed.\n */\nexport const OPERATION_SEMANTICS = [\n \"Every operation states whether it is safe to retry, derived from the endpoint's declared\",\n 'side-effect contract:',\n '',\n '| declared operation | read-only | destructive | idempotent |',\n '|---|---|---|---|',\n '| read | yes | no | yes |',\n '| write-idempotent | no | yes | yes |',\n '| write | no | yes | no |',\n].join('\\n');\n\n/**\n * WHICH contracts and operations a document contains, and what prose it stamps. The ONLY thing that\n * differs between the three generated documents.\n *\n * ## Two orthogonal decisions, at two levels\n *\n * - `@ApiType(SVC_TO_SVC, EXTERNAL_CUSTOMER)` on the CONTRACT selects which FILES it feeds. A document\n * is written at all only when some contract declares its type, so no contract declaring `MCP` means\n * no `mcp-openapi.json` — there is no second emptiness rule to keep in step with that one.\n * - `{ hidden: true }` on ONE `@Endpoint` subtracts that method from the CUSTOMER document only. It\n * stays in the private document, and in the MCP document when it is a tool.\n *\n * The per-method case is real and cannot be said at class level: a NEW endpoint on an\n * already-published API, built on main before it is announced. The per-contract case is the one that\n * must not default to permissive, and at class level naming it costs one token per contract.\n *\n * ## Select, then render — never render, then filter\n *\n * One render function takes one of these and is called once per document. It builds\n * `components.schemas` by walking OUTWARD from the operations this selection accepted, so an\n * unselected operation's DTOs are never constructed at all.\n *\n * That asymmetry is about what a BUG does. Build-then-filter puts an unreleased feature's full\n * request and response schemas into the document and then relies on a removal pass to take them out\n * again — so a defect in the visibility logic SHIPS them, named and fully shaped, with only the URL\n * missing, to customers who were told the feature was withheld. Select-then-render cannot do that:\n * no code path can emit a schema that was never built.\n *\n * The usual objection to rendering more than once — that the passes drift in how each renders the\n * same endpoint — applies to separate code paths. This is ONE function, so same code, same input,\n * same output.\n *\n * ## The thing that bites: map ordering\n *\n * Collecting schemas during a walk makes the key order of `components.schemas` depend on which\n * operations were walked, so two documents would list identical schemas in different orders and the\n * goldens would churn on unrelated changes. The renderer SORTS the schema keys before emitting.\n * Orders that carry MEANING are left alone and said so where they are built: `apis[]` order is the\n * published sidebar, and the security-scheme order is the order the credentials are declared in.\n */\nexport class DocumentSelection {\n private constructor(\n /** The file name this document is written to, and the name a failure uses for it. */\n readonly fileName: string,\n /** The `@ApiType` a contract must declare to appear in this document. */\n readonly apiType: ApiTypeKind,\n /** Drop methods marked `{ hidden: true }`. True for the customer document alone. */\n readonly dropHidden: boolean,\n /** Stamp `x-mcp-tool` and its siblings. Only the MCP document has a reader for them. */\n readonly includeMcpExtensions: boolean,\n /**\n * Prepend {@link INTERNAL_ONLY_LINE} to `info.description`, and say what TRIGGERS each\n * operation. Both are internal facts: a customer calls what they are given a url for, and\n * whether ours fires on a clock or off a queue is our business.\n */\n readonly internalNotice: boolean,\n ) {}\n\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);\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);\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);\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 `@WpAuthLocalOnly`\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.auth?.decorator === WpAuthLocalOnly.name) {\n return false;\n }\n return !this.dropHidden || !endpoint.hidden;\n }\n\n /** `info.description`: the manifest's prose, plus whatever this document adds to it. */\n description(manifestDescription: string | undefined): string | undefined {\n const parts: string[] = [];\n if (this.internalNotice) {\n parts.push(INTERNAL_ONLY_LINE);\n }\n if (manifestDescription !== undefined) {\n parts.push(manifestDescription);\n }\n parts.push(OPERATION_SEMANTICS);\n return parts.join('\\n\\n');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DocumentSelection.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/DocumentSelection.ts"],"names":[],"mappings":";;;AACA,oDAM8B;AAE9B,iGAAiG;AACpF,QAAA,kBAAkB,GAC3B,+MAA+M,CAAC;AAEpN;;;;;;;;GAQG;AACU,QAAA,mBAAmB,GAAG;IAC/B,0FAA0F;IAC1F,uBAAuB;IACvB,EAAE;IACF,+DAA+D;IAC/D,mBAAmB;IACnB,2BAA2B;IAC3B,uCAAuC;IACvC,2BAA2B;CAC9B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAa,iBAAiB;IAGb;IAEA;IAEA;IAEA;IAMA;IAQA;IAtBb;IACI,qF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;;;;;;;;OAQG;IACH,eAAe,CAAC,QAA4B;QACxC,IAAI,QAAQ,CAAC,IAAI,EAAE,SAAS,KAAK,2BAAe,CAAC,IAAI,EAAE,CAAC;YACpD,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAChD,CAAC;IAED,wFAAwF;IACxF,WAAW,CAAC,mBAAuC;QAC/C,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,KAAK,CAAC,IAAI,CAAC,0BAAkB,CAAC,CAAC;QACnC,CAAC;QACD,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;YACpC,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACpC,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,2BAAmB,CAAC,CAAC;QAChC,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACJ;AA1FD,8CA0FC","sourcesContent":["import { ApiDocModel, DocumentedEndpoint } from '@webpieces/api-doc-model';\nimport {\n ApiTypeKind,\n EXTERNAL_CUSTOMER,\n MCP,\n SVC_TO_SVC,\n WpAuthLocalOnly,\n} from '@webpieces/core-util';\n\n/** The one line that says a document is not the customer contract. It appears in exactly one. */\nexport const INTERNAL_ONLY_LINE =\n 'INTERNAL — service-to-service use only. This document lists every endpoint these services serve, including ones no customer is meant to see. It is not the customer contract and must never be handed to one.';\n\n/**\n * The retry contract, published ONCE per document rather than as booleans stamped on every operation.\n *\n * Each operation's own `description` ends with one derived sentence saying whether it is safe to\n * retry; this table says where that sentence comes from. Three vendor-extension booleans per\n * operation would have been invisible to a human — Swagger UI and most themes do not render `x-`\n * extensions, and no standard generator reads `x-webpieces-*` — and would have tripled golden churn\n * the day the mapping changed.\n */\nexport const OPERATION_SEMANTICS = [\n \"Every operation states whether it is safe to retry, derived from the endpoint's declared\",\n 'side-effect contract:',\n '',\n '| declared operation | read-only | destructive | idempotent |',\n '|---|---|---|---|',\n '| read | yes | no | yes |',\n '| write-idempotent | no | yes | yes |',\n '| write | no | yes | no |',\n].join('\\n');\n\n/**\n * WHICH contracts and operations a document contains, and what prose it stamps. The ONLY thing that\n * differs between the three generated documents.\n *\n * ## Two orthogonal decisions, at two levels\n *\n * - `@ApiType(SVC_TO_SVC, EXTERNAL_CUSTOMER)` on the CONTRACT selects which FILES it feeds. A document\n * is written at all only when some contract declares its type, so no contract declaring `MCP` means\n * no `mcp-openapi.json` — there is no second emptiness rule to keep in step with that one.\n * - `{ hidden: true }` on ONE `@Endpoint` subtracts that method from the CUSTOMER document only. It\n * stays in the private document, and in the MCP document when it is a tool.\n *\n * The per-method case is real and cannot be said at class level: a NEW endpoint on an\n * already-published API, built on main before it is announced. The per-contract case is the one that\n * must not default to permissive, and at class level naming it costs one token per contract.\n *\n * ## Select, then render — never render, then filter\n *\n * One render function takes one of these and is called once per document. It builds\n * `components.schemas` by walking OUTWARD from the operations this selection accepted, so an\n * unselected operation's DTOs are never constructed at all.\n *\n * That asymmetry is about what a BUG does. Build-then-filter puts an unreleased feature's full\n * request and response schemas into the document and then relies on a removal pass to take them out\n * again — so a defect in the visibility logic SHIPS them, named and fully shaped, with only the URL\n * missing, to customers who were told the feature was withheld. Select-then-render cannot do that:\n * no code path can emit a schema that was never built.\n *\n * The usual objection to rendering more than once — that the passes drift in how each renders the\n * same endpoint — applies to separate code paths. This is ONE function, so same code, same input,\n * same output.\n *\n * ## The thing that bites: map ordering\n *\n * Collecting schemas during a walk makes the key order of `components.schemas` depend on which\n * operations were walked, so two documents would list identical schemas in different orders and the\n * goldens would churn on unrelated changes. The renderer SORTS the schema keys before emitting.\n * Orders that carry MEANING are left alone and said so where they are built: `apis[]` order is the\n * published sidebar, and the security-scheme order is the order the credentials are declared in.\n */\nexport class DocumentSelection {\n private constructor(\n /** The file name this document is written to, and the name a failure uses for it. */\n readonly fileName: string,\n /** The `@ApiType` a contract must declare to appear in this document. */\n readonly apiType: ApiTypeKind,\n /** Drop methods marked `{ hidden: true }`. True for the customer document alone. */\n readonly dropHidden: boolean,\n /** Stamp `x-mcp-tool` and its siblings. Only the MCP document has a reader for them. */\n readonly includeMcpExtensions: boolean,\n /**\n * Prepend {@link INTERNAL_ONLY_LINE} to `info.description`, and say what TRIGGERS each\n * operation. Both are internal facts: a customer calls what they are given a url for, and\n * whether ours fires on a clock or off a queue is our business.\n */\n readonly internalNotice: boolean,\n /**\n * Define EVERY reached schema locally, whichever package declares it, and write no bundled\n * sibling — the MCP projection (#1058). The MCP document is the agent-facing view our own MCP\n * tooling reads, and MCP never requires a DTO library to publish a components document: an\n * MCP-only consumer is not forced to tag anything. The other two documents are SPLIT — they\n * `$ref` every other package's schema, and fail closed when that package publishes none.\n */\n readonly inlinesEveryPackage: boolean,\n ) {}\n\n /** Every contract declaring `SVC_TO_SVC` — which, by the fail-closed default, is every contract. */\n // webpieces-disable no-function-outside-class -- static factory; the private constructor is what stops a fourth, unnamed selection being invented at a call site\n static internal(): DocumentSelection {\n return new DocumentSelection('full-private-openapi', SVC_TO_SVC, false, false, true, false);\n }\n\n /** Every contract declaring `EXTERNAL_CUSTOMER`, minus its hidden methods. */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static customer(): DocumentSelection {\n return new DocumentSelection('public-openapi', EXTERNAL_CUSTOMER, true, false, false, false);\n }\n\n /**\n * Every contract declaring `MCP`. A HIDDEN method is kept — an internal endpoint that is an agent\n * tool is still a tool, and requiring it to be published to customers in order to be one would be\n * exactly the wrong coupling.\n */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static mcp(): DocumentSelection {\n return new DocumentSelection('mcp-openapi', MCP, false, true, false, true);\n }\n\n /** Every document this generator knows how to write, in the order it writes them. */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static all(): readonly DocumentSelection[] {\n return [\n DocumentSelection.internal(),\n DocumentSelection.customer(),\n DocumentSelection.mcp(),\n ];\n }\n\n acceptsContract(model: ApiDocModel): boolean {\n return model.apiTypes.includes(this.apiType);\n }\n\n /**\n * `{ hidden: true }` subtracts a method from the CUSTOMER document, and `@WpAuthLocalOnly`\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.auth?.decorator === WpAuthLocalOnly.name) {\n return false;\n }\n return !this.dropHidden || !endpoint.hidden;\n }\n\n /** `info.description`: the manifest's prose, plus whatever this document adds to it. */\n description(manifestDescription: string | undefined): string | undefined {\n const parts: string[] = [];\n if (this.internalNotice) {\n parts.push(INTERNAL_ONLY_LINE);\n }\n if (manifestDescription !== undefined) {\n parts.push(manifestDescription);\n }\n parts.push(OPERATION_SEMANTICS);\n return parts.join('\\n\\n');\n }\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ApiDocModel } from '@webpieces/api-doc-model';
|
|
1
|
+
import { ApiComponentsModel, ApiDocModel } from '@webpieces/api-doc-model';
|
|
2
2
|
import { JsonObject } from '../json/JsonObject';
|
|
3
|
-
import { ApiEntry, OpenApiManifest } from '../manifest/OpenApiManifest';
|
|
3
|
+
import { ApiEntry, ComponentsManifest, OpenApiManifest } from '../manifest/OpenApiManifest';
|
|
4
|
+
import { UpstreamComponentsIndex } from './UpstreamComponents';
|
|
4
5
|
/** One manifest entry, paired with the model extracted from the file it names. */
|
|
5
6
|
export declare class ContractModel {
|
|
6
7
|
readonly entry: ApiEntry;
|
|
@@ -38,11 +39,41 @@ export declare class GenerationInputs {
|
|
|
38
39
|
readonly responseHeaders: readonly ResolvedResponseHeader[];
|
|
39
40
|
/** The markdown preamble's TEXT, already read from `descriptionFile`. */
|
|
40
41
|
readonly description: string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* The package this document is published by — the nearest `package.json` above the manifest.
|
|
44
|
+
* Its own types are defined in the document; every other package's are `$ref`s (#1058).
|
|
45
|
+
*/
|
|
46
|
+
readonly homePackage: string | undefined;
|
|
47
|
+
/** The components documents of every other package the split documents reach. */
|
|
48
|
+
readonly upstream: UpstreamComponentsIndex;
|
|
41
49
|
constructor(manifestPath: string, manifest: OpenApiManifest, contracts: readonly ContractModel[],
|
|
42
50
|
/** The document-wide error body's model, when the manifest declared one. */
|
|
43
51
|
errorType: ApiDocModel | undefined, responseHeaders: readonly ResolvedResponseHeader[],
|
|
44
52
|
/** The markdown preamble's TEXT, already read from `descriptionFile`. */
|
|
45
|
-
description: string | undefined
|
|
53
|
+
description: string | undefined,
|
|
54
|
+
/**
|
|
55
|
+
* The package this document is published by — the nearest `package.json` above the manifest.
|
|
56
|
+
* Its own types are defined in the document; every other package's are `$ref`s (#1058).
|
|
57
|
+
*/
|
|
58
|
+
homePackage: string | undefined,
|
|
59
|
+
/** The components documents of every other package the split documents reach. */
|
|
60
|
+
upstream: UpstreamComponentsIndex);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Everything a DTO library's components document needs, every file already read (#1058). Data-only.
|
|
64
|
+
*/
|
|
65
|
+
export declare class ComponentsInputs {
|
|
66
|
+
readonly manifestPath: string;
|
|
67
|
+
readonly manifest: ComponentsManifest;
|
|
68
|
+
/** Every type the library exports and declares, and what they reach. */
|
|
69
|
+
readonly model: ApiComponentsModel;
|
|
70
|
+
/** The components documents of the OTHER packages those types reach — a chain of any depth. */
|
|
71
|
+
readonly upstream: UpstreamComponentsIndex;
|
|
72
|
+
constructor(manifestPath: string, manifest: ComponentsManifest,
|
|
73
|
+
/** Every type the library exports and declares, and what they reach. */
|
|
74
|
+
model: ApiComponentsModel,
|
|
75
|
+
/** The components documents of the OTHER packages those types reach — a chain of any depth. */
|
|
76
|
+
upstream: UpstreamComponentsIndex);
|
|
46
77
|
}
|
|
47
78
|
/** ONE rendered document and the name it is written under. */
|
|
48
79
|
export declare class GeneratedDocument {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GeneratedDocuments = exports.GeneratedDocument = exports.GenerationInputs = exports.ResolvedResponseHeader = exports.ContractModel = void 0;
|
|
3
|
+
exports.GeneratedDocuments = exports.GeneratedDocument = exports.ComponentsInputs = exports.GenerationInputs = exports.ResolvedResponseHeader = exports.ContractModel = void 0;
|
|
4
4
|
/** One manifest entry, paired with the model extracted from the file it names. */
|
|
5
5
|
class ContractModel {
|
|
6
6
|
entry;
|
|
@@ -44,20 +44,51 @@ class GenerationInputs {
|
|
|
44
44
|
errorType;
|
|
45
45
|
responseHeaders;
|
|
46
46
|
description;
|
|
47
|
+
homePackage;
|
|
48
|
+
upstream;
|
|
47
49
|
constructor(manifestPath, manifest, contracts,
|
|
48
50
|
/** The document-wide error body's model, when the manifest declared one. */
|
|
49
51
|
errorType, responseHeaders,
|
|
50
52
|
/** The markdown preamble's TEXT, already read from `descriptionFile`. */
|
|
51
|
-
description
|
|
53
|
+
description,
|
|
54
|
+
/**
|
|
55
|
+
* The package this document is published by — the nearest `package.json` above the manifest.
|
|
56
|
+
* Its own types are defined in the document; every other package's are `$ref`s (#1058).
|
|
57
|
+
*/
|
|
58
|
+
homePackage,
|
|
59
|
+
/** The components documents of every other package the split documents reach. */
|
|
60
|
+
upstream) {
|
|
52
61
|
this.manifestPath = manifestPath;
|
|
53
62
|
this.manifest = manifest;
|
|
54
63
|
this.contracts = contracts;
|
|
55
64
|
this.errorType = errorType;
|
|
56
65
|
this.responseHeaders = responseHeaders;
|
|
57
66
|
this.description = description;
|
|
67
|
+
this.homePackage = homePackage;
|
|
68
|
+
this.upstream = upstream;
|
|
58
69
|
}
|
|
59
70
|
}
|
|
60
71
|
exports.GenerationInputs = GenerationInputs;
|
|
72
|
+
/**
|
|
73
|
+
* Everything a DTO library's components document needs, every file already read (#1058). Data-only.
|
|
74
|
+
*/
|
|
75
|
+
class ComponentsInputs {
|
|
76
|
+
manifestPath;
|
|
77
|
+
manifest;
|
|
78
|
+
model;
|
|
79
|
+
upstream;
|
|
80
|
+
constructor(manifestPath, manifest,
|
|
81
|
+
/** Every type the library exports and declares, and what they reach. */
|
|
82
|
+
model,
|
|
83
|
+
/** The components documents of the OTHER packages those types reach — a chain of any depth. */
|
|
84
|
+
upstream) {
|
|
85
|
+
this.manifestPath = manifestPath;
|
|
86
|
+
this.manifest = manifest;
|
|
87
|
+
this.model = model;
|
|
88
|
+
this.upstream = upstream;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.ComponentsInputs = ComponentsInputs;
|
|
61
92
|
/** ONE rendered document and the name it is written under. */
|
|
62
93
|
class GeneratedDocument {
|
|
63
94
|
fileName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenerationInputs.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/GenerationInputs.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"GenerationInputs.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/GenerationInputs.ts"],"names":[],"mappings":";;;AAKA,kFAAkF;AAClF,MAAa,aAAa;IAET;IACA;IAEA;IAJb,YACa,KAAe,EACf,KAAkB;IAC3B,qFAAqF;IAC5E,IAAY;QAHZ,UAAK,GAAL,KAAK,CAAU;QACf,UAAK,GAAL,KAAK,CAAa;QAElB,SAAI,GAAJ,IAAI,CAAQ;IACtB,CAAC;CACP;AAPD,sCAOC;AAED;;;;;GAKG;AACH,MAAa,sBAAsB;IAElB;IACA;IAFb,YACa,UAAkB,EAClB,WAA+B;QAD/B,eAAU,GAAV,UAAU,CAAQ;QAClB,gBAAW,GAAX,WAAW,CAAoB;IACzC,CAAC;CACP;AALD,wDAKC;AAED;;;;;;GAMG;AACH,MAAa,gBAAgB;IAEZ;IACA;IACA;IAEA;IACA;IAEA;IAKA;IAEA;IAfb,YACa,YAAoB,EACpB,QAAyB,EACzB,SAAmC;IAC5C,4EAA4E;IACnE,SAAkC,EAClC,eAAkD;IAC3D,yEAAyE;IAChE,WAA+B;IACxC;;;OAGG;IACM,WAA+B;IACxC,iFAAiF;IACxE,QAAiC;QAdjC,iBAAY,GAAZ,YAAY,CAAQ;QACpB,aAAQ,GAAR,QAAQ,CAAiB;QACzB,cAAS,GAAT,SAAS,CAA0B;QAEnC,cAAS,GAAT,SAAS,CAAyB;QAClC,oBAAe,GAAf,eAAe,CAAmC;QAElD,gBAAW,GAAX,WAAW,CAAoB;QAK/B,gBAAW,GAAX,WAAW,CAAoB;QAE/B,aAAQ,GAAR,QAAQ,CAAyB;IAC3C,CAAC;CACP;AAlBD,4CAkBC;AAED;;GAEG;AACH,MAAa,gBAAgB;IAEZ;IACA;IAEA;IAEA;IANb,YACa,YAAoB,EACpB,QAA4B;IACrC,wEAAwE;IAC/D,KAAyB;IAClC,+FAA+F;IACtF,QAAiC;QALjC,iBAAY,GAAZ,YAAY,CAAQ;QACpB,aAAQ,GAAR,QAAQ,CAAoB;QAE5B,UAAK,GAAL,KAAK,CAAoB;QAEzB,aAAQ,GAAR,QAAQ,CAAyB;IAC3C,CAAC;CACP;AATD,4CASC;AAED,8DAA8D;AAC9D,MAAa,iBAAiB;IAGb;IACA;IAHb;IACI,wFAAwF;IAC/E,QAAgB,EAChB,QAAoB;QADpB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,aAAQ,GAAR,QAAQ,CAAY;IAC9B,CAAC;CACP;AAND,8CAMC;AAED;;;;;;;GAOG;AACH,MAAa,kBAAkB;IACN;IAArB,YAAqB,SAAuC;QAAvC,cAAS,GAAT,SAAS,CAA8B;IAAG,CAAC;CACnE;AAFD,gDAEC","sourcesContent":["import { ApiComponentsModel, ApiDocModel } from '@webpieces/api-doc-model';\nimport { JsonObject } from '../json/JsonObject';\nimport { ApiEntry, ComponentsManifest, OpenApiManifest } from '../manifest/OpenApiManifest';\nimport { UpstreamComponentsIndex } from './UpstreamComponents';\n\n/** One manifest entry, paired with the model extracted from the file it names. */\nexport class ContractModel {\n constructor(\n readonly entry: ApiEntry,\n readonly model: ApiDocModel,\n /** Absolute path to the contract, so a refusal can name a file somebody can open. */\n readonly file: string,\n ) {}\n}\n\n/**\n * One response header, with its name already FOLDED out of the constant the manifest named.\n *\n * The folding happens before generation, not during it, so the generator is a pure function of\n * already-established facts: everything that can fail by reading the world has failed by then.\n */\nexport class ResolvedResponseHeader {\n constructor(\n readonly headerName: string,\n readonly description: string | undefined,\n ) {}\n}\n\n/**\n * Everything generation needs, with every file already read and every constant already folded.\n *\n * Separating this from {@link OpenApiGenerator} is what makes the generator testable without a\n * filesystem — and, more usefully, what makes the two documents provably one generation pass: they\n * are rendered from THIS value, twice, with only the hidden-endpoint filter differing.\n */\nexport class GenerationInputs {\n constructor(\n readonly manifestPath: string,\n readonly manifest: OpenApiManifest,\n readonly contracts: readonly ContractModel[],\n /** The document-wide error body's model, when the manifest declared one. */\n readonly errorType: ApiDocModel | undefined,\n readonly responseHeaders: readonly ResolvedResponseHeader[],\n /** The markdown preamble's TEXT, already read from `descriptionFile`. */\n readonly description: string | undefined,\n /**\n * The package this document is published by — the nearest `package.json` above the manifest.\n * Its own types are defined in the document; every other package's are `$ref`s (#1058).\n */\n readonly homePackage: string | undefined,\n /** The components documents of every other package the split documents reach. */\n readonly upstream: UpstreamComponentsIndex,\n ) {}\n}\n\n/**\n * Everything a DTO library's components document needs, every file already read (#1058). Data-only.\n */\nexport class ComponentsInputs {\n constructor(\n readonly manifestPath: string,\n readonly manifest: ComponentsManifest,\n /** Every type the library exports and declares, and what they reach. */\n readonly model: ApiComponentsModel,\n /** The components documents of the OTHER packages those types reach — a chain of any depth. */\n readonly upstream: UpstreamComponentsIndex,\n ) {}\n}\n\n/** ONE rendered document and the name it is written under. */\nexport class GeneratedDocument {\n constructor(\n /** Without an extension — `--format` decides whether it is `.json`, `.yaml` or both. */\n readonly fileName: string,\n readonly document: JsonObject,\n ) {}\n}\n\n/**\n * The documents this generation pass produced — one per `@ApiType` some contract declared, and no\n * others.\n *\n * `diff full-private-openapi.json public-openapi.json` is the complete list of what these contracts\n * do not show a customer, and both are committed, so hiding a method shows up as a diff in the PR\n * that hides it. That is the property the pair exists for.\n */\nexport class GeneratedDocuments {\n constructor(readonly documents: readonly GeneratedDocument[]) {}\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GeneratedDocuments, GenerationInputs } from './GenerationInputs';
|
|
1
|
+
import { ComponentsInputs, GeneratedDocument, GeneratedDocuments, GenerationInputs } from './GenerationInputs';
|
|
2
2
|
/**
|
|
3
3
|
* {@link GenerationInputs} -> one OpenAPI 3.1.0 document per `@ApiType` some contract declares.
|
|
4
4
|
*
|
|
@@ -40,8 +40,46 @@ export declare class OpenApiGenerator {
|
|
|
40
40
|
* with the first.
|
|
41
41
|
*/
|
|
42
42
|
generate(inputs: GenerationInputs): GeneratedDocuments;
|
|
43
|
+
/**
|
|
44
|
+
* A DTO library's COMPONENTS-ONLY document (#1058): `openapi`, `info`, `x-webpieces-id` and
|
|
45
|
+
* `components.schemas` — every type the library exports and declares, with every OTHER package's
|
|
46
|
+
* type a `$ref` into that package's own components document, so a chain of DTO libraries is a
|
|
47
|
+
* chain of documents of any depth.
|
|
48
|
+
*
|
|
49
|
+
* `info.version` is the PACKAGE version. The package-qualified URI downstream documents reference
|
|
50
|
+
* it by (`@scope/pkg/components.openapi.json`) is stated as `x-webpieces-id`, because OpenAPI 3.1's
|
|
51
|
+
* root object admits no `$id` — a 3.1 validator rejects one — and the document must validate on its
|
|
52
|
+
* own.
|
|
53
|
+
*/
|
|
54
|
+
components(inputs: ComponentsInputs): GeneratedDocument;
|
|
55
|
+
/**
|
|
56
|
+
* The SELF-CONTAINED form of a document: every reached schema defined locally, whichever package
|
|
57
|
+
* declares it — the `*.bundled.json` sibling of a split document, and the MCP projection.
|
|
58
|
+
*
|
|
59
|
+
* Two passes, because a schema's NAME depends on which other schemas the document reaches: the
|
|
60
|
+
* first renders with every type under its unique model key just to learn the reached set, and the
|
|
61
|
+
* second renders with the names {@link BundledNames} assigns from it. Rendering is a pure walk of
|
|
62
|
+
* the model, so the second pass reaches exactly what the first did.
|
|
63
|
+
*/
|
|
64
|
+
private bundled;
|
|
43
65
|
/** ONE document, from the operations this selection accepts and nothing else. */
|
|
44
66
|
private render;
|
|
67
|
+
/** Same-named, different declarations in one package, across every contract a document reads. */
|
|
68
|
+
private collisionsOf;
|
|
69
|
+
/**
|
|
70
|
+
* Two DIFFERENT declarations of one name in one package. A document defines each of its
|
|
71
|
+
* package's schemas under its bare name, so one of the two would be published as the other's
|
|
72
|
+
* shape. (Two packages' same-named types are not this: each is defined in its own package's
|
|
73
|
+
* document — #1058's `LocalizedDescriptionsDto` case.)
|
|
74
|
+
*/
|
|
75
|
+
private refuseCollisions;
|
|
76
|
+
/**
|
|
77
|
+
* FAIL CLOSED (#1058): every type this document references in another package must be a schema
|
|
78
|
+
* of that package's published components document. A package that publishes none is refused —
|
|
79
|
+
* naming the type, its package and the fix — rather than copied in, because silent copying is
|
|
80
|
+
* exactly the duplication this replaces. A document that exists but lacks the schema is stale.
|
|
81
|
+
*/
|
|
82
|
+
private refuseUnpublished;
|
|
45
83
|
/**
|
|
46
84
|
* A webhook is served by the PARTNER, so neither our failure envelope nor the header we stamp on
|
|
47
85
|
* our own responses is true of it. Publishing either would document their server, not ours.
|
|
@@ -58,9 +96,10 @@ export declare class OpenApiGenerator {
|
|
|
58
96
|
*/
|
|
59
97
|
private eventName;
|
|
60
98
|
/**
|
|
61
|
-
* Every named type from every contract, merged
|
|
99
|
+
* Every named type from every contract, merged by MODEL KEY — which carries the declaring
|
|
100
|
+
* package, so two packages' same-named types never meet here (#1058).
|
|
62
101
|
*
|
|
63
|
-
* Two contracts declaring DIFFERENT types under one
|
|
102
|
+
* Two contracts declaring DIFFERENT types under one key is a hard failure, not a first-wins
|
|
64
103
|
* merge: `components.schemas` is keyed by name, so one of the two would be published as the
|
|
65
104
|
* other's shape, and the operation referring to it would be quietly wrong.
|
|
66
105
|
*/
|
|
@@ -109,5 +148,5 @@ export declare class OpenApiGenerator {
|
|
|
109
148
|
* The guard. An unmapped field is a published partner-facing field with no shape, and there is
|
|
110
149
|
* deliberately no flag to switch this off — the cure is at the contract, by naming the type.
|
|
111
150
|
*/
|
|
112
|
-
private
|
|
151
|
+
private refuseUnmapped;
|
|
113
152
|
}
|