@trapi/metadata 0.1.4 → 0.1.5

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 (60) hide show
  1. package/package.json +11 -8
  2. package/src/cache/driver.ts +0 -97
  3. package/src/cache/index.ts +0 -10
  4. package/src/cache/type.ts +0 -43
  5. package/src/cache/utils.ts +0 -49
  6. package/src/config/index.ts +0 -8
  7. package/src/config/path.ts +0 -29
  8. package/src/decorator/functions.ts +0 -142
  9. package/src/decorator/index.ts +0 -13
  10. package/src/decorator/mapper/index.ts +0 -153
  11. package/src/decorator/mapper/maps/decorators-express.ts +0 -117
  12. package/src/decorator/mapper/maps/internal.ts +0 -95
  13. package/src/decorator/mapper/maps/typescript-rest.ts +0 -150
  14. package/src/decorator/mapper/utils.ts +0 -88
  15. package/src/decorator/representation/index.ts +0 -82
  16. package/src/decorator/representation/property/utils.ts +0 -146
  17. package/src/decorator/type.ts +0 -235
  18. package/src/decorator/utils/index.ts +0 -9
  19. package/src/decorator/utils/node.ts +0 -59
  20. package/src/decorator/utils/validator.ts +0 -104
  21. package/src/generator/controller.ts +0 -65
  22. package/src/generator/endpoint.ts +0 -212
  23. package/src/generator/index.ts +0 -219
  24. package/src/generator/method.ts +0 -198
  25. package/src/generator/parameter.ts +0 -392
  26. package/src/index.ts +0 -13
  27. package/src/resolver/error.ts +0 -38
  28. package/src/resolver/index.ts +0 -11
  29. package/src/resolver/type-node.ts +0 -1287
  30. package/src/resolver/type.ts +0 -257
  31. package/src/resolver/utils/index.ts +0 -9
  32. package/src/resolver/utils/initializer.ts +0 -84
  33. package/src/resolver/utils/validator.ts +0 -144
  34. package/src/type.ts +0 -185
  35. package/src/utils/generator.ts +0 -42
  36. package/src/utils/index.ts +0 -10
  37. package/src/utils/js-doc.ts +0 -125
  38. package/src/utils/validator.ts +0 -43
  39. package/test/data/library/@decorators-express/decorators.ts +0 -7
  40. package/test/data/library/self/api.ts +0 -37
  41. package/test/data/library/type.ts +0 -138
  42. package/test/data/library/typescript-rest/api.ts +0 -366
  43. package/test/data/library/typescript-rest/decorators/index.ts +0 -10
  44. package/test/data/library/typescript-rest/decorators/methods.ts +0 -34
  45. package/test/data/library/typescript-rest/decorators/parameters.ts +0 -62
  46. package/test/data/library/typescript-rest/decorators/services.ts +0 -47
  47. package/test/data/library/typescript-rest/return-types.ts +0 -94
  48. package/test/data/library/utils.ts +0 -7
  49. package/test/jest.config.js +0 -49
  50. package/test/unit/cache.spec.ts +0 -48
  51. package/test/unit/decorator/mapper/index.spec.ts +0 -83
  52. package/test/unit/decorator/representation/index.spec.ts +0 -102
  53. package/test/unit/decorator/utils/node.spec.ts +0 -47
  54. package/test/unit/library/typescript-rest.spec.ts +0 -342
  55. package/test/unit/resolver/type.spec.ts +0 -134
  56. package/test/unit/utils/generator.spec.ts +0 -41
  57. package/test/unit/utils/js-doc.spec.ts +0 -104
  58. package/tsconfig.build.json +0 -11
  59. package/tsconfig.json +0 -9
  60. package/writable/.gitignore +0 -3
