ProtoDef-io / ProtoDef

ProtoDef specification: describe your protocol, and read it with ease.
35 stars 8 forks source link

Cleaning schemas a bit. #44

Open stefalce opened 3 years ago

stefalce commented 3 years ago

Here are some things I didn't find cool about json schemas:

The strict mode error doesn't mean much except the schema has something unclear or meaningless. Validation for strict mode or not is identical. For example in the container schema there is a non necessary additionalItems which annoyingly throws an error if strict mode is on.

{
   "type":"array",
   "items":{
      "type":"object",
      "properties":{
         "anon":{
            "type":"boolean"
         },
         "name":{

         },
         "type":{
            "$ref":"dataType"
         }
      },
      "oneOf":[
         {
            "required":[
               "anon"
            ]
         },
         {
            "required":[
               "name"
            ]
         }
      ],
      "required":[
         "type"
      ],
      "additionalProperties":false
   },
   "additionalItems":false
}
stefalce commented 3 years ago

I've done more tests, I found a problem in cstring. Since it hasn't 'type: "array"' it validates all non array data as true. Also currently json like ["container"] or [] is considered valid (at least in newer versions), ajv strict mode is useful as it requires to state minItems. Schemas could also be rewritten using the const keyword instead of the single item enum.

rom1504 commented 7 months ago

Please propose PRs for fixes