Skip to content

Commit

Permalink
feat(*): Support string length validation (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ragi-dayananda authored May 16, 2023
1 parent 5f88b5c commit 2ab4abe
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 6 deletions.
7 changes: 7 additions & 0 deletions lib/metamodel.cto
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,19 @@ concept DateTimeProperty extends Property {
concept StringProperty extends Property {
o String defaultValue optional
o StringRegexValidator validator optional
o StringLengthValidator lengthValidator optional
}

concept StringRegexValidator {
o String pattern
o String flags
}

concept StringLengthValidator {
o Integer minLength optional
o Integer maxLength optional
}

concept DoubleProperty extends Property {
o Double defaultValue optional
o DoubleDomainValidator validator optional
Expand Down Expand Up @@ -239,6 +245,7 @@ concept DoubleScalar extends ScalarDeclaration {
concept StringScalar extends ScalarDeclaration {
o String defaultValue optional
o StringRegexValidator validator optional
o StringLengthValidator lengthValidator optional
}

concept DateTimeScalar extends ScalarDeclaration {
Expand Down
2 changes: 1 addition & 1 deletion lib/metamodel.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions lib/metamodel.json
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,16 @@
},
"isArray": false,
"isOptional": true
},
{
"$class": "[email protected]",
"name": "lengthValidator",
"type": {
"$class": "[email protected]",
"name": "StringLengthValidator"
},
"isArray": false,
"isOptional": true
}
],
"superType": {
Expand All @@ -724,6 +734,25 @@
}
]
},
{
"$class": "[email protected]",
"name": "StringLengthValidator",
"isAbstract": false,
"properties": [
{
"$class": "[email protected]",
"name": "minLength",
"isArray": false,
"isOptional": true
},
{
"$class": "[email protected]",
"name": "maxLength",
"isArray": false,
"isOptional": true
}
]
},
{
"$class": "[email protected]",
"name": "DoubleProperty",
Expand Down Expand Up @@ -1125,6 +1154,16 @@
},
"isArray": false,
"isOptional": true
},
{
"$class": "[email protected]",
"name": "lengthValidator",
"type": {
"$class": "[email protected]",
"name": "StringLengthValidator"
},
"isArray": false,
"isOptional": true
}
],
"superType": {
Expand Down
5 changes: 3 additions & 2 deletions test/cto/person.cto
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ abstract participant Individual {
}

participant Person extends Individual {
o String firstName regex=/[a-zA-Z]*/u
o String lastName
o String firstName regex=/[a-zA-Z]*/u length=[1,]
o String lastName length=[,100]
o string middleName length=[1,100]
o Address address
o Address address2 default="USAddress"
@description("Work Address")
Expand Down
21 changes: 20 additions & 1 deletion test/cto/person.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,32 @@
"$class": "[email protected]",
"pattern": "[a-zA-Z]*",
"flags": "u"
},
"lengthValidator": {
"$class": "[email protected]",
"minLength": 1
}
},
{
"$class": "[email protected]",
"name": "lastName",
"isArray": false,
"isOptional": false
"isOptional": false,
"lengthValidator": {
"$class": "[email protected]",
"maxLength": 100
}
},
{
"$class": "[email protected]",
"name": "middleName",
"isArray": false,
"isOptional": false,
"lengthValidator": {
"$class": "[email protected]",
"minLength": 1,
"maxLength": 100
}
},
{
"$class": "[email protected]",
Expand Down
21 changes: 20 additions & 1 deletion test/cto/personResolved.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,32 @@
"$class": "[email protected]",
"pattern": "[a-zA-Z]*",
"flags": "u"
},
"lengthValidator": {
"$class": "[email protected]",
"minLength": 1
}
},
{
"$class": "[email protected]",
"name": "lastName",
"isArray": false,
"isOptional": false
"isOptional": false,
"lengthValidator": {
"$class": "[email protected]",
"maxLength": 100
}
},
{
"$class": "[email protected]",
"name": "middleName",
"isArray": false,
"isOptional": false,
"lengthValidator": {
"$class": "[email protected]",
"minLength": 1,
"maxLength": 100
}
},
{
"$class": "[email protected]",
Expand Down
Loading

0 comments on commit 2ab4abe

Please sign in to comment.