Joi: Tuple?

Created on 11 Dec 2014  路  7Comments  路  Source: sideway/joi

Would you consider tuple as a first-class concept in Joi?
(and be interested in a PR?)

Consider, a query param foo=bar:baz an a schema like:

query: {
  foo: Joi.tuple(':', Joi.string().min(3), Joi.string().guid())
}
// would fail on 'baz' not being a guid

I would expect tuple to

  • split the value of param at the first occurrence of the provided delimiter
  • validate split value[0] against the first schema
  • for each remaining schema, split value[1] again on the next occurrence of the delimiter and repeat

In my _particular_ case, I need to be able to validate

GET /entities?relationship=someUserString:someObjectGUID

And using regex can quickly get ugly.

feature

Most helpful comment

You can now, with a custom joi type, see Joi.extend(). I don't want to implement string parsing into joi as I don't consider this to be core-worthy, many formats exist and I don't have enough time to support everything that's out there on my own.

All 7 comments

That's what JSON serialization is for, why would you do your own thing ?

Thanks for the quick reply. Not all clients are producing/consuming JSON, but in my case I can make do. It's a bit more verbose and by default logging doesn't look as good but it seems to allow even more powerful validation. Thanks again.

I'm not going to put a parser for an obscure serialization format into core anyway :-)

those obscure delimited values :poodle:

Obscure format ?
If I want to follow a standard like this for example :
http://jsonapi.org/format/#fetching-sorting
example: "http://..../...?sort=-updated,author,name"

Sure, if I can do my own format, I can use the ones available in Joi, it's sufficient, but well,
If I have to follow JSON API standard, then I cannot parse the values with Joi...

You can now, with a custom joi type, see Joi.extend(). I don't want to implement string parsing into joi as I don't consider this to be core-worthy, many formats exist and I don't have enough time to support everything that's out there on my own.

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

neroaugustus1 picture neroaugustus1  路  4Comments

Taxi4you picture Taxi4you  路  3Comments

mohamadresaaa picture mohamadresaaa  路  3Comments

JbIPS picture JbIPS  路  4Comments

alekbarszczewski picture alekbarszczewski  路  3Comments