Skip to content
This repository has been archived by the owner on Jan 31, 2025. It is now read-only.

hapi-openapi prevents application using @hapi/glue v7.0.0 and @hapi/hapi v19.1.1 on starting due to no validator being configured #171

Closed
edward-whittle opened this issue Feb 19, 2020 · 1 comment

Comments

@edward-whittle
Copy link
Contributor

The latest version of Hapi requires a Validator to be configured as per this issue for this release.

The issue can be replicated by removing the hapi-openapi plugin which allows the server to start

plugin-hapi-openapi

exports.plugin = {
  plugin: require('hapi-openapi'),
  options: {
    api: require('path').resolve('./config/swagger.yaml'),
    handlers: require('path').resolve('./handlers'),
    docs: {
      path: 'api-docs',
    },
  },
};

Manifest for Glue.compose

/* eslint-disable max-len */
const returnXVHeader = require('../plugins/plugin-xv-header').plugin;
const hapiOpenAPI = require('../plugins/plugin-hapi-openapi').plugin;
const hapiAlive = require('../plugins/plugin-hapi-alive').plugin;
const hapiPino = require('../plugins/plugin-hapi-pino').plugin;
const validateAcceptHeader = require('../plugins/plugin-preresponse-error').plugin;
const validateContentType = require('../plugins/plugin-validate-content-type').plugin;

const plugins = [
  returnXVHeader,
  // hapiOpenAPI, Commenting out allows server to start
  hapiAlive,
  hapiPino,
  validateContentType,
  validateAcceptHeader,
  {
    plugin: require('@hapi/vision'),
  },
  {
    plugin: require('@hapi/inert'),
  },
  {
    plugin: require('hapi-swagger'),
  },
];

exports.manifest = {
  server: {
    host: '0.0.0.0',
    port: 3001,
  }, register: {
    plugins: plugins,
  },
};

Error Stack

Error: Cannot set uncompiled validation rules without configuring a validator
    at new module.exports (/application/node_modules/@hapi/hapi/node_modules/@hapi/hoek/lib/error.js:23:19)
    at Object.module.exports [as assert] (/application/node_modules/@hapi/hapi/node_modules/@hapi/hoek/lib/assert.js:20:11)
    at Object.exports.compile (/application/node_modules/@hapi/hapi/lib/validation.js:48:10)
    at module.exports.internals.Route._setupValidation (/application/node_modules/@hapi/hapi/lib/route.js:197:43)
    at new module.exports.internals.Route (/application/node_modules/@hapi/hapi/lib/route.js:122:14)
    at internals.Server._addRoute (/application/node_modules/@hapi/hapi/lib/server.js:498:23)
    at internals.Server.route (/application/node_modules/@hapi/hapi/lib/server.js:491:22)
    at Object.register (/application/node_modules/hapi-openapi/lib/index.js:171:16)
    at async internals.Server.register (/application/node_modules/@hapi/hapi/lib/server.js:466:17)
    at async Object.exports.compose (/application/node_modules/@hapi/glue/lib/index.js:46:9)
@edward-whittle
Copy link
Contributor Author

edward-whittle commented Feb 19, 2020

This issue can be fixed by adding the following to the register function in lib/index.js

server.validator(require('joi')); //Add this line
const validation = Joi.validate(options, optionsSchema); //Above this line

edward-whittle added a commit to edward-whittle/hapi-openapi that referenced this issue Feb 19, 2020
tlivings added a commit that referenced this issue Jan 31, 2021
Co-authored-by: Trevor Livingston <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants