hapi-swaggered
hapi-swaggered copied to clipboard
Swagger schema validation failed.
I have a route with joy validation. { method: 'GET', path : '/users/login_history/{historyLength?}', config: { description: 'Get login history for current user.', notes : 'Get login history for current user.', tags : ['api', 'get', 'user', 'history', 'login', 'current'], handler : userController.listLoginHistory, validate : userValidate.listLoginHistory, response : {schema: userModel.listLoginHistory}, plugins : { 'hapi-swagger': { responseMessages: [ {code: 400, message: 'Bad Request'}, {code: 401, message: 'Unauthorized'} ] } } }
userValidate.listLoginHistory : { params : Joi.object({historyLength: Joi.number().integer().default(5)}).meta({className: 'listLoginHistory'}), headers: AuthSchema.headers }
And i get error Swagger schema validation failed. Data does not match any schemas from 'oneOf' at #/paths//users/login_history/{historyLength}/get/parameters/0 Data does not match any schemas from 'oneOf' at #/paths//users/login_history/{historyLength}/get/parameters/0 Missing required property: schema at #/ Data does not match any schemas from 'oneOf' at #/ No enum match for: path at #/in No enum match for: path at #/in No enum match for: path at #/in No enum match for: false at #/required Missing required property: $ref at #/paths//users/login_history/{historyLength}/get/parameters/0
JSON_OBJECT_VALIDATION_FAILED }
If i change historyLength to .required() error dissapears. How to describe optional parameter?
Thanks, Indrek