tlivings / enjoi

Converts a JSON schema to a Joi schema.
Apache License 2.0
283 stars 57 forks source link

Parameter name is undefined #56

Closed ozum closed 6 years ago

ozum commented 6 years ago

Hi,

If name property is not present in schema, field name in thrown error (by Joi) is undefined.

It may not be a bug (name property is already missing), but during conversion Enjoi may use property key as field name if it is not present.

Sample code:

const Joi = require("joi");
const Enjoi = require("enjoi");

const jsonSchema = {
  title: "User Detailed Output",
  allOf: [
    {
      title: "User Basic Output",
      allOf: [
        {
          type: "object",
          properties: {
            id: { type: "string", format: "uuid", description: "Kaydın ID'si." },
          },
          required: ["id"],
        },
        {
          title: "User Common",
          type: "object",
          properties: {
            businessUnitId: {
              type: "string",
              format: "uuid",
            },
          },
        },
      ],
    },
    { type: "object" },
  ],
  $schema: "http://json-schema.org/draft-04/schema#",
};

Joi.assert({}, Enjoi.schema(jsonSchema));

Actual Output

ValidationError: {
  "id" [1]: -- missing --
}

[1] "undefined" is required

Expected Output

ValidationError: {
  "id" [1]: -- missing --
}

[1] "id" is required