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

feat(*): Support string length validation #3

Merged
merged 1 commit into from
May 16, 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
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