@twin.org/ts-to-schema 0.0.1-next.24 → 0.0.1-next.25

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.
@@ -79,23 +79,30 @@ async function tsToSchema(config, outputFolder, workingDirectory) {
79
79
  cliCore.CLIDisplay.break();
80
80
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.ts-to-schema.progress.writingSchemas"));
81
81
  for (const typeSource of config.types) {
82
- cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.ts-to-schema.progress.generatingSchema"));
83
82
  const typeSourceParts = typeSource.split("/");
84
83
  const type = core.StringHelper.pascalCase(typeSourceParts[typeSourceParts.length - 1].replace(/(\.d)?\.ts$/, ""), false);
85
- const schemas = await generateSchemas(typeSource, type, workingDirectory);
86
- if (core.Is.empty(schemas[type])) {
87
- throw new core.GeneralError("commands", "commands.ts-to-schema.schemaNotFound", { type });
84
+ let content;
85
+ if (core.Is.object(config.overrides?.[type])) {
86
+ cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.ts-to-schema.progress.overridingSchema"));
87
+ content = JSON.stringify(config.overrides?.[type], undefined, "\t");
88
88
  }
89
- let content = JSON.stringify(schemas[type], undefined, "\t");
90
- if (core.Is.objectValue(config.externalReferences)) {
91
- for (const external in config.externalReferences) {
92
- content = content.replace(new RegExp(`#/definitions/${external}`, "g"), config.externalReferences[external]);
89
+ else {
90
+ cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.ts-to-schema.progress.generatingSchema"));
91
+ const schemas = await generateSchemas(typeSource, type, workingDirectory);
92
+ if (core.Is.empty(schemas[type])) {
93
+ throw new core.GeneralError("commands", "commands.ts-to-schema.schemaNotFound", { type });
94
+ }
95
+ content = JSON.stringify(schemas[type], undefined, "\t");
96
+ if (core.Is.objectValue(config.externalReferences)) {
97
+ for (const external in config.externalReferences) {
98
+ content = content.replace(new RegExp(`#/definitions/${external}`, "g"), config.externalReferences[external]);
99
+ }
93
100
  }
101
+ // First replace all types that start with II to a single I with the new base url
102
+ content = content.replace(/#\/definitions\/II(.*)/g, `${config.baseUrl}I$1`);
103
+ // Then other types starting with capitals (optionally interfaces starting with I)
104
+ content = content.replace(/#\/definitions\/I?([A-Z].*)/g, `${config.baseUrl}$1`);
94
105
  }
95
- // First replace all types that start with II to a single I with the new base url
96
- content = content.replace(/#\/definitions\/II(.*)/g, `${config.baseUrl}I$1`);
97
- // Then other types starting with capitals (optionally interfaces starting with I)
98
- content = content.replace(/#\/definitions\/I?([A-Z].*)/g, `${config.baseUrl}$1`);
99
106
  const filename = path.join(outputFolder, `${core.StringHelper.stripPrefix(type)}.json`);
100
107
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.ts-to-schema.progress.writingSchema"), filename, 1);
101
108
  await promises.writeFile(filename, `${content}\n`);
@@ -220,7 +227,7 @@ class CLI extends cliCore.CLIBase {
220
227
  return this.execute({
221
228
  title: "TWIN TypeScript To Schema",
222
229
  appName: "ts-to-schema",
223
- version: "0.0.1-next.24", // x-release-please-version
230
+ version: "0.0.1-next.25", // x-release-please-version
224
231
  icon: "⚙️ ",
225
232
  supportsEnvFiles: false,
226
233
  overrideOutputWidth: options?.overrideOutputWidth
@@ -76,23 +76,30 @@ async function tsToSchema(config, outputFolder, workingDirectory) {
76
76
  CLIDisplay.break();
77
77
  CLIDisplay.task(I18n.formatMessage("commands.ts-to-schema.progress.writingSchemas"));
78
78
  for (const typeSource of config.types) {
79
- CLIDisplay.task(I18n.formatMessage("commands.ts-to-schema.progress.generatingSchema"));
80
79
  const typeSourceParts = typeSource.split("/");
81
80
  const type = StringHelper.pascalCase(typeSourceParts[typeSourceParts.length - 1].replace(/(\.d)?\.ts$/, ""), false);
82
- const schemas = await generateSchemas(typeSource, type, workingDirectory);
83
- if (Is.empty(schemas[type])) {
84
- throw new GeneralError("commands", "commands.ts-to-schema.schemaNotFound", { type });
81
+ let content;
82
+ if (Is.object(config.overrides?.[type])) {
83
+ CLIDisplay.task(I18n.formatMessage("commands.ts-to-schema.progress.overridingSchema"));
84
+ content = JSON.stringify(config.overrides?.[type], undefined, "\t");
85
85
  }
86
- let content = JSON.stringify(schemas[type], undefined, "\t");
87
- if (Is.objectValue(config.externalReferences)) {
88
- for (const external in config.externalReferences) {
89
- content = content.replace(new RegExp(`#/definitions/${external}`, "g"), config.externalReferences[external]);
86
+ else {
87
+ CLIDisplay.task(I18n.formatMessage("commands.ts-to-schema.progress.generatingSchema"));
88
+ const schemas = await generateSchemas(typeSource, type, workingDirectory);
89
+ if (Is.empty(schemas[type])) {
90
+ throw new GeneralError("commands", "commands.ts-to-schema.schemaNotFound", { type });
91
+ }
92
+ content = JSON.stringify(schemas[type], undefined, "\t");
93
+ if (Is.objectValue(config.externalReferences)) {
94
+ for (const external in config.externalReferences) {
95
+ content = content.replace(new RegExp(`#/definitions/${external}`, "g"), config.externalReferences[external]);
96
+ }
90
97
  }
98
+ // First replace all types that start with II to a single I with the new base url
99
+ content = content.replace(/#\/definitions\/II(.*)/g, `${config.baseUrl}I$1`);
100
+ // Then other types starting with capitals (optionally interfaces starting with I)
101
+ content = content.replace(/#\/definitions\/I?([A-Z].*)/g, `${config.baseUrl}$1`);
91
102
  }
92
- // First replace all types that start with II to a single I with the new base url
93
- content = content.replace(/#\/definitions\/II(.*)/g, `${config.baseUrl}I$1`);
94
- // Then other types starting with capitals (optionally interfaces starting with I)
95
- content = content.replace(/#\/definitions\/I?([A-Z].*)/g, `${config.baseUrl}$1`);
96
103
  const filename = path.join(outputFolder, `${StringHelper.stripPrefix(type)}.json`);
97
104
  CLIDisplay.value(I18n.formatMessage("commands.ts-to-schema.progress.writingSchema"), filename, 1);
98
105
  await writeFile(filename, `${content}\n`);
@@ -217,7 +224,7 @@ class CLI extends CLIBase {
217
224
  return this.execute({
218
225
  title: "TWIN TypeScript To Schema",
219
226
  appName: "ts-to-schema",
220
- version: "0.0.1-next.24", // x-release-please-version
227
+ version: "0.0.1-next.25", // x-release-please-version
221
228
  icon: "⚙️ ",
222
229
  supportsEnvFiles: false,
223
230
  overrideOutputWidth: options?.overrideOutputWidth
@@ -80,6 +80,8 @@
80
80
  "array": "Property \"{property}\" must be an array, it is \"{value}\"",
81
81
  "arrayValue": "Property \"{property}\" must be an array with at least one item",
82
82
  "arrayOneOf": "Property \"{property}\" must be one of [{options}], it is \"{value}\"",
83
+ "arrayStartsWith": "Property \"{property}\" must be an array starting with [{startValues}], it is \"{value}\"",
84
+ "arrayEndsWith": "Property \"{property}\" must be an array ending with [{endValues}], it is \"{value}\"",
83
85
  "uint8Array": "Property \"{property}\" must be a Uint8Array, it is \"{value}\"",
84
86
  "function": "Property \"{property}\" must be a function, it is \"{value}\"",
85
87
  "urn": "Property \"{property}\" must be a Urn formatted string, it is \"{value}\"",
@@ -250,6 +252,7 @@
250
252
  "loadingConfigJson": "Loading Config JSON",
251
253
  "creatingWorkingDir": "Creating Working Directory",
252
254
  "generatingSchema": "Generating Schema",
255
+ "overridingSchema": "Overriding Schema",
253
256
  "writingSchemas": "Writing Schemas",
254
257
  "writingSchema": "Writing Schema",
255
258
  "models": "Models"
@@ -0,0 +1,5 @@
1
+ import type { JsonSchemaDraft202012Object } from "@hyperjump/json-schema/draft-2020-12";
2
+ /**
3
+ * Default schema type.
4
+ */
5
+ export type IJsonSchema = JsonSchemaDraft202012Object;
@@ -1,3 +1,4 @@
1
+ import type { IJsonSchema } from "./IJsonSchema";
1
2
  /**
2
3
  * Configuration for the tool.
3
4
  */
@@ -16,4 +17,10 @@ export interface ITsToSchemaConfig {
16
17
  externalReferences?: {
17
18
  [id: string]: string;
18
19
  };
20
+ /**
21
+ * Override for specific types, to be used when the type cannot be generated automatically, or is generated incorrectly.
22
+ */
23
+ overrides?: {
24
+ [id: string]: IJsonSchema;
25
+ };
19
26
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @twin.org/ts-to-schema - Changelog
2
2
 
3
+ ## [0.0.1-next.25](https://github.com/twinfoundation/tools/compare/ts-to-schema-v0.0.1-next.24...ts-to-schema-v0.0.1-next.25) (2025-06-10)
4
+
5
+
6
+ ### Features
7
+
8
+ * add ts-to-schema overrides ([3c54504](https://github.com/twinfoundation/tools/commit/3c5450468eb998204a75576b7791a7ca4027da62))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/nameof bumped from 0.0.1-next.24 to 0.0.1-next.25
16
+ * devDependencies
17
+ * @twin.org/merge-locales bumped from 0.0.1-next.24 to 0.0.1-next.25
18
+ * @twin.org/nameof-transformer bumped from 0.0.1-next.24 to 0.0.1-next.25
19
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.1-next.24 to 0.0.1-next.25
20
+
3
21
  ## [0.0.1-next.24](https://github.com/twinfoundation/tools/compare/ts-to-schema-v0.0.1-next.23...ts-to-schema-v0.0.1-next.24) (2025-06-05)
4
22
 
5
23
 
@@ -29,3 +29,15 @@ External type references
29
29
  #### Index Signature
30
30
 
31
31
  \[`id`: `string`\]: `string`
32
+
33
+ ***
34
+
35
+ ### overrides?
36
+
37
+ > `optional` **overrides**: `object`
38
+
39
+ Override for specific types, to be used when the type cannot be generated automatically, or is generated incorrectly.
40
+
41
+ #### Index Signature
42
+
43
+ \[`id`: `string`\]: `JsonSchemaDraft202012Object`
package/locales/en.json CHANGED
@@ -23,6 +23,7 @@
23
23
  "loadingConfigJson": "Loading Config JSON",
24
24
  "creatingWorkingDir": "Creating Working Directory",
25
25
  "generatingSchema": "Generating Schema",
26
+ "overridingSchema": "Overriding Schema",
26
27
  "writingSchemas": "Writing Schemas",
27
28
  "writingSchema": "Writing Schema",
28
29
  "models": "Models"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/ts-to-schema",
3
- "version": "0.0.1-next.24",
3
+ "version": "0.0.1-next.25",
4
4
  "description": "Tool to convert TypeScript definitions to JSON schemas",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,12 +14,13 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
+ "@hyperjump/json-pointer": "1.1.1",
18
+ "@hyperjump/json-schema": "1.14.1",
17
19
  "@twin.org/cli-core": "next",
18
20
  "@twin.org/core": "next",
19
- "@twin.org/nameof": "0.0.1-next.24",
20
- "commander": "13.1.0",
21
- "glob": "11.0.1",
22
- "jsonschema": "1.5.0",
21
+ "@twin.org/nameof": "0.0.1-next.25",
22
+ "commander": "14.0.0",
23
+ "glob": "11.0.2",
23
24
  "ts-json-schema-generator": "2.4.0"
24
25
  },
25
26
  "main": "./dist/cjs/index.cjs",