@api-client/core 0.19.29 → 0.19.31
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/modeling/DomainAssociation.d.ts +4 -4
- package/build/src/modeling/DomainAssociation.d.ts.map +1 -1
- package/build/src/modeling/DomainAssociation.js.map +1 -1
- package/build/src/modeling/ai/domain_response_schema.d.ts +4 -2
- package/build/src/modeling/ai/domain_response_schema.d.ts.map +1 -1
- package/build/src/modeling/ai/domain_response_schema.js +1 -1
- package/build/src/modeling/ai/domain_response_schema.js.map +1 -1
- package/build/src/modeling/ai/types.d.ts +2 -3
- package/build/src/modeling/ai/types.d.ts.map +1 -1
- package/build/src/modeling/ai/types.js.map +1 -1
- package/build/src/modeling/amf/ShapeGenerator.js +1 -1
- package/build/src/modeling/amf/ShapeGenerator.js.map +1 -1
- package/build/src/modeling/generators/oas_312/OasGenerator.js +1 -1
- package/build/src/modeling/generators/oas_312/OasGenerator.js.map +1 -1
- package/build/src/modeling/generators/oas_312/OasSchemaGenerator.js +3 -3
- package/build/src/modeling/generators/oas_312/OasSchemaGenerator.js.map +1 -1
- package/build/src/modeling/generators/oas_320/OasSchemaGenerator.js +3 -3
- package/build/src/modeling/generators/oas_320/OasSchemaGenerator.js.map +1 -1
- package/build/src/modeling/types.d.ts +55 -0
- package/build/src/modeling/types.d.ts.map +1 -1
- package/build/src/modeling/types.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/skills-lock.json +10 -0
- package/src/modeling/DomainAssociation.ts +4 -4
- package/src/modeling/ai/domain_response_schema.ts +1 -1
- package/src/modeling/ai/types.ts +2 -3
- package/src/modeling/amf/ShapeGenerator.ts +1 -1
- package/src/modeling/generators/oas_312/OasGenerator.ts +1 -1
- package/src/modeling/generators/oas_312/OasSchemaGenerator.ts +3 -3
- package/src/modeling/generators/oas_320/OasSchemaGenerator.ts +3 -3
- package/src/modeling/types.ts +56 -0
- package/tests/unit/modeling/amf/shape_generator.spec.ts +32 -14
- package/tests/unit/modeling/data_domain_change_observers.spec.ts +1 -1
- package/tests/unit/modeling/domain_asociation.spec.ts +18 -18
- package/tests/unit/modeling/domain_entity_example_generator_json.spec.ts +68 -23
- package/tests/unit/modeling/domain_entity_example_generator_xml.spec.ts +32 -9
- package/tests/unit/modeling/generators/OasGenerator.spec.ts +2 -2
package/package.json
CHANGED
package/skills-lock.json
ADDED
|
@@ -8,7 +8,7 @@ import type { DomainEntity } from './DomainEntity.js'
|
|
|
8
8
|
import type { Shapes } from '@api-client/amf-core'
|
|
9
9
|
import type { AssociationBinding, AssociationBindings, AssociationWebBindings } from './Bindings.js'
|
|
10
10
|
import { DomainAttributeAttribute, DomainAttributeAttributes } from './DataFormat.js'
|
|
11
|
-
import type { AssociationTarget, DomainGraphEdge } from './types.js'
|
|
11
|
+
import type { AssociationSchema, AssociationTarget, DomainGraphEdge } from './types.js'
|
|
12
12
|
import { ShapeGenerator } from './amf/ShapeGenerator.js'
|
|
13
13
|
import { DataSemantics, isAssociationSemantic, type SemanticType, type AppliedDataSemantic } from './Semantics.js'
|
|
14
14
|
|
|
@@ -53,7 +53,7 @@ export interface DomainAssociationSchema extends DomainElementSchema {
|
|
|
53
53
|
* referenced entities schemas. Note, changes in the referenced entities may not be propagated
|
|
54
54
|
* to schemas altered by the user.
|
|
55
55
|
*/
|
|
56
|
-
schema?:
|
|
56
|
+
schema?: AssociationSchema
|
|
57
57
|
/**
|
|
58
58
|
* The list of bindings for this property.
|
|
59
59
|
*
|
|
@@ -153,7 +153,7 @@ export class DomainAssociation extends DomainElement {
|
|
|
153
153
|
* The schema allowing to translate the model into a
|
|
154
154
|
* specific format (like JSON, RAML, XML, etc.)
|
|
155
155
|
*/
|
|
156
|
-
@observed({ deep: true }) accessor schema:
|
|
156
|
+
@observed({ deep: true }) accessor schema: AssociationSchema | undefined
|
|
157
157
|
|
|
158
158
|
/**
|
|
159
159
|
* The list of bindings for this property.
|
|
@@ -351,7 +351,7 @@ export class DomainAssociation extends DomainElement {
|
|
|
351
351
|
* const schema = association.ensureSchema();
|
|
352
352
|
* ```
|
|
353
353
|
*/
|
|
354
|
-
ensureSchema():
|
|
354
|
+
ensureSchema(): AssociationSchema {
|
|
355
355
|
if (!this.schema) {
|
|
356
356
|
this.schema = {}
|
|
357
357
|
}
|
|
@@ -94,7 +94,7 @@ const PropertySchema = {
|
|
|
94
94
|
const AssociationSchemaShape = {
|
|
95
95
|
type: Type.OBJECT,
|
|
96
96
|
properties: {
|
|
97
|
-
|
|
97
|
+
embedded: { type: Type.BOOLEAN, description: 'Whether the association should be embedded in the target entity' },
|
|
98
98
|
unionType: { type: Type.STRING, description: 'Enum: allOf, anyOf, oneOf, not' },
|
|
99
99
|
},
|
|
100
100
|
}
|
package/src/modeling/ai/types.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type { Shapes } from '@api-client/amf-core'
|
|
2
1
|
import type { Exception } from '../../exceptions/exception.js'
|
|
3
2
|
import type { AiSessionSchema } from '../../models/AiSession.js'
|
|
4
3
|
import type { DomainPropertyType } from '../DataFormat.js'
|
|
5
4
|
import type { OnDeleteRule } from '../index.js'
|
|
6
5
|
import { SemanticType } from '../Semantics.js'
|
|
7
|
-
import type { AssociationTarget, PropertySchema } from '../types.js'
|
|
6
|
+
import type { AssociationSchema, AssociationTarget, PropertySchema } from '../types.js'
|
|
8
7
|
import type { AiModelMessageSchema, AiModelMessage, AiUserMessageSchema } from '../../models/AiMessage.js'
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -150,7 +149,7 @@ export interface AiDomainAssociation {
|
|
|
150
149
|
multiple?: boolean
|
|
151
150
|
onDelete?: OnDeleteRule
|
|
152
151
|
semantics?: AiDomainSemantic[]
|
|
153
|
-
schema?:
|
|
152
|
+
schema?: AssociationSchema
|
|
154
153
|
}
|
|
155
154
|
|
|
156
155
|
/**
|
|
@@ -199,7 +199,7 @@ export class ShapeGenerator {
|
|
|
199
199
|
*/
|
|
200
200
|
associationShape(input: DomainAssociation, visited: Set<string> = new Set<string>()): Shapes.IShapeUnion | undefined {
|
|
201
201
|
const schema = input.schema
|
|
202
|
-
if (schema
|
|
202
|
+
if (!schema?.embedded) {
|
|
203
203
|
return this.createLinkedShape(input)
|
|
204
204
|
}
|
|
205
205
|
const items = this.associationUnion(input, visited)
|
|
@@ -439,7 +439,7 @@ export class OasGenerator {
|
|
|
439
439
|
}
|
|
440
440
|
const links: Record<string, LinkObject> = {}
|
|
441
441
|
for (const assoc of domainEntity.associations) {
|
|
442
|
-
if (assoc.schema?.
|
|
442
|
+
if (assoc.schema?.embedded === true) {
|
|
443
443
|
continue
|
|
444
444
|
}
|
|
445
445
|
const targets = Array.from(assoc.listTargets())
|
|
@@ -105,12 +105,12 @@ export class OasSchemaGenerator {
|
|
|
105
105
|
const targets = Array.from(assoc.listTargets())
|
|
106
106
|
if (targets.length === 0) continue
|
|
107
107
|
|
|
108
|
-
const linked = assoc.schema?.
|
|
108
|
+
const linked = !assoc.schema?.embedded
|
|
109
109
|
const targetRefs: (SchemaObject | ReferenceObject)[] = []
|
|
110
110
|
|
|
111
111
|
for (const targetEntity of targets) {
|
|
112
112
|
if (linked) {
|
|
113
|
-
// When an entity is
|
|
113
|
+
// When an entity is not embedded then we treat it as a regular property, which value is a key to
|
|
114
114
|
// the target entity. The consuming application has to construct the endpoint manually.
|
|
115
115
|
const targetName = targetEntity.info.displayName || targetEntity.info.name || targetEntity.key
|
|
116
116
|
targetRefs.push({
|
|
@@ -118,7 +118,7 @@ export class OasSchemaGenerator {
|
|
|
118
118
|
description: `The ID of the linked ${targetName}.`,
|
|
119
119
|
})
|
|
120
120
|
} else {
|
|
121
|
-
// If
|
|
121
|
+
// If "embedded", add the resource as a reference to the schema.
|
|
122
122
|
if (targetEntity !== entity) {
|
|
123
123
|
this.generateEntity(targetEntity)
|
|
124
124
|
}
|
|
@@ -78,12 +78,12 @@ export class OasSchemaGenerator {
|
|
|
78
78
|
const targets = Array.from(assoc.listTargets())
|
|
79
79
|
if (targets.length === 0) continue
|
|
80
80
|
|
|
81
|
-
const linked = assoc.schema?.
|
|
81
|
+
const linked = !assoc.schema?.embedded
|
|
82
82
|
const targetRefs: (SchemaObject | ReferenceObject)[] = []
|
|
83
83
|
|
|
84
84
|
for (const targetEntity of targets) {
|
|
85
85
|
if (linked) {
|
|
86
|
-
// When an entity is
|
|
86
|
+
// When an entity is not embedded then we treat it as a regular property, which value is a key to
|
|
87
87
|
// the target entity. The consuming application has to construct the endpoint manually.
|
|
88
88
|
const targetName = targetEntity.info.displayName || targetEntity.info.name || targetEntity.key
|
|
89
89
|
targetRefs.push({
|
|
@@ -91,7 +91,7 @@ export class OasSchemaGenerator {
|
|
|
91
91
|
description: `The ID of the linked ${targetName}.`,
|
|
92
92
|
})
|
|
93
93
|
} else {
|
|
94
|
-
// If
|
|
94
|
+
// If "embedded", add the resource as a reference to the schema.
|
|
95
95
|
if (targetEntity !== entity) {
|
|
96
96
|
this.generateEntity(targetEntity)
|
|
97
97
|
}
|
package/src/modeling/types.ts
CHANGED
|
@@ -897,3 +897,59 @@ export interface ApiModelValidationResult {
|
|
|
897
897
|
*/
|
|
898
898
|
issues: ApiModelValidationItem[]
|
|
899
899
|
}
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* Schema definition for an association.
|
|
903
|
+
*
|
|
904
|
+
* This is used to define how an association is represented in the schema.
|
|
905
|
+
*/
|
|
906
|
+
export interface AssociationSchema {
|
|
907
|
+
/**
|
|
908
|
+
* Whether the target entity should be embedded under the property name.
|
|
909
|
+
* When false, this association is just an information that one entity depend on another.
|
|
910
|
+
* When true, it changes the definition of the schema having this association to
|
|
911
|
+
* add the target schema properties inline with this property.
|
|
912
|
+
*
|
|
913
|
+
* **When true**
|
|
914
|
+
*
|
|
915
|
+
* ```javascript
|
|
916
|
+
* // generated schema for `address` association
|
|
917
|
+
* {
|
|
918
|
+
* "name": "example value",
|
|
919
|
+
* "address": {
|
|
920
|
+
* "city": "example value",
|
|
921
|
+
* ...
|
|
922
|
+
* }
|
|
923
|
+
* }
|
|
924
|
+
* ```
|
|
925
|
+
*
|
|
926
|
+
* **When false**
|
|
927
|
+
*
|
|
928
|
+
* ```javascript
|
|
929
|
+
* // generated schema for `address` association
|
|
930
|
+
* {
|
|
931
|
+
* "name": "example value",
|
|
932
|
+
* "address": "the key of the referenced schema"
|
|
933
|
+
* }
|
|
934
|
+
* ```
|
|
935
|
+
*/
|
|
936
|
+
embedded?: boolean
|
|
937
|
+
/**
|
|
938
|
+
* When the association has multiple targets the union type should be
|
|
939
|
+
* set to describe which union this is.
|
|
940
|
+
*
|
|
941
|
+
* Possible values are:
|
|
942
|
+
*
|
|
943
|
+
* - allOf - To validate against `allOf`, the given data must be valid against
|
|
944
|
+
* all of the given sub-schemas. When generating, it's a sum of all properties.
|
|
945
|
+
* - anyOf - To validate against `anyOf`, the given data must be valid against
|
|
946
|
+
* any (one or more) of the given sub-schemas. When generation a schema, it takes first union schema.
|
|
947
|
+
* - oneOf - To validate against `oneOf`, the given data must be valid against
|
|
948
|
+
* exactly one of the given sub-schemas. It behaves the same as `anyOf` when generating a schema
|
|
949
|
+
* - not - The `not` keyword declares that an instance validates if it doesn’t
|
|
950
|
+
* validate against the given sub-schema. It has no use when generating a schema.
|
|
951
|
+
*
|
|
952
|
+
* @default anyOf
|
|
953
|
+
*/
|
|
954
|
+
unionType?: 'allOf' | 'anyOf' | 'oneOf' | 'not'
|
|
955
|
+
}
|
|
@@ -762,6 +762,9 @@ test.group('associationProperty()', (group) => {
|
|
|
762
762
|
})
|
|
763
763
|
|
|
764
764
|
test('returns basic shape definition', ({ assert }) => {
|
|
765
|
+
a1.schema = {
|
|
766
|
+
embedded: true,
|
|
767
|
+
}
|
|
765
768
|
const result = a1.toApiShape()
|
|
766
769
|
assert.typeOf(result, 'object')
|
|
767
770
|
|
|
@@ -812,8 +815,8 @@ test.group('associationProperty()', (group) => {
|
|
|
812
815
|
assert.equal(result.path, AmfNamespace.aml.vocabularies.data.key + 'a1', 'has the path')
|
|
813
816
|
})
|
|
814
817
|
|
|
815
|
-
test('returns a
|
|
816
|
-
a1.schema = {
|
|
818
|
+
test('returns a reference definition when not embedded', ({ assert }) => {
|
|
819
|
+
a1.schema = { embedded: false }
|
|
817
820
|
const result = a1.toApiShape()
|
|
818
821
|
const range = result.range as Shapes.IApiScalarShape
|
|
819
822
|
assert.equal(range.id, `link-${a1.key}`)
|
|
@@ -824,6 +827,9 @@ test.group('associationProperty()', (group) => {
|
|
|
824
827
|
test('returns a default union type', ({ assert }) => {
|
|
825
828
|
const e3 = m1.addEntity({ key: 'e3', info: { name: 'e3' } })
|
|
826
829
|
a1.addTarget(e3)
|
|
830
|
+
a1.schema = {
|
|
831
|
+
embedded: true,
|
|
832
|
+
}
|
|
827
833
|
const result = a1.toApiShape()
|
|
828
834
|
const range = result.range as Shapes.IApiUnionShape
|
|
829
835
|
|
|
@@ -841,12 +847,18 @@ test.group('associationProperty()', (group) => {
|
|
|
841
847
|
|
|
842
848
|
test('has no range when no associations', ({ assert }) => {
|
|
843
849
|
a1.removeTarget(e2)
|
|
850
|
+
a1.schema = {
|
|
851
|
+
embedded: true,
|
|
852
|
+
}
|
|
844
853
|
const result = a1.toApiShape()
|
|
845
854
|
assert.isUndefined(result.range)
|
|
846
855
|
})
|
|
847
856
|
|
|
848
857
|
test('returns an array shape when multiple', ({ assert }) => {
|
|
849
858
|
a1.multiple = true
|
|
859
|
+
a1.schema = {
|
|
860
|
+
embedded: true,
|
|
861
|
+
}
|
|
850
862
|
const result = a1.toApiShape()
|
|
851
863
|
const range = result.range as Shapes.IApiArrayShape
|
|
852
864
|
assert.deepEqual(range.types, AmfTypes.IAmfArrayTypes)
|
|
@@ -859,7 +871,7 @@ test.group('associationProperty()', (group) => {
|
|
|
859
871
|
})
|
|
860
872
|
|
|
861
873
|
test('creates the "anyOf" union', ({ assert }) => {
|
|
862
|
-
a1.schema = { unionType: 'anyOf' }
|
|
874
|
+
a1.schema = { unionType: 'anyOf', embedded: true }
|
|
863
875
|
|
|
864
876
|
const e3 = m1.addEntity({ key: 'e3', info: { name: 'e3' } })
|
|
865
877
|
a1.addTarget(e3)
|
|
@@ -879,7 +891,7 @@ test.group('associationProperty()', (group) => {
|
|
|
879
891
|
})
|
|
880
892
|
|
|
881
893
|
test('creates the "allOf" union', ({ assert }) => {
|
|
882
|
-
a1.schema = { unionType: 'allOf' }
|
|
894
|
+
a1.schema = { unionType: 'allOf', embedded: true }
|
|
883
895
|
|
|
884
896
|
const e3 = m1.addEntity({ key: 'e3', info: { name: 'e3' } })
|
|
885
897
|
a1.addTarget(e3)
|
|
@@ -899,7 +911,7 @@ test.group('associationProperty()', (group) => {
|
|
|
899
911
|
})
|
|
900
912
|
|
|
901
913
|
test('creates the "oneOf" union', ({ assert }) => {
|
|
902
|
-
a1.schema = { unionType: 'oneOf' }
|
|
914
|
+
a1.schema = { unionType: 'oneOf', embedded: true }
|
|
903
915
|
|
|
904
916
|
const e3 = m1.addEntity({ key: 'e3', info: { name: 'e3' } })
|
|
905
917
|
a1.addTarget(e3)
|
|
@@ -919,7 +931,7 @@ test.group('associationProperty()', (group) => {
|
|
|
919
931
|
})
|
|
920
932
|
|
|
921
933
|
test('creates the "not" union', ({ assert }) => {
|
|
922
|
-
a1.schema = { unionType: 'not' }
|
|
934
|
+
a1.schema = { unionType: 'not', embedded: true }
|
|
923
935
|
|
|
924
936
|
const e3 = m1.addEntity({ key: 'e3', info: { name: 'e3' } })
|
|
925
937
|
a1.addTarget(e3)
|
|
@@ -938,7 +950,7 @@ test.group('associationProperty()', (group) => {
|
|
|
938
950
|
})
|
|
939
951
|
|
|
940
952
|
test('creates the "not" shape', ({ assert }) => {
|
|
941
|
-
a1.schema = { unionType: 'not' }
|
|
953
|
+
a1.schema = { unionType: 'not', embedded: true }
|
|
942
954
|
|
|
943
955
|
const result = a1.toApiShape()
|
|
944
956
|
const range = result.range as Shapes.IApiUnionShape
|
|
@@ -956,7 +968,7 @@ test.group('associationProperty()', (group) => {
|
|
|
956
968
|
|
|
957
969
|
test('wraps the union in the array shape', ({ assert }) => {
|
|
958
970
|
a1.multiple = true
|
|
959
|
-
a1.schema = { unionType: 'anyOf' }
|
|
971
|
+
a1.schema = { unionType: 'anyOf', embedded: true }
|
|
960
972
|
|
|
961
973
|
const e3 = m1.addEntity({ key: 'e3', info: { name: 'e3' } })
|
|
962
974
|
a1.addTarget(e3)
|
|
@@ -978,8 +990,8 @@ test.group('associationProperty()', (group) => {
|
|
|
978
990
|
assert.lengthOf(p2.properties, 0, 'p2 has the properties')
|
|
979
991
|
})
|
|
980
992
|
|
|
981
|
-
test('handles
|
|
982
|
-
a1.schema = {
|
|
993
|
+
test('handles not embedded schema', ({ assert }) => {
|
|
994
|
+
a1.schema = { embedded: false }
|
|
983
995
|
const result = a1.toApiShape()
|
|
984
996
|
const range = result.range as Shapes.IApiScalarShape
|
|
985
997
|
assert.equal(range.dataType, AmfNamespace.w3.xmlSchema.string)
|
|
@@ -988,13 +1000,16 @@ test.group('associationProperty()', (group) => {
|
|
|
988
1000
|
test('handles multiple associations', ({ assert }) => {
|
|
989
1001
|
const e3 = m1.addEntity({ key: 'e3', info: { name: 'e3' } })
|
|
990
1002
|
a1.addTarget(e3)
|
|
1003
|
+
a1.schema = {
|
|
1004
|
+
embedded: true,
|
|
1005
|
+
}
|
|
991
1006
|
const result = a1.toApiShape()
|
|
992
1007
|
const range = result.range as Shapes.IApiUnionShape
|
|
993
1008
|
assert.lengthOf(range.anyOf, 2)
|
|
994
1009
|
})
|
|
995
1010
|
|
|
996
1011
|
test('handles unionType', ({ assert }) => {
|
|
997
|
-
a1.schema = { unionType: 'allOf' }
|
|
1012
|
+
a1.schema = { unionType: 'allOf', embedded: true }
|
|
998
1013
|
const e3 = m1.addEntity({ key: 'e3', info: { name: 'e3' } })
|
|
999
1014
|
a1.addTarget(e3)
|
|
1000
1015
|
const result = a1.toApiShape()
|
|
@@ -1004,7 +1019,7 @@ test.group('associationProperty()', (group) => {
|
|
|
1004
1019
|
|
|
1005
1020
|
test('handles multiple and unionType', ({ assert }) => {
|
|
1006
1021
|
a1.multiple = true
|
|
1007
|
-
a1.schema = { unionType: 'allOf' }
|
|
1022
|
+
a1.schema = { unionType: 'allOf', embedded: true }
|
|
1008
1023
|
const e3 = m1.addEntity({ key: 'e3', info: { name: 'e3' } })
|
|
1009
1024
|
a1.addTarget(e3)
|
|
1010
1025
|
const result = a1.toApiShape()
|
|
@@ -1119,9 +1134,9 @@ test.group('AI Generated tests', (group) => {
|
|
|
1119
1134
|
assert.equal(items.format, AmfNamespace.w3.xmlSchema.integer)
|
|
1120
1135
|
})
|
|
1121
1136
|
|
|
1122
|
-
test('handles multiple associations
|
|
1137
|
+
test('handles multiple associations not embedded', ({ assert }) => {
|
|
1123
1138
|
a1.multiple = true
|
|
1124
|
-
a1.schema = {
|
|
1139
|
+
a1.schema = { embedded: true }
|
|
1125
1140
|
const result = a1.toApiShape()
|
|
1126
1141
|
const range = result.range as Shapes.IApiArrayShape
|
|
1127
1142
|
assert.include(range.types, AmfNamespace.aml.vocabularies.shapes.ArrayShape)
|
|
@@ -1139,6 +1154,9 @@ test.group('AI Generated tests', (group) => {
|
|
|
1139
1154
|
},
|
|
1140
1155
|
},
|
|
1141
1156
|
]
|
|
1157
|
+
a1.schema = {
|
|
1158
|
+
embedded: true,
|
|
1159
|
+
}
|
|
1142
1160
|
const result = a1.toApiShape()
|
|
1143
1161
|
const range = result.range as Shapes.IApiArrayShape
|
|
1144
1162
|
assert.include(range.types, AmfNamespace.aml.vocabularies.shapes.ArrayShape)
|
|
@@ -664,7 +664,7 @@ test.group('DomainAssociation change observers', (g) => {
|
|
|
664
664
|
const e1 = m1.addEntity()
|
|
665
665
|
const a1 = e1.addAssociation()
|
|
666
666
|
await sleep(1)
|
|
667
|
-
a1.schema = {
|
|
667
|
+
a1.schema = { embedded: false }
|
|
668
668
|
await assert.dispatchCount(domain, 'change', 1, { timeout: 1 })
|
|
669
669
|
})
|
|
670
670
|
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
DataFormat,
|
|
9
9
|
SemanticType,
|
|
10
10
|
type OnDeleteRule,
|
|
11
|
+
type AssociationSchema,
|
|
11
12
|
} from '../../../src/index.js'
|
|
12
|
-
import { Shapes } from '@api-client/amf-core'
|
|
13
13
|
|
|
14
14
|
test.group('DomainAssociation.createSchema()', () => {
|
|
15
15
|
test('creates a valid schema with default values', ({ assert }) => {
|
|
@@ -58,7 +58,7 @@ test.group('DomainAssociation.createSchema()', () => {
|
|
|
58
58
|
})
|
|
59
59
|
|
|
60
60
|
test('creates a schema with provided schema', ({ assert }) => {
|
|
61
|
-
const schemaDefinition:
|
|
61
|
+
const schemaDefinition: AssociationSchema = { embedded: false }
|
|
62
62
|
const schema = DomainAssociation.createSchema({ schema: schemaDefinition })
|
|
63
63
|
assert.deepEqual(schema.schema, schemaDefinition)
|
|
64
64
|
})
|
|
@@ -88,7 +88,7 @@ test.group('DomainAssociation.createSchema()', () => {
|
|
|
88
88
|
test('creates a schema with all properties', ({ assert }) => {
|
|
89
89
|
const key = 'test-key'
|
|
90
90
|
const info = { name: 'Test Association', description: 'Test description' }
|
|
91
|
-
const schemaDefinition:
|
|
91
|
+
const schemaDefinition: AssociationSchema = { embedded: false }
|
|
92
92
|
const multiple = true
|
|
93
93
|
const required = true
|
|
94
94
|
const bindings: AssociationBinding[] = [{ type: 'web', schema: { hidden: false } }]
|
|
@@ -144,7 +144,7 @@ test.group('DomainAssociation.createSchema()', () => {
|
|
|
144
144
|
})
|
|
145
145
|
|
|
146
146
|
test('creates a schema with cloned schema', ({ assert }) => {
|
|
147
|
-
const schemaDefinition:
|
|
147
|
+
const schemaDefinition: AssociationSchema = { embedded: false }
|
|
148
148
|
const schema = DomainAssociation.createSchema({ schema: schemaDefinition })
|
|
149
149
|
assert.deepEqual(schema.schema, schemaDefinition)
|
|
150
150
|
assert.notStrictEqual(schema.schema, schemaDefinition)
|
|
@@ -212,7 +212,7 @@ test.group('DomainAssociation.constructor()', () => {
|
|
|
212
212
|
test('creates an instance with provided schema', ({ assert }) => {
|
|
213
213
|
const dataDomain = new DataDomain()
|
|
214
214
|
const parentKey = 'test-parent'
|
|
215
|
-
const schemaDefinition:
|
|
215
|
+
const schemaDefinition: AssociationSchema = { embedded: false }
|
|
216
216
|
const association = new DomainAssociation(dataDomain, parentKey, { schema: schemaDefinition })
|
|
217
217
|
assert.deepEqual(association.schema, schemaDefinition)
|
|
218
218
|
})
|
|
@@ -252,7 +252,7 @@ test.group('DomainAssociation.constructor()', () => {
|
|
|
252
252
|
const parentKey = 'test-parent'
|
|
253
253
|
const key = 'test-key'
|
|
254
254
|
const info = { name: 'Test Association', description: 'Test description' }
|
|
255
|
-
const schemaDefinition:
|
|
255
|
+
const schemaDefinition: AssociationSchema = { embedded: false }
|
|
256
256
|
const multiple = true
|
|
257
257
|
const required = true
|
|
258
258
|
const bindings: AssociationBinding[] = [{ type: 'web', schema: { hidden: false } }]
|
|
@@ -316,7 +316,7 @@ test.group('DomainAssociation.constructor()', () => {
|
|
|
316
316
|
test('creates an instance with cloned schema', ({ assert }) => {
|
|
317
317
|
const dataDomain = new DataDomain()
|
|
318
318
|
const parentKey = 'test-parent'
|
|
319
|
-
const schemaDefinition:
|
|
319
|
+
const schemaDefinition: AssociationSchema = { embedded: false }
|
|
320
320
|
const association = new DomainAssociation(dataDomain, parentKey, { schema: schemaDefinition })
|
|
321
321
|
assert.deepEqual(association.schema, schemaDefinition)
|
|
322
322
|
assert.notStrictEqual(association.schema, schemaDefinition)
|
|
@@ -390,7 +390,7 @@ test.group('DomainAssociation.toJSON()', () => {
|
|
|
390
390
|
test('returns a JSON representation with provided schema', ({ assert }) => {
|
|
391
391
|
const dataDomain = new DataDomain()
|
|
392
392
|
const parentKey = 'test-parent'
|
|
393
|
-
const schemaDefinition:
|
|
393
|
+
const schemaDefinition: AssociationSchema = { embedded: false }
|
|
394
394
|
const association = new DomainAssociation(dataDomain, parentKey, { schema: schemaDefinition })
|
|
395
395
|
const json = association.toJSON()
|
|
396
396
|
assert.deepEqual(json.schema, schemaDefinition)
|
|
@@ -438,7 +438,7 @@ test.group('DomainAssociation.toJSON()', () => {
|
|
|
438
438
|
const parentKey = 'test-parent'
|
|
439
439
|
const key = 'test-key'
|
|
440
440
|
const info = { name: 'Test Association', description: 'Test description' }
|
|
441
|
-
const schemaDefinition:
|
|
441
|
+
const schemaDefinition: AssociationSchema = { embedded: false }
|
|
442
442
|
const multiple = true
|
|
443
443
|
const required = true
|
|
444
444
|
const bindings: AssociationBinding[] = [{ type: 'web', schema: { hidden: false } }]
|
|
@@ -527,7 +527,7 @@ test.group('DomainAssociation.toJSON()', () => {
|
|
|
527
527
|
test('returns a JSON representation with cloned schema', ({ assert }) => {
|
|
528
528
|
const dataDomain = new DataDomain()
|
|
529
529
|
const parentKey = 'test-parent'
|
|
530
|
-
const schemaDefinition:
|
|
530
|
+
const schemaDefinition: AssociationSchema = { embedded: false }
|
|
531
531
|
const association = new DomainAssociation(dataDomain, parentKey, { schema: schemaDefinition })
|
|
532
532
|
const json = association.toJSON()
|
|
533
533
|
assert.deepEqual(json.schema, schemaDefinition)
|
|
@@ -538,7 +538,7 @@ test.group('DomainAssociation.toJSON()', () => {
|
|
|
538
538
|
const dataDomain = new DataDomain()
|
|
539
539
|
const parentKey = 'test-parent'
|
|
540
540
|
const association = new DomainAssociation(dataDomain, parentKey)
|
|
541
|
-
const schemaDefinition:
|
|
541
|
+
const schemaDefinition: AssociationSchema = { embedded: false }
|
|
542
542
|
association.schema = schemaDefinition
|
|
543
543
|
const json = association.toJSON()
|
|
544
544
|
assert.deepEqual(json.schema, schemaDefinition)
|
|
@@ -672,7 +672,7 @@ test.group('DomainAssociation.ensureSchema()', () => {
|
|
|
672
672
|
|
|
673
673
|
test('returns the existing schema object if it exists', ({ assert }) => {
|
|
674
674
|
const dataDomain = new DataDomain()
|
|
675
|
-
const schemaDefinition:
|
|
675
|
+
const schemaDefinition: AssociationSchema = { embedded: false }
|
|
676
676
|
const association = new DomainAssociation(dataDomain, 'test-parent', { schema: schemaDefinition })
|
|
677
677
|
const originalSchema = association.schema
|
|
678
678
|
const schema = association.ensureSchema()
|
|
@@ -682,7 +682,7 @@ test.group('DomainAssociation.ensureSchema()', () => {
|
|
|
682
682
|
|
|
683
683
|
test('does not modify the existing schema object', ({ assert }) => {
|
|
684
684
|
const dataDomain = new DataDomain()
|
|
685
|
-
const schemaDefinition:
|
|
685
|
+
const schemaDefinition: AssociationSchema = { embedded: false }
|
|
686
686
|
const association = new DomainAssociation(dataDomain, 'test-parent', { schema: schemaDefinition })
|
|
687
687
|
const originalSchema = association.schema
|
|
688
688
|
association.ensureSchema()
|
|
@@ -1083,7 +1083,7 @@ test.group('DomainAssociation.duplicate()', () => {
|
|
|
1083
1083
|
association.readOnly = true
|
|
1084
1084
|
association.onDelete = 'cascade'
|
|
1085
1085
|
association.semantics = [{ id: SemanticType.ResourceOwnerIdentifier }]
|
|
1086
|
-
association.schema = {
|
|
1086
|
+
association.schema = { embedded: true, unionType: 'allOf' }
|
|
1087
1087
|
association.bindings = [{ type: 'web', schema: { hidden: true } }]
|
|
1088
1088
|
|
|
1089
1089
|
const duplicate = association.duplicate()
|
|
@@ -1095,7 +1095,7 @@ test.group('DomainAssociation.duplicate()', () => {
|
|
|
1095
1095
|
assert.equal(duplicate.readOnly, true)
|
|
1096
1096
|
assert.equal(duplicate.onDelete, 'cascade')
|
|
1097
1097
|
assert.deepEqual(duplicate.semantics, [{ id: SemanticType.ResourceOwnerIdentifier }])
|
|
1098
|
-
assert.deepEqual(duplicate.schema, {
|
|
1098
|
+
assert.deepEqual(duplicate.schema, { embedded: true, unionType: 'allOf' })
|
|
1099
1099
|
assert.deepEqual(duplicate.bindings, [{ type: 'web', schema: { hidden: true } }])
|
|
1100
1100
|
})
|
|
1101
1101
|
|
|
@@ -1107,17 +1107,17 @@ test.group('DomainAssociation.duplicate()', () => {
|
|
|
1107
1107
|
|
|
1108
1108
|
const association = entity.addAssociation({ targets: [{ key: targetEntity.key }] })
|
|
1109
1109
|
association.info.name = 'original'
|
|
1110
|
-
association.schema = {
|
|
1110
|
+
association.schema = { embedded: false, unionType: 'anyOf' }
|
|
1111
1111
|
association.bindings = [{ type: 'web', schema: { hidden: false } }]
|
|
1112
1112
|
|
|
1113
1113
|
const duplicate = association.duplicate()
|
|
1114
1114
|
|
|
1115
1115
|
// Modify original schema and bindings
|
|
1116
|
-
association.schema!.
|
|
1116
|
+
association.schema!.embedded = true
|
|
1117
1117
|
association.bindings[0].schema = { hidden: true }
|
|
1118
1118
|
|
|
1119
1119
|
// Duplicate should be unaffected
|
|
1120
|
-
assert.equal(duplicate.schema!.
|
|
1120
|
+
assert.equal(duplicate.schema!.embedded, false)
|
|
1121
1121
|
assert.deepEqual(duplicate.bindings[0].schema, { hidden: false })
|
|
1122
1122
|
})
|
|
1123
1123
|
|