Open Gregy opened 9 years ago
Yes - joi.alternatives() are currently not supported and will be stripped. I would be interested how your schema should look in swagger 2.0 specs (designed by hand) and then we should have a look how close we can get.
I have a similar problem. The following model actually breaks swagger (with a 500 error):
kindSeparator = Joi.object({
pagingKind: Joi.string().required()["default"]("separator").example("separator").description("Specifies the kind of page.").valid('separator')
}).description("Instruction to render a page separator").meta({
className: 'PaginationPageSeparator'
}).options({
allowUnknown: true,
stripUnknown: true
});
kindPage = Joi.object({
pagingKind: Joi.string().required()["default"]("page").example("page").description("Specifies the kind of page.").valid(['page']),
pageNumber: Joi.number().integer()["default"](0).example(0).description("The zero based page number of this page.").required(),
pageNumberDisplay: Joi.string()["default"]("1").example("1").description("The one based page number as a string, useful for displaying to the end user.").required(),
nextUrl: me.urlOptional("The request url to retrieve this page, or null."),
active: Joi.boolean()["default"](false).example(true).description("Boolean that indicates that this item is the currently active page.").required()
}).description("The description of a single page").meta({
className: 'PaginationPagePage'
}).options({
allowUnknown: true,
stripUnknown: true
});
return Joi.alternatives(kindPage, kindSeparator).description("The description of a single page").meta({
className: 'PaginationPage'
}).options({
allowUnknown: true,
stripUnknown: true
});
THe idea is to have an alternative between object a and b, where a has a specific kind and b another.
@z0mt3c Hello, any updates on this since then? Is it still not working?
Any updates on this?
Edit: mixed up issues
Alternatives have no special implementation yet - but at least it shouldn't throw... will double check with the new version 2.10.0.
As i mentioned earlier: joi.alternatives() are currently not supported and will be stripped. I would be interested how your schema should look in swagger 2.0 specs (designed by hand) and then we should have a look how close we can get.
I know what alternatives do but when i created this module the swagger specs where not capable of polymorphism - at least i didn't find a way. Can u provide me a swagger example schema with polymorphism?
Should be partially possible with Swagger 3.0: https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/
Discriminator Object adds support for polymorphism - https://swagger.io/specification/#discriminatorObject
I have a fairly complex validation object shared on multiple routes. Sometimes with slight modifications which are handled by joi.alternatives:
Alternatives fields seems to be ignored completely in generated model: