Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vocabularymanager) analysis fails with scalar. issue 723 #724

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines 152 to +156
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These ternary expressions are starting to get very difficult to read. Time for a refactor?

: 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": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"declaration": "Color",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
},
"type": "UPSERT",
},
Expand All @@ -38,7 +38,7 @@ Object {
"target": Object {
"$class": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"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": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"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": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"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": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"declaration": "SSN",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
},
"type": "UPSERT",
},
Object {
"$class": "org.accordproject.decoratorcommands@0.3.0.Command",
"decorator": Object {
"$class": "concerto.metamodel@1.0.0.Decorator",
"arguments": Array [
Object {
"$class": "concerto.metamodel@1.0.0.DecoratorString",
"value": "A vehicle identification number",
},
],
"name": "Term",
},
"target": Object {
"$class": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"declaration": "VIN",
"namespace": "org.acme@1.0.0",
},
"type": "UPSERT",
},
Expand All @@ -117,7 +136,7 @@ Object {
"target": Object {
"$class": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"declaration": "Vehicle",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
},
"type": "UPSERT",
},
Expand All @@ -136,7 +155,7 @@ Object {
"target": Object {
"$class": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"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": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"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": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"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": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"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": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"declaration": "Truck",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
},
"type": "UPSERT",
},
Expand All @@ -235,7 +254,7 @@ Object {
"target": Object {
"$class": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"declaration": "Truck",
"namespace": "org.acme",
"namespace": "org.acme@1.0.0",
},
"type": "UPSERT",
},
Expand All @@ -254,7 +273,7 @@ Object {
"target": Object {
"$class": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"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": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"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": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"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": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"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": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"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": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"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": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"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": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"declaration": "Thing",
"namespace": "org.accordproject",
"namespace": "org.accordproject@1.0.0",
},
"type": "UPSERT",
},
Expand All @@ -413,7 +432,7 @@ Object {
"target": Object {
"$class": "org.accordproject.decoratorcommands@0.3.0.CommandTarget",
"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
Loading