@twin.org/tools-core 0.0.2-next.9 → 0.0.3-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.
Files changed (32) hide show
  1. package/dist/es/index.js +14 -0
  2. package/dist/es/index.js.map +1 -0
  3. package/dist/es/models/IJsonSchema.js +2 -0
  4. package/dist/es/models/IJsonSchema.js.map +1 -0
  5. package/dist/es/models/IOpenApi.js +2 -0
  6. package/dist/es/models/IOpenApi.js.map +1 -0
  7. package/dist/es/models/IOpenApiExample.js +4 -0
  8. package/dist/es/models/IOpenApiExample.js.map +1 -0
  9. package/dist/es/models/IOpenApiHeader.js +4 -0
  10. package/dist/es/models/IOpenApiHeader.js.map +1 -0
  11. package/dist/es/models/IOpenApiPathMethod.js +2 -0
  12. package/dist/es/models/IOpenApiPathMethod.js.map +1 -0
  13. package/dist/es/models/IOpenApiResponse.js +2 -0
  14. package/dist/es/models/IOpenApiResponse.js.map +1 -0
  15. package/dist/es/models/IOpenApiSecurityScheme.js +4 -0
  16. package/dist/es/models/IOpenApiSecurityScheme.js.map +1 -0
  17. package/dist/es/models/IPackageJson.js +4 -0
  18. package/dist/es/models/IPackageJson.js.map +1 -0
  19. package/dist/es/models/jsonTypeName.js +2 -0
  20. package/dist/es/models/jsonTypeName.js.map +1 -0
  21. package/dist/{esm/index.mjs → es/utils/jsonSchemaHelper.js} +33 -28
  22. package/dist/es/utils/jsonSchemaHelper.js.map +1 -0
  23. package/dist/es/utils/openApiHelper.js +12 -0
  24. package/dist/es/utils/openApiHelper.js.map +1 -0
  25. package/dist/types/index.d.ts +11 -11
  26. package/dist/types/models/IOpenApi.d.ts +3 -3
  27. package/dist/types/models/IOpenApiPathMethod.d.ts +4 -4
  28. package/dist/types/models/IOpenApiResponse.d.ts +2 -2
  29. package/dist/types/utils/jsonSchemaHelper.d.ts +1 -1
  30. package/docs/changelog.md +30 -0
  31. package/package.json +21 -8
  32. package/dist/cjs/index.cjs +0 -256
