@webpieces/openapi-generator 0.4.838 → 0.4.839
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/openapi-generator",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.839",
|
|
4
4
|
"description": "Render an ApiDocModel to OpenAPI 3.1.0 — the canonical internal document and the customer-published one, JSON and YAML, from one generation pass. Ships the wp-openapi bin.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@webpieces/api-doc-model": "0.4.
|
|
27
|
-
"@webpieces/core-util": "0.4.
|
|
26
|
+
"@webpieces/api-doc-model": "0.4.839",
|
|
27
|
+
"@webpieces/core-util": "0.4.839",
|
|
28
28
|
"typescript": "5.9.3"
|
|
29
29
|
},
|
|
30
30
|
"bin": {
|
package/src/cli/OpenApiCli.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export declare class OpenApiCli {
|
|
|
26
26
|
private readonly writer;
|
|
27
27
|
/** @param argv the arguments AFTER the program name. @param cwd what relative paths resolve against. */
|
|
28
28
|
run(argv: readonly string[], cwd: string): CliResult;
|
|
29
|
+
private streamingCatalogs;
|
|
29
30
|
/**
|
|
30
31
|
* A DTO library's `components.openapi.json` (#1058). JSON is required: downstream documents `$ref`
|
|
31
32
|
* it by that file name, so a YAML-only run would publish a library nothing can reference.
|
package/src/cli/OpenApiCli.js
CHANGED
|
@@ -30,7 +30,7 @@ exports.USAGE = [
|
|
|
30
30
|
'and has an @WpMcpTool: the RUNTIME catalogs WpMcpServer boots from. They are not documents, so',
|
|
31
31
|
'--format does not apply.',
|
|
32
32
|
'',
|
|
33
|
-
|
|
33
|
+
"Those documents are SPLIT: a schema another package declares is a $ref into that package's",
|
|
34
34
|
'components.openapi.json, and generation FAILS when that package publishes none. Each one also',
|
|
35
35
|
'gets a <name>.bundled.json sibling with every schema defined locally and no external reference.',
|
|
36
36
|
'mcp-openapi and the MCP tool catalogs stay fully inlined and require no components document.',
|
|
@@ -97,9 +97,20 @@ class OpenApiCli {
|
|
|
97
97
|
const artifacts = [
|
|
98
98
|
...this.writer.artifacts(documents, this.formatOf(argv)),
|
|
99
99
|
...mcp.artifacts,
|
|
100
|
+
...this.streamingCatalogs(inputs),
|
|
100
101
|
];
|
|
101
102
|
return new CliResult(this.writer.write(path.resolve(cwd, out), artifacts), artifacts, mcp.skipped);
|
|
102
103
|
}
|
|
104
|
+
streamingCatalogs(inputs) {
|
|
105
|
+
const artifacts = [];
|
|
106
|
+
for (const contract of inputs.contracts) {
|
|
107
|
+
const catalog = new api_doc_model_1.StreamingSchemaRenderer().render(contract.model);
|
|
108
|
+
if (Object.keys(catalog.methods).length === 0)
|
|
109
|
+
continue;
|
|
110
|
+
artifacts.push(new ArtifactWriter_1.GeneratedArtifact(`stream-${catalog.contractName}-schemas.json`, JSON.stringify(catalog, null, 2) + '\n'));
|
|
111
|
+
}
|
|
112
|
+
return artifacts;
|
|
113
|
+
}
|
|
103
114
|
/**
|
|
104
115
|
* A DTO library's `components.openapi.json` (#1058). JSON is required: downstream documents `$ref`
|
|
105
116
|
* it by that file name, so a YAML-only run would publish a library nothing can reference.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenApiCli.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/cli/OpenApiCli.ts"],"names":[],"mappings":";;;;AAAA,wDAAkC;AAClC,oDAA+D;AAC/D,4DAA+F;AAC/F,2DAAyF;AACzF,mEAIsC;AACtC,mEAAgE;AAChE,uDAAoD;AACpD,sEAAmE;AAEnE,MAAM,QAAQ,GAAG,YAAY,CAAC;AAC9B,MAAM,GAAG,GAAG,OAAO,CAAC;AACpB,MAAM,M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,CAAC,EAAE,CAAC;gBACzD,MAAM,IAAI,+CAAsB,CAC5B,iBAAiB,QAAQ,GAAG,EAC5B,YAAY,EACZ,oBAAoB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAC5D,CAAC;YACN,CAAC;QACL,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AA1HD,gCA0HC","sourcesContent":["import * as path from 'node:path';\nimport { MCP, McpToolCatalogFile } from '@webpieces/core-util';\nimport { McpCatalogRender, McpSchemaRenderer, SkippedMcpTool } from '@webpieces/api-doc-model';\nimport { ArtifactWriter, GeneratedArtifact, OutputFormat } from '../emit/ArtifactWriter';\nimport {\n ContractModel,\n GeneratedDocuments,\n GenerationInputs,\n} from '../generate/GenerationInputs';\nimport { OpenApiGenerator } from '../generate/OpenApiGenerator';\nimport { InputsLoader } from '../load/InputsLoader';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\n\nconst MANIFEST = '--manifest';\nconst OUT = '--out';\nconst FORMAT = '--format';\nconst HELP = '--help';\n\nconst FLAGS = [MANIFEST, OUT, FORMAT];\nconst FORMATS: readonly string[] = ['json', 'yaml', 'both'];\n\nexport const USAGE = [\n 'wp-openapi --manifest <openapi.manifest.json> --out <dir> [--format json|yaml|both]',\n '',\n 'Renders the contracts a manifest names into OpenAPI 3.1.0. WHICH documents are written is a',\n \"property of the contracts themselves — each one's @ApiType(...) names the documents it feeds:\",\n '',\n ' full-private-openapi every contract declaring SVC_TO_SVC, hidden methods included',\n ' public-openapi contracts declaring EXTERNAL_CUSTOMER, minus every { hidden: true } method',\n ' mcp-openapi contracts declaring MCP, carrying the x-mcp-* extensions',\n '',\n 'Alongside them, one mcp-<ContractClass>-tools.json is written per contract that declares MCP',\n 'and has an @WpMcpTool: the RUNTIME catalogs WpMcpServer boots from. They are not documents, so',\n '--format does not apply.',\n '',\n 'Those documents are SPLIT: a schema another package declares is a $ref into that package\\'s',\n 'components.openapi.json, and generation FAILS when that package publishes none. Each one also',\n 'gets a <name>.bundled.json sibling with every schema defined locally and no external reference.',\n 'mcp-openapi and the MCP tool catalogs stay fully inlined and require no components document.',\n '',\n 'A manifest declaring \"kind\": \"components\" is a DTO LIBRARY\\'s: it writes components.openapi.json,',\n 'every type its \"entries\" export, versioned as the package. It needs --format json or both.',\n '',\n 'A document no contract asked for is not written. --format chooses the serialization of',\n 'whichever documents were written, and defaults to both.',\n '',\n 'It exits non-zero, naming the JSON pointer of every offending field, rather than writing a',\n 'document containing a field it has no schema for. There is no flag to switch that off.',\n].join('\\n');\n\n/** The result of one run: what was written, so a caller can print it or assert on it. */\nexport class CliResult {\n constructor(\n readonly written: readonly string[],\n readonly artifacts: readonly GeneratedArtifact[],\n /** `@WpMcpTool`s the MCP catalog could not carry, with the reason. Never silent. */\n readonly skippedMcpTools: readonly SkippedMcpTool[] = [],\n ) {}\n}\n\n/** The MCP half of one run: the per-contract catalogs to write, and what they could not carry. */\nclass McpArtifacts {\n constructor(\n readonly artifacts: readonly GeneratedArtifact[],\n readonly skipped: readonly SkippedMcpTool[],\n ) {}\n}\n\n/**\n * `wp-openapi`'s argument parsing and composition, with NO process-level concerns in it — no\n * `process.exit`, no `console` — so the whole command is exercised by the suite exactly as a user\n * runs it. The bin is the only thing that knows about the process.\n *\n * `--manifest` and `--out` are REQUIRED and have no defaults. A defaulted `--out` writes generated\n * documents somewhere the caller did not name, and a defaulted `--manifest` picks a service out of\n * whatever directory the command happened to start in.\n */\nexport class OpenApiCli {\n private readonly loader = new InputsLoader();\n private readonly generator = new OpenApiGenerator();\n private readonly writer = new ArtifactWriter();\n\n /** @param argv the arguments AFTER the program name. @param cwd what relative paths resolve against. */\n run(argv: readonly string[], cwd: string): CliResult {\n const manifest = this.valueOf(argv, MANIFEST);\n const out = this.valueOf(argv, OUT);\n if (manifest === undefined || out === undefined) {\n throw new OpenApiGenerationError(\n `wp-openapi needs both ${MANIFEST} and ${OUT}`,\n 'wp-openapi',\n `Run: wp-openapi ${MANIFEST} <openapi.manifest.json> ${OUT} <dir>`,\n );\n }\n const manifestPath = path.resolve(cwd, manifest);\n if (this.loader.isComponents(manifestPath)) {\n return this.components(manifestPath, path.resolve(cwd, out), this.formatOf(argv));\n }\n const inputs = this.loader.load(manifestPath);\n const documents = this.generator.generate(inputs);\n const mcp = OpenApiCli.mcpCatalog(inputs);\n const artifacts = [\n ...this.writer.artifacts(documents, this.formatOf(argv)),\n ...mcp.artifacts,\n ];\n return new CliResult(\n this.writer.write(path.resolve(cwd, out), artifacts),\n artifacts,\n mcp.skipped,\n );\n }\n\n /**\n * A DTO library's `components.openapi.json` (#1058). JSON is required: downstream documents `$ref`\n * it by that file name, so a YAML-only run would publish a library nothing can reference.\n */\n private components(manifestPath: string, outDir: string, format: OutputFormat): CliResult {\n if (format === 'yaml') {\n throw new OpenApiGenerationError(\n `${FORMAT} yaml writes no components.openapi.json`,\n manifestPath,\n `A components document is referenced by its .json name — use ${FORMAT} json or both.`,\n );\n }\n const inputs = this.loader.loadComponents(manifestPath);\n const document = this.generator.components(inputs);\n const artifacts = this.writer.artifacts(new GeneratedDocuments([document]), format);\n return new CliResult(this.writer.write(outDir, artifacts), artifacts);\n }\n\n wantsHelp(argv: readonly string[]): boolean {\n return argv.includes(HELP);\n }\n\n /**\n * `mcp-<ContractClass>-tools.json` — the RUNTIME artifacts, one per contract, beside the three\n * documents.\n *\n * They are not documents and are not serialized by `--format`: `WpMcpServer` boots from them, and\n * `McpToolRegistry` checks every `McpApiBinding` against the file generated from exactly that\n * contract, failing fast at boot when one is missing (#1021). That is what took the MCP runtime off\n * reflect-metadata (#984) — the schema an agent is shown and the schema the server accepts are now\n * the same bytes, rather than two derivations of one contract.\n *\n * Written only for a contract that declares `MCP` and has at least one renderable tool, which is\n * the same rule `mcp-openapi.json` follows, for the same reason: an empty file is a claim that there\n * are no tools.\n */\n // webpieces-disable no-function-outside-class -- private static composition step of this class\n private static mcpCatalog(inputs: GenerationInputs): McpArtifacts {\n const models = inputs.contracts\n .filter((contract: ContractModel) => contract.model.apiTypes.includes(MCP))\n .map((contract: ContractModel) => contract.model);\n if (models.length === 0) {\n return new McpArtifacts([], []);\n }\n const rendered: McpCatalogRender = McpSchemaRenderer.catalogOf(models);\n const artifacts = rendered.catalogs.map(\n (catalog: McpToolCatalogFile) => new GeneratedArtifact(catalog.fileName, catalog.toJsonText()),\n );\n return new McpArtifacts(artifacts, rendered.skipped);\n }\n\n /** `both` unless told otherwise: the second serialization comes free from the same document. */\n private formatOf(argv: readonly string[]): OutputFormat {\n const declared = this.valueOf(argv, FORMAT);\n if (declared === undefined) {\n return 'both';\n }\n if (!FORMATS.includes(declared)) {\n throw new OpenApiGenerationError(\n `unknown ${FORMAT} '${declared}'`,\n 'wp-openapi',\n `${FORMAT} takes one of: ${FORMATS.join(', ')}.`,\n );\n }\n return declared as OutputFormat;\n }\n\n /**\n * The value after a flag. An UNKNOWN flag is refused rather than ignored: a mistyped `--manifets`\n * would otherwise fall through to \"needs both flags\", which sends the reader looking at the wrong\n * thing.\n */\n private valueOf(argv: readonly string[], flag: string): string | undefined {\n for (let i = 0; i < argv.length; i++) {\n const argument = argv[i]!;\n if (argument === flag) {\n return argv[i + 1];\n }\n if (argument.startsWith('--') && !FLAGS.includes(argument)) {\n throw new OpenApiGenerationError(\n `unknown flag '${argument}'`,\n 'wp-openapi',\n `wp-openapi takes ${FLAGS.join(', ')}, and nothing else.`,\n );\n }\n }\n return undefined;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"OpenApiCli.js","sourceRoot":"","sources":["../../../../../../packages/docs/openapi-generator/src/cli/OpenApiCli.ts"],"names":[],"mappings":";;;;AAAA,wDAAkC;AAClC,oDAA+D;AAC/D,4DAKkC;AAClC,2DAAyF;AACzF,mEAAmG;AACnG,mEAAgE;AAChE,uDAAoD;AACpD,sEAAmE;AAEnE,MAAM,QAAQ,GAAG,YAAY,CAAC;AAC9B,MAAM,GAAG,GAAG,OAAO,CAAC;AACpB,MAAM,MAAM,GAAG,UAAU,C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,MAAM,KAAK,QAAQ,GAAG,EACjC,YAAY,EACZ,GAAG,MAAM,kBAAkB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACnD,CAAC;QACN,CAAC;QACD,OAAO,QAAwB,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACK,OAAO,CAAC,IAAuB,EAAE,IAAY;QACjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC;YAC1B,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;gBACpB,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACvB,CAAC;YACD,IAAI,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACzD,MAAM,IAAI,+CAAsB,CAC5B,iBAAiB,QAAQ,GAAG,EAC5B,YAAY,EACZ,oBAAoB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAC5D,CAAC;YACN,CAAC;QACL,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AA3ID,gCA2IC","sourcesContent":["import * as path from 'node:path';\nimport { MCP, McpToolCatalogFile } from '@webpieces/core-util';\nimport {\n McpCatalogRender,\n McpSchemaRenderer,\n SkippedMcpTool,\n StreamingSchemaRenderer,\n} from '@webpieces/api-doc-model';\nimport { ArtifactWriter, GeneratedArtifact, OutputFormat } from '../emit/ArtifactWriter';\nimport { ContractModel, GeneratedDocuments, GenerationInputs } from '../generate/GenerationInputs';\nimport { OpenApiGenerator } from '../generate/OpenApiGenerator';\nimport { InputsLoader } from '../load/InputsLoader';\nimport { OpenApiGenerationError } from '../OpenApiGenerationError';\n\nconst MANIFEST = '--manifest';\nconst OUT = '--out';\nconst FORMAT = '--format';\nconst HELP = '--help';\n\nconst FLAGS = [MANIFEST, OUT, FORMAT];\nconst FORMATS: readonly string[] = ['json', 'yaml', 'both'];\n\nexport const USAGE = [\n 'wp-openapi --manifest <openapi.manifest.json> --out <dir> [--format json|yaml|both]',\n '',\n 'Renders the contracts a manifest names into OpenAPI 3.1.0. WHICH documents are written is a',\n \"property of the contracts themselves — each one's @ApiType(...) names the documents it feeds:\",\n '',\n ' full-private-openapi every contract declaring SVC_TO_SVC, hidden methods included',\n ' public-openapi contracts declaring EXTERNAL_CUSTOMER, minus every { hidden: true } method',\n ' mcp-openapi contracts declaring MCP, carrying the x-mcp-* extensions',\n '',\n 'Alongside them, one mcp-<ContractClass>-tools.json is written per contract that declares MCP',\n 'and has an @WpMcpTool: the RUNTIME catalogs WpMcpServer boots from. They are not documents, so',\n '--format does not apply.',\n '',\n \"Those documents are SPLIT: a schema another package declares is a $ref into that package's\",\n 'components.openapi.json, and generation FAILS when that package publishes none. Each one also',\n 'gets a <name>.bundled.json sibling with every schema defined locally and no external reference.',\n 'mcp-openapi and the MCP tool catalogs stay fully inlined and require no components document.',\n '',\n 'A manifest declaring \"kind\": \"components\" is a DTO LIBRARY\\'s: it writes components.openapi.json,',\n 'every type its \"entries\" export, versioned as the package. It needs --format json or both.',\n '',\n 'A document no contract asked for is not written. --format chooses the serialization of',\n 'whichever documents were written, and defaults to both.',\n '',\n 'It exits non-zero, naming the JSON pointer of every offending field, rather than writing a',\n 'document containing a field it has no schema for. There is no flag to switch that off.',\n].join('\\n');\n\n/** The result of one run: what was written, so a caller can print it or assert on it. */\nexport class CliResult {\n constructor(\n readonly written: readonly string[],\n readonly artifacts: readonly GeneratedArtifact[],\n /** `@WpMcpTool`s the MCP catalog could not carry, with the reason. Never silent. */\n readonly skippedMcpTools: readonly SkippedMcpTool[] = [],\n ) {}\n}\n\n/** The MCP half of one run: the per-contract catalogs to write, and what they could not carry. */\nclass McpArtifacts {\n constructor(\n readonly artifacts: readonly GeneratedArtifact[],\n readonly skipped: readonly SkippedMcpTool[],\n ) {}\n}\n\n/**\n * `wp-openapi`'s argument parsing and composition, with NO process-level concerns in it — no\n * `process.exit`, no `console` — so the whole command is exercised by the suite exactly as a user\n * runs it. The bin is the only thing that knows about the process.\n *\n * `--manifest` and `--out` are REQUIRED and have no defaults. A defaulted `--out` writes generated\n * documents somewhere the caller did not name, and a defaulted `--manifest` picks a service out of\n * whatever directory the command happened to start in.\n */\nexport class OpenApiCli {\n private readonly loader = new InputsLoader();\n private readonly generator = new OpenApiGenerator();\n private readonly writer = new ArtifactWriter();\n\n /** @param argv the arguments AFTER the program name. @param cwd what relative paths resolve against. */\n run(argv: readonly string[], cwd: string): CliResult {\n const manifest = this.valueOf(argv, MANIFEST);\n const out = this.valueOf(argv, OUT);\n if (manifest === undefined || out === undefined) {\n throw new OpenApiGenerationError(\n `wp-openapi needs both ${MANIFEST} and ${OUT}`,\n 'wp-openapi',\n `Run: wp-openapi ${MANIFEST} <openapi.manifest.json> ${OUT} <dir>`,\n );\n }\n const manifestPath = path.resolve(cwd, manifest);\n if (this.loader.isComponents(manifestPath)) {\n return this.components(manifestPath, path.resolve(cwd, out), this.formatOf(argv));\n }\n const inputs = this.loader.load(manifestPath);\n const documents = this.generator.generate(inputs);\n const mcp = OpenApiCli.mcpCatalog(inputs);\n const artifacts = [\n ...this.writer.artifacts(documents, this.formatOf(argv)),\n ...mcp.artifacts,\n ...this.streamingCatalogs(inputs),\n ];\n return new CliResult(\n this.writer.write(path.resolve(cwd, out), artifacts),\n artifacts,\n mcp.skipped,\n );\n }\n\n private streamingCatalogs(inputs: GenerationInputs): readonly GeneratedArtifact[] {\n const artifacts: GeneratedArtifact[] = [];\n for (const contract of inputs.contracts) {\n const catalog = new StreamingSchemaRenderer().render(contract.model);\n if (Object.keys(catalog.methods).length === 0) continue;\n artifacts.push(\n new GeneratedArtifact(\n `stream-${catalog.contractName}-schemas.json`,\n JSON.stringify(catalog, null, 2) + '\\n',\n ),\n );\n }\n return artifacts;\n }\n\n /**\n * A DTO library's `components.openapi.json` (#1058). JSON is required: downstream documents `$ref`\n * it by that file name, so a YAML-only run would publish a library nothing can reference.\n */\n private components(manifestPath: string, outDir: string, format: OutputFormat): CliResult {\n if (format === 'yaml') {\n throw new OpenApiGenerationError(\n `${FORMAT} yaml writes no components.openapi.json`,\n manifestPath,\n `A components document is referenced by its .json name — use ${FORMAT} json or both.`,\n );\n }\n const inputs = this.loader.loadComponents(manifestPath);\n const document = this.generator.components(inputs);\n const artifacts = this.writer.artifacts(new GeneratedDocuments([document]), format);\n return new CliResult(this.writer.write(outDir, artifacts), artifacts);\n }\n\n wantsHelp(argv: readonly string[]): boolean {\n return argv.includes(HELP);\n }\n\n /**\n * `mcp-<ContractClass>-tools.json` — the RUNTIME artifacts, one per contract, beside the three\n * documents.\n *\n * They are not documents and are not serialized by `--format`: `WpMcpServer` boots from them, and\n * `McpToolRegistry` checks every `McpApiBinding` against the file generated from exactly that\n * contract, failing fast at boot when one is missing (#1021). That is what took the MCP runtime off\n * reflect-metadata (#984) — the schema an agent is shown and the schema the server accepts are now\n * the same bytes, rather than two derivations of one contract.\n *\n * Written only for a contract that declares `MCP` and has at least one renderable tool, which is\n * the same rule `mcp-openapi.json` follows, for the same reason: an empty file is a claim that there\n * are no tools.\n */\n // webpieces-disable no-function-outside-class -- private static composition step of this class\n private static mcpCatalog(inputs: GenerationInputs): McpArtifacts {\n const models = inputs.contracts\n .filter((contract: ContractModel) => contract.model.apiTypes.includes(MCP))\n .map((contract: ContractModel) => contract.model);\n if (models.length === 0) {\n return new McpArtifacts([], []);\n }\n const rendered: McpCatalogRender = McpSchemaRenderer.catalogOf(models);\n const artifacts = rendered.catalogs.map(\n (catalog: McpToolCatalogFile) =>\n new GeneratedArtifact(catalog.fileName, catalog.toJsonText()),\n );\n return new McpArtifacts(artifacts, rendered.skipped);\n }\n\n /** `both` unless told otherwise: the second serialization comes free from the same document. */\n private formatOf(argv: readonly string[]): OutputFormat {\n const declared = this.valueOf(argv, FORMAT);\n if (declared === undefined) {\n return 'both';\n }\n if (!FORMATS.includes(declared)) {\n throw new OpenApiGenerationError(\n `unknown ${FORMAT} '${declared}'`,\n 'wp-openapi',\n `${FORMAT} takes one of: ${FORMATS.join(', ')}.`,\n );\n }\n return declared as OutputFormat;\n }\n\n /**\n * The value after a flag. An UNKNOWN flag is refused rather than ignored: a mistyped `--manifets`\n * would otherwise fall through to \"needs both flags\", which sends the reader looking at the wrong\n * thing.\n */\n private valueOf(argv: readonly string[], flag: string): string | undefined {\n for (let i = 0; i < argv.length; i++) {\n const argument = argv[i]!;\n if (argument === flag) {\n return argv[i + 1];\n }\n if (argument.startsWith('--') && !FLAGS.includes(argument)) {\n throw new OpenApiGenerationError(\n `unknown flag '${argument}'`,\n 'wp-openapi',\n `wp-openapi takes ${FLAGS.join(', ')}, and nothing else.`,\n );\n }\n }\n return undefined;\n }\n}\n"]}
|