@api-client/core 0.14.0 → 0.14.1
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/build/src/amf/AmfTypes.d.ts +1 -1
- package/build/src/amf/AmfTypes.js +1 -1
- package/build/src/amf/AmfTypes.js.map +1 -1
- package/build/src/amf/Utils.d.ts +0 -6
- package/build/src/amf/Utils.d.ts.map +1 -1
- package/build/src/amf/Utils.js +0 -14
- package/build/src/amf/Utils.js.map +1 -1
- package/build/src/browser.d.ts +1 -0
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +1 -0
- package/build/src/browser.js.map +1 -1
- package/build/src/index.d.ts +1 -0
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +1 -0
- package/build/src/index.js.map +1 -1
- package/build/src/legacy.d.ts +0 -8
- package/build/src/legacy.d.ts.map +1 -1
- package/build/src/legacy.js +0 -9
- package/build/src/legacy.js.map +1 -1
- package/build/src/modeling/Bindings.d.ts +1 -1
- package/build/src/modeling/Bindings.js.map +1 -1
- package/build/src/modeling/DataDomain.js +2 -2
- package/build/src/modeling/DataDomain.js.map +1 -1
- package/build/src/modeling/DataFormat.d.ts +0 -40
- package/build/src/modeling/DataFormat.d.ts.map +1 -1
- package/build/src/modeling/DataFormat.js +0 -27
- package/build/src/modeling/DataFormat.js.map +1 -1
- package/build/src/modeling/DomainAssociation.d.ts +28 -0
- package/build/src/modeling/DomainAssociation.d.ts.map +1 -1
- package/build/src/modeling/DomainAssociation.js +73 -4
- package/build/src/modeling/DomainAssociation.js.map +1 -1
- package/build/src/modeling/DomainEntity.d.ts +25 -9
- package/build/src/modeling/DomainEntity.d.ts.map +1 -1
- package/build/src/modeling/DomainEntity.js +65 -21
- package/build/src/modeling/DomainEntity.js.map +1 -1
- package/build/src/modeling/DomainFile.d.ts +1 -1
- package/build/src/modeling/DomainFile.js +1 -1
- package/build/src/modeling/DomainFile.js.map +1 -1
- package/build/src/modeling/DomainImpactAnalysis.d.ts +1 -1
- package/build/src/modeling/DomainImpactAnalysis.d.ts.map +1 -1
- package/build/src/modeling/DomainImpactAnalysis.js +3 -3
- package/build/src/modeling/DomainImpactAnalysis.js.map +1 -1
- package/build/src/modeling/DomainModel.d.ts +2 -2
- package/build/src/modeling/DomainModel.js +2 -2
- package/build/src/modeling/DomainModel.js.map +1 -1
- package/build/src/modeling/DomainProperty.d.ts +28 -12
- package/build/src/modeling/DomainProperty.d.ts.map +1 -1
- package/build/src/modeling/DomainProperty.js +61 -26
- package/build/src/modeling/DomainProperty.js.map +1 -1
- package/build/src/modeling/Semantics.d.ts +109 -0
- package/build/src/modeling/Semantics.d.ts.map +1 -0
- package/build/src/modeling/Semantics.js +97 -0
- package/build/src/modeling/Semantics.js.map +1 -0
- package/build/src/models/kinds.d.ts +0 -24
- package/build/src/models/kinds.d.ts.map +1 -1
- package/build/src/models/kinds.js +0 -24
- package/build/src/models/kinds.js.map +1 -1
- package/build/src/models/store/data_catalog.d.ts +1 -1
- package/build/src/models/store/data_catalog.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/data/models/example-generator-api.json +11 -11
- package/package.json +1 -1
- package/src/amf/AmfTypes.ts +1 -1
- package/src/amf/Utils.ts +0 -15
- package/src/modeling/Bindings.ts +1 -1
- package/src/modeling/DataDomain.ts +2 -2
- package/src/modeling/DataFormat.ts +0 -48
- package/src/modeling/DomainAssociation.ts +66 -3
- package/src/modeling/DomainEntity.ts +56 -17
- package/src/modeling/DomainFile.ts +1 -1
- package/src/modeling/DomainImpactAnalysis.ts +3 -3
- package/src/modeling/DomainModel.ts +2 -2
- package/src/modeling/DomainProperty.ts +60 -21
- package/src/modeling/Semantics.ts +178 -0
- package/src/modeling/graph.md +14 -14
- package/src/modeling/readme.md +29 -29
- package/src/models/kinds.ts +0 -25
- package/src/models/store/data_catalog.ts +1 -1
- package/tests/unit/modeling/data_domain_change_observers.spec.ts +11 -10
- package/tests/unit/modeling/data_domain_entities.spec.ts +129 -1
- package/tests/unit/modeling/data_domain_property.spec.ts +1 -1
- package/tests/unit/modeling/domain_asociation.spec.ts +177 -0
- package/tests/unit/modeling/domain_entity.spec.ts +27 -26
- package/tests/unit/modeling/domain_entity_example_generator_json.spec.ts +11 -11
- package/tests/unit/modeling/domain_entity_example_generator_xml.spec.ts +10 -10
- package/tests/unit/modeling/{domain.property.spec.ts → domain_property.spec.ts} +139 -23
- package/build/src/amf/AmfShapeGenerator.d.ts +0 -103
- package/build/src/amf/AmfShapeGenerator.d.ts.map +0 -1
- package/build/src/amf/AmfShapeGenerator.js +0 -416
- package/build/src/amf/AmfShapeGenerator.js.map +0 -1
- package/build/src/modeling/legacy/DataAssociation.d.ts +0 -284
- package/build/src/modeling/legacy/DataAssociation.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataAssociation.js +0 -443
- package/build/src/modeling/legacy/DataAssociation.js.map +0 -1
- package/build/src/modeling/legacy/DataEntity.d.ts +0 -358
- package/build/src/modeling/legacy/DataEntity.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataEntity.js +0 -855
- package/build/src/modeling/legacy/DataEntity.js.map +0 -1
- package/build/src/modeling/legacy/DataEntityBuilder.d.ts +0 -162
- package/build/src/modeling/legacy/DataEntityBuilder.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataEntityBuilder.js +0 -221
- package/build/src/modeling/legacy/DataEntityBuilder.js.map +0 -1
- package/build/src/modeling/legacy/DataImpactAnalysis.d.ts +0 -298
- package/build/src/modeling/legacy/DataImpactAnalysis.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataImpactAnalysis.js +0 -441
- package/build/src/modeling/legacy/DataImpactAnalysis.js.map +0 -1
- package/build/src/modeling/legacy/DataModel.d.ts +0 -99
- package/build/src/modeling/legacy/DataModel.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataModel.js +0 -237
- package/build/src/modeling/legacy/DataModel.js.map +0 -1
- package/build/src/modeling/legacy/DataNamespace.d.ts +0 -340
- package/build/src/modeling/legacy/DataNamespace.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataNamespace.js +0 -784
- package/build/src/modeling/legacy/DataNamespace.js.map +0 -1
- package/build/src/modeling/legacy/DataProperty.d.ts +0 -332
- package/build/src/modeling/legacy/DataProperty.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataProperty.js +0 -415
- package/build/src/modeling/legacy/DataProperty.js.map +0 -1
- package/build/src/models/store/DataFile.d.ts +0 -29
- package/build/src/models/store/DataFile.d.ts.map +0 -1
- package/build/src/models/store/DataFile.js +0 -87
- package/build/src/models/store/DataFile.js.map +0 -1
- package/src/amf/AmfShapeGenerator.ts +0 -477
- package/src/modeling/legacy/DataAssociation.ts +0 -554
- package/src/modeling/legacy/DataEntity.ts +0 -1019
- package/src/modeling/legacy/DataEntityBuilder.ts +0 -236
- package/src/modeling/legacy/DataImpactAnalysis.ts +0 -530
- package/src/modeling/legacy/DataModel.ts +0 -276
- package/src/modeling/legacy/DataNamespace.ts +0 -929
- package/src/modeling/legacy/DataProperty.ts +0 -630
- package/src/models/store/DataFile.ts +0 -95
- package/tests/unit/modeling/legacy/amf_shape_generator.spec.ts +0 -1041
- package/tests/unit/modeling/legacy/data_association.spec.ts +0 -710
- package/tests/unit/modeling/legacy/data_entity.spec.ts +0 -2061
- package/tests/unit/modeling/legacy/data_entity_generator_json.spec.ts +0 -987
- package/tests/unit/modeling/legacy/data_entity_generator_xml.spec.ts +0 -1451
- package/tests/unit/modeling/legacy/data_model.spec.ts +0 -395
- package/tests/unit/modeling/legacy/data_namespace.spec.ts +0 -1312
- package/tests/unit/modeling/legacy/data_property.spec.ts +0 -887
- package/tests/unit/modeling/legacy/impact_analysis.spec.ts +0 -373
|
@@ -1,987 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-len */
|
|
2
|
-
import { test } from '@japa/runner'
|
|
3
|
-
import { DataNamespace, DataEntity, DataModel, DataProperty } from '../../../../src/legacy.js'
|
|
4
|
-
|
|
5
|
-
// const rfc2616Re =
|
|
6
|
-
// /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), ([0-3][0-9]) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([0-9]{4}) ([01][0-9]|2[0-3])(:[0-5][0-9]){2} GMT$/
|
|
7
|
-
const rfc3339Re = /^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}Z$/
|
|
8
|
-
const dateRe = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/
|
|
9
|
-
const timeRe = /^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/
|
|
10
|
-
const mime = 'application/json'
|
|
11
|
-
|
|
12
|
-
test.group('JSON DataEntity Generator: string', (group) => {
|
|
13
|
-
let e1: DataEntity
|
|
14
|
-
|
|
15
|
-
group.each.setup(() => {
|
|
16
|
-
const ns = new DataNamespace()
|
|
17
|
-
const d1 = ns.addDataModel('d1')
|
|
18
|
-
e1 = d1.addEntity('e1')
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
test('generates an example', ({ assert }) => {
|
|
22
|
-
e1.addTypedProperty('string', 'p1')
|
|
23
|
-
const result = e1.toExample(mime) as string
|
|
24
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
25
|
-
const data = JSON.parse(result as string)
|
|
26
|
-
assert.typeOf(data.p1, 'string', 'has the property value')
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
test('has min length with schema', ({ assert }) => {
|
|
30
|
-
const p1 = e1.addTypedProperty('string', 'p1')
|
|
31
|
-
p1.schema = {
|
|
32
|
-
minimum: 10,
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const result = e1.toExample(mime) as string
|
|
36
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
37
|
-
const data = JSON.parse(result as string)
|
|
38
|
-
assert.typeOf(data.p1, 'string', 'has the property value')
|
|
39
|
-
assert.isAtLeast(data.p1.length, 10, 'has the minimum length')
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
test('has max length with schema', ({ assert }) => {
|
|
43
|
-
const p1 = e1.addTypedProperty('string', 'p1')
|
|
44
|
-
p1.schema = {
|
|
45
|
-
maximum: 10,
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const result = e1.toExample(mime) as string
|
|
49
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
50
|
-
const data = JSON.parse(result as string)
|
|
51
|
-
assert.typeOf(data.p1, 'string', 'has the property value')
|
|
52
|
-
assert.isAtMost(data.p1.length, 10, 'has the maximum length')
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
test('returns an array when multiple property', ({ assert }) => {
|
|
56
|
-
const p1 = e1.addTypedProperty('string', 'p1')
|
|
57
|
-
p1.multiple = true
|
|
58
|
-
const result = e1.toExample(mime) as string
|
|
59
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
60
|
-
const data = JSON.parse(result as string)
|
|
61
|
-
assert.typeOf(data.p1, 'array', 'has the array value')
|
|
62
|
-
assert.lengthOf(data.p1, 1, 'has a single value')
|
|
63
|
-
assert.typeOf(data.p1[0], 'string', 'has a final value correct type')
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
test('returns example value when defined on the mime type scheme', ({ assert }) => {
|
|
67
|
-
const p1 = e1.addTypedProperty('string', 'p1')
|
|
68
|
-
p1.schema = {
|
|
69
|
-
minimum: 1,
|
|
70
|
-
maximum: 3,
|
|
71
|
-
examples: ['test123'],
|
|
72
|
-
}
|
|
73
|
-
const result = e1.toExample(mime) as string
|
|
74
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
75
|
-
const data = JSON.parse(result as string)
|
|
76
|
-
assert.equal(data.p1, 'test123', 'has the example value')
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
test('returns all example values with multiple property', ({ assert }) => {
|
|
80
|
-
const p1 = e1.addTypedProperty('string', 'p1')
|
|
81
|
-
p1.multiple = true
|
|
82
|
-
p1.schema = {
|
|
83
|
-
examples: ['test123', '123test'],
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const result = e1.toExample(mime) as string
|
|
87
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
88
|
-
const data = JSON.parse(result as string)
|
|
89
|
-
assert.deepEqual(data.p1, ['test123', '123test'], 'has the examples value')
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
test('returns the default value when defined', ({ assert }) => {
|
|
93
|
-
const p1 = e1.addTypedProperty('string', 'p1')
|
|
94
|
-
p1.schema = {
|
|
95
|
-
defaultValue: { value: 'test123', type: 'literal' },
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const result = e1.toExample(mime) as string
|
|
99
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
100
|
-
const data = JSON.parse(result as string)
|
|
101
|
-
assert.deepEqual(data.p1, 'test123', 'has the default value')
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
test('returns the default value when multiple property', ({ assert }) => {
|
|
105
|
-
const p1 = e1.addTypedProperty('string', 'p1')
|
|
106
|
-
p1.multiple = true
|
|
107
|
-
p1.schema = {
|
|
108
|
-
defaultValue: { value: 'test123', type: 'literal' },
|
|
109
|
-
}
|
|
110
|
-
const result = e1.toExample(mime) as string
|
|
111
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
112
|
-
const data = JSON.parse(result as string)
|
|
113
|
-
assert.deepEqual(data.p1, ['test123'], 'has the default value')
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
test('respects both the min and max length', ({ assert }) => {
|
|
117
|
-
const p1 = e1.addTypedProperty('string', 'p1')
|
|
118
|
-
p1.schema = {
|
|
119
|
-
minimum: 15,
|
|
120
|
-
maximum: 30,
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const result = e1.toExample(mime) as string
|
|
124
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
125
|
-
const data = JSON.parse(result as string)
|
|
126
|
-
assert.typeOf(data.p1, 'string', 'has the property value')
|
|
127
|
-
assert.isAtLeast(data.p1.length, 15, 'has the minimum length')
|
|
128
|
-
assert.isAtMost(data.p1.length, 30, 'has the maximum length')
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
test('respects the hidden binding', ({ assert }) => {
|
|
132
|
-
e1.addTypedProperty('string', 'p1')
|
|
133
|
-
const p2 = e1.addTypedProperty('string', 'p2')
|
|
134
|
-
p2.getWebBinding().hidden = true
|
|
135
|
-
const result = e1.toExample(mime) as string
|
|
136
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
137
|
-
const data = JSON.parse(result as string)
|
|
138
|
-
assert.typeOf(data.p1, 'string', 'has the property value')
|
|
139
|
-
assert.isUndefined(data.p2, 'hidden property is not set')
|
|
140
|
-
})
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
test.group('JSON DataEntity Generator: number', (group) => {
|
|
144
|
-
let e1: DataEntity
|
|
145
|
-
|
|
146
|
-
group.each.setup(() => {
|
|
147
|
-
const ns = new DataNamespace()
|
|
148
|
-
const d1 = ns.addDataModel('d1')
|
|
149
|
-
e1 = d1.addEntity('e1')
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
test('generates an example value', ({ assert }) => {
|
|
153
|
-
e1.addTypedProperty('number', 'p1')
|
|
154
|
-
const result = e1.toExample(mime) as string
|
|
155
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
156
|
-
const data = JSON.parse(result)
|
|
157
|
-
assert.typeOf(data.p1, 'number', 'has the property number')
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
test('has the minimum value', ({ assert }) => {
|
|
161
|
-
const p1 = e1.addTypedProperty('number', 'p1')
|
|
162
|
-
p1.schema = {
|
|
163
|
-
minimum: 10,
|
|
164
|
-
}
|
|
165
|
-
const result = e1.toExample(mime) as string
|
|
166
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
167
|
-
const data = JSON.parse(result)
|
|
168
|
-
assert.isAtLeast(data.p1, 10, 'has the minimum length')
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
test('has the maximum value', ({ assert }) => {
|
|
172
|
-
const p1 = e1.addTypedProperty('number', 'p1')
|
|
173
|
-
p1.schema = {
|
|
174
|
-
maximum: 10,
|
|
175
|
-
}
|
|
176
|
-
const result = e1.toExample(mime) as string
|
|
177
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
178
|
-
const data = JSON.parse(result)
|
|
179
|
-
assert.isAtMost(data.p1, 10, 'has the maximum length')
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
test('respects both the min and max', ({ assert }) => {
|
|
183
|
-
const p1 = e1.addTypedProperty('number', 'p1')
|
|
184
|
-
p1.schema = {
|
|
185
|
-
minimum: 5,
|
|
186
|
-
maximum: 10,
|
|
187
|
-
}
|
|
188
|
-
const result = e1.toExample(mime) as string
|
|
189
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
190
|
-
const data = JSON.parse(result)
|
|
191
|
-
assert.isAtLeast(data.p1, 5, 'has the minimum length')
|
|
192
|
-
assert.isAtMost(data.p1, 10, 'has the maximum length')
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
// Note, this may randomly fail because the data generation library does not
|
|
196
|
-
// guarantee to always generate a float (it does generate a float but with `.00` value).
|
|
197
|
-
test('generates a floating-point number for a float format', ({ assert }) => {
|
|
198
|
-
const p1 = e1.addTypedProperty('number', 'p1')
|
|
199
|
-
p1.bindings = [
|
|
200
|
-
{
|
|
201
|
-
type: 'web',
|
|
202
|
-
schema: {
|
|
203
|
-
format: 'float',
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
]
|
|
207
|
-
const result = e1.toExample(mime) as string
|
|
208
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
209
|
-
const data = JSON.parse(result)
|
|
210
|
-
assert.isNotNaN(data)
|
|
211
|
-
// const rest = data.p1 % 1;
|
|
212
|
-
// assert.isAbove(rest, 0, 'module is above 0');
|
|
213
|
-
// assert.isBelow(rest, 1, 'module is below 0');
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
test('generates a floating-point number for a double format', ({ assert }) => {
|
|
217
|
-
const p1 = e1.addTypedProperty('number', 'p1')
|
|
218
|
-
p1.bindings = [
|
|
219
|
-
{
|
|
220
|
-
type: 'web',
|
|
221
|
-
schema: {
|
|
222
|
-
format: 'double',
|
|
223
|
-
},
|
|
224
|
-
},
|
|
225
|
-
]
|
|
226
|
-
const result = e1.toExample(mime) as string
|
|
227
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
228
|
-
const data = JSON.parse(result)
|
|
229
|
-
assert.isNotNaN(data.p1)
|
|
230
|
-
// const rest = data.p1 % 1;
|
|
231
|
-
// assert.isAbove(rest, 0, 'module is above 0');
|
|
232
|
-
// assert.isBelow(rest, 1, 'module is below 0');
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
test('returns an array number property when multiple property', ({ assert }) => {
|
|
236
|
-
const p1 = e1.addTypedProperty('number', 'p1')
|
|
237
|
-
p1.multiple = true
|
|
238
|
-
const result = e1.toExample(mime) as string
|
|
239
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
240
|
-
const data = JSON.parse(result)
|
|
241
|
-
assert.typeOf(data.p1, 'array', 'has the array value')
|
|
242
|
-
assert.lengthOf(data.p1, 1, 'has a single value')
|
|
243
|
-
assert.typeOf(data.p1[0], 'number', 'has a final value correct type')
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
test('respects the "multipleOf" schema property', ({ assert }) => {
|
|
247
|
-
const p1 = e1.addTypedProperty('number', 'p1')
|
|
248
|
-
p1.schema = {
|
|
249
|
-
multipleOf: 5,
|
|
250
|
-
}
|
|
251
|
-
const result = e1.toExample(mime) as string
|
|
252
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
253
|
-
const data = JSON.parse(result)
|
|
254
|
-
assert.equal(data.p1 % 5, 0, 'has a value multipliable by 5')
|
|
255
|
-
})
|
|
256
|
-
|
|
257
|
-
test('returns the example value', ({ assert }) => {
|
|
258
|
-
const p1 = e1.addTypedProperty('number', 'p1')
|
|
259
|
-
p1.schema = {
|
|
260
|
-
examples: ['1', '2', '3'],
|
|
261
|
-
}
|
|
262
|
-
const result = e1.toExample(mime) as string
|
|
263
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
264
|
-
const data = JSON.parse(result)
|
|
265
|
-
assert.equal(data.p1, 1, 'has the first example')
|
|
266
|
-
})
|
|
267
|
-
|
|
268
|
-
test('returns all examples when multiple property', ({ assert }) => {
|
|
269
|
-
const p1 = e1.addTypedProperty('number', 'p1')
|
|
270
|
-
p1.multiple = true
|
|
271
|
-
p1.schema = {
|
|
272
|
-
examples: ['1', '2', '3'],
|
|
273
|
-
}
|
|
274
|
-
const result = e1.toExample(mime) as string
|
|
275
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
276
|
-
const data = JSON.parse(result)
|
|
277
|
-
assert.deepEqual(data.p1, [1, 2, 3], 'has the first example')
|
|
278
|
-
})
|
|
279
|
-
|
|
280
|
-
test('returns the default value', ({ assert }) => {
|
|
281
|
-
const p1 = e1.addTypedProperty('number', 'p1')
|
|
282
|
-
p1.schema = {
|
|
283
|
-
defaultValue: { value: '123', type: 'literal' },
|
|
284
|
-
}
|
|
285
|
-
const result = e1.toExample(mime) as string
|
|
286
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
287
|
-
const data = JSON.parse(result)
|
|
288
|
-
assert.deepEqual(data.p1, 123, 'has the first example')
|
|
289
|
-
})
|
|
290
|
-
})
|
|
291
|
-
|
|
292
|
-
test.group('JSON DataEntity Generator: int64 format', (group) => {
|
|
293
|
-
let e1: DataEntity
|
|
294
|
-
let p1: DataProperty
|
|
295
|
-
|
|
296
|
-
group.each.setup(() => {
|
|
297
|
-
const ns = new DataNamespace()
|
|
298
|
-
const d1 = ns.addDataModel('d1')
|
|
299
|
-
e1 = d1.addEntity('e1')
|
|
300
|
-
p1 = e1.addTypedProperty('number', 'p1')
|
|
301
|
-
p1.getWebBinding().format = 'int64'
|
|
302
|
-
})
|
|
303
|
-
|
|
304
|
-
test('generates an example value', ({ assert }) => {
|
|
305
|
-
const result = e1.toExample(mime) as string
|
|
306
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
307
|
-
const data = JSON.parse(result)
|
|
308
|
-
assert.typeOf(data.p1, 'number', 'has the property number')
|
|
309
|
-
})
|
|
310
|
-
|
|
311
|
-
test('has the minimum value', ({ assert }) => {
|
|
312
|
-
p1.schema = {
|
|
313
|
-
minimum: 10,
|
|
314
|
-
}
|
|
315
|
-
const result = e1.toExample(mime) as string
|
|
316
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
317
|
-
const data = JSON.parse(result)
|
|
318
|
-
assert.isAtLeast(data.p1, 10, 'has the minimum length')
|
|
319
|
-
})
|
|
320
|
-
|
|
321
|
-
test('has the maximum value', ({ assert }) => {
|
|
322
|
-
p1.schema = {
|
|
323
|
-
maximum: 10,
|
|
324
|
-
}
|
|
325
|
-
const result = e1.toExample(mime) as string
|
|
326
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
327
|
-
const data = JSON.parse(result)
|
|
328
|
-
assert.isAtMost(data.p1, 10, 'has the maximum length')
|
|
329
|
-
})
|
|
330
|
-
|
|
331
|
-
test('respects both the min and max', ({ assert }) => {
|
|
332
|
-
p1.schema = {
|
|
333
|
-
minimum: 5,
|
|
334
|
-
maximum: 10,
|
|
335
|
-
}
|
|
336
|
-
const result = e1.toExample(mime) as string
|
|
337
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
338
|
-
const data = JSON.parse(result)
|
|
339
|
-
assert.isAtLeast(data.p1, 5, 'has the minimum length')
|
|
340
|
-
assert.isAtMost(data.p1, 10, 'has the maximum length')
|
|
341
|
-
})
|
|
342
|
-
|
|
343
|
-
test('generates an integer for an int32 format', ({ assert }) => {
|
|
344
|
-
p1.bindings = [
|
|
345
|
-
{
|
|
346
|
-
type: 'web',
|
|
347
|
-
schema: {
|
|
348
|
-
format: 'int32',
|
|
349
|
-
},
|
|
350
|
-
},
|
|
351
|
-
]
|
|
352
|
-
const result = e1.toExample(mime) as string
|
|
353
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
354
|
-
const data = JSON.parse(result)
|
|
355
|
-
const rest = data.p1 % 1
|
|
356
|
-
assert.equal(rest, 0, 'module is 0')
|
|
357
|
-
})
|
|
358
|
-
|
|
359
|
-
test('generates an integer for an int64 format', ({ assert }) => {
|
|
360
|
-
const result = e1.toExample(mime) as string
|
|
361
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
362
|
-
const data = JSON.parse(result)
|
|
363
|
-
const rest = data.p1 % 1
|
|
364
|
-
assert.equal(rest, 0, 'module is 0')
|
|
365
|
-
})
|
|
366
|
-
|
|
367
|
-
test('returns an array number property when multiple property', ({ assert }) => {
|
|
368
|
-
p1.multiple = true
|
|
369
|
-
const result = e1.toExample(mime) as string
|
|
370
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
371
|
-
const data = JSON.parse(result)
|
|
372
|
-
assert.typeOf(data.p1, 'array', 'has the array value')
|
|
373
|
-
assert.lengthOf(data.p1, 1, 'has a single value')
|
|
374
|
-
assert.typeOf(data.p1[0], 'number', 'has a final value correct type')
|
|
375
|
-
})
|
|
376
|
-
|
|
377
|
-
test('respects the "multipleOf" schema property', ({ assert }) => {
|
|
378
|
-
p1.schema = {
|
|
379
|
-
multipleOf: 5,
|
|
380
|
-
}
|
|
381
|
-
const result = e1.toExample(mime) as string
|
|
382
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
383
|
-
const data = JSON.parse(result)
|
|
384
|
-
assert.equal(data.p1 % 5, 0, 'has a value multipliable by 5')
|
|
385
|
-
})
|
|
386
|
-
|
|
387
|
-
test('returns the example value', ({ assert }) => {
|
|
388
|
-
p1.schema = {
|
|
389
|
-
examples: ['1', '2', '3'],
|
|
390
|
-
}
|
|
391
|
-
const result = e1.toExample(mime) as string
|
|
392
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
393
|
-
const data = JSON.parse(result)
|
|
394
|
-
assert.equal(data.p1, 1, 'has the first example')
|
|
395
|
-
})
|
|
396
|
-
|
|
397
|
-
test('returns all examples when multiple property', ({ assert }) => {
|
|
398
|
-
p1.multiple = true
|
|
399
|
-
p1.schema = {
|
|
400
|
-
examples: ['1', '2', '3'],
|
|
401
|
-
}
|
|
402
|
-
const result = e1.toExample(mime) as string
|
|
403
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
404
|
-
const data = JSON.parse(result)
|
|
405
|
-
assert.deepEqual(data.p1, [1, 2, 3], 'has the first example')
|
|
406
|
-
})
|
|
407
|
-
|
|
408
|
-
test('returns the default value', ({ assert }) => {
|
|
409
|
-
p1.schema = {
|
|
410
|
-
defaultValue: { value: '123', type: 'literal' },
|
|
411
|
-
}
|
|
412
|
-
const result = e1.toExample(mime) as string
|
|
413
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
414
|
-
const data = JSON.parse(result)
|
|
415
|
-
assert.deepEqual(data.p1, 123, 'has the first example')
|
|
416
|
-
})
|
|
417
|
-
})
|
|
418
|
-
|
|
419
|
-
test.group('JSON DataEntity Generator: date', (group) => {
|
|
420
|
-
let e1: DataEntity
|
|
421
|
-
|
|
422
|
-
group.each.setup(() => {
|
|
423
|
-
const ns = new DataNamespace()
|
|
424
|
-
const d1 = ns.addDataModel('d1')
|
|
425
|
-
e1 = d1.addEntity('e1')
|
|
426
|
-
})
|
|
427
|
-
|
|
428
|
-
test('generates an example', ({ assert }) => {
|
|
429
|
-
e1.addTypedProperty('date', 'p1')
|
|
430
|
-
const result = e1.toExample(mime) as string
|
|
431
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
432
|
-
const data = JSON.parse(result)
|
|
433
|
-
assert.typeOf(data.p1, 'string', 'has the string value')
|
|
434
|
-
assert.match(data.p1, dateRe)
|
|
435
|
-
})
|
|
436
|
-
|
|
437
|
-
test('generates an example with the multiple property', ({ assert }) => {
|
|
438
|
-
const p1 = e1.addTypedProperty('date', 'p1')
|
|
439
|
-
p1.multiple = true
|
|
440
|
-
const result = e1.toExample(mime) as string
|
|
441
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
442
|
-
const data = JSON.parse(result)
|
|
443
|
-
assert.typeOf(data.p1, 'array', 'has the array value')
|
|
444
|
-
assert.lengthOf(data.p1, 1, 'has a single value')
|
|
445
|
-
assert.match(data.p1[0], dateRe)
|
|
446
|
-
})
|
|
447
|
-
|
|
448
|
-
test('returns the default value', ({ assert }) => {
|
|
449
|
-
const p1 = e1.addTypedProperty('date', 'p1')
|
|
450
|
-
p1.schema = {
|
|
451
|
-
defaultValue: { value: '2022-08-08', type: 'literal' },
|
|
452
|
-
}
|
|
453
|
-
const result = e1.toExample(mime) as string
|
|
454
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
455
|
-
const data = JSON.parse(result)
|
|
456
|
-
assert.equal(data.p1, '2022-08-08')
|
|
457
|
-
})
|
|
458
|
-
|
|
459
|
-
test('returns the default value as array with multiple property', ({ assert }) => {
|
|
460
|
-
const p1 = e1.addTypedProperty('date', 'p1')
|
|
461
|
-
p1.multiple = true
|
|
462
|
-
p1.schema = {
|
|
463
|
-
defaultValue: { value: '2022-08-08', type: 'literal' },
|
|
464
|
-
}
|
|
465
|
-
const result = e1.toExample(mime) as string
|
|
466
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
467
|
-
const data = JSON.parse(result)
|
|
468
|
-
assert.deepEqual(data.p1, ['2022-08-08'])
|
|
469
|
-
})
|
|
470
|
-
|
|
471
|
-
test('returns the example value', ({ assert }) => {
|
|
472
|
-
const p1 = e1.addTypedProperty('date', 'p1')
|
|
473
|
-
p1.schema = {
|
|
474
|
-
examples: ['2022-08-08', '2022-08-09'],
|
|
475
|
-
}
|
|
476
|
-
const result = e1.toExample(mime) as string
|
|
477
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
478
|
-
const data = JSON.parse(result)
|
|
479
|
-
assert.equal(data.p1, '2022-08-08')
|
|
480
|
-
})
|
|
481
|
-
|
|
482
|
-
test('returns the default value as array with multiple property', ({ assert }) => {
|
|
483
|
-
const p1 = e1.addTypedProperty('date', 'p1')
|
|
484
|
-
p1.multiple = true
|
|
485
|
-
p1.schema = {
|
|
486
|
-
examples: ['2022-08-08', '2022-08-09'],
|
|
487
|
-
}
|
|
488
|
-
const result = e1.toExample(mime) as string
|
|
489
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
490
|
-
const data = JSON.parse(result)
|
|
491
|
-
assert.deepEqual(data.p1, ['2022-08-08', '2022-08-09'])
|
|
492
|
-
})
|
|
493
|
-
})
|
|
494
|
-
|
|
495
|
-
test.group('JSON DataEntity Generator: datetime', (group) => {
|
|
496
|
-
let e1: DataEntity
|
|
497
|
-
|
|
498
|
-
group.each.setup(() => {
|
|
499
|
-
const ns = new DataNamespace()
|
|
500
|
-
const d1 = ns.addDataModel('d1')
|
|
501
|
-
e1 = d1.addEntity('e1')
|
|
502
|
-
})
|
|
503
|
-
|
|
504
|
-
test('generates an example with default format', ({ assert }) => {
|
|
505
|
-
e1.addTypedProperty('datetime', 'p1')
|
|
506
|
-
const result = e1.toExample(mime) as string
|
|
507
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
508
|
-
const data = JSON.parse(result)
|
|
509
|
-
assert.typeOf(data.p1, 'string', 'has the string value')
|
|
510
|
-
assert.match(data.p1, rfc3339Re)
|
|
511
|
-
})
|
|
512
|
-
|
|
513
|
-
test('returns the default value', ({ assert }) => {
|
|
514
|
-
const p1 = e1.addTypedProperty('datetime', 'p1')
|
|
515
|
-
p1.schema = {
|
|
516
|
-
defaultValue: { value: '2036-01-04T19:49:30.224Z', type: 'literal' },
|
|
517
|
-
}
|
|
518
|
-
const result = e1.toExample(mime) as string
|
|
519
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
520
|
-
const data = JSON.parse(result)
|
|
521
|
-
assert.equal(data.p1, '2036-01-04T19:49:30.224Z')
|
|
522
|
-
})
|
|
523
|
-
|
|
524
|
-
test('returns the default value as array with multiple property', ({ assert }) => {
|
|
525
|
-
const p1 = e1.addTypedProperty('datetime', 'p1')
|
|
526
|
-
p1.multiple = true
|
|
527
|
-
p1.schema = {
|
|
528
|
-
defaultValue: { value: '2036-01-04T19:49:30.224Z', type: 'literal' },
|
|
529
|
-
}
|
|
530
|
-
const result = e1.toExample(mime) as string
|
|
531
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
532
|
-
const data = JSON.parse(result)
|
|
533
|
-
assert.deepEqual(data.p1, ['2036-01-04T19:49:30.224Z'])
|
|
534
|
-
})
|
|
535
|
-
|
|
536
|
-
test('returns the example value', ({ assert }) => {
|
|
537
|
-
const p1 = e1.addTypedProperty('datetime', 'p1')
|
|
538
|
-
p1.schema = {
|
|
539
|
-
examples: ['2036-01-04T19:49:30.224Z', '2036-01-05T19:49:30.224Z'],
|
|
540
|
-
}
|
|
541
|
-
const result = e1.toExample(mime) as string
|
|
542
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
543
|
-
const data = JSON.parse(result)
|
|
544
|
-
assert.equal(data.p1, '2036-01-04T19:49:30.224Z')
|
|
545
|
-
})
|
|
546
|
-
|
|
547
|
-
test('returns the default value as array with multiple property', ({ assert }) => {
|
|
548
|
-
const p1 = e1.addTypedProperty('datetime', 'p1')
|
|
549
|
-
p1.multiple = true
|
|
550
|
-
p1.schema = {
|
|
551
|
-
examples: ['2036-01-04T19:49:30.224Z', '2036-01-05T19:49:30.224Z'],
|
|
552
|
-
}
|
|
553
|
-
const result = e1.toExample(mime) as string
|
|
554
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
555
|
-
const data = JSON.parse(result)
|
|
556
|
-
assert.deepEqual(data.p1, ['2036-01-04T19:49:30.224Z', '2036-01-05T19:49:30.224Z'])
|
|
557
|
-
})
|
|
558
|
-
})
|
|
559
|
-
|
|
560
|
-
test.group('JSON DataEntity Generator: time', (group) => {
|
|
561
|
-
let e1: DataEntity
|
|
562
|
-
|
|
563
|
-
group.each.setup(() => {
|
|
564
|
-
const ns = new DataNamespace()
|
|
565
|
-
const d1 = ns.addDataModel('d1')
|
|
566
|
-
e1 = d1.addEntity('e1')
|
|
567
|
-
})
|
|
568
|
-
|
|
569
|
-
test('generates an example', ({ assert }) => {
|
|
570
|
-
e1.addTypedProperty('time', 'p1')
|
|
571
|
-
const result = e1.toExample(mime) as string
|
|
572
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
573
|
-
const data = JSON.parse(result)
|
|
574
|
-
assert.typeOf(data.p1, 'string', 'has the string value')
|
|
575
|
-
assert.match(data.p1, timeRe)
|
|
576
|
-
})
|
|
577
|
-
|
|
578
|
-
test('generates an example with multiple property', ({ assert }) => {
|
|
579
|
-
const p1 = e1.addTypedProperty('time', 'p1')
|
|
580
|
-
p1.multiple = true
|
|
581
|
-
const result = e1.toExample(mime) as string
|
|
582
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
583
|
-
const data = JSON.parse(result)
|
|
584
|
-
assert.typeOf(data.p1, 'array', 'has the array value')
|
|
585
|
-
assert.lengthOf(data.p1, 1, 'has a single value')
|
|
586
|
-
assert.match(data.p1[0], timeRe)
|
|
587
|
-
})
|
|
588
|
-
|
|
589
|
-
test('returns the default value', ({ assert }) => {
|
|
590
|
-
const p1 = e1.addTypedProperty('time', 'p1')
|
|
591
|
-
p1.schema = {
|
|
592
|
-
defaultValue: { value: '2080-02-04T09:39:13', type: 'literal' },
|
|
593
|
-
}
|
|
594
|
-
const result = e1.toExample(mime) as string
|
|
595
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
596
|
-
const data = JSON.parse(result)
|
|
597
|
-
assert.equal(data.p1, '2080-02-04T09:39:13')
|
|
598
|
-
})
|
|
599
|
-
|
|
600
|
-
test('returns the default value as array with multiple property', ({ assert }) => {
|
|
601
|
-
const p1 = e1.addTypedProperty('time', 'p1')
|
|
602
|
-
p1.multiple = true
|
|
603
|
-
p1.schema = {
|
|
604
|
-
defaultValue: { value: '2080-02-04T09:39:13', type: 'literal' },
|
|
605
|
-
}
|
|
606
|
-
const result = e1.toExample(mime) as string
|
|
607
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
608
|
-
const data = JSON.parse(result)
|
|
609
|
-
assert.deepEqual(data.p1, ['2080-02-04T09:39:13'])
|
|
610
|
-
})
|
|
611
|
-
|
|
612
|
-
test('returns the example value', ({ assert }) => {
|
|
613
|
-
const p1 = e1.addTypedProperty('time', 'p1')
|
|
614
|
-
p1.schema = {
|
|
615
|
-
examples: ['2080-02-04T09:39:13', '2080-02-05T09:39:13'],
|
|
616
|
-
}
|
|
617
|
-
const result = e1.toExample(mime) as string
|
|
618
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
619
|
-
const data = JSON.parse(result)
|
|
620
|
-
assert.equal(data.p1, '2080-02-04T09:39:13')
|
|
621
|
-
})
|
|
622
|
-
|
|
623
|
-
test('returns the default value as array with multiple property', ({ assert }) => {
|
|
624
|
-
const p1 = e1.addTypedProperty('time', 'p1')
|
|
625
|
-
p1.multiple = true
|
|
626
|
-
p1.schema = {
|
|
627
|
-
examples: ['2080-02-04T09:39:13', '2080-02-05T09:39:13'],
|
|
628
|
-
}
|
|
629
|
-
const result = e1.toExample(mime) as string
|
|
630
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
631
|
-
const data = JSON.parse(result)
|
|
632
|
-
assert.deepEqual(data.p1, ['2080-02-04T09:39:13', '2080-02-05T09:39:13'])
|
|
633
|
-
})
|
|
634
|
-
})
|
|
635
|
-
|
|
636
|
-
test.group('JSON DataEntity Generator: boolean', (group) => {
|
|
637
|
-
let e1: DataEntity
|
|
638
|
-
|
|
639
|
-
group.each.setup(() => {
|
|
640
|
-
const ns = new DataNamespace()
|
|
641
|
-
const d1 = ns.addDataModel('d1')
|
|
642
|
-
e1 = d1.addEntity('e1')
|
|
643
|
-
})
|
|
644
|
-
|
|
645
|
-
test('generates an example', ({ assert }) => {
|
|
646
|
-
e1.addTypedProperty('boolean', 'p1')
|
|
647
|
-
const result = e1.toExample(mime) as string
|
|
648
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
649
|
-
const data = JSON.parse(result)
|
|
650
|
-
assert.typeOf(data.p1, 'boolean', 'has the boolean value')
|
|
651
|
-
})
|
|
652
|
-
|
|
653
|
-
test('generates an example with multiple property', ({ assert }) => {
|
|
654
|
-
const p1 = e1.addTypedProperty('boolean', 'p1')
|
|
655
|
-
p1.multiple = true
|
|
656
|
-
const result = e1.toExample(mime) as string
|
|
657
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
658
|
-
const data = JSON.parse(result)
|
|
659
|
-
assert.typeOf(data.p1, 'array', 'has the array value')
|
|
660
|
-
assert.lengthOf(data.p1, 1, 'has a single value')
|
|
661
|
-
assert.typeOf(data.p1[0], 'boolean', 'has the final value type')
|
|
662
|
-
})
|
|
663
|
-
})
|
|
664
|
-
|
|
665
|
-
// test.group('JSON DataEntity Generator: nil', (group) => {
|
|
666
|
-
// let e1: DataEntity
|
|
667
|
-
|
|
668
|
-
// group.each.setup(() => {
|
|
669
|
-
// const ns = new DataNamespace()
|
|
670
|
-
// const d1 = ns.addDataModel('d1')
|
|
671
|
-
// e1 = d1.addEntity('e1')
|
|
672
|
-
// })
|
|
673
|
-
|
|
674
|
-
// test('generates an example', ({ assert }) => {
|
|
675
|
-
// e1.addTypedProperty('nil', 'p1')
|
|
676
|
-
// const result = e1.toExample(mime) as string
|
|
677
|
-
// assert.typeOf(result, 'string', 'result is a string')
|
|
678
|
-
// const data = JSON.parse(result)
|
|
679
|
-
// assert.typeOf(data.p1, 'null', 'has the null value')
|
|
680
|
-
// })
|
|
681
|
-
|
|
682
|
-
// test('generates an example with multiple property', ({ assert }) => {
|
|
683
|
-
// const p1 = e1.addTypedProperty('nil', 'p1')
|
|
684
|
-
// p1.multiple = true
|
|
685
|
-
// const result = e1.toExample(mime) as string
|
|
686
|
-
// assert.typeOf(result, 'string', 'result is a string')
|
|
687
|
-
// const data = JSON.parse(result)
|
|
688
|
-
// assert.typeOf(data.p1, 'array', 'has the array value')
|
|
689
|
-
// assert.lengthOf(data.p1, 1, 'has a single value')
|
|
690
|
-
// assert.typeOf(data.p1[0], 'null', 'has the final value type')
|
|
691
|
-
// })
|
|
692
|
-
// })
|
|
693
|
-
|
|
694
|
-
test.group('JSON DataEntity Generator: binary', (group) => {
|
|
695
|
-
let e1: DataEntity
|
|
696
|
-
|
|
697
|
-
group.each.setup(() => {
|
|
698
|
-
const ns = new DataNamespace()
|
|
699
|
-
const d1 = ns.addDataModel('d1')
|
|
700
|
-
e1 = d1.addEntity('e1')
|
|
701
|
-
})
|
|
702
|
-
|
|
703
|
-
test('does not generate an example for a file', ({ assert }) => {
|
|
704
|
-
e1.addTypedProperty('binary', 'p1')
|
|
705
|
-
const result = e1.toExample(mime) as string
|
|
706
|
-
assert.equal(result, '{}')
|
|
707
|
-
})
|
|
708
|
-
|
|
709
|
-
// this could potentially generate a value
|
|
710
|
-
test('does not generate an example for base64 binary format', ({ assert }) => {
|
|
711
|
-
const p1 = e1.addTypedProperty('binary', 'p1')
|
|
712
|
-
p1.getWebBinding().format = 'base64'
|
|
713
|
-
const result = e1.toExample(mime) as string
|
|
714
|
-
assert.equal(result, '{}')
|
|
715
|
-
})
|
|
716
|
-
})
|
|
717
|
-
|
|
718
|
-
test.group('JSON DataEntity Generator: associations', (group) => {
|
|
719
|
-
let n1: DataNamespace
|
|
720
|
-
let d1: DataModel
|
|
721
|
-
let e1: DataEntity
|
|
722
|
-
let e2: DataEntity
|
|
723
|
-
|
|
724
|
-
group.each.setup(() => {
|
|
725
|
-
n1 = new DataNamespace()
|
|
726
|
-
d1 = n1.addDataModel('d1')
|
|
727
|
-
e1 = d1.addEntity('e1')
|
|
728
|
-
e2 = d1.addEntity('e2')
|
|
729
|
-
})
|
|
730
|
-
|
|
731
|
-
test('creates a property from an association', ({ assert }) => {
|
|
732
|
-
e2.addTypedProperty('number', 'n1')
|
|
733
|
-
e1.addTargetAssociation(e2.key, 'a1')
|
|
734
|
-
|
|
735
|
-
const result = e1.toExample(mime) as string
|
|
736
|
-
|
|
737
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
738
|
-
const data = JSON.parse(result)
|
|
739
|
-
assert.typeOf(data.a1, 'object', 'has the association property')
|
|
740
|
-
assert.typeOf(data.a1.n1, 'number', 'has the association properties')
|
|
741
|
-
})
|
|
742
|
-
|
|
743
|
-
test('creates a deep association', ({ assert }) => {
|
|
744
|
-
const e3 = d1.addEntity('e3')
|
|
745
|
-
e3.addTypedProperty('number', 'i1')
|
|
746
|
-
e2.addTypedProperty('number', 'n1')
|
|
747
|
-
e1.addTargetAssociation(e2.key, 'a1')
|
|
748
|
-
e2.addTargetAssociation(e3.key, 'a2')
|
|
749
|
-
|
|
750
|
-
const result = e1.toExample(mime) as string
|
|
751
|
-
|
|
752
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
753
|
-
const data = JSON.parse(result)
|
|
754
|
-
assert.typeOf(data.a1, 'object', 'has the association property')
|
|
755
|
-
assert.typeOf(data.a1.n1, 'number', 'has the association properties')
|
|
756
|
-
assert.typeOf(data.a1.a2, 'object', 'has a deep association')
|
|
757
|
-
assert.typeOf(data.a1.a2.i1, 'number', 'has a deep association property')
|
|
758
|
-
})
|
|
759
|
-
|
|
760
|
-
test('does not make associations to self (recursive #1)', ({ assert }) => {
|
|
761
|
-
e1.addTargetAssociation(e1.key, 'a1')
|
|
762
|
-
const result = e1.toExample(mime) as string
|
|
763
|
-
assert.equal(result, '{}')
|
|
764
|
-
})
|
|
765
|
-
|
|
766
|
-
test('does not make recursive associations (recursive #2)', ({ assert }) => {
|
|
767
|
-
const e3 = d1.addEntity('e3')
|
|
768
|
-
e3.addTypedProperty('number', 'i1')
|
|
769
|
-
e2.addTypedProperty('number', 'n1')
|
|
770
|
-
e1.addTargetAssociation(e2.key, 'a1')
|
|
771
|
-
e2.addTargetAssociation(e3.key, 'a2')
|
|
772
|
-
e3.addTargetAssociation(e1.key, 'a3')
|
|
773
|
-
|
|
774
|
-
const result = e1.toExample(mime) as string
|
|
775
|
-
|
|
776
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
777
|
-
const data = JSON.parse(result)
|
|
778
|
-
assert.typeOf(data.a1, 'object', 'has the association property')
|
|
779
|
-
assert.typeOf(data.a1.n1, 'number', 'has the association properties')
|
|
780
|
-
assert.typeOf(data.a1.a2, 'object', 'has a deep association')
|
|
781
|
-
assert.typeOf(data.a1.a2.i1, 'number', 'has a deep association property')
|
|
782
|
-
assert.isUndefined(data.a1.a2.a3, 'has no recursive property')
|
|
783
|
-
})
|
|
784
|
-
|
|
785
|
-
test('returns the default union result', ({ assert }) => {
|
|
786
|
-
const e3 = d1.addEntity('e3')
|
|
787
|
-
e3.addTypedProperty('number', 'i1')
|
|
788
|
-
e2.addTypedProperty('string', 's1')
|
|
789
|
-
const a1 = e1.addTargetAssociation(e2.key, 'a1')
|
|
790
|
-
a1.addTarget(e3.key)
|
|
791
|
-
|
|
792
|
-
const result = e1.toExample(mime) as string
|
|
793
|
-
|
|
794
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
795
|
-
const data = JSON.parse(result)
|
|
796
|
-
assert.typeOf(data.a1, 'object', 'has the association property')
|
|
797
|
-
assert.typeOf(data.a1.s1, 'string', 'has the association properties')
|
|
798
|
-
})
|
|
799
|
-
|
|
800
|
-
test('returns the default union result with multiple', ({ assert }) => {
|
|
801
|
-
const e3 = d1.addEntity('e3')
|
|
802
|
-
e3.addTypedProperty('number', 'i1')
|
|
803
|
-
e2.addTypedProperty('string', 's1')
|
|
804
|
-
const a1 = e1.addTargetAssociation(e2.key, 'a1')
|
|
805
|
-
a1.addTarget(e3.key)
|
|
806
|
-
a1.multiple = true
|
|
807
|
-
|
|
808
|
-
const result = e1.toExample(mime) as string
|
|
809
|
-
|
|
810
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
811
|
-
const data = JSON.parse(result)
|
|
812
|
-
assert.typeOf(data.a1, 'array', 'has the association property as an array')
|
|
813
|
-
const [prop] = data.a1
|
|
814
|
-
assert.typeOf(prop, 'object', 'has the item in the array')
|
|
815
|
-
assert.typeOf(prop.s1, 'string', 'has the association properties')
|
|
816
|
-
})
|
|
817
|
-
|
|
818
|
-
test('returns the schema for anyOf union', ({ assert }) => {
|
|
819
|
-
const e3 = d1.addEntity('e3')
|
|
820
|
-
|
|
821
|
-
e2.addTypedProperty('string', 's1')
|
|
822
|
-
e3.addTypedProperty('number', 'i1')
|
|
823
|
-
|
|
824
|
-
const a1 = e1.addTargetAssociation(e2.key, 'a1')
|
|
825
|
-
a1.addTarget(e3.key)
|
|
826
|
-
a1.schema = { unionType: 'anyOf' }
|
|
827
|
-
|
|
828
|
-
const result = e1.toExample(mime) as string
|
|
829
|
-
|
|
830
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
831
|
-
const data = JSON.parse(result)
|
|
832
|
-
assert.typeOf(data.a1, 'object', 'has the association property')
|
|
833
|
-
assert.typeOf(data.a1.s1, 'string', 'has the association properties')
|
|
834
|
-
assert.isUndefined(data.a1.i1, 'has no other association target')
|
|
835
|
-
})
|
|
836
|
-
|
|
837
|
-
test('returns the schema for allOf union', ({ assert }) => {
|
|
838
|
-
const e3 = d1.addEntity('e3')
|
|
839
|
-
e3.addTypedProperty('number', 'i1')
|
|
840
|
-
e2.addTypedProperty('string', 's1')
|
|
841
|
-
const a1 = e1.addTargetAssociation(e2.key, 'a1')
|
|
842
|
-
a1.addTarget(e3.key)
|
|
843
|
-
a1.schema = { unionType: 'allOf' }
|
|
844
|
-
|
|
845
|
-
const result = e1.toExample(mime) as string
|
|
846
|
-
|
|
847
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
848
|
-
const data = JSON.parse(result)
|
|
849
|
-
assert.typeOf(data.a1, 'object', 'has the association property')
|
|
850
|
-
assert.typeOf(data.a1.s1, 'string', 'has the association properties')
|
|
851
|
-
assert.typeOf(data.a1.i1, 'number', 'has all association targets')
|
|
852
|
-
})
|
|
853
|
-
|
|
854
|
-
test('returns the schema for oneOf union', ({ assert }) => {
|
|
855
|
-
const e3 = d1.addEntity('e3')
|
|
856
|
-
|
|
857
|
-
e2.addTypedProperty('string', 's1')
|
|
858
|
-
e3.addTypedProperty('number', 'i1')
|
|
859
|
-
|
|
860
|
-
const a1 = e1.addTargetAssociation(e2.key, 'a1')
|
|
861
|
-
a1.addTarget(e3.key)
|
|
862
|
-
|
|
863
|
-
a1.schema = { unionType: 'oneOf' }
|
|
864
|
-
|
|
865
|
-
const result = e1.toExample(mime) as string
|
|
866
|
-
|
|
867
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
868
|
-
const data = JSON.parse(result)
|
|
869
|
-
assert.typeOf(data.a1, 'object', 'has the association property')
|
|
870
|
-
assert.typeOf(data.a1.s1, 'string', 'has the association properties')
|
|
871
|
-
assert.isUndefined(data.a1.i1, 'has no other association target')
|
|
872
|
-
})
|
|
873
|
-
|
|
874
|
-
test('returns the schema for oneOf union with selected shape', ({ assert }) => {
|
|
875
|
-
const e3 = d1.addEntity('e3')
|
|
876
|
-
|
|
877
|
-
e2.addTypedProperty('string', 's1')
|
|
878
|
-
e3.addTypedProperty('number', 'i1')
|
|
879
|
-
|
|
880
|
-
const a1 = e1.addTargetAssociation(e2.key, 'a1')
|
|
881
|
-
a1.addTarget(e3.key)
|
|
882
|
-
a1.schema = { unionType: 'oneOf' }
|
|
883
|
-
|
|
884
|
-
const result = e1.toExample(mime) as string
|
|
885
|
-
|
|
886
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
887
|
-
const data = JSON.parse(result)
|
|
888
|
-
assert.typeOf(data.a1, 'object', 'has the association property')
|
|
889
|
-
assert.typeOf(data.a1.s1, 'string', 'has the association properties')
|
|
890
|
-
assert.isUndefined(data.a1.i1, 'has no other association target')
|
|
891
|
-
})
|
|
892
|
-
|
|
893
|
-
test('creates a property from a foreign association', ({ assert }) => {
|
|
894
|
-
const n2 = new DataNamespace()
|
|
895
|
-
n1.foreign = [n2]
|
|
896
|
-
const d2 = n2.addDataModel('d2')
|
|
897
|
-
const e3 = d2.addEntity('e2')
|
|
898
|
-
e3.addTypedProperty('number', 'n1')
|
|
899
|
-
e1.addForeignAssociation(e3.key, n2.key, 'a3')
|
|
900
|
-
const result = e1.toExample(mime) as string
|
|
901
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
902
|
-
const data = JSON.parse(result)
|
|
903
|
-
assert.typeOf(data.a3, 'object', 'has the association property')
|
|
904
|
-
assert.typeOf(data.a3.n1, 'number', 'has the association properties')
|
|
905
|
-
})
|
|
906
|
-
})
|
|
907
|
-
|
|
908
|
-
test.group('JSON DataEntity Generator: parents', (group) => {
|
|
909
|
-
let d1: DataModel
|
|
910
|
-
let e1: DataEntity
|
|
911
|
-
let e2: DataEntity
|
|
912
|
-
|
|
913
|
-
group.each.setup(() => {
|
|
914
|
-
const ns = new DataNamespace()
|
|
915
|
-
d1 = ns.addDataModel('d1')
|
|
916
|
-
e1 = d1.addEntity('e1')
|
|
917
|
-
e2 = d1.addEntity('e2')
|
|
918
|
-
})
|
|
919
|
-
|
|
920
|
-
test('inherits parent properties', ({ assert }) => {
|
|
921
|
-
e1.addTypedProperty('number', 'p1')
|
|
922
|
-
e2.parents.push(e1.key)
|
|
923
|
-
const result = e2.toExample(mime) as string
|
|
924
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
925
|
-
const data = JSON.parse(result)
|
|
926
|
-
assert.typeOf(data.p1, 'number', 'has the parent property')
|
|
927
|
-
})
|
|
928
|
-
|
|
929
|
-
test('inherits parent properties and combines with own', ({ assert }) => {
|
|
930
|
-
e1.addTypedProperty('number', 'p1')
|
|
931
|
-
e2.addTypedProperty('string', 'p2')
|
|
932
|
-
e2.parents.push(e1.key)
|
|
933
|
-
|
|
934
|
-
const result = e2.toExample(mime) as string
|
|
935
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
936
|
-
const data = JSON.parse(result)
|
|
937
|
-
assert.typeOf(data.p1, 'number', 'has the parent property')
|
|
938
|
-
assert.typeOf(data.p2, 'string', 'has own property')
|
|
939
|
-
})
|
|
940
|
-
|
|
941
|
-
test('inherits parent properties and combines with own association', ({ assert }) => {
|
|
942
|
-
e1.addTypedProperty('number', 'p1')
|
|
943
|
-
e2.addTypedProperty('string', 'p2')
|
|
944
|
-
e2.parents.push(e1.key)
|
|
945
|
-
const e3 = d1.addEntity('e3')
|
|
946
|
-
e3.addTypedProperty('string', 'p3')
|
|
947
|
-
e2.addTargetAssociation(e3.key, 'a1')
|
|
948
|
-
|
|
949
|
-
const result = e2.toExample(mime) as string
|
|
950
|
-
|
|
951
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
952
|
-
const data = JSON.parse(result)
|
|
953
|
-
assert.typeOf(data.p1, 'number', 'has the parent property')
|
|
954
|
-
assert.typeOf(data.p2, 'string', 'has own property')
|
|
955
|
-
assert.typeOf(data.a1, 'object', 'has own association')
|
|
956
|
-
assert.typeOf(data.a1.p3, 'string', 'has association property')
|
|
957
|
-
})
|
|
958
|
-
|
|
959
|
-
test('inherits parent properties with parent association', ({ assert }) => {
|
|
960
|
-
e1.addTypedProperty('number', 'p1')
|
|
961
|
-
e2.addTypedProperty('string', 'p2')
|
|
962
|
-
e2.parents.push(e1.key)
|
|
963
|
-
const e3 = d1.addEntity('e3')
|
|
964
|
-
e3.addTypedProperty('string', 'p3')
|
|
965
|
-
e1.addTargetAssociation(e3.key, 'a1')
|
|
966
|
-
|
|
967
|
-
const result = e2.toExample(mime) as string
|
|
968
|
-
|
|
969
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
970
|
-
const data = JSON.parse(result)
|
|
971
|
-
assert.typeOf(data.p1, 'number', 'has the parent property')
|
|
972
|
-
assert.typeOf(data.p2, 'string', 'has own property')
|
|
973
|
-
assert.typeOf(data.a1, 'object', 'has own association')
|
|
974
|
-
assert.typeOf(data.a1.p3, 'string', 'has association property')
|
|
975
|
-
})
|
|
976
|
-
|
|
977
|
-
test('shadows properties', ({ assert }) => {
|
|
978
|
-
e1.addTypedProperty('number', 'p1')
|
|
979
|
-
e2.addTypedProperty('string', 'p1')
|
|
980
|
-
e2.parents.push(e1.key)
|
|
981
|
-
const result = e2.toExample(mime) as string
|
|
982
|
-
|
|
983
|
-
assert.typeOf(result, 'string', 'result is a string')
|
|
984
|
-
const data = JSON.parse(result)
|
|
985
|
-
assert.typeOf(data.p1, 'string', 'overwrites parent property')
|
|
986
|
-
})
|
|
987
|
-
})
|