Comments (8)
Does it work if you add strict: true
to the address definition?
See https://github.com/icebob/fastest-validator#properties-10
from moleculer-web.
@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.
@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.
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.
$$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.
@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.
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.
Thanks! Closing this as RTFM.
from moleculer-web.
Related Issues (20)
- Q&A: How can I remove the service name from the api endpoint? HOT 6
- Could not handle the request when the request come with files and data in multipart HOT 2
- Sometime the list of REST api is missing some functions HOT 1
- multipartHandler throws unhandled error if payload is too large
- CORS Preflight Issue HOT 2
- Response headers affectation HOT 2
- Missing interface when upload file. HOT 2
- resetTime should accept function
- Undefined `actions` property in `/api/~node/services?withActions=true` causes empty REST API page HOT 1
- Route-level `mergeParams` doesn't exist for auto aliases HOT 1
- Cannot skip route with middleware HOT 1
- Improve routes priorization HOT 1
- RateLimit didn't check if trusted proxy send the header x-forwarded-for HOT 4
- REST shortcut doesn't handle action object correctly
- Typescript error: import { IParseOptions } from 'qs'
- Can we get an official interface for ctx.meta.$ fields available in moleculer-web?
- Routes with autoAliases not considered for started HOT 1
- Allow define action type in auto aliases (rest action param) HOT 2
- What is the benefit of using ctx.meta.$location & ctx.meta.$responseType vs just setting via ctx.meta.$responseHeaders? HOT 4
- update request body value in onBeforeCall hook not working HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moleculer-web.