@webpieces/openapi-generator 0.4.921 → 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":"SecurityDeriver.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/SecurityDeriver.ts"],"names":[],"mappings":";;;AACA,mDAA2D;AAC3D,sEAAmE;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,eAAe;IACxB,SAAS,CAAC,IAAgC,EAAE,iBAAmD;QAC3F,MAAM,OAAO,GAAG,IAAI,EAAE,OAAO,CAAC;QAC9B,IAAI,CAAC,OAAO,EAAE,MAAM;YAAE,OAAO,SAAS,CAAC;QACvC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,iBAAiB,CAAC;QACnF,MAAM,YAAY,GAAgB,EAAE,CAAC;QACrC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC3B,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC3B,IAAI,CAAC,iBAAiB;oBAAE,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;gBAC/G,YAAY,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,CAAC;YAC5C,CAAC;iBAAM,CAAC;gBACJ,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBAC3C,mFAAmF;gBACnF,kFAAkF;gBAClF,IAAI,CAAC,IAAI;oBAAE,OAAO,SAAS,CAAC;gBAC5B,YAAY,CAAC,IAAI,CAAC,IAAI,uBAAU,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;YACtD,CAAC;QACL,CAAC;QACD,OAAO,YAAY,CAAC;IACxB,CAAC;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BAAU,EAAE;aAClB,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC;aACrB,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC;aACnB,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC;aAC5B,GAAG,CAAC,aAAa,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IACpD,CAAC;IAED,8FAA8F;IAC9F,WAAW,CAAC,WAA8B;QACtC,MAAM,KAAK,GAAG,IAAI,uBAAU,EAAE,CAAC;QAC/B,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;YAC7B,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACxB,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;CACJ;AA1GD,0CA0GC","sourcesContent":["import { DocumentedAuth, DocumentedApiKey, DocumentedApiKeyCredential, DocumentedEndpoint } from '@webpieces/api-doc-model';\nimport { JsonObject, JsonValue } from '../json/JsonObject';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\n\n/**\n * `components.securitySchemes` and the `security` requirement, DERIVED from the contract's own\n * `apiKey(regime, credentials)`. The manifest contributes the published KEYS and nothing else.\n *\n * ## Why the schemes are not in the manifest\n *\n * A `components.securitySchemes` block in a JSON file would be a second copy of header names the\n * running server never reads — and nothing could contradict it. Deriving them from the decorator\n * means the published document and the hook that enforces the credential are the same declaration,\n * so the document cannot say `x-api-key` while the server checks `x-partner-key`. The manifest keeps\n * the KEYS because a scheme key is partner-visible naming, which is a product decision.\n *\n * ## ONE requirement object holding every scheme, never a list of one-key objects\n *\n * OpenAPI's `security` is a list of ALTERNATIVES, and each alternative is an object whose keys must\n * ALL be satisfied. So:\n *\n * ```\n * [{ PartnerApiKey: [], PartnerOrg: [] }] // AND — present both. What a real regime means.\n * [{ PartnerApiKey: [] }, { PartnerOrg: [] }] // OR — \"either header alone suffices\". A lie.\n * ```\n *\n * The second form is the dangerous default because it is what \"a list of credentials\" reads like,\n * and NO BUILD COULD CONTRADICT IT: the document would be well-formed, the tooling green, and a\n * partner told they may skip the organization header. Hence one object, always.\n */\nexport class SecurityDeriver {\n operation(auth: DocumentedAuth | undefined, apiKeyRequirement: readonly JsonValue[] | undefined): readonly JsonValue[] | undefined {\n const methods = auth?.methods;\n if (!methods?.length) return undefined;\n if (methods.length === 1 && methods[0].kind === 'apikey') return apiKeyRequirement;\n const alternatives: JsonValue[] = [];\n for (const method of methods) {\n if (method.kind === 'apikey') {\n if (!apiKeyRequirement) throw new Error('Mixed credentials require an explicit API-key security requirement.');\n alternatives.push(...apiKeyRequirement);\n } else {\n const name = this.builtinName(method.kind);\n // Vendor signatures do not declare their wire headers. Keep the complete canonical\n // authentication extension rather than inventing a header or publishing a subset.\n if (!name) return undefined;\n alternatives.push(new JsonObject().set(name, []));\n }\n }\n return alternatives;\n }\n\n addBuiltinSchemes(schemes: JsonObject, endpoints: readonly DocumentedEndpoint[]): JsonObject {\n const added = new Set<string>();\n for (const endpoint of endpoints) for (const method of endpoint.auth?.methods ?? []) {\n const name = this.builtinName(method.kind);\n if (!name || added.has(name)) continue;\n if (schemes.has(name)) throw new Error(`securitySchemeNames reserves '${name}' for framework credentials; choose another API-key scheme name.`);\n added.add(name);\n schemes.set(name, new JsonObject().set('type', 'http').set('scheme', method.kind === 'shared-secret' ? 'Webpieces' : 'bearer'));\n }\n return schemes;\n }\n\n private builtinName(kind: string): string | undefined {\n switch (kind) {\n case 'jwt': return 'WebpiecesJwt';\n case 'oidc': return 'WebpiecesOidc';\n case 'shared-secret': return 'WebpiecesSharedSecret';\n default: return undefined;\n }\n }\n\n /** Every scheme, keyed by the manifest's published names, in declaration order. */\n schemes(\n apiKey: DocumentedApiKey,\n schemeNames: readonly string[],\n manifestPath: string,\n ): JsonObject {\n if (schemeNames.length !== apiKey.credentials.length) {\n throw new OpenApiGenerationError(\n `securitySchemeNames has ${schemeNames.length} name(s) but the '${apiKey.regime}' ` +\n `regime declares ${apiKey.credentials.length} credential(s)`,\n manifestPath,\n 'Give exactly one published scheme name per credential, in the order the ' +\n 'contract declares them. The names are partner-visible; the credentials are not ' +\n 'the manifest to choose.',\n );\n }\n const schemes = new JsonObject();\n for (let i = 0; i < schemeNames.length; i++) {\n schemes.set(schemeNames[i]!, this.scheme(apiKey.credentials[i]!, manifestPath));\n }\n return schemes;\n }\n\n /**\n * ONE credential -> ONE scheme. The two shapes are STRUCTURALLY different documents, which is\n * exactly why `ApiKeyCredential` is a union in the framework rather than one optional field.\n */\n private scheme(credential: DocumentedApiKeyCredential, manifestPath: string): JsonObject {\n if (credential.location === 'bearer') {\n return new JsonObject()\n .set('type', 'http')\n .set('scheme', 'bearer')\n .set('description', credential.description);\n }\n if (credential.location !== 'header') {\n throw new OpenApiGenerationError(\n `unknown api-key credential location '${credential.location}'`,\n manifestPath,\n \"A credential rides `in: 'header'` with a name, or `in: 'bearer'`.\",\n );\n }\n if (credential.name === undefined) {\n throw new OpenApiGenerationError(\n 'a header api-key credential declares no header name',\n manifestPath,\n \"Write `{ in: 'header', name: 'x-api-key' }`; a header credential with no name \" +\n 'is unusable and cannot be published.',\n );\n }\n return new JsonObject()\n .set('type', 'apiKey')\n .set('in', 'header')\n .set('name', credential.name)\n .set('description', credential.description);\n }\n\n /** The ONE AND-ed requirement — see the class doc for why it is one object and not a list. */\n requirement(schemeNames: readonly string[]): readonly JsonValue[] {\n const anded = new JsonObject();\n for (const name of schemeNames) {\n anded.set(name, []);\n }\n return [anded];\n }\n}\n"]}
1
+ {"version":3,"file":"SecurityDeriver.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/generate/SecurityDeriver.ts"],"names":[],"mappings":";;;AACA,mDAA2D;AAC3D,sEAAmE;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,eAAe;IACxB,SAAS,CAAC,IAAgC,EAAE,iBAAmD;QAC3F,MAAM,OAAO,GAAG,IAAI,EAAE,OAAO,CAAC;QAC9B,IAAI,C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AAI,EAAE,EAAE,CAAC,CAAC;QACxB,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;CACJ;AA5GD,0CA4GC","sourcesContent":["import { DocumentedAuth, DocumentedApiKey, DocumentedApiKeyCredential, DocumentedEndpoint } from '@webpieces/api-doc-model';\nimport { JsonObject, JsonValue } from '../json/JsonObject';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\n\n/**\n * `components.securitySchemes` and the `security` requirement, DERIVED from the contract's own\n * `apiKey(regime, credentials)`. The manifest contributes the published KEYS and nothing else.\n *\n * ## Why the schemes are not in the manifest\n *\n * A `components.securitySchemes` block in a JSON file would be a second copy of header names the\n * running server never reads — and nothing could contradict it. Deriving them from the decorator\n * means the published document and the hook that enforces the credential are the same declaration,\n * so the document cannot say `x-api-key` while the server checks `x-partner-key`. The manifest keeps\n * the KEYS because a scheme key is partner-visible naming, which is a product decision.\n *\n * ## ONE requirement object holding every scheme, never a list of one-key objects\n *\n * OpenAPI's `security` is a list of ALTERNATIVES, and each alternative is an object whose keys must\n * ALL be satisfied. So:\n *\n * ```\n * [{ PartnerApiKey: [], PartnerOrg: [] }] // AND — present both. What a real regime means.\n * [{ PartnerApiKey: [] }, { PartnerOrg: [] }] // OR — \"either header alone suffices\". A lie.\n * ```\n *\n * The second form is the dangerous default because it is what \"a list of credentials\" reads like,\n * and NO BUILD COULD CONTRADICT IT: the document would be well-formed, the tooling green, and a\n * partner told they may skip the organization header. Hence one object, always.\n */\nexport class SecurityDeriver {\n operation(auth: DocumentedAuth | undefined, apiKeyRequirement: readonly JsonValue[] | undefined): readonly JsonValue[] | undefined {\n const methods = auth?.methods;\n if (!methods?.length) return undefined;\n if (methods.length === 1 && methods[0].kind === 'apikey') return apiKeyRequirement;\n const alternatives: JsonValue[] = [];\n for (const method of methods) {\n if (method.kind === 'apikey') {\n if (!apiKeyRequirement) throw new Error('Mixed credentials require an explicit API-key security requirement.');\n alternatives.push(...apiKeyRequirement);\n } else {\n const name = this.builtinName(method.kind);\n // Vendor signatures do not declare their wire headers. Keep the complete canonical\n // authentication extension rather than inventing a header or publishing a subset.\n if (!name) return undefined;\n alternatives.push(new JsonObject().set(name, []));\n }\n }\n return alternatives;\n }\n\n addBuiltinSchemes(schemes: JsonObject, endpoints: readonly DocumentedEndpoint[]): JsonObject {\n const added = new Set<string>();\n for (const endpoint of endpoints) for (const method of endpoint.auth?.methods ?? []) {\n const name = this.builtinName(method.kind);\n if (!name || added.has(name)) continue;\n if (schemes.has(name)) throw new Error(`securitySchemeNames reserves '${name}' for framework credentials; choose another API-key scheme name.`);\n added.add(name);\n schemes.set(name, new JsonObject().set('type', 'http').set('scheme', method.kind === 'shared-secret' ? 'Webpieces' : 'bearer'));\n }\n return schemes;\n }\n\n private builtinName(kind: string): string | undefined {\n switch (kind) {\n case 'jwt': return 'WebpiecesJwt';\n case 'oidc': return 'WebpiecesOidc';\n case 'shared-secret': return 'WebpiecesSharedSecret';\n default: return undefined;\n }\n }\n\n /** Every scheme, keyed by the manifest's published names, in declaration order. */\n schemes(\n apiKey: DocumentedApiKey,\n schemeNames: readonly string[],\n manifestPath: string,\n ): JsonObject {\n if (schemeNames.length !== apiKey.credentials.length) {\n throw new OpenApiGenerationError(\n `securitySchemeNames has ${schemeNames.length} name(s) but the '${apiKey.regime}' ` +\n `regime declares ${apiKey.credentials.length} credential(s)`,\n manifestPath,\n 'Give exactly one published scheme name per credential, in the order the ' +\n 'contract declares them. The names are partner-visible; the credentials are not ' +\n 'the manifest to choose.',\n );\n }\n const schemes = new JsonObject();\n for (let i = 0; i < schemeNames.length; i++) {\n schemes.set(schemeNames[i]!, this.scheme(apiKey.credentials[i]!, manifestPath));\n }\n return schemes;\n }\n\n /**\n * ONE credential -> ONE scheme. The two shapes are STRUCTURALLY different documents, which is\n * exactly why `ApiKeyCredential` is a union in the framework rather than one optional field.\n */\n private scheme(credential: DocumentedApiKeyCredential, manifestPath: string): JsonObject {\n if (credential.location === 'bearer') {\n return new JsonObject()\n .set('type', 'http')\n .set('scheme', 'bearer')\n .set('description', credential.description);\n }\n if (credential.location !== 'header') {\n throw new OpenApiGenerationError(\n `unknown api-key credential location '${credential.location}'`,\n manifestPath,\n \"A credential rides `in: 'header'` with its ContextKey, or `in: 'bearer'`.\",\n );\n }\n // The extractor reads the name off the credential's ContextKey and refuses, quoting the key,\n // when it cannot — so a model reaching here without one was built by hand, not extracted.\n if (credential.name === undefined) {\n throw new OpenApiGenerationError(\n 'a header api-key credential reached the generator with no resolved header name',\n manifestPath,\n \"Declare it as `{ in: 'header', key: MyKeys.API_KEY }` and let the extractor read the \" +\n \"header name off that ContextKey's httpHeader.\",\n );\n }\n return new JsonObject()\n .set('type', 'apiKey')\n .set('in', 'header')\n .set('name', credential.name)\n .set('description', credential.description);\n }\n\n /** The ONE AND-ed requirement — see the class doc for why it is one object and not a list. */\n requirement(schemeNames: readonly string[]): readonly JsonValue[] {\n const anded = new JsonObject();\n for (const name of schemeNames) {\n anded.set(name, []);\n }\n return [anded];\n }\n}\n"]}
package/src/index.d.ts CHANGED
@@ -27,7 +27,6 @@ export type { SchemaPlacement } from './generate/SchemaPlacement';
27
27
  export { MissingComponents, PublishedComponents, UpstreamComponentsIndex, } from './generate/UpstreamComponents';
28
28
  export { ComponentsLocator, LocatedComponents } from './load/ComponentsLocator';
29
29
  export { SecurityDeriver } from './generate/SecurityDeriver';
30
- export { ExportedConstantFolder } from './load/ExportedConstantFolder';
31
30
  export { ForeignFailure } from './load/ForeignFailure';
32
31
  export { InputsLoader } from './load/InputsLoader';
33
32
  export { ArtifactWriter, GeneratedArtifact } from './emit/ArtifactWriter';
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WpOpenApiMain = exports.USAGE = exports.OpenApiCli = exports.CliResult = exports.GeneratedArtifact = exports.ArtifactWriter = exports.InputsLoader = exports.ForeignFailure = exports.ExportedConstantFolder = exports.SecurityDeriver = exports.LocatedComponents = exports.ComponentsLocator = exports.UpstreamComponentsIndex = exports.PublishedComponents = exports.MissingComponents = exports.SplitPlacement = exports.DiscoveryPlacement = exports.ComponentsReference = exports.BundledPlacement = exports.BundledNames = exports.UnmappedField = exports.SchemaRenderer = exports.ResponseContract = exports.OperationRenderer = exports.OpenApiGenerator = exports.OPERATION_SEMANTICS = exports.INTERNAL_ONLY_LINE = exports.DocumentSelection = exports.ResolvedResponseHeader = exports.GenerationInputs = exports.GeneratedDocuments = exports.GeneratedDocument = exports.ContractModel = exports.ComponentsInputs = exports.ManifestLoader = exports.JsonReader = exports.ServerEntry = exports.ResponseHeaderEntry = exports.OpenApiManifest = exports.ErrorsEntry = exports.ErrorResponseEntry = exports.ComponentsManifest = exports.ApiEntry = exports.YamlReader = exports.YamlWriter = exports.JsonWriter = exports.JsonObject = exports.OpenApiGenerationError = void 0;
3
+ exports.WpOpenApiMain = exports.USAGE = exports.OpenApiCli = exports.CliResult = exports.GeneratedArtifact = exports.ArtifactWriter = exports.InputsLoader = exports.ForeignFailure = exports.SecurityDeriver = exports.LocatedComponents = exports.ComponentsLocator = exports.UpstreamComponentsIndex = exports.PublishedComponents = exports.MissingComponents = exports.SplitPlacement = exports.DiscoveryPlacement = exports.ComponentsReference = exports.BundledPlacement = exports.BundledNames = exports.UnmappedField = exports.SchemaRenderer = exports.ResponseContract = exports.OperationRenderer = exports.OpenApiGenerator = exports.OPERATION_SEMANTICS = exports.INTERNAL_ONLY_LINE = exports.DocumentSelection = exports.ResolvedResponseHeader = exports.GenerationInputs = exports.GeneratedDocuments = exports.GeneratedDocument = exports.ContractModel = exports.ComponentsInputs = exports.ManifestLoader = exports.JsonReader = exports.ServerEntry = exports.ResponseHeaderEntry = exports.OpenApiManifest = exports.ErrorsEntry = exports.ErrorResponseEntry = exports.ComponentsManifest = exports.ApiEntry = exports.YamlReader = exports.YamlWriter = exports.JsonWriter = exports.JsonObject = exports.OpenApiGenerationError = void 0;
4
4
  /**
5
5
  * `@webpieces/openapi-generator` — render an `ApiDocModel` to OpenAPI 3.1.0.
6
6
  *
@@ -67,8 +67,6 @@ Object.defineProperty(exports, "ComponentsLocator", { enumerable: true, get: fun
67
67
  Object.defineProperty(exports, "LocatedComponents", { enumerable: true, get: function () { return ComponentsLocator_1.LocatedComponents; } });
68
68
  var SecurityDeriver_1 = require("./generate/SecurityDeriver");
69
69
  Object.defineProperty(exports, "SecurityDeriver", { enumerable: true, get: function () { return SecurityDeriver_1.SecurityDeriver; } });
70
- var ExportedConstantFolder_1 = require("./load/ExportedConstantFolder");
71
- Object.defineProperty(exports, "ExportedConstantFolder", { enumerable: true, get: function () { return ExportedConstantFolder_1.ExportedConstantFolder; } });
72
70
  var ForeignFailure_1 = require("./load/ForeignFailure");
73
71
  Object.defineProperty(exports, "ForeignFailure", { enumerable: true, get: function () { return ForeignFailure_1.ForeignFailure; } });
74
72
  var InputsLoader_1 = require("./load/InputsLoader");
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/docs/openapi-generator/src/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,mEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAC/B,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AAEnB,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AACnB,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AACnB,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AACnB,8DAQoC;AAPhC,2GAAA,QAAQ,OAAA;AACR,qHAAA,kBAAkB,OAAA;AAClB,qHAAA,kBAAkB,OAAA;AAClB,8GAAA,WAAW,OAAA;AACX,kHAAA,eAAe,OAAA;AACf,sHAAA,mBAAmB,OAAA;AACnB,8GAAA,WAAW,OAAA;AAEf,oDAAmD;AAA1C,wGAAA,UAAU,OAAA;AACnB,4DAA2D;AAAlD,gHAAA,cAAc,OAAA;AACvB,gEAOqC;AANjC,oHAAA,gBAAgB,OAAA;AAChB,iHAAA,aAAa,OAAA;AACb,qHAAA,iBAAiB,OAAA;AACjB,sHAAA,kBAAkB,OAAA;AAClB,oHAAA,gBAAgB,OAAA;AAChB,0HAAA,sBAAsB,OAAA;AAE1B,kEAIsC;AAHlC,sHAAA,iBAAiB,OAAA;AACjB,uHAAA,kBAAkB,OAAA;AAClB,wHAAA,mBAAmB,OAAA;AAEvB,gEAA+D;AAAtD,oHAAA,gBAAgB,OAAA;AACzB,kEAAmF;AAA1E,sHAAA,iBAAiB,OAAA;AAAE,qHAAA,gBAAgB,OAAA;AAC5C,4DAA0E;AAAjE,gHAAA,cAAc,OAAA;AAAE,+GAAA,aAAa,OAAA;AACtC,8DAMoC;AALhC,+GAAA,YAAY,OAAA;AACZ,mHAAA,gBAAgB,OAAA;AAChB,sHAAA,mBAAmB,OAAA;AACnB,qHAAA,kBAAkB,OAAA;AAClB,iHAAA,cAAc,OAAA;AAGlB,oEAIuC;AAHnC,uHAAA,iBAAiB,OAAA;AACjB,yHAAA,mBAAmB,OAAA;AACnB,6HAAA,uBAAuB,OAAA;AAE3B,8DAAgF;AAAvE,sHAAA,iBAAiB,OAAA;AAAE,sHAAA,iBAAiB,OAAA;AAC7C,8DAA6D;AAApD,kHAAA,eAAe,OAAA;AACxB,wEAAuE;AAA9D,gIAAA,sBAAsB,OAAA;AAC/B,wDAAuD;AAA9C,gHAAA,cAAc,OAAA;AACvB,oDAAmD;AAA1C,4GAAA,YAAY,OAAA;AACrB,wDAA0E;AAAjE,gHAAA,cAAc,OAAA;AAAE,mHAAA,iBAAiB,OAAA;AAE1C,+CAAgE;AAAvD,uGAAA,SAAS,OAAA;AAAE,wGAAA,UAAU,OAAA;AAAE,mGAAA,KAAK,OAAA;AACrC,qDAAoD;AAA3C,8GAAA,aAAa,OAAA","sourcesContent":["/**\n * `@webpieces/openapi-generator` — render an `ApiDocModel` to OpenAPI 3.1.0.\n *\n * ONE generation pass produces TWO documents: the CANONICAL internal one, which carries every\n * operation including hidden ones plus the `x-mcp-*` extensions, and the CUSTOMER one, from which a\n * hidden endpoint is absent entirely. They are byte-identical when nothing is hidden, which is the\n * property that makes hiding reviewable — see `responsibilities.md`.\n *\n * It ships the `wp-openapi` bin, and depends on `typescript` and `@webpieces/api-doc-model` alone.\n */\nexport { OpenApiGenerationError } from './OpenApiGenerationError';\nexport { JsonObject } from './json/JsonObject';\nexport type { JsonValue } from './json/JsonObject';\nexport { JsonWriter } from './json/JsonWriter';\nexport { YamlWriter } from './json/YamlWriter';\nexport { YamlReader } from './json/YamlReader';\nexport {\n ApiEntry,\n ComponentsManifest,\n ErrorResponseEntry,\n ErrorsEntry,\n OpenApiManifest,\n ResponseHeaderEntry,\n ServerEntry,\n} from './manifest/OpenApiManifest';\nexport { JsonReader } from './manifest/JsonReader';\nexport { ManifestLoader } from './manifest/ManifestLoader';\nexport {\n ComponentsInputs,\n ContractModel,\n GeneratedDocument,\n GeneratedDocuments,\n GenerationInputs,\n ResolvedResponseHeader,\n} from './generate/GenerationInputs';\nexport {\n DocumentSelection,\n INTERNAL_ONLY_LINE,\n OPERATION_SEMANTICS,\n} from './generate/DocumentSelection';\nexport { OpenApiGenerator } from './generate/OpenApiGenerator';\nexport { OperationRenderer, ResponseContract } from './generate/OperationRenderer';\nexport { SchemaRenderer, UnmappedField } from './generate/SchemaRenderer';\nexport {\n BundledNames,\n BundledPlacement,\n ComponentsReference,\n DiscoveryPlacement,\n SplitPlacement,\n} from './generate/SchemaPlacement';\nexport type { SchemaPlacement } from './generate/SchemaPlacement';\nexport {\n MissingComponents,\n PublishedComponents,\n UpstreamComponentsIndex,\n} from './generate/UpstreamComponents';\nexport { ComponentsLocator, LocatedComponents } from './load/ComponentsLocator';\nexport { SecurityDeriver } from './generate/SecurityDeriver';\nexport { ExportedConstantFolder } from './load/ExportedConstantFolder';\nexport { ForeignFailure } from './load/ForeignFailure';\nexport { InputsLoader } from './load/InputsLoader';\nexport { ArtifactWriter, GeneratedArtifact } from './emit/ArtifactWriter';\nexport type { OutputFormat } from './emit/ArtifactWriter';\nexport { CliResult, OpenApiCli, USAGE } from './cli/OpenApiCli';\nexport { WpOpenApiMain } from './cli/WpOpenApiMain';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/docs/openapi-generator/src/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,mEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAC/B,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AAEnB,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AACnB,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AACnB,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AACnB,8DAQoC;AAPhC,2GAAA,QAAQ,OAAA;AACR,qHAAA,kBAAkB,OAAA;AAClB,qHAAA,kBAAkB,OAAA;AAClB,8GAAA,WAAW,OAAA;AACX,kHAAA,eAAe,OAAA;AACf,sHAAA,mBAAmB,OAAA;AACnB,8GAAA,WAAW,OAAA;AAEf,oDAAmD;AAA1C,wGAAA,UAAU,OAAA;AACnB,4DAA2D;AAAlD,gHAAA,cAAc,OAAA;AACvB,gEAOqC;AANjC,oHAAA,gBAAgB,OAAA;AAChB,iHAAA,aAAa,OAAA;AACb,qHAAA,iBAAiB,OAAA;AACjB,sHAAA,kBAAkB,OAAA;AAClB,oHAAA,gBAAgB,OAAA;AAChB,0HAAA,sBAAsB,OAAA;AAE1B,kEAIsC;AAHlC,sHAAA,iBAAiB,OAAA;AACjB,uHAAA,kBAAkB,OAAA;AAClB,wHAAA,mBAAmB,OAAA;AAEvB,gEAA+D;AAAtD,oHAAA,gBAAgB,OAAA;AACzB,kEAAmF;AAA1E,sHAAA,iBAAiB,OAAA;AAAE,qHAAA,gBAAgB,OAAA;AAC5C,4DAA0E;AAAjE,gHAAA,cAAc,OAAA;AAAE,+GAAA,aAAa,OAAA;AACtC,8DAMoC;AALhC,+GAAA,YAAY,OAAA;AACZ,mHAAA,gBAAgB,OAAA;AAChB,sHAAA,mBAAmB,OAAA;AACnB,qHAAA,kBAAkB,OAAA;AAClB,iHAAA,cAAc,OAAA;AAGlB,oEAIuC;AAHnC,uHAAA,iBAAiB,OAAA;AACjB,yHAAA,mBAAmB,OAAA;AACnB,6HAAA,uBAAuB,OAAA;AAE3B,8DAAgF;AAAvE,sHAAA,iBAAiB,OAAA;AAAE,sHAAA,iBAAiB,OAAA;AAC7C,8DAA6D;AAApD,kHAAA,eAAe,OAAA;AACxB,wDAAuD;AAA9C,gHAAA,cAAc,OAAA;AACvB,oDAAmD;AAA1C,4GAAA,YAAY,OAAA;AACrB,wDAA0E;AAAjE,gHAAA,cAAc,OAAA;AAAE,mHAAA,iBAAiB,OAAA;AAE1C,+CAAgE;AAAvD,uGAAA,SAAS,OAAA;AAAE,wGAAA,UAAU,OAAA;AAAE,mGAAA,KAAK,OAAA;AACrC,qDAAoD;AAA3C,8GAAA,aAAa,OAAA","sourcesContent":["/**\n * `@webpieces/openapi-generator` — render an `ApiDocModel` to OpenAPI 3.1.0.\n *\n * ONE generation pass produces TWO documents: the CANONICAL internal one, which carries every\n * operation including hidden ones plus the `x-mcp-*` extensions, and the CUSTOMER one, from which a\n * hidden endpoint is absent entirely. They are byte-identical when nothing is hidden, which is the\n * property that makes hiding reviewable — see `responsibilities.md`.\n *\n * It ships the `wp-openapi` bin, and depends on `typescript` and `@webpieces/api-doc-model` alone.\n */\nexport { OpenApiGenerationError } from './OpenApiGenerationError';\nexport { JsonObject } from './json/JsonObject';\nexport type { JsonValue } from './json/JsonObject';\nexport { JsonWriter } from './json/JsonWriter';\nexport { YamlWriter } from './json/YamlWriter';\nexport { YamlReader } from './json/YamlReader';\nexport {\n ApiEntry,\n ComponentsManifest,\n ErrorResponseEntry,\n ErrorsEntry,\n OpenApiManifest,\n ResponseHeaderEntry,\n ServerEntry,\n} from './manifest/OpenApiManifest';\nexport { JsonReader } from './manifest/JsonReader';\nexport { ManifestLoader } from './manifest/ManifestLoader';\nexport {\n ComponentsInputs,\n ContractModel,\n GeneratedDocument,\n GeneratedDocuments,\n GenerationInputs,\n ResolvedResponseHeader,\n} from './generate/GenerationInputs';\nexport {\n DocumentSelection,\n INTERNAL_ONLY_LINE,\n OPERATION_SEMANTICS,\n} from './generate/DocumentSelection';\nexport { OpenApiGenerator } from './generate/OpenApiGenerator';\nexport { OperationRenderer, ResponseContract } from './generate/OperationRenderer';\nexport { SchemaRenderer, UnmappedField } from './generate/SchemaRenderer';\nexport {\n BundledNames,\n BundledPlacement,\n ComponentsReference,\n DiscoveryPlacement,\n SplitPlacement,\n} from './generate/SchemaPlacement';\nexport type { SchemaPlacement } from './generate/SchemaPlacement';\nexport {\n MissingComponents,\n PublishedComponents,\n UpstreamComponentsIndex,\n} from './generate/UpstreamComponents';\nexport { ComponentsLocator, LocatedComponents } from './load/ComponentsLocator';\nexport { SecurityDeriver } from './generate/SecurityDeriver';\nexport { ForeignFailure } from './load/ForeignFailure';\nexport { InputsLoader } from './load/InputsLoader';\nexport { ArtifactWriter, GeneratedArtifact } from './emit/ArtifactWriter';\nexport type { OutputFormat } from './emit/ArtifactWriter';\nexport { CliResult, OpenApiCli, USAGE } from './cli/OpenApiCli';\nexport { WpOpenApiMain } from './cli/WpOpenApiMain';\n"]}
@@ -9,7 +9,6 @@ import { ComponentsInputs, GenerationInputs } from '../generate/GenerationInputs
9
9
  */
10
10
  export declare class InputsLoader {
11
11
  private readonly manifests;
12
- private readonly constants;
13
12
  private extractor;
14
13
  private readonly packages;
15
14
  private readonly locator;
@@ -12,7 +12,6 @@ const ManifestLoader_1 = require("../manifest/ManifestLoader");
12
12
  const GenerationInputs_1 = require("../generate/GenerationInputs");
13
13
  const UpstreamComponents_1 = require("../generate/UpstreamComponents");
14
14
  const ComponentsLocator_1 = require("./ComponentsLocator");
15
- const ExportedConstantFolder_1 = require("./ExportedConstantFolder");
16
15
  const ForeignFailure_1 = require("./ForeignFailure");
17
16
  /** A `path/to/File.ts:12:5` location's FILE. */
18
17
  const LINE_AND_COLUMN = /:\d+:\d+$/;
@@ -44,7 +43,6 @@ const FALLBACK_OPTIONS = {
44
43
  */
45
44
  class InputsLoader {
46
45
  manifests = new ManifestLoader_1.ManifestLoader();
47
- constants = new ExportedConstantFolder_1.ExportedConstantFolder();
48
46
  extractor = new api_doc_model_1.ApiDocExtractor();
49
47
  packages = new api_doc_model_1.PackageOfFile();
50
48
  locator = new ComponentsLocator_1.ComponentsLocator();
@@ -207,7 +205,15 @@ class InputsLoader {
207
205
  responseHeaders(manifestPath, manifest) {
208
206
  return manifest.responseHeaders.map((header) => {
209
207
  const file = this.manifests.resolve(manifestPath, header.entry);
210
- return new GenerationInputs_1.ResolvedResponseHeader(this.constants.fold(file, header.nameConstant), header.description);
208
+ this.mustExist(file, header.entry, manifestPath);
209
+ // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package
210
+ try {
211
+ return new GenerationInputs_1.ResolvedResponseHeader(this.extractor.extractContextKeyHeader(file, header.contextKey, api_doc_model_1.ContextKeyHeaderSlot.RESPONSE, this.options), header.description, header.required);
212
+ }
213
+ catch (err) {
214
+ //const error = toError(err);
215
+ throw this.rethrow(err, file);
216
+ }
211
217
  });
212
218
  }
213
219
  description(manifestPath, manifest) {
@@ -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,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,EA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Model,\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"]}
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,4DAOkC;AAClC,oDAAqE;AACrE,sEAAmE;AACnE,+DAA4D;AAE5D,mEAKsC;AACtC,uEAIwC;AACxC,2DAAwD;AACxD,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;IA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AI,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,+CAAsB,CAC5B,uBAAuB,QAAQ,yBAAyB,EACxD,YAAY,EACZ,sEAAsE,IAAI,GAAG,CAChF,CAAC;QACN,CAAC;IACL,CAAC;CACJ;AAzPD,oCAyPC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport * as ts from 'typescript';\nimport {\n ApiComponentsModel,\n ApiDocExtractor,\n ContextKeyHeaderSlot,\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 { 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 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 this.mustExist(file, header.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 new ResolvedResponseHeader(\n this.extractor.extractContextKeyHeader(\n file,\n header.contextKey,\n ContextKeyHeaderSlot.RESPONSE,\n this.options,\n ),\n header.description,\n header.required,\n );\n } catch (err: unknown) {\n //const error = toError(err);\n throw this.rethrow(err, file);\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"]}
@@ -28,6 +28,8 @@ export declare class JsonReader {
28
28
  /** A required, non-empty string. */
29
29
  string(field: string): string;
30
30
  optionalString(field: string): string | undefined;
31
+ /** A boolean, or undefined when the field is absent. Anything else present is refused. */
32
+ optionalBoolean(field: string): boolean | undefined;
31
33
  /** An array of strings, empty when the field is absent. */
32
34
  strings(field: string): readonly string[];
33
35
  /** A nested object, or undefined when the field is absent. */
@@ -72,6 +72,18 @@ class JsonReader {
72
72
  const value = this.entries.get(field);
73
73
  return typeof value === 'string' && value !== '' ? value : undefined;
74
74
  }
75
+ /** A boolean, or undefined when the field is absent. Anything else present is refused. */
76
+ optionalBoolean(field) {
77
+ // webpieces-disable no-any-unknown -- the raw entry, narrowed below
78
+ const value = this.entries.get(field);
79
+ if (value === undefined) {
80
+ return undefined;
81
+ }
82
+ if (typeof value !== 'boolean') {
83
+ throw new OpenApiGenerationError_1.OpenApiGenerationError(`'${field}' is not a boolean`, this.where, `Write "${field}" as true or false, or leave it out.`);
84
+ }
85
+ return value;
86
+ }
75
87
  /** An array of strings, empty when the field is absent. */
76
88
  strings(field) {
77
89
  // webpieces-disable no-any-unknown -- the raw entry, narrowed below
@@ -1 +1 @@
1
- {"version":3,"file":"JsonReader.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/manifest/JsonReader.ts"],"names":[],"mappings":";;;AAAA,sEAAmE;AAEnE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,UAAU;IAGE;IAER;IAJb;IACI,sJAAsJ;IACrI,OAAqC;IACtD,mFAAmF;IAC1E,KAAa;QAFL,YAAO,GAAP,OAAO,CAA8B;QAE7C,UAAK,GAAL,KAAK,CAAQ;IACvB,CAAC;IAEJ,0BAA0B;IAC1B,8IAA8I;IAC9I,MAAM,CAAC,SAAS,CAAC,IAAY,EAAE,KAAa;QACxC,gIAAgI;QAChI,IAAI,CAAC;YACD,2FAA2F;YAC3F,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACzC,OAAO,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,K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AC/C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACtB,OAAO,EAAE,CAAC;QACd,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,+CAAsB,CAC5B,IAAI,KAAK,mBAAmB,EAC5B,IAAI,CAAC,KAAK,EACV,UAAU,KAAK,qCAAqC,CACvD,CAAC;QACN,CAAC;QACD,0EAA0E;QAC1E,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAa,EAAE,EAAE,CAC/B,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,gBAAgB,KAAK,GAAG,CAAC,CAC5D,CAAC;IACN,CAAC;CACJ;AA9GD,gCA8GC","sourcesContent":["import { OpenApiGenerationError } from '../OpenApiGenerationError';\n\n/**\n * A narrowing reader over ONE parsed JSON object.\n *\n * ## Why this class exists at all\n *\n * `JSON.parse` returns something with no shape, and a loader that passed that shapelessness around\n * would spread it over every method that touches the manifest. Concentrating it HERE means the rest\n * of the package deals only in `string`, `JsonReader` and the manifest classes — and it means the\n * \"this value came off disk and has not been checked yet\" state exists in exactly one file, where a\n * reader can see every check that state is subjected to.\n *\n * ## Every miss is a HARD FAILURE naming the field\n *\n * There is deliberately no defaulting of anything a reader would notice. A published document quietly\n * missing a section is indistinguishable, from the outside, from an API that genuinely has no error\n * contract — so a mistyped `errors` must stop the run rather than silently publish less.\n */\nexport class JsonReader {\n private constructor(\n // webpieces-disable no-any-unknown -- parsed JSON is genuinely shapeless until the accessors below narrow it; this is the ONE place that state exists\n private readonly entries: ReadonlyMap<string, unknown>,\n /** The file this came from, so every failure names something somebody can open. */\n readonly where: string,\n ) {}\n\n /** Parse a whole file. */\n // webpieces-disable no-function-outside-class -- static factory; the private constructor is what keeps unchecked JSON out of every other file\n static parseFile(text: string, where: string): JsonReader {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package, with its cure\n try {\n // webpieces-disable no-any-unknown -- JSON.parse's result, before anything has narrowed it\n const parsed: unknown = JSON.parse(text);\n return JsonReader.of(parsed, where, 'the manifest');\n } catch (err: unknown) {\n //const error = toError(err);\n if (err instanceof OpenApiGenerationError) {\n throw err;\n }\n throw new OpenApiGenerationError(\n `not valid JSON: ${err instanceof Error ? err.message : String(err)}`,\n where,\n 'Fix the JSON syntax. The manifest is read before anything else runs.',\n );\n }\n }\n\n /** One already-parsed value that must be an object. */\n // webpieces-disable no-any-unknown -- the value has not been narrowed yet; that is this method's job\n // webpieces-disable no-function-outside-class -- static factory of this class\n private static of(value: unknown, where: string, what: string): JsonReader {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new OpenApiGenerationError(\n `${what} is not a JSON object`,\n where,\n 'Write it as a JSON object — one `{ ... }` with named fields.',\n );\n }\n return new JsonReader(new Map(Object.entries(value)), where);\n }\n\n has(field: string): boolean {\n return this.entries.get(field) !== undefined;\n }\n\n /** A required, non-empty string. */\n string(field: string): string {\n const value = this.optionalString(field);\n if (value === undefined) {\n throw new OpenApiGenerationError(\n `'${field}' is missing or is not a non-empty string`,\n this.where,\n `Give \"${field}\" a value; an empty one publishes a document nobody can identify.`,\n );\n }\n return value;\n }\n\n optionalString(field: string): string | undefined {\n // webpieces-disable no-any-unknown -- the raw entry, narrowed on the next line\n const value: unknown = this.entries.get(field);\n return typeof value === 'string' && value !== '' ? value : undefined;\n }\n\n /** An array of strings, empty when the field is absent. */\n strings(field: string): readonly string[] {\n // webpieces-disable no-any-unknown -- the raw entry, narrowed below\n const value: unknown = this.entries.get(field);\n if (value === undefined) {\n return [];\n }\n // webpieces-disable no-any-unknown -- element of a not-yet-narrowed array\n if (!Array.isArray(value) || value.some((each: unknown) => typeof each !== 'string')) {\n throw new OpenApiGenerationError(\n `'${field}' is not an array of strings`,\n this.where,\n `Write \"${field}\" as a JSON array of strings, or leave it out.`,\n );\n }\n return value as readonly string[];\n }\n\n /** A nested object, or undefined when the field is absent. */\n object(field: string): JsonReader | undefined {\n // webpieces-disable no-any-unknown -- the raw entry, narrowed by `of`\n const value: unknown = this.entries.get(field);\n return value === undefined ? undefined : JsonReader.of(value, this.where, `'${field}'`);\n }\n\n /** An array of objects, empty when the field is absent. */\n objects(field: string): readonly JsonReader[] {\n // webpieces-disable no-any-unknown -- the raw entry, narrowed below\n const value: unknown = this.entries.get(field);\n if (value === undefined) {\n return [];\n }\n if (!Array.isArray(value)) {\n throw new OpenApiGenerationError(\n `'${field}' is not an array`,\n this.where,\n `Write \"${field}\" as a JSON array, or leave it out.`,\n );\n }\n // webpieces-disable no-any-unknown -- element of a not-yet-narrowed array\n return value.map((each: unknown) =>\n JsonReader.of(each, this.where, `an entry of '${field}'`),\n );\n }\n}\n"]}
1
+ {"version":3,"file":"JsonReader.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/manifest/JsonReader.ts"],"names":[],"mappings":";;;AAAA,sEAAmE;AAEnE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,UAAU;IAGE;IAER;IAJb;IACI,sJAAsJ;IACrI,OAAqC;IACtD,mFAAmF;IAC1E,KAAa;QAFL,YAAO,GAAP,OAAO,CAA8B;QAE7C,UAAK,GAAL,KAAK,CAAQ;IACvB,CAAC;IAEJ,0BAA0B;IAC1B,8IAA8I;IAC9I,MAAM,CAAC,SAAS,CAAC,IAAY,EAAE,KAAa;QACxC,gIAAgI;QAChI,IAAI,CAAC;YACD,2FAA2F;YAC3F,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACzC,OAAO,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC;QACxD,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,6BAA6B;YAC7B,IAAI,GAAG,YAAY,+CAAsB,EAAE,CAAC;gBACxC,MAAM,GAAG,CAAC;YACd,CAAC;YACD,MAAM,IAAI,+CAAsB,CAC5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EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,KAAK,GAAG,CAAC,CAAC;IAC5F,CAAC;IAED,2DAA2D;IAC3D,OAAO,CAAC,KAAa;QACjB,oEAAoE;QACpE,MAAM,KAAK,GAAY,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC/C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACtB,OAAO,EAAE,CAAC;QACd,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,+CAAsB,CAC5B,IAAI,KAAK,mBAAmB,EAC5B,IAAI,CAAC,KAAK,EACV,UAAU,KAAK,qCAAqC,CACvD,CAAC;QACN,CAAC;QACD,0EAA0E;QAC1E,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAa,EAAE,EAAE,CAC/B,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,gBAAgB,KAAK,GAAG,CAAC,CAC5D,CAAC;IACN,CAAC;CACJ;AA/HD,gCA+HC","sourcesContent":["import { OpenApiGenerationError } from '../OpenApiGenerationError';\n\n/**\n * A narrowing reader over ONE parsed JSON object.\n *\n * ## Why this class exists at all\n *\n * `JSON.parse` returns something with no shape, and a loader that passed that shapelessness around\n * would spread it over every method that touches the manifest. Concentrating it HERE means the rest\n * of the package deals only in `string`, `JsonReader` and the manifest classes — and it means the\n * \"this value came off disk and has not been checked yet\" state exists in exactly one file, where a\n * reader can see every check that state is subjected to.\n *\n * ## Every miss is a HARD FAILURE naming the field\n *\n * There is deliberately no defaulting of anything a reader would notice. A published document quietly\n * missing a section is indistinguishable, from the outside, from an API that genuinely has no error\n * contract — so a mistyped `errors` must stop the run rather than silently publish less.\n */\nexport class JsonReader {\n private constructor(\n // webpieces-disable no-any-unknown -- parsed JSON is genuinely shapeless until the accessors below narrow it; this is the ONE place that state exists\n private readonly entries: ReadonlyMap<string, unknown>,\n /** The file this came from, so every failure names something somebody can open. */\n readonly where: string,\n ) {}\n\n /** Parse a whole file. */\n // webpieces-disable no-function-outside-class -- static factory; the private constructor is what keeps unchecked JSON out of every other file\n static parseFile(text: string, where: string): JsonReader {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package, with its cure\n try {\n // webpieces-disable no-any-unknown -- JSON.parse's result, before anything has narrowed it\n const parsed: unknown = JSON.parse(text);\n return JsonReader.of(parsed, where, 'the manifest');\n } catch (err: unknown) {\n //const error = toError(err);\n if (err instanceof OpenApiGenerationError) {\n throw err;\n }\n throw new OpenApiGenerationError(\n `not valid JSON: ${err instanceof Error ? err.message : String(err)}`,\n where,\n 'Fix the JSON syntax. The manifest is read before anything else runs.',\n );\n }\n }\n\n /** One already-parsed value that must be an object. */\n // webpieces-disable no-any-unknown -- the value has not been narrowed yet; that is this method's job\n // webpieces-disable no-function-outside-class -- static factory of this class\n private static of(value: unknown, where: string, what: string): JsonReader {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new OpenApiGenerationError(\n `${what} is not a JSON object`,\n where,\n 'Write it as a JSON object — one `{ ... }` with named fields.',\n );\n }\n return new JsonReader(new Map(Object.entries(value)), where);\n }\n\n has(field: string): boolean {\n return this.entries.get(field) !== undefined;\n }\n\n /** A required, non-empty string. */\n string(field: string): string {\n const value = this.optionalString(field);\n if (value === undefined) {\n throw new OpenApiGenerationError(\n `'${field}' is missing or is not a non-empty string`,\n this.where,\n `Give \"${field}\" a value; an empty one publishes a document nobody can identify.`,\n );\n }\n return value;\n }\n\n optionalString(field: string): string | undefined {\n // webpieces-disable no-any-unknown -- the raw entry, narrowed on the next line\n const value: unknown = this.entries.get(field);\n return typeof value === 'string' && value !== '' ? value : undefined;\n }\n\n /** A boolean, or undefined when the field is absent. Anything else present is refused. */\n optionalBoolean(field: string): boolean | undefined {\n // webpieces-disable no-any-unknown -- the raw entry, narrowed below\n const value: unknown = this.entries.get(field);\n if (value === undefined) {\n return undefined;\n }\n if (typeof value !== 'boolean') {\n throw new OpenApiGenerationError(\n `'${field}' is not a boolean`,\n this.where,\n `Write \"${field}\" as true or false, or leave it out.`,\n );\n }\n return value;\n }\n\n /** An array of strings, empty when the field is absent. */\n strings(field: string): readonly string[] {\n // webpieces-disable no-any-unknown -- the raw entry, narrowed below\n const value: unknown = this.entries.get(field);\n if (value === undefined) {\n return [];\n }\n // webpieces-disable no-any-unknown -- element of a not-yet-narrowed array\n if (!Array.isArray(value) || value.some((each: unknown) => typeof each !== 'string')) {\n throw new OpenApiGenerationError(\n `'${field}' is not an array of strings`,\n this.where,\n `Write \"${field}\" as a JSON array of strings, or leave it out.`,\n );\n }\n return value as readonly string[];\n }\n\n /** A nested object, or undefined when the field is absent. */\n object(field: string): JsonReader | undefined {\n // webpieces-disable no-any-unknown -- the raw entry, narrowed by `of`\n const value: unknown = this.entries.get(field);\n return value === undefined ? undefined : JsonReader.of(value, this.where, `'${field}'`);\n }\n\n /** An array of objects, empty when the field is absent. */\n objects(field: string): readonly JsonReader[] {\n // webpieces-disable no-any-unknown -- the raw entry, narrowed below\n const value: unknown = this.entries.get(field);\n if (value === undefined) {\n return [];\n }\n if (!Array.isArray(value)) {\n throw new OpenApiGenerationError(\n `'${field}' is not an array`,\n this.where,\n `Write \"${field}\" as a JSON array, or leave it out.`,\n );\n }\n // webpieces-disable no-any-unknown -- element of a not-yet-narrowed array\n return value.map((each: unknown) =>\n JsonReader.of(each, this.where, `an entry of '${field}'`),\n );\n }\n}\n"]}
@@ -15,6 +15,8 @@ const WEBHOOK = 'webhook';
15
15
  * manifest with no `kind` is a contract library's, exactly as before.
16
16
  */
17
17
  const COMPONENTS = 'components';
18
+ /** The deleted string-constant spelling of a response header's name (#1249). */
19
+ const RETIRED_NAME_CONSTANT = 'nameConstant';
18
20
  /** Keys a components manifest must not carry, each with why — a contract-manifest key is a mix-up. */
19
21
  const NOT_IN_COMPONENTS = new Map([
20
22
  ['apis', 'a components document has no paths; list the library\'s entry files in "entries"'],
@@ -120,12 +122,20 @@ class ManifestLoader {
120
122
  }
121
123
  return new OpenApiManifest_1.ErrorsEntry(errors.string('entry'), errors.string('type'), errors
122
124
  .objects('responses')
123
- .map((response) => new OpenApiManifest_1.ErrorResponseEntry(response.string('status'), response.string('description'))));
125
+ .map((response) => new OpenApiManifest_1.ErrorResponseEntry(response.string('status'), response.string('description'), response.optionalBoolean('requiresAuth') ?? false)));
124
126
  }
125
127
  responseHeaders(raw) {
126
- return raw
127
- .objects('responseHeaders')
128
- .map((header) => new OpenApiManifest_1.ResponseHeaderEntry(header.string('entry'), header.string('nameConstant'), header.optionalString('description')));
128
+ return raw.objects('responseHeaders').map((header) => {
129
+ // RETIRED (#1249): a header NAME is never a string constant any more — it is read off the
130
+ // ContextKey that is the one definition of the header. Refused, never accepted beside the
131
+ // new key: two spellings means the old one is never migrated.
132
+ if (header.has(RETIRED_NAME_CONSTANT)) {
133
+ throw new OpenApiGenerationError_1.OpenApiGenerationError(`'${RETIRED_NAME_CONSTANT}' was removed from responseHeaders[]; it moved to 'contextKey'`, raw.where, `Replace "${RETIRED_NAME_CONSTANT}" with "contextKey" naming an exported ContextKey in ` +
134
+ '"entry" (e.g. `export const REQUEST_ID_KEY = WebpiecesCoreHeaders.REQUEST_ID;`, ' +
135
+ 'or a dotted path like "OneTabletKey.TX_ID"); the header name is read off its responseHeader.');
136
+ }
137
+ return new OpenApiManifest_1.ResponseHeaderEntry(header.string('entry'), header.string('contextKey'), header.optionalString('description'), header.optionalBoolean('required'));
138
+ });
129
139
  }
130
140
  /** A manifest-relative path, resolved against the manifest's own directory. */
131
141
  resolve(manifestPath, relative) {
@@ -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,4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AM,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"]}
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,gFAAgF;AAChF,MAAM,qBAAqB,GAAG,cAAc,CAAC;AAE7C,sGAAsG;AACtG,MAAM,iBAAiB,GAAgC,IAAI,GAAG,CAAiB;IAC3E,CAAC,MAAM,EAAE,kF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9B,QAAQ,CAAC,eAAe,CAAC,cAAc,CAAC,IAAI,KAAK,CACpD,CACR,CACR,CAAC;IACN,CAAC;IAEO,eAAe,CAAC,GAAe;QACnC,OAAO,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,MAAkB,EAAE,EAAE;YAC7D,0FAA0F;YAC1F,0FAA0F;YAC1F,8DAA8D;YAC9D,IAAI,MAAM,CAAC,GAAG,CAAC,qBAAqB,CAAC,EAAE,CAAC;gBACpC,MAAM,IAAI,+CAAsB,CAC5B,IAAI,qBAAqB,gEAAgE,EACzF,GAAG,CAAC,KAAK,EACT,YAAY,qBAAqB,uDAAuD;oBACpF,kFAAkF;oBAClF,8FAA8F,CACrG,CAAC;YACN,CAAC;YACD,OAAO,IAAI,qCAAmB,CAC1B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EACtB,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAC3B,MAAM,CAAC,cAAc,CAAC,aAAa,CAAC,EACpC,MAAM,CAAC,eAAe,CAAC,UAAU,CAAC,CACrC,CAAC;QACN,CAAC,CAAC,CAAC;IACP,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;AA7LD,wCA6LC","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/** The deleted string-constant spelling of a response header's name (#1249). */\nconst RETIRED_NAME_CONSTANT = 'nameConstant';\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 response.optionalBoolean('requiresAuth') ?? false,\n ),\n ),\n );\n }\n\n private responseHeaders(raw: JsonReader): readonly ResponseHeaderEntry[] {\n return raw.objects('responseHeaders').map((header: JsonReader) => {\n // RETIRED (#1249): a header NAME is never a string constant any more — it is read off the\n // ContextKey that is the one definition of the header. Refused, never accepted beside the\n // new key: two spellings means the old one is never migrated.\n if (header.has(RETIRED_NAME_CONSTANT)) {\n throw new OpenApiGenerationError(\n `'${RETIRED_NAME_CONSTANT}' was removed from responseHeaders[]; it moved to 'contextKey'`,\n raw.where,\n `Replace \"${RETIRED_NAME_CONSTANT}\" with \"contextKey\" naming an exported ContextKey in ` +\n '\"entry\" (e.g. `export const REQUEST_ID_KEY = WebpiecesCoreHeaders.REQUEST_ID;`, ' +\n 'or a dotted path like \"OneTabletKey.TX_ID\"); the header name is read off its responseHeader.',\n );\n }\n return new ResponseHeaderEntry(\n header.string('entry'),\n header.string('contextKey'),\n header.optionalString('description'),\n header.optionalBoolean('required'),\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"]}
@@ -16,7 +16,7 @@
16
16
  * server never reads, and nothing could contradict it.
17
17
  * - `errors` — the document-wide failure contract, with the BODY read from a real TS type so the
18
18
  * published shape cannot drift from the one on the wire.
19
- * - `responseHeaders[]` — declared by `nameConstant` naming an exported const, never by a literal.
19
+ * - `responseHeaders[]` — declared by `contextKey` naming an exported ContextKey, never by a literal.
20
20
  *
21
21
  * Anything a renderer could read off the source instead belongs in the source.
22
22
  *
@@ -66,7 +66,21 @@ export declare class ApiEntry {
66
66
  export declare class ErrorResponseEntry {
67
67
  readonly status: string;
68
68
  readonly description: string;
69
- constructor(status: string, description: string);
69
+ /**
70
+ * `true`: this failure can only happen to an AUTHENTICATED operation (a 401 for a bad
71
+ * credential), so it is left OFF every operation whose resolved auth is public
72
+ * (`@WpAuthPublic`) — a public endpoint cannot fail authentication. Omitted means `false`:
73
+ * the response is listed on every operation.
74
+ */
75
+ readonly requiresAuth: boolean;
76
+ constructor(status: string, description: string,
77
+ /**
78
+ * `true`: this failure can only happen to an AUTHENTICATED operation (a 401 for a bad
79
+ * credential), so it is left OFF every operation whose resolved auth is public
80
+ * (`@WpAuthPublic`) — a public endpoint cannot fail authentication. Omitted means `false`:
81
+ * the response is listed on every operation.
82
+ */
83
+ requiresAuth: boolean);
70
84
  }
71
85
  /**
72
86
  * The document-wide failure contract.
@@ -90,16 +104,29 @@ export declare class ErrorsEntry {
90
104
  /**
91
105
  * One response header every operation carries.
92
106
  *
93
- * `nameConstant` names an exported `const` in `entry`, and the generator FOLDS it. A literal here
94
- * would be a copy of the header name that a rename leaves silently stale — and JSON cannot import,
95
- * so naming the constant is the only way for this file to point at the one the server actually
96
- * writes. Failing to fold it is a HARD FAILURE for the same reason.
107
+ * `contextKey` names an exported `ContextKey` in `entry` — the export's name, or a dotted path into
108
+ * one (`OneTabletKey.TX_ID`) — and the generator reads the header name off that key's own
109
+ * `ContextKey.trusted(...)` / `ContextKey.untrusted(...)` definition: its `responseHeader`, which is
110
+ * what the server's response choke point actually writes (#1249). A literal here would be a copy of
111
+ * the header name that a rename leaves silently stale — and JSON cannot import, so naming the key is
112
+ * the only way for this file to point at the one definition. Failing to resolve it is a HARD
113
+ * FAILURE for the same reason.
97
114
  */
98
115
  export declare class ResponseHeaderEntry {
99
116
  readonly entry: string;
100
- readonly nameConstant: string;
117
+ readonly contextKey: string;
101
118
  readonly description: string | undefined;
102
- constructor(entry: string, nameConstant: string, description: string | undefined);
119
+ /**
120
+ * Rendered verbatim as the OpenAPI header object's `required`. Omitted means the document
121
+ * does not state it, which OpenAPI reads as `false`.
122
+ */
123
+ readonly required: boolean | undefined;
124
+ constructor(entry: string, contextKey: string, description: string | undefined,
125
+ /**
126
+ * Rendered verbatim as the OpenAPI header object's `required`. Omitted means the document
127
+ * does not state it, which OpenAPI reads as `false`.
128
+ */
129
+ required: boolean | undefined);
103
130
  }
104
131
  export declare class OpenApiManifest {
105
132
  readonly title: string;
@@ -42,9 +42,18 @@ exports.ApiEntry = ApiEntry;
42
42
  class ErrorResponseEntry {
43
43
  status;
44
44
  description;
45
- constructor(status, description) {
45
+ requiresAuth;
46
+ constructor(status, description,
47
+ /**
48
+ * `true`: this failure can only happen to an AUTHENTICATED operation (a 401 for a bad
49
+ * credential), so it is left OFF every operation whose resolved auth is public
50
+ * (`@WpAuthPublic`) — a public endpoint cannot fail authentication. Omitted means `false`:
51
+ * the response is listed on every operation.
52
+ */
53
+ requiresAuth) {
46
54
  this.status = status;
47
55
  this.description = description;
56
+ this.requiresAuth = requiresAuth;
48
57
  }
49
58
  }
50
59
  exports.ErrorResponseEntry = ErrorResponseEntry;
@@ -73,19 +82,29 @@ exports.ErrorsEntry = ErrorsEntry;
73
82
  /**
74
83
  * One response header every operation carries.
75
84
  *
76
- * `nameConstant` names an exported `const` in `entry`, and the generator FOLDS it. A literal here
77
- * would be a copy of the header name that a rename leaves silently stale — and JSON cannot import,
78
- * so naming the constant is the only way for this file to point at the one the server actually
79
- * writes. Failing to fold it is a HARD FAILURE for the same reason.
85
+ * `contextKey` names an exported `ContextKey` in `entry` — the export's name, or a dotted path into
86
+ * one (`OneTabletKey.TX_ID`) — and the generator reads the header name off that key's own
87
+ * `ContextKey.trusted(...)` / `ContextKey.untrusted(...)` definition: its `responseHeader`, which is
88
+ * what the server's response choke point actually writes (#1249). A literal here would be a copy of
89
+ * the header name that a rename leaves silently stale — and JSON cannot import, so naming the key is
90
+ * the only way for this file to point at the one definition. Failing to resolve it is a HARD
91
+ * FAILURE for the same reason.
80
92
  */
81
93
  class ResponseHeaderEntry {
82
94
  entry;
83
- nameConstant;
95
+ contextKey;
84
96
  description;
85
- constructor(entry, nameConstant, description) {
97
+ required;
98
+ constructor(entry, contextKey, description,
99
+ /**
100
+ * Rendered verbatim as the OpenAPI header object's `required`. Omitted means the document
101
+ * does not state it, which OpenAPI reads as `false`.
102
+ */
103
+ required) {
86
104
  this.entry = entry;
87
- this.nameConstant = nameConstant;
105
+ this.contextKey = contextKey;
88
106
  this.description = description;
107
+ this.required = required;
89
108
  }
90
109
  }
91
110
  exports.ResponseHeaderEntry = ResponseHeaderEntry;