@@ -1,48 +0,0 @@
1
- /*
2
- * Copyright (c) 2021.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import {CacheDriver} from "../../src";
9
- import {getWritableDirPath} from "../../src/config";
10
- import * as fs from "fs";
11
-
12
- describe('src/cache/index.ts', function () {
13
- it('should save cache', () => {
14
- const cache = new CacheDriver(getWritableDirPath());
15
-
16
- const cachePath : string = cache.save({
17
- controllers: [],
18
- referenceTypes: {},
19
- sourceFilesSize: 0
20
- });
21
-
22
- expect(cachePath).toBeDefined();
23
- expect(fs.existsSync(cachePath)).toBeTruthy();
24
-
25
- const output = cache.get(0);
26
-
27
- expect(output).toBeDefined();
28
- expect(output).toHaveProperty('controllers');
29
- expect(output).toHaveProperty('referenceTypes');
30
- expect(output).toHaveProperty('sourceFilesSize');
31
- });
32
-
33
- it('should not save & get cache', () => {
34
- const cacheNone = new CacheDriver(false);
35
-
36
- const cachePath : string = cacheNone.save({
37
- controllers: [],
38
- referenceTypes: {},
39
- sourceFilesSize: 0
40
- });
41
-
42
- expect(cachePath).toBeUndefined();
43
-
44
- const output = cacheNone.get(0);
45
-
46
- expect(output).toBeUndefined();
47
- });
48
- });
@@ -1,83 +0,0 @@
1
- /*
2
- * Copyright (c) 2021.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import {DecoratorMapper, Decorator, RepresentationManager} from "../../../../src";
9
-
10
- describe('src/decorator/mapper/index.ts', () => {
11
- const decorators : Decorator.Data[] = [
12
- {text: 'foo', arguments: [], typeArguments: []},
13
- {text: 'SwaggerTags', arguments: [], typeArguments: []}
14
- ];
15
-
16
- const decoratorsWithResponseExample : Decorator.Data[] = [
17
- ...decorators,
18
- {
19
- text: 'ResponseExample',
20
- arguments: [],
21
- typeArguments: []
22
- }
23
- ];
24
-
25
- const mapper = new DecoratorMapper({
26
- internal: false
27
- });
28
-
29
- it('should not match', () => {
30
- expect(mapper.match('RESPONSE_EXAMPLE', [])).toBeUndefined();
31
- expect(mapper.match('RESPONSE_EXAMPLE', decorators)).toBeUndefined();
32
- expect(mapper.match('RESPONSE_EXAMPLE', decoratorsWithResponseExample)).toBeUndefined();
33
- expect(mapper.match('SWAGGER_TAGS', decorators)).toBeUndefined();
34
- })
35
-
36
- it('should work with internal configurations', () => {
37
- mapper.setConfig({
38
- internal: true
39
- });
40
-
41
- expect(mapper.match('SWAGGER_TAGS', decorators)).toBeDefined();
42
- expect(mapper.match('RESPONSE_EXAMPLE', decorators)).toBeUndefined();
43
- expect(mapper.match('RESPONSE_EXAMPLE', decoratorsWithResponseExample)).toBeDefined();
44
- });
45
-
46
- it('should work with library configurations', () => {
47
- mapper.setConfig({internal: false, library: {'typescript-rest': {RESPONSE_EXAMPLE: false}}});
48
- expect(mapper.match('RESPONSE_EXAMPLE', decoratorsWithResponseExample)).toBeUndefined();
49
- mapper.setConfig({internal: false, library: {'typescript-rest': false}});
50
- expect(mapper.match('RESPONSE_EXAMPLE', decoratorsWithResponseExample)).toBeUndefined();
51
- mapper.setConfig({internal: false, library: {'typescript-rest': []}});
52
- expect(mapper.match('RESPONSE_EXAMPLE', decoratorsWithResponseExample)).toBeUndefined();
53
- mapper.setConfig({internal: false, library: {'typescript-rest': 'SWAGGER_TAGS'}});
54
- expect(mapper.match('RESPONSE_EXAMPLE', decoratorsWithResponseExample)).toBeUndefined();
55
-
56
- const data = [...decorators, {text: 'Example', arguments: [], typeArguments: []}];
57
-
58
- mapper.setConfig({internal: false, library: {'typescript-rest': {RESPONSE_EXAMPLE: true}}});
59
- expect(mapper.match('RESPONSE_EXAMPLE', data)).toBeDefined();
60
- mapper.setConfig({internal: false, library: {'typescript-rest': true}});
61
- expect(mapper.match('RESPONSE_EXAMPLE', data)).toBeDefined();
62
- mapper.setConfig({internal: false, library: {'typescript-rest': ['RESPONSE_EXAMPLE']}});
63
- expect(mapper.match('RESPONSE_EXAMPLE', data)).toBeDefined();
64
- })
65
-
66
- it('should match', () => {
67
- mapper.setConfig({
68
- map: {
69
- SWAGGER_TAGS: {
70
- id: 'SwaggerTags',
71
- properties: {
72
- DEFAULT: {}
73
- }
74
- }
75
- }
76
- });
77
-
78
- const match = mapper.match('SWAGGER_TAGS', decorators);
79
-
80
- expect(match).toBeDefined();
81
- expect(match).toBeInstanceOf(RepresentationManager);
82
- })
83
- });
@@ -1,102 +0,0 @@
1
- /*
2
- * Copyright (c) 2021.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import {SyntaxKind, NodeFlags, ArrayLiteralExpression, NodeArray, Expression} from 'typescript';
9
- import {Decorator, RepresentationManager} from "../../../../src";
10
- import {mergeObjectArguments} from "../../../../src/decorator/representation/property/utils";
11
-
12
- describe('src/decorator/representation/index.ts', () => {
13
- const swaggerTagsRepresentation : Decorator.Representation<'SWAGGER_TAGS'> = {
14
- id: 'SwaggerTags',
15
- properties: {
16
- DEFAULT: {
17
- srcArgumentType: "argument",
18
- type: "array",
19
- srcAmount: -1,
20
- srcStrategy: "merge"
21
- }
22
- }
23
- };
24
-
25
- const swaggerTagsDecorators : Decorator.Data[] = [
26
- {text: 'SwaggerTags', arguments: [['auth', 'admin']], typeArguments: []},
27
- {text: 'SwaggerTags', arguments: [['auth'], ['admin']], typeArguments: []},
28
- {text: 'SwaggerTags', arguments: [], typeArguments: []},
29
- ]
30
-
31
- const swaggerTagsRepresentationManager = new RepresentationManager<'SWAGGER_TAGS'>(swaggerTagsRepresentation, swaggerTagsDecorators);
32
-
33
- // ----------------------------------------------------------------------------------
34
-
35
- const responseExampleRepresentation : Decorator.Representation<'RESPONSE_EXAMPLE'> = {
36
- id: 'ResponseExample',
37
- properties: {
38
- TYPE: {
39
- isType: true,
40
- srcArgumentType: "typeArgument",
41
- srcStrategy: "none"
42
- },
43
- PAYLOAD: {
44
- srcArgumentType: "argument",
45
- srcAmount: -1,
46
- srcStrategy: (items: unknown[] | unknown[][]) => {
47
- // return items.reduce((accumulator, value) => accumulator.concat(value), []);
48
- return mergeObjectArguments(items);
49
- }
50
- }
51
- }
52
- };
53
-
54
- const responseExampleDecorators : Decorator.Data[] = [
55
- {text: 'ResponseExample', arguments: [{foo: 'bar'}], typeArguments: [{foo: 'bar'}]},
56
- {text: 'ResponseExample', arguments: [{foo: 'bar'}, {bar: 'baz'}], typeArguments: []}
57
- ]
58
-
59
- const responseExampleRepresentationManager = new RepresentationManager<'RESPONSE_EXAMPLE'>(responseExampleRepresentation, responseExampleDecorators);
60
-
61
- it('should get property value', () => {
62
- let value = swaggerTagsRepresentationManager.getPropertyValue('DEFAULT');
63
- expect(value).toEqual(['auth', 'admin']);
64
-
65
- value = swaggerTagsRepresentationManager.getPropertyValue('DEFAULT', 1);
66
- expect(value).toEqual(['auth', 'admin']);
67
-
68
- let payloadValue = responseExampleRepresentationManager.getPropertyValue('PAYLOAD');
69
- expect(payloadValue).toEqual({foo: 'bar'});
70
-
71
- payloadValue = responseExampleRepresentationManager.getPropertyValue('TYPE');
72
- expect(payloadValue).toEqual({foo: 'bar'});
73
-
74
- payloadValue = responseExampleRepresentationManager.getPropertyValue('PAYLOAD', 1);
75
- expect(payloadValue).toEqual({foo: 'bar', bar: 'baz'});
76
- });
77
-
78
- it('should get property value with array literal expression', () => {
79
- const arrayLiteralExpression : ArrayLiteralExpression = {
80
- kind: SyntaxKind.ArrayLiteralExpression,
81
- elements: [
82
- {text: 'auth', flags: NodeFlags.None, parent: undefined} as unknown as Expression,
83
- {text: 'admin', flags: NodeFlags.None, parent: undefined} as unknown as Expression,
84
- ] as unknown as NodeArray<Expression>
85
- } as ArrayLiteralExpression;
86
-
87
- const manager = new RepresentationManager<'SWAGGER_TAGS'>(swaggerTagsRepresentation, [
88
- {text: 'SwaggerTags', arguments: [arrayLiteralExpression], typeArguments: []}
89
- ]);
90
-
91
- const value = manager.getPropertyValue('DEFAULT');
92
- expect(value).toEqual(['auth', 'admin']);
93
- });
94
-
95
- it('should not get property value', () => {
96
- let value = swaggerTagsRepresentationManager.getPropertyValue('DEFAULT', 2);
97
- expect(value).toEqual([]);
98
-
99
- value = swaggerTagsRepresentationManager.getPropertyValue('DEFAULT', 3);
100
- expect(value).toBeUndefined();
101
- })
102
- });
@@ -1,47 +0,0 @@
1
- /*
2
- * Copyright (c) 2021.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import {Node, SyntaxKind} from 'typescript';
9
- import {getNodeDecorators} from "../../../../src";
10
-
11
- describe('src/decorator/utils/node.ts', () => {
12
- const fakeNode : Record<string, any> = {
13
- decorators: [
14
- {
15
- expression: {
16
- kind: SyntaxKind.CallExpression,
17
- arguments: [
18
- {
19
- kind: SyntaxKind.StringLiteral,
20
- text: 'foo'
21
- },
22
- {
23
- kind: SyntaxKind.NumericLiteral,
24
- text: 0
25
- }
26
- ],
27
- typeArguments: [],
28
- expression: {
29
- text: 'MyText'
30
- }
31
- }
32
- }
33
- ],
34
- };
35
-
36
- it('should get node decorators', () => {
37
- const decorators = getNodeDecorators(fakeNode as Node);
38
-
39
- expect(decorators).toBeDefined();
40
- expect(decorators.length).toEqual(1);
41
- expect(decorators[0].arguments.length).toEqual(2);
42
- expect(decorators[0].arguments).toEqual(['foo', 0]);
43
-
44
- expect(decorators[0].typeArguments.length).toEqual(0);
45
- expect(decorators[0].typeArguments).toEqual([]);
46
- })
47
- });
@@ -1,342 +0,0 @@
1
- /*
2
- * Copyright (c) 2021.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import path from "path";
9
- const jsonata = require('jsonata');
10
- import {Config, MetadataGenerator, Property, Resolver} from "../../../src";
11
-
12
- const config : Config = {
13
- entryFile: ['./test/data/library/typescript-rest/api.ts'],
14
- cache: {
15
- directoryPath: './writable',
16
- clearAtRandom: false,
17
- enabled: false,
18
- fileName: 'metadata.json'
19
- },
20
- decorator: {
21
- internal: true,
22
- library: 'typescript-rest'
23
- }
24
- };
25
-
26
- const generator = new MetadataGenerator(config, {});
27
-
28
- const metadata = generator.generate();
29
-
30
- describe('library/typescript-rest', () => {
31
- it('should be generated and have top level properties', () => {
32
- expect(metadata).toBeDefined();
33
- expect(metadata).toHaveProperty('controllers');
34
- expect(metadata).toHaveProperty('referenceTypes');
35
- });
36
-
37
- describe('check controllers', () => {
38
- it('should have elements', () => {
39
- expect(metadata.controllers.length).toBeGreaterThan(0);
40
- });
41
-
42
- it('should have abstract structure', () => {
43
- expect(metadata.controllers[0]).toHaveProperty('consumes');
44
- expect(metadata.controllers[0].consumes.length).toEqual(0);
45
-
46
- expect(metadata.controllers[0]).toHaveProperty('location');
47
- expect(metadata.controllers[0].location).toEqual("test/data/library/typescript-rest/api.ts");
48
-
49
- expect(metadata.controllers[0]).toHaveProperty('methods');
50
- expect(metadata.controllers[0].methods.length).toBeGreaterThan(0);
51
-
52
- expect(metadata.controllers[0]).toHaveProperty('name');
53
- expect(metadata.controllers[0].name).toEqual('TestUnionType');
54
-
55
- expect(metadata.controllers[0]).toHaveProperty('path');
56
- expect(metadata.controllers[0].path).toEqual('unionTypes');
57
-
58
- expect(metadata.controllers[0]).toHaveProperty('produces');
59
- expect(metadata.controllers[0].produces.length).toEqual(0);
60
-
61
- expect(metadata.controllers[0]).toHaveProperty('responses');
62
- expect(metadata.controllers[0].responses.length).toEqual(0);
63
-
64
- expect(metadata.controllers[0]).toHaveProperty('tags');
65
- expect(metadata.controllers[0].tags.length).toEqual(0);
66
- });
67
-
68
- it('should have methods', () => {
69
- const method = metadata.controllers[0].methods[0];
70
-
71
- expect(method).toHaveProperty('consumes');
72
- expect(method.consumes.length).toEqual(0);
73
-
74
- expect(method).toHaveProperty('deprecated');
75
- expect(method.deprecated).toBeFalsy();
76
-
77
- expect(method).toHaveProperty('extensions');
78
- expect(method.extensions.length).toEqual(0);
79
-
80
- expect(method).toHaveProperty('hidden');
81
- expect(method.hidden).toBeFalsy();
82
-
83
- expect(method).toHaveProperty('method');
84
- expect(method.method).toEqual("post");
85
-
86
- expect(method).toHaveProperty('name');
87
- expect(method.name).toEqual("post");
88
-
89
- expect(method).toHaveProperty('parameters');
90
- expect(method.parameters.length).toBeGreaterThan(0);
91
-
92
- expect(method).toHaveProperty('path');
93
- expect(method.path).toEqual("");
94
-
95
- expect(method).toHaveProperty('produces');
96
- expect(method.produces.length).toEqual(0);
97
-
98
- expect(method).toHaveProperty('responses');
99
- expect(method.responses.length).toEqual(1);
100
-
101
- expect(method).toHaveProperty('tags');
102
- expect(method.tags.length).toEqual(0);
103
-
104
- expect(method).toHaveProperty('type');
105
- expect(method.type).toHaveProperty('typeName');
106
- expect(method.type.typeName).toEqual('string');
107
- });
108
- })
109
-
110
- describe('check referenceTypes', () => {
111
- it('referenceTypes should be defined', () => {
112
- expect(metadata.referenceTypes).toHaveProperty('MyTypeWithUnion');
113
- expect(metadata.referenceTypes).toHaveProperty('Address');
114
- expect(metadata.referenceTypes).toHaveProperty('Person');
115
- expect(metadata.referenceTypes).toHaveProperty('TestEnum');
116
- expect(metadata.referenceTypes).toHaveProperty('TestNumericEnum');
117
- expect(metadata.referenceTypes).toHaveProperty('TestMixedEnum');
118
- expect(metadata.referenceTypes).toHaveProperty('TestInterface');
119
- // todo: tod object keys seem not to work :(
120
- // expect(metadata.referenceTypes).toHaveProperty('Return\.NewResourcePerson');
121
- // expect(metadata.referenceTypes).toHaveProperty('Return\.DownloadBinaryData');
122
- expect(metadata.referenceTypes).toHaveProperty('MyDataType2');
123
- expect(metadata.referenceTypes).toHaveProperty('UUID');
124
- expect(metadata.referenceTypes).toHaveProperty('Something');
125
- expect(metadata.referenceTypes).toHaveProperty('SimpleHelloType');
126
- expect(metadata.referenceTypes).toHaveProperty('PrimitiveClassModel');
127
- expect(metadata.referenceTypes).toHaveProperty('PrimitiveInterfaceModel');
128
- expect(metadata.referenceTypes).toHaveProperty('ResponseBodystringarray');
129
- expect(metadata.referenceTypes).toHaveProperty('NamedEntity');
130
- });
131
-
132
- it('referenceType MyTypeWithUnion', () => {
133
- let expression = jsonata("MyTypeWithUnion.properties[0]");
134
- let value : Property = expression.evaluate(metadata.referenceTypes);
135
-
136
- expect(value.name).toEqual('property');
137
- expect(value.required).toBeTruthy();
138
- expect(value.type).toBeDefined();
139
- expect(value.type.typeName).toEqual('union');
140
- expect((value.type as Resolver.UnionType).members).toBeDefined();
141
- expect((value.type as Resolver.UnionType).members.length).toEqual(2);
142
- expect((value.type as Resolver.UnionType).members[0].typeName).toEqual('enum');
143
- expect((value.type as Resolver.UnionType).members[1].typeName).toEqual('enum');
144
- })
145
-
146
- it('referenceType Address', () => {
147
- let expression = jsonata("Address.properties[0]");
148
- let value : Property = expression.evaluate(metadata.referenceTypes);
149
-
150
- expect(value.name).toEqual('street');
151
- expect(value.required).toBeTruthy();
152
- expect(value.type).toBeDefined();
153
- expect(value.type.typeName).toEqual('string');
154
- })
155
-
156
- it('referenceType Person', () => {
157
- let expression = jsonata("Person.properties[0]");
158
- let value : Property = expression.evaluate(metadata.referenceTypes);
159
-
160
- expect(value.name).toEqual('name');
161
- expect(value.required).toBeTruthy();
162
- expect(value.type).toBeDefined();
163
- expect(value.type.typeName).toEqual('string');
164
-
165
- expression = jsonata("Person.properties[1]");
166
- value = expression.evaluate(metadata.referenceTypes);
167
-
168
- expect(value.name).toEqual('address');
169
- expect(value.required).toBeFalsy();
170
- expect(value.type).toBeDefined();
171
- expect(value.type.typeName).toEqual('refObject');
172
- })
173
-
174
- it('referenceType TestEnum', () => {
175
- let expression = jsonata("TestEnum");
176
- let value : Resolver.RefEnumType = expression.evaluate(metadata.referenceTypes);
177
-
178
- expect(value.typeName).toEqual('refEnum');
179
- expect(value.members).toEqual(["option1", "option2"]);
180
- expect(value.memberNames).toEqual(["Option1", "Option2"]);
181
- expect(value.deprecated).toBeFalsy();
182
- })
183
-
184
- it('referenceType TestNumericEnum', () => {
185
- let expression = jsonata("TestNumericEnum");
186
- let value : Resolver.RefEnumType = expression.evaluate(metadata.referenceTypes);
187
-
188
- expect(value.typeName).toEqual('refEnum');
189
- expect(value.members).toEqual([0, 1]);
190
- expect(value.memberNames).toEqual(["Option1", "Option2"]);
191
- expect(value.deprecated).toBeFalsy();
192
- })
193
-
194
- it('referenceType TestMixedEnum', () => {
195
- let expression = jsonata("TestMixedEnum");
196
- let value : Resolver.RefEnumType = expression.evaluate(metadata.referenceTypes);
197
-
198
- expect(value.typeName).toEqual('refEnum');
199
- expect(value.members).toEqual([0, "option2"]);
200
- expect(value.memberNames).toEqual(["Option1", "Option2"]);
201
- expect(value.deprecated).toBeFalsy();
202
- })
203
-
204
- it('referenceType TestInterface', () => {
205
- let expression = jsonata("TestInterface");
206
- let value : Resolver.RefObjectType = expression.evaluate(metadata.referenceTypes);
207
-
208
- expect(value.typeName).toEqual('refObject');
209
-
210
- expect(value.properties).toBeDefined();
211
- expect(value.properties.length).toEqual(2);
212
-
213
- expect(value.properties[0].name).toEqual("a");
214
- expect(value.properties[0].type.typeName).toEqual("string");
215
-
216
- expect(value.properties[1].name).toEqual("b");
217
- expect(value.properties[1].type.typeName).toEqual("double");
218
- })
219
-
220
- it('referenceType MyDataType2', () => {
221
- let expression = jsonata("MyDataType2");
222
- let value : Resolver.RefObjectType = expression.evaluate(metadata.referenceTypes);
223
-
224
- expect(value.typeName).toEqual('refObject');
225
-
226
- expect(value.properties).toBeDefined();
227
- expect(value.properties.length).toEqual(2);
228
-
229
- expect(value.properties[0].name).toEqual("prop");
230
- expect(value.properties[0].type.typeName).toEqual("string");
231
-
232
- expect(value.properties[1].name).toEqual("property1");
233
- expect(value.properties[1].type.typeName).toEqual("string");
234
- })
235
-
236
- it('referenceType UUID', () => {
237
- let expression = jsonata("UUID");
238
- let value : Resolver.RefAliasType = expression.evaluate(metadata.referenceTypes);
239
-
240
- expect(value.typeName).toEqual('refAlias');
241
- expect(value.refName).toEqual('UUID');
242
- expect(value.type.typeName).toEqual('string');
243
- })
244
-
245
- it('referenceType Something', () => {
246
- let expression = jsonata("Something");
247
- let value : Resolver.RefObjectType = expression.evaluate(metadata.referenceTypes);
248
-
249
- expect(value.typeName).toEqual('refObject');
250
-
251
- expect(value.properties).toBeDefined();
252
- expect(value.properties.length).toEqual(3);
253
-
254
- expect(value.properties[0].name).toEqual("id");
255
- expect(value.properties[0].type.typeName).toEqual("refAlias");
256
- expect((value.properties[0].type as Resolver.RefAliasType).refName).toEqual("UUID");
257
-
258
- expect(value.properties[1].name).toEqual("someone");
259
- expect(value.properties[1].type.typeName).toEqual("string");
260
-
261
- expect(value.properties[2].name).toEqual("kind");
262
- expect(value.properties[2].type.typeName).toEqual("string");
263
- })
264
-
265
- it('referenceType SimpleHelloType', () => {
266
- let expression = jsonata("SimpleHelloType");
267
- let value : Resolver.RefAliasType = expression.evaluate(metadata.referenceTypes);
268
-
269
- expect(value.typeName).toEqual('refAlias');
270
-
271
- expect(value.type.typeName).toEqual('nestedObjectLiteral');
272
-
273
- const typeValue = value.type as Resolver.NestedObjectLiteralType;
274
-
275
- expect(typeValue.properties).toBeDefined();
276
- expect(typeValue.properties.length).toEqual(4);
277
-
278
- expect(typeValue.properties[0].name).toEqual("comparePassword");
279
- expect(typeValue.properties[0].type.typeName).toEqual("object");
280
-
281
- expect(typeValue.properties[1].name).toEqual("profile");
282
- expect(typeValue.properties[1].description).toEqual("Description for profile");
283
- expect(typeValue.properties[1].type.typeName).toEqual("nestedObjectLiteral");
284
-
285
- expect(typeValue.properties[2].name).toEqual("arrayOfSomething");
286
- expect(typeValue.properties[2].type.typeName).toEqual("array");
287
-
288
- const arrayElementTypeValue = (typeValue.properties[2].type as Resolver.ArrayType).elementType;
289
-
290
- expect(arrayElementTypeValue.typeName).toEqual('refObject');
291
- expect((arrayElementTypeValue as Resolver.RefObjectType).refName).toEqual('Something');
292
-
293
- expect(typeValue.properties[3].name).toEqual("greeting");
294
- expect(typeValue.properties[3].type.typeName).toEqual("string");
295
- })
296
-
297
- it('referenceType PrimitiveClassModel & PrimitiveInterfaceModel', () => {
298
- const values : Resolver.RefObjectType[] = [
299
- jsonata("PrimitiveClassModel").evaluate(metadata.referenceTypes),
300
- jsonata("PrimitiveInterfaceModel").evaluate(metadata.referenceTypes)
301
- ];
302
-
303
- values.map(value => {
304
- expect(value.typeName).toEqual('refObject');
305
- expect(value.properties).toBeDefined();
306
- expect(value.properties.length).toEqual(4);
307
-
308
- expect(value.properties[0].name).toEqual("int");
309
- expect(value.properties[0].description).toEqual("An integer");
310
- expect(value.properties[0].type.typeName).toEqual("integer");
311
-
312
- expect(value.properties[1].name).toEqual("long");
313
- expect(value.properties[1].type.typeName).toEqual("long");
314
-
315
- expect(value.properties[2].name).toEqual("float");
316
- expect(value.properties[2].type.typeName).toEqual("float");
317
-
318
- expect(value.properties[3].name).toEqual("double");
319
- expect(value.properties[3].type.typeName).toEqual("double");
320
- });
321
- });
322
-
323
- it('referenceType ResponseBodystringarray', () => {
324
- let expression = jsonata("ResponseBodystringarray");
325
- let value: Resolver.RefObjectType = expression.evaluate(metadata.referenceTypes);
326
-
327
- expect(value.properties).toBeDefined();
328
- expect(value.properties[0].name).toEqual('data');
329
- expect(value.properties[0].required).toBeTruthy();
330
- expect(value.properties[0].type.typeName).toEqual('array');
331
- expect((value.properties[0].type as Resolver.ArrayType).elementType.typeName).toEqual('string');
332
- });
333
-
334
- it('referenceType NamedEntity', () => {
335
- let expression = jsonata("NamedEntity");
336
- let value: Resolver.RefObjectType = expression.evaluate(metadata.referenceTypes);
337
-
338
- expect(value).toBeDefined();
339
- // todo: better testing.
340
- });
341
- })
342
- })