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

Describe references as such #345

Closed
Marsup opened this issue May 22, 2014 · 10 comments
Closed

Describe references as such #345

Marsup opened this issue May 22, 2014 · 10 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@Marsup
Copy link
Collaborator

Marsup commented May 22, 2014

As mentioned in outmoded/lout#57, references should have their own descriptions.

> Joi.compile(Joi.ref('a.b')).describe()
{ type: 'any',
  flags: { allowOnly: true },
  valids:
   [ undefined,
     { [Function]
       isContext: false,
       key: 'a.b',
       path: [Object],
       depth: 2,
       root: 'a',
       isJoi: true,
       toString: [Function] } ],
  invalids: [ null ] }

I think isContext, key, path, depth, root should be exposed at the root of the description and type should indeed be ref.

@hueniverse
Copy link
Contributor

Example?

@hueniverse hueniverse added the bug label May 22, 2014
@hueniverse hueniverse added this to the 3.4.1 milestone May 22, 2014
@hueniverse hueniverse self-assigned this May 22, 2014
@Marsup
Copy link
Collaborator Author

Marsup commented May 22, 2014

{
  type: 'ref',
  isContext: false,
  key: 'a.b'
  path: ['a', 'b'],
  depth: 2,
  root: 'a'
}

Not sure about valids/invalids, can they ever have other values ?

@hueniverse
Copy link
Contributor

Valid and invalid cannot be an object or function other than: null, undefined, Date, Buffer, or Ref. So making it an object is safe. However, also need to figure out default() which takes anything. Should I just expose Ref.isRef() as an API and leave it as is?

@Marsup
Copy link
Collaborator Author

Marsup commented May 22, 2014

Considering the specific api of refs, I don't see how valids could ever be anything else than [undefined, function] and invalids [null], am I wrong ?
isRef would only help me detect which function in valids is the one to extract information from, I'd rather have it exposed right away without having to dig through valids, don't you think ?

@hueniverse
Copy link
Contributor

Valid and invalid is easy to do. What do you want to do about flags.default?

@Marsup
Copy link
Collaborator Author

Marsup commented May 22, 2014

Does it exist at all ?

> Joi.ref('a.b').default(0)
TypeError: Object ref:a.b has no method 'default'

@hueniverse
Copy link
Contributor

No. Joi.any().default(Joi.ref('a.b'))

@Marsup
Copy link
Collaborator Author

Marsup commented May 22, 2014

I think it's out of topic. My current problem is to describe references alone, not objects of any type that have a default to a reference. Unless I missed something I don't see how it's related.

@hueniverse
Copy link
Contributor

Yeah, but it's the same problem for me.

@hueniverse
Copy link
Contributor

I've decided to leave the describe() behavior as-is, and add Joi.isRef(). Right now, in valids and invalids a function can only be a ref, but this may change in the future. flags.default can be anything. If a value is a function, just call Joi.isRef() on it to find out.

hueniverse pushed a commit that referenced this issue May 23, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 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