Code Monkey home page Code Monkey logo

Comments (6)

mac- avatar mac- commented on May 20, 2024

Great question. This issue may give you some context.

At the time I built this module, they didn't allow other implementations to be used within the validate config.

With that said, I actually wouldn't mind changing the module to use the built in validate config, but I just haven't had time to update it.

from ratify.

KrisSiegel avatar KrisSiegel commented on May 20, 2024

Understood. Thanks!

from ratify.

KrisSiegel avatar KrisSiegel commented on May 20, 2024

With this ticket closed does that mean you won't end up moving to the built in config? Or will that go into a new ticket?

from ratify.

mac- avatar mac- commented on May 20, 2024

I was going to create a new one, but I'll actually just leave this one open for some additional context

from ratify.

ozum avatar ozum commented on May 20, 2024

Hi,

I tried to write a plugin which would check if object given to config.validate is a JSON schema and act according to, but I failed. How is it possible even in latest version of Hapi? (v11.1.2 as of this message is written)

From hapi.js /lib/route.js line: 260

internals.compileRule = function (rule) {

    // null, undefined, true - anything allowed
    // false - nothing allowed
    // {...} - ... allowed

    return (rule === false ? Joi.object({}).allow(null)
                           : typeof rule === 'function' ? rule
                                                        : !rule || rule === true ? null                     // false tested earlier
                                                                                 : Joi.compile(rule));
};

If you provide JSON schema as an object to standard config.validate.payload etc. of a route, hapi directly tries to convert it to JOI object. This is also clearly stated in API docs of hapi. As a result you cannot access bare JSON schema even in onPostAuth, since it is already converted as below:

{ options: {},
  params: 
   { isJoi: true,
     _type: 'object',
     _settings: null,
     _valids: { _set: [] },
     _invalids: { _set: [] },
     _tests: [],
     _refs: [],
     _flags: {},
     _description: null,
     _unit: null,
     _notes: [],
     _tags: [],
     _examples: [],
     _meta: [],
     _inner: 
      { children: [Object],
        renames: [],
        dependencies: [],
        patterns: [] } },
  payload: null,
  headers: null,
  query: null }

I will also open a ticket about this in hapi repository, but I will appreciate if you suggest any ideas how to achieve this in current version?

from ratify.

ozum avatar ozum commented on May 20, 2024

For update. I asked in hapi repository and got an answer. It seems impossible according to hapijs/hapi#2967.

from ratify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.