@trayio/tray-schema 1.3.0 → 1.4.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.
- package/dist/schema/TJSTraySchemaGenerator.d.ts.map +1 -1
- package/dist/schema/TJSTraySchemaGenerator.js +2 -1
- package/dist/schema/TJSTraySchemaGenerator.unit.test.js +40 -2
- package/dist/schema/enumLabels.test.data.d.ts +20 -0
- package/dist/schema/enumLabels.test.data.d.ts.map +1 -0
- package/dist/schema/enumLabels.test.data.js +11 -0
- package/package.json +3 -3
|
@@ -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;IAgC1E,sBAAsB,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU;
|
|
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;IAgC1E,sBAAsB,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU;CAsG9D"}
|
|
@@ -76,7 +76,7 @@ class TJSTraySchemaGenerator {
|
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
const generateEnumLabels = (object) => {
|
|
79
|
-
if (object.enum && Array.isArray(object.enum)) {
|
|
79
|
+
if (object.enum && !object.enumLabels && Array.isArray(object.enum)) {
|
|
80
80
|
const enumLabels = [];
|
|
81
81
|
const enums = object.enum;
|
|
82
82
|
enums.forEach((enumItem) => {
|
|
@@ -142,6 +142,7 @@ class TJSTraySchemaGenerator {
|
|
|
142
142
|
for (const [key, value] of Object.entries(object)) {
|
|
143
143
|
if (typeof value === 'object' && value !== null) {
|
|
144
144
|
transformLookup(value);
|
|
145
|
+
transformEnumLabels(value);
|
|
145
146
|
generateEnumLabels(value);
|
|
146
147
|
transformOneOf(value);
|
|
147
148
|
recursiveObjectSearch(value);
|
|
@@ -195,8 +195,46 @@ describe('TJSTraySchemaGenerator', () => {
|
|
|
195
195
|
properties: {
|
|
196
196
|
text: { type: 'string' },
|
|
197
197
|
type: {
|
|
198
|
-
enumLabels: ['Default Always', '
|
|
199
|
-
enum: ['default always', '
|
|
198
|
+
enumLabels: ['Default Always', 'The Danger', 'Primary One'],
|
|
199
|
+
enum: ['default always', 'the_danger', 'primary-one'],
|
|
200
|
+
type: 'string',
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
advanced: [],
|
|
204
|
+
required: ['text', 'type'],
|
|
205
|
+
additionalProperties: false,
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
advanced: [],
|
|
210
|
+
required: ['actions'],
|
|
211
|
+
additionalProperties: false,
|
|
212
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
213
|
+
};
|
|
214
|
+
expect(actual).toEqual(expected);
|
|
215
|
+
});
|
|
216
|
+
it('Generates enums and custom enumLabels', () => {
|
|
217
|
+
const type = 'Input';
|
|
218
|
+
const dirPath = __dirname;
|
|
219
|
+
const path = (0, path_1.join)(dirPath, 'enumLabels.test.data.ts');
|
|
220
|
+
const result = new TJSTraySchemaGenerator_1.TJSTraySchemaGenerator().generateFromType(type, path);
|
|
221
|
+
const actual = E.getOrElse((error) => {
|
|
222
|
+
console.warn(error);
|
|
223
|
+
throw new Error(`Failed to generate JSON schema from type`);
|
|
224
|
+
})(result);
|
|
225
|
+
const expected = {
|
|
226
|
+
type: 'object',
|
|
227
|
+
properties: {
|
|
228
|
+
actions: {
|
|
229
|
+
description: 'example dropdown',
|
|
230
|
+
type: 'array',
|
|
231
|
+
items: {
|
|
232
|
+
type: 'object',
|
|
233
|
+
properties: {
|
|
234
|
+
text: { type: 'string' },
|
|
235
|
+
type: {
|
|
236
|
+
enumLabels: ['The Default', 'The Danger', 'The Primary'],
|
|
237
|
+
enum: ['default', 'danger', 'primary'],
|
|
200
238
|
type: 'string',
|
|
201
239
|
},
|
|
202
240
|
},
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type Input = {
|
|
2
|
+
/**
|
|
3
|
+
* @description example dropdown
|
|
4
|
+
*/
|
|
5
|
+
actions: Action[];
|
|
6
|
+
};
|
|
7
|
+
type Action = {
|
|
8
|
+
text: string;
|
|
9
|
+
type: ActionType;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @enumLabels The Default, The Danger, The Primary
|
|
13
|
+
*/
|
|
14
|
+
declare enum ActionType {
|
|
15
|
+
default = "default",
|
|
16
|
+
danger = "danger",
|
|
17
|
+
primary = "primary"
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=enumLabels.test.data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enumLabels.test.data.d.ts","sourceRoot":"","sources":["../../src/schema/enumLabels.test.data.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG;IACnB;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,KAAK,MAAM,GAAG;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;CACjB,CAAC;AACF;;GAEG;AACH,aAAK,UAAU;IACd,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,OAAO,YAAY;CACnB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* @enumLabels The Default, The Danger, The Primary
|
|
5
|
+
*/
|
|
6
|
+
var ActionType;
|
|
7
|
+
(function (ActionType) {
|
|
8
|
+
ActionType["default"] = "default";
|
|
9
|
+
ActionType["danger"] = "danger";
|
|
10
|
+
ActionType["primary"] = "primary";
|
|
11
|
+
})(ActionType || (ActionType = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayio/tray-schema",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Schema for Tray connectors and authentications",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./*": "./dist/*.js"
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@trayio/commons": "1.
|
|
14
|
+
"@trayio/commons": "1.4.0",
|
|
15
15
|
"@types/node": "18.11.9",
|
|
16
16
|
"lodash": "4.17.5",
|
|
17
|
-
"typescript-json-schema": "0.
|
|
17
|
+
"typescript-json-schema": "0.62.0"
|
|
18
18
|
},
|
|
19
19
|
"typesVersions": {
|
|
20
20
|
"*": {
|