quicktype-typescript-input 23.0.136 → 23.0.138

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.
Files changed (2) hide show
  1. package/dist/index.js +14 -8
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -46,6 +46,7 @@ const compilerOptions = {
46
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
+ var _a, _b, _c, _d;
49
50
  const program = ts.createProgram(sourceFileNames, compilerOptions);
50
51
  const diagnostics = ts.getPreEmitDiagnostics(program);
51
52
  const error = diagnostics.find(d => d.category === ts.DiagnosticCategory.Error);
@@ -56,7 +57,18 @@ function schemaForTypeScriptSources(sourceFileNames) {
56
57
  }
57
58
  const schema = (0, typescript_json_schema_1.generateSchema)(program, "*", settings);
58
59
  const uris = [];
59
- let topLevelName = undefined;
60
+ let topLevelName = "";
61
+ // if there is a type that is `export default`, swap the corresponding ref
62
+ if ((_a = schema === null || schema === void 0 ? void 0 : schema.definitions) === null || _a === void 0 ? void 0 : _a.default) {
63
+ 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"] === "#/definitions/default")) === null || _d === void 0 ? void 0 : _d[0];
65
+ if (matchingDefaultName) {
66
+ topLevelName = matchingDefaultName;
67
+ defaultDefinition.title = topLevelName;
68
+ schema.definitions[matchingDefaultName] = defaultDefinition;
69
+ schema.definitions.default = { $ref: `#/definitions/${matchingDefaultName}` };
70
+ }
71
+ }
60
72
  if (schema !== null && typeof schema === "object" && typeof schema.definitions === "object") {
61
73
  for (const name of Object.getOwnPropertyNames(schema.definitions)) {
62
74
  const definition = schema.definitions[name];
@@ -74,7 +86,7 @@ function schemaForTypeScriptSources(sourceFileNames) {
74
86
  const index = (0, quicktype_core_1.defined)(matches.index);
75
87
  definition.description = description.slice(0, index) + description.slice(index + matches[0].length);
76
88
  uris.push(`#/definitions/${name}`);
77
- if (topLevelName === undefined) {
89
+ if (!topLevelName) {
78
90
  if (typeof definition.title === "string") {
79
91
  topLevelName = definition.title;
80
92
  }
@@ -82,17 +94,11 @@ function schemaForTypeScriptSources(sourceFileNames) {
82
94
  topLevelName = name;
83
95
  }
84
96
  }
85
- else {
86
- topLevelName = "";
87
- }
88
97
  }
89
98
  }
90
99
  if (uris.length === 0) {
91
100
  uris.push("#/definitions/");
92
101
  }
93
- if (topLevelName === undefined) {
94
- topLevelName = "";
95
- }
96
102
  return { schema: JSON.stringify(schema), name: topLevelName, uris, isConverted: true };
97
103
  }
98
104
  exports.schemaForTypeScriptSources = schemaForTypeScriptSources;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-typescript-input",
3
- "version": "23.0.136",
3
+ "version": "23.0.138",
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",
@@ -12,7 +12,7 @@
12
12
  "tslint": "tslint --project ."
13
13
  },
14
14
  "dependencies": {
15
- "quicktype-core": "23.0.136",
15
+ "quicktype-core": "23.0.138",
16
16
  "typescript": "4.9.5",
17
17
  "@mark.probst/typescript-json-schema": "0.55.0"
18
18
  },