-
Notifications
You must be signed in to change notification settings - Fork 32
Check all required properties are defined #33
base: master
Are you sure you want to change the base?
Conversation
@piranna specifying missing props wouldn't make for an invalid JSON schema in the first place? |
It should, but this needs a higher level check because we need to check that some fields are available based on what's defined in another one, that's what my pull-request does... I don't think json schema is powerful enough to do that itself, and in fact currently I'm able to render invalid forms with non-existing required properties due to this. |
Let me understand, given this invalid schema {
"type": "object",
"properties": {
"a": { "type": "string" }
},
"required": ["b"]
} is tcomb-json-schema somehow generating a type with both an Or, in another words, could you please show/add a test case in which tcomb-json-schema would produce a wrong type? |
It's showing an |
I know this is a small change but I don't feel that tcomb-json-schema should validate the input schema |
Can you argument on this? I don't understand about why it shouldn't at least show a warning... |
Because validating the input schema is out of scope. This library should just convert a (valid) JSON Schema to tcomb types. Otherwise why just stop here? There are plenty of other validations that could be done but then you end up replicating a json schema validator |
I try to use defensive programming whenever is possible, I understand validation would be done in a previous step and maybe also in an independent module, but I tend to do checkings just before I'm going to use it, like it's this case, and just as last option if the data structure don't offer a safer option. For example, instead of a list of required field, each one would have a |
This ensure that if a property is marked as required, that it exists in the definition of properties in a struct.