openapi-typesafe 1.0.0-rc.2 → 1.0.0-rc.3
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/dist/adapters/node-deprecations/node-deprecations.cjs +14 -0
- package/dist/adapters/node-deprecations/node-deprecations.cjs.map +1 -0
- package/dist/adapters/node-deprecations/node-deprecations.mjs +12 -0
- package/dist/adapters/node-deprecations/node-deprecations.mjs.map +1 -0
- package/dist/api/default-ports.cjs +5 -0
- package/dist/api/default-ports.cjs.map +1 -1
- package/dist/api/default-ports.mjs +5 -1
- package/dist/api/default-ports.mjs.map +1 -1
- package/dist/api/discriminator-conflict-warnings.cjs +1 -1
- package/dist/api/discriminator-conflict-warnings.cjs.map +1 -1
- package/dist/api/discriminator-conflict-warnings.mjs +2 -2
- package/dist/api/discriminator-conflict-warnings.mjs.map +1 -1
- package/dist/api/discriminator-patch.cjs +3 -3
- package/dist/api/discriminator-patch.cjs.map +1 -1
- package/dist/api/discriminator-patch.mjs +4 -4
- package/dist/api/discriminator-patch.mjs.map +1 -1
- package/dist/api/discriminator-scan.cjs +2 -2
- package/dist/api/discriminator-scan.cjs.map +1 -1
- package/dist/api/discriminator-scan.mjs +3 -3
- package/dist/api/discriminator-scan.mjs.map +1 -1
- package/dist/api/document-run.cjs +2 -1
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +2 -1
- package/dist/api/document-run.mjs.map +1 -1
- package/dist/api/legacy-callback-warning.cjs +7 -4
- package/dist/api/legacy-callback-warning.cjs.map +1 -1
- package/dist/api/legacy-callback-warning.mjs +8 -5
- package/dist/api/legacy-callback-warning.mjs.map +1 -1
- package/dist/api/openapi-ts.cjs +1 -1
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs +2 -2
- package/dist/api/openapi-ts.mjs.map +1 -1
- package/dist/api/string-to-ast.cjs +7 -9
- package/dist/api/string-to-ast.cjs.map +1 -1
- package/dist/api/string-to-ast.mjs +8 -9
- package/dist/api/string-to-ast.mjs.map +1 -1
- package/dist/api/transform-schema.cjs +2 -2
- package/dist/api/transform-schema.cjs.map +1 -1
- package/dist/api/transform-schema.mjs +3 -3
- package/dist/api/transform-schema.mjs.map +1 -1
- package/dist/application/transform/document/components.cjs +1 -1
- package/dist/application/transform/document/components.cjs.map +1 -1
- package/dist/application/transform/document/components.mjs +2 -2
- package/dist/application/transform/document/components.mjs.map +1 -1
- package/dist/application/transform/document/parameters.cjs +1 -1
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +2 -2
- package/dist/application/transform/document/parameters.mjs.map +1 -1
- package/dist/application/transform/document/paths.cjs +1 -1
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +2 -2
- package/dist/application/transform/document/paths.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.cjs +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.mjs +2 -2
- package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -1
- package/dist/application/transform/schema/access-flags.cjs +1 -1
- package/dist/application/transform/schema/access-flags.cjs.map +1 -1
- package/dist/application/transform/schema/access-flags.mjs +2 -2
- package/dist/application/transform/schema/access-flags.mjs.map +1 -1
- package/dist/application/transform/schema/array-type.cjs +2 -2
- package/dist/application/transform/schema/array-type.cjs.map +1 -1
- package/dist/application/transform/schema/array-type.mjs +3 -3
- package/dist/application/transform/schema/array-type.mjs.map +1 -1
- package/dist/application/transform/schema/composition-type.cjs +3 -3
- package/dist/application/transform/schema/composition-type.cjs.map +1 -1
- package/dist/application/transform/schema/composition-type.mjs +4 -4
- package/dist/application/transform/schema/composition-type.mjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.cjs +3 -5
- package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.mjs +4 -6
- package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
- package/dist/application/transform/schema/presence-members.cjs +1 -1
- package/dist/application/transform/schema/presence-members.cjs.map +1 -1
- package/dist/application/transform/schema/presence-members.mjs +2 -2
- package/dist/application/transform/schema/presence-members.mjs.map +1 -1
- package/dist/application/transform/schema/required-variants.cjs +2 -2
- package/dist/application/transform/schema/required-variants.cjs.map +1 -1
- package/dist/application/transform/schema/required-variants.mjs +3 -3
- package/dist/application/transform/schema/required-variants.mjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.mjs +2 -2
- package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -1
- package/dist/application/transform/schema-comment.cjs +1 -1
- package/dist/application/transform/schema-comment.cjs.map +1 -1
- package/dist/application/transform/schema-comment.mjs +2 -2
- package/dist/application/transform/schema-comment.mjs.map +1 -1
- package/dist/domain/deprecations.cjs +11 -0
- package/dist/domain/deprecations.cjs.map +1 -0
- package/dist/domain/deprecations.mjs +9 -0
- package/dist/domain/deprecations.mjs.map +1 -0
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/output-fixes.cjs +11 -14
- package/dist/domain/output-fixes.cjs.map +1 -1
- package/dist/domain/output-fixes.mjs +11 -13
- package/dist/domain/output-fixes.mjs.map +1 -1
- package/dist/domain/warnings.cjs +0 -1
- package/dist/domain/warnings.cjs.map +1 -1
- package/dist/domain/warnings.mjs +0 -1
- package/dist/domain/warnings.mjs.map +1 -1
- package/dist/index.cjs +2 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -16
- package/dist/index.d.mts +35 -16
- package/dist/index.d.ts +35 -16
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/adapters/node-deprecations/node-deprecations.ts +14 -0
- package/src/api/default-ports.ts +7 -0
- package/src/api/discriminator-conflict-warnings.ts +2 -2
- package/src/api/discriminator-patch.ts +4 -5
- package/src/api/discriminator-scan.ts +3 -3
- package/src/api/document-run.ts +5 -0
- package/src/api/legacy-callback-warning.ts +13 -6
- package/src/api/openapi-ts.ts +6 -2
- package/src/api/run-context.ts +3 -0
- package/src/api/string-to-ast.ts +11 -15
- package/src/api/transform-schema.ts +3 -3
- package/src/application/ports/deprecation-reporter.ts +9 -0
- package/src/application/transform/document/components.ts +2 -2
- package/src/application/transform/document/parameters.ts +2 -2
- package/src/application/transform/document/paths.ts +2 -2
- package/src/application/transform/ref-pointer/pointer-type.ts +2 -4
- package/src/application/transform/schema/access-flags.ts +2 -2
- package/src/application/transform/schema/array-type.ts +3 -5
- package/src/application/transform/schema/composition-type.ts +4 -4
- package/src/application/transform/schema/enum-rule.ts +4 -6
- package/src/application/transform/schema/presence-members.ts +2 -2
- package/src/application/transform/schema/required-variants.ts +3 -3
- package/src/application/transform/schema/unevaluated-properties.ts +2 -2
- package/src/application/transform/schema-comment.ts +2 -2
- package/src/domain/deprecations.ts +15 -0
- package/src/domain/errors.ts +8 -2
- package/src/domain/output-fixes.ts +16 -16
- package/src/domain/warnings.ts +0 -1
- package/src/index.ts +2 -6
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const node_util = require('node:util');
|
|
4
|
+
|
|
5
|
+
function createNodeDeprecationReporter() {
|
|
6
|
+
return {
|
|
7
|
+
report(code, message) {
|
|
8
|
+
node_util.deprecate(() => void 0, message, code)();
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.createNodeDeprecationReporter = createNodeDeprecationReporter;
|
|
14
|
+
//# sourceMappingURL=node-deprecations.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-deprecations.cjs","sources":["../../../src/adapters/node-deprecations/node-deprecations.ts"],"sourcesContent":["import { deprecate } from \"node:util\";\nimport type { DeprecationReporter } from \"../../application/ports/deprecation-reporter.js\";\n\n/**\n * Deprecations as Node.js `DeprecationWarning`s. `util.deprecate` warns once per process for each\n * code, also across wrappers, and honours `--no-deprecation` and `--throw-deprecation`.\n */\nexport function createNodeDeprecationReporter(): DeprecationReporter {\n return {\n report(code, message) {\n deprecate(() => undefined, message, code)();\n },\n };\n}\n"],"names":["deprecate"],"mappings":";;;;AAOO,SAAS,6BAAA,GAAqD;AACnE,EAAA,OAAO;AAAA,IACL,MAAA,CAAO,MAAM,OAAA,EAAS;AACpB,MAAAA,mBAAA,CAAU,MAAM,MAAA,EAAW,OAAA,EAAS,IAAI,CAAA,EAAE;AAAA,IAC5C;AAAA,GACF;AACF;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { deprecate } from 'node:util';
|
|
2
|
+
|
|
3
|
+
function createNodeDeprecationReporter() {
|
|
4
|
+
return {
|
|
5
|
+
report(code, message) {
|
|
6
|
+
deprecate(() => void 0, message, code)();
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { createNodeDeprecationReporter };
|
|
12
|
+
//# sourceMappingURL=node-deprecations.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-deprecations.mjs","sources":["../../../src/adapters/node-deprecations/node-deprecations.ts"],"sourcesContent":["import { deprecate } from \"node:util\";\nimport type { DeprecationReporter } from \"../../application/ports/deprecation-reporter.js\";\n\n/**\n * Deprecations as Node.js `DeprecationWarning`s. `util.deprecate` warns once per process for each\n * code, also across wrappers, and honours `--no-deprecation` and `--throw-deprecation`.\n */\nexport function createNodeDeprecationReporter(): DeprecationReporter {\n return {\n report(code, message) {\n deprecate(() => undefined, message, code)();\n },\n };\n}\n"],"names":[],"mappings":";;AAOO,SAAS,6BAAA,GAAqD;AACnE,EAAA,OAAO;AAAA,IACL,MAAA,CAAO,MAAM,OAAA,EAAS;AACpB,MAAA,SAAA,CAAU,MAAM,MAAA,EAAW,OAAA,EAAS,IAAI,CAAA,EAAE;AAAA,IAC5C;AAAA,GACF;AACF;;"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const node_perf_hooks = require('node:perf_hooks');
|
|
4
4
|
const openapiCore = require('@redocly/openapi-core');
|
|
5
5
|
const supportsColor = require('supports-color');
|
|
6
|
+
const nodeDeprecations = require('../adapters/node-deprecations/node-deprecations.cjs');
|
|
6
7
|
const terminalLogger = require('../adapters/terminal-logger/terminal-logger.cjs');
|
|
7
8
|
|
|
8
9
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
@@ -21,6 +22,9 @@ function defaultLogger(silent) {
|
|
|
21
22
|
sink: console
|
|
22
23
|
});
|
|
23
24
|
}
|
|
25
|
+
function defaultDeprecationReporter() {
|
|
26
|
+
return nodeDeprecations.createNodeDeprecationReporter();
|
|
27
|
+
}
|
|
24
28
|
const REMOTE_REF_TIMEOUT_MS = 6e4;
|
|
25
29
|
const DEFAULT_REMOTE_DOCUMENT_LIMITS = {
|
|
26
30
|
maxDocuments: 1e4,
|
|
@@ -39,6 +43,7 @@ function defaultRedoclyConfig() {
|
|
|
39
43
|
|
|
40
44
|
exports.DEFAULT_REMOTE_DOCUMENT_LIMITS = DEFAULT_REMOTE_DOCUMENT_LIMITS;
|
|
41
45
|
exports.REMOTE_REF_TIMEOUT_MS = REMOTE_REF_TIMEOUT_MS;
|
|
46
|
+
exports.defaultDeprecationReporter = defaultDeprecationReporter;
|
|
42
47
|
exports.defaultLogger = defaultLogger;
|
|
43
48
|
exports.defaultRedoclyConfig = defaultRedoclyConfig;
|
|
44
49
|
exports.monotonicNow = monotonicNow;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-ports.cjs","sources":["../../src/api/default-ports.ts"],"sourcesContent":["import { performance } from \"node:perf_hooks\";\nimport { createConfig, type Config as RedoclyConfig } from \"@redocly/openapi-core\";\nimport supportsColor from \"supports-color\";\nimport type { RemoteDocumentLimits } from \"../adapters/redocly-loader/remote-fetch.js\";\nimport { createTerminalLogger } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { Logger } from \"../application/ports/logger.js\";\n\n/**\n * The default adapters of the Node API (ENGINEERING_PLAN 4.5): this module and the CLI's\n * composition root are where the process environment is read.\n */\n\n/** Colors when the terminal supports them, as the original decided. */\nexport function terminalSupportsColor(): boolean {\n const stdout = supportsColor.stdout;\n return Boolean(stdout) && stdout !== false && stdout.hasBasic !== false;\n}\n\n/** The terminal logger with `DEBUG` from the environment, writing to the console. */\nexport function defaultLogger(silent: boolean): Logger {\n return createTerminalLogger({\n silent,\n debugFilter: process.env.DEBUG,\n useColors: terminalSupportsColor(),\n sink: console,\n });\n}\n\n/**\n * How long one remote `$ref` (or a remote source) may take to load. Large documents (the 27 MB\n * Cloudflare spec) download in seconds; a minute covers slow hosts, while Node's own fetch would\n * wait five minutes for a server that never answers (ENGINEERING_PLAN 8.5).\n */\nexport const REMOTE_REF_TIMEOUT_MS = 60_000;\n\n/**\n * Bounds on the remote documents of one run (ADR-033). Large split documents have a few thousand\n * files, so 10,000 leaves room and still ends an endless fan-out. 16 parallel fetches keep a\n * multi-file document fast without exhausting local ports.\n */\nexport const DEFAULT_REMOTE_DOCUMENT_LIMITS: RemoteDocumentLimits = {\n maxDocuments: 10_000,\n maxParallelFetches: 16,\n};\n\n/** The working directory of the process: the default `cwd` of an inline source. */\nexport function processCwd(): string {\n return process.cwd();\n}\n\n/** A monotonic clock in milliseconds, for debug durations. */\nexport function monotonicNow(): number {\n return performance.now();\n}\n\n/** The default Redocly config: minimal rules, and duplicate operation IDs are an error. */\nexport function defaultRedoclyConfig(): Promise<RedoclyConfig> {\n const rules = { \"operation-operationId-unique\": { severity: \"error\" as const } };\n return createConfig({ rules }, { extends: [\"minimal\"] });\n}\n"],"names":["supportsColor","createTerminalLogger","performance","createConfig"],"mappings":"
|
|
1
|
+
{"version":3,"file":"default-ports.cjs","sources":["../../src/api/default-ports.ts"],"sourcesContent":["import { performance } from \"node:perf_hooks\";\nimport { createConfig, type Config as RedoclyConfig } from \"@redocly/openapi-core\";\nimport supportsColor from \"supports-color\";\nimport { createNodeDeprecationReporter } from \"../adapters/node-deprecations/node-deprecations.js\";\nimport type { RemoteDocumentLimits } from \"../adapters/redocly-loader/remote-fetch.js\";\nimport { createTerminalLogger } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { DeprecationReporter } from \"../application/ports/deprecation-reporter.js\";\nimport type { Logger } from \"../application/ports/logger.js\";\n\n/**\n * The default adapters of the Node API (ENGINEERING_PLAN 4.5): this module and the CLI's\n * composition root are where the process environment is read.\n */\n\n/** Colors when the terminal supports them, as the original decided. */\nexport function terminalSupportsColor(): boolean {\n const stdout = supportsColor.stdout;\n return Boolean(stdout) && stdout !== false && stdout.hasBasic !== false;\n}\n\n/** The terminal logger with `DEBUG` from the environment, writing to the console. */\nexport function defaultLogger(silent: boolean): Logger {\n return createTerminalLogger({\n silent,\n debugFilter: process.env.DEBUG,\n useColors: terminalSupportsColor(),\n sink: console,\n });\n}\n\n/** Deprecations as Node.js `DeprecationWarning`s, each code once per process. */\nexport function defaultDeprecationReporter(): DeprecationReporter {\n return createNodeDeprecationReporter();\n}\n\n/**\n * How long one remote `$ref` (or a remote source) may take to load. Large documents (the 27 MB\n * Cloudflare spec) download in seconds; a minute covers slow hosts, while Node's own fetch would\n * wait five minutes for a server that never answers (ENGINEERING_PLAN 8.5).\n */\nexport const REMOTE_REF_TIMEOUT_MS = 60_000;\n\n/**\n * Bounds on the remote documents of one run (ADR-033). Large split documents have a few thousand\n * files, so 10,000 leaves room and still ends an endless fan-out. 16 parallel fetches keep a\n * multi-file document fast without exhausting local ports.\n */\nexport const DEFAULT_REMOTE_DOCUMENT_LIMITS: RemoteDocumentLimits = {\n maxDocuments: 10_000,\n maxParallelFetches: 16,\n};\n\n/** The working directory of the process: the default `cwd` of an inline source. */\nexport function processCwd(): string {\n return process.cwd();\n}\n\n/** A monotonic clock in milliseconds, for debug durations. */\nexport function monotonicNow(): number {\n return performance.now();\n}\n\n/** The default Redocly config: minimal rules, and duplicate operation IDs are an error. */\nexport function defaultRedoclyConfig(): Promise<RedoclyConfig> {\n const rules = { \"operation-operationId-unique\": { severity: \"error\" as const } };\n return createConfig({ rules }, { extends: [\"minimal\"] });\n}\n"],"names":["supportsColor","createTerminalLogger","createNodeDeprecationReporter","performance","createConfig"],"mappings":";;;;;;;;;;;;AAeO,SAAS,qBAAA,GAAiC;AAC/C,EAAA,MAAM,SAASA,sBAAA,CAAc,MAAA;AAC7B,EAAA,OAAO,QAAQ,MAAM,CAAA,IAAK,MAAA,KAAW,KAAA,IAAS,OAAO,QAAA,KAAa,KAAA;AACpE;AAGO,SAAS,cAAc,MAAA,EAAyB;AACrD,EAAA,OAAOC,mCAAA,CAAqB;AAAA,IAC1B,MAAA;AAAA,IACA,WAAA,EAAa,QAAQ,GAAA,CAAI,KAAA;AAAA,IACzB,WAAW,qBAAA,EAAsB;AAAA,IACjC,IAAA,EAAM;AAAA,GACP,CAAA;AACH;AAGO,SAAS,0BAAA,GAAkD;AAChE,EAAA,OAAOC,8CAAA,EAA8B;AACvC;AAOO,MAAM,qBAAA,GAAwB;AAO9B,MAAM,8BAAA,GAAuD;AAAA,EAClE,YAAA,EAAc,GAAA;AAAA,EACd,kBAAA,EAAoB;AACtB;AAGO,SAAS,UAAA,GAAqB;AACnC,EAAA,OAAO,QAAQ,GAAA,EAAI;AACrB;AAGO,SAAS,YAAA,GAAuB;AACrC,EAAA,OAAOC,4BAAY,GAAA,EAAI;AACzB;AAGO,SAAS,oBAAA,GAA+C;AAC7D,EAAA,MAAM,QAAQ,EAAE,8BAAA,EAAgC,EAAE,QAAA,EAAU,SAAiB,EAAE;AAC/E,EAAA,OAAOC,wBAAA,CAAa,EAAE,KAAA,EAAM,EAAG,EAAE,OAAA,EAAS,CAAC,SAAS,CAAA,EAAG,CAAA;AACzD;;;;;;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { performance } from 'node:perf_hooks';
|
|
2
2
|
import { createConfig } from '@redocly/openapi-core';
|
|
3
3
|
import supportsColor from 'supports-color';
|
|
4
|
+
import { createNodeDeprecationReporter } from '../adapters/node-deprecations/node-deprecations.mjs';
|
|
4
5
|
import { createTerminalLogger } from '../adapters/terminal-logger/terminal-logger.mjs';
|
|
5
6
|
|
|
6
7
|
function terminalSupportsColor() {
|
|
@@ -15,6 +16,9 @@ function defaultLogger(silent) {
|
|
|
15
16
|
sink: console
|
|
16
17
|
});
|
|
17
18
|
}
|
|
19
|
+
function defaultDeprecationReporter() {
|
|
20
|
+
return createNodeDeprecationReporter();
|
|
21
|
+
}
|
|
18
22
|
const REMOTE_REF_TIMEOUT_MS = 6e4;
|
|
19
23
|
const DEFAULT_REMOTE_DOCUMENT_LIMITS = {
|
|
20
24
|
maxDocuments: 1e4,
|
|
@@ -31,5 +35,5 @@ function defaultRedoclyConfig() {
|
|
|
31
35
|
return createConfig({ rules }, { extends: ["minimal"] });
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
export { DEFAULT_REMOTE_DOCUMENT_LIMITS, REMOTE_REF_TIMEOUT_MS, defaultLogger, defaultRedoclyConfig, monotonicNow, processCwd, terminalSupportsColor };
|
|
38
|
+
export { DEFAULT_REMOTE_DOCUMENT_LIMITS, REMOTE_REF_TIMEOUT_MS, defaultDeprecationReporter, defaultLogger, defaultRedoclyConfig, monotonicNow, processCwd, terminalSupportsColor };
|
|
35
39
|
//# sourceMappingURL=default-ports.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-ports.mjs","sources":["../../src/api/default-ports.ts"],"sourcesContent":["import { performance } from \"node:perf_hooks\";\nimport { createConfig, type Config as RedoclyConfig } from \"@redocly/openapi-core\";\nimport supportsColor from \"supports-color\";\nimport type { RemoteDocumentLimits } from \"../adapters/redocly-loader/remote-fetch.js\";\nimport { createTerminalLogger } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { Logger } from \"../application/ports/logger.js\";\n\n/**\n * The default adapters of the Node API (ENGINEERING_PLAN 4.5): this module and the CLI's\n * composition root are where the process environment is read.\n */\n\n/** Colors when the terminal supports them, as the original decided. */\nexport function terminalSupportsColor(): boolean {\n const stdout = supportsColor.stdout;\n return Boolean(stdout) && stdout !== false && stdout.hasBasic !== false;\n}\n\n/** The terminal logger with `DEBUG` from the environment, writing to the console. */\nexport function defaultLogger(silent: boolean): Logger {\n return createTerminalLogger({\n silent,\n debugFilter: process.env.DEBUG,\n useColors: terminalSupportsColor(),\n sink: console,\n });\n}\n\n/**\n * How long one remote `$ref` (or a remote source) may take to load. Large documents (the 27 MB\n * Cloudflare spec) download in seconds; a minute covers slow hosts, while Node's own fetch would\n * wait five minutes for a server that never answers (ENGINEERING_PLAN 8.5).\n */\nexport const REMOTE_REF_TIMEOUT_MS = 60_000;\n\n/**\n * Bounds on the remote documents of one run (ADR-033). Large split documents have a few thousand\n * files, so 10,000 leaves room and still ends an endless fan-out. 16 parallel fetches keep a\n * multi-file document fast without exhausting local ports.\n */\nexport const DEFAULT_REMOTE_DOCUMENT_LIMITS: RemoteDocumentLimits = {\n maxDocuments: 10_000,\n maxParallelFetches: 16,\n};\n\n/** The working directory of the process: the default `cwd` of an inline source. */\nexport function processCwd(): string {\n return process.cwd();\n}\n\n/** A monotonic clock in milliseconds, for debug durations. */\nexport function monotonicNow(): number {\n return performance.now();\n}\n\n/** The default Redocly config: minimal rules, and duplicate operation IDs are an error. */\nexport function defaultRedoclyConfig(): Promise<RedoclyConfig> {\n const rules = { \"operation-operationId-unique\": { severity: \"error\" as const } };\n return createConfig({ rules }, { extends: [\"minimal\"] });\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"default-ports.mjs","sources":["../../src/api/default-ports.ts"],"sourcesContent":["import { performance } from \"node:perf_hooks\";\nimport { createConfig, type Config as RedoclyConfig } from \"@redocly/openapi-core\";\nimport supportsColor from \"supports-color\";\nimport { createNodeDeprecationReporter } from \"../adapters/node-deprecations/node-deprecations.js\";\nimport type { RemoteDocumentLimits } from \"../adapters/redocly-loader/remote-fetch.js\";\nimport { createTerminalLogger } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { DeprecationReporter } from \"../application/ports/deprecation-reporter.js\";\nimport type { Logger } from \"../application/ports/logger.js\";\n\n/**\n * The default adapters of the Node API (ENGINEERING_PLAN 4.5): this module and the CLI's\n * composition root are where the process environment is read.\n */\n\n/** Colors when the terminal supports them, as the original decided. */\nexport function terminalSupportsColor(): boolean {\n const stdout = supportsColor.stdout;\n return Boolean(stdout) && stdout !== false && stdout.hasBasic !== false;\n}\n\n/** The terminal logger with `DEBUG` from the environment, writing to the console. */\nexport function defaultLogger(silent: boolean): Logger {\n return createTerminalLogger({\n silent,\n debugFilter: process.env.DEBUG,\n useColors: terminalSupportsColor(),\n sink: console,\n });\n}\n\n/** Deprecations as Node.js `DeprecationWarning`s, each code once per process. */\nexport function defaultDeprecationReporter(): DeprecationReporter {\n return createNodeDeprecationReporter();\n}\n\n/**\n * How long one remote `$ref` (or a remote source) may take to load. Large documents (the 27 MB\n * Cloudflare spec) download in seconds; a minute covers slow hosts, while Node's own fetch would\n * wait five minutes for a server that never answers (ENGINEERING_PLAN 8.5).\n */\nexport const REMOTE_REF_TIMEOUT_MS = 60_000;\n\n/**\n * Bounds on the remote documents of one run (ADR-033). Large split documents have a few thousand\n * files, so 10,000 leaves room and still ends an endless fan-out. 16 parallel fetches keep a\n * multi-file document fast without exhausting local ports.\n */\nexport const DEFAULT_REMOTE_DOCUMENT_LIMITS: RemoteDocumentLimits = {\n maxDocuments: 10_000,\n maxParallelFetches: 16,\n};\n\n/** The working directory of the process: the default `cwd` of an inline source. */\nexport function processCwd(): string {\n return process.cwd();\n}\n\n/** A monotonic clock in milliseconds, for debug durations. */\nexport function monotonicNow(): number {\n return performance.now();\n}\n\n/** The default Redocly config: minimal rules, and duplicate operation IDs are an error. */\nexport function defaultRedoclyConfig(): Promise<RedoclyConfig> {\n const rules = { \"operation-operationId-unique\": { severity: \"error\" as const } };\n return createConfig({ rules }, { extends: [\"minimal\"] });\n}\n"],"names":[],"mappings":";;;;;;AAeO,SAAS,qBAAA,GAAiC;AAC/C,EAAA,MAAM,SAAS,aAAA,CAAc,MAAA;AAC7B,EAAA,OAAO,QAAQ,MAAM,CAAA,IAAK,MAAA,KAAW,KAAA,IAAS,OAAO,QAAA,KAAa,KAAA;AACpE;AAGO,SAAS,cAAc,MAAA,EAAyB;AACrD,EAAA,OAAO,oBAAA,CAAqB;AAAA,IAC1B,MAAA;AAAA,IACA,WAAA,EAAa,QAAQ,GAAA,CAAI,KAAA;AAAA,IACzB,WAAW,qBAAA,EAAsB;AAAA,IACjC,IAAA,EAAM;AAAA,GACP,CAAA;AACH;AAGO,SAAS,0BAAA,GAAkD;AAChE,EAAA,OAAO,6BAAA,EAA8B;AACvC;AAOO,MAAM,qBAAA,GAAwB;AAO9B,MAAM,8BAAA,GAAuD;AAAA,EAClE,YAAA,EAAc,GAAA;AAAA,EACd,kBAAA,EAAoB;AACtB;AAGO,SAAS,UAAA,GAAqB;AACnC,EAAA,OAAO,QAAQ,GAAA,EAAI;AACrB;AAGO,SAAS,YAAA,GAAuB;AACrC,EAAA,OAAO,YAAY,GAAA,EAAI;AACzB;AAGO,SAAS,oBAAA,GAA+C;AAC7D,EAAA,MAAM,QAAQ,EAAE,8BAAA,EAAgC,EAAE,QAAA,EAAU,SAAiB,EAAE;AAC/E,EAAA,OAAO,YAAA,CAAa,EAAE,KAAA,EAAM,EAAG,EAAE,OAAA,EAAS,CAAC,SAAS,CAAA,EAAG,CAAA;AACzD;;"}
|
|
@@ -15,7 +15,7 @@ function warningOf(conflict) {
|
|
|
15
15
|
return `${member}: the discriminator "${propertyName}" of ${owner} gives this schema the value ${listed(values)}, which its "${propertyName}" property does not allow (${listed(allowed)}), so no value of the schema matches the discriminator. ${rule} See ${DOCS_URL}`;
|
|
16
16
|
}
|
|
17
17
|
function warnDiscriminatorValueConflicts(document, fixes, logger) {
|
|
18
|
-
const isUnionReused = fixes.includes(outputFixes.
|
|
18
|
+
const isUnionReused = fixes.includes(outputFixes.FIX.ALLOF_DISCRIMINATED_UNION);
|
|
19
19
|
for (const conflict of discriminatorConflicts.findDiscriminatorValueConflicts(document, { isUnionReused })) {
|
|
20
20
|
logger.warn(warnings.warningText(warningOf(conflict), warnings.WARNING_CODES.DISCRIMINATOR_VALUE_NOT_ALLOWED));
|
|
21
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discriminator-conflict-warnings.cjs","sources":["../../src/api/discriminator-conflict-warnings.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport {\n type DiscriminatorValueConflict,\n findDiscriminatorValueConflicts,\n} from \"../domain/openapi/discriminator-conflicts.js\";\nimport { OutputFix } from \"../domain/output-fixes.js\";\nimport { WARNING_CODES, warningText } from \"../domain/warnings.js\";\n\nconst DOCS_BASE_URL = \"https://github.com/openapi-typesafe/openapi-typesafe/blob/main/docs\";\nconst DOCS_URL = `${DOCS_BASE_URL}/advanced.md#discriminator-values`;\n\nfunction listed(values: readonly unknown[]): string {\n return values.map((value) => JSON.stringify(value)).join(\", \");\n}\n\nfunction warningOf(conflict: DiscriminatorValueConflict): string {\n const { member, owner, propertyName, values, allowed, isImplicit } = conflict;\n const rule = isImplicit\n ? \"A Discriminator Object without a mapping entry for a schema gives it its schema name as \" +\n `the value; add a mapping entry such as ${JSON.stringify(allowed[0])}: \"${member}\".`\n : \"The Discriminator Object maps these values to the schema; map the values it allows.\";\n return (\n `${member}: the discriminator \"${propertyName}\" of ${owner} gives this schema the value ` +\n `${listed(values)}, which its \"${propertyName}\" property does not allow ` +\n `(${listed(allowed)}), so no value of the schema matches the discriminator. ${rule} ` +\n `See ${DOCS_URL}`\n );\n}\n\n/**\n * Warn once per discriminator member whose value its own property does not allow. The members\n * depend on the run's fixes (`allof-discriminated-union`).\n */\nexport function warnDiscriminatorValueConflicts(\n document: unknown,\n fixes: readonly OutputFix[],\n logger: Logger,\n): void {\n const isUnionReused = fixes.includes(
|
|
1
|
+
{"version":3,"file":"discriminator-conflict-warnings.cjs","sources":["../../src/api/discriminator-conflict-warnings.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport {\n type DiscriminatorValueConflict,\n findDiscriminatorValueConflicts,\n} from \"../domain/openapi/discriminator-conflicts.js\";\nimport { FIX, type OutputFix } from \"../domain/output-fixes.js\";\nimport { WARNING_CODES, warningText } from \"../domain/warnings.js\";\n\nconst DOCS_BASE_URL = \"https://github.com/openapi-typesafe/openapi-typesafe/blob/main/docs\";\nconst DOCS_URL = `${DOCS_BASE_URL}/advanced.md#discriminator-values`;\n\nfunction listed(values: readonly unknown[]): string {\n return values.map((value) => JSON.stringify(value)).join(\", \");\n}\n\nfunction warningOf(conflict: DiscriminatorValueConflict): string {\n const { member, owner, propertyName, values, allowed, isImplicit } = conflict;\n const rule = isImplicit\n ? \"A Discriminator Object without a mapping entry for a schema gives it its schema name as \" +\n `the value; add a mapping entry such as ${JSON.stringify(allowed[0])}: \"${member}\".`\n : \"The Discriminator Object maps these values to the schema; map the values it allows.\";\n return (\n `${member}: the discriminator \"${propertyName}\" of ${owner} gives this schema the value ` +\n `${listed(values)}, which its \"${propertyName}\" property does not allow ` +\n `(${listed(allowed)}), so no value of the schema matches the discriminator. ${rule} ` +\n `See ${DOCS_URL}`\n );\n}\n\n/**\n * Warn once per discriminator member whose value its own property does not allow. The members\n * depend on the run's fixes (`allof-discriminated-union`).\n */\nexport function warnDiscriminatorValueConflicts(\n document: unknown,\n fixes: readonly OutputFix[],\n logger: Logger,\n): void {\n const isUnionReused = fixes.includes(FIX.ALLOF_DISCRIMINATED_UNION);\n for (const conflict of findDiscriminatorValueConflicts(document, { isUnionReused })) {\n logger.warn(warningText(warningOf(conflict), WARNING_CODES.DISCRIMINATOR_VALUE_NOT_ALLOWED));\n }\n}\n"],"names":["FIX","find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findDiscriminatorValueConflicts } from '../domain/openapi/discriminator-conflicts.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { FIX } from '../domain/output-fixes.mjs';
|
|
3
3
|
import { warningText, WARNING_CODES } from '../domain/warnings.mjs';
|
|
4
4
|
|
|
5
5
|
const DOCS_BASE_URL = "https://github.com/openapi-typesafe/openapi-typesafe/blob/main/docs";
|
|
@@ -13,7 +13,7 @@ function warningOf(conflict) {
|
|
|
13
13
|
return `${member}: the discriminator "${propertyName}" of ${owner} gives this schema the value ${listed(values)}, which its "${propertyName}" property does not allow (${listed(allowed)}), so no value of the schema matches the discriminator. ${rule} See ${DOCS_URL}`;
|
|
14
14
|
}
|
|
15
15
|
function warnDiscriminatorValueConflicts(document, fixes, logger) {
|
|
16
|
-
const isUnionReused = fixes.includes(
|
|
16
|
+
const isUnionReused = fixes.includes(FIX.ALLOF_DISCRIMINATED_UNION);
|
|
17
17
|
for (const conflict of findDiscriminatorValueConflicts(document, { isUnionReused })) {
|
|
18
18
|
logger.warn(warningText(warningOf(conflict), WARNING_CODES.DISCRIMINATOR_VALUE_NOT_ALLOWED));
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discriminator-conflict-warnings.mjs","sources":["../../src/api/discriminator-conflict-warnings.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport {\n type DiscriminatorValueConflict,\n findDiscriminatorValueConflicts,\n} from \"../domain/openapi/discriminator-conflicts.js\";\nimport { OutputFix } from \"../domain/output-fixes.js\";\nimport { WARNING_CODES, warningText } from \"../domain/warnings.js\";\n\nconst DOCS_BASE_URL = \"https://github.com/openapi-typesafe/openapi-typesafe/blob/main/docs\";\nconst DOCS_URL = `${DOCS_BASE_URL}/advanced.md#discriminator-values`;\n\nfunction listed(values: readonly unknown[]): string {\n return values.map((value) => JSON.stringify(value)).join(\", \");\n}\n\nfunction warningOf(conflict: DiscriminatorValueConflict): string {\n const { member, owner, propertyName, values, allowed, isImplicit } = conflict;\n const rule = isImplicit\n ? \"A Discriminator Object without a mapping entry for a schema gives it its schema name as \" +\n `the value; add a mapping entry such as ${JSON.stringify(allowed[0])}: \"${member}\".`\n : \"The Discriminator Object maps these values to the schema; map the values it allows.\";\n return (\n `${member}: the discriminator \"${propertyName}\" of ${owner} gives this schema the value ` +\n `${listed(values)}, which its \"${propertyName}\" property does not allow ` +\n `(${listed(allowed)}), so no value of the schema matches the discriminator. ${rule} ` +\n `See ${DOCS_URL}`\n );\n}\n\n/**\n * Warn once per discriminator member whose value its own property does not allow. The members\n * depend on the run's fixes (`allof-discriminated-union`).\n */\nexport function warnDiscriminatorValueConflicts(\n document: unknown,\n fixes: readonly OutputFix[],\n logger: Logger,\n): void {\n const isUnionReused = fixes.includes(
|
|
1
|
+
{"version":3,"file":"discriminator-conflict-warnings.mjs","sources":["../../src/api/discriminator-conflict-warnings.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport {\n type DiscriminatorValueConflict,\n findDiscriminatorValueConflicts,\n} from \"../domain/openapi/discriminator-conflicts.js\";\nimport { FIX, type OutputFix } from \"../domain/output-fixes.js\";\nimport { WARNING_CODES, warningText } from \"../domain/warnings.js\";\n\nconst DOCS_BASE_URL = \"https://github.com/openapi-typesafe/openapi-typesafe/blob/main/docs\";\nconst DOCS_URL = `${DOCS_BASE_URL}/advanced.md#discriminator-values`;\n\nfunction listed(values: readonly unknown[]): string {\n return values.map((value) => JSON.stringify(value)).join(\", \");\n}\n\nfunction warningOf(conflict: DiscriminatorValueConflict): string {\n const { member, owner, propertyName, values, allowed, isImplicit } = conflict;\n const rule = isImplicit\n ? \"A Discriminator Object without a mapping entry for a schema gives it its schema name as \" +\n `the value; add a mapping entry such as ${JSON.stringify(allowed[0])}: \"${member}\".`\n : \"The Discriminator Object maps these values to the schema; map the values it allows.\";\n return (\n `${member}: the discriminator \"${propertyName}\" of ${owner} gives this schema the value ` +\n `${listed(values)}, which its \"${propertyName}\" property does not allow ` +\n `(${listed(allowed)}), so no value of the schema matches the discriminator. ${rule} ` +\n `See ${DOCS_URL}`\n );\n}\n\n/**\n * Warn once per discriminator member whose value its own property does not allow. The members\n * depend on the run's fixes (`allof-discriminated-union`).\n */\nexport function warnDiscriminatorValueConflicts(\n document: unknown,\n fixes: readonly OutputFix[],\n logger: Logger,\n): void {\n const isUnionReused = fixes.includes(FIX.ALLOF_DISCRIMINATED_UNION);\n for (const conflict of findDiscriminatorValueConflicts(document, { isUnionReused })) {\n logger.warn(warningText(warningOf(conflict), WARNING_CODES.DISCRIMINATOR_VALUE_NOT_ALLOWED));\n }\n}\n"],"names":[],"mappings":";;;;AAQA,MAAM,aAAA,GAAgB,qEAAA;AACtB,MAAM,QAAA,GAAW,GAAG,aAAa,CAAA,iCAAA,CAAA;AAEjC,SAAS,OAAO,MAAA,EAAoC;AAClD,EAAA,OAAO,MAAA,CAAO,GAAA,CAAI,CAAC,KAAA,KAAU,IAAA,CAAK,UAAU,KAAK,CAAC,CAAA,CAAE,IAAA,CAAK,IAAI,CAAA;AAC/D;AAEA,SAAS,UAAU,QAAA,EAA8C;AAC/D,EAAA,MAAM,EAAE,MAAA,EAAQ,KAAA,EAAO,cAAc,MAAA,EAAQ,OAAA,EAAS,YAAW,GAAI,QAAA;AACrE,EAAA,MAAM,IAAA,GAAO,UAAA,GACT,CAAA,+HAAA,EAC0C,IAAA,CAAK,SAAA,CAAU,OAAA,CAAQ,CAAC,CAAC,CAAC,CAAA,GAAA,EAAM,MAAM,CAAA,EAAA,CAAA,GAChF,qFAAA;AACJ,EAAA,OACE,GAAG,MAAM,CAAA,qBAAA,EAAwB,YAAY,CAAA,KAAA,EAAQ,KAAK,gCACvD,MAAA,CAAO,MAAM,CAAC,CAAA,aAAA,EAAgB,YAAY,8BACzC,MAAA,CAAO,OAAO,CAAC,CAAA,wDAAA,EAA2D,IAAI,QAC3E,QAAQ,CAAA,CAAA;AAEnB;AAMO,SAAS,+BAAA,CACd,QAAA,EACA,KAAA,EACA,MAAA,EACM;AACN,EAAA,MAAM,aAAA,GAAgB,KAAA,CAAM,QAAA,CAAS,GAAA,CAAI,yBAAyB,CAAA;AAClE,EAAA,KAAA,MAAW,YAAY,+BAAA,CAAgC,QAAA,EAAU,EAAE,aAAA,EAAe,CAAA,EAAG;AACnF,IAAA,MAAA,CAAO,KAAK,WAAA,CAAY,SAAA,CAAU,QAAQ,CAAA,EAAG,aAAA,CAAc,+BAA+B,CAAC,CAAA;AAAA,EAC7F;AACF;;"}
|
|
@@ -7,17 +7,17 @@ const discriminatorEnumParent = require('./discriminator-enum-parent.cjs');
|
|
|
7
7
|
const documentRefs = require('./document-refs.cjs');
|
|
8
8
|
|
|
9
9
|
function mergesValues(state) {
|
|
10
|
-
return state.fixes.has(outputFixes.
|
|
10
|
+
return state.fixes.has(outputFixes.FIX.DISCRIMINATOR_VALUES);
|
|
11
11
|
}
|
|
12
12
|
function patchedSchema(state, patch) {
|
|
13
13
|
const { silent, logger } = state;
|
|
14
14
|
return documentRefs.resolveDocumentRef(state.schema, patch.ref, { silent, logger });
|
|
15
15
|
}
|
|
16
16
|
function isDeclared(state, patch) {
|
|
17
|
-
return state.fixes.has(outputFixes.
|
|
17
|
+
return state.fixes.has(outputFixes.FIX.DISCRIMINATOR_VALUES) && discriminatorEnum.declaresValues(patchedSchema(state, patch), patch);
|
|
18
18
|
}
|
|
19
19
|
function recordEnumParent(state, owner, key) {
|
|
20
|
-
if (!state.fixes.has(outputFixes.
|
|
20
|
+
if (!state.fixes.has(outputFixes.FIX.DISCRIMINATOR_VALUES)) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
const { silent, logger } = state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discriminator-patch.cjs","sources":["../../src/api/discriminator-patch.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport { OutputFix } from \"../domain/output-fixes.js\";\nimport { WARNING_CODES, warningText } from \"../domain/warnings.js\";\nimport type { DiscriminatorObject, OpenAPI3, SchemaObject } from \"../types.js\";\nimport { addEnumProperty, declaresValues, type EnumPatch } from \"./discriminator-enum.js\";\nimport {\n type DiscriminatorOwner,\n type EnumParent,\n enumParentOf,\n} from \"./discriminator-enum-parent.js\";\nimport { resolveDocumentRef } from \"./document-refs.js\";\n\n/**\n * The state of the discriminator pre-pass and the in-place patch of a mapped schema: the enum\n * property that the generated union narrows by. Two discriminators of one property may patch one\n * schema; how they combine is the `discriminator-values` fix (ADR-021, roadmap R12).\n */\n\n/** How to scan: the warnings, and the output fixes of the run (ADR-021). */\nexport interface DiscriminatorScanOptions {\n readonly silent: boolean;\n readonly logger: Logger;\n readonly fixes: ReadonlySet<OutputFix>;\n}\n\n/** What the two passes share: the document they patch and what they found so far. */\nexport interface ScanState extends DiscriminatorScanOptions {\n readonly schema: OpenAPI3;\n readonly objects: Record<string, DiscriminatorObject>;\n /** The schemas that define a discriminator themselves (pass 1), not by inheritance. */\n readonly owners: Set<string>;\n readonly refsHandled: string[];\n /** With the fix: the enum added to each schema, by schema and property, so values merge. */\n readonly patchedEnums: Map<string, SchemaObject>;\n /** With the fix: schema-name values, applied after both passes where no mapping names one. */\n readonly inferredPatches: EnumPatch[];\n /** With the fix: schema-name values of other properties (`inheritOtherOwners`). */\n readonly otherInferredPatches: EnumPatch[];\n /** With the fix: the other properties each schema got a value of (`inheritOtherOwners`). */\n readonly otherProperties: Record<string, string[]>;\n /** With `discriminator-values`: the enum keys that a schema declares itself. */\n readonly declaredKeys: Set<string>;\n /** With `discriminator-values`: the owner's enum of each added enum, by that enum. */\n readonly enumParents: Map<object, EnumParent>;\n}\n\n/** Whether `discriminator-values` is on: values of two discriminators merge into one enum. */\nexport function mergesValues(state: ScanState): boolean {\n return state.fixes.has(
|
|
1
|
+
{"version":3,"file":"discriminator-patch.cjs","sources":["../../src/api/discriminator-patch.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport { FIX, type OutputFix } from \"../domain/output-fixes.js\";\nimport { WARNING_CODES, warningText } from \"../domain/warnings.js\";\nimport type { DiscriminatorObject, OpenAPI3, SchemaObject } from \"../types.js\";\nimport { addEnumProperty, declaresValues, type EnumPatch } from \"./discriminator-enum.js\";\nimport {\n type DiscriminatorOwner,\n type EnumParent,\n enumParentOf,\n} from \"./discriminator-enum-parent.js\";\nimport { resolveDocumentRef } from \"./document-refs.js\";\n\n/**\n * The state of the discriminator pre-pass and the in-place patch of a mapped schema: the enum\n * property that the generated union narrows by. Two discriminators of one property may patch one\n * schema; how they combine is the `discriminator-values` fix (ADR-021, roadmap R12).\n */\n\n/** How to scan: the warnings, and the output fixes of the run (ADR-021). */\nexport interface DiscriminatorScanOptions {\n readonly silent: boolean;\n readonly logger: Logger;\n readonly fixes: ReadonlySet<OutputFix>;\n}\n\n/** What the two passes share: the document they patch and what they found so far. */\nexport interface ScanState extends DiscriminatorScanOptions {\n readonly schema: OpenAPI3;\n readonly objects: Record<string, DiscriminatorObject>;\n /** The schemas that define a discriminator themselves (pass 1), not by inheritance. */\n readonly owners: Set<string>;\n readonly refsHandled: string[];\n /** With the fix: the enum added to each schema, by schema and property, so values merge. */\n readonly patchedEnums: Map<string, SchemaObject>;\n /** With the fix: schema-name values, applied after both passes where no mapping names one. */\n readonly inferredPatches: EnumPatch[];\n /** With the fix: schema-name values of other properties (`inheritOtherOwners`). */\n readonly otherInferredPatches: EnumPatch[];\n /** With the fix: the other properties each schema got a value of (`inheritOtherOwners`). */\n readonly otherProperties: Record<string, string[]>;\n /** With `discriminator-values`: the enum keys that a schema declares itself. */\n readonly declaredKeys: Set<string>;\n /** With `discriminator-values`: the owner's enum of each added enum, by that enum. */\n readonly enumParents: Map<object, EnumParent>;\n}\n\n/** Whether `discriminator-values` is on: values of two discriminators merge into one enum. */\nexport function mergesValues(state: ScanState): boolean {\n return state.fixes.has(FIX.DISCRIMINATOR_VALUES);\n}\n\nfunction patchedSchema(state: ScanState, patch: EnumPatch): SchemaObject | undefined {\n const { silent, logger } = state;\n return resolveDocumentRef<SchemaObject>(state.schema, patch.ref, { silent, logger });\n}\n\n/**\n * With `discriminator-values`: the schema at `patch.ref` requires the property with\n * exactly these values already, so a patch would only repeat it (#2124).\n */\nfunction isDeclared(state: ScanState, patch: EnumPatch): boolean {\n return (\n state.fixes.has(FIX.DISCRIMINATOR_VALUES) && declaresValues(patchedSchema(state, patch), patch)\n );\n}\n\n/**\n * With `discriminator-values`: the enum of the owner's property, for `key`: an enum the scan\n * added, or a discriminator object that a schema inherited.\n */\nexport function recordEnumParent(state: ScanState, owner: DiscriminatorOwner, key: object): void {\n if (!state.fixes.has(FIX.DISCRIMINATOR_VALUES)) {\n return;\n }\n const { silent, logger } = state;\n const parent = enumParentOf(owner, (ref) =>\n resolveDocumentRef(state.schema, ref, { silent, logger }),\n );\n if (parent !== undefined) {\n state.enumParents.set(key, parent);\n }\n}\n\n/** The enum the schema at `patch.ref` gets, or null (with a warning) for another kind of schema. */\nfunction addDiscriminatorEnum(state: ScanState, patch: EnumPatch): SchemaObject | null {\n const added = addEnumProperty(patchedSchema(state, patch), patch);\n if (added === null) {\n warnInvalidMapping(patch, state.logger);\n } else {\n recordEnumParent(state, patch, added);\n }\n return added;\n}\n\n/** One schema and discriminator property; two discriminators of one property share an enum. */\nexport function enumKey(patch: EnumPatch): string {\n return `${patch.ref}\\n${patch.discriminator.propertyName}`;\n}\n\n/** With the fix, a second discriminator of the same property adds its values to the first enum. */\nfunction mergeIntoPatchedEnum(state: ScanState, key: string, values: readonly string[]): boolean {\n const patched = state.patchedEnums.get(key);\n if (patched === undefined) {\n return false;\n }\n const merged = patched.enum as unknown[];\n merged.push(...values.filter((value) => !merged.includes(value)));\n return true;\n}\n\n/**\n * Add or replace the discriminator enum in the schema at `patch.ref`. Returns false, with a\n * warning, when that schema is neither an `allOf` nor an object schema. Without the fix every\n * patch adds a property, so two discriminators with different values intersect to `never`.\n */\nexport function patchDiscriminatorEnum(state: ScanState, patch: EnumPatch): boolean {\n if (isDeclared(state, patch)) {\n state.declaredKeys.add(enumKey(patch));\n return true;\n }\n if (!mergesValues(state)) {\n return addDiscriminatorEnum(state, patch) !== null;\n }\n const key = enumKey(patch);\n if (mergeIntoPatchedEnum(state, key, patch.values)) {\n return true;\n }\n const added = addDiscriminatorEnum(state, patch);\n if (added !== null) {\n state.patchedEnums.set(key, added);\n }\n return added !== null;\n}\n\nexport function markHandled(state: ScanState, ref: string): void {\n if (!state.refsHandled.includes(ref)) {\n state.refsHandled.push(ref);\n }\n}\n\nfunction warnInvalidMapping(patch: EnumPatch, logger: Logger): void {\n const mapped = `${patch.ref} => ${patch.values.join(\", \")}`;\n logger.warn(\n warningText(\n \"Discriminator mapping has an invalid schema \" +\n \"(neither an object schema nor an allOf array): \" +\n `${mapped} (Discriminator: ${patch.discriminatorRef})`,\n WARNING_CODES.DISCRIMINATOR_MAPPING_INVALID,\n ),\n );\n}\n"],"names":["FIX","resolveDocumentRef","declaresValues","enumParentOf","addEnumProperty","warningText","WARNING_CODES"],"mappings":";;;;;;;;AA+CO,SAAS,aAAa,KAAA,EAA2B;AACtD,EAAA,OAAO,KAAA,CAAM,KAAA,CAAM,GAAA,CAAIA,eAAA,CAAI,oBAAoB,CAAA;AACjD;AAEA,SAAS,aAAA,CAAc,OAAkB,KAAA,EAA4C;AACnF,EAAA,MAAM,EAAE,MAAA,EAAQ,MAAA,EAAO,GAAI,KAAA;AAC3B,EAAA,OAAOC,+BAAA,CAAiC,MAAM,MAAA,EAAQ,KAAA,CAAM,KAAK,EAAE,MAAA,EAAQ,QAAQ,CAAA;AACrF;AAMA,SAAS,UAAA,CAAW,OAAkB,KAAA,EAA2B;AAC/D,EAAA,OACE,KAAA,CAAM,KAAA,CAAM,GAAA,CAAID,eAAA,CAAI,oBAAoB,CAAA,IAAKE,gCAAA,CAAe,aAAA,CAAc,KAAA,EAAO,KAAK,CAAA,EAAG,KAAK,CAAA;AAElG;AAMO,SAAS,gBAAA,CAAiB,KAAA,EAAkB,KAAA,EAA2B,GAAA,EAAmB;A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AA,CAAK,IAAI,CAAC,CAAA,CAAA;AACzD,EAAA,MAAA,CAAO,IAAA;AAAA,IACLC,oBAAA;AAAA,MACE,CAAA,2FAAA,EAEK,MAAM,CAAA,iBAAA,EAAoB,KAAA,CAAM,gBAAgB,CAAA,CAAA,CAAA;AAAA,MACrDC,sBAAA,CAAc;AAAA;AAChB,GACF;AACF;;;;;;"}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FIX } from '../domain/output-fixes.mjs';
|
|
2
2
|
import { warningText, WARNING_CODES } from '../domain/warnings.mjs';
|
|
3
3
|
import { declaresValues, addEnumProperty } from './discriminator-enum.mjs';
|
|
4
4
|
import { enumParentOf } from './discriminator-enum-parent.mjs';
|
|
5
5
|
import { resolveDocumentRef } from './document-refs.mjs';
|
|
6
6
|
|
|
7
7
|
function mergesValues(state) {
|
|
8
|
-
return state.fixes.has(
|
|
8
|
+
return state.fixes.has(FIX.DISCRIMINATOR_VALUES);
|
|
9
9
|
}
|
|
10
10
|
function patchedSchema(state, patch) {
|
|
11
11
|
const { silent, logger } = state;
|
|
12
12
|
return resolveDocumentRef(state.schema, patch.ref, { silent, logger });
|
|
13
13
|
}
|
|
14
14
|
function isDeclared(state, patch) {
|
|
15
|
-
return state.fixes.has(
|
|
15
|
+
return state.fixes.has(FIX.DISCRIMINATOR_VALUES) && declaresValues(patchedSchema(state, patch), patch);
|
|
16
16
|
}
|
|
17
17
|
function recordEnumParent(state, owner, key) {
|
|
18
|
-
if (!state.fixes.has(
|
|
18
|
+
if (!state.fixes.has(FIX.DISCRIMINATOR_VALUES)) {
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
21
|
const { silent, logger } = state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discriminator-patch.mjs","sources":["../../src/api/discriminator-patch.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport { OutputFix } from \"../domain/output-fixes.js\";\nimport { WARNING_CODES, warningText } from \"../domain/warnings.js\";\nimport type { DiscriminatorObject, OpenAPI3, SchemaObject } from \"../types.js\";\nimport { addEnumProperty, declaresValues, type EnumPatch } from \"./discriminator-enum.js\";\nimport {\n type DiscriminatorOwner,\n type EnumParent,\n enumParentOf,\n} from \"./discriminator-enum-parent.js\";\nimport { resolveDocumentRef } from \"./document-refs.js\";\n\n/**\n * The state of the discriminator pre-pass and the in-place patch of a mapped schema: the enum\n * property that the generated union narrows by. Two discriminators of one property may patch one\n * schema; how they combine is the `discriminator-values` fix (ADR-021, roadmap R12).\n */\n\n/** How to scan: the warnings, and the output fixes of the run (ADR-021). */\nexport interface DiscriminatorScanOptions {\n readonly silent: boolean;\n readonly logger: Logger;\n readonly fixes: ReadonlySet<OutputFix>;\n}\n\n/** What the two passes share: the document they patch and what they found so far. */\nexport interface ScanState extends DiscriminatorScanOptions {\n readonly schema: OpenAPI3;\n readonly objects: Record<string, DiscriminatorObject>;\n /** The schemas that define a discriminator themselves (pass 1), not by inheritance. */\n readonly owners: Set<string>;\n readonly refsHandled: string[];\n /** With the fix: the enum added to each schema, by schema and property, so values merge. */\n readonly patchedEnums: Map<string, SchemaObject>;\n /** With the fix: schema-name values, applied after both passes where no mapping names one. */\n readonly inferredPatches: EnumPatch[];\n /** With the fix: schema-name values of other properties (`inheritOtherOwners`). */\n readonly otherInferredPatches: EnumPatch[];\n /** With the fix: the other properties each schema got a value of (`inheritOtherOwners`). */\n readonly otherProperties: Record<string, string[]>;\n /** With `discriminator-values`: the enum keys that a schema declares itself. */\n readonly declaredKeys: Set<string>;\n /** With `discriminator-values`: the owner's enum of each added enum, by that enum. */\n readonly enumParents: Map<object, EnumParent>;\n}\n\n/** Whether `discriminator-values` is on: values of two discriminators merge into one enum. */\nexport function mergesValues(state: ScanState): boolean {\n return state.fixes.has(
|
|
1
|
+
{"version":3,"file":"discriminator-patch.mjs","sources":["../../src/api/discriminator-patch.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport { FIX, type OutputFix } from \"../domain/output-fixes.js\";\nimport { WARNING_CODES, warningText } from \"../domain/warnings.js\";\nimport type { DiscriminatorObject, OpenAPI3, SchemaObject } from \"../types.js\";\nimport { addEnumProperty, declaresValues, type EnumPatch } from \"./discriminator-enum.js\";\nimport {\n type DiscriminatorOwner,\n type EnumParent,\n enumParentOf,\n} from \"./discriminator-enum-parent.js\";\nimport { resolveDocumentRef } from \"./document-refs.js\";\n\n/**\n * The state of the discriminator pre-pass and the in-place patch of a mapped schema: the enum\n * property that the generated union narrows by. Two discriminators of one property may patch one\n * schema; how they combine is the `discriminator-values` fix (ADR-021, roadmap R12).\n */\n\n/** How to scan: the warnings, and the output fixes of the run (ADR-021). */\nexport interface DiscriminatorScanOptions {\n readonly silent: boolean;\n readonly logger: Logger;\n readonly fixes: ReadonlySet<OutputFix>;\n}\n\n/** What the two passes share: the document they patch and what they found so far. */\nexport interface ScanState extends DiscriminatorScanOptions {\n readonly schema: OpenAPI3;\n readonly objects: Record<string, DiscriminatorObject>;\n /** The schemas that define a discriminator themselves (pass 1), not by inheritance. */\n readonly owners: Set<string>;\n readonly refsHandled: string[];\n /** With the fix: the enum added to each schema, by schema and property, so values merge. */\n readonly patchedEnums: Map<string, SchemaObject>;\n /** With the fix: schema-name values, applied after both passes where no mapping names one. */\n readonly inferredPatches: EnumPatch[];\n /** With the fix: schema-name values of other properties (`inheritOtherOwners`). */\n readonly otherInferredPatches: EnumPatch[];\n /** With the fix: the other properties each schema got a value of (`inheritOtherOwners`). */\n readonly otherProperties: Record<string, string[]>;\n /** With `discriminator-values`: the enum keys that a schema declares itself. */\n readonly declaredKeys: Set<string>;\n /** With `discriminator-values`: the owner's enum of each added enum, by that enum. */\n readonly enumParents: Map<object, EnumParent>;\n}\n\n/** Whether `discriminator-values` is on: values of two discriminators merge into one enum. */\nexport function mergesValues(state: ScanState): boolean {\n return state.fixes.has(FIX.DISCRIMINATOR_VALUES);\n}\n\nfunction patchedSchema(state: ScanState, patch: EnumPatch): SchemaObject | undefined {\n const { silent, logger } = state;\n return resolveDocumentRef<SchemaObject>(state.schema, patch.ref, { silent, logger });\n}\n\n/**\n * With `discriminator-values`: the schema at `patch.ref` requires the property with\n * exactly these values already, so a patch would only repeat it (#2124).\n */\nfunction isDeclared(state: ScanState, patch: EnumPatch): boolean {\n return (\n state.fixes.has(FIX.DISCRIMINATOR_VALUES) && declaresValues(patchedSchema(state, patch), patch)\n );\n}\n\n/**\n * With `discriminator-values`: the enum of the owner's property, for `key`: an enum the scan\n * added, or a discriminator object that a schema inherited.\n */\nexport function recordEnumParent(state: ScanState, owner: DiscriminatorOwner, key: object): void {\n if (!state.fixes.has(FIX.DISCRIMINATOR_VALUES)) {\n return;\n }\n const { silent, logger } = state;\n const parent = enumParentOf(owner, (ref) =>\n resolveDocumentRef(state.schema, ref, { silent, logger }),\n );\n if (parent !== undefined) {\n state.enumParents.set(key, parent);\n }\n}\n\n/** The enum the schema at `patch.ref` gets, or null (with a warning) for another kind of schema. */\nfunction addDiscriminatorEnum(state: ScanState, patch: EnumPatch): SchemaObject | null {\n const added = addEnumProperty(patchedSchema(state, patch), patch);\n if (added === null) {\n warnInvalidMapping(patch, state.logger);\n } else {\n recordEnumParent(state, patch, added);\n }\n return added;\n}\n\n/** One schema and discriminator property; two discriminators of one property share an enum. */\nexport function enumKey(patch: EnumPatch): string {\n return `${patch.ref}\\n${patch.discriminator.propertyName}`;\n}\n\n/** With the fix, a second discriminator of the same property adds its values to the first enum. */\nfunction mergeIntoPatchedEnum(state: ScanState, key: string, values: readonly string[]): boolean {\n const patched = state.patchedEnums.get(key);\n if (patched === undefined) {\n return false;\n }\n const merged = patched.enum as unknown[];\n merged.push(...values.filter((value) => !merged.includes(value)));\n return true;\n}\n\n/**\n * Add or replace the discriminator enum in the schema at `patch.ref`. Returns false, with a\n * warning, when that schema is neither an `allOf` nor an object schema. Without the fix every\n * patch adds a property, so two discriminators with different values intersect to `never`.\n */\nexport function patchDiscriminatorEnum(state: ScanState, patch: EnumPatch): boolean {\n if (isDeclared(state, patch)) {\n state.declaredKeys.add(enumKey(patch));\n return true;\n }\n if (!mergesValues(state)) {\n return addDiscriminatorEnum(state, patch) !== null;\n }\n const key = enumKey(patch);\n if (mergeIntoPatchedEnum(state, key, patch.values)) {\n return true;\n }\n const added = addDiscriminatorEnum(state, patch);\n if (added !== null) {\n state.patchedEnums.set(key, added);\n }\n return added !== null;\n}\n\nexport function markHandled(state: ScanState, ref: string): void {\n if (!state.refsHandled.includes(ref)) {\n state.refsHandled.push(ref);\n }\n}\n\nfunction warnInvalidMapping(patch: EnumPatch, logger: Logger): void {\n const mapped = `${patch.ref} => ${patch.values.join(\", \")}`;\n logger.warn(\n warningText(\n \"Discriminator mapping has an invalid schema \" +\n \"(neither an object schema nor an allOf array): \" +\n `${mapped} (Discriminator: ${patch.discriminatorRef})`,\n WARNING_CODES.DISCRIMINATOR_MAPPING_INVALID,\n ),\n );\n}\n"],"names":[],"mappings":";;;;;;AA+CO,SAAS,aAAa,KAAA,EAA2B;AACtD,EAAA,OAAO,KAAA,CAAM,KAAA,CAAM,GAAA,CAAI,GAAA,CAAI,oBAAoB,CAAA;AACjD;AAEA,SAAS,aAAA,CAAc,OAAkB,KAAA,EAA4C;AACnF,EAAA,MAAM,EAAE,MAAA,EAAQ,MAAA,EAAO,GAAI,KAAA;AAC3B,EAAA,OAAO,kBAAA,CAAiC,MAAM,MAAA,EAAQ,KAAA,CAAM,KAAK,EAAE,MAAA,EAAQ,QAAQ,CAAA;AACrF;AAMA,SAAS,UAAA,CAAW,OAAkB,KAAA,EAA2B;AAC/D,EAAA,OACE,KAAA,CAAM,KAAA,CAAM,GAAA,CAAI,GAAA,CAAI,oBAAoB,CAAA,IAAK,cAAA,CAAe,aAAA,CAAc,KAAA,EAAO,KAAK,CAAA,EAAG,KAAK,CAAA;AAElG;AAMO,SAAS,gBAAA,CAAiB,KAAA,EAAkB,KAAA,EAA2B,GAAA,EAAmB;AAC/F,EAAA,IAAI,CAAC,KAAA,C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zD,EAAA,MAAA,CAAO,IAAA;AAAA,IACL,WAAA;AAAA,MACE,CAAA,2FAAA,EAEK,MAAM,CAAA,iBAAA,EAAoB,KAAA,CAAM,gBAAgB,CAAA,CAAA,CAAA;AAAA,MACrD,aAAA,CAAc;AAAA;AAChB,GACF;AACF;;"}
|
|
@@ -67,7 +67,7 @@ function valuesMappedTo(discriminator, ref) {
|
|
|
67
67
|
return Object.entries(discriminator.mapping ?? {}).filter(([, mappedRef]) => mappedRef === ref).map(([mappedValue]) => mappedValue);
|
|
68
68
|
}
|
|
69
69
|
function inheritsDiscriminator(state, parentRef, ref) {
|
|
70
|
-
if (!state.fixes.has(outputFixes.
|
|
70
|
+
if (!state.fixes.has(outputFixes.FIX.ALLOF_DISCRIMINATED_UNION)) {
|
|
71
71
|
return true;
|
|
72
72
|
}
|
|
73
73
|
const resolve = (target) => documentRefs.resolveDocumentRef(state.schema, target, state);
|
|
@@ -75,7 +75,7 @@ function inheritsDiscriminator(state, parentRef, ref) {
|
|
|
75
75
|
return union === void 0 || discriminatedUnion.isUnionMember(union, ref, resolve);
|
|
76
76
|
}
|
|
77
77
|
function recordInherited(state, ref, discriminator, ownerRef) {
|
|
78
|
-
if (state.fixes.has(outputFixes.
|
|
78
|
+
if (state.fixes.has(outputFixes.FIX.DISCRIMINATOR_VALUES) && state.owners.has(ref)) {
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
81
|
const inherited = { ...discriminator };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discriminator-scan.cjs","sources":["../../src/api/discriminator-scan.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport { isUnionMember, unionAt } from \"../domain/openapi/discriminated-union.js\";\nimport { OutputFix } from \"../domain/output-fixes.js\";\nimport type {\n DiscriminatorObject,\n GeneratorOptions,\n OpenAPI3,\n ReferenceObject,\n SchemaObject,\n} from \"../types.js\";\nimport { defaultLogger } from \"./default-ports.js\";\nimport type { EnumPatch } from \"./discriminator-enum.js\";\nimport type { EnumParent } from \"./discriminator-enum-parent.js\";\nimport { applyOtherInferredPatches, inheritOtherOwners } from \"./discriminator-other-owners.js\";\nimport {\n type DiscriminatorScanOptions,\n enumKey,\n markHandled,\n mergesValues,\n patchDiscriminatorEnum,\n recordEnumParent,\n type ScanState,\n} from \"./discriminator-patch.js\";\nimport { resolveDocumentRef, walkDocument } from \"./document-refs.js\";\nimport { createRef } from \"./legacy-utils.js\";\n\n/**\n * The inherited discriminator pre-pass. It finds every discriminator in the bundled document and\n * patches the mapped schemas in place with a required enum property, so that TypeScript can narrow\n * the generated union. The behavior and the warning text match the original `scanDiscriminators`.\n */\n\ntype DiscriminatorMapping = Record<string, { inferred?: string; defined?: string[] }>;\n\n/** The schema name at the end of each `oneOf` `$ref` is the inferred discriminator value. */\nfunction inferredMapping(oneOf: (SchemaObject | ReferenceObject)[]): DiscriminatorMapping {\n const mapping: DiscriminatorMapping = {};\n for (const item of oneOf) {\n if (!(\"$ref\" in item)) {\n continue;\n }\n const value = item.$ref.split(\"/\").pop();\n if (value) {\n mapping[item.$ref] = { ...mapping[item.$ref], inferred: value };\n }\n }\n return mapping;\n}\n\n/** Values defined in `discriminator.mapping` replace inferred ones for the same schema. */\nfunction addDefinedMapping(\n mapping: DiscriminatorMapping,\n defined: Readonly<Record<string, string>>,\n): void {\n for (const [mappedValue, mappedRef] of Object.entries(defined)) {\n if (!mappedRef) {\n continue;\n }\n if (!mapping[mappedRef]?.defined) {\n mapping[mappedRef] = { defined: [] };\n }\n mapping[mappedRef].defined?.push(mappedValue);\n }\n}\n\nfunction patchMappedSchemas(\n state: ScanState,\n mapping: DiscriminatorMapping,\n discriminator: Omit<EnumPatch, \"ref\" | \"values\">,\n): void {\n for (const [ref, { inferred, defined }] of Object.entries(mapping)) {\n const isSkipped = !mergesValues(state) && state.refsHandled.includes(ref);\n if (isSkipped || (!inferred && !defined)) {\n continue;\n }\n // A defined value wins: the schema name may not be the value the API sends.\n const values = defined ?? [inferred as string];\n if (mergesValues(state) && defined === undefined) {\n // A mapping found later, in this pass or the next, may name the schema.\n state.inferredPatches.push({ ...discriminator, ref, values });\n } else if (patchDiscriminatorEnum(state, { ...discriminator, ref, values })) {\n markHandled(state, ref);\n }\n }\n}\n\n/** Pass 1: collect every discriminator; patch the schemas of a discriminator + `oneOf`. */\nfunction collectDiscriminator(\n state: ScanState,\n value: Record<string, unknown>,\n path: (string | number)[],\n): void {\n const discriminator = value.discriminator as DiscriminatorObject | undefined;\n if (!discriminator?.propertyName) {\n return;\n }\n const discriminatorRef = createRef(path);\n state.objects[discriminatorRef] = discriminator;\n state.owners.add(discriminatorRef);\n if (!Array.isArray(value.oneOf)) {\n return;\n }\n const mapping = inferredMapping(value.oneOf);\n if (discriminator.mapping) {\n addDefinedMapping(mapping, discriminator.mapping);\n }\n patchMappedSchemas(state, mapping, { discriminator, discriminatorRef });\n}\n\n/** The mapping keys of `discriminator` that point at `ref`. */\nfunction valuesMappedTo(discriminator: DiscriminatorObject, ref: string): string[] {\n return Object.entries(discriminator.mapping ?? {})\n .filter(([, mappedRef]) => mappedRef === ref)\n .map(([mappedValue]) => mappedValue);\n}\n\n/**\n * Whether the schema at `ref` takes the discriminator of its `allOf` parent at `parentRef`. With\n * `allof-discriminated-union`, a schema that `allOf`s a discriminated union that does not contain\n * it is that union, not one of its members, so it gets no value of its own (#1464, #1690). A\n * schema that the union's mapping names is a member.\n */\nfunction inheritsDiscriminator(state: ScanState, parentRef: string, ref: string): boolean {\n if (!state.fixes.has(OutputFix.ALLOF_DISCRIMINATED_UNION)) {\n return true;\n }\n const resolve = (target: string) => resolveDocumentRef(state.schema, target, state);\n const union = unionAt(parentRef, resolve);\n return union === undefined || isUnionMember(union, ref, resolve);\n}\n\n/**\n * The schema at `ref` inherits `discriminator`. With `discriminator-values`, a schema that\n * defines a discriminator keeps it: the inherited one replaced its mapping, so the members walked\n * after this schema got their schema name instead of the mapped value (#2200). `ownerRef` is the\n * schema that declares the discriminator property, whose enum `--enum` values use (#1700).\n */\nfunction recordInherited(\n state: ScanState,\n ref: string,\n discriminator: DiscriminatorObject,\n ownerRef: string,\n): void {\n if (state.fixes.has(OutputFix.DISCRIMINATOR_VALUES) && state.owners.has(ref)) {\n return;\n }\n const inherited = { ...discriminator };\n state.objects[ref] = inherited;\n recordEnumParent(state, { discriminator, discriminatorRef: ownerRef }, inherited);\n}\n\n/**\n * An `allOf` item that is a `$ref` to a discriminator owner: the schema at `ref` inherits the\n * discriminator, and gets its enum when the parent's mapping names it. Returns false when the\n * `$ref` owns no discriminator, which ends the scan of this `allOf` (as in the original).\n */\nfunction inheritFromRef(state: ScanState, parentRef: string, ref: string): boolean {\n const discriminator = state.objects[parentRef];\n if (!discriminator) {\n return false;\n }\n const values = valuesMappedTo(discriminator, ref);\n const patch = { ref, values, discriminator, discriminatorRef: parentRef };\n if (values.length > 0 && patchDiscriminatorEnum(state, patch)) {\n markHandled(state, ref);\n }\n if (inheritsDiscriminator(state, parentRef, ref)) {\n recordInherited(state, ref, discriminator, parentRef);\n if (mergesValues(state)) {\n inheritOtherOwners(state, parentRef, ref);\n }\n }\n return true;\n}\n\n/** Pass 2: a schema whose `allOf` holds a discriminator, or a `$ref` to one, inherits it. */\nfunction inheritDiscriminators(\n state: ScanState,\n value: Record<string, unknown>,\n path: (string | number)[],\n): void {\n if (!Array.isArray(value.allOf)) {\n return;\n }\n for (const item of value.allOf as (SchemaObject | ReferenceObject)[]) {\n if (\"$ref\" in item) {\n if (!inheritFromRef(state, item.$ref, createRef(path))) {\n return;\n }\n } else if (item.discriminator?.propertyName) {\n // The inline item is typed at the schema's own location.\n recordInherited(state, createRef(path), item.discriminator, createRef(path));\n }\n }\n}\n\n/** The discriminators of a bundled document, after patching the mapped schemas in place. */\nexport interface DiscriminatorScan {\n objects: Record<string, DiscriminatorObject>;\n refsHandled: string[];\n /** With `discriminator-values`: the owner's enum of each enum the scan added. */\n enumParents: ReadonlyMap<object, EnumParent>;\n /** With `discriminator-values`: the properties of the other discriminators a schema inherits. */\n otherProperties: Readonly<Record<string, readonly string[]>>;\n}\n\n/**\n * With the fix: a schema-name value, only for a schema and property that no mapping gave a value.\n * Every enum patched so far came from a mapping, since schema-name values wait for this step.\n */\nfunction applyInferredPatches(state: ScanState): void {\n // A value that a schema declares itself came from a mapping as well.\n const mapped = new Set([...state.patchedEnums.keys(), ...state.declaredKeys]);\n for (const patch of state.inferredPatches) {\n if (!mapped.has(enumKey(patch)) && patchDiscriminatorEnum(state, patch)) {\n markHandled(state, patch.ref);\n }\n }\n applyOtherInferredPatches(state, mapped);\n}\n\n/** Find every discriminator in `schema`; warnings go to `logger` unless `silent`. */\nexport function findDiscriminators(\n schema: OpenAPI3,\n options: DiscriminatorScanOptions,\n): DiscriminatorScan {\n const state: ScanState = {\n ...options,\n schema,\n objects: {},\n owners: new Set(),\n refsHandled: [],\n patchedEnums: new Map(),\n inferredPatches: [],\n otherInferredPatches: [],\n otherProperties: {},\n declaredKeys: new Set(),\n enumParents: new Map(),\n };\n walkDocument(schema, (value, path) => collectDiscriminator(state, value, path));\n // A second pass, because an `allOf` may name a discriminator that is defined later.\n walkDocument(schema, (value, path) => inheritDiscriminators(state, value, path));\n applyInferredPatches(state);\n const { objects, refsHandled, enumParents, otherProperties } = state;\n return { objects, refsHandled, enumParents, otherProperties };\n}\n\n/**\n * Return a key–value map of discriminator objects found in a schema. Warnings go to `logger`;\n * without one, to the default terminal logger, as the original did.\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9).\n */\nexport function scanDiscriminators(\n schema: OpenAPI3,\n options: GeneratorOptions,\n logger: Logger = defaultLogger(options.silent ?? false),\n): DiscriminatorScan {\n const silent = options.silent ?? false;\n return findDiscriminators(schema, { silent, logger, fixes: new Set() });\n}\n"],"names":["mergesValues","patchDiscriminatorEnum","markHandled","createRef","OutputFix","resolveDocumentRef","unionAt","isUnionMember","recordEnumParent","inheritOtherOwners","enumKey","applyOtherInferredPatches","walkDocument","defaultLogger"],"mappings":";;;;;;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AA,EAAa,WAAA,EAAa,iBAAgB,GAAI,KAAA;AAC/D,EAAA,OAAO,EAAE,OAAA,EAAS,WAAA,EAAa,WAAA,EAAa,eAAA,EAAgB;AAC9D;AAOO,SAAS,kBAAA,CACd,QACA,OAAA,EACA,MAAA,GAAiBC,2BAAc,OAAA,CAAQ,MAAA,IAAU,KAAK,CAAA,EACnC;AACnB,EAAA,MAAM,MAAA,GAAS,QAAQ,MAAA,IAAU,KAAA;AACjC,EAAA,OAAO,kBAAA,CAAmB,QAAQ,EAAE,MAAA,EAAQ,QAAQ,KAAA,kBAAO,IAAI,GAAA,EAAI,EAAG,CAAA;AACxE;;;"}
|
|
1
|
+
{"version":3,"file":"discriminator-scan.cjs","sources":["../../src/api/discriminator-scan.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport { isUnionMember, unionAt } from \"../domain/openapi/discriminated-union.js\";\nimport { FIX } from \"../domain/output-fixes.js\";\nimport type {\n DiscriminatorObject,\n GeneratorOptions,\n OpenAPI3,\n ReferenceObject,\n SchemaObject,\n} from \"../types.js\";\nimport { defaultLogger } from \"./default-ports.js\";\nimport type { EnumPatch } from \"./discriminator-enum.js\";\nimport type { EnumParent } from \"./discriminator-enum-parent.js\";\nimport { applyOtherInferredPatches, inheritOtherOwners } from \"./discriminator-other-owners.js\";\nimport {\n type DiscriminatorScanOptions,\n enumKey,\n markHandled,\n mergesValues,\n patchDiscriminatorEnum,\n recordEnumParent,\n type ScanState,\n} from \"./discriminator-patch.js\";\nimport { resolveDocumentRef, walkDocument } from \"./document-refs.js\";\nimport { createRef } from \"./legacy-utils.js\";\n\n/**\n * The inherited discriminator pre-pass. It finds every discriminator in the bundled document and\n * patches the mapped schemas in place with a required enum property, so that TypeScript can narrow\n * the generated union. The behavior and the warning text match the original `scanDiscriminators`.\n */\n\ntype DiscriminatorMapping = Record<string, { inferred?: string; defined?: string[] }>;\n\n/** The schema name at the end of each `oneOf` `$ref` is the inferred discriminator value. */\nfunction inferredMapping(oneOf: (SchemaObject | ReferenceObject)[]): DiscriminatorMapping {\n const mapping: DiscriminatorMapping = {};\n for (const item of oneOf) {\n if (!(\"$ref\" in item)) {\n continue;\n }\n const value = item.$ref.split(\"/\").pop();\n if (value) {\n mapping[item.$ref] = { ...mapping[item.$ref], inferred: value };\n }\n }\n return mapping;\n}\n\n/** Values defined in `discriminator.mapping` replace inferred ones for the same schema. */\nfunction addDefinedMapping(\n mapping: DiscriminatorMapping,\n defined: Readonly<Record<string, string>>,\n): void {\n for (const [mappedValue, mappedRef] of Object.entries(defined)) {\n if (!mappedRef) {\n continue;\n }\n if (!mapping[mappedRef]?.defined) {\n mapping[mappedRef] = { defined: [] };\n }\n mapping[mappedRef].defined?.push(mappedValue);\n }\n}\n\nfunction patchMappedSchemas(\n state: ScanState,\n mapping: DiscriminatorMapping,\n discriminator: Omit<EnumPatch, \"ref\" | \"values\">,\n): void {\n for (const [ref, { inferred, defined }] of Object.entries(mapping)) {\n const isSkipped = !mergesValues(state) && state.refsHandled.includes(ref);\n if (isSkipped || (!inferred && !defined)) {\n continue;\n }\n // A defined value wins: the schema name may not be the value the API sends.\n const values = defined ?? [inferred as string];\n if (mergesValues(state) && defined === undefined) {\n // A mapping found later, in this pass or the next, may name the schema.\n state.inferredPatches.push({ ...discriminator, ref, values });\n } else if (patchDiscriminatorEnum(state, { ...discriminator, ref, values })) {\n markHandled(state, ref);\n }\n }\n}\n\n/** Pass 1: collect every discriminator; patch the schemas of a discriminator + `oneOf`. */\nfunction collectDiscriminator(\n state: ScanState,\n value: Record<string, unknown>,\n path: (string | number)[],\n): void {\n const discriminator = value.discriminator as DiscriminatorObject | undefined;\n if (!discriminator?.propertyName) {\n return;\n }\n const discriminatorRef = createRef(path);\n state.objects[discriminatorRef] = discriminator;\n state.owners.add(discriminatorRef);\n if (!Array.isArray(value.oneOf)) {\n return;\n }\n const mapping = inferredMapping(value.oneOf);\n if (discriminator.mapping) {\n addDefinedMapping(mapping, discriminator.mapping);\n }\n patchMappedSchemas(state, mapping, { discriminator, discriminatorRef });\n}\n\n/** The mapping keys of `discriminator` that point at `ref`. */\nfunction valuesMappedTo(discriminator: DiscriminatorObject, ref: string): string[] {\n return Object.entries(discriminator.mapping ?? {})\n .filter(([, mappedRef]) => mappedRef === ref)\n .map(([mappedValue]) => mappedValue);\n}\n\n/**\n * Whether the schema at `ref` takes the discriminator of its `allOf` parent at `parentRef`. With\n * `allof-discriminated-union`, a schema that `allOf`s a discriminated union that does not contain\n * it is that union, not one of its members, so it gets no value of its own (#1464, #1690). A\n * schema that the union's mapping names is a member.\n */\nfunction inheritsDiscriminator(state: ScanState, parentRef: string, ref: string): boolean {\n if (!state.fixes.has(FIX.ALLOF_DISCRIMINATED_UNION)) {\n return true;\n }\n const resolve = (target: string) => resolveDocumentRef(state.schema, target, state);\n const union = unionAt(parentRef, resolve);\n return union === undefined || isUnionMember(union, ref, resolve);\n}\n\n/**\n * The schema at `ref` inherits `discriminator`. With `discriminator-values`, a schema that\n * defines a discriminator keeps it: the inherited one replaced its mapping, so the members walked\n * after this schema got their schema name instead of the mapped value (#2200). `ownerRef` is the\n * schema that declares the discriminator property, whose enum `--enum` values use (#1700).\n */\nfunction recordInherited(\n state: ScanState,\n ref: string,\n discriminator: DiscriminatorObject,\n ownerRef: string,\n): void {\n if (state.fixes.has(FIX.DISCRIMINATOR_VALUES) && state.owners.has(ref)) {\n return;\n }\n const inherited = { ...discriminator };\n state.objects[ref] = inherited;\n recordEnumParent(state, { discriminator, discriminatorRef: ownerRef }, inherited);\n}\n\n/**\n * An `allOf` item that is a `$ref` to a discriminator owner: the schema at `ref` inherits the\n * discriminator, and gets its enum when the parent's mapping names it. Returns false when the\n * `$ref` owns no discriminator, which ends the scan of this `allOf` (as in the original).\n */\nfunction inheritFromRef(state: ScanState, parentRef: string, ref: string): boolean {\n const discriminator = state.objects[parentRef];\n if (!discriminator) {\n return false;\n }\n const values = valuesMappedTo(discriminator, ref);\n const patch = { ref, values, discriminator, discriminatorRef: parentRef };\n if (values.length > 0 && patchDiscriminatorEnum(state, patch)) {\n markHandled(state, ref);\n }\n if (inheritsDiscriminator(state, parentRef, ref)) {\n recordInherited(state, ref, discriminator, parentRef);\n if (mergesValues(state)) {\n inheritOtherOwners(state, parentRef, ref);\n }\n }\n return true;\n}\n\n/** Pass 2: a schema whose `allOf` holds a discriminator, or a `$ref` to one, inherits it. */\nfunction inheritDiscriminators(\n state: ScanState,\n value: Record<string, unknown>,\n path: (string | number)[],\n): void {\n if (!Array.isArray(value.allOf)) {\n return;\n }\n for (const item of value.allOf as (SchemaObject | ReferenceObject)[]) {\n if (\"$ref\" in item) {\n if (!inheritFromRef(state, item.$ref, createRef(path))) {\n return;\n }\n } else if (item.discriminator?.propertyName) {\n // The inline item is typed at the schema's own location.\n recordInherited(state, createRef(path), item.discriminator, createRef(path));\n }\n }\n}\n\n/** The discriminators of a bundled document, after patching the mapped schemas in place. */\nexport interface DiscriminatorScan {\n objects: Record<string, DiscriminatorObject>;\n refsHandled: string[];\n /** With `discriminator-values`: the owner's enum of each enum the scan added. */\n enumParents: ReadonlyMap<object, EnumParent>;\n /** With `discriminator-values`: the properties of the other discriminators a schema inherits. */\n otherProperties: Readonly<Record<string, readonly string[]>>;\n}\n\n/**\n * With the fix: a schema-name value, only for a schema and property that no mapping gave a value.\n * Every enum patched so far came from a mapping, since schema-name values wait for this step.\n */\nfunction applyInferredPatches(state: ScanState): void {\n // A value that a schema declares itself came from a mapping as well.\n const mapped = new Set([...state.patchedEnums.keys(), ...state.declaredKeys]);\n for (const patch of state.inferredPatches) {\n if (!mapped.has(enumKey(patch)) && patchDiscriminatorEnum(state, patch)) {\n markHandled(state, patch.ref);\n }\n }\n applyOtherInferredPatches(state, mapped);\n}\n\n/** Find every discriminator in `schema`; warnings go to `logger` unless `silent`. */\nexport function findDiscriminators(\n schema: OpenAPI3,\n options: DiscriminatorScanOptions,\n): DiscriminatorScan {\n const state: ScanState = {\n ...options,\n schema,\n objects: {},\n owners: new Set(),\n refsHandled: [],\n patchedEnums: new Map(),\n inferredPatches: [],\n otherInferredPatches: [],\n otherProperties: {},\n declaredKeys: new Set(),\n enumParents: new Map(),\n };\n walkDocument(schema, (value, path) => collectDiscriminator(state, value, path));\n // A second pass, because an `allOf` may name a discriminator that is defined later.\n walkDocument(schema, (value, path) => inheritDiscriminators(state, value, path));\n applyInferredPatches(state);\n const { objects, refsHandled, enumParents, otherProperties } = state;\n return { objects, refsHandled, enumParents, otherProperties };\n}\n\n/**\n * Return a key–value map of discriminator objects found in a schema. Warnings go to `logger`;\n * without one, to the default terminal logger, as the original did.\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9).\n */\nexport function scanDiscriminators(\n schema: OpenAPI3,\n options: GeneratorOptions,\n logger: Logger = defaultLogger(options.silent ?? false),\n): DiscriminatorScan {\n const silent = options.silent ?? false;\n return findDiscriminators(schema, { silent, logger, fixes: new Set() });\n}\n"],"names":["mergesValues","patchDiscriminatorEnum","markHandled","createRef","FIX","resolveDocumentRef","unionAt","isUnionMember","recordEnumParent","inheritOtherOwners","enumKey","applyOtherInferredPatches","walkDocument","defaultLogger"],"mappings":";;;;;;;;;;AAmCA,SAAS,gBAAgB,KAAA,EAAiE;AACxF,EAAA,MAAM,UAAgC,EAAC;AACvC,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,IAAI,EAAE,UAAU,IAAA,CAAA,EAAO;AACrB,MAAA;AAAA,IACF;AACA,IAAA,MAAM,QAAQ,IAAA,CAAK,IAAA,CAAK,KAAA,CAAM,GAAG,EAAE,GAAA,EAAI;AACvC,IAAA,IAAI,KAAA,EAAO;AACT,MAAA,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAA,GAAI,EAAE,GAAG,QAAQ,IAAA,CAAK,IAAI,CAAA,EAAG,QAAA,EAAU,KAAA,EAAM;AAAA,IAChE;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAGA,SAAS,iBAAA,CACP,SACA,OAAA,EACM;AAC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'../domain/output-fixes.mjs';
|
|
3
3
|
import { defaultLogger } from './default-ports.mjs';
|
|
4
4
|
import { applyOtherInferredPatches, inheritOtherOwners } from './discriminator-other-owners.mjs';
|
|
5
5
|
import { enumKey, patchDiscriminatorEnum, markHandled, mergesValues, recordEnumParent } from './discriminator-patch.mjs';
|
|
@@ -65,7 +65,7 @@ function valuesMappedTo(discriminator, ref) {
|
|
|
65
65
|
return Object.entries(discriminator.mapping ?? {}).filter(([, mappedRef]) => mappedRef === ref).map(([mappedValue]) => mappedValue);
|
|
66
66
|
}
|
|
67
67
|
function inheritsDiscriminator(state, parentRef, ref) {
|
|
68
|
-
if (!state.fixes.has(
|
|
68
|
+
if (!state.fixes.has(FIX.ALLOF_DISCRIMINATED_UNION)) {
|
|
69
69
|
return true;
|
|
70
70
|
}
|
|
71
71
|
const resolve = (target) => resolveDocumentRef(state.schema, target, state);
|
|
@@ -73,7 +73,7 @@ function inheritsDiscriminator(state, parentRef, ref) {
|
|
|
73
73
|
return union === void 0 || isUnionMember(union, ref, resolve);
|
|
74
74
|
}
|
|
75
75
|
function recordInherited(state, ref, discriminator, ownerRef) {
|
|
76
|
-
if (state.fixes.has(
|
|
76
|
+
if (state.fixes.has(FIX.DISCRIMINATOR_VALUES) && state.owners.has(ref)) {
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
79
|
const inherited = { ...discriminator };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discriminator-scan.mjs","sources":["../../src/api/discriminator-scan.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport { isUnionMember, unionAt } from \"../domain/openapi/discriminated-union.js\";\nimport { OutputFix } from \"../domain/output-fixes.js\";\nimport type {\n DiscriminatorObject,\n GeneratorOptions,\n OpenAPI3,\n ReferenceObject,\n SchemaObject,\n} from \"../types.js\";\nimport { defaultLogger } from \"./default-ports.js\";\nimport type { EnumPatch } from \"./discriminator-enum.js\";\nimport type { EnumParent } from \"./discriminator-enum-parent.js\";\nimport { applyOtherInferredPatches, inheritOtherOwners } from \"./discriminator-other-owners.js\";\nimport {\n type DiscriminatorScanOptions,\n enumKey,\n markHandled,\n mergesValues,\n patchDiscriminatorEnum,\n recordEnumParent,\n type ScanState,\n} from \"./discriminator-patch.js\";\nimport { resolveDocumentRef, walkDocument } from \"./document-refs.js\";\nimport { createRef } from \"./legacy-utils.js\";\n\n/**\n * The inherited discriminator pre-pass. It finds every discriminator in the bundled document and\n * patches the mapped schemas in place with a required enum property, so that TypeScript can narrow\n * the generated union. The behavior and the warning text match the original `scanDiscriminators`.\n */\n\ntype DiscriminatorMapping = Record<string, { inferred?: string; defined?: string[] }>;\n\n/** The schema name at the end of each `oneOf` `$ref` is the inferred discriminator value. */\nfunction inferredMapping(oneOf: (SchemaObject | ReferenceObject)[]): DiscriminatorMapping {\n const mapping: DiscriminatorMapping = {};\n for (const item of oneOf) {\n if (!(\"$ref\" in item)) {\n continue;\n }\n const value = item.$ref.split(\"/\").pop();\n if (value) {\n mapping[item.$ref] = { ...mapping[item.$ref], inferred: value };\n }\n }\n return mapping;\n}\n\n/** Values defined in `discriminator.mapping` replace inferred ones for the same schema. */\nfunction addDefinedMapping(\n mapping: DiscriminatorMapping,\n defined: Readonly<Record<string, string>>,\n): void {\n for (const [mappedValue, mappedRef] of Object.entries(defined)) {\n if (!mappedRef) {\n continue;\n }\n if (!mapping[mappedRef]?.defined) {\n mapping[mappedRef] = { defined: [] };\n }\n mapping[mappedRef].defined?.push(mappedValue);\n }\n}\n\nfunction patchMappedSchemas(\n state: ScanState,\n mapping: DiscriminatorMapping,\n discriminator: Omit<EnumPatch, \"ref\" | \"values\">,\n): void {\n for (const [ref, { inferred, defined }] of Object.entries(mapping)) {\n const isSkipped = !mergesValues(state) && state.refsHandled.includes(ref);\n if (isSkipped || (!inferred && !defined)) {\n continue;\n }\n // A defined value wins: the schema name may not be the value the API sends.\n const values = defined ?? [inferred as string];\n if (mergesValues(state) && defined === undefined) {\n // A mapping found later, in this pass or the next, may name the schema.\n state.inferredPatches.push({ ...discriminator, ref, values });\n } else if (patchDiscriminatorEnum(state, { ...discriminator, ref, values })) {\n markHandled(state, ref);\n }\n }\n}\n\n/** Pass 1: collect every discriminator; patch the schemas of a discriminator + `oneOf`. */\nfunction collectDiscriminator(\n state: ScanState,\n value: Record<string, unknown>,\n path: (string | number)[],\n): void {\n const discriminator = value.discriminator as DiscriminatorObject | undefined;\n if (!discriminator?.propertyName) {\n return;\n }\n const discriminatorRef = createRef(path);\n state.objects[discriminatorRef] = discriminator;\n state.owners.add(discriminatorRef);\n if (!Array.isArray(value.oneOf)) {\n return;\n }\n const mapping = inferredMapping(value.oneOf);\n if (discriminator.mapping) {\n addDefinedMapping(mapping, discriminator.mapping);\n }\n patchMappedSchemas(state, mapping, { discriminator, discriminatorRef });\n}\n\n/** The mapping keys of `discriminator` that point at `ref`. */\nfunction valuesMappedTo(discriminator: DiscriminatorObject, ref: string): string[] {\n return Object.entries(discriminator.mapping ?? {})\n .filter(([, mappedRef]) => mappedRef === ref)\n .map(([mappedValue]) => mappedValue);\n}\n\n/**\n * Whether the schema at `ref` takes the discriminator of its `allOf` parent at `parentRef`. With\n * `allof-discriminated-union`, a schema that `allOf`s a discriminated union that does not contain\n * it is that union, not one of its members, so it gets no value of its own (#1464, #1690). A\n * schema that the union's mapping names is a member.\n */\nfunction inheritsDiscriminator(state: ScanState, parentRef: string, ref: string): boolean {\n if (!state.fixes.has(OutputFix.ALLOF_DISCRIMINATED_UNION)) {\n return true;\n }\n const resolve = (target: string) => resolveDocumentRef(state.schema, target, state);\n const union = unionAt(parentRef, resolve);\n return union === undefined || isUnionMember(union, ref, resolve);\n}\n\n/**\n * The schema at `ref` inherits `discriminator`. With `discriminator-values`, a schema that\n * defines a discriminator keeps it: the inherited one replaced its mapping, so the members walked\n * after this schema got their schema name instead of the mapped value (#2200). `ownerRef` is the\n * schema that declares the discriminator property, whose enum `--enum` values use (#1700).\n */\nfunction recordInherited(\n state: ScanState,\n ref: string,\n discriminator: DiscriminatorObject,\n ownerRef: string,\n): void {\n if (state.fixes.has(OutputFix.DISCRIMINATOR_VALUES) && state.owners.has(ref)) {\n return;\n }\n const inherited = { ...discriminator };\n state.objects[ref] = inherited;\n recordEnumParent(state, { discriminator, discriminatorRef: ownerRef }, inherited);\n}\n\n/**\n * An `allOf` item that is a `$ref` to a discriminator owner: the schema at `ref` inherits the\n * discriminator, and gets its enum when the parent's mapping names it. Returns false when the\n * `$ref` owns no discriminator, which ends the scan of this `allOf` (as in the original).\n */\nfunction inheritFromRef(state: ScanState, parentRef: string, ref: string): boolean {\n const discriminator = state.objects[parentRef];\n if (!discriminator) {\n return false;\n }\n const values = valuesMappedTo(discriminator, ref);\n const patch = { ref, values, discriminator, discriminatorRef: parentRef };\n if (values.length > 0 && patchDiscriminatorEnum(state, patch)) {\n markHandled(state, ref);\n }\n if (inheritsDiscriminator(state, parentRef, ref)) {\n recordInherited(state, ref, discriminator, parentRef);\n if (mergesValues(state)) {\n inheritOtherOwners(state, parentRef, ref);\n }\n }\n return true;\n}\n\n/** Pass 2: a schema whose `allOf` holds a discriminator, or a `$ref` to one, inherits it. */\nfunction inheritDiscriminators(\n state: ScanState,\n value: Record<string, unknown>,\n path: (string | number)[],\n): void {\n if (!Array.isArray(value.allOf)) {\n return;\n }\n for (const item of value.allOf as (SchemaObject | ReferenceObject)[]) {\n if (\"$ref\" in item) {\n if (!inheritFromRef(state, item.$ref, createRef(path))) {\n return;\n }\n } else if (item.discriminator?.propertyName) {\n // The inline item is typed at the schema's own location.\n recordInherited(state, createRef(path), item.discriminator, createRef(path));\n }\n }\n}\n\n/** The discriminators of a bundled document, after patching the mapped schemas in place. */\nexport interface DiscriminatorScan {\n objects: Record<string, DiscriminatorObject>;\n refsHandled: string[];\n /** With `discriminator-values`: the owner's enum of each enum the scan added. */\n enumParents: ReadonlyMap<object, EnumParent>;\n /** With `discriminator-values`: the properties of the other discriminators a schema inherits. */\n otherProperties: Readonly<Record<string, readonly string[]>>;\n}\n\n/**\n * With the fix: a schema-name value, only for a schema and property that no mapping gave a value.\n * Every enum patched so far came from a mapping, since schema-name values wait for this step.\n */\nfunction applyInferredPatches(state: ScanState): void {\n // A value that a schema declares itself came from a mapping as well.\n const mapped = new Set([...state.patchedEnums.keys(), ...state.declaredKeys]);\n for (const patch of state.inferredPatches) {\n if (!mapped.has(enumKey(patch)) && patchDiscriminatorEnum(state, patch)) {\n markHandled(state, patch.ref);\n }\n }\n applyOtherInferredPatches(state, mapped);\n}\n\n/** Find every discriminator in `schema`; warnings go to `logger` unless `silent`. */\nexport function findDiscriminators(\n schema: OpenAPI3,\n options: DiscriminatorScanOptions,\n): DiscriminatorScan {\n const state: ScanState = {\n ...options,\n schema,\n objects: {},\n owners: new Set(),\n refsHandled: [],\n patchedEnums: new Map(),\n inferredPatches: [],\n otherInferredPatches: [],\n otherProperties: {},\n declaredKeys: new Set(),\n enumParents: new Map(),\n };\n walkDocument(schema, (value, path) => collectDiscriminator(state, value, path));\n // A second pass, because an `allOf` may name a discriminator that is defined later.\n walkDocument(schema, (value, path) => inheritDiscriminators(state, value, path));\n applyInferredPatches(state);\n const { objects, refsHandled, enumParents, otherProperties } = state;\n return { objects, refsHandled, enumParents, otherProperties };\n}\n\n/**\n * Return a key–value map of discriminator objects found in a schema. Warnings go to `logger`;\n * without one, to the default terminal logger, as the original did.\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9).\n */\nexport function scanDiscriminators(\n schema: OpenAPI3,\n options: GeneratorOptions,\n logger: Logger = defaultLogger(options.silent ?? false),\n): DiscriminatorScan {\n const silent = options.silent ?? false;\n return findDiscriminators(schema, { silent, logger, fixes: new Set() });\n}\n"],"names":[],"mappings":";;;;;;;;AAmCA,SAAS,gBAAgB,KAAA,EAAiE;AACxF,EAAA,MAAM,UAAgC,EAAC;AACvC,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,IAAI,EAAE,UAAU,IAAA,CAAA,EAAO;AACrB,M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AA,EACnC;AACnB,EAAA,MAAM,MAAA,GAAS,QAAQ,MAAA,IAAU,KAAA;AACjC,EAAA,OAAO,kBAAA,CAAmB,QAAQ,EAAE,MAAA,EAAQ,QAAQ,KAAA,kBAAO,IAAI,GAAA,EAAI,EAAG,CAAA;AACxE;;"}
|
|
1
|
+
{"version":3,"file":"discriminator-scan.mjs","sources":["../../src/api/discriminator-scan.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport { isUnionMember, unionAt } from \"../domain/openapi/discriminated-union.js\";\nimport { FIX } from \"../domain/output-fixes.js\";\nimport type {\n DiscriminatorObject,\n GeneratorOptions,\n OpenAPI3,\n ReferenceObject,\n SchemaObject,\n} from \"../types.js\";\nimport { defaultLogger } from \"./default-ports.js\";\nimport type { EnumPatch } from \"./discriminator-enum.js\";\nimport type { EnumParent } from \"./discriminator-enum-parent.js\";\nimport { applyOtherInferredPatches, inheritOtherOwners } from \"./discriminator-other-owners.js\";\nimport {\n type DiscriminatorScanOptions,\n enumKey,\n markHandled,\n mergesValues,\n patchDiscriminatorEnum,\n recordEnumParent,\n type ScanState,\n} from \"./discriminator-patch.js\";\nimport { resolveDocumentRef, walkDocument } from \"./document-refs.js\";\nimport { createRef } from \"./legacy-utils.js\";\n\n/**\n * The inherited discriminator pre-pass. It finds every discriminator in the bundled document and\n * patches the mapped schemas in place with a required enum property, so that TypeScript can narrow\n * the generated union. The behavior and the warning text match the original `scanDiscriminators`.\n */\n\ntype DiscriminatorMapping = Record<string, { inferred?: string; defined?: string[] }>;\n\n/** The schema name at the end of each `oneOf` `$ref` is the inferred discriminator value. */\nfunction inferredMapping(oneOf: (SchemaObject | ReferenceObject)[]): DiscriminatorMapping {\n const mapping: DiscriminatorMapping = {};\n for (const item of oneOf) {\n if (!(\"$ref\" in item)) {\n continue;\n }\n const value = item.$ref.split(\"/\").pop();\n if (value) {\n mapping[item.$ref] = { ...mapping[item.$ref], inferred: value };\n }\n }\n return mapping;\n}\n\n/** Values defined in `discriminator.mapping` replace inferred ones for the same schema. */\nfunction addDefinedMapping(\n mapping: DiscriminatorMapping,\n defined: Readonly<Record<string, string>>,\n): void {\n for (const [mappedValue, mappedRef] of Object.entries(defined)) {\n if (!mappedRef) {\n continue;\n }\n if (!mapping[mappedRef]?.defined) {\n mapping[mappedRef] = { defined: [] };\n }\n mapping[mappedRef].defined?.push(mappedValue);\n }\n}\n\nfunction patchMappedSchemas(\n state: ScanState,\n mapping: DiscriminatorMapping,\n discriminator: Omit<EnumPatch, \"ref\" | \"values\">,\n): void {\n for (const [ref, { inferred, defined }] of Object.entries(mapping)) {\n const isSkipped = !mergesValues(state) && state.refsHandled.includes(ref);\n if (isSkipped || (!inferred && !defined)) {\n continue;\n }\n // A defined value wins: the schema name may not be the value the API sends.\n const values = defined ?? [inferred as string];\n if (mergesValues(state) && defined === undefined) {\n // A mapping found later, in this pass or the next, may name the schema.\n state.inferredPatches.push({ ...discriminator, ref, values });\n } else if (patchDiscriminatorEnum(state, { ...discriminator, ref, values })) {\n markHandled(state, ref);\n }\n }\n}\n\n/** Pass 1: collect every discriminator; patch the schemas of a discriminator + `oneOf`. */\nfunction collectDiscriminator(\n state: ScanState,\n value: Record<string, unknown>,\n path: (string | number)[],\n): void {\n const discriminator = value.discriminator as DiscriminatorObject | undefined;\n if (!discriminator?.propertyName) {\n return;\n }\n const discriminatorRef = createRef(path);\n state.objects[discriminatorRef] = discriminator;\n state.owners.add(discriminatorRef);\n if (!Array.isArray(value.oneOf)) {\n return;\n }\n const mapping = inferredMapping(value.oneOf);\n if (discriminator.mapping) {\n addDefinedMapping(mapping, discriminator.mapping);\n }\n patchMappedSchemas(state, mapping, { discriminator, discriminatorRef });\n}\n\n/** The mapping keys of `discriminator` that point at `ref`. */\nfunction valuesMappedTo(discriminator: DiscriminatorObject, ref: string): string[] {\n return Object.entries(discriminator.mapping ?? {})\n .filter(([, mappedRef]) => mappedRef === ref)\n .map(([mappedValue]) => mappedValue);\n}\n\n/**\n * Whether the schema at `ref` takes the discriminator of its `allOf` parent at `parentRef`. With\n * `allof-discriminated-union`, a schema that `allOf`s a discriminated union that does not contain\n * it is that union, not one of its members, so it gets no value of its own (#1464, #1690). A\n * schema that the union's mapping names is a member.\n */\nfunction inheritsDiscriminator(state: ScanState, parentRef: string, ref: string): boolean {\n if (!state.fixes.has(FIX.ALLOF_DISCRIMINATED_UNION)) {\n return true;\n }\n const resolve = (target: string) => resolveDocumentRef(state.schema, target, state);\n const union = unionAt(parentRef, resolve);\n return union === undefined || isUnionMember(union, ref, resolve);\n}\n\n/**\n * The schema at `ref` inherits `discriminator`. With `discriminator-values`, a schema that\n * defines a discriminator keeps it: the inherited one replaced its mapping, so the members walked\n * after this schema got their schema name instead of the mapped value (#2200). `ownerRef` is the\n * schema that declares the discriminator property, whose enum `--enum` values use (#1700).\n */\nfunction recordInherited(\n state: ScanState,\n ref: string,\n discriminator: DiscriminatorObject,\n ownerRef: string,\n): void {\n if (state.fixes.has(FIX.DISCRIMINATOR_VALUES) && state.owners.has(ref)) {\n return;\n }\n const inherited = { ...discriminator };\n state.objects[ref] = inherited;\n recordEnumParent(state, { discriminator, discriminatorRef: ownerRef }, inherited);\n}\n\n/**\n * An `allOf` item that is a `$ref` to a discriminator owner: the schema at `ref` inherits the\n * discriminator, and gets its enum when the parent's mapping names it. Returns false when the\n * `$ref` owns no discriminator, which ends the scan of this `allOf` (as in the original).\n */\nfunction inheritFromRef(state: ScanState, parentRef: string, ref: string): boolean {\n const discriminator = state.objects[parentRef];\n if (!discriminator) {\n return false;\n }\n const values = valuesMappedTo(discriminator, ref);\n const patch = { ref, values, discriminator, discriminatorRef: parentRef };\n if (values.length > 0 && patchDiscriminatorEnum(state, patch)) {\n markHandled(state, ref);\n }\n if (inheritsDiscriminator(state, parentRef, ref)) {\n recordInherited(state, ref, discriminator, parentRef);\n if (mergesValues(state)) {\n inheritOtherOwners(state, parentRef, ref);\n }\n }\n return true;\n}\n\n/** Pass 2: a schema whose `allOf` holds a discriminator, or a `$ref` to one, inherits it. */\nfunction inheritDiscriminators(\n state: ScanState,\n value: Record<string, unknown>,\n path: (string | number)[],\n): void {\n if (!Array.isArray(value.allOf)) {\n return;\n }\n for (const item of value.allOf as (SchemaObject | ReferenceObject)[]) {\n if (\"$ref\" in item) {\n if (!inheritFromRef(state, item.$ref, createRef(path))) {\n return;\n }\n } else if (item.discriminator?.propertyName) {\n // The inline item is typed at the schema's own location.\n recordInherited(state, createRef(path), item.discriminator, createRef(path));\n }\n }\n}\n\n/** The discriminators of a bundled document, after patching the mapped schemas in place. */\nexport interface DiscriminatorScan {\n objects: Record<string, DiscriminatorObject>;\n refsHandled: string[];\n /** With `discriminator-values`: the owner's enum of each enum the scan added. */\n enumParents: ReadonlyMap<object, EnumParent>;\n /** With `discriminator-values`: the properties of the other discriminators a schema inherits. */\n otherProperties: Readonly<Record<string, readonly string[]>>;\n}\n\n/**\n * With the fix: a schema-name value, only for a schema and property that no mapping gave a value.\n * Every enum patched so far came from a mapping, since schema-name values wait for this step.\n */\nfunction applyInferredPatches(state: ScanState): void {\n // A value that a schema declares itself came from a mapping as well.\n const mapped = new Set([...state.patchedEnums.keys(), ...state.declaredKeys]);\n for (const patch of state.inferredPatches) {\n if (!mapped.has(enumKey(patch)) && patchDiscriminatorEnum(state, patch)) {\n markHandled(state, patch.ref);\n }\n }\n applyOtherInferredPatches(state, mapped);\n}\n\n/** Find every discriminator in `schema`; warnings go to `logger` unless `silent`. */\nexport function findDiscriminators(\n schema: OpenAPI3,\n options: DiscriminatorScanOptions,\n): DiscriminatorScan {\n const state: ScanState = {\n ...options,\n schema,\n objects: {},\n owners: new Set(),\n refsHandled: [],\n patchedEnums: new Map(),\n inferredPatches: [],\n otherInferredPatches: [],\n otherProperties: {},\n declaredKeys: new Set(),\n enumParents: new Map(),\n };\n walkDocument(schema, (value, path) => collectDiscriminator(state, value, path));\n // A second pass, because an `allOf` may name a discriminator that is defined later.\n walkDocument(schema, (value, path) => inheritDiscriminators(state, value, path));\n applyInferredPatches(state);\n const { objects, refsHandled, enumParents, otherProperties } = state;\n return { objects, refsHandled, enumParents, otherProperties };\n}\n\n/**\n * Return a key–value map of discriminator objects found in a schema. Warnings go to `logger`;\n * without one, to the default terminal logger, as the original did.\n * @deprecated Kept for 1.x; removed in 2.0 (ADR-004, decision 9).\n */\nexport function scanDiscriminators(\n schema: OpenAPI3,\n options: GeneratorOptions,\n logger: Logger = defaultLogger(options.silent ?? false),\n): DiscriminatorScan {\n const silent = options.silent ?? false;\n return findDiscriminators(schema, { silent, logger, fixes: new Set() });\n}\n"],"names":[],"mappings":";;;;;;;;AAmCA,SAAS,gBAAgB,KAAA,EAAiE;AACxF,EAAA,MAAM,UAAgC,EAAC;AACvC,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,IAAI,EAAE,UAAU,IAAA,CAAA,EAAO;AACrB,MAAA;AAAA,IACF;AACA,IAAA,MAAM,QAAQ,IAAA,CAAK,IAAA,CAAK,KAAA,CAAM,GAAG,EAAE,GAAA,EAAI;AACvC,IAAA,IAAI,KAAA,EAAO;AACT,MAAA,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAA,GAAI,EAAE,GAAG,QAAQ,IAAA,CAAK,IAAI,CAAA,EAAG,QAAA,EAAU,KAAA,EAAM;AAAA,IAChE;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAGA,SAAS,iBAAA,CACP,SACA,OAAA,EACM;AACN,EAAA,KAAA,MAAW,CAAC,WAAA,EAAa,SAAS,KAAK,MAAA,CAAO,OAAA,CAAQ,OAAO,CAAA,EAAG;AAC9D,IAAA,IAAI,CAAC,SAAA,EAAW;AACd,MAAA;AAAA,IACF;AACA,IAAA,IAAI,CAAC,OAAA,CAAQ,SAAS,CAAA,EAAG,OAAA,EAAS;AAChC,MAAA,OAAA,CAAQ,SAAS,CAAA,GAAI,EAAE,OAAA,EAAS,EAAC,EAAE;AAAA,IACrC;AACA,IAAA,OAAA,CAAQ,SAAS,CAAA,CAAE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vB;AACA,EAAA,YAAA,CAAa,MAAA,EAAQ,CAAC,KAAA,EAAO,IAAA,KAAS,qBAAqB,KAAA,EAAO,KAAA,EAAO,IAAI,CAAC,CAAA;AAE9E,EAAA,YAAA,CAAa,MAAA,EAAQ,CAAC,KAAA,EAAO,IAAA,KAAS,sBAAsB,KAAA,EAAO,KAAA,EAAO,IAAI,CAAC,CAAA;AAC/E,EAAA,oBAAA,CAAqB,KAAK,CAAA;AAC1B,EAAA,MAAM,EAAE,OAAA,EAAS,WAAA,EAAa,WAAA,EAAa,iBAAgB,GAAI,KAAA;AAC/D,EAAA,OAAO,EAAE,OAAA,EAAS,WAAA,EAAa,WAAA,EAAa,eAAA,EAAgB;AAC9D;AAOO,SAAS,kBAAA,CACd,QACA,OAAA,EACA,MAAA,GAAiB,cAAc,OAAA,CAAQ,MAAA,IAAU,KAAK,CAAA,EACnC;AACnB,EAAA,MAAM,MAAA,GAAS,QAAQ,MAAA,IAAU,KAAA;AACjC,EAAA,OAAO,kBAAA,CAAmB,QAAQ,EAAE,MAAA,EAAQ,QAAQ,KAAA,kBAAO,IAAI,GAAA,EAAI,EAAG,CAAA;AACxE;;"}
|
|
@@ -115,7 +115,8 @@ async function createDocumentRun(source, options, ports) {
|
|
|
115
115
|
injectFooter: [],
|
|
116
116
|
redoc: ports.redoc,
|
|
117
117
|
resolve: ($ref) => documentRefs.resolveDocumentRef(schema, $ref, { silent, logger }),
|
|
118
|
-
logger
|
|
118
|
+
logger,
|
|
119
|
+
deprecations: ports.deprecations
|
|
119
120
|
};
|
|
120
121
|
return { schema, ctx };
|
|
121
122
|
}
|