GithubHelp home page GithubHelp logo

Comments (8)

ColinFrick avatar ColinFrick commented on June 20, 2024

Does it work if you add strict: true to the address definition?
See https://github.com/icebob/fastest-validator#properties-10

from moleculer-web.

ekellstrand avatar ekellstrand commented on June 20, 2024

@ColinFrick Yes!
Interesting...
Adding "$$strict:true" to the address definition did not work.
Adding "strict:true" to the address definition, with out the dollar signs, did work.

I'll have to check and see if I should be using "strict:true" everywhere now instead of "$$strict:true".

from moleculer-web.

ColinFrick avatar ColinFrick commented on June 20, 2024

@ekellstrand top level is $$strict. Otherwise you wouldn’t be able to add a parameter with the name strict.
See https://github.com/icebob/fastest-validator#strict-validation

from moleculer-web.

ekellstrand avatar ekellstrand commented on June 20, 2024

OK, so that gets me going.
@ColinFrick

  • I'm guessing this might be due to JS internals, but do you know it doesn't stick with "$$strict" on nested schemas?
  • Do you know if there was a conscious decision to make $$strict not affect nested schemas?
  • I wonder if I'm the only one who made a bad assumption here. Maybe it because I'm only using fastest-validator in the context on Moleculer? I guess I'm asking if this issue is still a valid feature request (either for fastest-validator, or specifically for Moleculer), to make $$strict affect nested schemas, or if this issue should get rewritten as, "Please make the docs call this out so others don't trip over a bad assumption", or if this issue just gets closed as RTFM.

from moleculer-web.

ColinFrick avatar ColinFrick commented on June 20, 2024

$$strict is only evaluated for the root schema. As far as I can tell it is the same behavior as if you have nested objects, children don't inherit the strict property from their parent either.

If you always want strict: true for object validator you can set it by default:
https://github.com/icebob/fastest-validator#default-options
https://moleculer.services/docs/0.14/validating.html#Fastest-Validator (Example with options)

I only can tell you what's in the documentation, maybe @icebob can tell you more.

from moleculer-web.

ekellstrand avatar ekellstrand commented on June 20, 2024

@ColinFrick Thank you for pointing me at the docs. The default values are new since I set this all up a few years back. I think docs are good and I'm going to close this out as "RTFM Success".

Related question: It looks like the default options handles any nested objects. Do you know if there is any config setting to handle the top level $$strict: true as a default for all actions? or is my existing Middleware function still the best bet for that? (I re-read both sets of docs but didn't see anything)

from moleculer-web.

icebob avatar icebob commented on June 20, 2024

Hi, @ColinFrick's explanation is right, no inheritance in properties, every property is evaluated on the given level and not affect the nested levels.

If you would like to add strict: true for every object rule, set it as a default option as Colin mentioned. You can do it in broker options, like:

// moleculer.config.js

module.exports = {
    validator: {
        type: "Fastest",
        options: {
            useNewCustomCheckerFunction: true,
            defaults: {
                object: {
                    strict: true
                }
            }
        }
    }
};

from moleculer-web.

ekellstrand avatar ekellstrand commented on June 20, 2024

Thanks! Closing this as RTFM.

from moleculer-web.

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.