Skip to content

Commit

Permalink
fix(vocabularymanager) analysis fails with scalar. issue 723 (accordp…
Browse files Browse the repository at this point in the history
…roject#724)

Signed-off-by: Dan Selman <[email protected]>
  • Loading branch information
dselman authored Oct 3, 2023
1 parent f3970a2 commit c637f19
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 102 deletions.
8 changes: 6 additions & 2 deletions packages/concerto-vocabulary/lib/vocabulary.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,16 @@ class Vocabulary {
* @returns {*} an object with missingTerms and additionalTerms properties
*/
validate(modelFile) {
const getOwnProperties = (d) => {
// ensures we have a valid return, even for scalars
return d.getOwnProperties?.() ? d.getOwnProperties?.() : [];
};
const result = {
missingTerms: modelFile.getAllDeclarations().flatMap( d => this.getTerm(d.getName())
? d.getOwnProperties().flatMap( p => this.getTerm(d.getName(), p.getName()) ? null : `${d.getName()}.${p.getName()}`)
? getOwnProperties(d).flatMap( p => this.getTerm(d.getName(), p.getName()) ? null : `${d.getName()}.${p.getName()}`)
: d.getName() ).filter( i => i !== null),
additionalTerms: this.content.declarations.flatMap( k => modelFile.getLocalType(Object.keys(k)[0])
? k.properties ? k.properties.flatMap( p => modelFile.getLocalType(Object.keys(k)[0]).getOwnProperty(Object.keys(p)[0]) ? null : `${Object.keys(k)[0]}.${Object.keys(p)[0]}`) : null
? Array.isArray(k.properties) ? k.properties.flatMap( p => modelFile.getLocalType(Object.keys(k)[0]).getOwnProperty(Object.keys(p)[0]) ? null : `${Object.keys(k)[0]}.${Object.keys(p)[0]}`) : null
: k ).filter( i => i !== null)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Color",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
},
"type": "UPSERT",
},
Expand All @@ -38,7 +38,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Color",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
"property": "RED",
},
"type": "UPSERT",
Expand All @@ -58,7 +58,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Color",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
"property": "BLUE",
},
"type": "UPSERT",
Expand All @@ -78,7 +78,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Color",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
"property": "GREEN",
},
"type": "UPSERT",
Expand All @@ -98,7 +98,26 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "SSN",
"namespace": "org.acme",
"namespace": "[email protected]",
},
"type": "UPSERT",
},
Object {
"$class": "[email protected]",
"decorator": Object {
"$class": "[email protected]",
"arguments": Array [
Object {
"$class": "[email protected]",
"value": "A vehicle identification number",
},
],
"name": "Term",
},
"target": Object {
"$class": "[email protected]",
"declaration": "VIN",
"namespace": "[email protected]",
},
"type": "UPSERT",
},
Expand All @@ -117,7 +136,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Vehicle",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
},
"type": "UPSERT",
},
Expand All @@ -136,7 +155,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Vehicle",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
"property": "vin",
},
"type": "UPSERT",
Expand All @@ -156,7 +175,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Vehicle",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
"property": "vin",
},
"type": "UPSERT",
Expand All @@ -176,7 +195,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Vehicle",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
"property": "color",
},
"type": "UPSERT",
Expand All @@ -196,7 +215,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Vehicle",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
"property": "$identifier",
},
"type": "UPSERT",
Expand All @@ -216,7 +235,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Truck",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
},
"type": "UPSERT",
},
Expand All @@ -235,7 +254,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Truck",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
},
"type": "UPSERT",
},
Expand All @@ -254,7 +273,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Truck",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
"property": "weight",
},
"type": "UPSERT",
Expand All @@ -274,7 +293,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Truck",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
"property": "weight",
},
"type": "UPSERT",
Expand All @@ -294,7 +313,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Truck",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
"property": "weight",
},
"type": "UPSERT",
Expand All @@ -314,7 +333,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Truck",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
"property": "vin",
},
"type": "UPSERT",
Expand All @@ -334,7 +353,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Truck",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
"property": "vin",
},
"type": "UPSERT",
Expand All @@ -354,7 +373,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Truck",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
"property": "color",
},
"type": "UPSERT",
Expand All @@ -374,7 +393,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Truck",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
"property": "$identifier",
},
"type": "UPSERT",
Expand All @@ -394,7 +413,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Thing",
"namespace": "org.accordproject",
"namespace": "org.accordproject@1.0.0",
},
"type": "UPSERT",
},
Expand All @@ -413,7 +432,7 @@ Object {
"target": Object {
"$class": "[email protected]",
"declaration": "Thing",
"namespace": "org.accordproject",
"namespace": "org.accordproject@1.0.0",
"property": "name",
},
"type": "UPSERT",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locale: en
namespace: com.example
namespace: com.example@1.0.0
declarations:
- Person: A person
properties:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace org.accordproject
namespace org.accordproject@1.0.0

concept Thing {
o String name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace org.acme
namespace org.acme@1.0.0

enum Color {
o RED
Expand All @@ -7,9 +7,10 @@ enum Color {
}

scalar SSN extends String default="000-00-0000"
scalar VIN extends String

asset Vehicle identified by vin {
o String vin
o VIN vin
o Color color
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locale: en-gb
namespace: org.acme
namespace: org.acme@1.0.0
declarations:
- Truck: A lorry
description: A heavy goods vehicle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
locale: en
namespace: org.acme
namespace: org.acme@1.0.0
declarations:
- VIN: A vehicle identification number
- Color: A color
- Vehicle: A road vehicle
properties:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locale: fr
namespace: org.acme
namespace: org.acme@1.0.0
declarations:
- Vehicle: Véhicule
properties:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locale: zh-cn
namespace: org.acme
namespace: org.acme@1.0.0
declarations:
- Color: 颜色
properties:
Expand Down
Loading

0 comments on commit c637f19

Please sign in to comment.