ts-json-schema-generator 2.4.1--canary.2413.85be772.0 → 2.4.1--canary.2417.cbf58ef.0
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/factory/parser.js +6 -1
- package/dist/factory/parser.js.map +1 -1
- package/dist/factory/program.js +2 -5
- package/dist/factory/program.js.map +1 -1
- package/dist/package.json +31 -29
- package/dist/src/Config.d.ts +1 -1
- package/dist/src/Error/BaseError.d.ts +1 -1
- package/dist/src/Error/BaseError.js +2 -1
- package/dist/src/Error/BaseError.js.map +1 -1
- package/dist/src/NodeParser/BinaryExpressionNodeParser.d.ts +13 -0
- package/dist/src/NodeParser/BinaryExpressionNodeParser.js +79 -0
- package/dist/src/NodeParser/BinaryExpressionNodeParser.js.map +1 -0
- package/dist/src/SchemaGenerator.d.ts +2 -2
- package/dist/src/SchemaGenerator.js +10 -5
- package/dist/src/SchemaGenerator.js.map +1 -1
- package/dist/src/Type/AnnotatedType.d.ts +1 -3
- package/dist/src/Type/AnnotatedType.js.map +1 -1
- package/dist/src/Type/UnknownType.d.ts +1 -1
- package/dist/src/Type/UnknownType.js +1 -1
- package/dist/src/Type/UnknownType.js.map +1 -1
- package/dist/src/TypeFormatter/AnnotatedTypeFormatter.js +1 -1
- package/dist/src/TypeFormatter/AnnotatedTypeFormatter.js.map +1 -1
- package/dist/src/Utils/castArray.d.ts +1 -0
- package/dist/src/Utils/castArray.js +10 -0
- package/dist/src/Utils/castArray.js.map +1 -0
- package/dist/src/Utils/narrowType.js.map +1 -1
- package/dist/src/Utils/nodeKey.d.ts +1 -1
- package/dist/src/Utils/nodeKey.js.map +1 -1
- package/dist/ts-json-schema-generator.js +3 -3
- package/dist/ts-json-schema-generator.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/factory/parser.ts +7 -1
- package/factory/program.ts +3 -7
- package/package.json +31 -29
- package/src/Config.ts +2 -2
- package/src/Error/BaseError.ts +3 -1
- package/src/NodeParser/BinaryExpressionNodeParser.ts +99 -0
- package/src/SchemaGenerator.ts +12 -5
- package/src/Type/AnnotatedType.ts +1 -3
- package/src/Type/UnknownType.ts +1 -1
- package/src/TypeFormatter/AnnotatedTypeFormatter.ts +2 -2
- package/src/Utils/castArray.ts +7 -0
- package/src/Utils/narrowType.ts +1 -6
- package/src/Utils/nodeKey.ts +3 -1
- package/ts-json-schema-generator.ts +3 -3
package/factory/parser.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { AnyTypeNodeParser } from "../src/NodeParser/AnyTypeNodeParser.js";
|
|
|
12
12
|
import { ArrayLiteralExpressionNodeParser } from "../src/NodeParser/ArrayLiteralExpressionNodeParser.js";
|
|
13
13
|
import { ArrayNodeParser } from "../src/NodeParser/ArrayNodeParser.js";
|
|
14
14
|
import { AsExpressionNodeParser } from "../src/NodeParser/AsExpressionNodeParser.js";
|
|
15
|
+
import { BinaryExpressionNodeParser } from "../src/NodeParser/BinaryExpressionNodeParser.js";
|
|
15
16
|
import { BooleanLiteralNodeParser } from "../src/NodeParser/BooleanLiteralNodeParser.js";
|
|
16
17
|
import { BooleanTypeNodeParser } from "../src/NodeParser/BooleanTypeNodeParser.js";
|
|
17
18
|
import { CallExpressionParser } from "../src/NodeParser/CallExpressionParser.js";
|
|
@@ -62,6 +63,7 @@ import { SatisfiesNodeParser } from "../src/NodeParser/SatisfiesNodeParser.js";
|
|
|
62
63
|
import { PromiseNodeParser } from "../src/NodeParser/PromiseNodeParser.js";
|
|
63
64
|
import { SpreadElementNodeParser } from "../src/NodeParser/SpreadElementNodeParser.js";
|
|
64
65
|
import { IdentifierNodeParser } from "../src/NodeParser/IdentifierNodeParser.js";
|
|
66
|
+
import { castArray } from "../src/Utils/castArray.js";
|
|
65
67
|
|
|
66
68
|
export type ParserAugmentor = (parser: MutableParser) => void;
|
|
67
69
|
|
|
@@ -73,7 +75,10 @@ export function createParser(program: ts.Program, config: CompletedConfig, augme
|
|
|
73
75
|
return new ExposeNodeParser(typeChecker, nodeParser, config.expose, config.jsDoc);
|
|
74
76
|
}
|
|
75
77
|
function withTopRef(nodeParser: NodeParser): NodeParser {
|
|
76
|
-
|
|
78
|
+
const typeArr = castArray(config.type);
|
|
79
|
+
// If we have multiple types, don't set a top-level $ref.
|
|
80
|
+
const topRefFullName = typeArr && typeArr.length === 1 ? typeArr[0] : undefined;
|
|
81
|
+
return new TopRefNodeParser(chainNodeParser, topRefFullName, config.topRef);
|
|
77
82
|
}
|
|
78
83
|
function withJsDoc(nodeParser: SubNodeParser): SubNodeParser {
|
|
79
84
|
const extraTags = new Set(config.extraTags);
|
|
@@ -114,6 +119,7 @@ export function createParser(program: ts.Program, config: CompletedConfig, augme
|
|
|
114
119
|
.addNodeParser(new NeverTypeNodeParser())
|
|
115
120
|
.addNodeParser(new ObjectTypeNodeParser())
|
|
116
121
|
.addNodeParser(new AsExpressionNodeParser(chainNodeParser))
|
|
122
|
+
.addNodeParser(new BinaryExpressionNodeParser(chainNodeParser))
|
|
117
123
|
.addNodeParser(new SatisfiesNodeParser(chainNodeParser))
|
|
118
124
|
.addNodeParser(withJsDoc(new ParameterParser(chainNodeParser)))
|
|
119
125
|
.addNodeParser(new StringLiteralNodeParser())
|
package/factory/program.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { globSync } from "glob";
|
|
2
1
|
import * as path from "node:path";
|
|
3
2
|
import normalize from "normalize-path";
|
|
4
|
-
import type { CompilerOptions } from "typescript";
|
|
5
3
|
import ts from "typescript";
|
|
6
4
|
import type { CompletedConfig, Config } from "../src/Config.js";
|
|
7
5
|
import { BuildError } from "../src/Error/Errors.js";
|
|
6
|
+
import { globSync } from "glob";
|
|
8
7
|
|
|
9
8
|
function loadTsConfigFile(configFile: string) {
|
|
10
9
|
const raw = ts.sys.readFile(configFile);
|
|
@@ -56,13 +55,10 @@ function getTsConfig(config: Config) {
|
|
|
56
55
|
noEmit: true,
|
|
57
56
|
emitDecoratorMetadata: true,
|
|
58
57
|
experimentalDecorators: true,
|
|
59
|
-
target: ts.ScriptTarget.
|
|
58
|
+
target: ts.ScriptTarget.ES5,
|
|
60
59
|
module: ts.ModuleKind.CommonJS,
|
|
61
60
|
strictNullChecks: false,
|
|
62
|
-
|
|
63
|
-
skipDefaultLibCheck: true,
|
|
64
|
-
esModuleInterop: true,
|
|
65
|
-
} satisfies CompilerOptions,
|
|
61
|
+
},
|
|
66
62
|
};
|
|
67
63
|
}
|
|
68
64
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-json-schema-generator",
|
|
3
|
-
"version": "2.4.1--canary.
|
|
3
|
+
"version": "2.4.1--canary.2417.cbf58ef.0",
|
|
4
4
|
"description": "Generate JSON schema from your Typescript sources",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ts",
|
|
@@ -49,51 +49,53 @@
|
|
|
49
49
|
"prepublishOnly": "npm run build",
|
|
50
50
|
"release": "npm run build && auto shipit",
|
|
51
51
|
"run": "tsx ts-json-schema-generator.ts",
|
|
52
|
-
"test": "
|
|
53
|
-
"test:
|
|
54
|
-
"test:
|
|
55
|
-
"test:
|
|
52
|
+
"test": "jest test/ --verbose",
|
|
53
|
+
"test:debug": "node --inspect-brk node_modules/.bin/jest test/ --verbose --runInBand",
|
|
54
|
+
"test:coverage": "npm run jest -- test/ --collectCoverage=true",
|
|
55
|
+
"test:fast": "cross-env FAST_TEST=1 jest test/ --verbose",
|
|
56
|
+
"test:update": "cross-env UPDATE_SCHEMA=true npm run test:fast",
|
|
56
57
|
"watch": "tsc -w"
|
|
57
58
|
},
|
|
58
59
|
"dependencies": {
|
|
59
60
|
"@types/json-schema": "^7.0.15",
|
|
60
|
-
"
|
|
61
|
-
"commander": "^14.0.0",
|
|
61
|
+
"commander": "^14.0.2",
|
|
62
62
|
"glob": "^13.0.0",
|
|
63
63
|
"json5": "^2.2.3",
|
|
64
64
|
"normalize-path": "^3.0.0",
|
|
65
65
|
"safe-stable-stringify": "^2.5.0",
|
|
66
66
|
"tslib": "^2.8.1",
|
|
67
|
-
"typescript": "^5.
|
|
67
|
+
"typescript": "^5.9.3",
|
|
68
|
+
"@typescript/vfs": "1.6.2"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
70
|
-
"@auto-it/conventional-commits": "^11.3.
|
|
71
|
-
"@auto-it/first-time-contributor": "^11.3.
|
|
72
|
-
"@babel/core": "^7.28.
|
|
73
|
-
"@babel/preset-env": "^7.28.
|
|
74
|
-
"@babel/preset-typescript": "^7.
|
|
75
|
-
"@eslint/js": "^9.
|
|
71
|
+
"@auto-it/conventional-commits": "^11.3.6",
|
|
72
|
+
"@auto-it/first-time-contributor": "^11.3.6",
|
|
73
|
+
"@babel/core": "^7.28.5",
|
|
74
|
+
"@babel/preset-env": "^7.28.5",
|
|
75
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
76
|
+
"@eslint/js": "^9.39.1",
|
|
76
77
|
"@types/eslint": "^9.6.1",
|
|
77
|
-
"@types/
|
|
78
|
+
"@types/jest": "^30.0.0",
|
|
79
|
+
"@types/node": "^24.10.1",
|
|
78
80
|
"@types/normalize-path": "^3.0.2",
|
|
79
81
|
"ajv": "^8.17.1",
|
|
80
82
|
"ajv-formats": "^3.0.1",
|
|
81
|
-
"auto": "^11.3.
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"cross-env": "^10.0.0",
|
|
83
|
+
"auto": "^11.3.6",
|
|
84
|
+
"chai": "^6.2.1",
|
|
85
|
+
"cross-env": "^10.1.0",
|
|
85
86
|
"eslint": "9.39.1",
|
|
86
|
-
"eslint-config-prettier": "^10.1.
|
|
87
|
-
"eslint-plugin-prettier": "^5.5.
|
|
88
|
-
"globals": "^16.
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"vega
|
|
87
|
+
"eslint-config-prettier": "^10.1.8",
|
|
88
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
89
|
+
"globals": "^16.5.0",
|
|
90
|
+
"jest": "^30.2.0",
|
|
91
|
+
"jest-junit": "^16.0.0",
|
|
92
|
+
"prettier": "^3.7.3",
|
|
93
|
+
"tsx": "^4.21.0",
|
|
94
|
+
"typescript-eslint": "^8.48.0",
|
|
95
|
+
"vega": "^6.2.0",
|
|
96
|
+
"vega-lite": "^6.4.1"
|
|
95
97
|
},
|
|
96
|
-
"packageManager": "npm@11.4
|
|
98
|
+
"packageManager": "npm@11.6.4",
|
|
97
99
|
"engines": {
|
|
98
100
|
"node": ">=18.0.0"
|
|
99
101
|
}
|
package/src/Config.ts
CHANGED
|
@@ -8,10 +8,10 @@ export interface Config {
|
|
|
8
8
|
path?: string;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Name of the type/interface to generate schema for.
|
|
11
|
+
* Name of the type(s)/interface(s) to generate schema for.
|
|
12
12
|
* Use "*" to generate schemas for all exported types.
|
|
13
13
|
*/
|
|
14
|
-
type?: string;
|
|
14
|
+
type?: string | string[];
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Minify the output JSON schema (no whitespace).
|
package/src/Error/BaseError.ts
CHANGED
|
@@ -12,6 +12,8 @@ export type PartialDiagnostic = Omit<ts.Diagnostic, "category" | "file" | "start
|
|
|
12
12
|
category?: ts.DiagnosticCategory;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
const isTTY = process.env.TTY || process.stdout.isTTY;
|
|
16
|
+
|
|
15
17
|
/**
|
|
16
18
|
* Base error for ts-json-schema-generator
|
|
17
19
|
*/
|
|
@@ -49,7 +51,7 @@ export abstract class BaseError extends Error {
|
|
|
49
51
|
);
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
format(
|
|
54
|
+
format() {
|
|
53
55
|
const formatter = isTTY ? ts.formatDiagnosticsWithColorAndContext : ts.formatDiagnostics;
|
|
54
56
|
|
|
55
57
|
return formatter([this.diagnostic], {
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import type { Context, NodeParser } from "../NodeParser.js";
|
|
3
|
+
import type { SubNodeParser } from "../SubNodeParser.js";
|
|
4
|
+
import { AnyType } from "../Type/AnyType.js";
|
|
5
|
+
import type { BaseType } from "../Type/BaseType.js";
|
|
6
|
+
import { BooleanType } from "../Type/BooleanType.js";
|
|
7
|
+
import { LiteralType } from "../Type/LiteralType.js";
|
|
8
|
+
import { NumberType } from "../Type/NumberType.js";
|
|
9
|
+
import { StringType } from "../Type/StringType.js";
|
|
10
|
+
import { UnionType } from "../Type/UnionType.js";
|
|
11
|
+
import { AliasType } from "../Type/AliasType.js";
|
|
12
|
+
|
|
13
|
+
export class BinaryExpressionNodeParser implements SubNodeParser {
|
|
14
|
+
public constructor(protected childNodeParser: NodeParser) {}
|
|
15
|
+
|
|
16
|
+
public supportsNode(node: ts.Node): boolean {
|
|
17
|
+
return node.kind === ts.SyntaxKind.BinaryExpression;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public createType(node: ts.BinaryExpression, context: Context): BaseType {
|
|
21
|
+
const leftType = this.childNodeParser.createType(node.left, context);
|
|
22
|
+
const rightType = this.childNodeParser.createType(node.right, context);
|
|
23
|
+
|
|
24
|
+
if (leftType instanceof AnyType || rightType instanceof AnyType) {
|
|
25
|
+
return new AnyType();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (this.isStringLike(leftType) || this.isStringLike(rightType)) {
|
|
29
|
+
return new StringType();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (this.isDefinitelyNumberLike(leftType) && this.isDefinitelyNumberLike(rightType)) {
|
|
33
|
+
return new NumberType();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (this.isBooleanLike(leftType) && this.isBooleanLike(rightType)) {
|
|
37
|
+
return new BooleanType();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Anything else (objects, any, unknown, weird unions, etc.) return
|
|
41
|
+
// 'string' because at runtime + will usually go through ToPrimitive and
|
|
42
|
+
// end up in the "string concatenation" branch when non-numeric stuff is
|
|
43
|
+
// involved.
|
|
44
|
+
return new StringType();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private isStringLike(type: BaseType): boolean {
|
|
48
|
+
if (type instanceof AliasType) {
|
|
49
|
+
return this.isStringLike(type.getType());
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (type instanceof StringType) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (type instanceof LiteralType && type.isString()) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Any union member being string-like is enough.
|
|
61
|
+
if (type instanceof UnionType) {
|
|
62
|
+
return type.getTypes().some((t) => this.isStringLike(t));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private isBooleanLike(type: BaseType): boolean {
|
|
69
|
+
if (type instanceof BooleanType) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (type instanceof LiteralType && typeof type.getValue() === "boolean") {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private isDefinitelyNumberLike(type: BaseType): boolean {
|
|
81
|
+
if (type instanceof AliasType) {
|
|
82
|
+
return this.isDefinitelyNumberLike(type.getType());
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (type instanceof NumberType) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (type instanceof LiteralType && typeof type.getValue() === "number") {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (type instanceof UnionType) {
|
|
94
|
+
return type.getTypes().every((t) => this.isDefinitelyNumberLike(t));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
package/src/SchemaGenerator.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { TypeFormatter } from "./TypeFormatter.js";
|
|
|
10
10
|
import type { StringMap } from "./Utils/StringMap.js";
|
|
11
11
|
import { hasJsDocTag } from "./Utils/hasJsDocTag.js";
|
|
12
12
|
import { removeUnreachable } from "./Utils/removeUnreachable.js";
|
|
13
|
+
import { castArray } from "./Utils/castArray.js";
|
|
13
14
|
import { symbolAtNode } from "./Utils/symbolAtNode.js";
|
|
14
15
|
|
|
15
16
|
export class SchemaGenerator {
|
|
@@ -20,8 +21,8 @@ export class SchemaGenerator {
|
|
|
20
21
|
protected readonly config?: Config,
|
|
21
22
|
) {}
|
|
22
23
|
|
|
23
|
-
public createSchema(
|
|
24
|
-
const rootNodes = this.getRootNodes(
|
|
24
|
+
public createSchema(fullNames?: string | string[]): Schema {
|
|
25
|
+
const rootNodes = this.getRootNodes(castArray(fullNames));
|
|
25
26
|
return this.createSchemaFromNodes(rootNodes);
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -60,9 +61,15 @@ export class SchemaGenerator {
|
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
protected getRootNodes(
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
protected getRootNodes(fullNames: string[] | undefined): ts.Node[] {
|
|
65
|
+
// ["*"] means generate everything.
|
|
66
|
+
if (fullNames && fullNames.includes("*") && fullNames.length > 1) {
|
|
67
|
+
throw new Error("Cannot mix '*' with specific type names");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const generateAll = !fullNames || fullNames.length === 0 || (fullNames.length === 1 && fullNames[0] === "*");
|
|
71
|
+
if (!generateAll) {
|
|
72
|
+
return fullNames.map((name) => this.findNamedNode(name));
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
const rootFileNames = this.program.getRootFileNames();
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { BaseType } from "./BaseType.js";
|
|
2
2
|
import { hash } from "../Utils/nodeKey.js";
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
[name: string]: any;
|
|
6
|
-
}
|
|
4
|
+
export type Annotations = Record<string, unknown>;
|
|
7
5
|
|
|
8
6
|
export class AnnotatedType extends BaseType {
|
|
9
7
|
public constructor(
|
package/src/Type/UnknownType.ts
CHANGED
|
@@ -5,7 +5,7 @@ export class UnknownType extends BaseType {
|
|
|
5
5
|
/**
|
|
6
6
|
* If the source for this UnknownType was from a failed operation than to an actual `unknown` type present in the source code.
|
|
7
7
|
*/
|
|
8
|
-
readonly erroredSource
|
|
8
|
+
readonly erroredSource: boolean,
|
|
9
9
|
) {
|
|
10
10
|
super();
|
|
11
11
|
}
|
|
@@ -8,7 +8,7 @@ import type { TypeFormatter } from "../TypeFormatter.js";
|
|
|
8
8
|
import { derefType } from "../Utils/derefType.js";
|
|
9
9
|
|
|
10
10
|
export function makeNullable(def: Definition): Definition {
|
|
11
|
-
const union = (def.oneOf
|
|
11
|
+
const union: Definition[] | undefined = (def.oneOf as Definition[]) || def.anyOf;
|
|
12
12
|
if (union && union.filter((d: Definition) => d.type === "null").length === 0) {
|
|
13
13
|
union.push({ type: "null" });
|
|
14
14
|
} else if (def.type && def.type !== "object") {
|
|
@@ -58,7 +58,7 @@ export class AnnotatedTypeFormatter implements SubTypeFormatter {
|
|
|
58
58
|
if ("discriminator" in annotations) {
|
|
59
59
|
const deref = derefType(type.getType());
|
|
60
60
|
if (deref instanceof UnionType) {
|
|
61
|
-
deref.setDiscriminator(annotations.discriminator);
|
|
61
|
+
deref.setDiscriminator(annotations.discriminator as string);
|
|
62
62
|
delete annotations.discriminator;
|
|
63
63
|
} else {
|
|
64
64
|
throw new JsonTypeError(
|
package/src/Utils/narrowType.ts
CHANGED
|
@@ -16,12 +16,7 @@ import { derefType } from "./derefType.js";
|
|
|
16
16
|
* kept, when returning false it is removed.
|
|
17
17
|
* @return The narrowed down type.
|
|
18
18
|
*/
|
|
19
|
-
export function narrowType(
|
|
20
|
-
type: BaseType,
|
|
21
|
-
// TODO: remove the next line
|
|
22
|
-
|
|
23
|
-
predicate: (type: BaseType) => boolean,
|
|
24
|
-
): BaseType {
|
|
19
|
+
export function narrowType(type: BaseType, predicate: (type: BaseType) => boolean): BaseType {
|
|
25
20
|
const derefed = derefType(type);
|
|
26
21
|
if (derefed instanceof UnionType || derefed instanceof EnumType) {
|
|
27
22
|
let changed = false;
|
package/src/Utils/nodeKey.ts
CHANGED
|
@@ -2,7 +2,9 @@ import stringify from "safe-stable-stringify";
|
|
|
2
2
|
import type { Node } from "typescript";
|
|
3
3
|
import type { Context } from "../NodeParser.js";
|
|
4
4
|
|
|
5
|
-
export function hash(
|
|
5
|
+
export function hash(
|
|
6
|
+
a: string | boolean | number | (string | boolean | number | Record<string, unknown>)[] | Record<string, unknown>,
|
|
7
|
+
): string | number {
|
|
6
8
|
if (typeof a === "number") {
|
|
7
9
|
return a;
|
|
8
10
|
}
|
|
@@ -11,14 +11,14 @@ import pkg from "./package.json";
|
|
|
11
11
|
|
|
12
12
|
const args = new Command()
|
|
13
13
|
.option("-p, --path <path>", "Source file path")
|
|
14
|
-
.option("-t, --type <name
|
|
14
|
+
.option("-t, --type <name...>", "Type name(s)")
|
|
15
15
|
.option("-i, --id <name>", "$id for generated schema")
|
|
16
16
|
.option("-f, --tsconfig <path>", "Custom tsconfig.json path")
|
|
17
17
|
.addOption(
|
|
18
18
|
new Option("-e, --expose <expose>", "Type exposing").choices(["all", "none", "export"]).default("export"),
|
|
19
19
|
)
|
|
20
20
|
.addOption(
|
|
21
|
-
new Option("-j, --jsDoc <extended>", "Read
|
|
21
|
+
new Option("-j, --jsDoc <extended>", "Read JSDoc annotations")
|
|
22
22
|
.choices(["none", "basic", "extended"])
|
|
23
23
|
.default("extended"),
|
|
24
24
|
)
|
|
@@ -84,7 +84,7 @@ const config: Config = {
|
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
try {
|
|
87
|
-
const schema = createGenerator(config).createSchema(
|
|
87
|
+
const schema = createGenerator(config).createSchema(config.type);
|
|
88
88
|
|
|
89
89
|
const stringify = config.sortProps ? stableStringify : JSON.stringify;
|
|
90
90
|
// need as string since TS can't figure out that the string | undefined case doesn't happen
|