@trayio/tray-schema 3.6.0 → 3.7.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"TJSTraySchemaGenerator.d.ts","sourceRoot":"","sources":["../../src/schema/TJSTraySchemaGenerator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAe,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,qBAAa,sBAAuB,YAAW,mBAAmB;IACjE,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC;IAqC1E,sBAAsB,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU;CAwG9D"}
1
+ {"version":3,"file":"TJSTraySchemaGenerator.d.ts","sourceRoot":"","sources":["../../src/schema/TJSTraySchemaGenerator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAe,MAAM,cAAc,CAAC;AAEnD,OAAO,EAEN,aAAa,EAEb,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,qBAAa,sBAAuB,YAAW,mBAAmB;IACjE,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC;IAuC1E,sBAAsB,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU;CA0H9D"}
@@ -40,6 +40,7 @@ class TJSTraySchemaGenerator {
40
40
  'lookupAuthRequired',
41
41
  'enumLabels',
42
42
  'advanced',
43
+ 'dropdown',
43
44
  ],
44
45
  // adds a required array to every entitiy in the schema which describes which children are required
45
46
  required: true,
@@ -75,6 +76,20 @@ class TJSTraySchemaGenerator {
75
76
  delete object.lookupAuthRequired;
76
77
  }
77
78
  };
79
+ const transformDropDown = (object) => {
80
+ if (object.dropdown === false) {
81
+ const unionTypes = [];
82
+ object.oneOf.forEach((item) => {
83
+ const types = Array.isArray(item.type)
84
+ ? item.type
85
+ : [item.type];
86
+ unionTypes.push(...types);
87
+ });
88
+ object.type = [...new Set(unionTypes)];
89
+ delete object.oneOf;
90
+ delete object.dropdown;
91
+ }
92
+ };
78
93
  const transformEnumLabels = (object) => {
79
94
  if (object.enumLabels && typeof object.enumLabels === 'string') {
80
95
  const enumLabelsString = object.enumLabels;
@@ -152,6 +167,7 @@ class TJSTraySchemaGenerator {
152
167
  transformEnumLabels(value);
153
168
  generateEnumLabels(value);
154
169
  transformOneOf(value);
170
+ transformDropDown(value);
155
171
  recursiveObjectSearch(value);
156
172
  }
157
173
  }
@@ -455,4 +455,27 @@ describe('TJSTraySchemaGenerator', () => {
455
455
  };
456
456
  expect(actual).toEqual(expected);
457
457
  });
458
+ it('Generates object with dropdown false', () => {
459
+ const type = 'Input';
460
+ const dirPath = __dirname;
461
+ const path = (0, path_1.join)(dirPath, 'dropdown.test.data.ts');
462
+ const result = new TJSTraySchemaGenerator_1.TJSTraySchemaGenerator().generateFromType(type, path);
463
+ const actual = E.getOrElse((error) => {
464
+ console.warn(error);
465
+ throw new Error(`Failed to generate JSON schema from type`);
466
+ })(result);
467
+ const expected = {
468
+ type: 'object',
469
+ properties: {
470
+ emails: {
471
+ type: ['object', 'string'],
472
+ },
473
+ },
474
+ advanced: [],
475
+ required: ['emails'],
476
+ additionalProperties: false,
477
+ $schema: 'http://json-schema.org/draft-07/schema#',
478
+ };
479
+ expect(actual).toEqual(expected);
480
+ });
458
481
  });
@@ -0,0 +1,7 @@
1
+ export type Input = {
2
+ /**
3
+ * @dropdown false
4
+ */
5
+ emails: string | object;
6
+ };
7
+ //# sourceMappingURL=dropdown.test.data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dropdown.test.data.d.ts","sourceRoot":"","sources":["../../src/schema/dropdown.test.data.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG;IACnB;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/tray-schema",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "description": "Schema for Tray connectors and authentications",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"
@@ -11,7 +11,7 @@
11
11
  "access": "public"
12
12
  },
13
13
  "dependencies": {
14
- "@trayio/commons": "3.6.0",
14
+ "@trayio/commons": "3.7.0",
15
15
  "@types/node": "18.11.9",
16
16
  "lodash": "4.17.21",
17
17
  "typescript-json-schema": "0.62.0"