@twin.org/tools-core 0.0.2-next.1 → 0.0.2-next.2

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.
@@ -147,10 +147,13 @@ class JsonSchemaHelper {
147
147
  */
148
148
  static extractTypes(allSchemas, requiredTypes, referencedSchemas) {
149
149
  for (const typeKey of Object.keys(allSchemas)) {
150
- for (const requiredType of requiredTypes) {
151
- if (new RegExp(requiredType).test(typeKey) && !referencedSchemas[typeKey]) {
152
- referencedSchemas[typeKey] = allSchemas[typeKey];
153
- JsonSchemaHelper.extractTypesFromSchema(allSchemas, allSchemas[typeKey], referencedSchemas);
150
+ if (!referencedSchemas[typeKey]) {
151
+ for (const requiredType of requiredTypes) {
152
+ if ((core.Is.regexp(requiredType) && new RegExp(requiredType).test(typeKey)) ||
153
+ (core.Is.stringValue(requiredType) && requiredType === typeKey)) {
154
+ referencedSchemas[typeKey] = allSchemas[typeKey];
155
+ JsonSchemaHelper.extractTypesFromSchema(allSchemas, allSchemas[typeKey], referencedSchemas);
156
+ }
154
157
  }
155
158
  }
156
159
  }
@@ -223,4 +226,17 @@ class JsonSchemaHelper {
223
226
  }
224
227
  }
225
228
 
229
+ // Copyright 2024 IOTA Stiftung.
230
+ // SPDX-License-Identifier: Apache-2.0.
231
+ /**
232
+ * Helper class for OpenAPI processing.
233
+ */
234
+ class OpenApiHelper {
235
+ /**
236
+ * The OpenAPI version used.
237
+ */
238
+ static API_VERSION = "3.1.1";
239
+ }
240
+
226
241
  exports.JsonSchemaHelper = JsonSchemaHelper;
242
+ exports.OpenApiHelper = OpenApiHelper;
@@ -145,10 +145,13 @@ class JsonSchemaHelper {
145
145
  */
146
146
  static extractTypes(allSchemas, requiredTypes, referencedSchemas) {
147
147
  for (const typeKey of Object.keys(allSchemas)) {
148
- for (const requiredType of requiredTypes) {
149
- if (new RegExp(requiredType).test(typeKey) && !referencedSchemas[typeKey]) {
150
- referencedSchemas[typeKey] = allSchemas[typeKey];
151
- JsonSchemaHelper.extractTypesFromSchema(allSchemas, allSchemas[typeKey], referencedSchemas);
148
+ if (!referencedSchemas[typeKey]) {
149
+ for (const requiredType of requiredTypes) {
150
+ if ((Is.regexp(requiredType) && new RegExp(requiredType).test(typeKey)) ||
151
+ (Is.stringValue(requiredType) && requiredType === typeKey)) {
152
+ referencedSchemas[typeKey] = allSchemas[typeKey];
153
+ JsonSchemaHelper.extractTypesFromSchema(allSchemas, allSchemas[typeKey], referencedSchemas);
154
+ }
152
155
  }
153
156
  }
154
157
  }
@@ -221,4 +224,16 @@ class JsonSchemaHelper {
221
224
  }
222
225
  }
223
226
 
224
- export { JsonSchemaHelper };
227
+ // Copyright 2024 IOTA Stiftung.
228
+ // SPDX-License-Identifier: Apache-2.0.
229
+ /**
230
+ * Helper class for OpenAPI processing.
231
+ */
232
+ class OpenApiHelper {
233
+ /**
234
+ * The OpenAPI version used.
235
+ */
236
+ static API_VERSION = "3.1.1";
237
+ }
238
+
239
+ export { JsonSchemaHelper, OpenApiHelper };
@@ -1,4 +1,11 @@
1
1
  export * from "./models/IJsonSchema";
2
+ export * from "./models/IOpenApi";
3
+ export * from "./models/IOpenApiExample";
4
+ export * from "./models/IOpenApiHeader";
5
+ export * from "./models/IOpenApiPathMethod";
6
+ export * from "./models/IOpenApiResponse";
7
+ export * from "./models/IOpenApiSecurityScheme";
2
8
  export * from "./models/IPackageJson";
3
9
  export * from "./models/jsonTypeName";
4
10
  export * from "./utils/jsonSchemaHelper";
11
+ export * from "./utils/openApiHelper";
@@ -0,0 +1,54 @@
1
+ import type { IJsonSchema } from "./IJsonSchema";
2
+ import type { IOpenApiPathMethod } from "./IOpenApiPathMethod";
3
+ import type { IOpenApiSecurityScheme } from "./IOpenApiSecurityScheme";
4
+ /**
5
+ * The Open API config definition.
6
+ */
7
+ export interface IOpenApi {
8
+ /**
9
+ * The open api version.
10
+ */
11
+ openapi: string;
12
+ /**
13
+ * Info.
14
+ */
15
+ info: {
16
+ title: string;
17
+ version: string;
18
+ description: string;
19
+ license?: {
20
+ name: string;
21
+ url: string;
22
+ };
23
+ };
24
+ /**
25
+ * The servers for the endpoints.
26
+ */
27
+ servers?: {
28
+ url: string;
29
+ }[];
30
+ /**
31
+ * Tags for the endpoints.
32
+ */
33
+ tags?: {
34
+ name: string;
35
+ description: string;
36
+ }[];
37
+ /**
38
+ * The paths.
39
+ */
40
+ paths: {
41
+ [path: string]: {
42
+ [method: string]: IOpenApiPathMethod;
43
+ };
44
+ };
45
+ /**
46
+ * The components.
47
+ */
48
+ components?: {
49
+ schemas?: IJsonSchema;
50
+ securitySchemes?: {
51
+ [name: string]: IOpenApiSecurityScheme;
52
+ };
53
+ };
54
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The Open API config definition.
3
+ */
4
+ export interface IOpenApiExample {
5
+ /**
6
+ * The summary of the example.
7
+ */
8
+ summary?: string;
9
+ /**
10
+ * The value of the example.
11
+ */
12
+ value: unknown;
13
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The Open API config definition.
3
+ */
4
+ export interface IOpenApiHeader {
5
+ /**
6
+ * The schema of the header.
7
+ */
8
+ schema?: {
9
+ type: string;
10
+ };
11
+ /**
12
+ * The description of the header.
13
+ */
14
+ description?: string;
15
+ /**
16
+ * The format of the header.
17
+ */
18
+ format?: string;
19
+ }
@@ -0,0 +1,65 @@
1
+ import type { IJsonSchema } from "./IJsonSchema";
2
+ import type { IOpenApiExample } from "./IOpenApiExample";
3
+ import type { IOpenApiResponse } from "./IOpenApiResponse";
4
+ import type { JsonTypeName } from "./jsonTypeName";
5
+ /**
6
+ * The Open API config definition.
7
+ */
8
+ export interface IOpenApiPathMethod {
9
+ /**
10
+ * The operation id.
11
+ */
12
+ operationId: string;
13
+ /**
14
+ * Summary.
15
+ */
16
+ summary: string;
17
+ /**
18
+ * Tags.
19
+ */
20
+ tags?: string[];
21
+ /**
22
+ * Parameters.
23
+ */
24
+ parameters?: {
25
+ name: string;
26
+ in: string;
27
+ description?: string;
28
+ required: boolean;
29
+ schema: {
30
+ type?: JsonTypeName | JsonTypeName[];
31
+ enum?: IJsonSchema[];
32
+ $ref?: string;
33
+ };
34
+ style?: string;
35
+ }[];
36
+ /**
37
+ * Request body.
38
+ */
39
+ requestBody?: {
40
+ required: boolean;
41
+ description?: string;
42
+ content?: {
43
+ [contentType: string]: {
44
+ schema: {
45
+ $ref: string;
46
+ };
47
+ examples?: {
48
+ [id: string]: IOpenApiExample;
49
+ };
50
+ };
51
+ };
52
+ };
53
+ /**
54
+ * Response body.
55
+ */
56
+ responses?: {
57
+ [code: string]: IOpenApiResponse;
58
+ };
59
+ /**
60
+ * Security model for the API.
61
+ */
62
+ security?: {
63
+ [name: string]: string[];
64
+ }[];
65
+ }
@@ -0,0 +1,32 @@
1
+ import type { IOpenApiExample } from "./IOpenApiExample";
2
+ import type { IOpenApiHeader } from "./IOpenApiHeader";
3
+ /**
4
+ * The Open API config definition.
5
+ */
6
+ export interface IOpenApiResponse {
7
+ /**
8
+ * Descriptions for the response.
9
+ */
10
+ description?: string;
11
+ /**
12
+ * Content for the response.
13
+ */
14
+ content?: {
15
+ [contentType: string]: {
16
+ schema: {
17
+ type?: string;
18
+ format?: string;
19
+ $ref?: string;
20
+ };
21
+ examples?: {
22
+ [id: string]: IOpenApiExample;
23
+ };
24
+ };
25
+ };
26
+ /**
27
+ * The headers for the response.
28
+ */
29
+ headers?: {
30
+ [id: string]: IOpenApiHeader;
31
+ };
32
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The Open API config definition for security scheme.
3
+ */
4
+ export interface IOpenApiSecurityScheme {
5
+ /**
6
+ * The type of the security schema.
7
+ */
8
+ type?: string;
9
+ /**
10
+ * The scheme method.
11
+ */
12
+ scheme?: string;
13
+ /**
14
+ * The bearer format.
15
+ */
16
+ bearerFormat?: string;
17
+ /**
18
+ * Where is the token located.
19
+ */
20
+ in?: string;
21
+ /**
22
+ * What is the name of the token.
23
+ */
24
+ name?: string;
25
+ }
@@ -11,7 +11,7 @@ export declare class JsonSchemaHelper {
11
11
  * Process arrays in the schema object.
12
12
  * @param schemaObject The schema object to process.
13
13
  */
14
- static processArrays(schemaObject?: IJsonSchema): void;
14
+ static processArrays(schemaObject: IJsonSchema): void;
15
15
  /**
16
16
  * Process arrays in the schema object.
17
17
  * @param schemaDictionary The schema object to process.
@@ -49,7 +49,7 @@ export declare class JsonSchemaHelper {
49
49
  */
50
50
  static extractTypes(allSchemas: {
51
51
  [id: string]: IJsonSchema;
52
- }, requiredTypes: string[], referencedSchemas: {
52
+ }, requiredTypes: (string | RegExp)[], referencedSchemas: {
53
53
  [id: string]: IJsonSchema;
54
54
  }): void;
55
55
  /**
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Helper class for OpenAPI processing.
3
+ */
4
+ export declare class OpenApiHelper {
5
+ /**
6
+ * The OpenAPI version used.
7
+ */
8
+ static readonly API_VERSION = "3.1.1";
9
+ }
package/docs/changelog.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.2-next.2](https://github.com/twinfoundation/tools/compare/tools-core-v0.0.2-next.1...tools-core-v0.0.2-next.2) (2025-07-17)
4
+
5
+
6
+ ### Features
7
+
8
+ * improve auto expand types ([6181d1d](https://github.com/twinfoundation/tools/commit/6181d1daded1f91323195cf7efbc2f1881f38b41))
9
+
3
10
  ## [0.0.2-next.1](https://github.com/twinfoundation/tools/compare/tools-core-v0.0.2-next.0...tools-core-v0.0.2-next.1) (2025-07-14)
4
11
 
5
12
 
@@ -24,13 +24,13 @@ The JSON Schema version used.
24
24
 
25
25
  ### processArrays()
26
26
 
27
- > `static` **processArrays**(`schemaObject?`): `void`
27
+ > `static` **processArrays**(`schemaObject`): `void`
28
28
 
29
29
  Process arrays in the schema object.
30
30
 
31
31
  #### Parameters
32
32
 
33
- ##### schemaObject?
33
+ ##### schemaObject
34
34
 
35
35
  `AnySchemaObject`
36
36
 
@@ -144,7 +144,7 @@ All the known schemas.
144
144
 
145
145
  ##### requiredTypes
146
146
 
147
- `string`[]
147
+ (`string` \| `RegExp`)[]
148
148
 
149
149
  The required types.
150
150
 
@@ -0,0 +1,21 @@
1
+ # Class: OpenApiHelper
2
+
3
+ Helper class for OpenAPI processing.
4
+
5
+ ## Constructors
6
+
7
+ ### Constructor
8
+
9
+ > **new OpenApiHelper**(): `OpenApiHelper`
10
+
11
+ #### Returns
12
+
13
+ `OpenApiHelper`
14
+
15
+ ## Properties
16
+
17
+ ### API\_VERSION
18
+
19
+ > `readonly` `static` **API\_VERSION**: `"3.1.1"` = `"3.1.1"`
20
+
21
+ The OpenAPI version used.
@@ -3,9 +3,16 @@
3
3
  ## Classes
4
4
 
5
5
  - [JsonSchemaHelper](classes/JsonSchemaHelper.md)
6
+ - [OpenApiHelper](classes/OpenApiHelper.md)
6
7
 
7
8
  ## Interfaces
8
9
 
10
+ - [IOpenApi](interfaces/IOpenApi.md)
11
+ - [IOpenApiExample](interfaces/IOpenApiExample.md)
12
+ - [IOpenApiHeader](interfaces/IOpenApiHeader.md)
13
+ - [IOpenApiPathMethod](interfaces/IOpenApiPathMethod.md)
14
+ - [IOpenApiResponse](interfaces/IOpenApiResponse.md)
15
+ - [IOpenApiSecurityScheme](interfaces/IOpenApiSecurityScheme.md)
9
16
  - [IPackageJson](interfaces/IPackageJson.md)
10
17
 
11
18
  ## Type Aliases
@@ -0,0 +1,103 @@
1
+ # Interface: IOpenApi
2
+
3
+ The Open API config definition.
4
+
5
+ ## Properties
6
+
7
+ ### openapi
8
+
9
+ > **openapi**: `string`
10
+
11
+ The open api version.
12
+
13
+ ***
14
+
15
+ ### info
16
+
17
+ > **info**: `object`
18
+
19
+ Info.
20
+
21
+ #### title
22
+
23
+ > **title**: `string`
24
+
25
+ #### version
26
+
27
+ > **version**: `string`
28
+
29
+ #### description
30
+
31
+ > **description**: `string`
32
+
33
+ #### license?
34
+
35
+ > `optional` **license**: `object`
36
+
37
+ ##### license.name
38
+
39
+ > **name**: `string`
40
+
41
+ ##### license.url
42
+
43
+ > **url**: `string`
44
+
45
+ ***
46
+
47
+ ### servers?
48
+
49
+ > `optional` **servers**: `object`[]
50
+
51
+ The servers for the endpoints.
52
+
53
+ #### url
54
+
55
+ > **url**: `string`
56
+
57
+ ***
58
+
59
+ ### tags?
60
+
61
+ > `optional` **tags**: `object`[]
62
+
63
+ Tags for the endpoints.
64
+
65
+ #### name
66
+
67
+ > **name**: `string`
68
+
69
+ #### description
70
+
71
+ > **description**: `string`
72
+
73
+ ***
74
+
75
+ ### paths
76
+
77
+ > **paths**: `object`
78
+
79
+ The paths.
80
+
81
+ #### Index Signature
82
+
83
+ \[`path`: `string`\]: `object`
84
+
85
+ ***
86
+
87
+ ### components?
88
+
89
+ > `optional` **components**: `object`
90
+
91
+ The components.
92
+
93
+ #### schemas?
94
+
95
+ > `optional` **schemas**: `AnySchemaObject`
96
+
97
+ #### securitySchemes?
98
+
99
+ > `optional` **securitySchemes**: `object`
100
+
101
+ ##### Index Signature
102
+
103
+ \[`name`: `string`\]: [`IOpenApiSecurityScheme`](IOpenApiSecurityScheme.md)
@@ -0,0 +1,19 @@
1
+ # Interface: IOpenApiExample
2
+
3
+ The Open API config definition.
4
+
5
+ ## Properties
6
+
7
+ ### summary?
8
+
9
+ > `optional` **summary**: `string`
10
+
11
+ The summary of the example.
12
+
13
+ ***
14
+
15
+ ### value
16
+
17
+ > **value**: `unknown`
18
+
19
+ The value of the example.
@@ -0,0 +1,31 @@
1
+ # Interface: IOpenApiHeader
2
+
3
+ The Open API config definition.
4
+
5
+ ## Properties
6
+
7
+ ### schema?
8
+
9
+ > `optional` **schema**: `object`
10
+
11
+ The schema of the header.
12
+
13
+ #### type
14
+
15
+ > **type**: `string`
16
+
17
+ ***
18
+
19
+ ### description?
20
+
21
+ > `optional` **description**: `string`
22
+
23
+ The description of the header.
24
+
25
+ ***
26
+
27
+ ### format?
28
+
29
+ > `optional` **format**: `string`
30
+
31
+ The format of the header.
@@ -0,0 +1,119 @@
1
+ # Interface: IOpenApiPathMethod
2
+
3
+ The Open API config definition.
4
+
5
+ ## Properties
6
+
7
+ ### operationId
8
+
9
+ > **operationId**: `string`
10
+
11
+ The operation id.
12
+
13
+ ***
14
+
15
+ ### summary
16
+
17
+ > **summary**: `string`
18
+
19
+ Summary.
20
+
21
+ ***
22
+
23
+ ### tags?
24
+
25
+ > `optional` **tags**: `string`[]
26
+
27
+ Tags.
28
+
29
+ ***
30
+
31
+ ### parameters?
32
+
33
+ > `optional` **parameters**: `object`[]
34
+
35
+ Parameters.
36
+
37
+ #### name
38
+
39
+ > **name**: `string`
40
+
41
+ #### in
42
+
43
+ > **in**: `string`
44
+
45
+ #### description?
46
+
47
+ > `optional` **description**: `string`
48
+
49
+ #### required
50
+
51
+ > **required**: `boolean`
52
+
53
+ #### schema
54
+
55
+ > **schema**: `object`
56
+
57
+ ##### schema.type?
58
+
59
+ > `optional` **type**: `"string"` \| `"number"` \| `"boolean"` \| `"object"` \| `"integer"` \| `"null"` \| `"array"` \| (`"string"` \| `"number"` \| `"boolean"` \| `"object"` \| `"integer"` \| `"null"` \| `"array"`)[]
60
+
61
+ ##### schema.enum?
62
+
63
+ > `optional` **enum**: `AnySchemaObject`[]
64
+
65
+ ##### schema.$ref?
66
+
67
+ > `optional` **$ref**: `string`
68
+
69
+ #### style?
70
+
71
+ > `optional` **style**: `string`
72
+
73
+ ***
74
+
75
+ ### requestBody?
76
+
77
+ > `optional` **requestBody**: `object`
78
+
79
+ Request body.
80
+
81
+ #### required
82
+
83
+ > **required**: `boolean`
84
+
85
+ #### description?
86
+
87
+ > `optional` **description**: `string`
88
+
89
+ #### content?
90
+
91
+ > `optional` **content**: `object`
92
+
93
+ ##### Index Signature
94
+
95
+ \[`contentType`: `string`\]: `object`
96
+
97
+ ***
98
+
99
+ ### responses?
100
+
101
+ > `optional` **responses**: `object`
102
+
103
+ Response body.
104
+
105
+ #### Index Signature
106
+
107
+ \[`code`: `string`\]: [`IOpenApiResponse`](IOpenApiResponse.md)
108
+
109
+ ***
110
+
111
+ ### security?
112
+
113
+ > `optional` **security**: `object`[]
114
+
115
+ Security model for the API.
116
+
117
+ #### Index Signature
118
+
119
+ \[`name`: `string`\]: `string`[]
@@ -0,0 +1,35 @@
1
+ # Interface: IOpenApiResponse
2
+
3
+ The Open API config definition.
4
+
5
+ ## Properties
6
+
7
+ ### description?
8
+
9
+ > `optional` **description**: `string`
10
+
11
+ Descriptions for the response.
12
+
13
+ ***
14
+
15
+ ### content?
16
+
17
+ > `optional` **content**: `object`
18
+
19
+ Content for the response.
20
+
21
+ #### Index Signature
22
+
23
+ \[`contentType`: `string`\]: `object`
24
+
25
+ ***
26
+
27
+ ### headers?
28
+
29
+ > `optional` **headers**: `object`
30
+
31
+ The headers for the response.
32
+
33
+ #### Index Signature
34
+
35
+ \[`id`: `string`\]: [`IOpenApiHeader`](IOpenApiHeader.md)
@@ -0,0 +1,43 @@
1
+ # Interface: IOpenApiSecurityScheme
2
+
3
+ The Open API config definition for security scheme.
4
+
5
+ ## Properties
6
+
7
+ ### type?
8
+
9
+ > `optional` **type**: `string`
10
+
11
+ The type of the security schema.
12
+
13
+ ***
14
+
15
+ ### scheme?
16
+
17
+ > `optional` **scheme**: `string`
18
+
19
+ The scheme method.
20
+
21
+ ***
22
+
23
+ ### bearerFormat?
24
+
25
+ > `optional` **bearerFormat**: `string`
26
+
27
+ The bearer format.
28
+
29
+ ***
30
+
31
+ ### in?
32
+
33
+ > `optional` **in**: `string`
34
+
35
+ Where is the token located.
36
+
37
+ ***
38
+
39
+ ### name?
40
+
41
+ > `optional` **name**: `string`
42
+
43
+ What is the name of the token.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/tools-core",
3
- "version": "0.0.2-next.1",
3
+ "version": "0.0.2-next.2",
4
4
  "description": "Shared components for the tools",
5
5
  "repository": {
6
6
  "type": "git",