@twin.org/ts-to-openapi 0.0.1-next.25 → 0.0.1-next.27

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.
@@ -659,11 +659,13 @@ async function finaliseOutput(usedCommonResponseTypes, schemas, openApi, securit
659
659
  }
660
660
  }
661
661
  }
662
- if (finalSchemas.HttpStatusCode) {
663
- delete finalSchemas.HttpStatusCode;
662
+ // Remove standard types that we don't want in the final output
663
+ const removeTypes = ["HttpStatusCode", "Uint8Array", "ArrayBuffer"];
664
+ for (const type of removeTypes) {
665
+ delete finalSchemas[type];
664
666
  }
665
- if (finalSchemas.Uint8Array) {
666
- delete finalSchemas.Uint8Array;
667
+ for (const type in finalSchemas) {
668
+ processArrays(finalSchemas[type]);
667
669
  }
668
670
  const schemaKeys = Object.keys(finalSchemas);
669
671
  schemaKeys.sort();
@@ -1098,6 +1100,59 @@ async function loadPackages(tsToOpenApiConfig, outputWorkingDir, typeRoots) {
1098
1100
  }
1099
1101
  return restRoutes;
1100
1102
  }
1103
+ /**
1104
+ * Process arrays in the schema object.
1105
+ * @param schemaObject The schema object to process.
1106
+ */
1107
+ function processArrays(schemaObject) {
1108
+ if (core.Is.object(schemaObject)) {
1109
+ // latest specs have singular items in `items` property
1110
+ // and multiple items in prefixItems, so update the schema accordingly
1111
+ // https://www.learnjsonschema.com/2020-12/applicator/items/
1112
+ // https://www.learnjsonschema.com/2020-12/applicator/prefixitems/
1113
+ const schemaItems = schemaObject.items;
1114
+ if (core.Is.array(schemaItems) || core.Is.object(schemaItems)) {
1115
+ schemaObject.prefixItems = core.ArrayHelper.fromObjectOrArray(schemaItems);
1116
+ delete schemaObject.items;
1117
+ }
1118
+ const additionalItems = schemaObject.additionalItems;
1119
+ if (core.Is.array(additionalItems) || core.Is.object(additionalItems)) {
1120
+ schemaObject.items = core.ArrayHelper.fromObjectOrArray(additionalItems)[0];
1121
+ delete schemaObject.additionalItems;
1122
+ }
1123
+ processSchemaDictionary(schemaObject.properties);
1124
+ processArrays(schemaObject.additionalProperties);
1125
+ processSchemaArray(schemaObject.allOf);
1126
+ processSchemaArray(schemaObject.anyOf);
1127
+ processSchemaArray(schemaObject.oneOf);
1128
+ }
1129
+ }
1130
+ /**
1131
+ * Process arrays in the schema object.
1132
+ * @param schemaDictionary The schema object to process.
1133
+ */
1134
+ function processSchemaDictionary(schemaDictionary) {
1135
+ if (core.Is.object(schemaDictionary)) {
1136
+ for (const item of Object.values(schemaDictionary)) {
1137
+ if (core.Is.object(item)) {
1138
+ processArrays(item);
1139
+ }
1140
+ }
1141
+ }
1142
+ }
1143
+ /**
1144
+ * Process arrays in the schema object.
1145
+ * @param schemaArray The schema object to process.
1146
+ */
1147
+ function processSchemaArray(schemaArray) {
1148
+ if (core.Is.arrayValue(schemaArray)) {
1149
+ for (const item of schemaArray) {
1150
+ if (core.Is.object(item)) {
1151
+ processArrays(item);
1152
+ }
1153
+ }
1154
+ }
1155
+ }
1101
1156
 
1102
1157
  // Copyright 2024 IOTA Stiftung.
1103
1158
  // SPDX-License-Identifier: Apache-2.0.
@@ -1117,7 +1172,7 @@ class CLI extends cliCore.CLIBase {
1117
1172
  return this.execute({
1118
1173
  title: "TWIN TypeScript To OpenAPI",
1119
1174
  appName: "ts-to-openapi",
1120
- version: "0.0.1-next.25", // x-release-please-version
1175
+ version: "0.0.1-next.27", // x-release-please-version
1121
1176
  icon: "⚙️ ",
1122
1177
  supportsEnvFiles: false,
1123
1178
  overrideOutputWidth: options?.overrideOutputWidth
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import { CLIDisplay, CLIUtils, CLIBase } from '@twin.org/cli-core';
4
4
  import { mkdir, rm, writeFile } from 'node:fs/promises';
5
- import { I18n, GeneralError, Is, StringHelper, ObjectHelper } from '@twin.org/core';
5
+ import { I18n, GeneralError, Is, StringHelper, ObjectHelper, ArrayHelper } from '@twin.org/core';
6
6
  import { HttpStatusCode, MimeTypes } from '@twin.org/web';
7
7
  import { createGenerator } from 'ts-json-schema-generator';
8
8
 
@@ -656,11 +656,13 @@ async function finaliseOutput(usedCommonResponseTypes, schemas, openApi, securit
656
656
  }
657
657
  }
658
658
  }
659
- if (finalSchemas.HttpStatusCode) {
660
- delete finalSchemas.HttpStatusCode;
659
+ // Remove standard types that we don't want in the final output
660
+ const removeTypes = ["HttpStatusCode", "Uint8Array", "ArrayBuffer"];
661
+ for (const type of removeTypes) {
662
+ delete finalSchemas[type];
661
663
  }
662
- if (finalSchemas.Uint8Array) {
663
- delete finalSchemas.Uint8Array;
664
+ for (const type in finalSchemas) {
665
+ processArrays(finalSchemas[type]);
664
666
  }
665
667
  const schemaKeys = Object.keys(finalSchemas);
666
668
  schemaKeys.sort();
@@ -1095,6 +1097,59 @@ async function loadPackages(tsToOpenApiConfig, outputWorkingDir, typeRoots) {
1095
1097
  }
1096
1098
  return restRoutes;
1097
1099
  }
1100
+ /**
1101
+ * Process arrays in the schema object.
1102
+ * @param schemaObject The schema object to process.
1103
+ */
1104
+ function processArrays(schemaObject) {
1105
+ if (Is.object(schemaObject)) {
1106
+ // latest specs have singular items in `items` property
1107
+ // and multiple items in prefixItems, so update the schema accordingly
1108
+ // https://www.learnjsonschema.com/2020-12/applicator/items/
1109
+ // https://www.learnjsonschema.com/2020-12/applicator/prefixitems/
1110
+ const schemaItems = schemaObject.items;
1111
+ if (Is.array(schemaItems) || Is.object(schemaItems)) {
1112
+ schemaObject.prefixItems = ArrayHelper.fromObjectOrArray(schemaItems);
1113
+ delete schemaObject.items;
1114
+ }
1115
+ const additionalItems = schemaObject.additionalItems;
1116
+ if (Is.array(additionalItems) || Is.object(additionalItems)) {
1117
+ schemaObject.items = ArrayHelper.fromObjectOrArray(additionalItems)[0];
1118
+ delete schemaObject.additionalItems;
1119
+ }
1120
+ processSchemaDictionary(schemaObject.properties);
1121
+ processArrays(schemaObject.additionalProperties);
1122
+ processSchemaArray(schemaObject.allOf);
1123
+ processSchemaArray(schemaObject.anyOf);
1124
+ processSchemaArray(schemaObject.oneOf);
1125
+ }
1126
+ }
1127
+ /**
1128
+ * Process arrays in the schema object.
1129
+ * @param schemaDictionary The schema object to process.
1130
+ */
1131
+ function processSchemaDictionary(schemaDictionary) {
1132
+ if (Is.object(schemaDictionary)) {
1133
+ for (const item of Object.values(schemaDictionary)) {
1134
+ if (Is.object(item)) {
1135
+ processArrays(item);
1136
+ }
1137
+ }
1138
+ }
1139
+ }
1140
+ /**
1141
+ * Process arrays in the schema object.
1142
+ * @param schemaArray The schema object to process.
1143
+ */
1144
+ function processSchemaArray(schemaArray) {
1145
+ if (Is.arrayValue(schemaArray)) {
1146
+ for (const item of schemaArray) {
1147
+ if (Is.object(item)) {
1148
+ processArrays(item);
1149
+ }
1150
+ }
1151
+ }
1152
+ }
1098
1153
 
1099
1154
  // Copyright 2024 IOTA Stiftung.
1100
1155
  // SPDX-License-Identifier: Apache-2.0.
@@ -1114,7 +1169,7 @@ class CLI extends CLIBase {
1114
1169
  return this.execute({
1115
1170
  title: "TWIN TypeScript To OpenAPI",
1116
1171
  appName: "ts-to-openapi",
1117
- version: "0.0.1-next.25", // x-release-please-version
1172
+ version: "0.0.1-next.27", // x-release-please-version
1118
1173
  icon: "⚙️ ",
1119
1174
  supportsEnvFiles: false,
1120
1175
  overrideOutputWidth: options?.overrideOutputWidth
@@ -1,5 +1,5 @@
1
- import type { JsonSchemaDraft202012Object } from "@hyperjump/json-schema/draft-2020-12";
1
+ import type { AnySchemaObject } from "ajv/dist/2020.js";
2
2
  /**
3
3
  * Default schema type.
4
4
  */
5
- export type IJsonSchema = JsonSchemaDraft202012Object;
5
+ export type IJsonSchema = AnySchemaObject;
@@ -1,7 +1,7 @@
1
- import type { Json } from "@hyperjump/json-pointer";
2
- import type { JsonSchemaType } from "@hyperjump/json-schema";
1
+ import type { IJsonSchema } from "./IJsonSchema";
3
2
  import type { IOpenApiExample } from "./IOpenApiExample";
4
3
  import type { IOpenApiResponse } from "./IOpenApiResponse";
4
+ import type { JsonTypeName } from "./jsonTypeName";
5
5
  /**
6
6
  * The Open API config definition.
7
7
  */
@@ -27,8 +27,8 @@ export interface IOpenApiPathMethod {
27
27
  description?: string;
28
28
  required: boolean;
29
29
  schema: {
30
- type?: JsonSchemaType | JsonSchemaType[];
31
- enum?: Json[];
30
+ type?: JsonTypeName | JsonTypeName[];
31
+ enum?: IJsonSchema[];
32
32
  $ref?: string;
33
33
  };
34
34
  style?: string;
@@ -0,0 +1,5 @@
1
+ import type { JSONType } from "ajv/dist/2020.js";
2
+ /**
3
+ * Default schema type.
4
+ */
5
+ export type JsonTypeName = JSONType;
package/docs/changelog.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # @twin.org/ts-to-openapi - Changelog
2
2
 
3
+ ## [0.0.1-next.27](https://github.com/twinfoundation/tools/compare/ts-to-openapi-v0.0.1-next.26...ts-to-openapi-v0.0.1-next.27) (2025-06-17)
4
+
5
+
6
+ ### Features
7
+
8
+ * add latest json schema features ([494293f](https://github.com/twinfoundation/tools/commit/494293f4252b9c7d4a20790ec157fc9d8c96c3d2))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/nameof bumped from 0.0.1-next.26 to 0.0.1-next.27
16
+ * devDependencies
17
+ * @twin.org/merge-locales bumped from 0.0.1-next.26 to 0.0.1-next.27
18
+ * @twin.org/nameof-transformer bumped from 0.0.1-next.26 to 0.0.1-next.27
19
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.1-next.26 to 0.0.1-next.27
20
+
21
+ ## [0.0.1-next.26](https://github.com/twinfoundation/tools/compare/ts-to-openapi-v0.0.1-next.25...ts-to-openapi-v0.0.1-next.26) (2025-06-11)
22
+
23
+
24
+ ### Features
25
+
26
+ * use most recent JSON schema specs ([4598cbf](https://github.com/twinfoundation/tools/commit/4598cbf29f7b82dba4a9f3b19f81dfe66f5a6060))
27
+
28
+
29
+ ### Dependencies
30
+
31
+ * The following workspace dependencies were updated
32
+ * dependencies
33
+ * @twin.org/nameof bumped from 0.0.1-next.25 to 0.0.1-next.26
34
+ * devDependencies
35
+ * @twin.org/merge-locales bumped from 0.0.1-next.25 to 0.0.1-next.26
36
+ * @twin.org/nameof-transformer bumped from 0.0.1-next.25 to 0.0.1-next.26
37
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.1-next.25 to 0.0.1-next.26
38
+
3
39
  ## [0.0.1-next.25](https://github.com/twinfoundation/tools/compare/ts-to-openapi-v0.0.1-next.24...ts-to-openapi-v0.0.1-next.25) (2025-06-10)
4
40
 
5
41
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/ts-to-openapi",
3
- "version": "0.0.1-next.25",
3
+ "version": "0.0.1-next.27",
4
4
  "description": "Tool to convert TypeScript REST route definitions to OpenAPI Specifications",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,13 +14,12 @@
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",
19
17
  "@twin.org/api-models": "next",
20
18
  "@twin.org/cli-core": "next",
21
19
  "@twin.org/core": "next",
22
- "@twin.org/nameof": "0.0.1-next.25",
20
+ "@twin.org/nameof": "0.0.1-next.27",
23
21
  "@twin.org/web": "next",
22
+ "ajv": "8.17.1",
24
23
  "commander": "14.0.0",
25
24
  "glob": "11.0.2",
26
25
  "ts-json-schema-generator": "2.4.0"