anote-server-libs 0.6.8 → 0.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +3 -0
- package/package.json +1 -1
- package/services/WithBody.js +7 -1
- package/services/WithBody.ts +6 -1
package/package.json
CHANGED
package/services/WithBody.js
CHANGED
|
@@ -10,7 +10,7 @@ exports.ajv.addKeyword({
|
|
|
10
10
|
schemaType: 'number',
|
|
11
11
|
validate: (schema, data) => typeof data === 'number' && Math.round(data * 10 ** schema) / (10 ** schema) === data
|
|
12
12
|
});
|
|
13
|
-
function WithBody(schema) {
|
|
13
|
+
function WithBody(schema, collapseTopLevelNulls = true) {
|
|
14
14
|
if (schema.type === 'object') {
|
|
15
15
|
const required = [];
|
|
16
16
|
const keys = Object.getOwnPropertyNames(schema.properties);
|
|
@@ -41,6 +41,12 @@ function WithBody(schema) {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
|
+
if (collapseTopLevelNulls) {
|
|
45
|
+
Object.keys(req.body).forEach(k => {
|
|
46
|
+
if (req.body[k] === null)
|
|
47
|
+
delete req.body[k];
|
|
48
|
+
});
|
|
49
|
+
}
|
|
44
50
|
const valid = validate(req.body);
|
|
45
51
|
if (valid) {
|
|
46
52
|
return previousMethod.call(this, req, res);
|
package/services/WithBody.ts
CHANGED
|
@@ -9,7 +9,7 @@ ajv.addKeyword({
|
|
|
9
9
|
validate: (schema: number, data: any) => typeof data === 'number' && Math.round(data * 10 ** schema) / (10 ** schema) === data
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
export function WithBody(schema: any) {
|
|
12
|
+
export function WithBody(schema: any, collapseTopLevelNulls = true) {
|
|
13
13
|
if(schema.type === 'object') {
|
|
14
14
|
const required: string[] = [];
|
|
15
15
|
const keys = Object.getOwnPropertyNames(schema.properties);
|
|
@@ -39,6 +39,11 @@ export function WithBody(schema: any) {
|
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
} else {
|
|
42
|
+
if(collapseTopLevelNulls) {
|
|
43
|
+
Object.keys(req.body).forEach(k => {
|
|
44
|
+
if(req.body[k] === null) delete req.body[k];
|
|
45
|
+
});
|
|
46
|
+
}
|
|
42
47
|
const valid = validate(req.body);
|
|
43
48
|
if(valid) {
|
|
44
49
|
return previousMethod.call(this, req, res);
|