Skip to content

schema.describe() does not work, when default value is assigned to array in schema #2068

@aron123

Description

@aron123

Context

  • node version: 10.14.0
  • joi version: 16.0.0-preview
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information:

What are you trying to achieve or the steps to reproduce ?

const Joi = require('@hapi/joi');

const schema = Joi.object({
    FundingSources: Joi.array().optional()
        .items(
            Joi.string().valid('All', 'Balance')
        )
        .length(1)
        .default(['All'])
});

console.log(schema.describe());

Which result you had ?

node_modules/@hapi/joi/lib/index.js:214
    throw error;
    ^

ValidationError: {
  "type": "array",
  "flags": {
    "presence": "optional",
    "default" [1]: [
      "All"
    ]
  },
  "rules": [
    {
      "name": "length",
      "args": {
        "limit": 1
      }
    }
  ],
  "items": [
    {
      "type": "string",
      "flags": {
        "only": true
      },
      "allow": [
        "All",
        "Balance"
      ]
    }
  ]
}

[1] "flags.default" must be one of [boolean, object, number, string, object, object, object, object, object, object, object, object]

What did you expect ?

Proper output of schema.describe().

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions