Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aron123 opened this issue Aug 23, 2019 · 0 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@aron123
Copy link

aron123 commented Aug 23, 2019

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().

@hueniverse hueniverse self-assigned this Aug 23, 2019
@hueniverse hueniverse added the bug Bug or defect label Aug 23, 2019
@hueniverse hueniverse added this to the 16.0.0 milestone Aug 23, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants