lperrin / paperwork Goto Github PK
View Code? Open in Web Editor NEWLightweight JSON validation for node.js REST APIs
Lightweight JSON validation for node.js REST APIs
Imagine the following example:
var paperwork = require('paperwork');
var ScenarioSchemaPatch = {
title: paperwork.optional(String),
text: paperwork.optional(String)
};
var post = { text : "data", unknown_field : "foo"};
paperwork(ScenarioSchemaPatch, post, function (err, validated) {
if (err) {
console.error("Error",err);
} else {
console.log("JSON", validated);
}
});
It returns:
JSON { title: null, text: 'data' }
Why is the title
set to null, even if it was set to optional?
I have a custom validator that is asynchronous (it interfaces with the database). Is it possible to integrate said validator with paperwork? Thanks in advance.
Hello,
Is paperwork clone all objects or just when there is too much fields ?
For example if I have this schema
var schema = { age: Number };
And this data
var data = { age: 20, firstname: 'Jean' }
The output will be :
{age: 20}
So, if I well understand, you have created a new "cleaned" object during validation.
But what happened if in data there is no extra fields ? Is object also cleaned ? What is the performance cost ?
Thanks.
Just a question. How do I validate an array of objects that are required. You show in the example how to validate an array of objects that is optional, but not required. Any help would be appreciated!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.