@webpieces/openapi-generator 0.4.920 → 0.4.922

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.
@@ -1 +1 @@
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,EACX,WAA+B;QAD/B,QAAG,GAAH,GAAG,CAAQ;QACX,gBAAW,GAAX,WAAW,CAAoB;IACzC,CAAC;CACP;AALD,kCAKC;AAED,6CAA6C;AAC7C,MAAa,QAAQ;IAGJ;IAEA;IASA;IAbb;IACI,4EAA4E;IACnE,KAAa;IACtB,2FAA2F;IAClF,GAAW;IACpB;;;;;;;OAOG;IACM,IAAwB;QAXxB,UAAK,GAAL,KAAK,CAAQ;QAEb,QAAG,GAAH,GAAG,CAAQ;QASX,SAAI,GAAJ,IAAI,CAAoB;IAClC,CAAC;IAEJ,SAAS;QACL,OAAO,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC;IACnC,CAAC;CACJ;AApBD,4BAoBC;AAED,6DAA6D;AAC7D,MAAa,kBAAkB;IAEd;IACA;IAFb,YACa,MAAc,EACd,WAAmB;QADnB,WAAM,GAAN,MAAM,CAAQ;QACd,gBAAW,GAAX,WAAW,CAAQ;IAC7B,CAAC;CACP;AALD,gDAKC;AAED;;;;;;GAMG;AACH,MAAa,WAAW;IAGP;IAEA;IACA;IALb;IACI,yEAAyE;IAChE,KAAa;IACtB,sFAAsF;IAC7E,IAAY,EACZ,SAAwC;QAHxC,UAAK,GAAL,KAAK,CAAQ;QAEb,SAAI,GAAJ,IAAI,CAAQ;QACZ,cAAS,GAAT,SAAS,CAA+B;IAClD,CAAC;CACP;AARD,kCAQC;AAED;;;;;;;GAOG;AACH,MAAa,mBAAmB;IAEf;IACA;IACA;IAHb,YACa,KAAa,EACb,YAAoB,EACpB,WAA+B;QAF/B,UAAK,GAAL,KAAK,CAAQ;QACb,iBAAY,GAAZ,YAAY,CAAQ;QACpB,gBAAW,GAAX,WAAW,CAAoB;IACzC,CAAC;CACP;AAND,kDAMC;AAED,MAAa,eAAe;IAEX;IACA;IACA;IAEA;IACA;IACA;IACA;IACA;IACA;IAVb,YACa,KAAa,EACb,OAAe,EACf,OAA+B;IACxC,uFAAuF;IAC9E,eAAmC,EACnC,IAAyB,EACzB,mBAAsC,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"]}
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,EACX,WAA+B;QAD/B,QAAG,GAAH,GAAG,CAAQ;QACX,gBAAW,GAAX,WAAW,CAAoB;IACzC,CAAC;CACP;AALD,kCAKC;AAED,6CAA6C;AAC7C,MAAa,QAAQ;IAGJ;IAEA;IASA;IAbb;IACI,4EAA4E;IACnE,KAAa;IACtB,2FAA2F;IAClF,GAAW;IACpB;;;;;;;OAOG;IACM,IAAwB;QAXxB,UAAK,GAAL,KAAK,CAAQ;QAEb,QAAG,GAAH,GAAG,CAAQ;QASX,SAAI,GAAJ,IAAI,CAAoB;IAClC,CAAC;IAEJ,SAAS;QACL,OAAO,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC;IACnC,CAAC;CACJ;AApBD,4BAoBC;AAED,6DAA6D;AAC7D,MAAa,kBAAkB;IAEd;IACA;IAOA;IATb,YACa,MAAc,EACd,WAAmB;IAC5B;;;;;OAKG;IACM,YAAqB;QARrB,WAAM,GAAN,MAAM,CAAQ;QACd,gBAAW,GAAX,WAAW,CAAQ;QAOnB,iBAAY,GAAZ,YAAY,CAAS;IAC/B,CAAC;CACP;AAZD,gDAYC;AAED;;;;;;GAMG;AACH,MAAa,WAAW;IAGP;IAEA;IACA;IALb;IACI,yEAAyE;IAChE,KAAa;IACtB,sFAAsF;IAC7E,IAAY,EACZ,SAAwC;QAHxC,UAAK,GAAL,KAAK,CAAQ;QAEb,SAAI,GAAJ,IAAI,CAAQ;QACZ,cAAS,GAAT,SAAS,CAA+B;IAClD,CAAC;CACP;AARD,kCAQC;AAED;;;;;;;;;;GAUG;AACH,MAAa,mBAAmB;IAEf;IACA;IACA;IAKA;IARb,YACa,KAAa,EACb,UAAkB,EAClB,WAA+B;IACxC;;;OAGG;IACM,QAA6B;QAP7B,UAAK,GAAL,KAAK,CAAQ;QACb,eAAU,GAAV,UAAU,CAAQ;QAClB,gBAAW,GAAX,WAAW,CAAoB;QAK/B,aAAQ,GAAR,QAAQ,CAAqB;IACvC,CAAC;CACP;AAXD,kDAWC;AAED,MAAa,eAAe;IAEX;IACA;IACA;IAEA;IACA;IACA;IACA;IACA;IACA;IAVb,YACa,KAAa,EACb,OAAe,EACf,OAA+B;IACxC,uFAAuF;IAC9E,eAAmC,EACnC,IAAyB,EACzB,mBAAsC,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 `contextKey` naming an exported ContextKey, 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 * `true`: this failure can only happen to an AUTHENTICATED operation (a 401 for a bad\n * credential), so it is left OFF every operation whose resolved auth is public\n * (`@WpAuthPublic`) — a public endpoint cannot fail authentication. Omitted means `false`:\n * the response is listed on every operation.\n */\n readonly requiresAuth: boolean,\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 * `contextKey` names an exported `ContextKey` in `entry` — the export's name, or a dotted path into\n * one (`OneTabletKey.TX_ID`) — and the generator reads the header name off that key's own\n * `ContextKey.trusted(...)` / `ContextKey.untrusted(...)` definition: its `responseHeader`, which is\n * what the server's response choke point actually writes (#1249). A literal here would be a copy of\n * the header name that a rename leaves silently stale — and JSON cannot import, so naming the key is\n * the only way for this file to point at the one definition. Failing to resolve it is a HARD\n * FAILURE for the same reason.\n */\nexport class ResponseHeaderEntry {\n constructor(\n readonly entry: string,\n readonly contextKey: string,\n readonly description: string | undefined,\n /**\n * Rendered verbatim as the OpenAPI header object's `required`. Omitted means the document\n * does not state it, which OpenAPI reads as `false`.\n */\n readonly required: boolean | 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"]}
@@ -1,21 +0,0 @@
1
- /**
2
- * Fold an exported `const` out of a `.ts` file — the header NAME behind a manifest's `nameConstant`.
3
- *
4
- * ## Why the manifest names a CONSTANT and not the header
5
- *
6
- * JSON cannot import. A header name written as a literal in `openapi.manifest.json` is a copy of the
7
- * one the server writes, and a rename leaves the copy silently stale — the published document then
8
- * documents a header nothing sets, which no test can catch because both files are internally
9
- * consistent. Naming the constant makes the manifest point at the same declaration the server reads.
10
- *
11
- * ## Why it HARD-FAILS instead of falling back to the constant's text
12
- *
13
- * The fallback would publish `REQUEST_ID_HEADER` as a header name. That is a document that is wrong
14
- * in a way a reader cannot detect, which is the one failure mode a generated document exists to
15
- * remove. It is the same call `ConstantFolder` makes about an `@Endpoint` path, for the same reason.
16
- */
17
- export declare class ExportedConstantFolder {
18
- /** @param file absolute path to the `.ts` file declaring the constant. */
19
- fold(file: string, constantName: string): string;
20
- private find;
21
- }
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExportedConstantFolder = void 0;
4
- const tslib_1 = require("tslib");
5
- const fs = tslib_1.__importStar(require("node:fs"));
6
- const ts = tslib_1.__importStar(require("typescript"));
7
- const OpenApiGenerationError_1 = require("../OpenApiGenerationError");
8
- /**
9
- * Fold an exported `const` out of a `.ts` file — the header NAME behind a manifest's `nameConstant`.
10
- *
11
- * ## Why the manifest names a CONSTANT and not the header
12
- *
13
- * JSON cannot import. A header name written as a literal in `openapi.manifest.json` is a copy of the
14
- * one the server writes, and a rename leaves the copy silently stale — the published document then
15
- * documents a header nothing sets, which no test can catch because both files are internally
16
- * consistent. Naming the constant makes the manifest point at the same declaration the server reads.
17
- *
18
- * ## Why it HARD-FAILS instead of falling back to the constant's text
19
- *
20
- * The fallback would publish `REQUEST_ID_HEADER` as a header name. That is a document that is wrong
21
- * in a way a reader cannot detect, which is the one failure mode a generated document exists to
22
- * remove. It is the same call `ConstantFolder` makes about an `@Endpoint` path, for the same reason.
23
- */
24
- class ExportedConstantFolder {
25
- /** @param file absolute path to the `.ts` file declaring the constant. */
26
- fold(file, constantName) {
27
- if (!fs.existsSync(file)) {
28
- throw new OpenApiGenerationError_1.OpenApiGenerationError(`no file declaring '${constantName}'`, file, 'Point `entry` at the .ts file that exports the constant.');
29
- }
30
- const source = ts.createSourceFile(file, fs.readFileSync(file, 'utf8'), ts.ScriptTarget.ES2022,
31
- /*setParentNodes*/ true);
32
- const value = this.find(source, constantName);
33
- if (value === undefined) {
34
- throw new OpenApiGenerationError_1.OpenApiGenerationError(`'${constantName}' is not an exported string constant in this file`, file, `Declare it as \`export const ${constantName} = '<header-name>';\` — a value only ` +
35
- 'known at runtime cannot appear in a published document.');
36
- }
37
- return value;
38
- }
39
- find(source, constantName) {
40
- for (const statement of source.statements) {
41
- if (!ts.isVariableStatement(statement)) {
42
- continue;
43
- }
44
- for (const declaration of statement.declarationList.declarations) {
45
- if (ts.isIdentifier(declaration.name) &&
46
- declaration.name.text === constantName &&
47
- declaration.initializer !== undefined &&
48
- ts.isStringLiteralLike(declaration.initializer)) {
49
- return declaration.initializer.text;
50
- }
51
- }
52
- }
53
- return undefined;
54
- }
55
- }
56
- exports.ExportedConstantFolder = ExportedConstantFolder;
57
- //# sourceMappingURL=ExportedConstantFolder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExportedConstantFolder.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/load/ExportedConstantFolder.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,uDAAiC;AACjC,sEAAmE;AAEnE;;;;;;;;;;;;;;;GAeG;AACH,MAAa,sBAAsB;IAC/B,0EAA0E;IAC1E,IAAI,CAAC,IAAY,EAAE,YAAoB;QACnC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,+CAAsB,CAC5B,sBAAsB,YAAY,GAAG,EACrC,IAAI,EACJ,0DAA0D,CAC7D,CAAC;QACN,CAAC;QACD,MAAM,MAAM,GAAG,EAAE,CAAC,gBAAgB,CAC9B,IAAI,EACJ,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,EAC7B,EAAE,CAAC,YAAY,CAAC,MAAM;QACtB,kBAAkB,CAAC,IAAI,CAC1B,CAAC;QACF,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAC9C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACtB,MAAM,IAAI,+CAAsB,CAC5B,IAAI,YAAY,mDAAmD,EACnE,IAAI,EACJ,gCAAgC,YAAY,uCAAuC;gBAC/E,yDAAyD,CAChE,CAAC;QACN,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAEO,IAAI,CAAC,MAAqB,EAAE,YAAoB;QACpD,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACxC,IAAI,CAAC,EAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC;gBACrC,SAAS;YACb,CAAC;YACD,KAAK,MAAM,WAAW,IAAI,SAAS,CAAC,eAAe,CAAC,YAAY,EAAE,CAAC;gBAC/D,IACI,EAAE,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC;oBACjC,WAAW,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY;oBACtC,WAAW,CAAC,WAAW,KAAK,SAAS;oBACrC,EAAE,CAAC,mBAAmB,CAAC,WAAW,CAAC,WAAW,CAAC,EACjD,CAAC;oBACC,OAAO,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC;gBACxC,CAAC;YACL,CAAC;QACL,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AA9CD,wDA8CC","sourcesContent":["import * as fs from 'node:fs';\nimport * as ts from 'typescript';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\n\n/**\n * Fold an exported `const` out of a `.ts` file — the header NAME behind a manifest's `nameConstant`.\n *\n * ## Why the manifest names a CONSTANT and not the header\n *\n * JSON cannot import. A header name written as a literal in `openapi.manifest.json` is a copy of the\n * one the server writes, and a rename leaves the copy silently stale — the published document then\n * documents a header nothing sets, which no test can catch because both files are internally\n * consistent. Naming the constant makes the manifest point at the same declaration the server reads.\n *\n * ## Why it HARD-FAILS instead of falling back to the constant's text\n *\n * The fallback would publish `REQUEST_ID_HEADER` as a header name. That is a document that is wrong\n * in a way a reader cannot detect, which is the one failure mode a generated document exists to\n * remove. It is the same call `ConstantFolder` makes about an `@Endpoint` path, for the same reason.\n */\nexport class ExportedConstantFolder {\n /** @param file absolute path to the `.ts` file declaring the constant. */\n fold(file: string, constantName: string): string {\n if (!fs.existsSync(file)) {\n throw new OpenApiGenerationError(\n `no file declaring '${constantName}'`,\n file,\n 'Point `entry` at the .ts file that exports the constant.',\n );\n }\n const source = ts.createSourceFile(\n file,\n fs.readFileSync(file, 'utf8'),\n ts.ScriptTarget.ES2022,\n /*setParentNodes*/ true,\n );\n const value = this.find(source, constantName);\n if (value === undefined) {\n throw new OpenApiGenerationError(\n `'${constantName}' is not an exported string constant in this file`,\n file,\n `Declare it as \\`export const ${constantName} = '<header-name>';\\` — a value only ` +\n 'known at runtime cannot appear in a published document.',\n );\n }\n return value;\n }\n\n private find(source: ts.SourceFile, constantName: string): string | undefined {\n for (const statement of source.statements) {\n if (!ts.isVariableStatement(statement)) {\n continue;\n }\n for (const declaration of statement.declarationList.declarations) {\n if (\n ts.isIdentifier(declaration.name) &&\n declaration.name.text === constantName &&\n declaration.initializer !== undefined &&\n ts.isStringLiteralLike(declaration.initializer)\n ) {\n return declaration.initializer.text;\n }\n }\n }\n return undefined;\n }\n}\n"]}