ts-json-schema-generator 2.5.0-next.0 → 2.5.0-next.10
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/README.md +22 -21
- package/dist/factory/generator.js +1 -1
- package/dist/factory/generator.js.map +1 -1
- package/dist/factory/parser.js +9 -2
- package/dist/factory/parser.js.map +1 -1
- package/dist/package.json +23 -21
- package/dist/src/AnnotationsReader/ExtendedAnnotationsReader.d.ts +2 -1
- package/dist/src/AnnotationsReader/ExtendedAnnotationsReader.js +22 -10
- package/dist/src/AnnotationsReader/ExtendedAnnotationsReader.js.map +1 -1
- package/dist/src/Config.d.ts +5 -2
- package/dist/src/Config.js +1 -0
- package/dist/src/Config.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/NodeParser/MappedTypeNodeParser.js +1 -1
- package/dist/src/NodeParser/MappedTypeNodeParser.js.map +1 -1
- package/dist/src/NodeParser/NewExpressionParser.d.ts +13 -0
- package/dist/src/NodeParser/NewExpressionParser.js +41 -0
- package/dist/src/NodeParser/NewExpressionParser.js.map +1 -0
- package/dist/src/NodeParser/TypeOperatorNodeParser.d.ts +1 -1
- package/dist/src/NodeParser/TypeOperatorNodeParser.js +2 -1
- package/dist/src/NodeParser/TypeOperatorNodeParser.js.map +1 -1
- package/dist/src/NodeParser/TypeReferenceNodeParser.js +1 -1
- package/dist/src/NodeParser/TypeReferenceNodeParser.js.map +1 -1
- package/dist/src/SchemaGenerator.d.ts +2 -2
- package/dist/src/SchemaGenerator.js +17 -7
- package/dist/src/SchemaGenerator.js.map +1 -1
- package/dist/src/TypeFormatter/LiteralUnionTypeFormatter.js +10 -5
- package/dist/src/TypeFormatter/LiteralUnionTypeFormatter.js.map +1 -1
- package/dist/src/TypeFormatter/PrimitiveUnionTypeFormatter.js +6 -2
- package/dist/src/TypeFormatter/PrimitiveUnionTypeFormatter.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/getFullDescription.d.ts +2 -0
- package/dist/src/Utils/getFullDescription.js +33 -0
- package/dist/src/Utils/getFullDescription.js.map +1 -0
- package/dist/ts-json-schema-generator.js +7 -3
- package/dist/ts-json-schema-generator.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/factory/generator.ts +1 -1
- package/factory/parser.ts +15 -2
- package/package.json +23 -21
- package/src/AnnotationsReader/ExtendedAnnotationsReader.ts +25 -10
- package/src/Config.ts +124 -2
- package/src/NodeParser/BinaryExpressionNodeParser.ts +99 -0
- package/src/NodeParser/MappedTypeNodeParser.ts +1 -1
- package/src/NodeParser/NewExpressionParser.ts +46 -0
- package/src/NodeParser/TypeOperatorNodeParser.ts +2 -2
- package/src/NodeParser/TypeReferenceNodeParser.ts +1 -1
- package/src/SchemaGenerator.ts +26 -9
- package/src/TypeFormatter/LiteralUnionTypeFormatter.ts +12 -6
- package/src/TypeFormatter/PrimitiveUnionTypeFormatter.ts +9 -2
- package/src/Utils/castArray.ts +7 -0
- package/src/Utils/getFullDescription.ts +39 -0
- package/ts-json-schema-generator.ts +12 -3
|
@@ -6,7 +6,6 @@ import type { BaseType } from "../Type/BaseType.js";
|
|
|
6
6
|
import { BooleanType } from "../Type/BooleanType.js";
|
|
7
7
|
import { NullType } from "../Type/NullType.js";
|
|
8
8
|
import { NumberType } from "../Type/NumberType.js";
|
|
9
|
-
import { PrimitiveType } from "../Type/PrimitiveType.js";
|
|
10
9
|
import { StringType } from "../Type/StringType.js";
|
|
11
10
|
import { UnionType } from "../Type/UnionType.js";
|
|
12
11
|
import { uniqueArray } from "../Utils/uniqueArray.js";
|
|
@@ -25,7 +24,15 @@ export class PrimitiveUnionTypeFormatter implements SubTypeFormatter {
|
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
protected isPrimitiveUnion(type: UnionType): boolean {
|
|
28
|
-
return type
|
|
27
|
+
return type
|
|
28
|
+
.getTypes()
|
|
29
|
+
.every(
|
|
30
|
+
(item) =>
|
|
31
|
+
item instanceof StringType ||
|
|
32
|
+
item instanceof NumberType ||
|
|
33
|
+
item instanceof BooleanType ||
|
|
34
|
+
item instanceof NullType,
|
|
35
|
+
);
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
protected getPrimitiveType(item: BaseType): RawTypeName {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export function getFullDescription(node: ts.Node): string | undefined {
|
|
4
|
+
const sourceFile = node.getSourceFile();
|
|
5
|
+
const jsDocNodes = ts.getJSDocCommentsAndTags(node);
|
|
6
|
+
|
|
7
|
+
if (!jsDocNodes || jsDocNodes.length === 0) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let rawText = "";
|
|
12
|
+
|
|
13
|
+
for (const jsDoc of jsDocNodes) {
|
|
14
|
+
rawText += jsDoc.getFullText(sourceFile) + "\n";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
rawText = rawText.trim();
|
|
18
|
+
|
|
19
|
+
return getTextWithoutStars(rawText).trim();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getTextWithoutStars(inputText: string) {
|
|
23
|
+
const innerTextWithStars = inputText.replace(/^\/\*\*[^\S\n]*\n?/, "").replace(/(\r?\n)?[^\S\n]*\*\/$/, "");
|
|
24
|
+
|
|
25
|
+
return innerTextWithStars
|
|
26
|
+
.split(/\n/)
|
|
27
|
+
.map((line) => {
|
|
28
|
+
const trimmedLine = line.trimStart();
|
|
29
|
+
|
|
30
|
+
if (trimmedLine[0] !== "*") {
|
|
31
|
+
return line;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const textStartPos = trimmedLine[1] === " " ? 2 : 1;
|
|
35
|
+
|
|
36
|
+
return trimmedLine.substring(textStartPos);
|
|
37
|
+
})
|
|
38
|
+
.join("\n");
|
|
39
|
+
}
|
|
@@ -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
|
)
|
|
@@ -27,6 +27,14 @@ const args = new Command()
|
|
|
27
27
|
jsDoc: "extended",
|
|
28
28
|
}),
|
|
29
29
|
)
|
|
30
|
+
.addOption(
|
|
31
|
+
new Option(
|
|
32
|
+
"--full-description",
|
|
33
|
+
"Include the full raw JSDoc comment as `fullDescription` in the schema.",
|
|
34
|
+
).implies({
|
|
35
|
+
jsDoc: "extended",
|
|
36
|
+
}),
|
|
37
|
+
)
|
|
30
38
|
.addOption(
|
|
31
39
|
new Option(
|
|
32
40
|
"--functions <functions>",
|
|
@@ -65,6 +73,7 @@ const config: Config = {
|
|
|
65
73
|
topRef: args.topRef,
|
|
66
74
|
jsDoc: args.jsDoc,
|
|
67
75
|
markdownDescription: args.markdownDescription,
|
|
76
|
+
fullDescription: args.fullDescription,
|
|
68
77
|
sortProps: !args.unstable,
|
|
69
78
|
strictTuples: args.strictTuples,
|
|
70
79
|
skipTypeCheck: !args.typeCheck,
|
|
@@ -75,7 +84,7 @@ const config: Config = {
|
|
|
75
84
|
};
|
|
76
85
|
|
|
77
86
|
try {
|
|
78
|
-
const schema = createGenerator(config).createSchema(
|
|
87
|
+
const schema = createGenerator(config).createSchema(config.type);
|
|
79
88
|
|
|
80
89
|
const stringify = config.sortProps ? stableStringify : JSON.stringify;
|
|
81
90
|
// need as string since TS can't figure out that the string | undefined case doesn't happen
|