@@ -0,0 +1,14 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export * from "./models/IJsonSchema.js";
4
+ export * from "./models/IOpenApi.js";
5
+ export * from "./models/IOpenApiExample.js";
6
+ export * from "./models/IOpenApiHeader.js";
7
+ export * from "./models/IOpenApiPathMethod.js";
8
+ export * from "./models/IOpenApiResponse.js";
9
+ export * from "./models/IOpenApiSecurityScheme.js";
10
+ export * from "./models/IPackageJson.js";
11
+ export * from "./models/jsonTypeName.js";
12
+ export * from "./utils/jsonSchemaHelper.js";
13
+ export * from "./utils/openApiHelper.js";
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./models/IJsonSchema.js\";\nexport * from \"./models/IOpenApi.js\";\nexport * from \"./models/IOpenApiExample.js\";\nexport * from \"./models/IOpenApiHeader.js\";\nexport * from \"./models/IOpenApiPathMethod.js\";\nexport * from \"./models/IOpenApiResponse.js\";\nexport * from \"./models/IOpenApiSecurityScheme.js\";\nexport * from \"./models/IPackageJson.js\";\nexport * from \"./models/jsonTypeName.js\";\nexport * from \"./utils/jsonSchemaHelper.js\";\nexport * from \"./utils/openApiHelper.js\";\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IJsonSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IJsonSchema.js","sourceRoot":"","sources":["../../../src/models/IJsonSchema.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { AnySchemaObject } from \"ajv/dist/2020.js\";\n\n/**\n * Default schema type.\n */\nexport type IJsonSchema = AnySchemaObject;\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IOpenApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IOpenApi.js","sourceRoot":"","sources":["../../../src/models/IOpenApi.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IJsonSchema } from \"./IJsonSchema.js\";\nimport type { IOpenApiPathMethod } from \"./IOpenApiPathMethod.js\";\nimport type { IOpenApiSecurityScheme } from \"./IOpenApiSecurityScheme.js\";\n\n/**\n * The Open API config definition.\n */\nexport interface IOpenApi {\n\t/**\n\t * The open api version.\n\t */\n\topenapi: string;\n\n\t/**\n\t * Info.\n\t */\n\tinfo: {\n\t\ttitle: string;\n\t\tversion: string;\n\t\tdescription: string;\n\t\tlicense?: {\n\t\t\tname: string;\n\t\t\turl: string;\n\t\t};\n\t};\n\n\t/**\n\t * The servers for the endpoints.\n\t */\n\tservers?: {\n\t\turl: string;\n\t}[];\n\n\t/**\n\t * Tags for the endpoints.\n\t */\n\ttags?: {\n\t\tname: string;\n\t\tdescription: string;\n\t}[];\n\n\t/**\n\t * The paths.\n\t */\n\tpaths: {\n\t\t[path: string]: {\n\t\t\t[method: string]: IOpenApiPathMethod;\n\t\t};\n\t};\n\n\t/**\n\t * The components.\n\t */\n\tcomponents?: {\n\t\tschemas?: IJsonSchema;\n\t\tsecuritySchemes?: {\n\t\t\t[name: string]: IOpenApiSecurityScheme;\n\t\t};\n\t};\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=IOpenApiExample.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IOpenApiExample.js","sourceRoot":"","sources":["../../../src/models/IOpenApiExample.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The Open API config definition.\n */\nexport interface IOpenApiExample {\n\t/**\n\t * The summary of the example.\n\t */\n\tsummary?: string;\n\n\t/**\n\t * The value of the example.\n\t */\n\tvalue: unknown;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=IOpenApiHeader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IOpenApiHeader.js","sourceRoot":"","sources":["../../../src/models/IOpenApiHeader.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The Open API config definition.\n */\nexport interface IOpenApiHeader {\n\t/**\n\t * The schema of the header.\n\t */\n\tschema?: {\n\t\ttype: string;\n\t};\n\n\t/**\n\t * The description of the header.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * The format of the header.\n\t */\n\tformat?: string;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IOpenApiPathMethod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IOpenApiPathMethod.js","sourceRoot":"","sources":["../../../src/models/IOpenApiPathMethod.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IJsonSchema } from \"./IJsonSchema.js\";\nimport type { IOpenApiExample } from \"./IOpenApiExample.js\";\nimport type { IOpenApiResponse } from \"./IOpenApiResponse.js\";\nimport type { JsonTypeName } from \"./jsonTypeName.js\";\n\n/**\n * The Open API config definition.\n */\nexport interface IOpenApiPathMethod {\n\t/**\n\t * The operation id.\n\t */\n\toperationId: string;\n\n\t/**\n\t * Summary.\n\t */\n\tsummary: string;\n\n\t/**\n\t * Tags.\n\t */\n\ttags?: string[];\n\n\t/**\n\t * Parameters.\n\t */\n\tparameters?: {\n\t\tname: string;\n\t\tin: string;\n\t\tdescription?: string;\n\t\trequired: boolean;\n\t\tschema: {\n\t\t\ttype?: JsonTypeName | JsonTypeName[];\n\t\t\tenum?: IJsonSchema[];\n\t\t\t$ref?: string;\n\t\t};\n\t\tstyle?: string;\n\t}[];\n\n\t/**\n\t * Request body.\n\t */\n\trequestBody?: {\n\t\trequired: boolean;\n\t\tdescription?: string;\n\t\tcontent?: {\n\t\t\t[contentType: string]: {\n\t\t\t\tschema: {\n\t\t\t\t\t$ref: string;\n\t\t\t\t};\n\t\t\t\texamples?: {\n\t\t\t\t\t[id: string]: IOpenApiExample;\n\t\t\t\t};\n\t\t\t};\n\t\t};\n\t};\n\n\t/**\n\t * Response body.\n\t */\n\tresponses?: {\n\t\t[code: string]: IOpenApiResponse;\n\t};\n\n\t/**\n\t * Security model for the API.\n\t */\n\tsecurity?: {\n\t\t[name: string]: string[];\n\t}[];\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IOpenApiResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IOpenApiResponse.js","sourceRoot":"","sources":["../../../src/models/IOpenApiResponse.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IOpenApiExample } from \"./IOpenApiExample.js\";\nimport type { IOpenApiHeader } from \"./IOpenApiHeader.js\";\n\n/**\n * The Open API config definition.\n */\nexport interface IOpenApiResponse {\n\t/**\n\t * Descriptions for the response.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Content for the response.\n\t */\n\tcontent?: {\n\t\t[contentType: string]: {\n\t\t\tschema: {\n\t\t\t\ttype?: string;\n\t\t\t\tformat?: string;\n\t\t\t\t$ref?: string;\n\t\t\t};\n\t\t\texamples?: {\n\t\t\t\t[id: string]: IOpenApiExample;\n\t\t\t};\n\t\t};\n\t};\n\n\t/**\n\t * The headers for the response.\n\t */\n\theaders?: {\n\t\t[id: string]: IOpenApiHeader;\n\t};\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=IOpenApiSecurityScheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IOpenApiSecurityScheme.js","sourceRoot":"","sources":["../../../src/models/IOpenApiSecurityScheme.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The Open API config definition for security scheme.\n */\nexport interface IOpenApiSecurityScheme {\n\t/**\n\t * The type of the security schema.\n\t */\n\ttype?: string;\n\n\t/**\n\t * The scheme method.\n\t */\n\tscheme?: string;\n\n\t/**\n\t * The bearer format.\n\t */\n\tbearerFormat?: string;\n\n\t/**\n\t * Where is the token located.\n\t */\n\tin?: string;\n\n\t/**\n\t * What is the name of the token.\n\t */\n\tname?: string;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=IPackageJson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IPackageJson.js","sourceRoot":"","sources":["../../../src/models/IPackageJson.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for each individual package.\n */\nexport interface IPackageJson {\n\t/**\n\t * The name of the package.\n\t */\n\tname: string;\n\n\t/**\n\t * The dependencies for the package.\n\t */\n\tdependencies?: { [id: string]: string };\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=jsonTypeName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonTypeName.js","sourceRoot":"","sources":["../../../src/models/jsonTypeName.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { JSONType } from \"ajv/dist/2020.js\";\n\n/**\n * Default schema type.\n */\nexport type JsonTypeName = JSONType;\n"]}
@@ -1,11 +1,10 @@
1
- import { Is, ArrayHelper } from '@twin.org/core';
2
-
3
1
  // Copyright 2024 IOTA Stiftung.
4
2
  // SPDX-License-Identifier: Apache-2.0.
3
+ import { Is } from "@twin.org/core";
5
4
  /**
6
5
  * Helper class for JSON Schema processing.
7
6
  */
8
- class JsonSchemaHelper {
7
+ export class JsonSchemaHelper {
9
8
  /**
10
9
  * The JSON Schema version used.
11
10
  */
@@ -16,20 +15,39 @@ class JsonSchemaHelper {
16
15
  */
17
16
  static processArrays(schemaObject) {
18
17
  if (Is.object(schemaObject)) {
19
- // latest specs have singular items in `items` property
20
- // and multiple items in prefixItems, so update the schema accordingly
18
+ // new json schema version has prefixItems instead of items for arrays with fixed ordering
19
+ // so convert any old style schemas that use items as an array
20
+ // prefixItems validates fixed positions and is an array
21
+ // items validates the rest and is an object
22
+ // additionalItems no longer exists
21
23
  // https://www.learnjsonschema.com/2020-12/applicator/items/
22
24
  // https://www.learnjsonschema.com/2020-12/applicator/prefixitems/
23
- const schemaItems = schemaObject.items;
24
- if (Is.array(schemaItems) || Is.object(schemaItems)) {
25
- schemaObject.prefixItems = ArrayHelper.fromObjectOrArray(schemaItems);
26
- schemaObject.items = false;
27
- }
28
- const additionalItems = schemaObject.additionalItems;
29
- if (Is.array(additionalItems) || Is.object(additionalItems)) {
30
- schemaObject.items = ArrayHelper.fromObjectOrArray(additionalItems)[0];
31
- delete schemaObject.additionalItems;
25
+ if (Is.array(schemaObject.items)) {
26
+ if (Is.object(schemaObject.additionalItems)) {
27
+ // If the items are an array then this is fixed ordering
28
+ // so move to prefixItems and then do the same for additionalItems
29
+ schemaObject.prefixItems = schemaObject.items;
30
+ delete schemaObject.items;
31
+ schemaObject.items = schemaObject.additionalItems;
32
+ }
33
+ else if (Is.integer(schemaObject.minItems) &&
34
+ Is.integer(schemaObject.maxItems) &&
35
+ schemaObject.minItems === schemaObject.maxItems &&
36
+ schemaObject.maxItems === schemaObject.items.length) {
37
+ // There is a fixed number of items which matches the items array length
38
+ // so move construct an allOf to enforce the fixed length
39
+ schemaObject.items = { allOf: schemaObject.items };
40
+ delete schemaObject.minItems;
41
+ delete schemaObject.maxItems;
42
+ }
43
+ else {
44
+ // no additional items so wrap in an anyOf
45
+ schemaObject.items = { anyOf: schemaObject.items };
46
+ }
32
47
  }
48
+ // We can't use additionalItems in the new schema version
49
+ // so just remove it after processing
50
+ delete schemaObject.additionalItems;
33
51
  JsonSchemaHelper.processSchemaDictionary(schemaObject.properties);
34
52
  JsonSchemaHelper.processArrays(schemaObject.additionalProperties);
35
53
  JsonSchemaHelper.processSchemaArray(schemaObject.allOf);
@@ -237,17 +255,4 @@ class JsonSchemaHelper {
237
255
  : new RegExp(`^${matchPattern}$`);
238
256
  }
239
257
  }
240
-
241
- // Copyright 2024 IOTA Stiftung.
242
- // SPDX-License-Identifier: Apache-2.0.
243
- /**
244
- * Helper class for OpenAPI processing.
245
- */
246
- class OpenApiHelper {
247
- /**
248
- * The OpenAPI version used.
249
- */
250
- static API_VERSION = "3.1.1";
251
- }
252
-
253
- export { JsonSchemaHelper, OpenApiHelper };
258
+ //# sourceMappingURL=jsonSchemaHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonSchemaHelper.js","sourceRoot":"","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M,CAAC,KAAK,EAAE,CAAC;gBACjC,IAAI,EAAE,CAAC,MAAM,CAAc,IAAI,CAAC,EAAE,CAAC;oBAClC,gBAAgB,CAAC,iBAAiB,CAAC,UAAU,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;gBACrE,CAAC;YACF,CAAC;QACF,CAAC;aAAM,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACxC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;gBACjC,IAAI,EAAE,CAAC,MAAM,CAAc,IAAI,CAAC,EAAE,CAAC;oBAClC,gBAAgB,CAAC,iBAAiB,CAAC,UAAU,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;gBACrE,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAAC,YAAoB;QAC/C,OAAO,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC;YAChE,CAAC,CAAC,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACvC,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,YAAY,GAAG,CAAC,CAAC;IACpC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is } from \"@twin.org/core\";\nimport type { IJsonSchema } from \"../models/IJsonSchema.js\";\n\n/**\n * Helper class for JSON Schema processing.\n */\nexport class JsonSchemaHelper {\n\t/**\n\t * The JSON Schema version used.\n\t */\n\tpublic static readonly SCHEMA_VERSION = \"https://json-schema.org/draft/2020-12/schema\";\n\n\t/**\n\t * Process arrays in the schema object.\n\t * @param schemaObject The schema object to process.\n\t */\n\tpublic static processArrays(schemaObject: IJsonSchema): void {\n\t\tif (Is.object<IJsonSchema>(schemaObject)) {\n\t\t\t// new json schema version has prefixItems instead of items for arrays with fixed ordering\n\t\t\t// so convert any old style schemas that use items as an array\n\t\t\t// prefixItems validates fixed positions and is an array\n\t\t\t// items validates the rest and is an object\n\t\t\t// additionalItems no longer exists\n\t\t\t// https://www.learnjsonschema.com/2020-12/applicator/items/\n\t\t\t// https://www.learnjsonschema.com/2020-12/applicator/prefixitems/\n\t\t\tif (Is.array(schemaObject.items)) {\n\t\t\t\tif (Is.object(schemaObject.additionalItems)) {\n\t\t\t\t\t// If the items are an array then this is fixed ordering\n\t\t\t\t\t// so move to prefixItems and then do the same for additionalItems\n\t\t\t\t\tschemaObject.prefixItems = schemaObject.items;\n\t\t\t\t\tdelete schemaObject.items;\n\t\t\t\t\tschemaObject.items = schemaObject.additionalItems;\n\t\t\t\t} else if (\n\t\t\t\t\tIs.integer(schemaObject.minItems) &&\n\t\t\t\t\tIs.integer(schemaObject.maxItems) &&\n\t\t\t\t\tschemaObject.minItems === schemaObject.maxItems &&\n\t\t\t\t\tschemaObject.maxItems === schemaObject.items.length\n\t\t\t\t) {\n\t\t\t\t\t// There is a fixed number of items which matches the items array length\n\t\t\t\t\t// so move construct an allOf to enforce the fixed length\n\t\t\t\t\tschemaObject.items = { allOf: schemaObject.items };\n\t\t\t\t\tdelete schemaObject.minItems;\n\t\t\t\t\tdelete schemaObject.maxItems;\n\t\t\t\t} else {\n\t\t\t\t\t// no additional items so wrap in an anyOf\n\t\t\t\t\tschemaObject.items = { anyOf: schemaObject.items };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// We can't use additionalItems in the new schema version\n\t\t\t// so just remove it after processing\n\t\t\tdelete schemaObject.additionalItems;\n\n\t\t\tJsonSchemaHelper.processSchemaDictionary(schemaObject.properties);\n\t\t\tJsonSchemaHelper.processArrays(schemaObject.additionalProperties);\n\t\t\tJsonSchemaHelper.processSchemaArray(schemaObject.allOf);\n\t\t\tJsonSchemaHelper.processSchemaArray(schemaObject.anyOf);\n\t\t\tJsonSchemaHelper.processSchemaArray(schemaObject.oneOf);\n\t\t}\n\t}\n\n\t/**\n\t * Process arrays in the schema object.\n\t * @param schemaDictionary The schema object to process.\n\t */\n\tpublic static processSchemaDictionary(schemaDictionary?: { [key: string]: IJsonSchema }): void {\n\t\tif (Is.object(schemaDictionary)) {\n\t\t\tfor (const item of Object.values(schemaDictionary)) {\n\t\t\t\tif (Is.object<IJsonSchema>(item)) {\n\t\t\t\t\tJsonSchemaHelper.processArrays(item);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Process arrays in the schema object.\n\t * @param schemaArray The schema object to process.\n\t */\n\tpublic static processSchemaArray(schemaArray?: IJsonSchema[]): void {\n\t\tif (Is.arrayValue(schemaArray)) {\n\t\t\tfor (const item of schemaArray) {\n\t\t\t\tif (Is.object<IJsonSchema>(item)) {\n\t\t\t\t\tJsonSchemaHelper.processArrays(item);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Cleanup TypeScript markers from the type name.\n\t * @param typeName The definition string to clean up.\n\t * @returns The cleaned up definition string.\n\t */\n\tpublic static normaliseTypeName(typeName: string): string {\n\t\t// Remove the partial markers\n\t\tlet sTypeName = typeName.replace(/^Partial<I(.*?)>/g, \"$1\");\n\t\tsTypeName = sTypeName.replace(/Partial%3CI(.*?)%3E/g, \"$1\");\n\n\t\t// Remove the omit markers\n\t\tsTypeName = sTypeName.replace(/^Omit<I(.*?),.*>/g, \"$1\");\n\t\tsTypeName = sTypeName.replace(/Omit%3CI(.*?)%2C.*%3E/g, \"$1\");\n\n\t\t// Remove the pick markers\n\t\tsTypeName = sTypeName.replace(/^Pick<I(.*?),.*>/g, \"$1\");\n\t\tsTypeName = sTypeName.replace(/Pick%3CI(.*?)%2C.*%3E/g, \"$1\");\n\n\t\t// Cleanup the generic markers\n\t\tsTypeName = sTypeName.replace(/^(.*?)<I(.*?)>/g, \"$1<$2>\");\n\t\tsTypeName = sTypeName.replace(/(.*?)%3CI(.*?)%3E/g, \"$1<$2>\");\n\n\t\t// Cleanup the unknown markers\n\t\tsTypeName = sTypeName.replace(/<unknown>/g, \"\");\n\t\tsTypeName = sTypeName.replace(/%3Cunknown%3E/g, \"\");\n\n\t\t// Replace the other url markers\n\t\tsTypeName = sTypeName.replace(/%7C/g, \"|\").replace(/%3C/g, \"<\").replace(/%3E/g, \">\");\n\n\t\treturn sTypeName;\n\t}\n\n\t/**\n\t * Extract type from properties definition.\n\t * @param allTypes All the known types.\n\t * @param schema The schema to extract from.\n\t * @param output The output types.\n\t */\n\tpublic static extractTypesFromSchema(\n\t\tallTypes: { [id: string]: IJsonSchema },\n\t\tschema: IJsonSchema,\n\t\toutput: { [id: string]: IJsonSchema }\n\t): void {\n\t\tconst additionalTypes = [];\n\n\t\tif (Is.stringValue(schema.$ref)) {\n\t\t\tadditionalTypes.push(\n\t\t\t\tJsonSchemaHelper.normaliseTypeName(schema.$ref.replace(\"#/definitions/\", \"\"))\n\t\t\t);\n\t\t} else if (Is.object<IJsonSchema>(schema.items)) {\n\t\t\tif (Is.arrayValue<IJsonSchema>(schema.items)) {\n\t\t\t\tfor (const itemSchema of schema.items) {\n\t\t\t\t\tJsonSchemaHelper.extractTypesFromSchema(allTypes, itemSchema, output);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tJsonSchemaHelper.extractTypesFromSchema(allTypes, schema.items, output);\n\t\t\t}\n\t\t} else if (Is.object(schema.properties) || Is.object(schema.additionalProperties)) {\n\t\t\tif (Is.object(schema.properties)) {\n\t\t\t\tfor (const prop in schema.properties) {\n\t\t\t\t\tconst p = schema.properties[prop];\n\t\t\t\t\tif (Is.object<IJsonSchema>(p)) {\n\t\t\t\t\t\tJsonSchemaHelper.extractTypesFromSchema(allTypes, p, output);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Is.object(schema.additionalProperties)) {\n\t\t\t\tJsonSchemaHelper.extractTypesFromSchema(allTypes, schema.additionalProperties, output);\n\t\t\t}\n\t\t} else if (Is.arrayValue(schema.anyOf)) {\n\t\t\tfor (const prop of schema.anyOf) {\n\t\t\t\tif (Is.object<IJsonSchema>(prop)) {\n\t\t\t\t\tJsonSchemaHelper.extractTypesFromSchema(allTypes, prop, output);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (Is.arrayValue(schema.oneOf)) {\n\t\t\tfor (const prop of schema.oneOf) {\n\t\t\t\tif (Is.object<IJsonSchema>(prop)) {\n\t\t\t\t\tJsonSchemaHelper.extractTypesFromSchema(allTypes, prop, output);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (additionalTypes.length > 0) {\n\t\t\tJsonSchemaHelper.extractTypes(allTypes, additionalTypes, output);\n\t\t}\n\t}\n\n\t/**\n\t * Extract the required types from all the known schemas.\n\t * @param allSchemas All the known schemas.\n\t * @param requiredTypes The required types.\n\t * @param referencedSchemas The references schemas.\n\t */\n\tpublic static extractTypes(\n\t\tallSchemas: { [id: string]: IJsonSchema },\n\t\trequiredTypes: string[],\n\t\treferencedSchemas: { [id: string]: IJsonSchema }\n\t): void {\n\t\tfor (const typeKey of Object.keys(allSchemas)) {\n\t\t\tif (!referencedSchemas[typeKey]) {\n\t\t\t\tfor (const requiredType of requiredTypes) {\n\t\t\t\t\tconst regex = JsonSchemaHelper.stringToRegEx(requiredType);\n\n\t\t\t\t\tif (regex.test(typeKey)) {\n\t\t\t\t\t\treferencedSchemas[typeKey] = allSchemas[typeKey];\n\t\t\t\t\t\tJsonSchemaHelper.extractTypesFromSchema(\n\t\t\t\t\t\t\tallSchemas,\n\t\t\t\t\t\t\tallSchemas[typeKey],\n\t\t\t\t\t\t\treferencedSchemas\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Expand the types inline.\n\t * @param schemas The schemas to include the expanded types.\n\t * @param expandedTypes The types to expand.\n\t */\n\tpublic static expandTypes(schemas: { [id: string]: IJsonSchema }, expandedTypes: string[]): void {\n\t\tfor (const typeKey of Object.keys(schemas)) {\n\t\t\tconst schema = schemas[typeKey];\n\n\t\t\tJsonSchemaHelper.expandSchemaTypes(schemas, schema, expandedTypes);\n\t\t}\n\t}\n\n\t/**\n\t * Expand the types inline.\n\t * @param allSchemas All the known schemas.\n\t * @param schema The schemas to include the expanded types.\n\t * @param expandedTypes The types to expand.\n\t */\n\tpublic static expandSchemaTypes(\n\t\tallSchemas: { [id: string]: IJsonSchema },\n\t\tschema: IJsonSchema,\n\t\texpandedTypes: string[]\n\t): void {\n\t\tif (Is.stringValue(schema.$ref)) {\n\t\t\tfor (const expandedType of expandedTypes) {\n\t\t\t\tconst typeName = JsonSchemaHelper.normaliseTypeName(\n\t\t\t\t\tschema.$ref.replace(\"#/definitions/\", \"\")\n\t\t\t\t);\n\t\t\t\tconst regex = JsonSchemaHelper.stringToRegEx(expandedType);\n\t\t\t\tif (regex.test(typeName) && allSchemas[typeName]) {\n\t\t\t\t\tdelete schema.$ref;\n\t\t\t\t\tObject.assign(schema, allSchemas[typeName]);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (Is.object<IJsonSchema>(schema.items)) {\n\t\t\tif (Is.arrayValue<IJsonSchema>(schema.items)) {\n\t\t\t\tfor (const itemSchema of schema.items) {\n\t\t\t\t\tJsonSchemaHelper.expandSchemaTypes(allSchemas, itemSchema, expandedTypes);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tJsonSchemaHelper.expandSchemaTypes(allSchemas, schema.items, expandedTypes);\n\t\t\t}\n\t\t} else if (Is.object(schema.properties) || Is.object(schema.additionalProperties)) {\n\t\t\tif (Is.object(schema.properties)) {\n\t\t\t\tfor (const prop in schema.properties) {\n\t\t\t\t\tconst p = schema.properties[prop];\n\t\t\t\t\tif (Is.object<IJsonSchema>(p)) {\n\t\t\t\t\t\tJsonSchemaHelper.expandSchemaTypes(allSchemas, p, expandedTypes);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Is.object(schema.additionalProperties)) {\n\t\t\t\tJsonSchemaHelper.expandSchemaTypes(allSchemas, schema.additionalProperties, expandedTypes);\n\t\t\t}\n\t\t} else if (Is.arrayValue(schema.anyOf)) {\n\t\t\tfor (const prop of schema.anyOf) {\n\t\t\t\tif (Is.object<IJsonSchema>(prop)) {\n\t\t\t\t\tJsonSchemaHelper.expandSchemaTypes(allSchemas, prop, expandedTypes);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (Is.arrayValue(schema.oneOf)) {\n\t\t\tfor (const prop of schema.oneOf) {\n\t\t\t\tif (Is.object<IJsonSchema>(prop)) {\n\t\t\t\t\tJsonSchemaHelper.expandSchemaTypes(allSchemas, prop, expandedTypes);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Convert a string pattern to a regular expression.\n\t * @param matchPattern The pattern to convert.\n\t * @returns The regular expression.\n\t */\n\tpublic static stringToRegEx(matchPattern: string): RegExp {\n\t\treturn matchPattern.startsWith(\"/\") && matchPattern.endsWith(\"/\")\n\t\t\t? new RegExp(matchPattern.slice(1, -1))\n\t\t\t: new RegExp(`^${matchPattern}$`);\n\t}\n}\n"]}
@@ -0,0 +1,12 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ /**
4
+ * Helper class for OpenAPI processing.
5
+ */
6
+ export class OpenApiHelper {
7
+ /**
8
+ * The OpenAPI version used.
9
+ */
10
+ static API_VERSION = "3.1.1";
11
+ }
12
+ //# sourceMappingURL=openApiHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openApiHelper.js","sourceRoot":"","sources":["../../../src/utils/openApiHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,MAAM,OAAO,aAAa;IACzB;;OAEG;IACI,MAAM,CAAU,WAAW,GAAG,OAAO,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Helper class for OpenAPI processing.\n */\nexport class OpenApiHelper {\n\t/**\n\t * The OpenAPI version used.\n\t */\n\tpublic static readonly API_VERSION = \"3.1.1\";\n}\n"]}
@@ -1,11 +1,11 @@
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";
8
- export * from "./models/IPackageJson";
9
- export * from "./models/jsonTypeName";
10
- export * from "./utils/jsonSchemaHelper";
11
- export * from "./utils/openApiHelper";
1
+ export * from "./models/IJsonSchema.js";
2
+ export * from "./models/IOpenApi.js";
3
+ export * from "./models/IOpenApiExample.js";
4
+ export * from "./models/IOpenApiHeader.js";
5
+ export * from "./models/IOpenApiPathMethod.js";
6
+ export * from "./models/IOpenApiResponse.js";
7
+ export * from "./models/IOpenApiSecurityScheme.js";
8
+ export * from "./models/IPackageJson.js";
9
+ export * from "./models/jsonTypeName.js";
10
+ export * from "./utils/jsonSchemaHelper.js";
11
+ export * from "./utils/openApiHelper.js";
@@ -1,6 +1,6 @@
1
- import type { IJsonSchema } from "./IJsonSchema";
2
- import type { IOpenApiPathMethod } from "./IOpenApiPathMethod";
3
- import type { IOpenApiSecurityScheme } from "./IOpenApiSecurityScheme";
1
+ import type { IJsonSchema } from "./IJsonSchema.js";
2
+ import type { IOpenApiPathMethod } from "./IOpenApiPathMethod.js";
3
+ import type { IOpenApiSecurityScheme } from "./IOpenApiSecurityScheme.js";
4
4
  /**
5
5
  * The Open API config definition.
6
6
  */
@@ -1,7 +1,7 @@
1
- import type { IJsonSchema } from "./IJsonSchema";
2
- import type { IOpenApiExample } from "./IOpenApiExample";
3
- import type { IOpenApiResponse } from "./IOpenApiResponse";
4
- import type { JsonTypeName } from "./jsonTypeName";
1
+ import type { IJsonSchema } from "./IJsonSchema.js";
2
+ import type { IOpenApiExample } from "./IOpenApiExample.js";
3
+ import type { IOpenApiResponse } from "./IOpenApiResponse.js";
4
+ import type { JsonTypeName } from "./jsonTypeName.js";
5
5
  /**
6
6
  * The Open API config definition.
7
7
  */
@@ -1,5 +1,5 @@
1
- import type { IOpenApiExample } from "./IOpenApiExample";
2
- import type { IOpenApiHeader } from "./IOpenApiHeader";
1
+ import type { IOpenApiExample } from "./IOpenApiExample.js";
2
+ import type { IOpenApiHeader } from "./IOpenApiHeader.js";
3
3
  /**
4
4
  * The Open API config definition.
5
5
  */
@@ -1,4 +1,4 @@
1
- import type { IJsonSchema } from "../models/IJsonSchema";
1
+ import type { IJsonSchema } from "../models/IJsonSchema.js";
2
2
  /**
3
3
  * Helper class for JSON Schema processing.
4
4
  */
package/docs/changelog.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.2](https://github.com/twinfoundation/tools/compare/tools-core-v0.0.3-next.1...tools-core-v0.0.3-next.2) (2025-11-11)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * additionalItems object check ([ca81668](https://github.com/twinfoundation/tools/commit/ca81668e1ee0d2b1a479215265e651932d7b76de))
9
+
10
+ ## [0.0.3-next.1](https://github.com/twinfoundation/tools/compare/tools-core-v0.0.3-next.0...tools-core-v0.0.3-next.1) (2025-11-10)
11
+
12
+
13
+ ### Features
14
+
15
+ * add context id features ([#54](https://github.com/twinfoundation/tools/issues/54)) ([41ad65d](https://github.com/twinfoundation/tools/commit/41ad65d5ae33d0533d32a2864cd94e5c35e56c76))
16
+ * add support for auto expand types ([dd1e10a](https://github.com/twinfoundation/tools/commit/dd1e10a5b2fea6f80890ff6f3971f48e239cb4c1))
17
+ * add validate-locales ([97bb11f](https://github.com/twinfoundation/tools/commit/97bb11fd9e6ed400e7fa69671075ba78f36ca6e6))
18
+ * correctly handle auto expand types ([57fce0f](https://github.com/twinfoundation/tools/commit/57fce0f9ec4a0876665d70adc6e885f6feb3caf7))
19
+ * eslint migration to flat config ([25acfcf](https://github.com/twinfoundation/tools/commit/25acfcf4c4e0c496fffeaf67659fe171bc15199a))
20
+ * improve auto expand types ([6181d1d](https://github.com/twinfoundation/tools/commit/6181d1daded1f91323195cf7efbc2f1881f38b41))
21
+ * improve type name normalisation ([1fe28e5](https://github.com/twinfoundation/tools/commit/1fe28e567593e46a41a833fbba95fe4cd958f525))
22
+ * remove auto expanded types from final output ([18e05dc](https://github.com/twinfoundation/tools/commit/18e05dc88f71a0a27b79d1d076b1261b42d2c4c2))
23
+ * tighten the types included with the regex matching ([e54909b](https://github.com/twinfoundation/tools/commit/e54909bded4a19d00560dd3ec783e9146580bda3))
24
+ * update framework core ([559cb98](https://github.com/twinfoundation/tools/commit/559cb98612c05a05458b37462cda806b9591b18a))
25
+
26
+ ## [0.0.2-next.10](https://github.com/twinfoundation/tools/compare/tools-core-v0.0.2-next.9...tools-core-v0.0.2-next.10) (2025-10-09)
27
+
28
+
29
+ ### Features
30
+
31
+ * add validate-locales ([97bb11f](https://github.com/twinfoundation/tools/commit/97bb11fd9e6ed400e7fa69671075ba78f36ca6e6))
32
+
3
33
  ## [0.0.2-next.9](https://github.com/twinfoundation/tools/compare/tools-core-v0.0.2-next.8...tools-core-v0.0.2-next.9) (2025-09-23)
4
34
 
5
35
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/tools-core",
3
- "version": "0.0.2-next.9",
3
+ "version": "0.0.3-next.2",
4
4
  "description": "Shared components for the tools",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,22 +18,35 @@
18
18
  "@twin.org/nameof": "next",
19
19
  "ajv": "8.17.1"
20
20
  },
21
- "main": "./dist/cjs/index.cjs",
22
- "module": "./dist/esm/index.mjs",
21
+ "main": "./dist/es/index.js",
23
22
  "types": "./dist/types/index.d.ts",
24
23
  "exports": {
25
24
  ".": {
26
25
  "types": "./dist/types/index.d.ts",
27
- "require": "./dist/cjs/index.cjs",
28
- "import": "./dist/esm/index.mjs"
26
+ "import": "./dist/es/index.js",
27
+ "default": "./dist/es/index.js"
29
28
  },
30
29
  "./locales/*.json": "./locales/*.json"
31
30
  },
32
31
  "files": [
33
- "dist/cjs",
34
- "dist/esm",
32
+ "dist/es",
35
33
  "dist/types",
36
34
  "locales",
37
35
  "docs"
38
- ]
36
+ ],
37
+ "keywords": [
38
+ "twin",
39
+ "trade",
40
+ "iota",
41
+ "framework",
42
+ "blockchain",
43
+ "tools",
44
+ "core",
45
+ "foundation",
46
+ "utilities"
47
+ ],
48
+ "bugs": {
49
+ "url": "git+https://github.com/twinfoundation/tools/issues"
50
+ },
51
+ "homepage": "https://twindev.org"
39
52
  }
@@ -1,256 +0,0 @@
1
- 'use strict';
2
-
3
- var core = require('@twin.org/core');
4
-
5
- // Copyright 2024 IOTA Stiftung.
6
- // SPDX-License-Identifier: Apache-2.0.
7
- /**
8
- * Helper class for JSON Schema processing.
9
- */
10
- class JsonSchemaHelper {
11
- /**
12
- * The JSON Schema version used.
13
- */
14
- static SCHEMA_VERSION = "https://json-schema.org/draft/2020-12/schema";
15
- /**
16
- * Process arrays in the schema object.
17
- * @param schemaObject The schema object to process.
18
- */
19
- static processArrays(schemaObject) {
20
- if (core.Is.object(schemaObject)) {
21
- // latest specs have singular items in `items` property
22
- // and multiple items in prefixItems, so update the schema accordingly
23
- // https://www.learnjsonschema.com/2020-12/applicator/items/
24
- // https://www.learnjsonschema.com/2020-12/applicator/prefixitems/
25
- const schemaItems = schemaObject.items;
26
- if (core.Is.array(schemaItems) || core.Is.object(schemaItems)) {
27
- schemaObject.prefixItems = core.ArrayHelper.fromObjectOrArray(schemaItems);
28
- schemaObject.items = false;
29
- }
30
- const additionalItems = schemaObject.additionalItems;
31
- if (core.Is.array(additionalItems) || core.Is.object(additionalItems)) {
32
- schemaObject.items = core.ArrayHelper.fromObjectOrArray(additionalItems)[0];
33
- delete schemaObject.additionalItems;
34
- }
35
- JsonSchemaHelper.processSchemaDictionary(schemaObject.properties);
36
- JsonSchemaHelper.processArrays(schemaObject.additionalProperties);
37
- JsonSchemaHelper.processSchemaArray(schemaObject.allOf);
38
- JsonSchemaHelper.processSchemaArray(schemaObject.anyOf);
39
- JsonSchemaHelper.processSchemaArray(schemaObject.oneOf);
40
- }
41
- }
42
- /**
43
- * Process arrays in the schema object.
44
- * @param schemaDictionary The schema object to process.
45
- */
46
- static processSchemaDictionary(schemaDictionary) {
47
- if (core.Is.object(schemaDictionary)) {
48
- for (const item of Object.values(schemaDictionary)) {
49
- if (core.Is.object(item)) {
50
- JsonSchemaHelper.processArrays(item);
51
- }
52
- }
53
- }
54
- }
55
- /**
56
- * Process arrays in the schema object.
57
- * @param schemaArray The schema object to process.
58
- */
59
- static processSchemaArray(schemaArray) {
60
- if (core.Is.arrayValue(schemaArray)) {
61
- for (const item of schemaArray) {
62
- if (core.Is.object(item)) {
63
- JsonSchemaHelper.processArrays(item);
64
- }
65
- }
66
- }
67
- }
68
- /**
69
- * Cleanup TypeScript markers from the type name.
70
- * @param typeName The definition string to clean up.
71
- * @returns The cleaned up definition string.
72
- */
73
- static normaliseTypeName(typeName) {
74
- // Remove the partial markers
75
- let sTypeName = typeName.replace(/^Partial<I(.*?)>/g, "$1");
76
- sTypeName = sTypeName.replace(/Partial%3CI(.*?)%3E/g, "$1");
77
- // Remove the omit markers
78
- sTypeName = sTypeName.replace(/^Omit<I(.*?),.*>/g, "$1");
79
- sTypeName = sTypeName.replace(/Omit%3CI(.*?)%2C.*%3E/g, "$1");
80
- // Remove the pick markers
81
- sTypeName = sTypeName.replace(/^Pick<I(.*?),.*>/g, "$1");
82
- sTypeName = sTypeName.replace(/Pick%3CI(.*?)%2C.*%3E/g, "$1");
83
- // Cleanup the generic markers
84
- sTypeName = sTypeName.replace(/^(.*?)<I(.*?)>/g, "$1<$2>");
85
- sTypeName = sTypeName.replace(/(.*?)%3CI(.*?)%3E/g, "$1<$2>");
86
- // Cleanup the unknown markers
87
- sTypeName = sTypeName.replace(/<unknown>/g, "");
88
- sTypeName = sTypeName.replace(/%3Cunknown%3E/g, "");
89
- // Replace the other url markers
90
- sTypeName = sTypeName.replace(/%7C/g, "|").replace(/%3C/g, "<").replace(/%3E/g, ">");
91
- return sTypeName;
92
- }
93
- /**
94
- * Extract type from properties definition.
95
- * @param allTypes All the known types.
96
- * @param schema The schema to extract from.
97
- * @param output The output types.
98
- */
99
- static extractTypesFromSchema(allTypes, schema, output) {
100
- const additionalTypes = [];
101
- if (core.Is.stringValue(schema.$ref)) {
102
- additionalTypes.push(JsonSchemaHelper.normaliseTypeName(schema.$ref.replace("#/definitions/", "")));
103
- }
104
- else if (core.Is.object(schema.items)) {
105
- if (core.Is.arrayValue(schema.items)) {
106
- for (const itemSchema of schema.items) {
107
- JsonSchemaHelper.extractTypesFromSchema(allTypes, itemSchema, output);
108
- }
109
- }
110
- else {
111
- JsonSchemaHelper.extractTypesFromSchema(allTypes, schema.items, output);
112
- }
113
- }
114
- else if (core.Is.object(schema.properties) || core.Is.object(schema.additionalProperties)) {
115
- if (core.Is.object(schema.properties)) {
116
- for (const prop in schema.properties) {
117
- const p = schema.properties[prop];
118
- if (core.Is.object(p)) {
119
- JsonSchemaHelper.extractTypesFromSchema(allTypes, p, output);
120
- }
121
- }
122
- }
123
- if (core.Is.object(schema.additionalProperties)) {
124
- JsonSchemaHelper.extractTypesFromSchema(allTypes, schema.additionalProperties, output);
125
- }
126
- }
127
- else if (core.Is.arrayValue(schema.anyOf)) {
128
- for (const prop of schema.anyOf) {
129
- if (core.Is.object(prop)) {
130
- JsonSchemaHelper.extractTypesFromSchema(allTypes, prop, output);
131
- }
132
- }
133
- }
134
- else if (core.Is.arrayValue(schema.oneOf)) {
135
- for (const prop of schema.oneOf) {
136
- if (core.Is.object(prop)) {
137
- JsonSchemaHelper.extractTypesFromSchema(allTypes, prop, output);
138
- }
139
- }
140
- }
141
- if (additionalTypes.length > 0) {
142
- JsonSchemaHelper.extractTypes(allTypes, additionalTypes, output);
143
- }
144
- }
145
- /**
146
- * Extract the required types from all the known schemas.
147
- * @param allSchemas All the known schemas.
148
- * @param requiredTypes The required types.
149
- * @param referencedSchemas The references schemas.
150
- */
151
- static extractTypes(allSchemas, requiredTypes, referencedSchemas) {
152
- for (const typeKey of Object.keys(allSchemas)) {
153
- if (!referencedSchemas[typeKey]) {
154
- for (const requiredType of requiredTypes) {
155
- const regex = JsonSchemaHelper.stringToRegEx(requiredType);
156
- if (regex.test(typeKey)) {
157
- referencedSchemas[typeKey] = allSchemas[typeKey];
158
- JsonSchemaHelper.extractTypesFromSchema(allSchemas, allSchemas[typeKey], referencedSchemas);
159
- }
160
- }
161
- }
162
- }
163
- }
164
- /**
165
- * Expand the types inline.
166
- * @param schemas The schemas to include the expanded types.
167
- * @param expandedTypes The types to expand.
168
- */
169
- static expandTypes(schemas, expandedTypes) {
170
- for (const typeKey of Object.keys(schemas)) {
171
- const schema = schemas[typeKey];
172
- JsonSchemaHelper.expandSchemaTypes(schemas, schema, expandedTypes);
173
- }
174
- }
175
- /**
176
- * Expand the types inline.
177
- * @param allSchemas All the known schemas.
178
- * @param schema The schemas to include the expanded types.
179
- * @param expandedTypes The types to expand.
180
- */
181
- static expandSchemaTypes(allSchemas, schema, expandedTypes) {
182
- if (core.Is.stringValue(schema.$ref)) {
183
- for (const expandedType of expandedTypes) {
184
- const typeName = JsonSchemaHelper.normaliseTypeName(schema.$ref.replace("#/definitions/", ""));
185
- const regex = JsonSchemaHelper.stringToRegEx(expandedType);
186
- if (regex.test(typeName) && allSchemas[typeName]) {
187
- delete schema.$ref;
188
- Object.assign(schema, allSchemas[typeName]);
189
- break;
190
- }
191
- }
192
- }
193
- else if (core.Is.object(schema.items)) {
194
- if (core.Is.arrayValue(schema.items)) {
195
- for (const itemSchema of schema.items) {
196
- JsonSchemaHelper.expandSchemaTypes(allSchemas, itemSchema, expandedTypes);
197
- }
198
- }
199
- else {
200
- JsonSchemaHelper.expandSchemaTypes(allSchemas, schema.items, expandedTypes);
201
- }
202
- }
203
- else if (core.Is.object(schema.properties) || core.Is.object(schema.additionalProperties)) {
204
- if (core.Is.object(schema.properties)) {
205
- for (const prop in schema.properties) {
206
- const p = schema.properties[prop];
207
- if (core.Is.object(p)) {
208
- JsonSchemaHelper.expandSchemaTypes(allSchemas, p, expandedTypes);
209
- }
210
- }
211
- }
212
- if (core.Is.object(schema.additionalProperties)) {
213
- JsonSchemaHelper.expandSchemaTypes(allSchemas, schema.additionalProperties, expandedTypes);
214
- }
215
- }
216
- else if (core.Is.arrayValue(schema.anyOf)) {
217
- for (const prop of schema.anyOf) {
218
- if (core.Is.object(prop)) {
219
- JsonSchemaHelper.expandSchemaTypes(allSchemas, prop, expandedTypes);
220
- }
221
- }
222
- }
223
- else if (core.Is.arrayValue(schema.oneOf)) {
224
- for (const prop of schema.oneOf) {
225
- if (core.Is.object(prop)) {
226
- JsonSchemaHelper.expandSchemaTypes(allSchemas, prop, expandedTypes);
227
- }
228
- }
229
- }
230
- }
231
- /**
232
- * Convert a string pattern to a regular expression.
233
- * @param matchPattern The pattern to convert.
234
- * @returns The regular expression.
235
- */
236
- static stringToRegEx(matchPattern) {
237
- return matchPattern.startsWith("/") && matchPattern.endsWith("/")
238
- ? new RegExp(matchPattern.slice(1, -1))
239
- : new RegExp(`^${matchPattern}$`);
240
- }
241
- }
242
-
243
- // Copyright 2024 IOTA Stiftung.
244
- // SPDX-License-Identifier: Apache-2.0.
245
- /**
246
- * Helper class for OpenAPI processing.
247
- */
248
- class OpenApiHelper {
249
- /**
250
- * The OpenAPI version used.
251
- */
252
- static API_VERSION = "3.1.1";
253
- }
254
-
255
- exports.JsonSchemaHelper = JsonSchemaHelper;
256
- exports.OpenApiHelper = OpenApiHelper;