quicktype-typescript-input 23.1.4 → 23.2.1
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/index.js +23 -10
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ const settings = {
|
|
|
31
31
|
required: true,
|
|
32
32
|
titles: true,
|
|
33
33
|
topRef: true,
|
|
34
|
-
noExtraProps: true
|
|
34
|
+
noExtraProps: true,
|
|
35
35
|
};
|
|
36
36
|
const compilerOptions = {
|
|
37
37
|
noEmit: true,
|
|
@@ -41,35 +41,41 @@ const compilerOptions = {
|
|
|
41
41
|
module: ts.ModuleKind.CommonJS,
|
|
42
42
|
strictNullChecks: true,
|
|
43
43
|
typeRoots: [],
|
|
44
|
-
rootDir: "."
|
|
44
|
+
rootDir: ".",
|
|
45
45
|
};
|
|
46
|
-
// FIXME: We're stringifying and then parsing this schema again.
|
|
46
|
+
// FIXME: We're stringifying and then parsing this schema again. Just pass around
|
|
47
47
|
// the schema directly.
|
|
48
48
|
function schemaForTypeScriptSources(sourceFileNames) {
|
|
49
49
|
var _a, _b, _c, _d;
|
|
50
50
|
const program = ts.createProgram(sourceFileNames, compilerOptions);
|
|
51
51
|
const diagnostics = ts.getPreEmitDiagnostics(program);
|
|
52
|
-
const error = diagnostics.find(d => d.category === ts.DiagnosticCategory.Error);
|
|
52
|
+
const error = diagnostics.find((d) => d.category === ts.DiagnosticCategory.Error);
|
|
53
53
|
if (error !== undefined) {
|
|
54
54
|
return (0, quicktype_core_1.messageError)("TypeScriptCompilerError", {
|
|
55
|
-
message: ts.flattenDiagnosticMessageText(error.messageText, "\n")
|
|
55
|
+
message: ts.flattenDiagnosticMessageText(error.messageText, "\n"),
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
+
// this breaks after upgrading to TS 5+
|
|
58
59
|
const schema = (0, typescript_json_schema_1.generateSchema)(program, "*", settings);
|
|
59
60
|
const uris = [];
|
|
60
61
|
let topLevelName = "";
|
|
61
62
|
// if there is a type that is `export default`, swap the corresponding ref
|
|
62
63
|
if ((_a = schema === null || schema === void 0 ? void 0 : schema.definitions) === null || _a === void 0 ? void 0 : _a.default) {
|
|
63
64
|
const defaultDefinition = (_b = schema === null || schema === void 0 ? void 0 : schema.definitions) === null || _b === void 0 ? void 0 : _b.default;
|
|
64
|
-
const matchingDefaultName = (_d = Object.entries((_c = schema === null || schema === void 0 ? void 0 : schema.definitions) !== null && _c !== void 0 ? _c : {}).find(([_name, definition]) => definition.$ref ===
|
|
65
|
+
const matchingDefaultName = (_d = Object.entries((_c = schema === null || schema === void 0 ? void 0 : schema.definitions) !== null && _c !== void 0 ? _c : {}).find(([_name, definition]) => definition.$ref ===
|
|
66
|
+
"#/definitions/default")) === null || _d === void 0 ? void 0 : _d[0];
|
|
65
67
|
if (matchingDefaultName) {
|
|
66
68
|
topLevelName = matchingDefaultName;
|
|
67
69
|
defaultDefinition.title = topLevelName;
|
|
68
70
|
schema.definitions[matchingDefaultName] = defaultDefinition;
|
|
69
|
-
schema.definitions.default = {
|
|
71
|
+
schema.definitions.default = {
|
|
72
|
+
$ref: `#/definitions/${matchingDefaultName}`,
|
|
73
|
+
};
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
|
-
if (schema !== null &&
|
|
76
|
+
if (schema !== null &&
|
|
77
|
+
typeof schema === "object" &&
|
|
78
|
+
typeof schema.definitions === "object") {
|
|
73
79
|
for (const name of Object.getOwnPropertyNames(schema.definitions)) {
|
|
74
80
|
const definition = schema.definitions[name];
|
|
75
81
|
if (definition === null ||
|
|
@@ -84,7 +90,9 @@ function schemaForTypeScriptSources(sourceFileNames) {
|
|
|
84
90
|
continue;
|
|
85
91
|
}
|
|
86
92
|
const index = (0, quicktype_core_1.defined)(matches.index);
|
|
87
|
-
definition.description =
|
|
93
|
+
definition.description =
|
|
94
|
+
description.slice(0, index) +
|
|
95
|
+
description.slice(index + matches[0].length);
|
|
88
96
|
uris.push(`#/definitions/${name}`);
|
|
89
97
|
if (!topLevelName) {
|
|
90
98
|
if (typeof definition.title === "string") {
|
|
@@ -99,6 +107,11 @@ function schemaForTypeScriptSources(sourceFileNames) {
|
|
|
99
107
|
if (uris.length === 0) {
|
|
100
108
|
uris.push("#/definitions/");
|
|
101
109
|
}
|
|
102
|
-
return {
|
|
110
|
+
return {
|
|
111
|
+
schema: JSON.stringify(schema),
|
|
112
|
+
name: topLevelName,
|
|
113
|
+
uris,
|
|
114
|
+
isConverted: true,
|
|
115
|
+
};
|
|
103
116
|
}
|
|
104
117
|
exports.schemaForTypeScriptSources = schemaForTypeScriptSources;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quicktype-typescript-input",
|
|
3
|
-
"version": "23.1
|
|
3
|
+
"version": "23.2.1",
|
|
4
4
|
"description": "Package for using TypeScript as an input language to quicktype",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
"build": "tsc"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"quicktype-core": "23.1
|
|
14
|
+
"quicktype-core": "23.2.1",
|
|
15
15
|
"typescript": "4.9.5",
|
|
16
16
|
"@mark.probst/typescript-json-schema": "0.55.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@types/node": "
|
|
19
|
+
"@types/node": "~22.14.0"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"dist"
|