Skip to content

Errors: context.key is actually the label, not the key #1167

@EvgenyOrekhov

Description

@EvgenyOrekhov

Context

  • node version: 7.9.0
  • joi version: 10.4.1
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone

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

I need to get the key from the context, I expected context.key to be the key, but it turns out it's the label.

const Joi = require("joi");

const context = Joi
    .object({
        someKey: Joi.required().label("some label")
    })
    .validate({})
    .error.details[0].context;

console.log(context);

Which result you had ?

{
    key: "some label"
}

What did you expect ?

{
    key: "someKey"
}

This example on RunKit: https://runkit.com/57d675ee7580c314003cf648/58fe1d4fad401b00120f475a/branches/master

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changesChange that can breaking existing codebugBug or defect

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions