@webpieces/openapi-generator 0.4.829 → 0.4.831

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.
Files changed (38) hide show
  1. package/README.md +50 -2
  2. package/package.json +3 -3
  3. package/src/cli/OpenApiCli.d.ts +5 -0
  4. package/src/cli/OpenApiCli.js +27 -1
  5. package/src/cli/OpenApiCli.js.map +1 -1
  6. package/src/generate/DocumentSelection.d.ts +8 -0
  7. package/src/generate/DocumentSelection.js +14 -4
  8. package/src/generate/DocumentSelection.js.map +1 -1
  9. package/src/generate/GenerationInputs.d.ts +34 -3
  10. package/src/generate/GenerationInputs.js +33 -2
  11. package/src/generate/GenerationInputs.js.map +1 -1
  12. package/src/generate/OpenApiGenerator.d.ts +43 -4
  13. package/src/generate/OpenApiGenerator.js +142 -10
  14. package/src/generate/OpenApiGenerator.js.map +1 -1
  15. package/src/generate/SchemaPlacement.d.ts +82 -0
  16. package/src/generate/SchemaPlacement.js +126 -0
  17. package/src/generate/SchemaPlacement.js.map +1 -0
  18. package/src/generate/SchemaRenderer.d.ts +27 -2
  19. package/src/generate/SchemaRenderer.js +57 -11
  20. package/src/generate/SchemaRenderer.js.map +1 -1
  21. package/src/generate/UpstreamComponents.d.ts +43 -0
  22. package/src/generate/UpstreamComponents.js +68 -0
  23. package/src/generate/UpstreamComponents.js.map +1 -0
  24. package/src/index.d.ts +6 -2
  25. package/src/index.js +16 -1
  26. package/src/index.js.map +1 -1
  27. package/src/load/ComponentsLocator.d.ts +46 -0
  28. package/src/load/ComponentsLocator.js +138 -0
  29. package/src/load/ComponentsLocator.js.map +1 -0
  30. package/src/load/InputsLoader.d.ts +14 -1
  31. package/src/load/InputsLoader.js +79 -1
  32. package/src/load/InputsLoader.js.map +1 -1
  33. package/src/manifest/ManifestLoader.d.ts +10 -2
  34. package/src/manifest/ManifestLoader.js +53 -3
  35. package/src/manifest/ManifestLoader.js.map +1 -1
  36. package/src/manifest/OpenApiManifest.d.ts +17 -0
  37. package/src/manifest/OpenApiManifest.js +21 -1
  38. package/src/manifest/OpenApiManifest.js.map +1 -1
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ComponentsLocator = exports.LocatedComponents = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("node:fs"));
6
+ const path = tslib_1.__importStar(require("node:path"));
7
+ const core_util_1 = require("@webpieces/core-util");
8
+ const OpenApiGenerationError_1 = require("../OpenApiGenerationError");
9
+ const SchemaPlacement_1 = require("../generate/SchemaPlacement");
10
+ const UpstreamComponents_1 = require("../generate/UpstreamComponents");
11
+ /** The outcome of locating ONE package's components document: exactly one side is set. Data-only. */
12
+ class LocatedComponents {
13
+ published;
14
+ missing;
15
+ constructor(published, missing) {
16
+ this.published = published;
17
+ this.missing = missing;
18
+ }
19
+ }
20
+ exports.LocatedComponents = LocatedComponents;
21
+ /**
22
+ * Find the `components.openapi.json` a package publishes (#1058) — by the SAME package lookup
23
+ * `McpToolCatalog.fromPackages` (`@webpieces/mcp-server`) uses to find a library's MCP catalogs:
24
+ *
25
+ * 1. resolve `<pkg>/package.json` the way node does, walking `node_modules` up from the manifest's
26
+ * directory (symlinks followed) — falling back to the directory the COMPILER read the type from
27
+ * (the nearest `package.json` above its declaration), for a workspace that maps packages with
28
+ * tsconfig `paths` and links none;
29
+ * 2. that directory holds `components.openapi.json` → a BUILT or PUBLISHED package → read it there;
30
+ * 3. it holds a `project.json` → a workspace SOURCE directory → read it from the `outputPath` of the
31
+ * target its `openapi-components-generate` dependsOn ({@link GeneratedApiDocsLayout}), resolved
32
+ * against the nx workspace root found by walking up to `nx.json`.
33
+ *
34
+ * Never an assumed `dist/`. Anything else is a {@link MissingComponents} carrying where it looked and
35
+ * what it found — which the generator turns into the fail-closed refusal, so a missing document is
36
+ * never a reason to copy a schema in.
37
+ */
38
+ class ComponentsLocator {
39
+ /**
40
+ * @param packageName the package whose document is wanted.
41
+ * @param resolveFrom where node resolution starts — the manifest's directory.
42
+ * @param declaredIn the directory of the `package.json` the compiler read the type from, if any.
43
+ */
44
+ locate(packageName, resolveFrom, declaredIn) {
45
+ const packageDir = this.resolve(packageName, resolveFrom) ?? declaredIn;
46
+ if (packageDir === undefined) {
47
+ return this.missing(packageName, `it is not installed where ${resolveFrom} can see it, and no package.json above its declaration names it`);
48
+ }
49
+ const beside = path.join(packageDir, core_util_1.GeneratedApiDocsLayout.COMPONENTS_FILE);
50
+ if (fs.existsSync(beside)) {
51
+ return this.read(packageName, beside);
52
+ }
53
+ if (fs.existsSync(path.join(packageDir, 'project.json'))) {
54
+ return this.fromSource(packageName, packageDir);
55
+ }
56
+ return this.missing(packageName, `${packageDir} holds neither a ${core_util_1.GeneratedApiDocsLayout.COMPONENTS_FILE} (a built package) nor ` +
57
+ 'a project.json (a workspace source directory)');
58
+ }
59
+ /** `<dir>/node_modules/<pkg>/package.json` in `resolveFrom` and every parent — node's own walk. */
60
+ resolve(packageName, resolveFrom) {
61
+ let dir = path.resolve(resolveFrom);
62
+ for (;;) {
63
+ const candidate = path.join(dir, 'node_modules', ...packageName.split('/'));
64
+ if (fs.existsSync(path.join(candidate, 'package.json'))) {
65
+ return fs.realpathSync(candidate);
66
+ }
67
+ const parent = path.dirname(dir);
68
+ if (parent === dir) {
69
+ return undefined;
70
+ }
71
+ dir = parent;
72
+ }
73
+ }
74
+ /** A workspace SOURCE directory: the outputPath of the target its components target dependsOn. */
75
+ fromSource(packageName, packageDir) {
76
+ const workspaceRoot = this.workspaceRootAbove(packageDir);
77
+ if (workspaceRoot === undefined) {
78
+ return this.missing(packageName, `${packageDir} has a project.json but no nx.json above it, so there is no build outputPath to read it from`);
79
+ }
80
+ const project = this.readJson(path.join(packageDir, 'project.json'));
81
+ const projectRoot = path.relative(workspaceRoot, packageDir).split(path.sep).join('/');
82
+ const lookup = new core_util_1.GeneratedApiDocsLayout(projectRoot, project.name ?? projectRoot, project.targets ?? {}).outputTarget(core_util_1.GeneratedApiDocsLayout.COMPONENTS_TARGET);
83
+ if (lookup.found === undefined) {
84
+ return this.missing(packageName, lookup.problem.problem);
85
+ }
86
+ const file = path.resolve(workspaceRoot, lookup.found.outputPath, core_util_1.GeneratedApiDocsLayout.COMPONENTS_FILE);
87
+ if (!fs.existsSync(file)) {
88
+ return this.missing(packageName, `${file} does not exist — run \`nx run ${project.name ?? projectRoot}:` +
89
+ `${core_util_1.GeneratedApiDocsLayout.COMPONENTS_TARGET}\` (dependents reach it through ` +
90
+ `"^${core_util_1.GeneratedApiDocsLayout.COMPONENTS_TARGET}")`);
91
+ }
92
+ return this.read(packageName, file);
93
+ }
94
+ workspaceRootAbove(packageDir) {
95
+ let dir = packageDir;
96
+ for (;;) {
97
+ if (fs.existsSync(path.join(dir, 'nx.json'))) {
98
+ return dir;
99
+ }
100
+ const parent = path.dirname(dir);
101
+ if (parent === dir) {
102
+ return undefined;
103
+ }
104
+ dir = parent;
105
+ }
106
+ }
107
+ /**
108
+ * Read one document. Its `x-webpieces-id` must be the package-qualified URI it is referenced by:
109
+ * a document published under another package's name is a copy, and referencing it would point
110
+ * every `$ref` at the wrong owner.
111
+ */
112
+ read(packageName, file) {
113
+ const document = this.readJson(file);
114
+ const expected = SchemaPlacement_1.ComponentsReference.documentUri(packageName);
115
+ if (document['x-webpieces-id'] !== expected) {
116
+ throw new OpenApiGenerationError_1.OpenApiGenerationError(`${file} is not ${packageName}'s components document: its x-webpieces-id is ` +
117
+ `${JSON.stringify(document['x-webpieces-id'])}, not "${expected}"`, file, `Regenerate ${packageName}'s components document; never copy one package's document into another.`);
118
+ }
119
+ const schemas = Object.keys(document.components?.schemas ?? {});
120
+ return new LocatedComponents(new UpstreamComponents_1.PublishedComponents(packageName, file, new Set(schemas)), undefined);
121
+ }
122
+ /** A JSON file this lookup reads, or the ONE error type of this package naming it. */
123
+ readJson(file) {
124
+ // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package, naming the file
125
+ try {
126
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
127
+ }
128
+ catch (err) {
129
+ //const error = toError(err);
130
+ throw new OpenApiGenerationError_1.OpenApiGenerationError(`${file} is not valid JSON: ${err instanceof Error ? err.message : String(err)}`, file, 'Fix or regenerate that file; a components lookup reads it as JSON.');
131
+ }
132
+ }
133
+ missing(packageName, reason) {
134
+ return new LocatedComponents(undefined, new UpstreamComponents_1.MissingComponents(packageName, reason));
135
+ }
136
+ }
137
+ exports.ComponentsLocator = ComponentsLocator;
138
+ //# sourceMappingURL=ComponentsLocator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ComponentsLocator.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/load/ComponentsLocator.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAClC,oDAA6E;AAC7E,sEAAmE;AACnE,iEAAkE;AAClE,uEAAwF;AAaxF,qGAAqG;AACrG,MAAa,iBAAiB;IAEb;IACA;IAFb,YACa,SAA0C,EAC1C,OAAsC;QADtC,cAAS,GAAT,SAAS,CAAiC;QAC1C,YAAO,GAAP,OAAO,CAA+B;IAChD,CAAC;CACP;AALD,8CAKC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,iBAAiB;IAC1B;;;;OAIG;IACH,MAAM,CACF,WAAmB,EACnB,WAAmB,EACnB,UAA8B;QAE9B,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,UAAU,CAAC;QACxE,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC,OAAO,CACf,WAAW,EACX,6BAA6B,WAAW,iEAAiE,CAC5G,CAAC;QACN,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,kCAAsB,CAAC,eAAe,CAAC,CAAC;QAC7E,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,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;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,6BAA6B;YAC7B,MAAM,IAAI,+CAAsB,CAC5B,GAAG,IAAI,uBAAuB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAChF,IAAI,EACJ,oEAAoE,CACvE,CAAC;QACN,CAAC;IACL,CAAC;IAEO,OAAO,CAAC,WAAmB,EAAE,MAAc;QAC/C,OAAO,IAAI,iBAAiB,CAAC,SAAS,EAAE,IAAI,sCAAiB,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IACxF,CAAC;CACJ;AA1ID,8CA0IC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { GeneratedApiDocsLayout, LayoutTargets } from '@webpieces/core-util';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\nimport { ComponentsReference } from '../generate/SchemaPlacement';\nimport { MissingComponents, PublishedComponents } from '../generate/UpstreamComponents';\n\n/** The two fields of an nx `project.json` this lookup reads. */\ntype ProjectJson = { readonly name?: string; readonly targets?: LayoutTargets };\n\n/** The fields of a components document this lookup reads. */\ntype ComponentsDocumentJson = {\n // webpieces-disable no-any-unknown -- a file off disk: compared by value, never trusted as a string\n readonly 'x-webpieces-id'?: unknown;\n // webpieces-disable no-any-unknown -- only the schema NAMES are read; the schemas stay opaque\n readonly components?: { readonly schemas?: Record<string, unknown> };\n};\n\n/** The outcome of locating ONE package's components document: exactly one side is set. Data-only. */\nexport class LocatedComponents {\n constructor(\n readonly published: PublishedComponents | undefined,\n readonly missing: MissingComponents | undefined,\n ) {}\n}\n\n/**\n * Find the `components.openapi.json` a package publishes (#1058) — by the SAME package lookup\n * `McpToolCatalog.fromPackages` (`@webpieces/mcp-server`) uses to find a library's MCP catalogs:\n *\n * 1. resolve `<pkg>/package.json` the way node does, walking `node_modules` up from the manifest's\n * directory (symlinks followed) — falling back to the directory the COMPILER read the type from\n * (the nearest `package.json` above its declaration), for a workspace that maps packages with\n * tsconfig `paths` and links none;\n * 2. that directory holds `components.openapi.json` → a BUILT or PUBLISHED package → read it there;\n * 3. it holds a `project.json` → a workspace SOURCE directory → read it from the `outputPath` of the\n * target its `openapi-components-generate` dependsOn ({@link GeneratedApiDocsLayout}), resolved\n * against the nx workspace root found by walking up to `nx.json`.\n *\n * Never an assumed `dist/`. Anything else is a {@link MissingComponents} carrying where it looked and\n * what it found — which the generator turns into the fail-closed refusal, so a missing document is\n * never a reason to copy a schema in.\n */\nexport class ComponentsLocator {\n /**\n * @param packageName the package whose document is wanted.\n * @param resolveFrom where node resolution starts — the manifest's directory.\n * @param declaredIn the directory of the `package.json` the compiler read the type from, if any.\n */\n locate(\n packageName: string,\n resolveFrom: string,\n declaredIn: string | undefined,\n ): LocatedComponents {\n const packageDir = this.resolve(packageName, resolveFrom) ?? declaredIn;\n if (packageDir === undefined) {\n return this.missing(\n packageName,\n `it is not installed where ${resolveFrom} can see it, and no package.json above its declaration names it`,\n );\n }\n const beside = path.join(packageDir, GeneratedApiDocsLayout.COMPONENTS_FILE);\n if (fs.existsSync(beside)) {\n return this.read(packageName, beside);\n }\n if (fs.existsSync(path.join(packageDir, 'project.json'))) {\n return this.fromSource(packageName, packageDir);\n }\n return this.missing(\n packageName,\n `${packageDir} holds neither a ${GeneratedApiDocsLayout.COMPONENTS_FILE} (a built package) nor ` +\n 'a project.json (a workspace source directory)',\n );\n }\n\n /** `<dir>/node_modules/<pkg>/package.json` in `resolveFrom` and every parent — node's own walk. */\n private resolve(packageName: string, resolveFrom: string): string | undefined {\n let dir = path.resolve(resolveFrom);\n for (;;) {\n const candidate = path.join(dir, 'node_modules', ...packageName.split('/'));\n if (fs.existsSync(path.join(candidate, 'package.json'))) {\n return fs.realpathSync(candidate);\n }\n const parent = path.dirname(dir);\n if (parent === dir) {\n return undefined;\n }\n dir = parent;\n }\n }\n\n /** A workspace SOURCE directory: the outputPath of the target its components target dependsOn. */\n private fromSource(packageName: string, packageDir: string): LocatedComponents {\n const workspaceRoot = this.workspaceRootAbove(packageDir);\n if (workspaceRoot === undefined) {\n return this.missing(\n packageName,\n `${packageDir} has a project.json but no nx.json above it, so there is no build outputPath to read it from`,\n );\n }\n const project = this.readJson(path.join(packageDir, 'project.json')) as ProjectJson;\n const projectRoot = path.relative(workspaceRoot, packageDir).split(path.sep).join('/');\n const lookup = new GeneratedApiDocsLayout(\n projectRoot,\n project.name ?? projectRoot,\n project.targets ?? {},\n ).outputTarget(GeneratedApiDocsLayout.COMPONENTS_TARGET);\n if (lookup.found === undefined) {\n return this.missing(packageName, lookup.problem!.problem);\n }\n const file = path.resolve(\n workspaceRoot,\n lookup.found.outputPath,\n GeneratedApiDocsLayout.COMPONENTS_FILE,\n );\n if (!fs.existsSync(file)) {\n return this.missing(\n packageName,\n `${file} does not exist — run \\`nx run ${project.name ?? projectRoot}:` +\n `${GeneratedApiDocsLayout.COMPONENTS_TARGET}\\` (dependents reach it through ` +\n `\"^${GeneratedApiDocsLayout.COMPONENTS_TARGET}\")`,\n );\n }\n return this.read(packageName, file);\n }\n\n private workspaceRootAbove(packageDir: string): string | undefined {\n let dir = packageDir;\n for (;;) {\n if (fs.existsSync(path.join(dir, 'nx.json'))) {\n return dir;\n }\n const parent = path.dirname(dir);\n if (parent === dir) {\n return undefined;\n }\n dir = parent;\n }\n }\n\n /**\n * Read one document. Its `x-webpieces-id` must be the package-qualified URI it is referenced by:\n * a document published under another package's name is a copy, and referencing it would point\n * every `$ref` at the wrong owner.\n */\n private read(packageName: string, file: string): LocatedComponents {\n const document = this.readJson(file) as ComponentsDocumentJson;\n const expected = ComponentsReference.documentUri(packageName);\n if (document['x-webpieces-id'] !== expected) {\n throw new OpenApiGenerationError(\n `${file} is not ${packageName}'s components document: its x-webpieces-id is ` +\n `${JSON.stringify(document['x-webpieces-id'])}, not \"${expected}\"`,\n file,\n `Regenerate ${packageName}'s components document; never copy one package's document into another.`,\n );\n }\n const schemas = Object.keys(document.components?.schemas ?? {});\n return new LocatedComponents(\n new PublishedComponents(packageName, file, new Set<string>(schemas)),\n undefined,\n );\n }\n\n /** A JSON file this lookup reads, or the ONE error type of this package naming it. */\n private readJson(file: string): object {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package, naming the file\n try {\n return JSON.parse(fs.readFileSync(file, 'utf8')) as object;\n } catch (err: unknown) {\n //const error = toError(err);\n throw new OpenApiGenerationError(\n `${file} is not valid JSON: ${err instanceof Error ? err.message : String(err)}`,\n file,\n 'Fix or regenerate that file; a components lookup reads it as JSON.',\n );\n }\n }\n\n private missing(packageName: string, reason: string): LocatedComponents {\n return new LocatedComponents(undefined, new MissingComponents(packageName, reason));\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { GenerationInputs } from '../generate/GenerationInputs';
1
+ import { ComponentsInputs, GenerationInputs } from '../generate/GenerationInputs';
2
2
  /**
3
3
  * Read everything from disk, ONCE, into {@link GenerationInputs}.
4
4
  *
@@ -11,8 +11,21 @@ export declare class InputsLoader {
11
11
  private readonly manifests;
12
12
  private readonly constants;
13
13
  private readonly extractor;
14
+ private readonly packages;
15
+ private readonly locator;
14
16
  private options;
17
+ /** True when `manifestPath` is a DTO library's `"kind": "components"` manifest. */
18
+ isComponents(manifestPath: string): boolean;
15
19
  load(manifestPath: string): GenerationInputs;
20
+ /** A DTO library's components manifest, its exported types, and the libraries THEY reach. */
21
+ loadComponents(manifestPath: string): ComponentsInputs;
22
+ private extractComponents;
23
+ /**
24
+ * The components document of EVERY OTHER package these types are declared in, located once each
25
+ * by {@link ComponentsLocator}. A package that publishes none is recorded, not refused, here: the
26
+ * generator refuses only when a document it renders actually reaches one of its types.
27
+ */
28
+ private upstream;
16
29
  /**
17
30
  * The nearest `tsconfig.json` at or above the MANIFEST, with the extraction flags forced on.
18
31
  *
@@ -6,11 +6,16 @@ const fs = tslib_1.__importStar(require("node:fs"));
6
6
  const path = tslib_1.__importStar(require("node:path"));
7
7
  const ts = tslib_1.__importStar(require("typescript"));
8
8
  const api_doc_model_1 = require("@webpieces/api-doc-model");
9
+ const core_util_1 = require("@webpieces/core-util");
9
10
  const OpenApiGenerationError_1 = require("../OpenApiGenerationError");
10
11
  const ManifestLoader_1 = require("../manifest/ManifestLoader");
11
12
  const GenerationInputs_1 = require("../generate/GenerationInputs");
13
+ const UpstreamComponents_1 = require("../generate/UpstreamComponents");
14
+ const ComponentsLocator_1 = require("./ComponentsLocator");
12
15
  const ExportedConstantFolder_1 = require("./ExportedConstantFolder");
13
16
  const ForeignFailure_1 = require("./ForeignFailure");
17
+ /** A `path/to/File.ts:12:5` location's FILE. */
18
+ const LINE_AND_COLUMN = /:\d+:\d+$/;
14
19
  /**
15
20
  * The compiler options the contracts are read with, when the project has no `tsconfig.json` of its
16
21
  * own to inherit from (see {@link InputsLoader.compilerOptions}).
@@ -41,11 +46,84 @@ class InputsLoader {
41
46
  manifests = new ManifestLoader_1.ManifestLoader();
42
47
  constants = new ExportedConstantFolder_1.ExportedConstantFolder();
43
48
  extractor = new api_doc_model_1.ApiDocExtractor();
49
+ packages = new api_doc_model_1.PackageOfFile();
50
+ locator = new ComponentsLocator_1.ComponentsLocator();
44
51
  options = FALLBACK_OPTIONS;
52
+ /** True when `manifestPath` is a DTO library's `"kind": "components"` manifest. */
53
+ isComponents(manifestPath) {
54
+ return this.manifests.isComponents(manifestPath);
55
+ }
45
56
  load(manifestPath) {
46
57
  const manifest = this.manifests.load(manifestPath);
47
58
  this.options = this.compilerOptions(manifestPath);
48
- return new GenerationInputs_1.GenerationInputs(manifestPath, manifest, this.contracts(manifestPath, manifest), this.errorType(manifestPath, manifest), this.responseHeaders(manifestPath, manifest), this.description(manifestPath, manifest));
59
+ const contracts = this.contracts(manifestPath, manifest);
60
+ const errorType = this.errorType(manifestPath, manifest);
61
+ const homePackage = this.packages.of(manifestPath)?.name;
62
+ // Only the SPLIT documents reference other packages' components documents. A contract that
63
+ // feeds nothing but the MCP projection inlines every schema, so it requires no DTO library to
64
+ // publish one (#1058) — and it is not asked to.
65
+ const split = contracts
66
+ .filter((contract) => contract.model.apiTypes.includes(core_util_1.SVC_TO_SVC) ||
67
+ contract.model.apiTypes.includes(core_util_1.EXTERNAL_CUSTOMER))
68
+ .map((contract) => contract.model.types);
69
+ const reached = errorType === undefined ? split : split.concat([errorType.types]);
70
+ return new GenerationInputs_1.GenerationInputs(manifestPath, manifest, contracts, errorType, this.responseHeaders(manifestPath, manifest), this.description(manifestPath, manifest), homePackage, this.upstream(manifestPath, homePackage, reached));
71
+ }
72
+ /** A DTO library's components manifest, its exported types, and the libraries THEY reach. */
73
+ loadComponents(manifestPath) {
74
+ const manifest = this.manifests.loadComponents(manifestPath);
75
+ this.options = this.compilerOptions(manifestPath);
76
+ const files = manifest.entries.map((entry) => {
77
+ const file = this.manifests.resolve(manifestPath, entry);
78
+ this.mustExist(file, entry, manifestPath);
79
+ return file;
80
+ });
81
+ const model = this.extractComponents(files, manifestPath);
82
+ const manifestPackage = this.packages.of(manifestPath)?.name;
83
+ if (manifestPackage !== model.packageName) {
84
+ throw new OpenApiGenerationError_1.OpenApiGenerationError(`the entries belong to ${model.packageName}, and the manifest to ${manifestPackage ?? 'no package'}`, manifestPath, "Keep a DTO library's manifest beside its own package.json, naming that library's entry files.");
85
+ }
86
+ return new GenerationInputs_1.ComponentsInputs(manifestPath, manifest, model, this.upstream(manifestPath, model.packageName, [model.types]));
87
+ }
88
+ extractComponents(files, manifestPath) {
89
+ // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package
90
+ try {
91
+ return this.extractor.extractComponents(files, this.options);
92
+ }
93
+ catch (err) {
94
+ //const error = toError(err);
95
+ throw this.rethrow(err, files[0] ?? manifestPath);
96
+ }
97
+ }
98
+ /**
99
+ * The components document of EVERY OTHER package these types are declared in, located once each
100
+ * by {@link ComponentsLocator}. A package that publishes none is recorded, not refused, here: the
101
+ * generator refuses only when a document it renders actually reaches one of its types.
102
+ */
103
+ upstream(manifestPath, homePackage, typeMaps) {
104
+ const declaredIn = new Map();
105
+ for (const types of typeMaps) {
106
+ for (const type of types.values()) {
107
+ if (type.packageName === undefined || type.packageName === homePackage) {
108
+ continue;
109
+ }
110
+ if (!declaredIn.has(type.packageName)) {
111
+ declaredIn.set(type.packageName, type.location.replace(LINE_AND_COLUMN, ''));
112
+ }
113
+ }
114
+ }
115
+ const published = new Map();
116
+ const missing = new Map();
117
+ for (const packageName of Array.from(declaredIn.keys()).sort()) {
118
+ const located = this.locator.locate(packageName, path.dirname(manifestPath), this.packages.of(declaredIn.get(packageName))?.directory);
119
+ if (located.published !== undefined) {
120
+ published.set(packageName, located.published);
121
+ }
122
+ else {
123
+ missing.set(packageName, located.missing);
124
+ }
125
+ }
126
+ return new UpstreamComponents_1.UpstreamComponentsIndex(published, missing);
49
127
  }
50
128
  /**
51
129
  * The nearest `tsconfig.json` at or above the MANIFEST, with the extraction flags forced on.
@@ -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,4DAA2D;AAC3D,sEAAmE;AACnE,+DAA4D;AAE5D,mEAIsC;AACtC,qEAAkE;AAClE,qDAAkD;AAElD;;;;;;;;GAQG;AACH,MAAM,gBAAgB,GAAuB;IACzC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM;IAC9B,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ;IAC9B,gBAAgB,EAAE,EAAE,CAAC,oBAAoB,CAAC,MAAM;IAChD,sBAAsB,EAAE,IAAI;IAC5B,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,IAAI;IACZ,YAAY,EAAE,IAAI;CACrB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAa,YAAY;IACJ,SAAS,GAAG,IAAI,+BAAc,EAAE,CAAC;IACjC,SAA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;QAC/D,IAAI,QAAQ,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;YACzC,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;QAC5E,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;QAC7D,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IAChD,CAAC;IAEO,SAAS,CAAC,IAAY,EAAE,QAAgB,EAAE,YAAoB;QAClE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,+CAAsB,CAC5B,uBAAuB,QAAQ,yBAAyB,EACxD,YAAY,EACZ,sEAAsE,IAAI,GAAG,CAChF,CAAC;QACN,CAAC;IACL,CAAC;CACJ;AA1ID,oCA0IC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport * as ts from 'typescript';\nimport { ApiDocExtractor } from '@webpieces/api-doc-model';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\nimport { ManifestLoader } from '../manifest/ManifestLoader';\nimport { ApiEntry, OpenApiManifest, ResponseHeaderEntry } from '../manifest/OpenApiManifest';\nimport {\n ContractModel,\n GenerationInputs,\n ResolvedResponseHeader,\n} from '../generate/GenerationInputs';\nimport { ExportedConstantFolder } from './ExportedConstantFolder';\nimport { ForeignFailure } from './ForeignFailure';\n\n/**\n * The compiler options the contracts are read with, when the project has no `tsconfig.json` of its\n * own to inherit from (see {@link InputsLoader.compilerOptions}).\n *\n * Decorators must be enabled or a contract does not parse at all, and `skipLibCheck` is on because\n * this is an EXTRACTION pass, not a type-check: the app's own build is what decides whether the\n * contract compiles, and duplicating that judgement here would make `wp-openapi` fail for reasons\n * that have nothing to do with the document.\n */\nconst FALLBACK_OPTIONS: ts.CompilerOptions = {\n target: ts.ScriptTarget.ES2022,\n module: ts.ModuleKind.CommonJS,\n moduleResolution: ts.ModuleResolutionKind.Node10,\n experimentalDecorators: true,\n strict: true,\n noEmit: true,\n skipLibCheck: true,\n};\n\n/**\n * Read everything from disk, ONCE, into {@link GenerationInputs}.\n *\n * Every path in the manifest is resolved against the MANIFEST's own directory, never against the\n * process's cwd. A document whose contents depended on where `wp-openapi` was invoked from would be\n * a different document per caller, and the committed golden would go red depending on which\n * directory a build happened to run in.\n */\nexport class InputsLoader {\n private readonly manifests = new ManifestLoader();\n private readonly constants = new ExportedConstantFolder();\n private readonly extractor = new ApiDocExtractor();\n private options: ts.CompilerOptions = FALLBACK_OPTIONS;\n\n load(manifestPath: string): GenerationInputs {\n const manifest = this.manifests.load(manifestPath);\n this.options = this.compilerOptions(manifestPath);\n return new GenerationInputs(\n manifestPath,\n manifest,\n this.contracts(manifestPath, manifest),\n this.errorType(manifestPath, manifest),\n this.responseHeaders(manifestPath, manifest),\n this.description(manifestPath, manifest),\n );\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,4DAKkC;AAClC,oDAAqE;AACrE,sEAAmE;AACnE,+DAA4D;AAE5D,mEAKsC;AACtC,uEAIwC;AACxC,2DAAwD;AACxD,qEAAkE;AAClE,qDAAkD;AAElD,gDAAgD;AAChD,MAAM,eAAe,GAAG,WAAW,CAAC;AAEpC;;;;;;;;GAQG;AACH,MAAM,gBAAgB,GAAuB;IACzC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM;IAC9B,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ;IAC9B,gBAAgB,EAAE,EAAE,CAAC,oBAAoB,CAAC,MAAM;IAChD,sBAAsB,EAAE,IAAI;IAC5B,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,IAAI;IACZ,YAAY,EAAE,IAAI;CACrB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAa,YAAY;IACJ,SAAS,GAAG,IAAI,+BAAc,EAAE,CAAC;IACjC,SA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AyB;QAC/D,IAAI,QAAQ,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;YACzC,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;QAC5E,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;QAC7D,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IAChD,CAAC;IAEO,SAAS,CAAC,IAAY,EAAE,QAAgB,EAAE,YAAoB;QAClE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,+CAAsB,CAC5B,uBAAuB,QAAQ,yBAAyB,EACxD,YAAY,EACZ,sEAAsE,IAAI,GAAG,CAChF,CAAC;QACN,CAAC;IACL,CAAC;CACJ;AA3OD,oCA2OC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport * as ts from 'typescript';\nimport {\n ApiComponentsModel,\n ApiDocExtractor,\n DocumentedType,\n PackageOfFile,\n} from '@webpieces/api-doc-model';\nimport { EXTERNAL_CUSTOMER, SVC_TO_SVC } from '@webpieces/core-util';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\nimport { ManifestLoader } from '../manifest/ManifestLoader';\nimport { ApiEntry, OpenApiManifest, ResponseHeaderEntry } from '../manifest/OpenApiManifest';\nimport {\n ComponentsInputs,\n ContractModel,\n GenerationInputs,\n ResolvedResponseHeader,\n} from '../generate/GenerationInputs';\nimport {\n MissingComponents,\n PublishedComponents,\n UpstreamComponentsIndex,\n} from '../generate/UpstreamComponents';\nimport { ComponentsLocator } from './ComponentsLocator';\nimport { ExportedConstantFolder } from './ExportedConstantFolder';\nimport { ForeignFailure } from './ForeignFailure';\n\n/** A `path/to/File.ts:12:5` location's FILE. */\nconst LINE_AND_COLUMN = /:\\d+:\\d+$/;\n\n/**\n * The compiler options the contracts are read with, when the project has no `tsconfig.json` of its\n * own to inherit from (see {@link InputsLoader.compilerOptions}).\n *\n * Decorators must be enabled or a contract does not parse at all, and `skipLibCheck` is on because\n * this is an EXTRACTION pass, not a type-check: the app's own build is what decides whether the\n * contract compiles, and duplicating that judgement here would make `wp-openapi` fail for reasons\n * that have nothing to do with the document.\n */\nconst FALLBACK_OPTIONS: ts.CompilerOptions = {\n target: ts.ScriptTarget.ES2022,\n module: ts.ModuleKind.CommonJS,\n moduleResolution: ts.ModuleResolutionKind.Node10,\n experimentalDecorators: true,\n strict: true,\n noEmit: true,\n skipLibCheck: true,\n};\n\n/**\n * Read everything from disk, ONCE, into {@link GenerationInputs}.\n *\n * Every path in the manifest is resolved against the MANIFEST's own directory, never against the\n * process's cwd. A document whose contents depended on where `wp-openapi` was invoked from would be\n * a different document per caller, and the committed golden would go red depending on which\n * directory a build happened to run in.\n */\nexport class InputsLoader {\n private readonly manifests = new ManifestLoader();\n private readonly constants = new ExportedConstantFolder();\n private readonly extractor = new ApiDocExtractor();\n private readonly packages = new PackageOfFile();\n private readonly locator = new ComponentsLocator();\n private options: ts.CompilerOptions = FALLBACK_OPTIONS;\n\n /** True when `manifestPath` is a DTO library's `\"kind\": \"components\"` manifest. */\n isComponents(manifestPath: string): boolean {\n return this.manifests.isComponents(manifestPath);\n }\n\n load(manifestPath: string): GenerationInputs {\n const manifest = this.manifests.load(manifestPath);\n this.options = this.compilerOptions(manifestPath);\n const contracts = this.contracts(manifestPath, manifest);\n const errorType = this.errorType(manifestPath, manifest);\n const homePackage = this.packages.of(manifestPath)?.name;\n // Only the SPLIT documents reference other packages' components documents. A contract that\n // feeds nothing but the MCP projection inlines every schema, so it requires no DTO library to\n // publish one (#1058) — and it is not asked to.\n const split = contracts\n .filter(\n (contract: ContractModel) =>\n contract.model.apiTypes.includes(SVC_TO_SVC) ||\n contract.model.apiTypes.includes(EXTERNAL_CUSTOMER),\n )\n .map((contract: ContractModel) => contract.model.types);\n const reached = errorType === undefined ? split : split.concat([errorType.types]);\n return new GenerationInputs(\n manifestPath,\n manifest,\n contracts,\n errorType,\n this.responseHeaders(manifestPath, manifest),\n this.description(manifestPath, manifest),\n homePackage,\n this.upstream(manifestPath, homePackage, reached),\n );\n }\n\n /** A DTO library's components manifest, its exported types, and the libraries THEY reach. */\n loadComponents(manifestPath: string): ComponentsInputs {\n const manifest = this.manifests.loadComponents(manifestPath);\n this.options = this.compilerOptions(manifestPath);\n const files = manifest.entries.map((entry: string) => {\n const file = this.manifests.resolve(manifestPath, entry);\n this.mustExist(file, entry, manifestPath);\n return file;\n });\n const model = this.extractComponents(files, manifestPath);\n const manifestPackage = this.packages.of(manifestPath)?.name;\n if (manifestPackage !== model.packageName) {\n throw new OpenApiGenerationError(\n `the entries belong to ${model.packageName}, and the manifest to ${manifestPackage ?? 'no package'}`,\n manifestPath,\n \"Keep a DTO library's manifest beside its own package.json, naming that library's entry files.\",\n );\n }\n return new ComponentsInputs(\n manifestPath,\n manifest,\n model,\n this.upstream(manifestPath, model.packageName, [model.types]),\n );\n }\n\n private extractComponents(files: readonly string[], manifestPath: string): ApiComponentsModel {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package\n try {\n return this.extractor.extractComponents(files, this.options);\n } catch (err: unknown) {\n //const error = toError(err);\n throw this.rethrow(err, files[0] ?? manifestPath);\n }\n }\n\n /**\n * The components document of EVERY OTHER package these types are declared in, located once each\n * by {@link ComponentsLocator}. A package that publishes none is recorded, not refused, here: the\n * generator refuses only when a document it renders actually reaches one of its types.\n */\n private upstream(\n manifestPath: string,\n homePackage: string | undefined,\n typeMaps: readonly ReadonlyMap<string, DocumentedType>[],\n ): UpstreamComponentsIndex {\n const declaredIn = new Map<string, string>();\n for (const types of typeMaps) {\n for (const type of types.values()) {\n if (type.packageName === undefined || type.packageName === homePackage) {\n continue;\n }\n if (!declaredIn.has(type.packageName)) {\n declaredIn.set(type.packageName, type.location.replace(LINE_AND_COLUMN, ''));\n }\n }\n }\n const published = new Map<string, PublishedComponents>();\n const missing = new Map<string, MissingComponents>();\n for (const packageName of Array.from(declaredIn.keys()).sort()) {\n const located = this.locator.locate(\n packageName,\n path.dirname(manifestPath),\n this.packages.of(declaredIn.get(packageName)!)?.directory,\n );\n if (located.published !== undefined) {\n published.set(packageName, located.published);\n } else {\n missing.set(packageName, located.missing!);\n }\n }\n return new UpstreamComponentsIndex(published, missing);\n }\n\n /**\n * The nearest `tsconfig.json` at or above the MANIFEST, with the extraction flags forced on.\n *\n * A contract imports its decorators from `@webpieces/core-util`, and a path mapping or a\n * `baseUrl` is what makes that name resolve. Reading the project's own tsconfig is therefore not\n * a convenience — without it the checker cannot see that `POST` is the string `'POST'`, and the\n * constant folder does the right thing and REFUSES rather than guessing a verb. Falling back to\n * a fixed set of options is for a caller with no tsconfig at all, which is a legal thing to be.\n *\n * The flags below are forced over whatever the project says because they are about THIS read and\n * not about the project's build: decorators must parse, nothing may be emitted, and a library\n * type error in `node_modules` is the project's business, not a reason to refuse a document.\n */\n private compilerOptions(manifestPath: string): ts.CompilerOptions {\n const configFile = ts.findConfigFile(path.dirname(manifestPath), (file: string) =>\n ts.sys.fileExists(file),\n );\n if (configFile === undefined) {\n return FALLBACK_OPTIONS;\n }\n const read = ts.readConfigFile(configFile, (file: string) => ts.sys.readFile(file));\n if (read.error !== undefined || read.config === undefined) {\n return FALLBACK_OPTIONS;\n }\n const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, path.dirname(configFile));\n const options = parsed.options;\n options.noEmit = true;\n options.skipLibCheck = true;\n options.experimentalDecorators = true;\n options.composite = false;\n options.declaration = false;\n return options;\n }\n\n private contracts(manifestPath: string, manifest: OpenApiManifest): readonly ContractModel[] {\n return manifest.apis.map((entry: ApiEntry) => {\n const file = this.manifests.resolve(manifestPath, entry.entry);\n this.mustExist(file, entry.entry, manifestPath);\n return new ContractModel(entry, this.extract(file), file);\n });\n }\n\n /**\n * The extractor's own failure is re-thrown as THIS package's one error type, carrying the\n * extractor's location and cure. The alternative — letting `ApiDocExtractionError` out — would\n * give `wp-openapi` two failure types that its top-level handler had to know about, and only one\n * of them would be documented on this package's surface.\n */\n private extract(file: string): ReturnType<ApiDocExtractor['extractFile']> {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package\n try {\n return this.extractor.extractFile(file, this.options);\n } catch (err: unknown) {\n //const error = toError(err);\n throw this.rethrow(err, file);\n }\n }\n\n private errorType(\n manifestPath: string,\n manifest: OpenApiManifest,\n ): ReturnType<ApiDocExtractor['extractType']> | undefined {\n const errors = manifest.errors;\n if (errors === undefined) {\n return undefined;\n }\n const file = this.manifests.resolve(manifestPath, errors.entry);\n this.mustExist(file, errors.entry, manifestPath);\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package\n try {\n return this.extractor.extractType(file, errors.type, this.options);\n } catch (err: unknown) {\n //const error = toError(err);\n throw this.rethrow(err, file);\n }\n }\n\n // webpieces-disable no-any-unknown -- a caught value; ForeignFailure is what narrows it\n private rethrow(err: unknown, file: string): OpenApiGenerationError {\n if (err instanceof OpenApiGenerationError) {\n return err;\n }\n return ForeignFailure.of(err).asGenerationError(\n file,\n 'Fix the contract this document is read from.',\n );\n }\n\n private responseHeaders(\n manifestPath: string,\n manifest: OpenApiManifest,\n ): readonly ResolvedResponseHeader[] {\n return manifest.responseHeaders.map((header: ResponseHeaderEntry) => {\n const file = this.manifests.resolve(manifestPath, header.entry);\n return new ResolvedResponseHeader(\n this.constants.fold(file, header.nameConstant),\n header.description,\n );\n });\n }\n\n private description(manifestPath: string, manifest: OpenApiManifest): string | undefined {\n if (manifest.descriptionFile === undefined) {\n return undefined;\n }\n const file = this.manifests.resolve(manifestPath, manifest.descriptionFile);\n this.mustExist(file, manifest.descriptionFile, manifestPath);\n return fs.readFileSync(file, 'utf8').trim();\n }\n\n private mustExist(file: string, declared: string, manifestPath: string): void {\n if (!fs.existsSync(file)) {\n throw new OpenApiGenerationError(\n `the manifest names '${declared}', which does not exist`,\n manifestPath,\n `Paths are relative to the manifest's own directory. Expected it at ${file}.`,\n );\n }\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { OpenApiManifest } from './OpenApiManifest';
1
+ import { ComponentsManifest, OpenApiManifest } from './OpenApiManifest';
2
2
  /**
3
3
  * Read `openapi.manifest.json` into {@link OpenApiManifest}.
4
4
  *
@@ -9,7 +9,15 @@ import { OpenApiManifest } from './OpenApiManifest';
9
9
  * is indistinguishable, from outside, from an API that genuinely has no error contract.
10
10
  */
11
11
  export declare class ManifestLoader {
12
- /** @param manifestPath absolute path to `openapi.manifest.json`. */
12
+ /**
13
+ * True for a DTO library's `"kind": "components"` manifest, false for a contract library's (no
14
+ * `kind`). Any other `kind` is refused: a typo there would otherwise render the wrong document.
15
+ */
16
+ isComponents(manifestPath: string): boolean;
17
+ /** A DTO library's components manifest. See {@link ComponentsManifest}. */
18
+ loadComponents(manifestPath: string): ComponentsManifest;
19
+ private read;
20
+ /** @param manifestPath absolute path to a CONTRACT library's `openapi.manifest.json`. */
13
21
  load(manifestPath: string): OpenApiManifest;
14
22
  private servers;
15
23
  private apis;
@@ -9,6 +9,20 @@ const JsonReader_1 = require("./JsonReader");
9
9
  const OpenApiManifest_1 = require("./OpenApiManifest");
10
10
  /** The only `kind` an api entry may declare. Anything else is a typo, and typos are refused. */
11
11
  const WEBHOOK = 'webhook';
12
+ /**
13
+ * The only `kind` a MANIFEST may declare (#1058): a DTO library's components-only document. A
14
+ * manifest with no `kind` is a contract library's, exactly as before.
15
+ */
16
+ const COMPONENTS = 'components';
17
+ /** Keys a components manifest must not carry, each with why — a contract-manifest key is a mix-up. */
18
+ const NOT_IN_COMPONENTS = new Map([
19
+ ['apis', 'a components document has no paths; list the library\'s entry files in "entries"'],
20
+ ['version', "a library document's info.version is the package version, read from its package.json"],
21
+ ['servers', 'a components document has no operations to serve'],
22
+ ['errors', 'the error contract belongs to a contract document'],
23
+ ['responseHeaders', 'response headers belong to a contract document'],
24
+ ['securitySchemeNames', 'security belongs to a contract document'],
25
+ ]);
12
26
  /**
13
27
  * Read `openapi.manifest.json` into {@link OpenApiManifest}.
14
28
  *
@@ -19,12 +33,48 @@ const WEBHOOK = 'webhook';
19
33
  * is indistinguishable, from outside, from an API that genuinely has no error contract.
20
34
  */
21
35
  class ManifestLoader {
22
- /** @param manifestPath absolute path to `openapi.manifest.json`. */
23
- load(manifestPath) {
36
+ /**
37
+ * True for a DTO library's `"kind": "components"` manifest, false for a contract library's (no
38
+ * `kind`). Any other `kind` is refused: a typo there would otherwise render the wrong document.
39
+ */
40
+ isComponents(manifestPath) {
41
+ const kind = this.read(manifestPath).optionalString('kind');
42
+ if (kind === undefined) {
43
+ return false;
44
+ }
45
+ if (kind !== COMPONENTS) {
46
+ throw new OpenApiGenerationError_1.OpenApiGenerationError(`unknown manifest kind '${kind}'`, manifestPath, `The only manifest kind is "${COMPONENTS}", for a DTO library's components document. ` +
47
+ "Leave it out for a contract library's manifest.");
48
+ }
49
+ return true;
50
+ }
51
+ /** A DTO library's components manifest. See {@link ComponentsManifest}. */
52
+ loadComponents(manifestPath) {
53
+ const raw = this.read(manifestPath);
54
+ for (const key of NOT_IN_COMPONENTS.keys()) {
55
+ const why = NOT_IN_COMPONENTS.get(key);
56
+ if (raw.has(key)) {
57
+ throw new OpenApiGenerationError_1.OpenApiGenerationError(`a "kind": "${COMPONENTS}" manifest declares '${key}'`, raw.where, `Delete it — ${why}.`);
58
+ }
59
+ }
60
+ const entries = raw.strings('entries');
61
+ if (entries.length === 0) {
62
+ throw new OpenApiGenerationError_1.OpenApiGenerationError("'entries' is empty", raw.where, 'Name the library\'s entry files, e.g. "entries": ["src/index.ts"]; the document holds every type they export.');
63
+ }
64
+ return new OpenApiManifest_1.ComponentsManifest(raw.string('title'), entries);
65
+ }
66
+ read(manifestPath) {
24
67
  if (!fs.existsSync(manifestPath)) {
25
68
  throw new OpenApiGenerationError_1.OpenApiGenerationError('no manifest at this path', manifestPath, 'Pass --manifest pointing at an openapi.manifest.json that exists.');
26
69
  }
27
- const raw = JsonReader_1.JsonReader.parseFile(fs.readFileSync(manifestPath, 'utf8'), manifestPath);
70
+ return JsonReader_1.JsonReader.parseFile(fs.readFileSync(manifestPath, 'utf8'), manifestPath);
71
+ }
72
+ /** @param manifestPath absolute path to a CONTRACT library's `openapi.manifest.json`. */
73
+ load(manifestPath) {
74
+ if (this.isComponents(manifestPath)) {
75
+ throw new OpenApiGenerationError_1.OpenApiGenerationError(`this is a "kind": "${COMPONENTS}" manifest, not a contract manifest`, manifestPath, 'Render it as a components document (wp-openapi does so on its own when it reads the kind).');
76
+ }
77
+ const raw = this.read(manifestPath);
28
78
  return new OpenApiManifest_1.OpenApiManifest(raw.string('title'), raw.string('version'), this.servers(raw), raw.optionalString('descriptionFile'), this.apis(raw), raw.strings('securitySchemeNames'), this.errors(raw), this.responseHeaders(raw));
29
79
  }
30
80
  servers(raw) {
@@ -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,uDAO2B;AAE3B,gGAAgG;AAChG,MAAM,OAAO,GAAG,SAAS,CAAC;AAE1B;;;;;;;;GAQG;AACH,MAAa,cAAc;IACvB,oEAAoE;IACpE,IAAI,CAAC,YAAoB;QACrB,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,+CAAsB,CAC5B,0BAA0B,EAC1B,YAAY,EACZ,mEAAmE,CACtE,CAAC;QACN,CAAC;QACD,MAAM,GAAG,GAAG,uBAAU,CAAC,SAAS,CAAC,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM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s';\nimport * as path from 'node:path';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\nimport { JsonReader } from './JsonReader';\nimport {\n ApiEntry,\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 * 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 /** @param manifestPath absolute path to `openapi.manifest.json`. */\n load(manifestPath: string): OpenApiManifest {\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 const raw = JsonReader.parseFile(fs.readFileSync(manifestPath, 'utf8'), manifestPath);\n return new OpenApiManifest(\n raw.string('title'),\n raw.string('version'),\n this.servers(raw),\n raw.optionalString('descriptionFile'),\n this.apis(raw),\n raw.strings('securitySchemeNames'),\n this.errors(raw),\n this.responseHeaders(raw),\n );\n }\n\n private servers(raw: JsonReader): readonly ServerEntry[] {\n return raw\n .objects('servers')\n .map(\n (server: JsonReader) =>\n new ServerEntry(server.string('url'), server.optionalString('description')),\n );\n }\n\n private apis(raw: JsonReader): readonly ApiEntry[] {\n const entries = raw\n .objects('apis')\n .map(\n (api: JsonReader) =>\n new ApiEntry(\n api.string('entry'),\n api.string('tag'),\n api.optionalString('kind'),\n ),\n );\n if (entries.length === 0) {\n throw new OpenApiGenerationError(\n \"'apis' is empty\",\n raw.where,\n 'List at least one contract; a document with no operations publishes nothing.',\n );\n }\n for (const entry of entries) {\n if (entry.kind !== undefined && entry.kind !== WEBHOOK) {\n throw new OpenApiGenerationError(\n `unknown api kind '${entry.kind}' on '${entry.entry}'`,\n raw.where,\n `The only declared kind is \"${WEBHOOK}\". Leave it out for an ordinary contract.`,\n );\n }\n }\n return entries;\n }\n\n private errors(raw: JsonReader): ErrorsEntry | undefined {\n const errors = raw.object('errors');\n if (errors === undefined) {\n return undefined;\n }\n return new ErrorsEntry(\n errors.string('entry'),\n errors.string('type'),\n errors\n .objects('responses')\n .map(\n (response: JsonReader) =>\n new ErrorResponseEntry(\n response.string('status'),\n response.string('description'),\n ),\n ),\n );\n }\n\n private responseHeaders(raw: JsonReader): readonly ResponseHeaderEntry[] {\n return raw\n .objects('responseHeaders')\n .map(\n (header: JsonReader) =>\n new ResponseHeaderEntry(\n header.string('entry'),\n header.string('nameConstant'),\n header.optionalString('description'),\n ),\n );\n }\n\n /** A manifest-relative path, resolved against the manifest's own directory. */\n resolve(manifestPath: string, relative: string): string {\n return path.resolve(path.dirname(manifestPath), relative);\n }\n}\n"]}
1
+ {"version":3,"file":"ManifestLoader.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/manifest/ManifestLoader.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAClC,sEAAmE;AACnE,6CAA0C;AAC1C,uDAQ2B;AAE3B,gGAAgG;AAChG,MAAM,OAAO,GAAG,SAAS,CAAC;AAE1B;;;GAGG;AACH,MAAM,UAAU,GAAG,YAAY,CAAC;AAEhC,sGAAsG;AACtG,MAAM,iBAAiB,GAAgC,IAAI,GAAG,CAAiB;IAC3E,CAAC,MAAM,EAAE,kFAAkF,CAAC;IAC5F,CAAC,SAAS,EAAE,sFAAsF,CAAC;IACnG,CAAC,SAAS,EAAE,kDAAkD,CAAC;IAC/D,CAAC,QAAQ,EAAE,mDAAmD,CAAC;IAC/D,CAAC,iBAAiB,EAAE,gDAAgD,CAAC;IACrE,CAAC,qBAAqB,EAAE,yCAAyC,CAAC;CACrE,CAAC,CAAC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,CAAC,aAAa,CAAC,CACjC,CACR,CACR,CAAC;IACN,CAAC;IAEO,eAAe,CAAC,GAAe;QACnC,OAAO,GAAG;aACL,OAAO,CAAC,iBAAiB,CAAC;aAC1B,GAAG,CACA,CAAC,MAAkB,EAAE,EAAE,CACnB,IAAI,qCAAmB,CACnB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EACtB,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,EAC7B,MAAM,CAAC,cAAc,CAAC,aAAa,CAAC,CACvC,CACR,CAAC;IACV,CAAC;IAED,+EAA+E;IAC/E,OAAO,CAAC,YAAoB,EAAE,QAAgB;QAC1C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC9D,CAAC;CACJ;AA1JD,wCA0JC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\nimport { JsonReader } from './JsonReader';\nimport {\n ApiEntry,\n ComponentsManifest,\n ErrorResponseEntry,\n ErrorsEntry,\n OpenApiManifest,\n ResponseHeaderEntry,\n ServerEntry,\n} from './OpenApiManifest';\n\n/** The only `kind` an api entry may declare. Anything else is a typo, and typos are refused. */\nconst WEBHOOK = 'webhook';\n\n/**\n * The only `kind` a MANIFEST may declare (#1058): a DTO library's components-only document. A\n * manifest with no `kind` is a contract library's, exactly as before.\n */\nconst COMPONENTS = 'components';\n\n/** Keys a components manifest must not carry, each with why — a contract-manifest key is a mix-up. */\nconst NOT_IN_COMPONENTS: ReadonlyMap<string, string> = new Map<string, string>([\n ['apis', 'a components document has no paths; list the library\\'s entry files in \"entries\"'],\n ['version', \"a library document's info.version is the package version, read from its package.json\"],\n ['servers', 'a components document has no operations to serve'],\n ['errors', 'the error contract belongs to a contract document'],\n ['responseHeaders', 'response headers belong to a contract document'],\n ['securitySchemeNames', 'security belongs to a contract document'],\n]);\n\n/**\n * Read `openapi.manifest.json` into {@link OpenApiManifest}.\n *\n * It deals only in {@link JsonReader}, which is where the \"came off disk, not yet checked\" state is\n * concentrated — so nothing in this file, or anywhere downstream, handles an unnarrowed value.\n *\n * Every rejection is a HARD FAILURE naming the field. A published document quietly missing a section\n * is indistinguishable, from outside, from an API that genuinely has no error contract.\n */\nexport class ManifestLoader {\n /**\n * True for a DTO library's `\"kind\": \"components\"` manifest, false for a contract library's (no\n * `kind`). Any other `kind` is refused: a typo there would otherwise render the wrong document.\n */\n isComponents(manifestPath: string): boolean {\n const kind = this.read(manifestPath).optionalString('kind');\n if (kind === undefined) {\n return false;\n }\n if (kind !== COMPONENTS) {\n throw new OpenApiGenerationError(\n `unknown manifest kind '${kind}'`,\n manifestPath,\n `The only manifest kind is \"${COMPONENTS}\", for a DTO library's components document. ` +\n \"Leave it out for a contract library's manifest.\",\n );\n }\n return true;\n }\n\n /** A DTO library's components manifest. See {@link ComponentsManifest}. */\n loadComponents(manifestPath: string): ComponentsManifest {\n const raw = this.read(manifestPath);\n for (const key of NOT_IN_COMPONENTS.keys()) {\n const why = NOT_IN_COMPONENTS.get(key)!;\n if (raw.has(key)) {\n throw new OpenApiGenerationError(\n `a \"kind\": \"${COMPONENTS}\" manifest declares '${key}'`,\n raw.where,\n `Delete it — ${why}.`,\n );\n }\n }\n const entries = raw.strings('entries');\n if (entries.length === 0) {\n throw new OpenApiGenerationError(\n \"'entries' is empty\",\n raw.where,\n 'Name the library\\'s entry files, e.g. \"entries\": [\"src/index.ts\"]; the document holds every type they export.',\n );\n }\n return new ComponentsManifest(raw.string('title'), entries);\n }\n\n private read(manifestPath: string): JsonReader {\n if (!fs.existsSync(manifestPath)) {\n throw new OpenApiGenerationError(\n 'no manifest at this path',\n manifestPath,\n 'Pass --manifest pointing at an openapi.manifest.json that exists.',\n );\n }\n return JsonReader.parseFile(fs.readFileSync(manifestPath, 'utf8'), manifestPath);\n }\n\n /** @param manifestPath absolute path to a CONTRACT library's `openapi.manifest.json`. */\n load(manifestPath: string): OpenApiManifest {\n if (this.isComponents(manifestPath)) {\n throw new OpenApiGenerationError(\n `this is a \"kind\": \"${COMPONENTS}\" manifest, not a contract manifest`,\n manifestPath,\n 'Render it as a components document (wp-openapi does so on its own when it reads the kind).',\n );\n }\n const raw = this.read(manifestPath);\n return new OpenApiManifest(\n raw.string('title'),\n raw.string('version'),\n this.servers(raw),\n raw.optionalString('descriptionFile'),\n this.apis(raw),\n raw.strings('securitySchemeNames'),\n this.errors(raw),\n this.responseHeaders(raw),\n );\n }\n\n private servers(raw: JsonReader): readonly ServerEntry[] {\n return raw\n .objects('servers')\n .map(\n (server: JsonReader) =>\n new ServerEntry(server.string('url'), server.optionalString('description')),\n );\n }\n\n private apis(raw: JsonReader): readonly ApiEntry[] {\n const entries = raw\n .objects('apis')\n .map(\n (api: JsonReader) =>\n new ApiEntry(\n api.string('entry'),\n api.string('tag'),\n api.optionalString('kind'),\n ),\n );\n if (entries.length === 0) {\n throw new OpenApiGenerationError(\n \"'apis' is empty\",\n raw.where,\n 'List at least one contract; a document with no operations publishes nothing.',\n );\n }\n for (const entry of entries) {\n if (entry.kind !== undefined && entry.kind !== WEBHOOK) {\n throw new OpenApiGenerationError(\n `unknown api kind '${entry.kind}' on '${entry.entry}'`,\n raw.where,\n `The only declared kind is \"${WEBHOOK}\". Leave it out for an ordinary contract.`,\n );\n }\n }\n return entries;\n }\n\n private errors(raw: JsonReader): ErrorsEntry | undefined {\n const errors = raw.object('errors');\n if (errors === undefined) {\n return undefined;\n }\n return new ErrorsEntry(\n errors.string('entry'),\n errors.string('type'),\n errors\n .objects('responses')\n .map(\n (response: JsonReader) =>\n new ErrorResponseEntry(\n response.string('status'),\n response.string('description'),\n ),\n ),\n );\n }\n\n private responseHeaders(raw: JsonReader): readonly ResponseHeaderEntry[] {\n return raw\n .objects('responseHeaders')\n .map(\n (header: JsonReader) =>\n new ResponseHeaderEntry(\n header.string('entry'),\n header.string('nameConstant'),\n header.optionalString('description'),\n ),\n );\n }\n\n /** A manifest-relative path, resolved against the manifest's own directory. */\n resolve(manifestPath: string, relative: string): string {\n return path.resolve(path.dirname(manifestPath), relative);\n }\n}\n"]}
@@ -114,3 +114,20 @@ export declare class OpenApiManifest {
114
114
  /** A markdown preamble, relative to the manifest. Rendered into `info.description`. */
115
115
  descriptionFile: string | undefined, apis: readonly ApiEntry[], securitySchemeNames: readonly string[], errors: ErrorsEntry | undefined, responseHeaders: readonly ResponseHeaderEntry[]);
116
116
  }
117
+ /**
118
+ * A DTO library's `openapi.manifest.json` — `"kind": "components"` (#1058).
119
+ *
120
+ * It names the library's ENTRY FILES instead of contracts: the document it produces is
121
+ * components-only — `openapi`, `info` and `components.schemas`, no paths — holding every type the
122
+ * library exports and declares, which contract documents `$ref` instead of copying. There is no
123
+ * `version` here: a library document's `info.version` IS the package version, read from its
124
+ * `package.json`, so the two cannot disagree.
125
+ */
126
+ export declare class ComponentsManifest {
127
+ readonly title: string;
128
+ /** The library's entry files (usually `src/index.ts`), relative to the manifest's directory. */
129
+ readonly entries: readonly string[];
130
+ constructor(title: string,
131
+ /** The library's entry files (usually `src/index.ts`), relative to the manifest's directory. */
132
+ entries: readonly string[]);
133
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpenApiManifest = exports.ResponseHeaderEntry = exports.ErrorsEntry = exports.ErrorResponseEntry = exports.ApiEntry = exports.ServerEntry = void 0;
3
+ exports.ComponentsManifest = exports.OpenApiManifest = exports.ResponseHeaderEntry = exports.ErrorsEntry = exports.ErrorResponseEntry = exports.ApiEntry = exports.ServerEntry = void 0;
4
4
  /**
5
5
  * `openapi.manifest.json`, as CLASSES.
6
6
  *
@@ -139,4 +139,24 @@ class OpenApiManifest {
139
139
  }
140
140
  }
141
141
  exports.OpenApiManifest = OpenApiManifest;
142
+ /**
143
+ * A DTO library's `openapi.manifest.json` — `"kind": "components"` (#1058).
144
+ *
145
+ * It names the library's ENTRY FILES instead of contracts: the document it produces is
146
+ * components-only — `openapi`, `info` and `components.schemas`, no paths — holding every type the
147
+ * library exports and declares, which contract documents `$ref` instead of copying. There is no
148
+ * `version` here: a library document's `info.version` IS the package version, read from its
149
+ * `package.json`, so the two cannot disagree.
150
+ */
151
+ class ComponentsManifest {
152
+ title;
153
+ entries;
154
+ constructor(title,
155
+ /** The library's entry files (usually `src/index.ts`), relative to the manifest's directory. */
156
+ entries) {
157
+ this.title = title;
158
+ this.entries = entries;
159
+ }
160
+ }
161
+ exports.ComponentsManifest = ComponentsManifest;
142
162
  //# sourceMappingURL=OpenApiManifest.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"OpenApiManifest.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/manifest/OpenApiManifest.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAa,WAAW;IAEP;IACA;IAFb,YACa,GAAW,EACX,WAA+B;QAD/B,QAAG,GAAH,GAAG,CAAQ;QACX,gBAAW,GAAX,WAAW,CAAoB;IACzC,CAAC;CACP;AALD,kCAKC;AAED,6CAA6C;AAC7C,MAAa,QAAQ;IAGJ;IAEA;IASA;IAbb;IACI,4EAA4E;IACnE,KAAa;IACtB,2FAA2F;IAClF,GAAW;IACpB;;;;;;;OAOG;IACM,IAAwB;QAXxB,UAAK,GAAL,KAAK,CAAQ;QAEb,QAAG,GAAH,GAAG,CAAQ;QASX,SAAI,GAAJ,IAAI,CAAoB;IAClC,CAAC;IAEJ,SAAS;QACL,OAAO,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC;IACnC,CAAC;CACJ;AApBD,4BAoBC;AAED,6DAA6D;AAC7D,MAAa,kBAAkB;IAEd;IACA;IAFb,YACa,MAAc,EACd,WAAmB;QADnB,WAAM,GAAN,MAAM,CAAQ;QACd,gBAAW,GAAX,WAAW,CAAQ;IAC7B,CAAC;CACP;AALD,gDAKC;AAED;;;;;;GAMG;AACH,MAAa,WAAW;IAGP;IAEA;IACA;IALb;IACI,yEAAyE;IAChE,KAAa;IACtB,sFAAsF;IAC7E,IAAY,EACZ,SAAwC;QAHxC,UAAK,GAAL,KAAK,CAAQ;QAEb,SAAI,GAAJ,IAAI,CAAQ;QACZ,cAAS,GAAT,SAAS,CAA+B;IAClD,CAAC;CACP;AARD,kCAQC;AAED;;;;;;;GAOG;AACH,MAAa,mBAAmB;IAEf;IACA;IACA;IAHb,YACa,KAAa,EACb,YAAoB,EACpB,WAA+B;QAF/B,UAAK,GAAL,KAAK,CAAQ;QACb,iBAAY,GAAZ,YAAY,CAAQ;QACpB,gBAAW,GAAX,WAAW,CAAoB;IACzC,CAAC;CACP;AAND,kDAMC;AAED,MAAa,eAAe;IAEX;IACA;IACA;IAEA;IACA;IACA;IACA;IACA;IATb,YACa,KAAa,EACb,OAAe,EACf,OAA+B;IACxC,uFAAuF;IAC9E,eAAmC,EACnC,IAAyB,EACzB,mBAAsC,EACtC,MAA+B,EAC/B,eAA+C;QAR/C,UAAK,GAAL,KAAK,CAAQ;QACb,YAAO,GAAP,OAAO,CAAQ;QACf,YAAO,GAAP,OAAO,CAAwB;QAE/B,oBAAe,GAAf,eAAe,CAAoB;QACnC,SAAI,GAAJ,IAAI,CAAqB;QACzB,wBAAmB,GAAnB,mBAAmB,CAAmB;QACtC,WAAM,GAAN,MAAM,CAAyB;QAC/B,oBAAe,GAAf,eAAe,CAAgC;IACzD,CAAC;CACP;AAZD,0CAYC","sourcesContent":["/**\n * `openapi.manifest.json`, as CLASSES.\n *\n * ## What is allowed in here, and what is not\n *\n * The manifest carries exactly what is **not a property of the code**, and nothing else. Every field\n * below is a product decision, a deployment fact, or a NAME pointing at something the code owns:\n *\n * - `title`, `version` — product decisions.\n * - `servers[]` — a deployment fact.\n * - `descriptionFile` — a teaching decision.\n * - `apis[]` — which contracts, in the order the published sidebar shows them.\n * - `securitySchemeNames[]` — the published scheme KEYS only. Everything else about the schemes, and\n * the AND-ed `security` requirement, is DERIVED from the contract's own `@WpAuthApiKey`. A\n * `components.securitySchemes` block here would be a second copy of header names the running\n * server never reads, and nothing could contradict it.\n * - `errors` — the document-wide failure contract, with the BODY read from a real TS type so the\n * published shape cannot drift from the one on the wire.\n * - `responseHeaders[]` — declared by `nameConstant` naming an exported const, never by a literal.\n *\n * Anything a renderer could read off the source instead belongs in the source.\n *\n * ## The ORDER of `apis[]` is published navigation\n *\n * It is rendered into `tags[]` in that order, and a docs theme builds its sidebar from `tags[]`.\n * Alphabetising this array is not a cleanup; it reorders partner-facing navigation.\n */\nexport class ServerEntry {\n constructor(\n readonly url: string,\n readonly description: string | undefined,\n ) {}\n}\n\n/** One contract file the generator reads. */\nexport class ApiEntry {\n constructor(\n /** Path to the contract `.ts`, relative to the manifest's own directory. */\n readonly entry: string,\n /** The tag every operation of this contract carries — and one `tags[]` entry, in order. */\n readonly tag: string,\n /**\n * `webhook` moves the contract into the top-level `webhooks:` block: these are calls WE\n * make to a partner's server, not routes on ours.\n *\n * DECLARED, never sniffed from a `*WebhookApi` filename. A name convention would hide a\n * partner-visible decision inside a rename, and a rename is the one edit nobody reviews for\n * contract impact.\n */\n readonly kind: string | undefined,\n ) {}\n\n isWebhook(): boolean {\n return this.kind === 'webhook';\n }\n}\n\n/** One status code of the document-wide failure contract. */\nexport class ErrorResponseEntry {\n constructor(\n readonly status: string,\n readonly description: string,\n ) {}\n}\n\n/**\n * The document-wide failure contract.\n *\n * Document-wide and not per-operation on purpose: per-operation codes would be a second hand-written\n * list to keep in step with the handlers, and stating them once tells a partner the truth — any\n * operation can fail these ways.\n */\nexport class ErrorsEntry {\n constructor(\n /** The `.ts` file declaring the error body, relative to the manifest. */\n readonly entry: string,\n /** The exported TYPE name of the body. Read with the compiler, so it cannot drift. */\n readonly type: string,\n readonly responses: readonly ErrorResponseEntry[],\n ) {}\n}\n\n/**\n * One response header every operation carries.\n *\n * `nameConstant` names an exported `const` in `entry`, and the generator FOLDS it. A literal here\n * would be a copy of the header name that a rename leaves silently stale — and JSON cannot import,\n * so naming the constant is the only way for this file to point at the one the server actually\n * writes. Failing to fold it is a HARD FAILURE for the same reason.\n */\nexport class ResponseHeaderEntry {\n constructor(\n readonly entry: string,\n readonly nameConstant: string,\n readonly description: string | undefined,\n ) {}\n}\n\nexport class OpenApiManifest {\n constructor(\n readonly title: string,\n readonly version: string,\n readonly servers: readonly ServerEntry[],\n /** A markdown preamble, relative to the manifest. Rendered into `info.description`. */\n readonly descriptionFile: string | undefined,\n readonly apis: readonly ApiEntry[],\n readonly securitySchemeNames: readonly string[],\n readonly errors: ErrorsEntry | undefined,\n readonly responseHeaders: readonly ResponseHeaderEntry[],\n ) {}\n}\n"]}
1
+ {"version":3,"file":"OpenApiManifest.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/manifest/OpenApiManifest.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAa,WAAW;IAEP;IACA;IAFb,YACa,GAAW,EACX,WAA+B;QAD/B,QAAG,GAAH,GAAG,CAAQ;QACX,gBAAW,GAAX,WAAW,CAAoB;IACzC,CAAC;CACP;AALD,kCAKC;AAED,6CAA6C;AAC7C,MAAa,QAAQ;IAGJ;IAEA;IASA;IAbb;IACI,4EAA4E;IACnE,KAAa;IACtB,2FAA2F;IAClF,GAAW;IACpB;;;;;;;OAOG;IACM,IAAwB;QAXxB,UAAK,GAAL,KAAK,CAAQ;QAEb,QAAG,GAAH,GAAG,CAAQ;QASX,SAAI,GAAJ,IAAI,CAAoB;IAClC,CAAC;IAEJ,SAAS;QACL,OAAO,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC;IACnC,CAAC;CACJ;AApBD,4BAoBC;AAED,6DAA6D;AAC7D,MAAa,kBAAkB;IAEd;IACA;IAFb,YACa,MAAc,EACd,WAAmB;QADnB,WAAM,GAAN,MAAM,CAAQ;QACd,gBAAW,GAAX,WAAW,CAAQ;IAC7B,CAAC;CACP;AALD,gDAKC;AAED;;;;;;GAMG;AACH,MAAa,WAAW;IAGP;IAEA;IACA;IALb;IACI,yEAAyE;IAChE,KAAa;IACtB,sFAAsF;IAC7E,IAAY,EACZ,SAAwC;QAHxC,UAAK,GAAL,KAAK,CAAQ;QAEb,SAAI,GAAJ,IAAI,CAAQ;QACZ,cAAS,GAAT,SAAS,CAA+B;IAClD,CAAC;CACP;AARD,kCAQC;AAED;;;;;;;GAOG;AACH,MAAa,mBAAmB;IAEf;IACA;IACA;IAHb,YACa,KAAa,EACb,YAAoB,EACpB,WAA+B;QAF/B,UAAK,GAAL,KAAK,CAAQ;QACb,iBAAY,GAAZ,YAAY,CAAQ;QACpB,gBAAW,GAAX,WAAW,CAAoB;IACzC,CAAC;CACP;AAND,kDAMC;AAED,MAAa,eAAe;IAEX;IACA;IACA;IAEA;IACA;IACA;IACA;IACA;IATb,YACa,KAAa,EACb,OAAe,EACf,OAA+B;IACxC,uFAAuF;IAC9E,eAAmC,EACnC,IAAyB,EACzB,mBAAsC,EACtC,MAA+B,EAC/B,eAA+C;QAR/C,UAAK,GAAL,KAAK,CAAQ;QACb,YAAO,GAAP,OAAO,CAAQ;QACf,YAAO,GAAP,OAAO,CAAwB;QAE/B,oBAAe,GAAf,eAAe,CAAoB;QACnC,SAAI,GAAJ,IAAI,CAAqB;QACzB,wBAAmB,GAAnB,mBAAmB,CAAmB;QACtC,WAAM,GAAN,MAAM,CAAyB;QAC/B,oBAAe,GAAf,eAAe,CAAgC;IACzD,CAAC;CACP;AAZD,0CAYC;AAED;;;;;;;;GAQG;AACH,MAAa,kBAAkB;IAEd;IAEA;IAHb,YACa,KAAa;IACtB,gGAAgG;IACvF,OAA0B;QAF1B,UAAK,GAAL,KAAK,CAAQ;QAEb,YAAO,GAAP,OAAO,CAAmB;IACpC,CAAC;CACP;AAND,gDAMC","sourcesContent":["/**\n * `openapi.manifest.json`, as CLASSES.\n *\n * ## What is allowed in here, and what is not\n *\n * The manifest carries exactly what is **not a property of the code**, and nothing else. Every field\n * below is a product decision, a deployment fact, or a NAME pointing at something the code owns:\n *\n * - `title`, `version` — product decisions.\n * - `servers[]` — a deployment fact.\n * - `descriptionFile` — a teaching decision.\n * - `apis[]` — which contracts, in the order the published sidebar shows them.\n * - `securitySchemeNames[]` — the published scheme KEYS only. Everything else about the schemes, and\n * the AND-ed `security` requirement, is DERIVED from the contract's own `@WpAuthApiKey`. A\n * `components.securitySchemes` block here would be a second copy of header names the running\n * server never reads, and nothing could contradict it.\n * - `errors` — the document-wide failure contract, with the BODY read from a real TS type so the\n * published shape cannot drift from the one on the wire.\n * - `responseHeaders[]` — declared by `nameConstant` naming an exported const, never by a literal.\n *\n * Anything a renderer could read off the source instead belongs in the source.\n *\n * ## The ORDER of `apis[]` is published navigation\n *\n * It is rendered into `tags[]` in that order, and a docs theme builds its sidebar from `tags[]`.\n * Alphabetising this array is not a cleanup; it reorders partner-facing navigation.\n */\nexport class ServerEntry {\n constructor(\n readonly url: string,\n readonly description: string | undefined,\n ) {}\n}\n\n/** One contract file the generator reads. */\nexport class ApiEntry {\n constructor(\n /** Path to the contract `.ts`, relative to the manifest's own directory. */\n readonly entry: string,\n /** The tag every operation of this contract carries — and one `tags[]` entry, in order. */\n readonly tag: string,\n /**\n * `webhook` moves the contract into the top-level `webhooks:` block: these are calls WE\n * make to a partner's server, not routes on ours.\n *\n * DECLARED, never sniffed from a `*WebhookApi` filename. A name convention would hide a\n * partner-visible decision inside a rename, and a rename is the one edit nobody reviews for\n * contract impact.\n */\n readonly kind: string | undefined,\n ) {}\n\n isWebhook(): boolean {\n return this.kind === 'webhook';\n }\n}\n\n/** One status code of the document-wide failure contract. */\nexport class ErrorResponseEntry {\n constructor(\n readonly status: string,\n readonly description: string,\n ) {}\n}\n\n/**\n * The document-wide failure contract.\n *\n * Document-wide and not per-operation on purpose: per-operation codes would be a second hand-written\n * list to keep in step with the handlers, and stating them once tells a partner the truth — any\n * operation can fail these ways.\n */\nexport class ErrorsEntry {\n constructor(\n /** The `.ts` file declaring the error body, relative to the manifest. */\n readonly entry: string,\n /** The exported TYPE name of the body. Read with the compiler, so it cannot drift. */\n readonly type: string,\n readonly responses: readonly ErrorResponseEntry[],\n ) {}\n}\n\n/**\n * One response header every operation carries.\n *\n * `nameConstant` names an exported `const` in `entry`, and the generator FOLDS it. A literal here\n * would be a copy of the header name that a rename leaves silently stale — and JSON cannot import,\n * so naming the constant is the only way for this file to point at the one the server actually\n * writes. Failing to fold it is a HARD FAILURE for the same reason.\n */\nexport class ResponseHeaderEntry {\n constructor(\n readonly entry: string,\n readonly nameConstant: string,\n readonly description: string | undefined,\n ) {}\n}\n\nexport class OpenApiManifest {\n constructor(\n readonly title: string,\n readonly version: string,\n readonly servers: readonly ServerEntry[],\n /** A markdown preamble, relative to the manifest. Rendered into `info.description`. */\n readonly descriptionFile: string | undefined,\n readonly apis: readonly ApiEntry[],\n readonly securitySchemeNames: readonly string[],\n readonly errors: ErrorsEntry | undefined,\n readonly responseHeaders: readonly ResponseHeaderEntry[],\n ) {}\n}\n\n/**\n * A DTO library's `openapi.manifest.json` — `\"kind\": \"components\"` (#1058).\n *\n * It names the library's ENTRY FILES instead of contracts: the document it produces is\n * components-only — `openapi`, `info` and `components.schemas`, no paths — holding every type the\n * library exports and declares, which contract documents `$ref` instead of copying. There is no\n * `version` here: a library document's `info.version` IS the package version, read from its\n * `package.json`, so the two cannot disagree.\n */\nexport class ComponentsManifest {\n constructor(\n readonly title: string,\n /** The library's entry files (usually `src/index.ts`), relative to the manifest's directory. */\n readonly entries: readonly string[],\n ) {}\n}\n"]}