-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Cannot have a property on a request called validate #121
Comments
This has been reported by a user. |
Should this issue be moved to https://github.com/accordproject/concerto ? (maybe with the cool issue transfer feature in GitHub) |
Replicate with the following script ... const ModelManager = require('@accordproject/concerto-core').ModelManager;
const Factory = require('@accordproject/concerto-core').Factory;
const Serializer = require('@accordproject/concerto-core').Serializer;
const modelManager = new ModelManager();
const concertoModel = `
namespace issue121
concept TestConcept {
o String validate
}
`;
modelManager.addModelFile( concertoModel, 'file.cto');
const factory = new Factory(modelManager);
const resource = factory.newConcept('issue121', 'TestConcept');
// resource.validate = 'foo';
const serializer = new Serializer(factory, modelManager);
const plainJsObject = serializer.toJSON(resource);
console.log(JSON.stringify(plainJsObject, null, 2)); This produces the output: /Users/matt/dev/sbx/concerto-issue121/node_modules/@accordproject/concerto-core/lib/serializer/resourcevalidator.js:433
throw new ValidationException(formatter({
^
ValidationException: Model violation in instance undefined field validate has value undefined (function) expected type String
at Function.reportFieldTypeViolation (/Users/matt/dev/sbx/concerto-issue121/node_modules/@accordproject/concerto-core/lib/serializer/resourcevalidator.js:433:15)
at ResourceValidator.checkItem (/Users/matt/dev/sbx/concerto-issue121/node_modules/@accordproject/concerto-core/lib/serializer/resourcevalidator.js:321:35)
at ResourceValidator.visitField (/Users/matt/dev/sbx/concerto-issue121/node_modules/@accordproject/concerto-core/lib/serializer/resourcevalidator.js:223:22)
at ResourceValidator.visit (/Users/matt/dev/sbx/concerto-issue121/node_modules/@accordproject/concerto-core/lib/serializer/resourcevalidator.js:79:25)
at Field.accept (/Users/matt/dev/sbx/concerto-issue121/node_modules/@accordproject/concerto-core/lib/introspect/decorated.js:65:24)
at ResourceValidator.visitClassDeclaration (/Users/matt/dev/sbx/concerto-issue121/node_modules/@accordproject/concerto-core/lib/serializer/resourcevalidator.js:176:26)
at ResourceValidator.visit (/Users/matt/dev/sbx/concerto-issue121/node_modules/@accordproject/concerto-core/lib/serializer/resourcevalidator.js:75:25)
at ConceptDeclaration.accept (/Users/matt/dev/sbx/concerto-issue121/node_modules/@accordproject/concerto-core/lib/introspect/decorated.js:65:24)
at Serializer.toJSON (/Users/matt/dev/sbx/concerto-issue121/node_modules/@accordproject/concerto-core/lib/serializer.js:109:30)
at Object.<anonymous> (/Users/matt/dev/sbx/concerto-issue121/index.js:24:34) Compare this to the output another required field with a missing value
|
It appears that this is down to instances of the
This means that all internal API methods for this class and its subtypes are reserved property names, e.g. One solution would be to push field properties into a resource.foo = "bar";
// becomes either
resource.$values.foo = "bar";
resource.setPropertyValue(foo, "bar"); Alternatively, we could add prefixes to all internal method names to reduce the likelihood of collisions. For example, A third option would be to retain the current behaviour but to add better detection and warnings when property names clash with internal methods. Any other ideas @dselman @jeromesimeon ? |
@mttrbrts Thanks for the reproducibility + analysis! I think the easiest would be the last option with a twist: use a prefix which is not allowed in the Concerto syntax (I think |
This is now supported via the new Concerto API, merged into the release-1.0 branch. |
Get a runtime failure because when we try to call the validate function on the Concerto object we are actually accessing the field.
The text was updated successfully, but these errors were encountered: