tlivings / enjoi

Converts a JSON schema to a Joi schema.
Apache License 2.0
282 stars 56 forks source link

doesn't handle schemas that use more than one of `type`, `anyOf`, `allOf` #102

Closed nlundquist closed 3 years ago

nlundquist commented 3 years ago

Enjoi doesn't attempt to create Joi validators for valid schemas like:

{
  type: "object",
  required: ['foo'],
  properties: {
    "foo": { type: "string" } 
  },
  oneOf: [
    { 
      type: "object",
      required: ['bar'],
      properties: {
        "bar": { type: "string" } 
      }
    },
    { 
      type: "object",
      properties: {
        "baz": { type: "string" } 
      }    
    }
  ]
}

It will only create the validator for the base object including the foo property. It ignores the additional mutually exclusive properties expressed in the oneOf.

Invalid data like { foo: 'a', bar: 'b', baz: 'c' } passes the validator returned.

nlundquist commented 3 years ago

The goal of this feature is validating an object against a base object schema ( foo ) and a set of alternative objects ( bar, baz ). This sort of comparison will fail unless additionalProperties: true is included in all the objects, this differs from typical JSONSchema due to the issue here: https://github.com/tlivings/enjoi/issues/103

For that reason I'll be resolving #103 as well in the PR for this issue.