hapi-swagger / hapi-swagger

A Swagger interface for hapi
https://hapi.dev/
MIT License
913 stars 420 forks source link

xor both fields included in request payload #585

Open jasonoverby opened 5 years ago

jasonoverby commented 5 years ago

Context

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

I am hoping to provide example request payload values in my swagger where one or the other value is required but not both.

Validation:

const requestSchema = joi
  .object()
  .keys({
    a: joi
      .string()
      .example('a')
      .required(),
    b: joi.string().example('b'),
    c: joi.string().example('c'),
  })
  .xor('b', 'c');

What result did you get?

Both b and c were included in the example request payload.

Screen Shot 2019-05-07 at 5 22 39 PM

What did you expect?

One or the other would be included, but not both.

isastim commented 3 years ago

Hi, I am facing the same limitations as OP. I really need the oneOf selection from OpenAPI and thought this can be solved with joi's xor() method. Since this issues was opened quite some time ago are there any alternatives to get this working or is it still in development? Thanks for your efforts.

robmcguinness commented 3 years ago

@isastim i'm not aware of anyone working to fix this issue. is this something you would be willing to do? if not, maybe some other member of the community can submit a fix.

isastim commented 3 years ago

@robmcguinness Thank's for your quick reply. That's very unfortunate this hasn't been implemented yet. I decided to pass on this feature for now. I think I still don't have the capacity to implement and contribute this feature since I am not a much experienced programmer.