@webpieces/openapi-generator 0.4.901 → 0.4.903
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 +38 -0
- package/package.json +3 -3
- package/src/generate/OpenApiGenerator.d.ts +1 -0
- package/src/generate/OpenApiGenerator.js +19 -3
- package/src/generate/OpenApiGenerator.js.map +1 -1
- package/src/generate/SchemaPlacement.js +12 -6
- package/src/generate/SchemaPlacement.js.map +1 -1
- package/src/load/InputsLoader.d.ts +1 -1
- package/src/load/InputsLoader.js +2 -0
- package/src/load/InputsLoader.js.map +1 -1
- package/src/manifest/ManifestLoader.d.ts +1 -0
- package/src/manifest/ManifestLoader.js +20 -3
- package/src/manifest/ManifestLoader.js.map +1 -1
- package/src/manifest/OpenApiManifest.d.ts +5 -2
- package/src/manifest/OpenApiManifest.js +6 -29
- package/src/manifest/OpenApiManifest.js.map +1 -1
package/README.md
CHANGED
|
@@ -80,6 +80,44 @@ It carries exactly what is **not a property of the code**:
|
|
|
80
80
|
|
|
81
81
|
Every path is relative to the manifest's own directory.
|
|
82
82
|
|
|
83
|
+
### Source suffixes and published schema names
|
|
84
|
+
|
|
85
|
+
An optional `schemaNames` list controls published type names independently of source
|
|
86
|
+
validation. It works in contract manifests and `"kind": "components"` manifests:
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
"schemaNames": [
|
|
90
|
+
{ "paths": ["../keep-my-names/**"], "stripSuffixes": [] },
|
|
91
|
+
{ "paths": ["../partner-apis/**", "../shared-dtos/**"], "stripSuffixes": ["Dto"] }
|
|
92
|
+
]
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Globs match the type's declaring file, relative to the manifest's directory. The
|
|
96
|
+
first matching entry wins; no match or an explicit empty list preserves the name.
|
|
97
|
+
Only one exact, case-sensitive trailing suffix is removed, in configured order.
|
|
98
|
+
`OrderDto` becomes `Order`; `Dto` alone and `OrderDTO` remain unchanged.
|
|
99
|
+
|
|
100
|
+
The same published names are used for schema keys, every reference and discriminator
|
|
101
|
+
mapping, bundled documents, MCP tool schemas, and streaming schemas. Source names
|
|
102
|
+
remain available to validation and diagnostics. If stripping makes two reached
|
|
103
|
+
declarations share a published name, generation fails naming both declarations and
|
|
104
|
+
their locations. Existing unstripped package-qualified homonyms remain supported.
|
|
105
|
+
|
|
106
|
+
Configure matching policies on **every producer and consumer** in a components
|
|
107
|
+
chain. The downstream generator checks that the upstream document actually exports
|
|
108
|
+
the expected schema name; a missing or inconsistent policy fails generation.
|
|
109
|
+
|
|
110
|
+
This combines with `required-type-suffix`: use an entry with `exempt: true` to
|
|
111
|
+
preserve published source names, or set `exempt: false` and enforce `Dto` gradually with
|
|
112
|
+
`NEW_AND_MODIFIED_CODE` while stripping it from generated documentation. The
|
|
113
|
+
chained-components regression test renames source declarations and checks that all
|
|
114
|
+
generated OpenAPI and MCP artifacts remain byte-identical.
|
|
115
|
+
|
|
116
|
+
Every suffix-enforcement entry requires an explicit `exempt` boolean and non-empty
|
|
117
|
+
`suffixes`, including exempt entries. Retaining the suffixes records the policy that
|
|
118
|
+
re-enabling the entry will enforce. `suffixes: []` is rejected with migration advice.
|
|
119
|
+
For example: `{ "paths": ["published/**"], "suffixes": ["Dto", "Api"], "exempt": true }`.
|
|
120
|
+
|
|
83
121
|
**The ORDER of `apis[]` is the published sidebar order.** Alphabetising it is not a cleanup.
|
|
84
122
|
|
|
85
123
|
**`securitySchemeNames` holds the published KEYS only.** The schemes themselves, and the AND-ed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/openapi-generator",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.903",
|
|
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.903",
|
|
27
|
+
"@webpieces/core-util": "0.4.903",
|
|
28
28
|
"typescript": "5.9.3"
|
|
29
29
|
},
|
|
30
30
|
"bin": {
|
|
@@ -64,6 +64,7 @@ export declare class OpenApiGenerator {
|
|
|
64
64
|
private bundled;
|
|
65
65
|
/** ONE document, from the operations this selection accepts and nothing else. */
|
|
66
66
|
private render;
|
|
67
|
+
private renderSecuritySchemes;
|
|
67
68
|
/** Same-named, different declarations in one package, across every contract a document reads. */
|
|
68
69
|
private collisionsOf;
|
|
69
70
|
/**
|
|
@@ -168,7 +168,7 @@ class OpenApiGenerator {
|
|
|
168
168
|
this.refuseUnmapped(schemas.unmapped(), selection.fileName, inputs.manifestPath);
|
|
169
169
|
const components = new JsonObject_1.JsonObject()
|
|
170
170
|
.set('schemas', renderedSchemas)
|
|
171
|
-
.set('securitySchemes', this.
|
|
171
|
+
.set('securitySchemes', this.renderSecuritySchemes(inputs, contracts, selection, apiKey))
|
|
172
172
|
.set('headers', this.headers(inputs));
|
|
173
173
|
const document = new JsonObject_1.JsonObject()
|
|
174
174
|
.set('openapi', OPENAPI_VERSION)
|
|
@@ -181,6 +181,14 @@ class OpenApiGenerator {
|
|
|
181
181
|
.set('components', components.orUndefined());
|
|
182
182
|
return new RenderedDocument(document, schemas);
|
|
183
183
|
}
|
|
184
|
+
renderSecuritySchemes(inputs, contracts, selection, apiKey) {
|
|
185
|
+
const schemes = apiKey === undefined
|
|
186
|
+
? new JsonObject_1.JsonObject()
|
|
187
|
+
: this.security.schemes(apiKey, inputs.manifest.securitySchemeNames, inputs.manifestPath);
|
|
188
|
+
return this.security
|
|
189
|
+
.addBuiltinSchemes(schemes, this.selectedEndpoints(contracts, selection))
|
|
190
|
+
.orUndefined();
|
|
191
|
+
}
|
|
184
192
|
/** Same-named, different declarations in one package, across every contract a document reads. */
|
|
185
193
|
collisionsOf(inputs, contracts) {
|
|
186
194
|
const models = contracts.map((each) => each.model);
|
|
@@ -222,8 +230,8 @@ class OpenApiGenerator {
|
|
|
222
230
|
const reason = upstream.missingFor(owner)?.reason ?? 'it was never located';
|
|
223
231
|
unpublished.push(`${declared}: ${owner} publishes no components document — ${reason}`);
|
|
224
232
|
}
|
|
225
|
-
else if (!published.schemaNames.has(type.
|
|
226
|
-
stale.push(`${declared}: ${published.documentPath} has no schema '${type.
|
|
233
|
+
else if (!published.schemaNames.has(type.schemaName)) {
|
|
234
|
+
stale.push(`${declared}: ${published.documentPath} has no schema '${type.schemaName}'`);
|
|
227
235
|
}
|
|
228
236
|
}
|
|
229
237
|
if (unpublished.length > 0) {
|
|
@@ -284,11 +292,19 @@ class OpenApiGenerator {
|
|
|
284
292
|
*/
|
|
285
293
|
mergedTypes(inputs) {
|
|
286
294
|
const merged = new Map();
|
|
295
|
+
const published = new Map();
|
|
287
296
|
const sources = inputs.contracts.map((each) => each.model);
|
|
288
297
|
const all = inputs.errorType === undefined ? sources : sources.concat([inputs.errorType]);
|
|
289
298
|
for (const model of all) {
|
|
290
299
|
for (const name of Array.from(model.types.keys())) {
|
|
291
300
|
const incoming = model.types.get(name);
|
|
301
|
+
const previous = published.get(incoming.schemaName);
|
|
302
|
+
if (previous !== undefined &&
|
|
303
|
+
previous.location !== incoming.location &&
|
|
304
|
+
(previous.name !== previous.schemaName || incoming.name !== incoming.schemaName)) {
|
|
305
|
+
throw new OpenApiGenerationError_1.OpenApiGenerationError(`stripped schema name '${incoming.schemaName}' collides: '${previous.name}' at ${previous.location} and '${incoming.name}' at ${incoming.location}`, inputs.manifestPath, 'Change schemaNames so every reached declaration has a distinct published name.');
|
|
306
|
+
}
|
|
307
|
+
published.set(incoming.schemaName, incoming);
|
|
292
308
|
const existing = merged.get(name);
|
|
293
309
|
if (existing !== undefined &&
|
|
294
310
|
this.signature(existing) !== this.signature(incoming)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenApiGenerator.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/OpenApiGenerator.ts"],"names":[],"mappings":";;;AAAA,4DASkC;AAClC,mDAA2D;AAC3D,sEAAmE;AAEnE,yDAM4B;AAC5B,2DAAwD;AACxD,2DAA0E;AAC1E,uDAO2B;AAC3B,qDAAiE;AACjE,uDAAoD;AAGpD,uGAAuG;AACvG,MAAM,gBAAgB;IAEL;IACA;IAFb,YACa,QAAoB,EACpB,OAAuB;QADvB,aAAQ,GAAR,QAAQ,CAAY;QACpB,YAAO,GAAP,OAAO,CAAgB;IACjC,CAAC;CACP;AAED,8FAA8F;AAC9F,MAAM,cAAc,GAAG,UAAU,CAAC;AAElC,2EAA2E;AAC3E,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,uBAAuB,GACzB,6FAA6F;IAC7F,oGAAoG;IACpG,6FAA6F;IAC7F,sGAAsG;IACtG,mGAAmG;IACnG,8EAA8E,CAAC;AAEnF,4FAA4F;AAC5F,MAAM,eAAe,GAAG,OAAO,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAa,gBAAgB;IACR,QAAQ,GAAG,IAAI,iCAAe,EAAE,CAAC;IAElD;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAwB;QAC7B,MAAM,SAAS,GAAwB,EAAE,CAAC;QAC1C,KAAK,MAAM,SAAS,IAAI,qCAAiB,CAAC,GAAG,EAAE,EAAE,CAAC;YAC9C,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAmB,EAAE,EAAE,CAC9D,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CACxC,CAAC;YACF,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gB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IACK,cAAc,CAClB,QAAkC,EAClC,QAAgB,EAChB,YAAoB;QAEpB,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO;QACX,CAAC;QACD,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CACzB,CAAC,KAAoB,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,QAAQ,GAAG,CACnE,CAAC;QACF,MAAM,IAAI,+CAAsB,CAC5B,GAAG,QAAQ,CAAC,MAAM,gBAAgB,QAAQ,8BAA8B,EACxE,YAAY,EACZ,8EAA8E;YAC1E,uFAAuF,EAC3F,QAAQ,CACX,CAAC;IACN,CAAC;CACJ;AApjBD,4CAojBC","sourcesContent":["import {\n ApiDocModel,\n DocumentedApiKey,\n DocumentedAuthMethod,\n DocumentedEndpoint,\n DocumentedField,\n DocumentedType,\n TypeNameCollision,\n TypeRef,\n} from '@webpieces/api-doc-model';\nimport { JsonObject, JsonValue } from '../json/JsonObject';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\nimport { ServerEntry } from '../manifest/OpenApiManifest';\nimport {\n ComponentsInputs,\n ContractModel,\n GeneratedDocument,\n GeneratedDocuments,\n GenerationInputs,\n} from './GenerationInputs';\nimport { DocumentSelection } from './DocumentSelection';\nimport { OperationRenderer, ResponseContract } from './OperationRenderer';\nimport {\n BundledNames,\n BundledPlacement,\n ComponentsReference,\n DiscoveryPlacement,\n SchemaPlacement,\n SplitPlacement,\n} from './SchemaPlacement';\nimport { SchemaRenderer, UnmappedField } from './SchemaRenderer';\nimport { SecurityDeriver } from './SecurityDeriver';\nimport { UpstreamComponentsIndex } from './UpstreamComponents';\n\n/** One rendered document, and the renderer that built its schemas — what it defined and referenced. */\nclass RenderedDocument {\n constructor(\n readonly document: JsonObject,\n readonly schemas: SchemaRenderer,\n ) {}\n}\n\n/** The suffix of a split document's self-contained sibling: `public-openapi.bundled.json`. */\nconst BUNDLED_SUFFIX = '.bundled';\n\n/** The document a DTO library publishes, without its extension (#1058). */\nconst COMPONENTS_DOCUMENT = 'components.openapi';\n\n/**\n * Every cure for a type reached in a package that publishes no components document.\n *\n * Tagging is offered ONLY for a package that is already a role:api-lib DTO library (#1064, D5): a\n * general library such as `company-core` is refused the tag by validate-nx-wiring and by the\n * openapi-components-generate executor, so \"tag the package\" is never a way out of moving the type.\n */\nconst PUBLISH_COMPONENTS_CURE =\n 'Move each type into a role:api-lib DTO library that publishes a components document — as a ' +\n '`…Dto` string enum when it is a string-literal union. Only when the declaring package is ITSELF a ' +\n 'role:api-lib DTO library, tag it \"generate:openapi-components\" so it publishes one (with a ' +\n '\"kind\": \"components\" openapi.manifest.json naming its entry files; outside nx, render that manifest ' +\n 'with wp-openapi into the directory the package is packed from); a general library is refused the ' +\n \"tag. A document references another package's schema; it never copies one in.\";\n\n/** The OpenAPI version this generator writes. See the class doc for why 3.1 and not 3.0. */\nconst OPENAPI_VERSION = '3.1.0';\n\n/**\n * {@link GenerationInputs} -> one OpenAPI 3.1.0 document per `@ApiType` some contract declares.\n *\n * ## 3.1, because it is what the model can state HONESTLY\n *\n * `type: [T, \"null\"]` instead of a `nullable` keyword; a `description` legal beside a `$ref`; a\n * top-level `webhooks:` block. Each of those is a fact the model holds that 3.0 would have forced\n * this renderer to drop or to lie about. 3.1's schema dialect is also JSON Schema 2020-12, which is\n * what MCP `tools/list` speaks.\n *\n * ## ONE render function, called once per document\n *\n * ```\n * ApiDocModel --> render(selection) --+--> full-private-openapi.json SVC_TO_SVC contracts\n * +--> public-openapi.json EXTERNAL_CUSTOMER contracts, minus hidden methods\n * +--> mcp-openapi.json MCP contracts\n * ```\n *\n * `components.schemas` is built by walking OUTWARD from the operations the selection accepted, so an\n * unselected operation's DTOs are never constructed. See {@link DocumentSelection} for why that\n * asymmetry — a bug emits nothing, rather than shipping an unreleased feature's schemas with only\n * its URL removed — decides the whole design.\n *\n * ## It REFUSES to write an unmapped field\n *\n * An unmapped type renders as an empty schema, which in JSON Schema means \"anything\". Publishing one\n * is a green build handing a partner a field with no shape, so the guard names the JSON pointer of\n * every one and exits non-zero. There is deliberately NO flag to switch it off: the cure is at the\n * contract, by naming the type.\n */\nexport class OpenApiGenerator {\n private readonly security = new SecurityDeriver();\n\n /**\n * ONE document per `@ApiType` some contract declares, and no others.\n *\n * A document nobody asked for is not written empty — it is not written. That is the ONE\n * conditional in the whole pipeline, and it lives here rather than in three places: no contract\n * declaring `MCP` means no `mcp-openapi.json`, with no second \"is it empty?\" rule to keep in step\n * with the first.\n */\n generate(inputs: GenerationInputs): GeneratedDocuments {\n const documents: GeneratedDocument[] = [];\n for (const selection of DocumentSelection.all()) {\n const contracts = inputs.contracts.filter((each: ContractModel) =>\n selection.acceptsContract(each.model),\n );\n if (contracts.length === 0) {\n continue;\n }\n if (selection.inlinesEveryPackage) {\n documents.push(\n new GeneratedDocument(\n selection.fileName,\n this.bundled(inputs, contracts, selection),\n ),\n );\n continue;\n }\n this.refuseCollisions(this.collisionsOf(inputs, contracts), inputs.manifestPath);\n const split = this.render(\n inputs,\n contracts,\n selection,\n new SplitPlacement(inputs.homePackage),\n );\n this.refuseUnpublished(\n split.schemas,\n this.mergedTypes(inputs),\n inputs.upstream,\n selection.fileName,\n inputs.manifestPath,\n );\n documents.push(new GeneratedDocument(selection.fileName, split.document));\n documents.push(\n new GeneratedDocument(\n `${selection.fileName}${BUNDLED_SUFFIX}`,\n this.bundled(inputs, contracts, selection),\n ),\n );\n }\n return new GeneratedDocuments(documents);\n }\n\n /**\n * A DTO library's COMPONENTS-ONLY document (#1058): `openapi`, `info`, `x-webpieces-id` and\n * `components.schemas` — every type the library exports and declares, with every OTHER package's\n * type a `$ref` into that package's own components document, so a chain of DTO libraries is a\n * chain of documents of any depth.\n *\n * `info.version` is the PACKAGE version. The package-qualified URI downstream documents reference\n * it by (`@scope/pkg/components.openapi.json`) is stated as `x-webpieces-id`, because OpenAPI 3.1's\n * root object admits no `$id` — a 3.1 validator rejects one — and the document must validate on its\n * own.\n */\n components(inputs: ComponentsInputs): GeneratedDocument {\n const model = inputs.model;\n const where = inputs.manifestPath;\n this.refuseCollisions(model.collisions, where);\n const schemas = new SchemaRenderer(model.types, new SplitPlacement(model.packageName));\n for (const key of model.exported) {\n schemas.define(key);\n }\n const rendered = schemas.components();\n this.refuseUnmapped(schemas.unmapped(), COMPONENTS_DOCUMENT, where);\n this.refuseUnpublished(schemas, model.types, inputs.upstream, COMPONENTS_DOCUMENT, where);\n if (rendered.isEmpty()) {\n throw new OpenApiGenerationError(\n `${model.packageName}'s entries export no type with a schema`,\n where,\n 'Name the entry files that export the library\\'s DTOs and enums — usually \"src/index.ts\".',\n );\n }\n return new GeneratedDocument(\n COMPONENTS_DOCUMENT,\n new JsonObject()\n .set('openapi', OPENAPI_VERSION)\n .set(\n 'info',\n new JsonObject()\n .set('title', inputs.manifest.title)\n .set('version', model.packageVersion),\n )\n .set('x-webpieces-id', ComponentsReference.documentUri(model.packageName))\n .set('components', new JsonObject().set('schemas', rendered)),\n );\n }\n\n /**\n * The SELF-CONTAINED form of a document: every reached schema defined locally, whichever package\n * declares it — the `*.bundled.json` sibling of a split document, and the MCP projection.\n *\n * Two passes, because a schema's NAME depends on which other schemas the document reaches: the\n * first renders with every type under its unique model key just to learn the reached set, and the\n * second renders with the names {@link BundledNames} assigns from it. Rendering is a pure walk of\n * the model, so the second pass reaches exactly what the first did.\n */\n private bundled(\n inputs: GenerationInputs,\n contracts: readonly ContractModel[],\n selection: DocumentSelection,\n ): JsonObject {\n const discovery = this.render(inputs, contracts, selection, new DiscoveryPlacement());\n const names = BundledNames.assign(\n discovery.schemas.reachedTypes(),\n this.mergedTypes(inputs),\n inputs.homePackage,\n );\n return this.render(inputs, contracts, selection, new BundledPlacement(names)).document;\n }\n\n /** ONE document, from the operations this selection accepts and nothing else. */\n private render(\n inputs: GenerationInputs,\n contracts: readonly ContractModel[],\n selection: DocumentSelection,\n placement: SchemaPlacement,\n ): RenderedDocument {\n const types = this.mergedTypes(inputs);\n const schemas = new SchemaRenderer(types, placement);\n const operations = new OperationRenderer(\n schemas,\n selection.includeMcpExtensions,\n selection.internalNotice,\n );\n const apiKey = this.singleApiKey(inputs, contracts, selection);\n const schemeNames = inputs.manifest.securitySchemeNames;\n const hoisted =\n apiKey !== undefined && this.everyOperationIsCovered(contracts, selection)\n ? this.security.requirement(schemeNames)\n : undefined;\n\n const contract = new ResponseContract(\n this.errorResponses(inputs),\n this.errorSchemaRef(inputs, schemas),\n this.headerRefs(inputs),\n );\n\n const paths = new JsonObject();\n const webhooks = new JsonObject();\n const tags = new JsonObject();\n for (const contractModel of contracts) {\n this.renderContract(\n contractModel,\n selection,\n operations,\n contract,\n this.webhookContract(),\n hoisted === undefined ? this.security.requirement(schemeNames) : undefined,\n paths,\n webhooks,\n tags,\n );\n }\n\n // The schemas are built HERE, after the operations, because building them is what walks a\n // DTO's fields — and an unmapped field can only be found by that walk. A guard that ran\n // before it would see only the top-level request and response refs and miss every one.\n const renderedSchemas = schemas.components().orUndefined();\n this.refuseUnmapped(schemas.unmapped(), selection.fileName, inputs.manifestPath);\n\n const components = new JsonObject()\n .set('schemas', renderedSchemas)\n .set(\n 'securitySchemes',\n this.security.addBuiltinSchemes(apiKey === undefined ? new JsonObject() : this.security.schemes(apiKey, schemeNames, inputs.manifestPath), this.selectedEndpoints(contracts, selection)).orUndefined(),\n )\n .set('headers', this.headers(inputs));\n\n const document = new JsonObject()\n .set('openapi', OPENAPI_VERSION)\n .set('info', this.info(inputs, selection))\n .set('servers', this.servers(inputs))\n .set('tags', this.tagList(tags))\n .set('security', hoisted === undefined ? undefined : hoisted.slice())\n .set('paths', paths)\n .set('webhooks', webhooks.orUndefined())\n .set('components', components.orUndefined());\n return new RenderedDocument(document, schemas);\n }\n\n /** Same-named, different declarations in one package, across every contract a document reads. */\n private collisionsOf(\n inputs: GenerationInputs,\n contracts: readonly ContractModel[],\n ): readonly TypeNameCollision[] {\n const models = contracts.map((each: ContractModel) => each.model);\n const all = inputs.errorType === undefined ? models : models.concat([inputs.errorType]);\n return all.flatMap((model: ApiDocModel) => Array.from(model.collisions));\n }\n\n /**\n * Two DIFFERENT declarations of one name in one package. A document defines each of its\n * package's schemas under its bare name, so one of the two would be published as the other's\n * shape. (Two packages' same-named types are not this: each is defined in its own package's\n * document — #1058's `LocalizedDescriptionsDto` case.)\n */\n private refuseCollisions(collisions: readonly TypeNameCollision[], where: string): void {\n if (collisions.length === 0) {\n return;\n }\n throw new OpenApiGenerationError(\n `${collisions.length} name(s) are declared twice in one package, so one document would ` +\n 'publish two different types under one name',\n where,\n 'Rename one declaration of each. Within one package a schema name is one type.',\n collisions.map(\n (each: TypeNameCollision) =>\n `${each.name} (${each.packageName ?? 'no package'}): ${each.firstLocation} and ${each.secondLocation}`,\n ),\n );\n }\n\n /**\n * FAIL CLOSED (#1058): every type this document references in another package must be a schema\n * of that package's published components document. A package that publishes none is refused —\n * naming the type, its package and the fix — rather than copied in, because silent copying is\n * exactly the duplication this replaces. A document that exists but lacks the schema is stale.\n */\n private refuseUnpublished(\n schemas: SchemaRenderer,\n types: ReadonlyMap<string, DocumentedType>,\n upstream: UpstreamComponentsIndex,\n fileName: string,\n where: string,\n ): void {\n const unpublished: string[] = [];\n const stale: string[] = [];\n for (const key of Array.from(schemas.externalTypes()).sort()) {\n const type = types.get(key)!;\n const owner = type.packageName;\n const declared = `${type.name} — declared in ${owner ?? 'no package'} (${type.location})`;\n if (owner === undefined) {\n unpublished.push(`${declared}: its file belongs to no package, so no document can own its schema`);\n continue;\n }\n const published = upstream.publishedBy(owner);\n if (published === undefined) {\n const reason = upstream.missingFor(owner)?.reason ?? 'it was never located';\n unpublished.push(`${declared}: ${owner} publishes no components document — ${reason}`);\n } else if (!published.schemaNames.has(type.name)) {\n stale.push(`${declared}: ${published.documentPath} has no schema '${type.name}'`);\n }\n }\n if (unpublished.length > 0) {\n throw new OpenApiGenerationError(\n `${unpublished.length} type(s) ${fileName} reaches are declared in a package that ` +\n 'publishes no components document',\n where,\n PUBLISH_COMPONENTS_CURE,\n unpublished,\n );\n }\n if (stale.length > 0) {\n throw new OpenApiGenerationError(\n `${stale.length} type(s) ${fileName} references are missing from their package's components document`,\n where,\n 'Regenerate the upstream components document before this one — it is older than its ' +\n 'source (in nx, \"^openapi-components-generate\" in this target\\'s dependsOn orders it).',\n stale,\n );\n }\n }\n\n /**\n * A webhook is served by the PARTNER, so neither our failure envelope nor the header we stamp on\n * our own responses is true of it. Publishing either would document their server, not ours.\n */\n private webhookContract(): ResponseContract {\n return new ResponseContract(new Map<string, string>(), undefined, undefined);\n }\n\n /** One contract's ACCEPTED endpoints, into `paths` or into `webhooks`. */\n private renderContract(\n contractModel: ContractModel,\n selection: DocumentSelection,\n operations: OperationRenderer,\n contract: ResponseContract,\n webhookContract: ResponseContract,\n perOperationSecurity: readonly JsonValue[] | undefined,\n paths: JsonObject,\n webhooks: JsonObject,\n tags: JsonObject,\n ): void {\n const model = contractModel.model;\n const tag = contractModel.entry.tag;\n for (const endpoint of model.endpoints) {\n if (!selection.acceptsEndpoint(endpoint)) {\n continue;\n }\n // A tag is added only by an operation that survived, so a document never advertises a\n // section of its sidebar that turns out to be empty.\n tags.set(tag, this.tagProse(model) ?? '');\n if (contractModel.entry.isWebhook()) {\n webhooks.set(\n this.eventName(endpoint),\n new JsonObject().set(\n 'post',\n operations.webhook(endpoint, model.contractName, tag, webhookContract),\n ),\n );\n continue;\n }\n const url = `${model.basePath}${endpoint.path}`;\n const existing = paths.get(url);\n const item = existing instanceof JsonObject ? existing : new JsonObject();\n item.set(\n endpoint.httpMethod.toLowerCase(),\n operations.operation(\n endpoint,\n model.contractName,\n tag,\n contract,\n this.security.operation(endpoint.auth, perOperationSecurity),\n ),\n );\n paths.set(url, item);\n }\n }\n\n /**\n * A webhook is keyed by the EVENT NAME, with the `@ApiPath` base deliberately NOT prepended.\n *\n * There is no url of ours here — the partner hosts the endpoint, at whatever path they choose —\n * so publishing `/our-base/delivered` would document a route that exists nowhere. What we are\n * naming is the event we will send.\n */\n private eventName(endpoint: DocumentedEndpoint): string {\n return endpoint.path.replace(/^\\/+/, '');\n }\n\n /**\n * Every named type from every contract, merged by MODEL KEY — which carries the declaring\n * package, so two packages' same-named types never meet here (#1058).\n *\n * Two contracts declaring DIFFERENT types under one key is a hard failure, not a first-wins\n * merge: `components.schemas` is keyed by name, so one of the two would be published as the\n * other's shape, and the operation referring to it would be quietly wrong.\n */\n private mergedTypes(inputs: GenerationInputs): ReadonlyMap<string, DocumentedType> {\n const merged = new Map<string, DocumentedType>();\n const sources = inputs.contracts.map((each: ContractModel) => each.model);\n const all = inputs.errorType === undefined ? sources : sources.concat([inputs.errorType]);\n for (const model of all) {\n for (const name of Array.from(model.types.keys())) {\n const incoming = model.types.get(name)!;\n const existing = merged.get(name);\n if (\n existing !== undefined &&\n this.signature(existing) !== this.signature(incoming)\n ) {\n throw new OpenApiGenerationError(\n `two different types are both named '${incoming.name}'`,\n `${model.contractName} (${inputs.manifestPath})`,\n 'Rename one of them. `components.schemas` is keyed by name, so one shape ' +\n 'would be published as the other.',\n );\n }\n merged.set(name, incoming);\n }\n }\n return merged;\n }\n\n /** Enough of a type's shape to tell two same-named types apart without comparing prose. */\n private signature(type: DocumentedType): string {\n const fields = type.fields.map((field: DocumentedField) => field.name).join(',');\n return `${fields}|${type.enumValues.join(',')}|${type.unionRefNames.join(',')}`;\n }\n\n /**\n * The ONE api-key regime this document publishes.\n *\n * Two regimes in one document is a hard failure: `securitySchemeNames` is a single ordered list,\n * so there is no honest way to say which regime a given name belongs to, and a document that\n * guessed would publish one regime's header names under the other's scheme keys.\n */\n private singleApiKey(\n inputs: GenerationInputs,\n contracts: readonly ContractModel[],\n selection: DocumentSelection,\n ): DocumentedApiKey | undefined {\n let found: DocumentedApiKey | undefined;\n for (const endpoint of this.selectedEndpoints(contracts, selection)) {\n const apiKey = endpoint.auth?.methods.find((method: DocumentedAuthMethod) => method.apiKey !== undefined)?.apiKey;\n if (apiKey === undefined) {\n continue;\n }\n if (found !== undefined && found.regime !== apiKey.regime) {\n throw new OpenApiGenerationError(\n `the ${selection.fileName} document mixes the api-key regimes ` +\n `'${found.regime}' ` +\n `and '${apiKey.regime}'`,\n inputs.manifestPath,\n 'Publish one regime per document — split the manifest, or move the ' +\n \"other regime's contract out of `apis`.\",\n );\n }\n found = apiKey;\n }\n return found;\n }\n\n /**\n * True when EVERY selected operation demands the credential, which is what licenses hoisting the\n * requirement to the document. A document that mixes credentialled and uncredentialled routes\n * stamps it per-operation instead — hoisting there would tell a partner that a public endpoint\n * needs a key.\n *\n * Judged per DOCUMENT, over the operations that document actually contains, because that is the\n * only question the document's own `security` block answers.\n */\n private everyOperationIsCovered(\n contracts: readonly ContractModel[],\n selection: DocumentSelection,\n ): boolean {\n const served = this.selectedEndpoints(contracts, selection);\n return (\n served.length > 0 &&\n served.every((e: DocumentedEndpoint) => e.auth?.methods.length === 1 && e.auth.methods[0].apiKey !== undefined)\n );\n }\n\n /**\n * The endpoints this selection accepts that are routes on OUR server. A webhook is somebody\n * else's route, so it never counts toward our security requirement or our regime.\n */\n private selectedEndpoints(\n contracts: readonly ContractModel[],\n selection: DocumentSelection,\n ): readonly DocumentedEndpoint[] {\n const served: DocumentedEndpoint[] = [];\n for (const contract of contracts) {\n if (contract.entry.isWebhook()) {\n continue;\n }\n for (const endpoint of contract.model.endpoints) {\n if (selection.acceptsEndpoint(endpoint)) {\n served.push(endpoint);\n }\n }\n }\n return served;\n }\n\n /** `info`, whose `description` is the ONE piece of prose that differs between the documents. */\n private info(inputs: GenerationInputs, selection: DocumentSelection): JsonObject {\n return new JsonObject()\n .set('title', inputs.manifest.title)\n .set('version', inputs.manifest.version)\n .set('description', selection.description(inputs.description));\n }\n\n private servers(inputs: GenerationInputs): readonly JsonValue[] | undefined {\n if (inputs.manifest.servers.length === 0) {\n return undefined;\n }\n return inputs.manifest.servers.map((server: ServerEntry) =>\n new JsonObject().set('url', server.url).set('description', server.description),\n );\n }\n\n /**\n * `tags[]` in MANIFEST ORDER, because that order IS the published sidebar — one of the two\n * orders in this document that carries meaning and is therefore NOT sorted.\n */\n private tagList(tags: JsonObject): readonly JsonValue[] | undefined {\n const list: JsonValue[] = [];\n for (const name of tags.keys()) {\n const prose = tags.get(name);\n list.push(\n new JsonObject()\n .set('name', name)\n .set('description', prose === '' ? undefined : prose),\n );\n }\n return list.length === 0 ? undefined : list;\n }\n\n private tagProse(model: ApiDocModel): string | undefined {\n return model.description.trim() === '' ? undefined : model.description;\n }\n\n private errorResponses(inputs: GenerationInputs): ReadonlyMap<string, string> {\n const responses = new Map<string, string>();\n for (const response of inputs.manifest.errors?.responses ?? []) {\n responses.set(response.status, response.description);\n }\n return responses;\n }\n\n private errorSchemaRef(\n inputs: GenerationInputs,\n schemas: SchemaRenderer,\n ): JsonObject | undefined {\n const errors = inputs.manifest.errors;\n if (errors === undefined || inputs.errorType === undefined) {\n return undefined;\n }\n // Rendering the reference is what puts the error body into `components.schemas`, so the\n // published shape is the compiler's answer about that TS type and not a hand-copied one.\n // The model key of a type its own file declares is its bare name (`DocumentedType.keyOf`).\n return schemas.type(TypeRef.ref(errors.type), '#/components/schemas/error');\n }\n\n /** `components.headers`, one entry per declared response header. */\n private headers(inputs: GenerationInputs): JsonObject | undefined {\n const headers = new JsonObject();\n for (const header of inputs.responseHeaders) {\n headers.set(\n header.headerName,\n new JsonObject()\n .set('description', header.description)\n .set('schema', new JsonObject().set('type', 'string')),\n );\n }\n return headers.orUndefined();\n }\n\n /** The `$ref`s every SUCCESS response carries at those headers. */\n private headerRefs(inputs: GenerationInputs): JsonObject | undefined {\n const refs = new JsonObject();\n for (const header of inputs.responseHeaders) {\n refs.set(\n header.headerName,\n new JsonObject().set('$ref', `#/components/headers/${header.headerName}`),\n );\n }\n return refs.orUndefined();\n }\n\n /**\n * The guard. An unmapped field is a published partner-facing field with no shape, and there is\n * deliberately no flag to switch this off — the cure is at the contract, by naming the type.\n */\n private refuseUnmapped(\n unmapped: readonly UnmappedField[],\n fileName: string,\n manifestPath: string,\n ): void {\n if (unmapped.length === 0) {\n return;\n }\n const pointers = unmapped.map(\n (field: UnmappedField) => `${field.pointer} (${field.typeText})`,\n );\n throw new OpenApiGenerationError(\n `${unmapped.length} field(s) in ${fileName} have no schema it can state`,\n manifestPath,\n 'Give each one a type a document can carry — a named DTO, an array of one, a ' +\n 'string-literal union, or Record<string, X>. An untyped field publishes as \"anything\".',\n pointers,\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"OpenApiGenerator.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/OpenApiGenerator.ts"],"names":[],"mappings":";;;AAAA,4DASkC;AAClC,mDAA2D;AAC3D,sEAAmE;AAEnE,yDAM4B;AAC5B,2DAAwD;AACxD,2DAA0E;AAC1E,uDAO2B;AAC3B,qDAAiE;AACjE,uDAAoD;AAGpD,uGAAuG;AACvG,MAAM,gBAAgB;IAEL;IACA;IAFb,YACa,QAAoB,EACpB,OAAuB;QADvB,aAAQ,GAAR,QAAQ,CAAY;QACpB,YAAO,GAAP,OAAO,CAAgB;IACjC,CAAC;CACP;AAED,8FAA8F;AAC9F,MAAM,cAAc,GAAG,UAAU,CAAC;AAElC,2EAA2E;AAC3E,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,uBAAuB,GACzB,6FAA6F;IAC7F,oGAAoG;IACpG,6FAA6F;IAC7F,sGAAsG;IACtG,mGAAmG;IACnG,8EAA8E,CAAC;AAEnF,4FAA4F;AAC5F,MAAM,eAAe,GAAG,OAAO,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAa,gBAAgB;IACR,QAAQ,GAAG,IAAI,iCAAe,EAAE,CAAC;IAElD;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAwB;QAC7B,MAAM,SAAS,GAAwB,EAAE,CAAC;QAC1C,KAAK,MAAM,SAAS,IAAI,qCAAiB,CAAC,GAAG,EAAE,EAAE,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ACD,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CACzB,CAAC,KAAoB,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,QAAQ,GAAG,CACnE,CAAC;QACF,MAAM,IAAI,+CAAsB,CAC5B,GAAG,QAAQ,CAAC,MAAM,gBAAgB,QAAQ,8BAA8B,EACxE,YAAY,EACZ,8EAA8E;YAC1E,uFAAuF,EAC3F,QAAQ,CACX,CAAC;IACN,CAAC;CACJ;AAhmBD,4CAgmBC","sourcesContent":["import {\n ApiDocModel,\n DocumentedApiKey,\n DocumentedAuthMethod,\n DocumentedEndpoint,\n DocumentedField,\n DocumentedType,\n TypeNameCollision,\n TypeRef,\n} from '@webpieces/api-doc-model';\nimport { JsonObject, JsonValue } from '../json/JsonObject';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\nimport { ServerEntry } from '../manifest/OpenApiManifest';\nimport {\n ComponentsInputs,\n ContractModel,\n GeneratedDocument,\n GeneratedDocuments,\n GenerationInputs,\n} from './GenerationInputs';\nimport { DocumentSelection } from './DocumentSelection';\nimport { OperationRenderer, ResponseContract } from './OperationRenderer';\nimport {\n BundledNames,\n BundledPlacement,\n ComponentsReference,\n DiscoveryPlacement,\n SchemaPlacement,\n SplitPlacement,\n} from './SchemaPlacement';\nimport { SchemaRenderer, UnmappedField } from './SchemaRenderer';\nimport { SecurityDeriver } from './SecurityDeriver';\nimport { UpstreamComponentsIndex } from './UpstreamComponents';\n\n/** One rendered document, and the renderer that built its schemas — what it defined and referenced. */\nclass RenderedDocument {\n constructor(\n readonly document: JsonObject,\n readonly schemas: SchemaRenderer,\n ) {}\n}\n\n/** The suffix of a split document's self-contained sibling: `public-openapi.bundled.json`. */\nconst BUNDLED_SUFFIX = '.bundled';\n\n/** The document a DTO library publishes, without its extension (#1058). */\nconst COMPONENTS_DOCUMENT = 'components.openapi';\n\n/**\n * Every cure for a type reached in a package that publishes no components document.\n *\n * Tagging is offered ONLY for a package that is already a role:api-lib DTO library (#1064, D5): a\n * general library such as `company-core` is refused the tag by validate-nx-wiring and by the\n * openapi-components-generate executor, so \"tag the package\" is never a way out of moving the type.\n */\nconst PUBLISH_COMPONENTS_CURE =\n 'Move each type into a role:api-lib DTO library that publishes a components document — as a ' +\n '`…Dto` string enum when it is a string-literal union. Only when the declaring package is ITSELF a ' +\n 'role:api-lib DTO library, tag it \"generate:openapi-components\" so it publishes one (with a ' +\n '\"kind\": \"components\" openapi.manifest.json naming its entry files; outside nx, render that manifest ' +\n 'with wp-openapi into the directory the package is packed from); a general library is refused the ' +\n \"tag. A document references another package's schema; it never copies one in.\";\n\n/** The OpenAPI version this generator writes. See the class doc for why 3.1 and not 3.0. */\nconst OPENAPI_VERSION = '3.1.0';\n\n/**\n * {@link GenerationInputs} -> one OpenAPI 3.1.0 document per `@ApiType` some contract declares.\n *\n * ## 3.1, because it is what the model can state HONESTLY\n *\n * `type: [T, \"null\"]` instead of a `nullable` keyword; a `description` legal beside a `$ref`; a\n * top-level `webhooks:` block. Each of those is a fact the model holds that 3.0 would have forced\n * this renderer to drop or to lie about. 3.1's schema dialect is also JSON Schema 2020-12, which is\n * what MCP `tools/list` speaks.\n *\n * ## ONE render function, called once per document\n *\n * ```\n * ApiDocModel --> render(selection) --+--> full-private-openapi.json SVC_TO_SVC contracts\n * +--> public-openapi.json EXTERNAL_CUSTOMER contracts, minus hidden methods\n * +--> mcp-openapi.json MCP contracts\n * ```\n *\n * `components.schemas` is built by walking OUTWARD from the operations the selection accepted, so an\n * unselected operation's DTOs are never constructed. See {@link DocumentSelection} for why that\n * asymmetry — a bug emits nothing, rather than shipping an unreleased feature's schemas with only\n * its URL removed — decides the whole design.\n *\n * ## It REFUSES to write an unmapped field\n *\n * An unmapped type renders as an empty schema, which in JSON Schema means \"anything\". Publishing one\n * is a green build handing a partner a field with no shape, so the guard names the JSON pointer of\n * every one and exits non-zero. There is deliberately NO flag to switch it off: the cure is at the\n * contract, by naming the type.\n */\nexport class OpenApiGenerator {\n private readonly security = new SecurityDeriver();\n\n /**\n * ONE document per `@ApiType` some contract declares, and no others.\n *\n * A document nobody asked for is not written empty — it is not written. That is the ONE\n * conditional in the whole pipeline, and it lives here rather than in three places: no contract\n * declaring `MCP` means no `mcp-openapi.json`, with no second \"is it empty?\" rule to keep in step\n * with the first.\n */\n generate(inputs: GenerationInputs): GeneratedDocuments {\n const documents: GeneratedDocument[] = [];\n for (const selection of DocumentSelection.all()) {\n const contracts = inputs.contracts.filter((each: ContractModel) =>\n selection.acceptsContract(each.model),\n );\n if (contracts.length === 0) {\n continue;\n }\n if (selection.inlinesEveryPackage) {\n documents.push(\n new GeneratedDocument(\n selection.fileName,\n this.bundled(inputs, contracts, selection),\n ),\n );\n continue;\n }\n this.refuseCollisions(this.collisionsOf(inputs, contracts), inputs.manifestPath);\n const split = this.render(\n inputs,\n contracts,\n selection,\n new SplitPlacement(inputs.homePackage),\n );\n this.refuseUnpublished(\n split.schemas,\n this.mergedTypes(inputs),\n inputs.upstream,\n selection.fileName,\n inputs.manifestPath,\n );\n documents.push(new GeneratedDocument(selection.fileName, split.document));\n documents.push(\n new GeneratedDocument(\n `${selection.fileName}${BUNDLED_SUFFIX}`,\n this.bundled(inputs, contracts, selection),\n ),\n );\n }\n return new GeneratedDocuments(documents);\n }\n\n /**\n * A DTO library's COMPONENTS-ONLY document (#1058): `openapi`, `info`, `x-webpieces-id` and\n * `components.schemas` — every type the library exports and declares, with every OTHER package's\n * type a `$ref` into that package's own components document, so a chain of DTO libraries is a\n * chain of documents of any depth.\n *\n * `info.version` is the PACKAGE version. The package-qualified URI downstream documents reference\n * it by (`@scope/pkg/components.openapi.json`) is stated as `x-webpieces-id`, because OpenAPI 3.1's\n * root object admits no `$id` — a 3.1 validator rejects one — and the document must validate on its\n * own.\n */\n components(inputs: ComponentsInputs): GeneratedDocument {\n const model = inputs.model;\n const where = inputs.manifestPath;\n this.refuseCollisions(model.collisions, where);\n const schemas = new SchemaRenderer(model.types, new SplitPlacement(model.packageName));\n for (const key of model.exported) {\n schemas.define(key);\n }\n const rendered = schemas.components();\n this.refuseUnmapped(schemas.unmapped(), COMPONENTS_DOCUMENT, where);\n this.refuseUnpublished(schemas, model.types, inputs.upstream, COMPONENTS_DOCUMENT, where);\n if (rendered.isEmpty()) {\n throw new OpenApiGenerationError(\n `${model.packageName}'s entries export no type with a schema`,\n where,\n 'Name the entry files that export the library\\'s DTOs and enums — usually \"src/index.ts\".',\n );\n }\n return new GeneratedDocument(\n COMPONENTS_DOCUMENT,\n new JsonObject()\n .set('openapi', OPENAPI_VERSION)\n .set(\n 'info',\n new JsonObject()\n .set('title', inputs.manifest.title)\n .set('version', model.packageVersion),\n )\n .set('x-webpieces-id', ComponentsReference.documentUri(model.packageName))\n .set('components', new JsonObject().set('schemas', rendered)),\n );\n }\n\n /**\n * The SELF-CONTAINED form of a document: every reached schema defined locally, whichever package\n * declares it — the `*.bundled.json` sibling of a split document, and the MCP projection.\n *\n * Two passes, because a schema's NAME depends on which other schemas the document reaches: the\n * first renders with every type under its unique model key just to learn the reached set, and the\n * second renders with the names {@link BundledNames} assigns from it. Rendering is a pure walk of\n * the model, so the second pass reaches exactly what the first did.\n */\n private bundled(\n inputs: GenerationInputs,\n contracts: readonly ContractModel[],\n selection: DocumentSelection,\n ): JsonObject {\n const discovery = this.render(inputs, contracts, selection, new DiscoveryPlacement());\n const names = BundledNames.assign(\n discovery.schemas.reachedTypes(),\n this.mergedTypes(inputs),\n inputs.homePackage,\n );\n return this.render(inputs, contracts, selection, new BundledPlacement(names)).document;\n }\n\n /** ONE document, from the operations this selection accepts and nothing else. */\n private render(\n inputs: GenerationInputs,\n contracts: readonly ContractModel[],\n selection: DocumentSelection,\n placement: SchemaPlacement,\n ): RenderedDocument {\n const types = this.mergedTypes(inputs);\n const schemas = new SchemaRenderer(types, placement);\n const operations = new OperationRenderer(\n schemas,\n selection.includeMcpExtensions,\n selection.internalNotice,\n );\n const apiKey = this.singleApiKey(inputs, contracts, selection);\n const schemeNames = inputs.manifest.securitySchemeNames;\n const hoisted =\n apiKey !== undefined && this.everyOperationIsCovered(contracts, selection)\n ? this.security.requirement(schemeNames)\n : undefined;\n\n const contract = new ResponseContract(\n this.errorResponses(inputs),\n this.errorSchemaRef(inputs, schemas),\n this.headerRefs(inputs),\n );\n\n const paths = new JsonObject();\n const webhooks = new JsonObject();\n const tags = new JsonObject();\n for (const contractModel of contracts) {\n this.renderContract(\n contractModel,\n selection,\n operations,\n contract,\n this.webhookContract(),\n hoisted === undefined ? this.security.requirement(schemeNames) : undefined,\n paths,\n webhooks,\n tags,\n );\n }\n\n // The schemas are built HERE, after the operations, because building them is what walks a\n // DTO's fields — and an unmapped field can only be found by that walk. A guard that ran\n // before it would see only the top-level request and response refs and miss every one.\n const renderedSchemas = schemas.components().orUndefined();\n this.refuseUnmapped(schemas.unmapped(), selection.fileName, inputs.manifestPath);\n\n const components = new JsonObject()\n .set('schemas', renderedSchemas)\n .set(\n 'securitySchemes',\n this.renderSecuritySchemes(inputs, contracts, selection, apiKey),\n )\n .set('headers', this.headers(inputs));\n\n const document = new JsonObject()\n .set('openapi', OPENAPI_VERSION)\n .set('info', this.info(inputs, selection))\n .set('servers', this.servers(inputs))\n .set('tags', this.tagList(tags))\n .set('security', hoisted === undefined ? undefined : hoisted.slice())\n .set('paths', paths)\n .set('webhooks', webhooks.orUndefined())\n .set('components', components.orUndefined());\n return new RenderedDocument(document, schemas);\n }\n\n private renderSecuritySchemes(\n inputs: GenerationInputs,\n contracts: readonly ContractModel[],\n selection: DocumentSelection,\n apiKey: DocumentedApiKey | undefined,\n ): JsonObject | undefined {\n const schemes =\n apiKey === undefined\n ? new JsonObject()\n : this.security.schemes(\n apiKey,\n inputs.manifest.securitySchemeNames,\n inputs.manifestPath,\n );\n return this.security\n .addBuiltinSchemes(schemes, this.selectedEndpoints(contracts, selection))\n .orUndefined();\n }\n\n /** Same-named, different declarations in one package, across every contract a document reads. */\n private collisionsOf(\n inputs: GenerationInputs,\n contracts: readonly ContractModel[],\n ): readonly TypeNameCollision[] {\n const models = contracts.map((each: ContractModel) => each.model);\n const all = inputs.errorType === undefined ? models : models.concat([inputs.errorType]);\n return all.flatMap((model: ApiDocModel) => Array.from(model.collisions));\n }\n\n /**\n * Two DIFFERENT declarations of one name in one package. A document defines each of its\n * package's schemas under its bare name, so one of the two would be published as the other's\n * shape. (Two packages' same-named types are not this: each is defined in its own package's\n * document — #1058's `LocalizedDescriptionsDto` case.)\n */\n private refuseCollisions(collisions: readonly TypeNameCollision[], where: string): void {\n if (collisions.length === 0) {\n return;\n }\n throw new OpenApiGenerationError(\n `${collisions.length} name(s) are declared twice in one package, so one document would ` +\n 'publish two different types under one name',\n where,\n 'Rename one declaration of each. Within one package a schema name is one type.',\n collisions.map(\n (each: TypeNameCollision) =>\n `${each.name} (${each.packageName ?? 'no package'}): ${each.firstLocation} and ${each.secondLocation}`,\n ),\n );\n }\n\n /**\n * FAIL CLOSED (#1058): every type this document references in another package must be a schema\n * of that package's published components document. A package that publishes none is refused —\n * naming the type, its package and the fix — rather than copied in, because silent copying is\n * exactly the duplication this replaces. A document that exists but lacks the schema is stale.\n */\n private refuseUnpublished(\n schemas: SchemaRenderer,\n types: ReadonlyMap<string, DocumentedType>,\n upstream: UpstreamComponentsIndex,\n fileName: string,\n where: string,\n ): void {\n const unpublished: string[] = [];\n const stale: string[] = [];\n for (const key of Array.from(schemas.externalTypes()).sort()) {\n const type = types.get(key)!;\n const owner = type.packageName;\n const declared = `${type.name} — declared in ${owner ?? 'no package'} (${type.location})`;\n if (owner === undefined) {\n unpublished.push(\n `${declared}: its file belongs to no package, so no document can own its schema`,\n );\n continue;\n }\n const published = upstream.publishedBy(owner);\n if (published === undefined) {\n const reason = upstream.missingFor(owner)?.reason ?? 'it was never located';\n unpublished.push(\n `${declared}: ${owner} publishes no components document — ${reason}`,\n );\n } else if (!published.schemaNames.has(type.schemaName)) {\n stale.push(\n `${declared}: ${published.documentPath} has no schema '${type.schemaName}'`,\n );\n }\n }\n if (unpublished.length > 0) {\n throw new OpenApiGenerationError(\n `${unpublished.length} type(s) ${fileName} reaches are declared in a package that ` +\n 'publishes no components document',\n where,\n PUBLISH_COMPONENTS_CURE,\n unpublished,\n );\n }\n if (stale.length > 0) {\n throw new OpenApiGenerationError(\n `${stale.length} type(s) ${fileName} references are missing from their package's components document`,\n where,\n 'Regenerate the upstream components document before this one — it is older than its ' +\n 'source (in nx, \"^openapi-components-generate\" in this target\\'s dependsOn orders it).',\n stale,\n );\n }\n }\n\n /**\n * A webhook is served by the PARTNER, so neither our failure envelope nor the header we stamp on\n * our own responses is true of it. Publishing either would document their server, not ours.\n */\n private webhookContract(): ResponseContract {\n return new ResponseContract(new Map<string, string>(), undefined, undefined);\n }\n\n /** One contract's ACCEPTED endpoints, into `paths` or into `webhooks`. */\n private renderContract(\n contractModel: ContractModel,\n selection: DocumentSelection,\n operations: OperationRenderer,\n contract: ResponseContract,\n webhookContract: ResponseContract,\n perOperationSecurity: readonly JsonValue[] | undefined,\n paths: JsonObject,\n webhooks: JsonObject,\n tags: JsonObject,\n ): void {\n const model = contractModel.model;\n const tag = contractModel.entry.tag;\n for (const endpoint of model.endpoints) {\n if (!selection.acceptsEndpoint(endpoint)) {\n continue;\n }\n // A tag is added only by an operation that survived, so a document never advertises a\n // section of its sidebar that turns out to be empty.\n tags.set(tag, this.tagProse(model) ?? '');\n if (contractModel.entry.isWebhook()) {\n webhooks.set(\n this.eventName(endpoint),\n new JsonObject().set(\n 'post',\n operations.webhook(endpoint, model.contractName, tag, webhookContract),\n ),\n );\n continue;\n }\n const url = `${model.basePath}${endpoint.path}`;\n const existing = paths.get(url);\n const item = existing instanceof JsonObject ? existing : new JsonObject();\n item.set(\n endpoint.httpMethod.toLowerCase(),\n operations.operation(\n endpoint,\n model.contractName,\n tag,\n contract,\n this.security.operation(endpoint.auth, perOperationSecurity),\n ),\n );\n paths.set(url, item);\n }\n }\n\n /**\n * A webhook is keyed by the EVENT NAME, with the `@ApiPath` base deliberately NOT prepended.\n *\n * There is no url of ours here — the partner hosts the endpoint, at whatever path they choose —\n * so publishing `/our-base/delivered` would document a route that exists nowhere. What we are\n * naming is the event we will send.\n */\n private eventName(endpoint: DocumentedEndpoint): string {\n return endpoint.path.replace(/^\\/+/, '');\n }\n\n /**\n * Every named type from every contract, merged by MODEL KEY — which carries the declaring\n * package, so two packages' same-named types never meet here (#1058).\n *\n * Two contracts declaring DIFFERENT types under one key is a hard failure, not a first-wins\n * merge: `components.schemas` is keyed by name, so one of the two would be published as the\n * other's shape, and the operation referring to it would be quietly wrong.\n */\n private mergedTypes(inputs: GenerationInputs): ReadonlyMap<string, DocumentedType> {\n const merged = new Map<string, DocumentedType>();\n const published = new Map<string, DocumentedType>();\n const sources = inputs.contracts.map((each: ContractModel) => each.model);\n const all = inputs.errorType === undefined ? sources : sources.concat([inputs.errorType]);\n for (const model of all) {\n for (const name of Array.from(model.types.keys())) {\n const incoming = model.types.get(name)!;\n const previous = published.get(incoming.schemaName);\n if (\n previous !== undefined &&\n previous.location !== incoming.location &&\n (previous.name !== previous.schemaName || incoming.name !== incoming.schemaName)\n ) {\n throw new OpenApiGenerationError(\n `stripped schema name '${incoming.schemaName}' collides: '${previous.name}' at ${previous.location} and '${incoming.name}' at ${incoming.location}`,\n inputs.manifestPath,\n 'Change schemaNames so every reached declaration has a distinct published name.',\n );\n }\n published.set(incoming.schemaName, incoming);\n const existing = merged.get(name);\n if (\n existing !== undefined &&\n this.signature(existing) !== this.signature(incoming)\n ) {\n throw new OpenApiGenerationError(\n `two different types are both named '${incoming.name}'`,\n `${model.contractName} (${inputs.manifestPath})`,\n 'Rename one of them. `components.schemas` is keyed by name, so one shape ' +\n 'would be published as the other.',\n );\n }\n merged.set(name, incoming);\n }\n }\n return merged;\n }\n\n /** Enough of a type's shape to tell two same-named types apart without comparing prose. */\n private signature(type: DocumentedType): string {\n const fields = type.fields.map((field: DocumentedField) => field.name).join(',');\n return `${fields}|${type.enumValues.join(',')}|${type.unionRefNames.join(',')}`;\n }\n\n /**\n * The ONE api-key regime this document publishes.\n *\n * Two regimes in one document is a hard failure: `securitySchemeNames` is a single ordered list,\n * so there is no honest way to say which regime a given name belongs to, and a document that\n * guessed would publish one regime's header names under the other's scheme keys.\n */\n private singleApiKey(\n inputs: GenerationInputs,\n contracts: readonly ContractModel[],\n selection: DocumentSelection,\n ): DocumentedApiKey | undefined {\n let found: DocumentedApiKey | undefined;\n for (const endpoint of this.selectedEndpoints(contracts, selection)) {\n const apiKey = endpoint.auth?.methods.find(\n (method: DocumentedAuthMethod) => method.apiKey !== undefined,\n )?.apiKey;\n if (apiKey === undefined) {\n continue;\n }\n if (found !== undefined && found.regime !== apiKey.regime) {\n throw new OpenApiGenerationError(\n `the ${selection.fileName} document mixes the api-key regimes ` +\n `'${found.regime}' ` +\n `and '${apiKey.regime}'`,\n inputs.manifestPath,\n 'Publish one regime per document — split the manifest, or move the ' +\n \"other regime's contract out of `apis`.\",\n );\n }\n found = apiKey;\n }\n return found;\n }\n\n /**\n * True when EVERY selected operation demands the credential, which is what licenses hoisting the\n * requirement to the document. A document that mixes credentialled and uncredentialled routes\n * stamps it per-operation instead — hoisting there would tell a partner that a public endpoint\n * needs a key.\n *\n * Judged per DOCUMENT, over the operations that document actually contains, because that is the\n * only question the document's own `security` block answers.\n */\n private everyOperationIsCovered(\n contracts: readonly ContractModel[],\n selection: DocumentSelection,\n ): boolean {\n const served = this.selectedEndpoints(contracts, selection);\n return (\n served.length > 0 &&\n served.every(\n (e: DocumentedEndpoint) =>\n e.auth?.methods.length === 1 && e.auth.methods[0].apiKey !== undefined,\n )\n );\n }\n\n /**\n * The endpoints this selection accepts that are routes on OUR server. A webhook is somebody\n * else's route, so it never counts toward our security requirement or our regime.\n */\n private selectedEndpoints(\n contracts: readonly ContractModel[],\n selection: DocumentSelection,\n ): readonly DocumentedEndpoint[] {\n const served: DocumentedEndpoint[] = [];\n for (const contract of contracts) {\n if (contract.entry.isWebhook()) {\n continue;\n }\n for (const endpoint of contract.model.endpoints) {\n if (selection.acceptsEndpoint(endpoint)) {\n served.push(endpoint);\n }\n }\n }\n return served;\n }\n\n /** `info`, whose `description` is the ONE piece of prose that differs between the documents. */\n private info(inputs: GenerationInputs, selection: DocumentSelection): JsonObject {\n return new JsonObject()\n .set('title', inputs.manifest.title)\n .set('version', inputs.manifest.version)\n .set('description', selection.description(inputs.description));\n }\n\n private servers(inputs: GenerationInputs): readonly JsonValue[] | undefined {\n if (inputs.manifest.servers.length === 0) {\n return undefined;\n }\n return inputs.manifest.servers.map((server: ServerEntry) =>\n new JsonObject().set('url', server.url).set('description', server.description),\n );\n }\n\n /**\n * `tags[]` in MANIFEST ORDER, because that order IS the published sidebar — one of the two\n * orders in this document that carries meaning and is therefore NOT sorted.\n */\n private tagList(tags: JsonObject): readonly JsonValue[] | undefined {\n const list: JsonValue[] = [];\n for (const name of tags.keys()) {\n const prose = tags.get(name);\n list.push(\n new JsonObject()\n .set('name', name)\n .set('description', prose === '' ? undefined : prose),\n );\n }\n return list.length === 0 ? undefined : list;\n }\n\n private tagProse(model: ApiDocModel): string | undefined {\n return model.description.trim() === '' ? undefined : model.description;\n }\n\n private errorResponses(inputs: GenerationInputs): ReadonlyMap<string, string> {\n const responses = new Map<string, string>();\n for (const response of inputs.manifest.errors?.responses ?? []) {\n responses.set(response.status, response.description);\n }\n return responses;\n }\n\n private errorSchemaRef(\n inputs: GenerationInputs,\n schemas: SchemaRenderer,\n ): JsonObject | undefined {\n const errors = inputs.manifest.errors;\n if (errors === undefined || inputs.errorType === undefined) {\n return undefined;\n }\n // Rendering the reference is what puts the error body into `components.schemas`, so the\n // published shape is the compiler's answer about that TS type and not a hand-copied one.\n // The model key of a type its own file declares is its bare name (`DocumentedType.keyOf`).\n return schemas.type(TypeRef.ref(errors.type), '#/components/schemas/error');\n }\n\n /** `components.headers`, one entry per declared response header. */\n private headers(inputs: GenerationInputs): JsonObject | undefined {\n const headers = new JsonObject();\n for (const header of inputs.responseHeaders) {\n headers.set(\n header.headerName,\n new JsonObject()\n .set('description', header.description)\n .set('schema', new JsonObject().set('type', 'string')),\n );\n }\n return headers.orUndefined();\n }\n\n /** The `$ref`s every SUCCESS response carries at those headers. */\n private headerRefs(inputs: GenerationInputs): JsonObject | undefined {\n const refs = new JsonObject();\n for (const header of inputs.responseHeaders) {\n refs.set(\n header.headerName,\n new JsonObject().set('$ref', `#/components/headers/${header.headerName}`),\n );\n }\n return refs.orUndefined();\n }\n\n /**\n * The guard. An unmapped field is a published partner-facing field with no shape, and there is\n * deliberately no flag to switch this off — the cure is at the contract, by naming the type.\n */\n private refuseUnmapped(\n unmapped: readonly UnmappedField[],\n fileName: string,\n manifestPath: string,\n ): void {\n if (unmapped.length === 0) {\n return;\n }\n const pointers = unmapped.map(\n (field: UnmappedField) => `${field.pointer} (${field.typeText})`,\n );\n throw new OpenApiGenerationError(\n `${unmapped.length} field(s) in ${fileName} have no schema it can state`,\n manifestPath,\n 'Give each one a type a document can carry — a named DTO, an array of one, a ' +\n 'string-literal union, or Record<string, X>. An untyped field publishes as \"anything\".',\n pointers,\n );\n }\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BundledNames = exports.DiscoveryPlacement = exports.BundledPlacement = exports.SplitPlacement = exports.ComponentsReference = void 0;
|
|
4
|
+
const OpenApiGenerationError_1 = require("../OpenApiGenerationError");
|
|
4
5
|
const core_util_1 = require("@webpieces/core-util");
|
|
5
6
|
const LOCAL_POINTER = '#/components/schemas/';
|
|
6
7
|
/**
|
|
@@ -35,13 +36,13 @@ class SplitPlacement {
|
|
|
35
36
|
return type.packageName === this.homePackage;
|
|
36
37
|
}
|
|
37
38
|
localName(_key, type) {
|
|
38
|
-
return type.
|
|
39
|
+
return type.schemaName;
|
|
39
40
|
}
|
|
40
41
|
pointer(key, type) {
|
|
41
42
|
if (this.isLocal(key, type)) {
|
|
42
|
-
return `${LOCAL_POINTER}${type.
|
|
43
|
+
return `${LOCAL_POINTER}${type.schemaName}`;
|
|
43
44
|
}
|
|
44
|
-
return ComponentsReference.to(type.packageName ?? '<no package>', type.
|
|
45
|
+
return ComponentsReference.to(type.packageName ?? '<no package>', type.schemaName);
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
exports.SplitPlacement = SplitPlacement;
|
|
@@ -58,7 +59,7 @@ class BundledPlacement {
|
|
|
58
59
|
return true;
|
|
59
60
|
}
|
|
60
61
|
localName(key, type) {
|
|
61
|
-
return this.names.get(key) ?? type.
|
|
62
|
+
return this.names.get(key) ?? type.schemaName;
|
|
62
63
|
}
|
|
63
64
|
pointer(key, type) {
|
|
64
65
|
return `${LOCAL_POINTER}${this.localName(key, type)}`;
|
|
@@ -100,13 +101,18 @@ class BundledNames {
|
|
|
100
101
|
if (type === undefined) {
|
|
101
102
|
continue;
|
|
102
103
|
}
|
|
103
|
-
const group = byName.get(type.
|
|
104
|
+
const group = byName.get(type.schemaName) ?? [];
|
|
104
105
|
group.push(key);
|
|
105
|
-
byName.set(type.
|
|
106
|
+
byName.set(type.schemaName, group);
|
|
106
107
|
}
|
|
107
108
|
const names = new Map();
|
|
108
109
|
for (const name of byName.keys()) {
|
|
109
110
|
const keys = byName.get(name);
|
|
111
|
+
const declarations = keys.map((key) => types.get(key));
|
|
112
|
+
if (keys.length > 1 &&
|
|
113
|
+
declarations.some((type) => type.name !== type.schemaName)) {
|
|
114
|
+
throw new OpenApiGenerationError_1.OpenApiGenerationError(`stripped schema name '${name}' collides: ${declarations.map((type) => `'${type.name}' at ${type.location}`).join(' and ')}`, '<bundled document>', 'Change schemaNames so every reached declaration has a distinct published name.');
|
|
115
|
+
}
|
|
110
116
|
for (const key of keys) {
|
|
111
117
|
const type = types.get(key);
|
|
112
118
|
const keepsBareName = keys.length === 1 || type.packageName === homePackage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaPlacement.js","sourceRoot":"","sources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C;YAC/B,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;YAC/B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;gBACrB,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;gBAC7B,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,WAAW,KAAK,WAAW,CAAC;gBAC5E,KAAK,CAAC,GAAG,CACL,GAAG,EACH,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CACxE,CAAC;YACN,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,sGAAsG;IACtG,qFAAqF;IAC7E,MAAM,CAAC,SAAS,CAAC,WAA+B,EAAE,IAAY;QAClE,MAAM,KAAK,GAAG,CAAC,WAAW,IAAI,YAAY,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAClF,OAAO,GAAG,KAAK,IAAI,IAAI,EAAE,CAAC,OAAO,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC;IAChE,CAAC;CACJ;AAtCD,oCAsCC","sourcesContent":["import { DocumentedType } from '@webpieces/api-doc-model';\nimport { GeneratedApiDocsLayout } from '@webpieces/core-util';\n\n/**\n * WHERE a named type's schema lives, from the point of view of ONE document being rendered (#1058).\n *\n * The model keys every type by its declaring package (`DocumentedType.keyOf`); a placement turns that\n * into the two facts a renderer needs — whether the schema is defined in THIS document's\n * `components.schemas` (and under what name), or referenced in another package's document — so the\n * three output forms are one renderer with three placements, not three renderers that could drift:\n *\n * | placement | used for | other packages' types |\n * |---|---|---|\n * | {@link SplitPlacement} | `full-private-openapi.json`, `public-openapi.json`, `components.openapi.json` | `$ref` into `<package>/components.openapi.json` |\n * | {@link BundledPlacement} | `*.bundled.json`, `mcp-openapi.json` | defined locally, renamed only on a name clash |\n * | {@link DiscoveryPlacement} | the first pass of a bundled render | defined locally under their unique key |\n */\nexport interface SchemaPlacement {\n /** True when `type` is defined in this document's own `components.schemas`. */\n isLocal(key: string, type: DocumentedType): boolean;\n /** The `components.schemas` key a LOCAL type is defined under. */\n localName(key: string, type: DocumentedType): string;\n /** The `$ref` value a reference to `type` is written as. */\n pointer(key: string, type: DocumentedType): string;\n}\n\nconst LOCAL_POINTER = '#/components/schemas/';\n\n/**\n * The package-qualified reference into a package's components document — decision 3 of #1058:\n * `@scope/pkg/components.openapi.json#/components/schemas/X`, resolved by the same package lookup\n * `McpToolCatalog.fromPackages` uses rather than by a `dist/` path.\n */\nexport class ComponentsReference {\n // webpieces-disable no-function-outside-class -- static helper on the class that owns the URI form\n static documentUri(packageName: string): string {\n return `${packageName}/${GeneratedApiDocsLayout.COMPONENTS_FILE}`;\n }\n\n // webpieces-disable no-function-outside-class -- static helper on the class that owns the URI form\n static to(packageName: string, schemaName: string): string {\n return `${ComponentsReference.documentUri(packageName)}#/components/schemas/${schemaName}`;\n }\n}\n\n/**\n * The SPLIT form: a schema is defined in the document of the package that declares it, and every\n * other package's schema is a `$ref` into that package's `components.openapi.json`. One owner per\n * schema — which is what removes both the duplicate copies and the name collisions of a flat namespace.\n */\nexport class SplitPlacement implements SchemaPlacement {\n constructor(\n /** The package this document is published by. */\n private readonly homePackage: string | undefined,\n ) {}\n\n isLocal(_key: string, type: DocumentedType): boolean {\n return type.packageName === this.homePackage;\n }\n\n localName(_key: string, type: DocumentedType): string {\n return type.name;\n }\n\n pointer(key: string, type: DocumentedType): string {\n if (this.isLocal(key, type)) {\n return `${LOCAL_POINTER}${type.name}`;\n }\n return ComponentsReference.to(type.packageName ?? '<no package>', type.name);\n }\n}\n\n/**\n * The BUNDLED form: every schema is defined locally, so the document has no external reference and\n * validates on its own. Names are assigned by {@link BundledNames}.\n */\nexport class BundledPlacement implements SchemaPlacement {\n constructor(private readonly names: ReadonlyMap<string, string>) {}\n\n isLocal(): boolean {\n return true;\n }\n\n localName(key: string, type: DocumentedType): string {\n return this.names.get(key) ?? type.name;\n }\n\n pointer(key: string, type: DocumentedType): string {\n return `${LOCAL_POINTER}${this.localName(key, type)}`;\n }\n}\n\n/**\n * The first pass of a bundled render, run only to learn WHICH types the document reaches: every type\n * is local under its unique model key, so nothing can collide before the names are chosen.\n */\nexport class DiscoveryPlacement implements SchemaPlacement {\n isLocal(): boolean {\n return true;\n }\n\n localName(key: string): string {\n return key;\n }\n\n pointer(key: string): string {\n return `${LOCAL_POINTER}${key}`;\n }\n}\n\n/**\n * The `components.schemas` names of a BUNDLED document.\n *\n * Every type keeps its own name unless two packages' types of ONE name are both reached — the\n * `LocalizedDescriptionsDto` case of #1058, which the split form keeps apart by keeping them in two\n * documents. A bundled document has one namespace, so then the home package's type keeps the bare\n * name and every other package's is qualified by its package (`myorg.lang-api-dtos.X`, in the\n * characters a components key may hold). Renaming only on a clash keeps every ordinary bundled\n * document identical to the split one wherever the split one defines the schema itself.\n */\nexport class BundledNames {\n // webpieces-disable no-function-outside-class -- static factory of this class\n static assign(\n reached: Iterable<string>,\n types: ReadonlyMap<string, DocumentedType>,\n homePackage: string | undefined,\n ): ReadonlyMap<string, string> {\n const byName = new Map<string, string[]>();\n for (const key of reached) {\n const type = types.get(key);\n if (type === undefined) {\n continue;\n }\n const group = byName.get(type.name) ?? [];\n group.push(key);\n byName.set(type.name, group);\n }\n const names = new Map<string, string>();\n for (const name of byName.keys()) {\n const keys = byName.get(name)!;\n for (const key of keys) {\n const type = types.get(key)!;\n const keepsBareName = keys.length === 1 || type.packageName === homePackage;\n names.set(\n key,\n keepsBareName ? name : BundledNames.qualified(type.packageName, name),\n );\n }\n }\n return names;\n }\n\n /** `@myorg/lang-api-dtos` + `X` → `myorg.lang-api-dtos.X` — `^[a-zA-Z0-9.\\-_]+$`, as 3.1 requires. */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static qualified(packageName: string | undefined, name: string): string {\n const owner = (packageName ?? 'no-package').replace(/^@/, '').replace(/\\//g, '.');\n return `${owner}.${name}`.replace(/[^A-Za-z0-9.\\-_]/g, '_');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SchemaPlacement.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/SchemaPlacement.ts"],"names":[],"mappings":";;;AAAA,sEAAmE;AAEnE,oDAA8D;AAyB9D,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAE9C;;;;GAIG;AACH,MAAa,mBAAmB;IAC5B,mGAAmG;IACnG,MAAM,CAAC,WAAW,CAAC,WAAmB;QAClC,OAAO,GAAG,WAAW,IAAI,kCAAsB,CAAC,eAAe,EAAE,CAAC;IACtE,CAAC;IAED,mGAAmG;IACnG,MAAM,CAAC,EAAE,CAAC,WAAmB,EAAE,UAAkB;QAC7C,OAAO,GAAG,mBAAmB,CAAC,WAAW,CAAC,WAAW,CAAC,wBAAwB,UAAU,EAAE,CAAC;IAC/F,CAAC;CACJ;AAVD,kDAUC;AAED;;;;GAIG;AACH,MAAa,cAAc;IAGF;IAFrB;IACI,iDAAiD;IAChC,WAA+B;QAA/B,gBAAW,GAAX,WAAW,CAAoB;IACjD,CAAC;IAEJ,OAAO,CAAC,IAAY,EAAE,IAAoB;QACtC,OAAO,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,WAAW,CAAC;IACjD,CAAC;IAED,SAAS,CAAC,IAAY,EAAE,IAAoB;QACxC,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED,OAAO,CAAC,GAAW,EAAE,IAAoB;QACrC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;YAC1B,OAAO,GAAG,aAAa,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAChD,CAAC;QACD,OAAO,mBAAmB,CAAC,EAAE,CAAC,IAAI,CA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AAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,sGAAsG;IACtG,qFAAqF;IAC7E,MAAM,CAAC,SAAS,CAAC,WAA+B,EAAE,IAAY;QAClE,MAAM,KAAK,GAAG,CAAC,WAAW,IAAI,YAAY,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAClF,OAAO,GAAG,KAAK,IAAI,IAAI,EAAE,CAAC,OAAO,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC;IAChE,CAAC;CACJ;AAjDD,oCAiDC","sourcesContent":["import { OpenApiGenerationError } from '../OpenApiGenerationError';\nimport { DocumentedType } from '@webpieces/api-doc-model';\nimport { GeneratedApiDocsLayout } from '@webpieces/core-util';\n\n/**\n * WHERE a named type's schema lives, from the point of view of ONE document being rendered (#1058).\n *\n * The model keys every type by its declaring package (`DocumentedType.keyOf`); a placement turns that\n * into the two facts a renderer needs — whether the schema is defined in THIS document's\n * `components.schemas` (and under what name), or referenced in another package's document — so the\n * three output forms are one renderer with three placements, not three renderers that could drift:\n *\n * | placement | used for | other packages' types |\n * |---|---|---|\n * | {@link SplitPlacement} | `full-private-openapi.json`, `public-openapi.json`, `components.openapi.json` | `$ref` into `<package>/components.openapi.json` |\n * | {@link BundledPlacement} | `*.bundled.json`, `mcp-openapi.json` | defined locally, renamed only on a name clash |\n * | {@link DiscoveryPlacement} | the first pass of a bundled render | defined locally under their unique key |\n */\nexport interface SchemaPlacement {\n /** True when `type` is defined in this document's own `components.schemas`. */\n isLocal(key: string, type: DocumentedType): boolean;\n /** The `components.schemas` key a LOCAL type is defined under. */\n localName(key: string, type: DocumentedType): string;\n /** The `$ref` value a reference to `type` is written as. */\n pointer(key: string, type: DocumentedType): string;\n}\n\nconst LOCAL_POINTER = '#/components/schemas/';\n\n/**\n * The package-qualified reference into a package's components document — decision 3 of #1058:\n * `@scope/pkg/components.openapi.json#/components/schemas/X`, resolved by the same package lookup\n * `McpToolCatalog.fromPackages` uses rather than by a `dist/` path.\n */\nexport class ComponentsReference {\n // webpieces-disable no-function-outside-class -- static helper on the class that owns the URI form\n static documentUri(packageName: string): string {\n return `${packageName}/${GeneratedApiDocsLayout.COMPONENTS_FILE}`;\n }\n\n // webpieces-disable no-function-outside-class -- static helper on the class that owns the URI form\n static to(packageName: string, schemaName: string): string {\n return `${ComponentsReference.documentUri(packageName)}#/components/schemas/${schemaName}`;\n }\n}\n\n/**\n * The SPLIT form: a schema is defined in the document of the package that declares it, and every\n * other package's schema is a `$ref` into that package's `components.openapi.json`. One owner per\n * schema — which is what removes both the duplicate copies and the name collisions of a flat namespace.\n */\nexport class SplitPlacement implements SchemaPlacement {\n constructor(\n /** The package this document is published by. */\n private readonly homePackage: string | undefined,\n ) {}\n\n isLocal(_key: string, type: DocumentedType): boolean {\n return type.packageName === this.homePackage;\n }\n\n localName(_key: string, type: DocumentedType): string {\n return type.schemaName;\n }\n\n pointer(key: string, type: DocumentedType): string {\n if (this.isLocal(key, type)) {\n return `${LOCAL_POINTER}${type.schemaName}`;\n }\n return ComponentsReference.to(type.packageName ?? '<no package>', type.schemaName);\n }\n}\n\n/**\n * The BUNDLED form: every schema is defined locally, so the document has no external reference and\n * validates on its own. Names are assigned by {@link BundledNames}.\n */\nexport class BundledPlacement implements SchemaPlacement {\n constructor(private readonly names: ReadonlyMap<string, string>) {}\n\n isLocal(): boolean {\n return true;\n }\n\n localName(key: string, type: DocumentedType): string {\n return this.names.get(key) ?? type.schemaName;\n }\n\n pointer(key: string, type: DocumentedType): string {\n return `${LOCAL_POINTER}${this.localName(key, type)}`;\n }\n}\n\n/**\n * The first pass of a bundled render, run only to learn WHICH types the document reaches: every type\n * is local under its unique model key, so nothing can collide before the names are chosen.\n */\nexport class DiscoveryPlacement implements SchemaPlacement {\n isLocal(): boolean {\n return true;\n }\n\n localName(key: string): string {\n return key;\n }\n\n pointer(key: string): string {\n return `${LOCAL_POINTER}${key}`;\n }\n}\n\n/**\n * The `components.schemas` names of a BUNDLED document.\n *\n * Every type keeps its own name unless two packages' types of ONE name are both reached — the\n * `LocalizedDescriptionsDto` case of #1058, which the split form keeps apart by keeping them in two\n * documents. A bundled document has one namespace, so then the home package's type keeps the bare\n * name and every other package's is qualified by its package (`myorg.lang-api-dtos.X`, in the\n * characters a components key may hold). Renaming only on a clash keeps every ordinary bundled\n * document identical to the split one wherever the split one defines the schema itself.\n */\nexport class BundledNames {\n // webpieces-disable no-function-outside-class -- static factory of this class\n static assign(\n reached: Iterable<string>,\n types: ReadonlyMap<string, DocumentedType>,\n homePackage: string | undefined,\n ): ReadonlyMap<string, string> {\n const byName = new Map<string, string[]>();\n for (const key of reached) {\n const type = types.get(key);\n if (type === undefined) {\n continue;\n }\n const group = byName.get(type.schemaName) ?? [];\n group.push(key);\n byName.set(type.schemaName, group);\n }\n const names = new Map<string, string>();\n for (const name of byName.keys()) {\n const keys = byName.get(name)!;\n const declarations = keys.map((key: string) => types.get(key)!);\n if (\n keys.length > 1 &&\n declarations.some((type: DocumentedType) => type.name !== type.schemaName)\n ) {\n throw new OpenApiGenerationError(\n `stripped schema name '${name}' collides: ${declarations.map((type: DocumentedType) => `'${type.name}' at ${type.location}`).join(' and ')}`,\n '<bundled document>',\n 'Change schemaNames so every reached declaration has a distinct published name.',\n );\n }\n for (const key of keys) {\n const type = types.get(key)!;\n const keepsBareName = keys.length === 1 || type.packageName === homePackage;\n names.set(\n key,\n keepsBareName ? name : BundledNames.qualified(type.packageName, name),\n );\n }\n }\n return names;\n }\n\n /** `@myorg/lang-api-dtos` + `X` → `myorg.lang-api-dtos.X` — `^[a-zA-Z0-9.\\-_]+$`, as 3.1 requires. */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static qualified(packageName: string | undefined, name: string): string {\n const owner = (packageName ?? 'no-package').replace(/^@/, '').replace(/\\//g, '.');\n return `${owner}.${name}`.replace(/[^A-Za-z0-9.\\-_]/g, '_');\n }\n}\n"]}
|
|
@@ -10,7 +10,7 @@ import { ComponentsInputs, GenerationInputs } from '../generate/GenerationInputs
|
|
|
10
10
|
export declare class InputsLoader {
|
|
11
11
|
private readonly manifests;
|
|
12
12
|
private readonly constants;
|
|
13
|
-
private
|
|
13
|
+
private extractor;
|
|
14
14
|
private readonly packages;
|
|
15
15
|
private readonly locator;
|
|
16
16
|
private options;
|
package/src/load/InputsLoader.js
CHANGED
|
@@ -55,6 +55,7 @@ class InputsLoader {
|
|
|
55
55
|
}
|
|
56
56
|
load(manifestPath) {
|
|
57
57
|
const manifest = this.manifests.load(manifestPath);
|
|
58
|
+
this.extractor = new api_doc_model_1.ApiDocExtractor(new api_doc_model_1.SchemaNames(manifest.schemaNames));
|
|
58
59
|
this.options = this.compilerOptions(manifestPath);
|
|
59
60
|
const contracts = this.contracts(manifestPath, manifest);
|
|
60
61
|
const errorType = this.errorType(manifestPath, manifest);
|
|
@@ -72,6 +73,7 @@ class InputsLoader {
|
|
|
72
73
|
/** A DTO library's components manifest, its exported types, and the libraries THEY reach. */
|
|
73
74
|
loadComponents(manifestPath) {
|
|
74
75
|
const manifest = this.manifests.loadComponents(manifestPath);
|
|
76
|
+
this.extractor = new api_doc_model_1.ApiDocExtractor(new api_doc_model_1.SchemaNames(manifest.schemaNames));
|
|
75
77
|
this.options = this.compilerOptions(manifestPath);
|
|
76
78
|
const files = manifest.entries.map((entry) => {
|
|
77
79
|
const file = this.manifests.resolve(manifestPath, entry);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputsLoader.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/load/InputsLoader.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAClC,uDAAiC;AACjC,4DAKkC;AAClC,oDAAqE;AACrE,sEAAmE;AACnE,+DAA4D;AAE5D,mEAKsC;AACtC,uEAIwC;AACxC,2DAAwD;AACxD,qEAAkE;AAClE,qDAAkD;AAElD,gDAAgD;AAChD,M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C;IAEO,eAAe,CACnB,YAAoB,EACpB,QAAyB;QAEzB,OAAO,QAAQ,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,MAA2B,EAAE,EAAE;YAChE,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;YAChE,OAAO,IAAI,yCAAsB,CAC7B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,YAAY,CAAC,EAC9C,MAAM,CAAC,WAAW,CACrB,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;IAEO,WAAW,CAAC,YAAoB,EAAE,QAAyB;QAC/D,IAAI,QAAQ,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;YACzC,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;QAC5E,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;QAC7D,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IAChD,CAAC;IAEO,SAAS,CAAC,IAAY,EAAE,QAAgB,EAAE,YAAoB;QAClE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,+CAAsB,CAC5B,uBAAuB,QAAQ,yBAAyB,EACxD,YAAY,EACZ,sEAAsE,IAAI,GAAG,CAChF,CAAC;QACN,CAAC;IACL,CAAC;CACJ;AA3OD,oCA2OC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport * as ts from 'typescript';\nimport {\n ApiComponentsModel,\n ApiDocExtractor,\n DocumentedType,\n PackageOfFile,\n} from '@webpieces/api-doc-model';\nimport { EXTERNAL_CUSTOMER, SVC_TO_SVC } from '@webpieces/core-util';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\nimport { ManifestLoader } from '../manifest/ManifestLoader';\nimport { ApiEntry, OpenApiManifest, ResponseHeaderEntry } from '../manifest/OpenApiManifest';\nimport {\n ComponentsInputs,\n ContractModel,\n GenerationInputs,\n ResolvedResponseHeader,\n} from '../generate/GenerationInputs';\nimport {\n MissingComponents,\n PublishedComponents,\n UpstreamComponentsIndex,\n} from '../generate/UpstreamComponents';\nimport { ComponentsLocator } from './ComponentsLocator';\nimport { ExportedConstantFolder } from './ExportedConstantFolder';\nimport { ForeignFailure } from './ForeignFailure';\n\n/** A `path/to/File.ts:12:5` location's FILE. */\nconst LINE_AND_COLUMN = /:\\d+:\\d+$/;\n\n/**\n * The compiler options the contracts are read with, when the project has no `tsconfig.json` of its\n * own to inherit from (see {@link InputsLoader.compilerOptions}).\n *\n * Decorators must be enabled or a contract does not parse at all, and `skipLibCheck` is on because\n * this is an EXTRACTION pass, not a type-check: the app's own build is what decides whether the\n * contract compiles, and duplicating that judgement here would make `wp-openapi` fail for reasons\n * that have nothing to do with the document.\n */\nconst FALLBACK_OPTIONS: ts.CompilerOptions = {\n target: ts.ScriptTarget.ES2022,\n module: ts.ModuleKind.CommonJS,\n moduleResolution: ts.ModuleResolutionKind.Node10,\n experimentalDecorators: true,\n strict: true,\n noEmit: true,\n skipLibCheck: true,\n};\n\n/**\n * Read everything from disk, ONCE, into {@link GenerationInputs}.\n *\n * Every path in the manifest is resolved against the MANIFEST's own directory, never against the\n * process's cwd. A document whose contents depended on where `wp-openapi` was invoked from would be\n * a different document per caller, and the committed golden would go red depending on which\n * directory a build happened to run in.\n */\nexport class InputsLoader {\n private readonly manifests = new ManifestLoader();\n private readonly constants = new ExportedConstantFolder();\n private readonly extractor = new ApiDocExtractor();\n private readonly packages = new PackageOfFile();\n private readonly locator = new ComponentsLocator();\n private options: ts.CompilerOptions = FALLBACK_OPTIONS;\n\n /** True when `manifestPath` is a DTO library's `\"kind\": \"components\"` manifest. */\n isComponents(manifestPath: string): boolean {\n return this.manifests.isComponents(manifestPath);\n }\n\n load(manifestPath: string): GenerationInputs {\n const manifest = this.manifests.load(manifestPath);\n this.options = this.compilerOptions(manifestPath);\n const contracts = this.contracts(manifestPath, manifest);\n const errorType = this.errorType(manifestPath, manifest);\n const homePackage = this.packages.of(manifestPath)?.name;\n // Only the SPLIT documents reference other packages' components documents. A contract that\n // feeds nothing but the MCP projection inlines every schema, so it requires no DTO library to\n // publish one (#1058) — and it is not asked to.\n const split = contracts\n .filter(\n (contract: ContractModel) =>\n contract.model.apiTypes.includes(SVC_TO_SVC) ||\n contract.model.apiTypes.includes(EXTERNAL_CUSTOMER),\n )\n .map((contract: ContractModel) => contract.model.types);\n const reached = errorType === undefined ? split : split.concat([errorType.types]);\n return new GenerationInputs(\n manifestPath,\n manifest,\n contracts,\n errorType,\n this.responseHeaders(manifestPath, manifest),\n this.description(manifestPath, manifest),\n homePackage,\n this.upstream(manifestPath, homePackage, reached),\n );\n }\n\n /** A DTO library's components manifest, its exported types, and the libraries THEY reach. */\n loadComponents(manifestPath: string): ComponentsInputs {\n const manifest = this.manifests.loadComponents(manifestPath);\n this.options = this.compilerOptions(manifestPath);\n const files = manifest.entries.map((entry: string) => {\n const file = this.manifests.resolve(manifestPath, entry);\n this.mustExist(file, entry, manifestPath);\n return file;\n });\n const model = this.extractComponents(files, manifestPath);\n const manifestPackage = this.packages.of(manifestPath)?.name;\n if (manifestPackage !== model.packageName) {\n throw new OpenApiGenerationError(\n `the entries belong to ${model.packageName}, and the manifest to ${manifestPackage ?? 'no package'}`,\n manifestPath,\n \"Keep a DTO library's manifest beside its own package.json, naming that library's entry files.\",\n );\n }\n return new ComponentsInputs(\n manifestPath,\n manifest,\n model,\n this.upstream(manifestPath, model.packageName, [model.types]),\n );\n }\n\n private extractComponents(files: readonly string[], manifestPath: string): ApiComponentsModel {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package\n try {\n return this.extractor.extractComponents(files, this.options);\n } catch (err: unknown) {\n //const error = toError(err);\n throw this.rethrow(err, files[0] ?? manifestPath);\n }\n }\n\n /**\n * The components document of EVERY OTHER package these types are declared in, located once each\n * by {@link ComponentsLocator}. A package that publishes none is recorded, not refused, here: the\n * generator refuses only when a document it renders actually reaches one of its types.\n */\n private upstream(\n manifestPath: string,\n homePackage: string | undefined,\n typeMaps: readonly ReadonlyMap<string, DocumentedType>[],\n ): UpstreamComponentsIndex {\n const declaredIn = new Map<string, string>();\n for (const types of typeMaps) {\n for (const type of types.values()) {\n if (type.packageName === undefined || type.packageName === homePackage) {\n continue;\n }\n if (!declaredIn.has(type.packageName)) {\n declaredIn.set(type.packageName, type.location.replace(LINE_AND_COLUMN, ''));\n }\n }\n }\n const published = new Map<string, PublishedComponents>();\n const missing = new Map<string, MissingComponents>();\n for (const packageName of Array.from(declaredIn.keys()).sort()) {\n const located = this.locator.locate(\n packageName,\n path.dirname(manifestPath),\n this.packages.of(declaredIn.get(packageName)!)?.directory,\n );\n if (located.published !== undefined) {\n published.set(packageName, located.published);\n } else {\n missing.set(packageName, located.missing!);\n }\n }\n return new UpstreamComponentsIndex(published, missing);\n }\n\n /**\n * The nearest `tsconfig.json` at or above the MANIFEST, with the extraction flags forced on.\n *\n * A contract imports its decorators from `@webpieces/core-util`, and a path mapping or a\n * `baseUrl` is what makes that name resolve. Reading the project's own tsconfig is therefore not\n * a convenience — without it the checker cannot see that `POST` is the string `'POST'`, and the\n * constant folder does the right thing and REFUSES rather than guessing a verb. Falling back to\n * a fixed set of options is for a caller with no tsconfig at all, which is a legal thing to be.\n *\n * The flags below are forced over whatever the project says because they are about THIS read and\n * not about the project's build: decorators must parse, nothing may be emitted, and a library\n * type error in `node_modules` is the project's business, not a reason to refuse a document.\n */\n private compilerOptions(manifestPath: string): ts.CompilerOptions {\n const configFile = ts.findConfigFile(path.dirname(manifestPath), (file: string) =>\n ts.sys.fileExists(file),\n );\n if (configFile === undefined) {\n return FALLBACK_OPTIONS;\n }\n const read = ts.readConfigFile(configFile, (file: string) => ts.sys.readFile(file));\n if (read.error !== undefined || read.config === undefined) {\n return FALLBACK_OPTIONS;\n }\n const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, path.dirname(configFile));\n const options = parsed.options;\n options.noEmit = true;\n options.skipLibCheck = true;\n options.experimentalDecorators = true;\n options.composite = false;\n options.declaration = false;\n return options;\n }\n\n private contracts(manifestPath: string, manifest: OpenApiManifest): readonly ContractModel[] {\n return manifest.apis.map((entry: ApiEntry) => {\n const file = this.manifests.resolve(manifestPath, entry.entry);\n this.mustExist(file, entry.entry, manifestPath);\n return new ContractModel(entry, this.extract(file), file);\n });\n }\n\n /**\n * The extractor's own failure is re-thrown as THIS package's one error type, carrying the\n * extractor's location and cure. The alternative — letting `ApiDocExtractionError` out — would\n * give `wp-openapi` two failure types that its top-level handler had to know about, and only one\n * of them would be documented on this package's surface.\n */\n private extract(file: string): ReturnType<ApiDocExtractor['extractFile']> {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package\n try {\n return this.extractor.extractFile(file, this.options);\n } catch (err: unknown) {\n //const error = toError(err);\n throw this.rethrow(err, file);\n }\n }\n\n private errorType(\n manifestPath: string,\n manifest: OpenApiManifest,\n ): ReturnType<ApiDocExtractor['extractType']> | undefined {\n const errors = manifest.errors;\n if (errors === undefined) {\n return undefined;\n }\n const file = this.manifests.resolve(manifestPath, errors.entry);\n this.mustExist(file, errors.entry, manifestPath);\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package\n try {\n return this.extractor.extractType(file, errors.type, this.options);\n } catch (err: unknown) {\n //const error = toError(err);\n throw this.rethrow(err, file);\n }\n }\n\n // webpieces-disable no-any-unknown -- a caught value; ForeignFailure is what narrows it\n private rethrow(err: unknown, file: string): OpenApiGenerationError {\n if (err instanceof OpenApiGenerationError) {\n return err;\n }\n return ForeignFailure.of(err).asGenerationError(\n file,\n 'Fix the contract this document is read from.',\n );\n }\n\n private responseHeaders(\n manifestPath: string,\n manifest: OpenApiManifest,\n ): readonly ResolvedResponseHeader[] {\n return manifest.responseHeaders.map((header: ResponseHeaderEntry) => {\n const file = this.manifests.resolve(manifestPath, header.entry);\n return new ResolvedResponseHeader(\n this.constants.fold(file, header.nameConstant),\n header.description,\n );\n });\n }\n\n private description(manifestPath: string, manifest: OpenApiManifest): string | undefined {\n if (manifest.descriptionFile === undefined) {\n return undefined;\n }\n const file = this.manifests.resolve(manifestPath, manifest.descriptionFile);\n this.mustExist(file, manifest.descriptionFile, manifestPath);\n return fs.readFileSync(file, 'utf8').trim();\n }\n\n private mustExist(file: string, declared: string, manifestPath: string): void {\n if (!fs.existsSync(file)) {\n throw new OpenApiGenerationError(\n `the manifest names '${declared}', which does not exist`,\n manifestPath,\n `Paths are relative to the manifest's own directory. Expected it at ${file}.`,\n );\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"InputsLoader.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/load/InputsLoader.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAClC,uDAAiC;AACjC,4DAMkC;AAClC,oDAAqE;AACrE,sEAAmE;AACnE,+DAA4D;AAE5D,mEAKsC;AACtC,uEAIwC;AACxC,2DAAwD;AACxD,qEAAkE;AAClE,qDAAkD;AAElD,gDAAgD;AAChD,MAAM,eAAe,GAAG,WAAW,CAAC;AAEpC;;;;;;;;GAQG;AACH,MAAM,gBAAgB,GAAuB;IACzC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM;IAC9B,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ;IAC9B,gBAAgB,EAAE,EAAE,CAAC,oBAAoB,CAAC,MAAM;IAChD,sBAAsB,EAAE,IAAI;IAC5B,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,IAAI;IACZ,YAAY,EAAE,IA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AAE;YAChE,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;YAChE,OAAO,IAAI,yCAAsB,CAC7B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,YAAY,CAAC,EAC9C,MAAM,CAAC,WAAW,CACrB,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;IAEO,WAAW,CAAC,YAAoB,EAAE,QAAyB;QAC/D,IAAI,QAAQ,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;YACzC,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;QAC5E,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;QAC7D,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IAChD,CAAC;IAEO,SAAS,CAAC,IAAY,EAAE,QAAgB,EAAE,YAAoB;QAClE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,+CAAsB,CAC5B,uBAAuB,QAAQ,yBAAyB,EACxD,YAAY,EACZ,sEAAsE,IAAI,GAAG,CAChF,CAAC;QACN,CAAC;IACL,CAAC;CACJ;AA7OD,oCA6OC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport * as ts from 'typescript';\nimport {\n ApiComponentsModel,\n ApiDocExtractor,\n DocumentedType,\n PackageOfFile,\n SchemaNames,\n} from '@webpieces/api-doc-model';\nimport { EXTERNAL_CUSTOMER, SVC_TO_SVC } from '@webpieces/core-util';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\nimport { ManifestLoader } from '../manifest/ManifestLoader';\nimport { ApiEntry, OpenApiManifest, ResponseHeaderEntry } from '../manifest/OpenApiManifest';\nimport {\n ComponentsInputs,\n ContractModel,\n GenerationInputs,\n ResolvedResponseHeader,\n} from '../generate/GenerationInputs';\nimport {\n MissingComponents,\n PublishedComponents,\n UpstreamComponentsIndex,\n} from '../generate/UpstreamComponents';\nimport { ComponentsLocator } from './ComponentsLocator';\nimport { ExportedConstantFolder } from './ExportedConstantFolder';\nimport { ForeignFailure } from './ForeignFailure';\n\n/** A `path/to/File.ts:12:5` location's FILE. */\nconst LINE_AND_COLUMN = /:\\d+:\\d+$/;\n\n/**\n * The compiler options the contracts are read with, when the project has no `tsconfig.json` of its\n * own to inherit from (see {@link InputsLoader.compilerOptions}).\n *\n * Decorators must be enabled or a contract does not parse at all, and `skipLibCheck` is on because\n * this is an EXTRACTION pass, not a type-check: the app's own build is what decides whether the\n * contract compiles, and duplicating that judgement here would make `wp-openapi` fail for reasons\n * that have nothing to do with the document.\n */\nconst FALLBACK_OPTIONS: ts.CompilerOptions = {\n target: ts.ScriptTarget.ES2022,\n module: ts.ModuleKind.CommonJS,\n moduleResolution: ts.ModuleResolutionKind.Node10,\n experimentalDecorators: true,\n strict: true,\n noEmit: true,\n skipLibCheck: true,\n};\n\n/**\n * Read everything from disk, ONCE, into {@link GenerationInputs}.\n *\n * Every path in the manifest is resolved against the MANIFEST's own directory, never against the\n * process's cwd. A document whose contents depended on where `wp-openapi` was invoked from would be\n * a different document per caller, and the committed golden would go red depending on which\n * directory a build happened to run in.\n */\nexport class InputsLoader {\n private readonly manifests = new ManifestLoader();\n private readonly constants = new ExportedConstantFolder();\n private extractor = new ApiDocExtractor();\n private readonly packages = new PackageOfFile();\n private readonly locator = new ComponentsLocator();\n private options: ts.CompilerOptions = FALLBACK_OPTIONS;\n\n /** True when `manifestPath` is a DTO library's `\"kind\": \"components\"` manifest. */\n isComponents(manifestPath: string): boolean {\n return this.manifests.isComponents(manifestPath);\n }\n\n load(manifestPath: string): GenerationInputs {\n const manifest = this.manifests.load(manifestPath);\n this.extractor = new ApiDocExtractor(new SchemaNames(manifest.schemaNames));\n this.options = this.compilerOptions(manifestPath);\n const contracts = this.contracts(manifestPath, manifest);\n const errorType = this.errorType(manifestPath, manifest);\n const homePackage = this.packages.of(manifestPath)?.name;\n // Only the SPLIT documents reference other packages' components documents. A contract that\n // feeds nothing but the MCP projection inlines every schema, so it requires no DTO library to\n // publish one (#1058) — and it is not asked to.\n const split = contracts\n .filter(\n (contract: ContractModel) =>\n contract.model.apiTypes.includes(SVC_TO_SVC) ||\n contract.model.apiTypes.includes(EXTERNAL_CUSTOMER),\n )\n .map((contract: ContractModel) => contract.model.types);\n const reached = errorType === undefined ? split : split.concat([errorType.types]);\n return new GenerationInputs(\n manifestPath,\n manifest,\n contracts,\n errorType,\n this.responseHeaders(manifestPath, manifest),\n this.description(manifestPath, manifest),\n homePackage,\n this.upstream(manifestPath, homePackage, reached),\n );\n }\n\n /** A DTO library's components manifest, its exported types, and the libraries THEY reach. */\n loadComponents(manifestPath: string): ComponentsInputs {\n const manifest = this.manifests.loadComponents(manifestPath);\n this.extractor = new ApiDocExtractor(new SchemaNames(manifest.schemaNames));\n this.options = this.compilerOptions(manifestPath);\n const files = manifest.entries.map((entry: string) => {\n const file = this.manifests.resolve(manifestPath, entry);\n this.mustExist(file, entry, manifestPath);\n return file;\n });\n const model = this.extractComponents(files, manifestPath);\n const manifestPackage = this.packages.of(manifestPath)?.name;\n if (manifestPackage !== model.packageName) {\n throw new OpenApiGenerationError(\n `the entries belong to ${model.packageName}, and the manifest to ${manifestPackage ?? 'no package'}`,\n manifestPath,\n \"Keep a DTO library's manifest beside its own package.json, naming that library's entry files.\",\n );\n }\n return new ComponentsInputs(\n manifestPath,\n manifest,\n model,\n this.upstream(manifestPath, model.packageName, [model.types]),\n );\n }\n\n private extractComponents(files: readonly string[], manifestPath: string): ApiComponentsModel {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package\n try {\n return this.extractor.extractComponents(files, this.options);\n } catch (err: unknown) {\n //const error = toError(err);\n throw this.rethrow(err, files[0] ?? manifestPath);\n }\n }\n\n /**\n * The components document of EVERY OTHER package these types are declared in, located once each\n * by {@link ComponentsLocator}. A package that publishes none is recorded, not refused, here: the\n * generator refuses only when a document it renders actually reaches one of its types.\n */\n private upstream(\n manifestPath: string,\n homePackage: string | undefined,\n typeMaps: readonly ReadonlyMap<string, DocumentedType>[],\n ): UpstreamComponentsIndex {\n const declaredIn = new Map<string, string>();\n for (const types of typeMaps) {\n for (const type of types.values()) {\n if (type.packageName === undefined || type.packageName === homePackage) {\n continue;\n }\n if (!declaredIn.has(type.packageName)) {\n declaredIn.set(type.packageName, type.location.replace(LINE_AND_COLUMN, ''));\n }\n }\n }\n const published = new Map<string, PublishedComponents>();\n const missing = new Map<string, MissingComponents>();\n for (const packageName of Array.from(declaredIn.keys()).sort()) {\n const located = this.locator.locate(\n packageName,\n path.dirname(manifestPath),\n this.packages.of(declaredIn.get(packageName)!)?.directory,\n );\n if (located.published !== undefined) {\n published.set(packageName, located.published);\n } else {\n missing.set(packageName, located.missing!);\n }\n }\n return new UpstreamComponentsIndex(published, missing);\n }\n\n /**\n * The nearest `tsconfig.json` at or above the MANIFEST, with the extraction flags forced on.\n *\n * A contract imports its decorators from `@webpieces/core-util`, and a path mapping or a\n * `baseUrl` is what makes that name resolve. Reading the project's own tsconfig is therefore not\n * a convenience — without it the checker cannot see that `POST` is the string `'POST'`, and the\n * constant folder does the right thing and REFUSES rather than guessing a verb. Falling back to\n * a fixed set of options is for a caller with no tsconfig at all, which is a legal thing to be.\n *\n * The flags below are forced over whatever the project says because they are about THIS read and\n * not about the project's build: decorators must parse, nothing may be emitted, and a library\n * type error in `node_modules` is the project's business, not a reason to refuse a document.\n */\n private compilerOptions(manifestPath: string): ts.CompilerOptions {\n const configFile = ts.findConfigFile(path.dirname(manifestPath), (file: string) =>\n ts.sys.fileExists(file),\n );\n if (configFile === undefined) {\n return FALLBACK_OPTIONS;\n }\n const read = ts.readConfigFile(configFile, (file: string) => ts.sys.readFile(file));\n if (read.error !== undefined || read.config === undefined) {\n return FALLBACK_OPTIONS;\n }\n const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, path.dirname(configFile));\n const options = parsed.options;\n options.noEmit = true;\n options.skipLibCheck = true;\n options.experimentalDecorators = true;\n options.composite = false;\n options.declaration = false;\n return options;\n }\n\n private contracts(manifestPath: string, manifest: OpenApiManifest): readonly ContractModel[] {\n return manifest.apis.map((entry: ApiEntry) => {\n const file = this.manifests.resolve(manifestPath, entry.entry);\n this.mustExist(file, entry.entry, manifestPath);\n return new ContractModel(entry, this.extract(file), file);\n });\n }\n\n /**\n * The extractor's own failure is re-thrown as THIS package's one error type, carrying the\n * extractor's location and cure. The alternative — letting `ApiDocExtractionError` out — would\n * give `wp-openapi` two failure types that its top-level handler had to know about, and only one\n * of them would be documented on this package's surface.\n */\n private extract(file: string): ReturnType<ApiDocExtractor['extractFile']> {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package\n try {\n return this.extractor.extractFile(file, this.options);\n } catch (err: unknown) {\n //const error = toError(err);\n throw this.rethrow(err, file);\n }\n }\n\n private errorType(\n manifestPath: string,\n manifest: OpenApiManifest,\n ): ReturnType<ApiDocExtractor['extractType']> | undefined {\n const errors = manifest.errors;\n if (errors === undefined) {\n return undefined;\n }\n const file = this.manifests.resolve(manifestPath, errors.entry);\n this.mustExist(file, errors.entry, manifestPath);\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package\n try {\n return this.extractor.extractType(file, errors.type, this.options);\n } catch (err: unknown) {\n //const error = toError(err);\n throw this.rethrow(err, file);\n }\n }\n\n // webpieces-disable no-any-unknown -- a caught value; ForeignFailure is what narrows it\n private rethrow(err: unknown, file: string): OpenApiGenerationError {\n if (err instanceof OpenApiGenerationError) {\n return err;\n }\n return ForeignFailure.of(err).asGenerationError(\n file,\n 'Fix the contract this document is read from.',\n );\n }\n\n private responseHeaders(\n manifestPath: string,\n manifest: OpenApiManifest,\n ): readonly ResolvedResponseHeader[] {\n return manifest.responseHeaders.map((header: ResponseHeaderEntry) => {\n const file = this.manifests.resolve(manifestPath, header.entry);\n return new ResolvedResponseHeader(\n this.constants.fold(file, header.nameConstant),\n header.description,\n );\n });\n }\n\n private description(manifestPath: string, manifest: OpenApiManifest): string | undefined {\n if (manifest.descriptionFile === undefined) {\n return undefined;\n }\n const file = this.manifests.resolve(manifestPath, manifest.descriptionFile);\n this.mustExist(file, manifest.descriptionFile, manifestPath);\n return fs.readFileSync(file, 'utf8').trim();\n }\n\n private mustExist(file: string, declared: string, manifestPath: string): void {\n if (!fs.existsSync(file)) {\n throw new OpenApiGenerationError(\n `the manifest names '${declared}', which does not exist`,\n manifestPath,\n `Paths are relative to the manifest's own directory. Expected it at ${file}.`,\n );\n }\n }\n}\n"]}
|
|
@@ -20,6 +20,7 @@ export declare class ManifestLoader {
|
|
|
20
20
|
/** @param manifestPath absolute path to a CONTRACT library's `openapi.manifest.json`. */
|
|
21
21
|
load(manifestPath: string): OpenApiManifest;
|
|
22
22
|
private servers;
|
|
23
|
+
private schemaNames;
|
|
23
24
|
private apis;
|
|
24
25
|
private errors;
|
|
25
26
|
private responseHeaders;
|
|
@@ -6,6 +6,7 @@ const fs = tslib_1.__importStar(require("node:fs"));
|
|
|
6
6
|
const path = tslib_1.__importStar(require("node:path"));
|
|
7
7
|
const OpenApiGenerationError_1 = require("../OpenApiGenerationError");
|
|
8
8
|
const JsonReader_1 = require("./JsonReader");
|
|
9
|
+
const api_doc_model_1 = require("@webpieces/api-doc-model");
|
|
9
10
|
const OpenApiManifest_1 = require("./OpenApiManifest");
|
|
10
11
|
/** The only `kind` an api entry may declare. Anything else is a typo, and typos are refused. */
|
|
11
12
|
const WEBHOOK = 'webhook';
|
|
@@ -17,7 +18,10 @@ const COMPONENTS = 'components';
|
|
|
17
18
|
/** Keys a components manifest must not carry, each with why — a contract-manifest key is a mix-up. */
|
|
18
19
|
const NOT_IN_COMPONENTS = new Map([
|
|
19
20
|
['apis', 'a components document has no paths; list the library\'s entry files in "entries"'],
|
|
20
|
-
[
|
|
21
|
+
[
|
|
22
|
+
'version',
|
|
23
|
+
"a library document's info.version is the package version, read from its package.json",
|
|
24
|
+
],
|
|
21
25
|
['servers', 'a components document has no operations to serve'],
|
|
22
26
|
['errors', 'the error contract belongs to a contract document'],
|
|
23
27
|
['responseHeaders', 'response headers belong to a contract document'],
|
|
@@ -61,7 +65,7 @@ class ManifestLoader {
|
|
|
61
65
|
if (entries.length === 0) {
|
|
62
66
|
throw new OpenApiGenerationError_1.OpenApiGenerationError("'entries' is empty", raw.where, 'Name the library\'s entry files, e.g. "entries": ["src/index.ts"]; the document holds every type they export.');
|
|
63
67
|
}
|
|
64
|
-
return new OpenApiManifest_1.ComponentsManifest(raw.string('title'), entries);
|
|
68
|
+
return new OpenApiManifest_1.ComponentsManifest(raw.string('title'), entries, this.schemaNames(raw));
|
|
65
69
|
}
|
|
66
70
|
read(manifestPath) {
|
|
67
71
|
if (!fs.existsSync(manifestPath)) {
|
|
@@ -75,13 +79,26 @@ class ManifestLoader {
|
|
|
75
79
|
throw new OpenApiGenerationError_1.OpenApiGenerationError(`this is a "kind": "${COMPONENTS}" manifest, not a contract manifest`, manifestPath, 'Render it as a components document (wp-openapi does so on its own when it reads the kind).');
|
|
76
80
|
}
|
|
77
81
|
const raw = this.read(manifestPath);
|
|
78
|
-
return new OpenApiManifest_1.OpenApiManifest(raw.string('title'), raw.string('version'), this.servers(raw), raw.optionalString('descriptionFile'), this.apis(raw), raw.strings('securitySchemeNames'), this.errors(raw), this.responseHeaders(raw));
|
|
82
|
+
return new OpenApiManifest_1.OpenApiManifest(raw.string('title'), raw.string('version'), this.servers(raw), raw.optionalString('descriptionFile'), this.apis(raw), raw.strings('securitySchemeNames'), this.errors(raw), this.responseHeaders(raw), this.schemaNames(raw));
|
|
79
83
|
}
|
|
80
84
|
servers(raw) {
|
|
81
85
|
return raw
|
|
82
86
|
.objects('servers')
|
|
83
87
|
.map((server) => new OpenApiManifest_1.ServerEntry(server.string('url'), server.optionalString('description')));
|
|
84
88
|
}
|
|
89
|
+
schemaNames(raw) {
|
|
90
|
+
return raw.objects('schemaNames').map((entry) => {
|
|
91
|
+
const paths = entry.strings('paths');
|
|
92
|
+
const suffixes = entry.strings('stripSuffixes');
|
|
93
|
+
if (paths.length === 0 ||
|
|
94
|
+
paths.some((glob) => glob.trim() === '') ||
|
|
95
|
+
!entry.has('stripSuffixes') ||
|
|
96
|
+
suffixes.some((suffix) => suffix.length === 0)) {
|
|
97
|
+
throw new OpenApiGenerationError_1.OpenApiGenerationError('invalid schemaNames entry', raw.where, 'Provide non-empty paths and an explicit stripSuffixes array of non-empty suffixes (or [] to preserve names). First matching path wins.');
|
|
98
|
+
}
|
|
99
|
+
return new api_doc_model_1.SchemaNameEntry(paths.map((glob) => path.resolve(path.dirname(raw.where), glob)), suffixes);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
85
102
|
apis(raw) {
|
|
86
103
|
const entries = raw
|
|
87
104
|
.objects('apis')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ManifestLoader.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/manifest/ManifestLoader.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAClC,sEAAmE;AACnE,6CAA0C;AAC1C,uDAQ2B;AAE3B,gGAAgG;AAChG,MAAM,OAAO,GAAG,SAAS,CAAC;AAE1B;;;GAGG;AACH,MAAM,UAAU,GAAG,YAAY,CAAC;AAEhC,sGAAsG;AACtG,MAAM,iBAAiB,GAAgC,IAAI,GAAG,CAAiB;IAC3E,CAAC,MAAM,EAAE,kFAAkF,CAAC;IAC5F,CAAC,SAAS,EAAE,sFAAsF,CAAC;IACnG,CAAC,SAAS,EAAE,kDAAkD,CAAC;IAC/D,CAAC,QA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GAAG,CACA,CAAC,QAAoB,EAAE,EAAE,CACrB,IAAI,oCAAkB,CAClB,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,EACzB,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,CACjC,CACR,CACR,CAAC;IACN,CAAC;IAEO,eAAe,CAAC,GAAe;QACnC,OAAO,GAAG;aACL,OAAO,CAAC,iBAAiB,CAAC;aAC1B,GAAG,CACA,CAAC,MAAkB,EAAE,EAAE,CACnB,IAAI,qCAAmB,CACnB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EACtB,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,EAC7B,MAAM,CAAC,cAAc,CAAC,aAAa,CAAC,CACvC,CACR,CAAC;IACV,CAAC;IAED,+EAA+E;IAC/E,OAAO,CAAC,YAAoB,EAAE,QAAgB;QAC1C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC9D,CAAC;CACJ;AA1JD,wCA0JC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\nimport { JsonReader } from './JsonReader';\nimport {\n ApiEntry,\n ComponentsManifest,\n ErrorResponseEntry,\n ErrorsEntry,\n OpenApiManifest,\n ResponseHeaderEntry,\n ServerEntry,\n} from './OpenApiManifest';\n\n/** The only `kind` an api entry may declare. Anything else is a typo, and typos are refused. */\nconst WEBHOOK = 'webhook';\n\n/**\n * The only `kind` a MANIFEST may declare (#1058): a DTO library's components-only document. A\n * manifest with no `kind` is a contract library's, exactly as before.\n */\nconst COMPONENTS = 'components';\n\n/** Keys a components manifest must not carry, each with why — a contract-manifest key is a mix-up. */\nconst NOT_IN_COMPONENTS: ReadonlyMap<string, string> = new Map<string, string>([\n ['apis', 'a components document has no paths; list the library\\'s entry files in \"entries\"'],\n ['version', \"a library document's info.version is the package version, read from its package.json\"],\n ['servers', 'a components document has no operations to serve'],\n ['errors', 'the error contract belongs to a contract document'],\n ['responseHeaders', 'response headers belong to a contract document'],\n ['securitySchemeNames', 'security belongs to a contract document'],\n]);\n\n/**\n * Read `openapi.manifest.json` into {@link OpenApiManifest}.\n *\n * It deals only in {@link JsonReader}, which is where the \"came off disk, not yet checked\" state is\n * concentrated — so nothing in this file, or anywhere downstream, handles an unnarrowed value.\n *\n * Every rejection is a HARD FAILURE naming the field. A published document quietly missing a section\n * is indistinguishable, from outside, from an API that genuinely has no error contract.\n */\nexport class ManifestLoader {\n /**\n * True for a DTO library's `\"kind\": \"components\"` manifest, false for a contract library's (no\n * `kind`). Any other `kind` is refused: a typo there would otherwise render the wrong document.\n */\n isComponents(manifestPath: string): boolean {\n const kind = this.read(manifestPath).optionalString('kind');\n if (kind === undefined) {\n return false;\n }\n if (kind !== COMPONENTS) {\n throw new OpenApiGenerationError(\n `unknown manifest kind '${kind}'`,\n manifestPath,\n `The only manifest kind is \"${COMPONENTS}\", for a DTO library's components document. ` +\n \"Leave it out for a contract library's manifest.\",\n );\n }\n return true;\n }\n\n /** A DTO library's components manifest. See {@link ComponentsManifest}. */\n loadComponents(manifestPath: string): ComponentsManifest {\n const raw = this.read(manifestPath);\n for (const key of NOT_IN_COMPONENTS.keys()) {\n const why = NOT_IN_COMPONENTS.get(key)!;\n if (raw.has(key)) {\n throw new OpenApiGenerationError(\n `a \"kind\": \"${COMPONENTS}\" manifest declares '${key}'`,\n raw.where,\n `Delete it — ${why}.`,\n );\n }\n }\n const entries = raw.strings('entries');\n if (entries.length === 0) {\n throw new OpenApiGenerationError(\n \"'entries' is empty\",\n raw.where,\n 'Name the library\\'s entry files, e.g. \"entries\": [\"src/index.ts\"]; the document holds every type they export.',\n );\n }\n return new ComponentsManifest(raw.string('title'), entries);\n }\n\n private read(manifestPath: string): JsonReader {\n if (!fs.existsSync(manifestPath)) {\n throw new OpenApiGenerationError(\n 'no manifest at this path',\n manifestPath,\n 'Pass --manifest pointing at an openapi.manifest.json that exists.',\n );\n }\n return JsonReader.parseFile(fs.readFileSync(manifestPath, 'utf8'), manifestPath);\n }\n\n /** @param manifestPath absolute path to a CONTRACT library's `openapi.manifest.json`. */\n load(manifestPath: string): OpenApiManifest {\n if (this.isComponents(manifestPath)) {\n throw new OpenApiGenerationError(\n `this is a \"kind\": \"${COMPONENTS}\" manifest, not a contract manifest`,\n manifestPath,\n 'Render it as a components document (wp-openapi does so on its own when it reads the kind).',\n );\n }\n const raw = this.read(manifestPath);\n return new OpenApiManifest(\n raw.string('title'),\n raw.string('version'),\n this.servers(raw),\n raw.optionalString('descriptionFile'),\n this.apis(raw),\n raw.strings('securitySchemeNames'),\n this.errors(raw),\n this.responseHeaders(raw),\n );\n }\n\n private servers(raw: JsonReader): readonly ServerEntry[] {\n return raw\n .objects('servers')\n .map(\n (server: JsonReader) =>\n new ServerEntry(server.string('url'), server.optionalString('description')),\n );\n }\n\n private apis(raw: JsonReader): readonly ApiEntry[] {\n const entries = raw\n .objects('apis')\n .map(\n (api: JsonReader) =>\n new ApiEntry(\n api.string('entry'),\n api.string('tag'),\n api.optionalString('kind'),\n ),\n );\n if (entries.length === 0) {\n throw new OpenApiGenerationError(\n \"'apis' is empty\",\n raw.where,\n 'List at least one contract; a document with no operations publishes nothing.',\n );\n }\n for (const entry of entries) {\n if (entry.kind !== undefined && entry.kind !== WEBHOOK) {\n throw new OpenApiGenerationError(\n `unknown api kind '${entry.kind}' on '${entry.entry}'`,\n raw.where,\n `The only declared kind is \"${WEBHOOK}\". Leave it out for an ordinary contract.`,\n );\n }\n }\n return entries;\n }\n\n private errors(raw: JsonReader): ErrorsEntry | undefined {\n const errors = raw.object('errors');\n if (errors === undefined) {\n return undefined;\n }\n return new ErrorsEntry(\n errors.string('entry'),\n errors.string('type'),\n errors\n .objects('responses')\n .map(\n (response: JsonReader) =>\n new ErrorResponseEntry(\n response.string('status'),\n response.string('description'),\n ),\n ),\n );\n }\n\n private responseHeaders(raw: JsonReader): readonly ResponseHeaderEntry[] {\n return raw\n .objects('responseHeaders')\n .map(\n (header: JsonReader) =>\n new ResponseHeaderEntry(\n header.string('entry'),\n header.string('nameConstant'),\n header.optionalString('description'),\n ),\n );\n }\n\n /** A manifest-relative path, resolved against the manifest's own directory. */\n resolve(manifestPath: string, relative: string): string {\n return path.resolve(path.dirname(manifestPath), relative);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ManifestLoader.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/manifest/ManifestLoader.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAClC,sEAAmE;AACnE,6CAA0C;AAC1C,4DAA2D;AAC3D,uDAQ2B;AAE3B,gGAAgG;AAChG,MAAM,OAAO,GAAG,SAAS,CAAC;AAE1B;;;GAGG;AACH,MAAM,UAAU,GAAG,YAAY,CAAC;AAEhC,sGAAsG;AACtG,MAAM,iBAAiB,GAAgC,IAAI,GAAG,CAAiB;IAC3E,CAAC,MAAM,EAAE,kFAAkF,CAAC;IAC5F;QACI,SAAS;QACT,sFAAsF;KACzF;IACD,CAAC,SAAS,EAAE,kDAAkD,CAAC;IAC/D,CAAC,QAAQ,EAAE,mDAAmD,CAAC;IAC/D,CAAC,iBAAiB,EAAE,gDAAgD,CAAC;IACrE,CAAC,qBAAqB,EAAE,yCAAyC,CAAC;CACrE,CAAC,CAAC;AAEH;;;;;;;;GAQG;AACH,MAAa,cAAc;IACvB;;;OAGG;IACH,YAAY,CAAC,YAAoB;QAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC5D,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACrB,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;YACtB,MAAM,IAAI,+CAAsB,CAC5B,0BAA0B,IAAI,GAAG,EACjC,YAAY,EACZ,8BAA8B,UAAU,8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AS,KAAK,CAAC,KAAK,GAAG,EACtD,GAAG,CAAC,KAAK,EACT,8BAA8B,OAAO,2CAA2C,CACnF,CAAC;YACN,CAAC;QACL,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;IAEO,MAAM,CAAC,GAAe;QAC1B,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACpC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,OAAO,IAAI,6BAAW,CAClB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EACtB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EACrB,MAAM;aACD,OAAO,CAAC,WAAW,CAAC;aACpB,GAAG,CACA,CAAC,QAAoB,EAAE,EAAE,CACrB,IAAI,oCAAkB,CAClB,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,EACzB,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,CACjC,CACR,CACR,CAAC;IACN,CAAC;IAEO,eAAe,CAAC,GAAe;QACnC,OAAO,GAAG;aACL,OAAO,CAAC,iBAAiB,CAAC;aAC1B,GAAG,CACA,CAAC,MAAkB,EAAE,EAAE,CACnB,IAAI,qCAAmB,CACnB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EACtB,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,EAC7B,MAAM,CAAC,cAAc,CAAC,aAAa,CAAC,CACvC,CACR,CAAC;IACV,CAAC;IAED,+EAA+E;IAC/E,OAAO,CAAC,YAAoB,EAAE,QAAgB;QAC1C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC9D,CAAC;CACJ;AAlLD,wCAkLC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\nimport { JsonReader } from './JsonReader';\nimport { SchemaNameEntry } from '@webpieces/api-doc-model';\nimport {\n ApiEntry,\n ComponentsManifest,\n ErrorResponseEntry,\n ErrorsEntry,\n OpenApiManifest,\n ResponseHeaderEntry,\n ServerEntry,\n} from './OpenApiManifest';\n\n/** The only `kind` an api entry may declare. Anything else is a typo, and typos are refused. */\nconst WEBHOOK = 'webhook';\n\n/**\n * The only `kind` a MANIFEST may declare (#1058): a DTO library's components-only document. A\n * manifest with no `kind` is a contract library's, exactly as before.\n */\nconst COMPONENTS = 'components';\n\n/** Keys a components manifest must not carry, each with why — a contract-manifest key is a mix-up. */\nconst NOT_IN_COMPONENTS: ReadonlyMap<string, string> = new Map<string, string>([\n ['apis', 'a components document has no paths; list the library\\'s entry files in \"entries\"'],\n [\n 'version',\n \"a library document's info.version is the package version, read from its package.json\",\n ],\n ['servers', 'a components document has no operations to serve'],\n ['errors', 'the error contract belongs to a contract document'],\n ['responseHeaders', 'response headers belong to a contract document'],\n ['securitySchemeNames', 'security belongs to a contract document'],\n]);\n\n/**\n * Read `openapi.manifest.json` into {@link OpenApiManifest}.\n *\n * It deals only in {@link JsonReader}, which is where the \"came off disk, not yet checked\" state is\n * concentrated — so nothing in this file, or anywhere downstream, handles an unnarrowed value.\n *\n * Every rejection is a HARD FAILURE naming the field. A published document quietly missing a section\n * is indistinguishable, from outside, from an API that genuinely has no error contract.\n */\nexport class ManifestLoader {\n /**\n * True for a DTO library's `\"kind\": \"components\"` manifest, false for a contract library's (no\n * `kind`). Any other `kind` is refused: a typo there would otherwise render the wrong document.\n */\n isComponents(manifestPath: string): boolean {\n const kind = this.read(manifestPath).optionalString('kind');\n if (kind === undefined) {\n return false;\n }\n if (kind !== COMPONENTS) {\n throw new OpenApiGenerationError(\n `unknown manifest kind '${kind}'`,\n manifestPath,\n `The only manifest kind is \"${COMPONENTS}\", for a DTO library's components document. ` +\n \"Leave it out for a contract library's manifest.\",\n );\n }\n return true;\n }\n\n /** A DTO library's components manifest. See {@link ComponentsManifest}. */\n loadComponents(manifestPath: string): ComponentsManifest {\n const raw = this.read(manifestPath);\n for (const key of NOT_IN_COMPONENTS.keys()) {\n const why = NOT_IN_COMPONENTS.get(key)!;\n if (raw.has(key)) {\n throw new OpenApiGenerationError(\n `a \"kind\": \"${COMPONENTS}\" manifest declares '${key}'`,\n raw.where,\n `Delete it — ${why}.`,\n );\n }\n }\n const entries = raw.strings('entries');\n if (entries.length === 0) {\n throw new OpenApiGenerationError(\n \"'entries' is empty\",\n raw.where,\n 'Name the library\\'s entry files, e.g. \"entries\": [\"src/index.ts\"]; the document holds every type they export.',\n );\n }\n return new ComponentsManifest(raw.string('title'), entries, this.schemaNames(raw));\n }\n\n private read(manifestPath: string): JsonReader {\n if (!fs.existsSync(manifestPath)) {\n throw new OpenApiGenerationError(\n 'no manifest at this path',\n manifestPath,\n 'Pass --manifest pointing at an openapi.manifest.json that exists.',\n );\n }\n return JsonReader.parseFile(fs.readFileSync(manifestPath, 'utf8'), manifestPath);\n }\n\n /** @param manifestPath absolute path to a CONTRACT library's `openapi.manifest.json`. */\n load(manifestPath: string): OpenApiManifest {\n if (this.isComponents(manifestPath)) {\n throw new OpenApiGenerationError(\n `this is a \"kind\": \"${COMPONENTS}\" manifest, not a contract manifest`,\n manifestPath,\n 'Render it as a components document (wp-openapi does so on its own when it reads the kind).',\n );\n }\n const raw = this.read(manifestPath);\n return new OpenApiManifest(\n raw.string('title'),\n raw.string('version'),\n this.servers(raw),\n raw.optionalString('descriptionFile'),\n this.apis(raw),\n raw.strings('securitySchemeNames'),\n this.errors(raw),\n this.responseHeaders(raw),\n this.schemaNames(raw),\n );\n }\n\n private servers(raw: JsonReader): readonly ServerEntry[] {\n return raw\n .objects('servers')\n .map(\n (server: JsonReader) =>\n new ServerEntry(server.string('url'), server.optionalString('description')),\n );\n }\n\n private schemaNames(raw: JsonReader): readonly SchemaNameEntry[] {\n return raw.objects('schemaNames').map((entry: JsonReader) => {\n const paths = entry.strings('paths');\n const suffixes = entry.strings('stripSuffixes');\n if (\n paths.length === 0 ||\n paths.some((glob: string) => glob.trim() === '') ||\n !entry.has('stripSuffixes') ||\n suffixes.some((suffix: string) => suffix.length === 0)\n ) {\n throw new OpenApiGenerationError(\n 'invalid schemaNames entry',\n raw.where,\n 'Provide non-empty paths and an explicit stripSuffixes array of non-empty suffixes (or [] to preserve names). First matching path wins.',\n );\n }\n return new SchemaNameEntry(\n paths.map((glob: string) => path.resolve(path.dirname(raw.where), glob)),\n suffixes,\n );\n });\n }\n\n private apis(raw: JsonReader): readonly ApiEntry[] {\n const entries = raw\n .objects('apis')\n .map(\n (api: JsonReader) =>\n new ApiEntry(\n api.string('entry'),\n api.string('tag'),\n api.optionalString('kind'),\n ),\n );\n if (entries.length === 0) {\n throw new OpenApiGenerationError(\n \"'apis' is empty\",\n raw.where,\n 'List at least one contract; a document with no operations publishes nothing.',\n );\n }\n for (const entry of entries) {\n if (entry.kind !== undefined && entry.kind !== WEBHOOK) {\n throw new OpenApiGenerationError(\n `unknown api kind '${entry.kind}' on '${entry.entry}'`,\n raw.where,\n `The only declared kind is \"${WEBHOOK}\". Leave it out for an ordinary contract.`,\n );\n }\n }\n return entries;\n }\n\n private errors(raw: JsonReader): ErrorsEntry | undefined {\n const errors = raw.object('errors');\n if (errors === undefined) {\n return undefined;\n }\n return new ErrorsEntry(\n errors.string('entry'),\n errors.string('type'),\n errors\n .objects('responses')\n .map(\n (response: JsonReader) =>\n new ErrorResponseEntry(\n response.string('status'),\n response.string('description'),\n ),\n ),\n );\n }\n\n private responseHeaders(raw: JsonReader): readonly ResponseHeaderEntry[] {\n return raw\n .objects('responseHeaders')\n .map(\n (header: JsonReader) =>\n new ResponseHeaderEntry(\n header.string('entry'),\n header.string('nameConstant'),\n header.optionalString('description'),\n ),\n );\n }\n\n /** A manifest-relative path, resolved against the manifest's own directory. */\n resolve(manifestPath: string, relative: string): string {\n return path.resolve(path.dirname(manifestPath), relative);\n }\n}\n"]}
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
* It is rendered into `tags[]` in that order, and a docs theme builds its sidebar from `tags[]`.
|
|
26
26
|
* Alphabetising this array is not a cleanup; it reorders partner-facing navigation.
|
|
27
27
|
*/
|
|
28
|
+
import { SchemaNameEntry } from '@webpieces/api-doc-model';
|
|
28
29
|
export declare class ServerEntry {
|
|
29
30
|
readonly url: string;
|
|
30
31
|
readonly description: string | undefined;
|
|
@@ -110,9 +111,10 @@ export declare class OpenApiManifest {
|
|
|
110
111
|
readonly securitySchemeNames: readonly string[];
|
|
111
112
|
readonly errors: ErrorsEntry | undefined;
|
|
112
113
|
readonly responseHeaders: readonly ResponseHeaderEntry[];
|
|
114
|
+
readonly schemaNames: readonly SchemaNameEntry[];
|
|
113
115
|
constructor(title: string, version: string, servers: readonly ServerEntry[],
|
|
114
116
|
/** A markdown preamble, relative to the manifest. Rendered into `info.description`. */
|
|
115
|
-
descriptionFile: string | undefined, apis: readonly ApiEntry[], securitySchemeNames: readonly string[], errors: ErrorsEntry | undefined, responseHeaders: readonly ResponseHeaderEntry[]);
|
|
117
|
+
descriptionFile: string | undefined, apis: readonly ApiEntry[], securitySchemeNames: readonly string[], errors: ErrorsEntry | undefined, responseHeaders: readonly ResponseHeaderEntry[], schemaNames: readonly SchemaNameEntry[]);
|
|
116
118
|
}
|
|
117
119
|
/**
|
|
118
120
|
* A DTO library's `openapi.manifest.json` — `"kind": "components"` (#1058).
|
|
@@ -127,7 +129,8 @@ export declare class ComponentsManifest {
|
|
|
127
129
|
readonly title: string;
|
|
128
130
|
/** The library's entry files (usually `src/index.ts`), relative to the manifest's directory. */
|
|
129
131
|
readonly entries: readonly string[];
|
|
132
|
+
readonly schemaNames: readonly SchemaNameEntry[];
|
|
130
133
|
constructor(title: string,
|
|
131
134
|
/** The library's entry files (usually `src/index.ts`), relative to the manifest's directory. */
|
|
132
|
-
entries: readonly string[]);
|
|
135
|
+
entries: readonly string[], schemaNames: readonly SchemaNameEntry[]);
|
|
133
136
|
}
|
|
@@ -1,33 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ComponentsManifest = exports.OpenApiManifest = exports.ResponseHeaderEntry = exports.ErrorsEntry = exports.ErrorResponseEntry = exports.ApiEntry = exports.ServerEntry = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* `openapi.manifest.json`, as CLASSES.
|
|
6
|
-
*
|
|
7
|
-
* ## What is allowed in here, and what is not
|
|
8
|
-
*
|
|
9
|
-
* The manifest carries exactly what is **not a property of the code**, and nothing else. Every field
|
|
10
|
-
* below is a product decision, a deployment fact, or a NAME pointing at something the code owns:
|
|
11
|
-
*
|
|
12
|
-
* - `title`, `version` — product decisions.
|
|
13
|
-
* - `servers[]` — a deployment fact.
|
|
14
|
-
* - `descriptionFile` — a teaching decision.
|
|
15
|
-
* - `apis[]` — which contracts, in the order the published sidebar shows them.
|
|
16
|
-
* - `securitySchemeNames[]` — the published scheme KEYS only. Everything else about the schemes, and
|
|
17
|
-
* the AND-ed `security` requirement, is DERIVED from the contract's own `apiKey(...)`. A
|
|
18
|
-
* `components.securitySchemes` block here would be a second copy of header names the running
|
|
19
|
-
* server never reads, and nothing could contradict it.
|
|
20
|
-
* - `errors` — the document-wide failure contract, with the BODY read from a real TS type so the
|
|
21
|
-
* published shape cannot drift from the one on the wire.
|
|
22
|
-
* - `responseHeaders[]` — declared by `nameConstant` naming an exported const, never by a literal.
|
|
23
|
-
*
|
|
24
|
-
* Anything a renderer could read off the source instead belongs in the source.
|
|
25
|
-
*
|
|
26
|
-
* ## The ORDER of `apis[]` is published navigation
|
|
27
|
-
*
|
|
28
|
-
* It is rendered into `tags[]` in that order, and a docs theme builds its sidebar from `tags[]`.
|
|
29
|
-
* Alphabetising this array is not a cleanup; it reorders partner-facing navigation.
|
|
30
|
-
*/
|
|
31
4
|
class ServerEntry {
|
|
32
5
|
url;
|
|
33
6
|
description;
|
|
@@ -125,9 +98,10 @@ class OpenApiManifest {
|
|
|
125
98
|
securitySchemeNames;
|
|
126
99
|
errors;
|
|
127
100
|
responseHeaders;
|
|
101
|
+
schemaNames;
|
|
128
102
|
constructor(title, version, servers,
|
|
129
103
|
/** A markdown preamble, relative to the manifest. Rendered into `info.description`. */
|
|
130
|
-
descriptionFile, apis, securitySchemeNames, errors, responseHeaders) {
|
|
104
|
+
descriptionFile, apis, securitySchemeNames, errors, responseHeaders, schemaNames) {
|
|
131
105
|
this.title = title;
|
|
132
106
|
this.version = version;
|
|
133
107
|
this.servers = servers;
|
|
@@ -136,6 +110,7 @@ class OpenApiManifest {
|
|
|
136
110
|
this.securitySchemeNames = securitySchemeNames;
|
|
137
111
|
this.errors = errors;
|
|
138
112
|
this.responseHeaders = responseHeaders;
|
|
113
|
+
this.schemaNames = schemaNames;
|
|
139
114
|
}
|
|
140
115
|
}
|
|
141
116
|
exports.OpenApiManifest = OpenApiManifest;
|
|
@@ -151,11 +126,13 @@ exports.OpenApiManifest = OpenApiManifest;
|
|
|
151
126
|
class ComponentsManifest {
|
|
152
127
|
title;
|
|
153
128
|
entries;
|
|
129
|
+
schemaNames;
|
|
154
130
|
constructor(title,
|
|
155
131
|
/** The library's entry files (usually `src/index.ts`), relative to the manifest's directory. */
|
|
156
|
-
entries) {
|
|
132
|
+
entries, schemaNames) {
|
|
157
133
|
this.title = title;
|
|
158
134
|
this.entries = entries;
|
|
135
|
+
this.schemaNames = schemaNames;
|
|
159
136
|
}
|
|
160
137
|
}
|
|
161
138
|
exports.ComponentsManifest = ComponentsManifest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenApiManifest.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/manifest/OpenApiManifest.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"OpenApiManifest.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/manifest/OpenApiManifest.ts"],"names":[],"mappings":";;;AA6BA,MAAa,WAAW;IAEP;IACA;IAFb,YACa,GAAW,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BAAsC,EACtC,MAA+B,EAC/B,eAA+C,EAC/C,WAAuC;QATvC,UAAK,GAAL,KAAK,CAAQ;QACb,YAAO,GAAP,OAAO,CAAQ;QACf,YAAO,GAAP,OAAO,CAAwB;QAE/B,oBAAe,GAAf,eAAe,CAAoB;QACnC,SAAI,GAAJ,IAAI,CAAqB;QACzB,wBAAmB,GAAnB,mBAAmB,CAAmB;QACtC,WAAM,GAAN,MAAM,CAAyB;QAC/B,oBAAe,GAAf,eAAe,CAAgC;QAC/C,gBAAW,GAAX,WAAW,CAA4B;IACjD,CAAC;CACP;AAbD,0CAaC;AAED;;;;;;;;GAQG;AACH,MAAa,kBAAkB;IAEd;IAEA;IACA;IAJb,YACa,KAAa;IACtB,gGAAgG;IACvF,OAA0B,EAC1B,WAAuC;QAHvC,UAAK,GAAL,KAAK,CAAQ;QAEb,YAAO,GAAP,OAAO,CAAmB;QAC1B,gBAAW,GAAX,WAAW,CAA4B;IACjD,CAAC;CACP;AAPD,gDAOC","sourcesContent":["/**\n * `openapi.manifest.json`, as CLASSES.\n *\n * ## What is allowed in here, and what is not\n *\n * The manifest carries exactly what is **not a property of the code**, and nothing else. Every field\n * below is a product decision, a deployment fact, or a NAME pointing at something the code owns:\n *\n * - `title`, `version` — product decisions.\n * - `servers[]` — a deployment fact.\n * - `descriptionFile` — a teaching decision.\n * - `apis[]` — which contracts, in the order the published sidebar shows them.\n * - `securitySchemeNames[]` — the published scheme KEYS only. Everything else about the schemes, and\n * the AND-ed `security` requirement, is DERIVED from the contract's own `apiKey(...)`. A\n * `components.securitySchemes` block here would be a second copy of header names the running\n * server never reads, and nothing could contradict it.\n * - `errors` — the document-wide failure contract, with the BODY read from a real TS type so the\n * published shape cannot drift from the one on the wire.\n * - `responseHeaders[]` — declared by `nameConstant` naming an exported const, never by a literal.\n *\n * Anything a renderer could read off the source instead belongs in the source.\n *\n * ## The ORDER of `apis[]` is published navigation\n *\n * It is rendered into `tags[]` in that order, and a docs theme builds its sidebar from `tags[]`.\n * Alphabetising this array is not a cleanup; it reorders partner-facing navigation.\n */\nimport { SchemaNameEntry } from '@webpieces/api-doc-model';\n\nexport class ServerEntry {\n constructor(\n readonly url: string,\n readonly description: string | undefined,\n ) {}\n}\n\n/** One contract file the generator reads. */\nexport class ApiEntry {\n constructor(\n /** Path to the contract `.ts`, relative to the manifest's own directory. */\n readonly entry: string,\n /** The tag every operation of this contract carries — and one `tags[]` entry, in order. */\n readonly tag: string,\n /**\n * `webhook` moves the contract into the top-level `webhooks:` block: these are calls WE\n * make to a partner's server, not routes on ours.\n *\n * DECLARED, never sniffed from a `*WebhookApi` filename. A name convention would hide a\n * partner-visible decision inside a rename, and a rename is the one edit nobody reviews for\n * contract impact.\n */\n readonly kind: string | undefined,\n ) {}\n\n isWebhook(): boolean {\n return this.kind === 'webhook';\n }\n}\n\n/** One status code of the document-wide failure contract. */\nexport class ErrorResponseEntry {\n constructor(\n readonly status: string,\n readonly description: string,\n ) {}\n}\n\n/**\n * The document-wide failure contract.\n *\n * Document-wide and not per-operation on purpose: per-operation codes would be a second hand-written\n * list to keep in step with the handlers, and stating them once tells a partner the truth — any\n * operation can fail these ways.\n */\nexport class ErrorsEntry {\n constructor(\n /** The `.ts` file declaring the error body, relative to the manifest. */\n readonly entry: string,\n /** The exported TYPE name of the body. Read with the compiler, so it cannot drift. */\n readonly type: string,\n readonly responses: readonly ErrorResponseEntry[],\n ) {}\n}\n\n/**\n * One response header every operation carries.\n *\n * `nameConstant` names an exported `const` in `entry`, and the generator FOLDS it. A literal here\n * would be a copy of the header name that a rename leaves silently stale — and JSON cannot import,\n * so naming the constant is the only way for this file to point at the one the server actually\n * writes. Failing to fold it is a HARD FAILURE for the same reason.\n */\nexport class ResponseHeaderEntry {\n constructor(\n readonly entry: string,\n readonly nameConstant: string,\n readonly description: string | undefined,\n ) {}\n}\n\nexport class OpenApiManifest {\n constructor(\n readonly title: string,\n readonly version: string,\n readonly servers: readonly ServerEntry[],\n /** A markdown preamble, relative to the manifest. Rendered into `info.description`. */\n readonly descriptionFile: string | undefined,\n readonly apis: readonly ApiEntry[],\n readonly securitySchemeNames: readonly string[],\n readonly errors: ErrorsEntry | undefined,\n readonly responseHeaders: readonly ResponseHeaderEntry[],\n readonly schemaNames: readonly SchemaNameEntry[],\n ) {}\n}\n\n/**\n * A DTO library's `openapi.manifest.json` — `\"kind\": \"components\"` (#1058).\n *\n * It names the library's ENTRY FILES instead of contracts: the document it produces is\n * components-only — `openapi`, `info` and `components.schemas`, no paths — holding every type the\n * library exports and declares, which contract documents `$ref` instead of copying. There is no\n * `version` here: a library document's `info.version` IS the package version, read from its\n * `package.json`, so the two cannot disagree.\n */\nexport class ComponentsManifest {\n constructor(\n readonly title: string,\n /** The library's entry files (usually `src/index.ts`), relative to the manifest's directory. */\n readonly entries: readonly string[],\n readonly schemaNames: readonly SchemaNameEntry[],\n ) {}\n}\n"]}
|