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(*): String length validation for csharp,json generators #19

Merged
merged 4 commits into from
May 23, 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
12 changes: 10 additions & 2 deletions lib/codegen/fromcto/csharp/csharpvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,16 @@ class CSharpVisitor {
const validator = field.getValidator();

if(validator) {
let regexVal = validator.getRegex().source;
parameters.fileWriter.writeLine(1, `[System.ComponentModel.DataAnnotations.RegularExpression(@"${regexVal}", ErrorMessage = "Invalid characters")]`);
if(validator.getMinLength()) {
parameters.fileWriter.writeLine(1, `[System.ComponentModel.DataAnnotations.MinLength(${validator.getMinLength()})]`);
}
if(validator.getMaxLength()) {
parameters.fileWriter.writeLine(1, `[System.ComponentModel.DataAnnotations.MaxLength(${validator.getMaxLength()})]`);
}
if (validator.getRegex()) {
let regexVal = validator.getRegex().source;
parameters.fileWriter.writeLine(1, `[System.ComponentModel.DataAnnotations.RegularExpression(@"${regexVal}", ErrorMessage = "Invalid characters")]`);
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion lib/codegen/fromcto/jsonschema/jsonschemavisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ class JSONSchemaVisitor {
jsonSchema.format = 'uuid';
} else if(validator) { // validator for uuid is not required.
// Note that regex flags are lost in this transformation
jsonSchema.pattern = validator.getRegex().source;
if (validator.getRegex()) {
jsonSchema.pattern = validator.getRegex().source;
}
if(validator.getMinLength()) {
jsonSchema.minLength = validator.getMinLength();
}
if(validator.getMaxLength()) {
jsonSchema.maxLength = validator.getMaxLength();
}
}
break;
case 'Double':
Expand Down
196 changes: 108 additions & 88 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"author": "accordproject.org",
"license": "Apache-2.0",
"devDependencies": {
"@accordproject/concerto-cto": "3.5.0",
"@accordproject/concerto-cto": "3.8.0",
"@babel/preset-env": "7.16.11",
"babel-loader": "8.2.3",
"chai": "4.3.6",
Expand All @@ -69,8 +69,8 @@
"webpack-cli": "4.9.1"
},
"dependencies": {
"@accordproject/concerto-core": "3.7.0",
"@accordproject/concerto-util": "3.7.0",
"@accordproject/concerto-core": "3.8.1",
"@accordproject/concerto-util": "3.8.0",
"@openapi-contrib/openapi-schema-to-json-schema": "3.2.0",
"ajv": "8.10.0",
"ajv-formats": "2.1.1",
Expand Down
Loading