Skip to content

Correct way to write an "identity" extension? #1000

@LudwikJaniuk

Description

@LudwikJaniuk

(by "identity" I mean "one that changes nothing", similar to the identity function)

Context

  • node version:6
  • joi version:9
  • environment (node, browser):node
  • used with (hapi, standalone, ...):standalone
  • any other relevant information:I'm extending joi

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

I'm trying to do a minimal "identity" extension to joi that would replace an existing data type, but not change it in any way, so I'm using it as the base.

var joi = require("joi");
joi = joi.extend({
    name: "object",
    base: joi.object(),
});

Which result you had ?

joi.object() seems to be behaving slightly differently, it has something to do with .options() and .keys() and allowUnknown changing their behavior. I will construct a minimal example demonstrating this if it's not obvious what I'm doing wrong.

What did you expect ?

I expected the new joi.object() to work exactly as before, and change nothing in how the new joi object behaves. Was that assumption correct? Is this how you would write an "identity" extension?

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