Open acheambe opened 8 years ago
I have many doubts about the usefulness of the Massage Factory. We can use methods to build messages that conform with the schema, but we still have a problem to validate the received messages! I have different and simpler suggestion to build this. We can have a method, something like validate(schema: JsonSchema, obj: Json): [throw error if failed] and use it like:
//in a config file
Validator.debug = true;
//if Validator.debug === false -> don't load
Validator.loadSchema(<message-schema-url>);
//normal use........................................................
let msg = {
from: x, to: y,
body: { ... }
}
//throw error if validation fails, if Validator.debug === false -> does nothing
Validator.validate(<message-schema-url>, msg);
It's a simple implementation that has the following advantages:
Thx Micael. you are touching two points which i am not sure are related to each other? message factory and validator of schema. Are you saying there is no need for the MessageFactory?
I agree that it is an overkill to validate the Objects all the time. So the question i guess is when to carry out this validation?
Yes, I think there is no need for the MessageFactory or any structure specific factory (just my opinion). Just create the data has any JSON object and validate if it's in agreement with the schema. But we may need other opinions about this.
That will be a quick approach to handle it. For a small project maybe, but i guess for a project this size, we need to structure things a little bit with these factories. Yes, interested in other opinions.
Mhm,
not sure if I got the entire technical view, but my feeling is that having these factories is better for so many partners working on the project / code. It allows to have a single point of verification upon creation and should also allow to provide proper conversion methods to generate a data object from, e.g. an optimized representation received over interfaces from other components.
I also think factories are useful to maintain the full project compliant with data models (minimise impact of changing the data models) and also because it provides an API that should abstract as much as possible the data models. But I like @shumy proposal to only use the "validator" when needed, by using some configuration flag, something similar to log4j but for schema validation.
And @shumy also raised an important issue: the framework should also provide a message parser. What do you think?
@pchainho message parser? on this thread? Didn't see that. But anyways, the factory will offer a parser. Which in effect is provided automatically in JavaScript through the JSON API. JSON.parse and JSON.stringify. @shumy correct me if i am wrong
No parser needed (this is automatically done in JS), just validation of the received message.
Thought so too. Okay
ah ok, I was not aware of that.
Another JSON schema validator tool:
This one is based on ECMAScript 3 and last commit was 3 years ago
On our last telco for the Service Framework, was a proposal for an agile procedure of working between specification from WP2 and implementation on WP3.
In other words to have the option to automate the changes carried out on JSON schemas to be reflected on implementations without huge efforts.
Mechanisms for this needs to be investigated and it is not exactly clear at what point this should be done. Any proposals?