Search code examples
joihapi-swagger

hapi-swagger Joi string example


I'm having an issue with adding proper examples to hapi-swagger with Joi. When I add .example('') to either the response schema or validate { payload: {} } it's adding an additional obj with a value.

    response: {
      schema: Joi.object().keys({
        name: Joi.string().example('Coinbase'),
        baseCurrency: Joi.string()
          .valid('USD', 'EUR', 'MXN', 'ETH', 'LTH', 'BTC'),
      }),
    },
    validate: {
      payload: Joi.object().keys({
        name: Joi.string().required(),
        baseCurrency: Joi.string().required(),
      }),
    },

enter image description here

What I expect is on the example value to have

{ "name": "Coinbase", "baseCurrency": "USD" }

Not

{ "name": { "value": "Coinbase" }, "baseCurrency": { "value": "USD" } }


Solution

  • Downgrade joi to v13.
    Track issue on hapi-swagger github: https://github.com/glennjones/hapi-swagger/issues/540