From 071bf8edb5f87058654a743b9e0203717450b141 Mon Sep 17 00:00:00 2001 From: naz Date: Wed, 30 Sep 2020 16:25:12 +1300 Subject: [PATCH] Extracted Admin API JSON schemas into @tryghost/admin-api-schema (#12237) closes https://github.com/TryGhost/Ghost/issues/10628 - JSON Schemas were extracted into a separate module to allow other clients to reuse them (for example documentation). Having them in a separate package also slims down the amount of code needed to be maintained in the core. - Updated canary API input validators to use admin-api-schema module - Removed canary schemas that moved into admin-api-schema package - Updated v2 API input validators to use admin-api-schema package - Removed v2 schemas that moved into admin-api-schema package - Updated tests to contain needed information in apiConfig to pick up correct validation - Added @tryghost/admin-api-schema package dependency --- core/server/api/canary/members.js | 9 +- .../canary/utils/validators/input/images.js | 4 +- .../canary/utils/validators/input/labels.js | 13 +- .../canary/utils/validators/input/members.js | 13 +- .../canary/utils/validators/input/pages.js | 13 +- .../canary/utils/validators/input/posts.js | 13 +- .../input/schemas/images-upload.json | 8 - .../validators/input/schemas/images.json | 24 -- .../validators/input/schemas/labels-add.json | 23 -- .../validators/input/schemas/labels-edit.json | 18 -- .../validators/input/schemas/labels.json | 40 --- .../validators/input/schemas/members-add.json | 22 -- .../input/schemas/members-edit.json | 63 ----- .../input/schemas/members-upload.json | 49 ---- .../validators/input/schemas/members.json | 92 ------- .../validators/input/schemas/pages-add.json | 22 -- .../validators/input/schemas/pages-edit.json | 22 -- .../utils/validators/input/schemas/pages.json | 252 ----------------- .../validators/input/schemas/posts-add.json | 22 -- .../validators/input/schemas/posts-edit.json | 22 -- .../utils/validators/input/schemas/posts.json | 253 ------------------ .../validators/input/schemas/tags-add.json | 23 -- .../validators/input/schemas/tags-edit.json | 18 -- .../utils/validators/input/schemas/tags.json | 113 -------- .../input/schemas/webhooks-add.json | 21 -- .../input/schemas/webhooks-edit.json | 74 ----- .../validators/input/schemas/webhooks.json | 68 ----- .../api/canary/utils/validators/input/tags.js | 13 +- .../canary/utils/validators/input/webhooks.js | 10 +- .../validators/utils/is-lowercase-keyword.js | 15 -- .../utils/validators/utils/json-schema.js | 69 +---- .../utils/validators/utils/strip-keyword.js | 22 -- .../api/v2/utils/validators/input/images.js | 4 +- .../api/v2/utils/validators/input/pages.js | 13 +- .../api/v2/utils/validators/input/posts.js | 13 +- .../input/schemas/images-upload.json | 8 - .../validators/input/schemas/images.json | 24 -- .../validators/input/schemas/pages-add.json | 22 -- .../validators/input/schemas/pages-edit.json | 22 -- .../utils/validators/input/schemas/pages.json | 252 ----------------- .../validators/input/schemas/posts-add.json | 22 -- .../validators/input/schemas/posts-edit.json | 22 -- .../utils/validators/input/schemas/posts.json | 243 ----------------- .../validators/input/schemas/tags-add.json | 23 -- .../validators/input/schemas/tags-edit.json | 18 -- .../utils/validators/input/schemas/tags.json | 70 ----- .../api/v2/utils/validators/input/tags.js | 13 +- .../v2/utils/validators/utils/json-schema.js | 67 +---- .../utils/validators/utils/strip-keyword.js | 22 -- package.json | 1 + .../utils/validators/input/pages_spec.js | 32 +-- .../utils/validators/input/posts_spec.js | 32 +-- .../utils/validators/input/tags_spec.js | 24 +- .../utils/validators/input/webhooks_spec.js | 24 +- .../v2/utils/validators/input/pages_spec.js | 32 +-- .../v2/utils/validators/input/posts_spec.js | 32 +-- .../v2/utils/validators/input/tags_spec.js | 24 +- .../v3/utils/validators/input/pages_spec.js | 32 +-- .../v3/utils/validators/input/posts_spec.js | 32 +-- .../v3/utils/validators/input/tags_spec.js | 24 +- .../utils/validators/input/webhooks_spec.js | 24 +- yarn.lock | 10 + 62 files changed, 230 insertions(+), 2394 deletions(-) delete mode 100644 core/server/api/canary/utils/validators/input/schemas/images-upload.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/images.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/labels-add.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/labels-edit.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/labels.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/members-add.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/members-edit.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/members-upload.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/members.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/pages-add.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/pages-edit.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/pages.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/posts-add.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/posts-edit.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/posts.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/tags-add.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/tags-edit.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/tags.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/webhooks-add.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/webhooks-edit.json delete mode 100644 core/server/api/canary/utils/validators/input/schemas/webhooks.json delete mode 100644 core/server/api/canary/utils/validators/utils/is-lowercase-keyword.js delete mode 100644 core/server/api/canary/utils/validators/utils/strip-keyword.js delete mode 100644 core/server/api/v2/utils/validators/input/schemas/images-upload.json delete mode 100644 core/server/api/v2/utils/validators/input/schemas/images.json delete mode 100644 core/server/api/v2/utils/validators/input/schemas/pages-add.json delete mode 100644 core/server/api/v2/utils/validators/input/schemas/pages-edit.json delete mode 100644 core/server/api/v2/utils/validators/input/schemas/pages.json delete mode 100644 core/server/api/v2/utils/validators/input/schemas/posts-add.json delete mode 100644 core/server/api/v2/utils/validators/input/schemas/posts-edit.json delete mode 100644 core/server/api/v2/utils/validators/input/schemas/posts.json delete mode 100644 core/server/api/v2/utils/validators/input/schemas/tags-add.json delete mode 100644 core/server/api/v2/utils/validators/input/schemas/tags-edit.json delete mode 100644 core/server/api/v2/utils/validators/input/schemas/tags.json delete mode 100644 core/server/api/v2/utils/validators/utils/strip-keyword.js diff --git a/core/server/api/canary/members.js b/core/server/api/canary/members.js index b7e77f7252..348d6ec08b 100644 --- a/core/server/api/canary/members.js +++ b/core/server/api/canary/members.js @@ -32,12 +32,15 @@ const sanitizeInput = async (members) => { let invalidCount = 0; const jsonSchema = require('./utils/validators/utils/json-schema'); - const schema = require('./utils/validators/input/schemas/members-upload'); - const definitions = require('./utils/validators/input/schemas/members'); let invalidValidationCount = 0; try { - await jsonSchema.validate(schema, definitions, members); + await jsonSchema.validate({ + docName: 'members', + method: 'upload' + }, { + data: members + }); } catch (error) { if (error.errorDetails && error.errorDetails.length) { const jsonPointerIndexRegex = /\[(?\d+)\]/; diff --git a/core/server/api/canary/utils/validators/input/images.js b/core/server/api/canary/utils/validators/input/images.js index 42ed757fd2..39bf5add72 100644 --- a/core/server/api/canary/utils/validators/input/images.js +++ b/core/server/api/canary/utils/validators/input/images.js @@ -64,9 +64,7 @@ module.exports = { upload(apiConfig, frame) { return Promise.resolve() .then(() => { - const schema = require('./schemas/images-upload'); - const definitions = require('./schemas/images'); - return jsonSchema.validate(schema, definitions, frame.data); + return jsonSchema.validate(apiConfig, frame); }) .then(() => { if (frame.data.purpose === 'profile_image') { diff --git a/core/server/api/canary/utils/validators/input/labels.js b/core/server/api/canary/utils/validators/input/labels.js index ceaf709c57..b4d8cea580 100644 --- a/core/server/api/canary/utils/validators/input/labels.js +++ b/core/server/api/canary/utils/validators/input/labels.js @@ -1,15 +1,6 @@ const jsonSchema = require('../utils/json-schema'); module.exports = { - add(apiConfig, frame) { - const schema = require('./schemas/labels-add'); - const definitions = require('./schemas/labels'); - return jsonSchema.validate(schema, definitions, frame.data); - }, - - edit(apiConfig, frame) { - const schema = require('./schemas/labels-edit'); - const definitions = require('./schemas/labels'); - return jsonSchema.validate(schema, definitions, frame.data); - } + add: jsonSchema.validate, + edit: jsonSchema.validate }; diff --git a/core/server/api/canary/utils/validators/input/members.js b/core/server/api/canary/utils/validators/input/members.js index aa01b06aeb..b4d8cea580 100644 --- a/core/server/api/canary/utils/validators/input/members.js +++ b/core/server/api/canary/utils/validators/input/members.js @@ -1,15 +1,6 @@ const jsonSchema = require('../utils/json-schema'); module.exports = { - add(apiConfig, frame) { - const schema = require('./schemas/members-add'); - const definitions = require('./schemas/members'); - return jsonSchema.validate(schema, definitions, frame.data); - }, - - edit(apiConfig, frame) { - const schema = require('./schemas/members-edit'); - const definitions = require('./schemas/members'); - return jsonSchema.validate(schema, definitions, frame.data); - } + add: jsonSchema.validate, + edit: jsonSchema.validate }; diff --git a/core/server/api/canary/utils/validators/input/pages.js b/core/server/api/canary/utils/validators/input/pages.js index 91eed3b0c6..b4d8cea580 100644 --- a/core/server/api/canary/utils/validators/input/pages.js +++ b/core/server/api/canary/utils/validators/input/pages.js @@ -1,15 +1,6 @@ const jsonSchema = require('../utils/json-schema'); module.exports = { - add(apiConfig, frame) { - const schema = require(`./schemas/pages-add`); - const definitions = require('./schemas/pages'); - return jsonSchema.validate(schema, definitions, frame.data); - }, - - edit(apiConfig, frame) { - const schema = require(`./schemas/pages-edit`); - const definitions = require('./schemas/pages'); - return jsonSchema.validate(schema, definitions, frame.data); - } + add: jsonSchema.validate, + edit: jsonSchema.validate }; diff --git a/core/server/api/canary/utils/validators/input/posts.js b/core/server/api/canary/utils/validators/input/posts.js index a29df595ae..b4d8cea580 100644 --- a/core/server/api/canary/utils/validators/input/posts.js +++ b/core/server/api/canary/utils/validators/input/posts.js @@ -1,15 +1,6 @@ const jsonSchema = require('../utils/json-schema'); module.exports = { - add(apiConfig, frame) { - const schema = require(`./schemas/posts-add`); - const definitions = require('./schemas/posts'); - return jsonSchema.validate(schema, definitions, frame.data); - }, - - edit(apiConfig, frame) { - const schema = require(`./schemas/posts-edit`); - const definitions = require('./schemas/posts'); - return jsonSchema.validate(schema, definitions, frame.data); - } + add: jsonSchema.validate, + edit: jsonSchema.validate }; diff --git a/core/server/api/canary/utils/validators/input/schemas/images-upload.json b/core/server/api/canary/utils/validators/input/schemas/images-upload.json deleted file mode 100644 index e0bb341839..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/images-upload.json +++ /dev/null @@ -1,8 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "images.upload", - "title": "images.upload", - "description": "Schema for images.upload", - "$ref": "images#/definitions/image" -} diff --git a/core/server/api/canary/utils/validators/input/schemas/images.json b/core/server/api/canary/utils/validators/input/schemas/images.json deleted file mode 100644 index 0919f7b74d..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/images.json +++ /dev/null @@ -1,24 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "images", - "title": "images", - "description": "Base images definitions", - "definitions": { - "image": { - "type": "object", - "additionalProperties": false, - "properties": { - "purpose": { - "type": "string", - "enum": ["image", "profile_image", "icon"], - "default": "image" - }, - "ref": { - "type": ["string", "null"], - "maxLength": 2000 - } - } - } - } -} diff --git a/core/server/api/canary/utils/validators/input/schemas/labels-add.json b/core/server/api/canary/utils/validators/input/schemas/labels-add.json deleted file mode 100644 index 9e10bc630c..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/labels-add.json +++ /dev/null @@ -1,23 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "labels.add", - "title": "labels.add", - "description": "Schema for labels.add", - "type": "object", - "additionalProperties": false, - "properties": { - "labels": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "additionalProperties": false, - "items": { - "type": "object", - "allOf": [{"$ref": "labels#/definitions/label"}], - "required": ["name"] - } - } - }, - "required": [ "labels" ] - } diff --git a/core/server/api/canary/utils/validators/input/schemas/labels-edit.json b/core/server/api/canary/utils/validators/input/schemas/labels-edit.json deleted file mode 100644 index dde143be42..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/labels-edit.json +++ /dev/null @@ -1,18 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "labels.edit", - "title": "labels.edit", - "description": "Schema for labels.edit", - "type": "object", - "additionalProperties": false, - "properties": { - "labels": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "items": {"$ref": "labels#/definitions/label"} - } - }, - "required": [ "labels" ] - } diff --git a/core/server/api/canary/utils/validators/input/schemas/labels.json b/core/server/api/canary/utils/validators/input/schemas/labels.json deleted file mode 100644 index 525cb53c9c..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/labels.json +++ /dev/null @@ -1,40 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "labels", - "title": "labels", - "description": "Base labels definitions", - "definitions": { - "label": { - "type": "object", - "additionalProperties": false, - "properties": { - "name": { - "type": "string", - "minLength": 1, - "maxLength": 191, - "pattern": "^([^,]|$)" - }, - "slug": { - "type": ["string", "null"], - "maxLength": 191 - }, - "id": { - "strip": true - }, - "created_at": { - "strip": true - }, - "created_by": { - "strip": true - }, - "updated_at": { - "strip": true - }, - "updated_by": { - "strip": true - } - } - } - } -} diff --git a/core/server/api/canary/utils/validators/input/schemas/members-add.json b/core/server/api/canary/utils/validators/input/schemas/members-add.json deleted file mode 100644 index d6370b6595..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/members-add.json +++ /dev/null @@ -1,22 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "members.add", - "title": "members.add", - "description": "Schema for members.add", - "type": "object", - "additionalProperties": false, - "properties": { - "members": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "items": { - "type": "object", - "allOf": [{"$ref": "members#/definitions/member"}], - "required": ["email"] - } - } - }, - "required": ["members"] - } diff --git a/core/server/api/canary/utils/validators/input/schemas/members-edit.json b/core/server/api/canary/utils/validators/input/schemas/members-edit.json deleted file mode 100644 index bf0744747e..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/members-edit.json +++ /dev/null @@ -1,63 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "members.edit", - "title": "members.edit", - "description": "Schema for members.edit", - "type": "object", - "additionalProperties": false, - "properties": { - "members": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "items": { - "type": "object", - "additionalProperties": false, - "properties": { - "name": { - "type": "string", - "maxLength": 191, - "pattern": "^([^,]|$)" - }, - "email": { - "type": "string", - "minLength": 1, - "maxLength": 191, - "pattern": "^([^,]|$)" - }, - "note": { - "type": "string", - "minLength": 0, - "maxLength": 2000 - }, - "subscribed": { - "type": "boolean" - }, - "comped": { - "type": "boolean" - }, - "id": { - "strip": true - }, - "labels": { - "$ref": "members#/definitions/member-labels" - }, - "created_at": { - "strip": true - }, - "created_by": { - "strip": true - }, - "updated_at": { - "strip": true - }, - "updated_by": { - "strip": true - } - } - } - } - }, - "required": ["members"] -} diff --git a/core/server/api/canary/utils/validators/input/schemas/members-upload.json b/core/server/api/canary/utils/validators/input/schemas/members-upload.json deleted file mode 100644 index 53a9af6b7f..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/members-upload.json +++ /dev/null @@ -1,49 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "members.upload", - "title": "members.upload", - "description": "Schema for members.upload", - "type": "array", - "items": { - "type": "object", - "additionalProperties": true, - "required": ["email"], - "properties": { - "name": { - "type": ["string", "null"], - "maxLength": 191, - "pattern": "^([^,]|$)" - }, - "email": { - "type": "string", - "minLength": 1, - "maxLength": 191, - "pattern": "^([^,]|$)" - }, - "note": { - "type": ["string", "null"], - "minLength": 0, - "maxLength": 2000 - }, - "subscribed": { - "type": ["string", "null"], - "enum": ["true", "false", "TRUE", "FALSE", "", null] - }, - "labels": { - "type": ["string", "null"] - }, - "created_at": { - "type": ["string", "null"], - "format": "date-time" - }, - "stripe_customer_id": { - "type": ["string", "null"] - }, - "complimentary_plan": { - "type": ["string", "null"], - "enum": ["true", "false", "TRUE", "FALSE", "", null] - } - } - } - } diff --git a/core/server/api/canary/utils/validators/input/schemas/members.json b/core/server/api/canary/utils/validators/input/schemas/members.json deleted file mode 100644 index 32ca166b37..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/members.json +++ /dev/null @@ -1,92 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "members", - "title": "members", - "description": "Base members definitions", - "definitions": { - "member": { - "type": "object", - "additionalProperties": false, - "properties": { - "name": { - "type": "string", - "maxLength": 191, - "pattern": "^([^,]|$)" - }, - "email": { - "type": "string", - "minLength": 1, - "maxLength": 191, - "pattern": "^([^,]|$)" - }, - "avatar_image": { - "strip": true - }, - "note": { - "type": "string", - "minLength": 0, - "maxLength": 2000 - }, - "subscribed": { - "type": "boolean" - }, - "comped": { - "strip": "true" - }, - "id": { - "strip": true - }, - "labels": { - "$ref": "#/definitions/member-labels" - }, - "created_at": { - "strip": true - }, - "created_by": { - "strip": true - }, - "updated_at": { - "strip": true - }, - "updated_by": { - "strip": true - } - } - }, - "member-labels": { - "description": "Labels of the member", - "type": "array", - "items": { - "anyOf": [{ - "type": "object", - "properties": { - "id": { - "type": "string", - "maxLength": 24 - }, - "name": { - "type": "string", - "maxLength": 191 - }, - "slug": { - "type": ["string", "null"], - "maxLength": 191 - }, - "members": { - "strip": true - } - }, - "anyOf": [ - {"required": ["id"]}, - {"required": ["name"]}, - {"required": ["slug"]} - ] - }, { - "type": "string", - "maxLength": 191 - }] - } - } - } -} diff --git a/core/server/api/canary/utils/validators/input/schemas/pages-add.json b/core/server/api/canary/utils/validators/input/schemas/pages-add.json deleted file mode 100644 index 9dbef3c9a5..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/pages-add.json +++ /dev/null @@ -1,22 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "pages.add", - "title": "pages.add", - "description": "Schema for pages.add", - "type": "object", - "additionalProperties": false, - "properties": { - "pages": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "items": { - "type": "object", - "allOf": [{"$ref": "pages#/definitions/page"}], - "required": ["title"] - } - } - }, - "required": ["pages"] - } diff --git a/core/server/api/canary/utils/validators/input/schemas/pages-edit.json b/core/server/api/canary/utils/validators/input/schemas/pages-edit.json deleted file mode 100644 index 04a68ede7e..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/pages-edit.json +++ /dev/null @@ -1,22 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "pages.edit", - "title": "pages.edit", - "description": "Schema for pages.edit", - "type": "object", - "additionalProperties": false, - "properties": { - "pages": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "items": { - "type": "object", - "allOf": [{"$ref": "pages#/definitions/page"}], - "required": ["updated_at"] - } - } - }, - "required": ["pages"] - } diff --git a/core/server/api/canary/utils/validators/input/schemas/pages.json b/core/server/api/canary/utils/validators/input/schemas/pages.json deleted file mode 100644 index 46b59a882e..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/pages.json +++ /dev/null @@ -1,252 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "pages", - "title": "pages", - "description": "Base pages definitions", - "definitions": { - "page": { - "type": "object", - "additionalProperties": false, - "properties": { - "title": { - "type": "string", - "maxLength": 2000 - }, - "slug": { - "type": "string", - "maxLength": 191 - }, - "mobiledoc": { - "type": ["string", "null"], - "format": "json-string", - "maxLength": 1000000000 - }, - "html": { - "type": ["string", "null"], - "maxLength": 1000000000 - }, - "feature_image": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "featured": { - "type": "boolean" - }, - "status": { - "type": "string", - "enum": ["published", "draft", "scheduled"] - }, - "locale": { - "type": ["string", "null"], - "maxLength": 6 - }, - "visibility": { - "type": ["string", "null"], - "enum": ["public", "members", "paid"] - }, - "meta_title": { - "type": ["string", "null"], - "maxLength": 300 - }, - "meta_description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "updated_at": { - "type": ["string", "null"], - "format": "date-time" - }, - "published_at": { - "type": ["string", "null"], - "format": "date-time" - }, - "custom_excerpt": { - "type": ["string", "null"], - "maxLength": 300 - }, - "codeinjection_head": { - "type": ["string", "null"], - "maxLength": 65535 - }, - "codeinjection_foot": { - "type": ["string", "null"], - "maxLength": 65535 - }, - "og_image": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "og_title": { - "type": ["string", "null"], - "maxLength": 300 - }, - "og_description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "twitter_image": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "twitter_title": { - "type": ["string", "null"], - "maxLength": 300 - }, - "twitter_description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "custom_template": { - "type": ["string", "null"], - "maxLength": 100 - }, - "canonical_url": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "authors": { - "$ref": "#/definitions/page-authors" - }, - "tags": { - "$ref": "#/definitions/page-tags" - }, - "id": { - "strip": true - }, - "page": { - "strip": true - }, - "author": { - "strip": true - }, - "author_id": { - "strip": true - }, - "created_at": { - "strip": true - }, - "created_by": { - "strip": true - }, - "updated_by": { - "strip": true - }, - "published_by": { - "strip": true - }, - "url": { - "strip": true - }, - "primary_tag": { - "strip": true - }, - "primary_author": { - "strip": true - }, - "excerpt": { - "strip": true - }, - "plaintext": { - "strip": true - } - } - }, - "page-authors": { - "description": "Authors of the page", - "type": "array", - "items": { - "anyOf": [{ - "type": "object", - "properties": { - "id": { - "type": "string", - "maxLength": 24 - }, - "slug": { - "type": "string", - "maxLength": 191 - }, - "email": { - "type": "string", - "maxLength": 191 - }, - "roles": { - "strip": true - }, - "permissions": { - "strip": true - } - }, - "anyOf": [ - {"required": ["id"]}, - {"required": ["slug"]}, - {"required": ["email"]} - ] - }, { - "type": "string", - "maxLength": 191 - }] - } - }, - "page-tags": { - "description": "Tags of the page", - "type": "array", - "items": { - "anyOf": [{ - "type": "object", - "properties": { - "id": { - "type": "string", - "maxLength": 24 - }, - "name": { - "type": "string", - "maxLength": 191 - }, - "slug": { - "type": [ - "string", - "null" - ], - "maxLength": 191 - }, - "parent": { - "strip": true - }, - "parent_id": { - "strip": true - }, - "pages": { - "strip": true - } - }, - "anyOf": [ - { - "required": [ - "id" - ] - }, - { - "required": [ - "name" - ] - }, - { - "required": [ - "slug" - ] - } - ] - }, { - "type": "string", - "maxLength": 191 - }] - } - } - } -} diff --git a/core/server/api/canary/utils/validators/input/schemas/posts-add.json b/core/server/api/canary/utils/validators/input/schemas/posts-add.json deleted file mode 100644 index ec14731571..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/posts-add.json +++ /dev/null @@ -1,22 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "posts.add", - "title": "posts.add", - "description": "Schema for posts.add", - "type": "object", - "additionalProperties": false, - "properties": { - "posts": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "items": { - "type": "object", - "allOf": [{"$ref": "posts#/definitions/post"}], - "required": ["title"] - } - } - }, - "required": [ "posts" ] - } diff --git a/core/server/api/canary/utils/validators/input/schemas/posts-edit.json b/core/server/api/canary/utils/validators/input/schemas/posts-edit.json deleted file mode 100644 index 6315d437fa..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/posts-edit.json +++ /dev/null @@ -1,22 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "posts.edit", - "title": "posts.edit", - "description": "Schema for posts.edit", - "type": "object", - "additionalProperties": false, - "properties": { - "posts": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "items": { - "type": "object", - "allOf": [{"$ref": "posts#/definitions/post"}], - "required": ["updated_at"] - } - } - }, - "required": [ "posts" ] - } diff --git a/core/server/api/canary/utils/validators/input/schemas/posts.json b/core/server/api/canary/utils/validators/input/schemas/posts.json deleted file mode 100644 index a34db4884c..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/posts.json +++ /dev/null @@ -1,253 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "posts", - "title": "posts", - "description": "Base posts definitions", - "definitions": { - "post": { - "type": "object", - "additionalProperties": false, - "properties": { - "title": { - "type": "string", - "maxLength": 2000 - }, - "slug": { - "type": "string", - "maxLength": 191 - }, - "mobiledoc": { - "type": ["string", "null"], - "format": "json-string", - "maxLength": 1000000000 - }, - "html": { - "type": ["string", "null"], - "maxLength": 1000000000 - }, - "feature_image": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "featured": { - "type": "boolean" - }, - "status": { - "type": "string", - "enum": ["published", "draft", "scheduled"] - }, - "locale": { - "type": ["string", "null"], - "maxLength": 6 - }, - "visibility": { - "type": ["string", "null"], - "enum": ["public", "members", "paid"] - }, - "meta_title": { - "type": ["string", "null"], - "maxLength": 300 - }, - "meta_description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "updated_at": { - "type": ["string", "null"], - "format": "date-time" - }, - "published_at": { - "type": ["string", "null"], - "format": "date-time" - }, - "custom_excerpt": { - "type": ["string", "null"], - "maxLength": 300 - }, - "codeinjection_head": { - "type": ["string", "null"], - "maxLength": 65535 - }, - "codeinjection_foot": { - "type": ["string", "null"], - "maxLength": 65535 - }, - "og_image": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "og_title": { - "type": ["string", "null"], - "maxLength": 300 - }, - "og_description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "twitter_image": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "twitter_title": { - "type": ["string", "null"], - "maxLength": 300 - }, - "twitter_description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "email_subject": { - "type": ["string", "null"], - "maxLength": 300 - }, - "custom_template": { - "type": ["string", "null"], - "maxLength": 100 - }, - "canonical_url": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "authors": { - "$ref": "#/definitions/post-authors" - }, - "tags": { - "$ref": "#/definitions/post-tags" - }, - "id": { - "strip": true - }, - "uuid": { - "strip": true - }, - "comment_id": { - "strip": true - }, - "author": { - "strip": true - }, - "author_id": { - "strip": true - }, - "page": { - "strip": true - }, - "created_at": { - "strip": true - }, - "created_by": { - "strip": true - }, - "updated_by": { - "strip": true - }, - "published_by": { - "strip": true - }, - "url": { - "strip": true - }, - "primary_tag": { - "strip": true - }, - "primary_author": { - "strip": true - }, - "excerpt": { - "strip": true - }, - "plaintext": { - "strip": true - }, - "email": { - "strip": true - }, - "send_email_when_published": { - "strip": true - } - } - }, - "post-authors": { - "description": "Authors of the post", - "type": "array", - "items": { - "anyOf": [{ - "type": "object", - "properties": { - "id": { - "type": "string", - "maxLength": 24 - }, - "slug": { - "type": "string", - "maxLength": 191 - }, - "email": { - "type": "string", - "maxLength": 191 - }, - "roles": { - "strip": true - }, - "permissions": { - "strip": true - } - }, - "anyOf": [ - {"required": ["id"]}, - {"required": ["slug"]}, - {"required": ["email"]} - ] - }, { - "type": "string", - "maxLength": 191 - }] - } - }, - "post-tags": { - "description": "Tags of the post", - "type": "array", - "items": { - "anyOf": [{ - "type": "object", - "properties": { - "id": { - "type": "string", - "maxLength": 24 - }, - "name": { - "type": "string", - "maxLength": 191 - }, - "slug": { - "type": ["string", "null"], - "maxLength": 191 - }, - "parent": { - "strip": true - }, - "parent_id": { - "strip": true - }, - "posts": { - "strip": true - } - }, - "anyOf": [ - {"required": ["id"]}, - {"required": ["name"]}, - {"required": ["slug"]} - ] - }, { - "type": "string", - "maxLength": 191 - }] - } - } - } -} diff --git a/core/server/api/canary/utils/validators/input/schemas/tags-add.json b/core/server/api/canary/utils/validators/input/schemas/tags-add.json deleted file mode 100644 index 21801cc0f8..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/tags-add.json +++ /dev/null @@ -1,23 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "tags.add", - "title": "tags.add", - "description": "Schema for tags.add", - "type": "object", - "additionalProperties": false, - "properties": { - "tags": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "additionalProperties": false, - "items": { - "type": "object", - "allOf": [{"$ref": "tags#/definitions/tag"}], - "required": ["name"] - } - } - }, - "required": [ "tags" ] - } diff --git a/core/server/api/canary/utils/validators/input/schemas/tags-edit.json b/core/server/api/canary/utils/validators/input/schemas/tags-edit.json deleted file mode 100644 index 82926cc443..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/tags-edit.json +++ /dev/null @@ -1,18 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "tags.edit", - "title": "tags.edit", - "description": "Schema for tags.edit", - "type": "object", - "additionalProperties": false, - "properties": { - "tags": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "items": {"$ref": "tags#/definitions/tag"} - } - }, - "required": [ "tags" ] - } diff --git a/core/server/api/canary/utils/validators/input/schemas/tags.json b/core/server/api/canary/utils/validators/input/schemas/tags.json deleted file mode 100644 index e4ac6b80e9..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/tags.json +++ /dev/null @@ -1,113 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "tags", - "title": "tags", - "description": "Base tags definitions", - "definitions": { - "tag": { - "type": "object", - "additionalProperties": false, - "properties": { - "name": { - "type": "string", - "minLength": 1, - "maxLength": 191, - "pattern": "^([^,]|$)" - }, - "slug": { - "type": ["string", "null"], - "maxLength": 191 - }, - "description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "feature_image": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "visibility": { - "type": "string", - "enum": ["public", "internal"] - }, - "meta_title": { - "type": ["string", "null"], - "maxLength": 300 - }, - "meta_description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "og_image": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "og_title": { - "type": ["string", "null"], - "maxLength": 300 - }, - "og_description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "twitter_image": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "twitter_title": { - "type": ["string", "null"], - "maxLength": 300 - }, - "twitter_description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "codeinjection_head": { - "type": ["string", "null"], - "maxLength": 65535 - }, - "codeinjection_foot": { - "type": ["string", "null"], - "maxLength": 65535 - }, - "canonical_url": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "accent_color": { - "type": ["string", "null"], - "maxLength": 50 - }, - "id": { - "strip": true - }, - "parent": { - "strip": true - }, - "parent_id": { - "strip": true - }, - "created_at": { - "strip": true - }, - "created_by": { - "strip": true - }, - "updated_at": { - "strip": true - }, - "updated_by": { - "strip": true - }, - "url": { - "strip": true - } - } - } - } -} diff --git a/core/server/api/canary/utils/validators/input/schemas/webhooks-add.json b/core/server/api/canary/utils/validators/input/schemas/webhooks-add.json deleted file mode 100644 index e1f3c82bc9..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/webhooks-add.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "webhooks.add", - "title": "webhooks.add", - "description": "Schema for webhooks.add", - "type": "object", - "additionalProperties": false, - "properties": { - "webhooks": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "items": { - "type": "object", - "allOf": [{"$ref": "webhooks#/definitions/webhook"}], - "required": ["event", "target_url"] - } - } - }, - "required": ["webhooks"] -} diff --git a/core/server/api/canary/utils/validators/input/schemas/webhooks-edit.json b/core/server/api/canary/utils/validators/input/schemas/webhooks-edit.json deleted file mode 100644 index bddc906e49..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/webhooks-edit.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "webhooks.edit", - "title": "webhooks.edit", - "description": "Schema for webhooks.edit", - "type": "object", - "additionalProperties": false, - "properties": { - "webhooks": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "items": { - "type": "object", - "additionalProperties": false, - "properties": { - "event": { - "type": "string", - "maxLength": 50, - "isLowercase": true - }, - "target_url": { - "type": "string", - "format": "uri-reference", - "maxLength": 2000 - }, - "name": { - "type": ["string", "null"], - "maxLength": 191 - }, - "secret": { - "type": ["string", "null"], - "maxLength": 191 - }, - "api_version": { - "type": ["string", "null"], - "maxLength": 50 - }, - "integration_id": { - "strip": true - }, - "id": { - "strip": true - }, - "status": { - "strip": true - }, - "last_triggered_at": { - "strip": true - }, - "last_triggered_status": { - "strip": true - }, - "last_triggered_error": { - "strip": true - }, - "created_at": { - "strip": true - }, - "created_by": { - "strip": true - }, - "updated_at": { - "strip": true - }, - "updated_by": { - "strip": true - } - } - } - } - }, - "required": ["webhooks"] -} diff --git a/core/server/api/canary/utils/validators/input/schemas/webhooks.json b/core/server/api/canary/utils/validators/input/schemas/webhooks.json deleted file mode 100644 index a30af2001e..0000000000 --- a/core/server/api/canary/utils/validators/input/schemas/webhooks.json +++ /dev/null @@ -1,68 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "webhooks", - "title": "webhooks", - "description": "Base webhooks definitions", - "definitions": { - "webhook": { - "type": "object", - "additionalProperties": false, - "properties": { - "event": { - "type": "string", - "maxLength": 50, - "isLowercase": true - }, - "target_url": { - "type": "string", - "format": "uri-reference", - "maxLength": 2000 - }, - "name": { - "type": ["string", "null"], - "maxLength": 191 - }, - "secret": { - "type": ["string", "null"], - "maxLength": 191 - }, - "api_version": { - "type": ["string", "null"], - "maxLength": 50 - }, - "integration_id": { - "type": ["string", "null"], - "maxLength": 24 - }, - "id": { - "strip": true - }, - "status": { - "strip": true - }, - "last_triggered_at": { - "strip": true - }, - "last_triggered_status": { - "strip": true - }, - "last_triggered_error": { - "strip": true - }, - "created_at": { - "strip": true - }, - "created_by": { - "strip": true - }, - "updated_at": { - "strip": true - }, - "updated_by": { - "strip": true - } - } - } - } -} diff --git a/core/server/api/canary/utils/validators/input/tags.js b/core/server/api/canary/utils/validators/input/tags.js index 3f66d2195b..b4d8cea580 100644 --- a/core/server/api/canary/utils/validators/input/tags.js +++ b/core/server/api/canary/utils/validators/input/tags.js @@ -1,15 +1,6 @@ const jsonSchema = require('../utils/json-schema'); module.exports = { - add(apiConfig, frame) { - const schema = require('./schemas/tags-add'); - const definitions = require('./schemas/tags'); - return jsonSchema.validate(schema, definitions, frame.data); - }, - - edit(apiConfig, frame) { - const schema = require('./schemas/tags-edit'); - const definitions = require('./schemas/tags'); - return jsonSchema.validate(schema, definitions, frame.data); - } + add: jsonSchema.validate, + edit: jsonSchema.validate }; diff --git a/core/server/api/canary/utils/validators/input/webhooks.js b/core/server/api/canary/utils/validators/input/webhooks.js index fc0fa2264f..28d3618ffa 100644 --- a/core/server/api/canary/utils/validators/input/webhooks.js +++ b/core/server/api/canary/utils/validators/input/webhooks.js @@ -15,14 +15,8 @@ module.exports = { })); } - const schema = require('./schemas/webhooks-add'); - const definitions = require('./schemas/webhooks'); - return jsonSchema.validate(schema, definitions, frame.data); + return jsonSchema.validate(apiConfig, frame); }, - edit(apiConfig, frame) { - const schema = require('./schemas/webhooks-edit'); - const definitions = require('./schemas/webhooks'); - return jsonSchema.validate(schema, definitions, frame.data); - } + edit: jsonSchema.validate }; diff --git a/core/server/api/canary/utils/validators/utils/is-lowercase-keyword.js b/core/server/api/canary/utils/validators/utils/is-lowercase-keyword.js deleted file mode 100644 index 032a1310e4..0000000000 --- a/core/server/api/canary/utils/validators/utils/is-lowercase-keyword.js +++ /dev/null @@ -1,15 +0,0 @@ -module.exports = function defFunc(ajv) { - defFunc.definition = { - errors: false, - validate: function (schema, data) { - if (data) { - return data === data.toLowerCase(); - } - - return true; - } - }; - - ajv.addKeyword('isLowercase', defFunc.definition); - return ajv; -}; diff --git a/core/server/api/canary/utils/validators/utils/json-schema.js b/core/server/api/canary/utils/validators/utils/json-schema.js index 90729a3562..a587a44045 100644 --- a/core/server/api/canary/utils/validators/utils/json-schema.js +++ b/core/server/api/canary/utils/validators/utils/json-schema.js @@ -1,60 +1,17 @@ -const _ = require('lodash'); -const Ajv = require('ajv'); -const stripKeyword = require('./strip-keyword'); -const isLowercaseKeyword = require('./is-lowercase-keyword'); -const {i18n} = require('../../../../../lib/common'); -const errors = require('@tryghost/errors'); +const jsonSchema = require('@tryghost/admin-api-schema'); -const ajv = new Ajv({ - allErrors: true, - useDefaults: true, - formats: { - 'json-string': (data) => { - try { - JSON.parse(data); - return true; - } catch (e) { - return false; - } - } - } +/** + * + * @param {Object} apiConfig "frame" api configruation object + * @param {string} apiConfig.docName the name of the resource + * @param {string} apiConfig.method API's method name + * @param {Object} frame "frame" object with data attached to it + * @param {Object} frame.data request data to validate + */ +const validate = async (apiConfig, frame) => await jsonSchema.validate({ + data: frame.data, + schema: `${apiConfig.docName}-${apiConfig.method}`, + version: 'canary' }); -stripKeyword(ajv); -isLowercaseKeyword(ajv); - -const getValidation = (schema, def) => { - if (!ajv.getSchema(def.$id)) { - ajv.addSchema(def); - } - return ajv.getSchema(schema.$id) || ajv.compile(schema); -}; - -const validate = (schema, definition, data) => { - const validation = getValidation(schema, definition); - - validation(data); - - if (validation.errors) { - let key; - const dataPath = _.get(validation, 'errors[0].dataPath'); - - if (dataPath) { - key = dataPath.split('.').pop(); - } else { - key = schema.$id.split('.')[0]; - } - - return Promise.reject(new errors.ValidationError({ - message: i18n.t('notices.data.validation.index.schemaValidationFailed', { - key: key - }), - property: key, - errorDetails: validation.errors - })); - } - - return Promise.resolve(); -}; - module.exports.validate = validate; diff --git a/core/server/api/canary/utils/validators/utils/strip-keyword.js b/core/server/api/canary/utils/validators/utils/strip-keyword.js deleted file mode 100644 index 3962d68ffe..0000000000 --- a/core/server/api/canary/utils/validators/utils/strip-keyword.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * 'strip' keyword is introduced into schemas for following behavior: - * properties that are 'known' but should not be present in the model - * should be stripped from data and not throw validation errors. - * - * An example of such property is `tag.parent` which we want to ignore - * but not necessarily throw a validation error as it was present in - * responses in previous versions of API - */ -module.exports = function defFunc(ajv) { - defFunc.definition = { - errors: false, - modifying: true, - valid: true, - validate: function (schema, data, parentSchema, dataPath, parentData, propName) { - delete parentData[propName]; - } - }; - - ajv.addKeyword('strip', defFunc.definition); - return ajv; -}; diff --git a/core/server/api/v2/utils/validators/input/images.js b/core/server/api/v2/utils/validators/input/images.js index 42ed757fd2..39bf5add72 100644 --- a/core/server/api/v2/utils/validators/input/images.js +++ b/core/server/api/v2/utils/validators/input/images.js @@ -64,9 +64,7 @@ module.exports = { upload(apiConfig, frame) { return Promise.resolve() .then(() => { - const schema = require('./schemas/images-upload'); - const definitions = require('./schemas/images'); - return jsonSchema.validate(schema, definitions, frame.data); + return jsonSchema.validate(apiConfig, frame); }) .then(() => { if (frame.data.purpose === 'profile_image') { diff --git a/core/server/api/v2/utils/validators/input/pages.js b/core/server/api/v2/utils/validators/input/pages.js index 91eed3b0c6..b4d8cea580 100644 --- a/core/server/api/v2/utils/validators/input/pages.js +++ b/core/server/api/v2/utils/validators/input/pages.js @@ -1,15 +1,6 @@ const jsonSchema = require('../utils/json-schema'); module.exports = { - add(apiConfig, frame) { - const schema = require(`./schemas/pages-add`); - const definitions = require('./schemas/pages'); - return jsonSchema.validate(schema, definitions, frame.data); - }, - - edit(apiConfig, frame) { - const schema = require(`./schemas/pages-edit`); - const definitions = require('./schemas/pages'); - return jsonSchema.validate(schema, definitions, frame.data); - } + add: jsonSchema.validate, + edit: jsonSchema.validate }; diff --git a/core/server/api/v2/utils/validators/input/posts.js b/core/server/api/v2/utils/validators/input/posts.js index a29df595ae..b4d8cea580 100644 --- a/core/server/api/v2/utils/validators/input/posts.js +++ b/core/server/api/v2/utils/validators/input/posts.js @@ -1,15 +1,6 @@ const jsonSchema = require('../utils/json-schema'); module.exports = { - add(apiConfig, frame) { - const schema = require(`./schemas/posts-add`); - const definitions = require('./schemas/posts'); - return jsonSchema.validate(schema, definitions, frame.data); - }, - - edit(apiConfig, frame) { - const schema = require(`./schemas/posts-edit`); - const definitions = require('./schemas/posts'); - return jsonSchema.validate(schema, definitions, frame.data); - } + add: jsonSchema.validate, + edit: jsonSchema.validate }; diff --git a/core/server/api/v2/utils/validators/input/schemas/images-upload.json b/core/server/api/v2/utils/validators/input/schemas/images-upload.json deleted file mode 100644 index e0bb341839..0000000000 --- a/core/server/api/v2/utils/validators/input/schemas/images-upload.json +++ /dev/null @@ -1,8 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "images.upload", - "title": "images.upload", - "description": "Schema for images.upload", - "$ref": "images#/definitions/image" -} diff --git a/core/server/api/v2/utils/validators/input/schemas/images.json b/core/server/api/v2/utils/validators/input/schemas/images.json deleted file mode 100644 index 0919f7b74d..0000000000 --- a/core/server/api/v2/utils/validators/input/schemas/images.json +++ /dev/null @@ -1,24 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "images", - "title": "images", - "description": "Base images definitions", - "definitions": { - "image": { - "type": "object", - "additionalProperties": false, - "properties": { - "purpose": { - "type": "string", - "enum": ["image", "profile_image", "icon"], - "default": "image" - }, - "ref": { - "type": ["string", "null"], - "maxLength": 2000 - } - } - } - } -} diff --git a/core/server/api/v2/utils/validators/input/schemas/pages-add.json b/core/server/api/v2/utils/validators/input/schemas/pages-add.json deleted file mode 100644 index 9dbef3c9a5..0000000000 --- a/core/server/api/v2/utils/validators/input/schemas/pages-add.json +++ /dev/null @@ -1,22 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "pages.add", - "title": "pages.add", - "description": "Schema for pages.add", - "type": "object", - "additionalProperties": false, - "properties": { - "pages": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "items": { - "type": "object", - "allOf": [{"$ref": "pages#/definitions/page"}], - "required": ["title"] - } - } - }, - "required": ["pages"] - } diff --git a/core/server/api/v2/utils/validators/input/schemas/pages-edit.json b/core/server/api/v2/utils/validators/input/schemas/pages-edit.json deleted file mode 100644 index 04a68ede7e..0000000000 --- a/core/server/api/v2/utils/validators/input/schemas/pages-edit.json +++ /dev/null @@ -1,22 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "pages.edit", - "title": "pages.edit", - "description": "Schema for pages.edit", - "type": "object", - "additionalProperties": false, - "properties": { - "pages": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "items": { - "type": "object", - "allOf": [{"$ref": "pages#/definitions/page"}], - "required": ["updated_at"] - } - } - }, - "required": ["pages"] - } diff --git a/core/server/api/v2/utils/validators/input/schemas/pages.json b/core/server/api/v2/utils/validators/input/schemas/pages.json deleted file mode 100644 index 46b59a882e..0000000000 --- a/core/server/api/v2/utils/validators/input/schemas/pages.json +++ /dev/null @@ -1,252 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "pages", - "title": "pages", - "description": "Base pages definitions", - "definitions": { - "page": { - "type": "object", - "additionalProperties": false, - "properties": { - "title": { - "type": "string", - "maxLength": 2000 - }, - "slug": { - "type": "string", - "maxLength": 191 - }, - "mobiledoc": { - "type": ["string", "null"], - "format": "json-string", - "maxLength": 1000000000 - }, - "html": { - "type": ["string", "null"], - "maxLength": 1000000000 - }, - "feature_image": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "featured": { - "type": "boolean" - }, - "status": { - "type": "string", - "enum": ["published", "draft", "scheduled"] - }, - "locale": { - "type": ["string", "null"], - "maxLength": 6 - }, - "visibility": { - "type": ["string", "null"], - "enum": ["public", "members", "paid"] - }, - "meta_title": { - "type": ["string", "null"], - "maxLength": 300 - }, - "meta_description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "updated_at": { - "type": ["string", "null"], - "format": "date-time" - }, - "published_at": { - "type": ["string", "null"], - "format": "date-time" - }, - "custom_excerpt": { - "type": ["string", "null"], - "maxLength": 300 - }, - "codeinjection_head": { - "type": ["string", "null"], - "maxLength": 65535 - }, - "codeinjection_foot": { - "type": ["string", "null"], - "maxLength": 65535 - }, - "og_image": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "og_title": { - "type": ["string", "null"], - "maxLength": 300 - }, - "og_description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "twitter_image": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "twitter_title": { - "type": ["string", "null"], - "maxLength": 300 - }, - "twitter_description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "custom_template": { - "type": ["string", "null"], - "maxLength": 100 - }, - "canonical_url": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "authors": { - "$ref": "#/definitions/page-authors" - }, - "tags": { - "$ref": "#/definitions/page-tags" - }, - "id": { - "strip": true - }, - "page": { - "strip": true - }, - "author": { - "strip": true - }, - "author_id": { - "strip": true - }, - "created_at": { - "strip": true - }, - "created_by": { - "strip": true - }, - "updated_by": { - "strip": true - }, - "published_by": { - "strip": true - }, - "url": { - "strip": true - }, - "primary_tag": { - "strip": true - }, - "primary_author": { - "strip": true - }, - "excerpt": { - "strip": true - }, - "plaintext": { - "strip": true - } - } - }, - "page-authors": { - "description": "Authors of the page", - "type": "array", - "items": { - "anyOf": [{ - "type": "object", - "properties": { - "id": { - "type": "string", - "maxLength": 24 - }, - "slug": { - "type": "string", - "maxLength": 191 - }, - "email": { - "type": "string", - "maxLength": 191 - }, - "roles": { - "strip": true - }, - "permissions": { - "strip": true - } - }, - "anyOf": [ - {"required": ["id"]}, - {"required": ["slug"]}, - {"required": ["email"]} - ] - }, { - "type": "string", - "maxLength": 191 - }] - } - }, - "page-tags": { - "description": "Tags of the page", - "type": "array", - "items": { - "anyOf": [{ - "type": "object", - "properties": { - "id": { - "type": "string", - "maxLength": 24 - }, - "name": { - "type": "string", - "maxLength": 191 - }, - "slug": { - "type": [ - "string", - "null" - ], - "maxLength": 191 - }, - "parent": { - "strip": true - }, - "parent_id": { - "strip": true - }, - "pages": { - "strip": true - } - }, - "anyOf": [ - { - "required": [ - "id" - ] - }, - { - "required": [ - "name" - ] - }, - { - "required": [ - "slug" - ] - } - ] - }, { - "type": "string", - "maxLength": 191 - }] - } - } - } -} diff --git a/core/server/api/v2/utils/validators/input/schemas/posts-add.json b/core/server/api/v2/utils/validators/input/schemas/posts-add.json deleted file mode 100644 index ec14731571..0000000000 --- a/core/server/api/v2/utils/validators/input/schemas/posts-add.json +++ /dev/null @@ -1,22 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "posts.add", - "title": "posts.add", - "description": "Schema for posts.add", - "type": "object", - "additionalProperties": false, - "properties": { - "posts": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "items": { - "type": "object", - "allOf": [{"$ref": "posts#/definitions/post"}], - "required": ["title"] - } - } - }, - "required": [ "posts" ] - } diff --git a/core/server/api/v2/utils/validators/input/schemas/posts-edit.json b/core/server/api/v2/utils/validators/input/schemas/posts-edit.json deleted file mode 100644 index 6315d437fa..0000000000 --- a/core/server/api/v2/utils/validators/input/schemas/posts-edit.json +++ /dev/null @@ -1,22 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "posts.edit", - "title": "posts.edit", - "description": "Schema for posts.edit", - "type": "object", - "additionalProperties": false, - "properties": { - "posts": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "items": { - "type": "object", - "allOf": [{"$ref": "posts#/definitions/post"}], - "required": ["updated_at"] - } - } - }, - "required": [ "posts" ] - } diff --git a/core/server/api/v2/utils/validators/input/schemas/posts.json b/core/server/api/v2/utils/validators/input/schemas/posts.json deleted file mode 100644 index 6c27253957..0000000000 --- a/core/server/api/v2/utils/validators/input/schemas/posts.json +++ /dev/null @@ -1,243 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "posts", - "title": "posts", - "description": "Base posts definitions", - "definitions": { - "post": { - "type": "object", - "additionalProperties": false, - "properties": { - "title": { - "type": "string", - "maxLength": 2000 - }, - "slug": { - "type": "string", - "maxLength": 191 - }, - "mobiledoc": { - "type": ["string", "null"], - "format": "json-string", - "maxLength": 1000000000 - }, - "html": { - "type": ["string", "null"], - "maxLength": 1000000000 - }, - "feature_image": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "featured": { - "type": "boolean" - }, - "status": { - "type": "string", - "enum": ["published", "draft", "scheduled"] - }, - "locale": { - "type": ["string", "null"], - "maxLength": 6 - }, - "visibility": { - "type": ["string", "null"], - "enum": ["public", "members", "paid"] - }, - "meta_title": { - "type": ["string", "null"], - "maxLength": 300 - }, - "meta_description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "updated_at": { - "type": ["string", "null"], - "format": "date-time" - }, - "published_at": { - "type": ["string", "null"], - "format": "date-time" - }, - "custom_excerpt": { - "type": ["string", "null"], - "maxLength": 300 - }, - "codeinjection_head": { - "type": ["string", "null"], - "maxLength": 65535 - }, - "codeinjection_foot": { - "type": ["string", "null"], - "maxLength": 65535 - }, - "og_image": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "og_title": { - "type": ["string", "null"], - "maxLength": 300 - }, - "og_description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "twitter_image": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "twitter_title": { - "type": ["string", "null"], - "maxLength": 300 - }, - "twitter_description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "custom_template": { - "type": ["string", "null"], - "maxLength": 100 - }, - "canonical_url": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "authors": { - "$ref": "#/definitions/post-authors" - }, - "tags": { - "$ref": "#/definitions/post-tags" - }, - "id": { - "strip": true - }, - "uuid": { - "strip": true - }, - "comment_id": { - "strip": true - }, - "author": { - "strip": true - }, - "author_id": { - "strip": true - }, - "page": { - "strip": true - }, - "created_at": { - "strip": true - }, - "created_by": { - "strip": true - }, - "updated_by": { - "strip": true - }, - "published_by": { - "strip": true - }, - "url": { - "strip": true - }, - "primary_tag": { - "strip": true - }, - "primary_author": { - "strip": true - }, - "excerpt": { - "strip": true - }, - "plaintext": { - "strip": true - } - } - }, - "post-authors": { - "description": "Authors of the post", - "type": "array", - "items": { - "anyOf": [{ - "type": "object", - "properties": { - "id": { - "type": "string", - "maxLength": 24 - }, - "slug": { - "type": "string", - "maxLength": 191 - }, - "email": { - "type": "string", - "maxLength": 191 - }, - "roles": { - "strip": true - }, - "permissions": { - "strip": true - } - }, - "anyOf": [ - {"required": ["id"]}, - {"required": ["slug"]}, - {"required": ["email"]} - ] - }, { - "type": "string", - "maxLength": 191 - }] - } - }, - "post-tags": { - "description": "Tags of the post", - "type": "array", - "items": { - "anyOf": [{ - "type": "object", - "properties": { - "id": { - "type": "string", - "maxLength": 24 - }, - "name": { - "type": "string", - "maxLength": 191 - }, - "slug": { - "type": ["string", "null"], - "maxLength": 191 - }, - "parent": { - "strip": true - }, - "parent_id": { - "strip": true - }, - "posts": { - "strip": true - } - }, - "anyOf": [ - {"required": ["id"]}, - {"required": ["name"]}, - {"required": ["slug"]} - ] - }, { - "type": "string", - "maxLength": 191 - }] - } - } - } -} diff --git a/core/server/api/v2/utils/validators/input/schemas/tags-add.json b/core/server/api/v2/utils/validators/input/schemas/tags-add.json deleted file mode 100644 index 21801cc0f8..0000000000 --- a/core/server/api/v2/utils/validators/input/schemas/tags-add.json +++ /dev/null @@ -1,23 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "tags.add", - "title": "tags.add", - "description": "Schema for tags.add", - "type": "object", - "additionalProperties": false, - "properties": { - "tags": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "additionalProperties": false, - "items": { - "type": "object", - "allOf": [{"$ref": "tags#/definitions/tag"}], - "required": ["name"] - } - } - }, - "required": [ "tags" ] - } diff --git a/core/server/api/v2/utils/validators/input/schemas/tags-edit.json b/core/server/api/v2/utils/validators/input/schemas/tags-edit.json deleted file mode 100644 index 82926cc443..0000000000 --- a/core/server/api/v2/utils/validators/input/schemas/tags-edit.json +++ /dev/null @@ -1,18 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "tags.edit", - "title": "tags.edit", - "description": "Schema for tags.edit", - "type": "object", - "additionalProperties": false, - "properties": { - "tags": { - "type": "array", - "minItems": 1, - "maxItems": 1, - "items": {"$ref": "tags#/definitions/tag"} - } - }, - "required": [ "tags" ] - } diff --git a/core/server/api/v2/utils/validators/input/schemas/tags.json b/core/server/api/v2/utils/validators/input/schemas/tags.json deleted file mode 100644 index 0684899728..0000000000 --- a/core/server/api/v2/utils/validators/input/schemas/tags.json +++ /dev/null @@ -1,70 +0,0 @@ - -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "tags", - "title": "tags", - "description": "Base tags definitions", - "definitions": { - "tag": { - "type": "object", - "additionalProperties": false, - "properties": { - "name": { - "type": "string", - "minLength": 1, - "maxLength": 191, - "pattern": "^([^,]|$)" - }, - "slug": { - "type": ["string", "null"], - "maxLength": 191 - }, - "description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "feature_image": { - "type": ["string", "null"], - "format": "uri-reference", - "maxLength": 2000 - }, - "visibility": { - "type": "string", - "enum": ["public", "internal"] - }, - "meta_title": { - "type": ["string", "null"], - "maxLength": 300 - }, - "meta_description": { - "type": ["string", "null"], - "maxLength": 500 - }, - "id": { - "strip": true - }, - "parent": { - "strip": true - }, - "parent_id": { - "strip": true - }, - "created_at": { - "strip": true - }, - "created_by": { - "strip": true - }, - "updated_at": { - "strip": true - }, - "updated_by": { - "strip": true - }, - "url": { - "strip": true - } - } - } - } -} diff --git a/core/server/api/v2/utils/validators/input/tags.js b/core/server/api/v2/utils/validators/input/tags.js index 3f66d2195b..b4d8cea580 100644 --- a/core/server/api/v2/utils/validators/input/tags.js +++ b/core/server/api/v2/utils/validators/input/tags.js @@ -1,15 +1,6 @@ const jsonSchema = require('../utils/json-schema'); module.exports = { - add(apiConfig, frame) { - const schema = require('./schemas/tags-add'); - const definitions = require('./schemas/tags'); - return jsonSchema.validate(schema, definitions, frame.data); - }, - - edit(apiConfig, frame) { - const schema = require('./schemas/tags-edit'); - const definitions = require('./schemas/tags'); - return jsonSchema.validate(schema, definitions, frame.data); - } + add: jsonSchema.validate, + edit: jsonSchema.validate }; diff --git a/core/server/api/v2/utils/validators/utils/json-schema.js b/core/server/api/v2/utils/validators/utils/json-schema.js index ad0065c785..e95144bdee 100644 --- a/core/server/api/v2/utils/validators/utils/json-schema.js +++ b/core/server/api/v2/utils/validators/utils/json-schema.js @@ -1,58 +1,17 @@ -const _ = require('lodash'); -const Ajv = require('ajv'); -const stripKeyword = require('./strip-keyword'); -const {i18n} = require('../../../../../lib/common'); -const errors = require('@tryghost/errors'); +const jsonSchema = require('@tryghost/admin-api-schema'); -const ajv = new Ajv({ - allErrors: true, - useDefaults: true, - formats: { - 'json-string': (data) => { - try { - JSON.parse(data); - return true; - } catch (e) { - return false; - } - } - } +/** + * + * @param {Object} apiConfig "frame" api configruation object + * @param {string} apiConfig.docName the name of the resource + * @param {string} apiConfig.method API's method name + * @param {Object} frame "frame" object with data attached to it + * @param {Object} frame.data request data to validate + */ +const validate = async (apiConfig, frame) => await jsonSchema.validate({ + data: frame.data, + schema: `${apiConfig.docName}-${apiConfig.method}`, + version: 'v2' }); -stripKeyword(ajv); - -const getValidation = (schema, def) => { - if (!ajv.getSchema(def.$id)) { - ajv.addSchema(def); - } - return ajv.getSchema(schema.$id) || ajv.compile(schema); -}; - -const validate = (schema, definition, data) => { - const validation = getValidation(schema, definition); - - validation(data); - - if (validation.errors) { - let key; - const dataPath = _.get(validation, 'errors[0].dataPath'); - - if (dataPath) { - key = dataPath.split('.').pop(); - } else { - key = schema.$id.split('.')[0]; - } - - return Promise.reject(new errors.ValidationError({ - message: i18n.t('notices.data.validation.index.schemaValidationFailed', { - key: key - }), - property: key, - errorDetails: validation.errors - })); - } - - return Promise.resolve(); -}; - module.exports.validate = validate; diff --git a/core/server/api/v2/utils/validators/utils/strip-keyword.js b/core/server/api/v2/utils/validators/utils/strip-keyword.js deleted file mode 100644 index 3962d68ffe..0000000000 --- a/core/server/api/v2/utils/validators/utils/strip-keyword.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * 'strip' keyword is introduced into schemas for following behavior: - * properties that are 'known' but should not be present in the model - * should be stripped from data and not throw validation errors. - * - * An example of such property is `tag.parent` which we want to ignore - * but not necessarily throw a validation error as it was present in - * responses in previous versions of API - */ -module.exports = function defFunc(ajv) { - defFunc.definition = { - errors: false, - modifying: true, - valid: true, - validate: function (schema, data, parentSchema, dataPath, parentData, propName) { - delete parentData[propName]; - } - }; - - ajv.addKeyword('strip', defFunc.definition); - return ajv; -}; diff --git a/package.json b/package.json index afab510c0f..f1269f1a7d 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "@nexes/nql": "0.4.0", "@sentry/node": "5.24.2", "@tryghost/adapter-manager": "0.1.11", + "@tryghost/admin-api-schema": "1.0.0", "@tryghost/bootstrap-socket": "0.2.2", "@tryghost/constants": "0.1.1", "@tryghost/errors": "0.2.4", diff --git a/test/unit/api/canary/utils/validators/input/pages_spec.js b/test/unit/api/canary/utils/validators/input/pages_spec.js index a755b78f9f..f035bc3378 100644 --- a/test/unit/api/canary/utils/validators/input/pages_spec.js +++ b/test/unit/api/canary/utils/validators/input/pages_spec.js @@ -12,7 +12,8 @@ describe('Unit: canary/utils/validators/input/pages', function () { describe('add', function () { const apiConfig = { - docName: 'pages' + docName: 'pages', + method: 'add' }; describe('required fields', function () { @@ -25,7 +26,7 @@ describe('Unit: canary/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -40,7 +41,7 @@ describe('Unit: canary/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -55,7 +56,7 @@ describe('Unit: canary/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -71,7 +72,7 @@ describe('Unit: canary/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -88,7 +89,7 @@ describe('Unit: canary/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -172,7 +173,7 @@ describe('Unit: canary/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -198,7 +199,7 @@ describe('Unit: canary/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -220,7 +221,7 @@ describe('Unit: canary/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -247,7 +248,8 @@ describe('Unit: canary/utils/validators/input/pages', function () { describe('edit', function () { const apiConfig = { - docName: 'pages' + docName: 'pages', + method: 'edit' }; describe('required fields', function () { @@ -260,7 +262,7 @@ describe('Unit: canary/utils/validators/input/pages', function () { return validators.input.pages.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -275,7 +277,7 @@ describe('Unit: canary/utils/validators/input/pages', function () { return validators.input.pages.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -291,7 +293,7 @@ describe('Unit: canary/utils/validators/input/pages', function () { return validators.input.pages.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -327,7 +329,7 @@ describe('Unit: canary/utils/validators/input/pages', function () { return validators.input.pages.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -349,7 +351,7 @@ describe('Unit: canary/utils/validators/input/pages', function () { return validators.input.pages.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); diff --git a/test/unit/api/canary/utils/validators/input/posts_spec.js b/test/unit/api/canary/utils/validators/input/posts_spec.js index 6290b9678e..4de5db2afb 100644 --- a/test/unit/api/canary/utils/validators/input/posts_spec.js +++ b/test/unit/api/canary/utils/validators/input/posts_spec.js @@ -12,7 +12,8 @@ describe('Unit: canary/utils/validators/input/posts', function () { describe('add', function () { const apiConfig = { - docName: 'posts' + docName: 'posts', + method: 'add' }; describe('required fields', function () { @@ -25,7 +26,7 @@ describe('Unit: canary/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -40,7 +41,7 @@ describe('Unit: canary/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -55,7 +56,7 @@ describe('Unit: canary/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -71,7 +72,7 @@ describe('Unit: canary/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -88,7 +89,7 @@ describe('Unit: canary/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -172,7 +173,7 @@ describe('Unit: canary/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -198,7 +199,7 @@ describe('Unit: canary/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -220,7 +221,7 @@ describe('Unit: canary/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -247,7 +248,8 @@ describe('Unit: canary/utils/validators/input/posts', function () { describe('edit', function () { const apiConfig = { - docName: 'posts' + docName: 'posts', + method: 'edit' }; describe('required fields', function () { @@ -260,7 +262,7 @@ describe('Unit: canary/utils/validators/input/posts', function () { return validators.input.posts.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -275,7 +277,7 @@ describe('Unit: canary/utils/validators/input/posts', function () { return validators.input.posts.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -291,7 +293,7 @@ describe('Unit: canary/utils/validators/input/posts', function () { return validators.input.posts.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -327,7 +329,7 @@ describe('Unit: canary/utils/validators/input/posts', function () { return validators.input.posts.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -349,7 +351,7 @@ describe('Unit: canary/utils/validators/input/posts', function () { return validators.input.posts.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); diff --git a/test/unit/api/canary/utils/validators/input/tags_spec.js b/test/unit/api/canary/utils/validators/input/tags_spec.js index 3b26746ec5..7130ecb2bb 100644 --- a/test/unit/api/canary/utils/validators/input/tags_spec.js +++ b/test/unit/api/canary/utils/validators/input/tags_spec.js @@ -12,7 +12,8 @@ describe('Unit: canary/utils/validators/input/tags', function () { describe('add', function () { const apiConfig = { - docName: 'tags' + docName: 'tags', + method: 'add' }; describe('required fields', function () { @@ -25,7 +26,7 @@ describe('Unit: canary/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -40,7 +41,7 @@ describe('Unit: canary/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -55,7 +56,7 @@ describe('Unit: canary/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -71,7 +72,7 @@ describe('Unit: canary/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -88,7 +89,7 @@ describe('Unit: canary/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -166,7 +167,7 @@ describe('Unit: canary/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -178,7 +179,8 @@ describe('Unit: canary/utils/validators/input/tags', function () { describe('edit', function () { const apiConfig = { - docName: 'tags' + docName: 'tags', + method: 'edit' }; describe('required fields', function () { @@ -191,7 +193,7 @@ describe('Unit: canary/utils/validators/input/tags', function () { return validators.input.tags.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -206,7 +208,7 @@ describe('Unit: canary/utils/validators/input/tags', function () { return validators.input.tags.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -222,7 +224,7 @@ describe('Unit: canary/utils/validators/input/tags', function () { return validators.input.tags.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); diff --git a/test/unit/api/canary/utils/validators/input/webhooks_spec.js b/test/unit/api/canary/utils/validators/input/webhooks_spec.js index 6de6c412e2..52ad7a4a17 100644 --- a/test/unit/api/canary/utils/validators/input/webhooks_spec.js +++ b/test/unit/api/canary/utils/validators/input/webhooks_spec.js @@ -12,7 +12,8 @@ describe('Unit: canary/utils/validators/input/webhooks', function () { describe('add', function () { const apiConfig = { - docName: 'webhooks' + docName: 'webhooks', + method: 'add' }; describe('required fields', function () { @@ -25,7 +26,7 @@ describe('Unit: canary/utils/validators/input/webhooks', function () { return validators.input.webhooks.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -40,7 +41,7 @@ describe('Unit: canary/utils/validators/input/webhooks', function () { return validators.input.webhooks.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -55,7 +56,7 @@ describe('Unit: canary/utils/validators/input/webhooks', function () { return validators.input.webhooks.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -71,7 +72,7 @@ describe('Unit: canary/utils/validators/input/webhooks', function () { return validators.input.webhooks.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -88,7 +89,7 @@ describe('Unit: canary/utils/validators/input/webhooks', function () { return validators.input.webhooks.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -176,7 +177,7 @@ describe('Unit: canary/utils/validators/input/webhooks', function () { return validators.input.webhooks.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -188,7 +189,8 @@ describe('Unit: canary/utils/validators/input/webhooks', function () { describe('edit', function () { const apiConfig = { - docName: 'webhooks' + docName: 'webhooks', + method: 'edit' }; describe('required fields', function () { @@ -201,7 +203,7 @@ describe('Unit: canary/utils/validators/input/webhooks', function () { return validators.input.webhooks.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -216,7 +218,7 @@ describe('Unit: canary/utils/validators/input/webhooks', function () { return validators.input.webhooks.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -232,7 +234,7 @@ describe('Unit: canary/utils/validators/input/webhooks', function () { return validators.input.webhooks.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); diff --git a/test/unit/api/v2/utils/validators/input/pages_spec.js b/test/unit/api/v2/utils/validators/input/pages_spec.js index f96f71f1c5..3c9352f6e2 100644 --- a/test/unit/api/v2/utils/validators/input/pages_spec.js +++ b/test/unit/api/v2/utils/validators/input/pages_spec.js @@ -12,7 +12,8 @@ describe('Unit: v2/utils/validators/input/pages', function () { describe('add', function () { const apiConfig = { - docName: 'pages' + docName: 'pages', + method: 'add' }; describe('required fields', function () { @@ -25,7 +26,7 @@ describe('Unit: v2/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -40,7 +41,7 @@ describe('Unit: v2/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -55,7 +56,7 @@ describe('Unit: v2/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -71,7 +72,7 @@ describe('Unit: v2/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -88,7 +89,7 @@ describe('Unit: v2/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -172,7 +173,7 @@ describe('Unit: v2/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -198,7 +199,7 @@ describe('Unit: v2/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -220,7 +221,7 @@ describe('Unit: v2/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -247,7 +248,8 @@ describe('Unit: v2/utils/validators/input/pages', function () { describe('edit', function () { const apiConfig = { - docName: 'pages' + docName: 'pages', + method: 'edit' }; describe('required fields', function () { @@ -260,7 +262,7 @@ describe('Unit: v2/utils/validators/input/pages', function () { return validators.input.pages.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -275,7 +277,7 @@ describe('Unit: v2/utils/validators/input/pages', function () { return validators.input.pages.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -291,7 +293,7 @@ describe('Unit: v2/utils/validators/input/pages', function () { return validators.input.pages.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -327,7 +329,7 @@ describe('Unit: v2/utils/validators/input/pages', function () { return validators.input.pages.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -349,7 +351,7 @@ describe('Unit: v2/utils/validators/input/pages', function () { return validators.input.pages.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); diff --git a/test/unit/api/v2/utils/validators/input/posts_spec.js b/test/unit/api/v2/utils/validators/input/posts_spec.js index 97e00f7ac1..0f435026c4 100644 --- a/test/unit/api/v2/utils/validators/input/posts_spec.js +++ b/test/unit/api/v2/utils/validators/input/posts_spec.js @@ -12,7 +12,8 @@ describe('Unit: v2/utils/validators/input/posts', function () { describe('add', function () { const apiConfig = { - docName: 'posts' + docName: 'posts', + method: 'add' }; describe('required fields', function () { @@ -25,7 +26,7 @@ describe('Unit: v2/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -40,7 +41,7 @@ describe('Unit: v2/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -55,7 +56,7 @@ describe('Unit: v2/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -71,7 +72,7 @@ describe('Unit: v2/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -88,7 +89,7 @@ describe('Unit: v2/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -172,7 +173,7 @@ describe('Unit: v2/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -198,7 +199,7 @@ describe('Unit: v2/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -220,7 +221,7 @@ describe('Unit: v2/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -247,7 +248,8 @@ describe('Unit: v2/utils/validators/input/posts', function () { describe('edit', function () { const apiConfig = { - docName: 'posts' + docName: 'posts', + method: 'edit' }; describe('required fields', function () { @@ -260,7 +262,7 @@ describe('Unit: v2/utils/validators/input/posts', function () { return validators.input.posts.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -275,7 +277,7 @@ describe('Unit: v2/utils/validators/input/posts', function () { return validators.input.posts.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -291,7 +293,7 @@ describe('Unit: v2/utils/validators/input/posts', function () { return validators.input.posts.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -327,7 +329,7 @@ describe('Unit: v2/utils/validators/input/posts', function () { return validators.input.posts.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -349,7 +351,7 @@ describe('Unit: v2/utils/validators/input/posts', function () { return validators.input.posts.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); diff --git a/test/unit/api/v2/utils/validators/input/tags_spec.js b/test/unit/api/v2/utils/validators/input/tags_spec.js index 2d02de8ca4..8ab52fe422 100644 --- a/test/unit/api/v2/utils/validators/input/tags_spec.js +++ b/test/unit/api/v2/utils/validators/input/tags_spec.js @@ -12,7 +12,8 @@ describe('Unit: v2/utils/validators/input/tags', function () { describe('add', function () { const apiConfig = { - docName: 'tags' + docName: 'tags', + method: 'add' }; describe('required fields', function () { @@ -25,7 +26,7 @@ describe('Unit: v2/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -40,7 +41,7 @@ describe('Unit: v2/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -55,7 +56,7 @@ describe('Unit: v2/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -71,7 +72,7 @@ describe('Unit: v2/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -88,7 +89,7 @@ describe('Unit: v2/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -166,7 +167,7 @@ describe('Unit: v2/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -178,7 +179,8 @@ describe('Unit: v2/utils/validators/input/tags', function () { describe('edit', function () { const apiConfig = { - docName: 'tags' + docName: 'tags', + method: 'edit' }; describe('required fields', function () { @@ -191,7 +193,7 @@ describe('Unit: v2/utils/validators/input/tags', function () { return validators.input.tags.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -206,7 +208,7 @@ describe('Unit: v2/utils/validators/input/tags', function () { return validators.input.tags.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -222,7 +224,7 @@ describe('Unit: v2/utils/validators/input/tags', function () { return validators.input.tags.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); diff --git a/test/unit/api/v3/utils/validators/input/pages_spec.js b/test/unit/api/v3/utils/validators/input/pages_spec.js index 315e31c67b..d3f72e7055 100644 --- a/test/unit/api/v3/utils/validators/input/pages_spec.js +++ b/test/unit/api/v3/utils/validators/input/pages_spec.js @@ -12,7 +12,8 @@ describe('Unit: v3/utils/validators/input/pages', function () { describe('add', function () { const apiConfig = { - docName: 'pages' + docName: 'pages', + method: 'add' }; describe('required fields', function () { @@ -25,7 +26,7 @@ describe('Unit: v3/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -40,7 +41,7 @@ describe('Unit: v3/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -55,7 +56,7 @@ describe('Unit: v3/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -71,7 +72,7 @@ describe('Unit: v3/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -88,7 +89,7 @@ describe('Unit: v3/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -172,7 +173,7 @@ describe('Unit: v3/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -198,7 +199,7 @@ describe('Unit: v3/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -220,7 +221,7 @@ describe('Unit: v3/utils/validators/input/pages', function () { return validators.input.pages.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -247,7 +248,8 @@ describe('Unit: v3/utils/validators/input/pages', function () { describe('edit', function () { const apiConfig = { - docName: 'pages' + docName: 'pages', + method: 'edit' }; describe('required fields', function () { @@ -260,7 +262,7 @@ describe('Unit: v3/utils/validators/input/pages', function () { return validators.input.pages.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -275,7 +277,7 @@ describe('Unit: v3/utils/validators/input/pages', function () { return validators.input.pages.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -291,7 +293,7 @@ describe('Unit: v3/utils/validators/input/pages', function () { return validators.input.pages.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -327,7 +329,7 @@ describe('Unit: v3/utils/validators/input/pages', function () { return validators.input.pages.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -349,7 +351,7 @@ describe('Unit: v3/utils/validators/input/pages', function () { return validators.input.pages.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); diff --git a/test/unit/api/v3/utils/validators/input/posts_spec.js b/test/unit/api/v3/utils/validators/input/posts_spec.js index d7d483bc30..95dc432b22 100644 --- a/test/unit/api/v3/utils/validators/input/posts_spec.js +++ b/test/unit/api/v3/utils/validators/input/posts_spec.js @@ -12,7 +12,8 @@ describe('Unit: v3/utils/validators/input/posts', function () { describe('add', function () { const apiConfig = { - docName: 'posts' + docName: 'posts', + method: 'add' }; describe('required fields', function () { @@ -25,7 +26,7 @@ describe('Unit: v3/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -40,7 +41,7 @@ describe('Unit: v3/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -55,7 +56,7 @@ describe('Unit: v3/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -71,7 +72,7 @@ describe('Unit: v3/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -88,7 +89,7 @@ describe('Unit: v3/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -172,7 +173,7 @@ describe('Unit: v3/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -198,7 +199,7 @@ describe('Unit: v3/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -220,7 +221,7 @@ describe('Unit: v3/utils/validators/input/posts', function () { return validators.input.posts.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -247,7 +248,8 @@ describe('Unit: v3/utils/validators/input/posts', function () { describe('edit', function () { const apiConfig = { - docName: 'posts' + docName: 'posts', + method: 'edit' }; describe('required fields', function () { @@ -260,7 +262,7 @@ describe('Unit: v3/utils/validators/input/posts', function () { return validators.input.posts.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -275,7 +277,7 @@ describe('Unit: v3/utils/validators/input/posts', function () { return validators.input.posts.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -291,7 +293,7 @@ describe('Unit: v3/utils/validators/input/posts', function () { return validators.input.posts.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -327,7 +329,7 @@ describe('Unit: v3/utils/validators/input/posts', function () { return validators.input.posts.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -349,7 +351,7 @@ describe('Unit: v3/utils/validators/input/posts', function () { return validators.input.posts.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); diff --git a/test/unit/api/v3/utils/validators/input/tags_spec.js b/test/unit/api/v3/utils/validators/input/tags_spec.js index eb501de03a..c6bb04a68b 100644 --- a/test/unit/api/v3/utils/validators/input/tags_spec.js +++ b/test/unit/api/v3/utils/validators/input/tags_spec.js @@ -12,7 +12,8 @@ describe('Unit: v3/utils/validators/input/tags', function () { describe('add', function () { const apiConfig = { - docName: 'tags' + docName: 'tags', + method: 'add' }; describe('required fields', function () { @@ -25,7 +26,7 @@ describe('Unit: v3/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -40,7 +41,7 @@ describe('Unit: v3/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -55,7 +56,7 @@ describe('Unit: v3/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -71,7 +72,7 @@ describe('Unit: v3/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -88,7 +89,7 @@ describe('Unit: v3/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -166,7 +167,7 @@ describe('Unit: v3/utils/validators/input/tags', function () { return validators.input.tags.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -178,7 +179,8 @@ describe('Unit: v3/utils/validators/input/tags', function () { describe('edit', function () { const apiConfig = { - docName: 'tags' + docName: 'tags', + method: 'edit' }; describe('required fields', function () { @@ -191,7 +193,7 @@ describe('Unit: v3/utils/validators/input/tags', function () { return validators.input.tags.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -206,7 +208,7 @@ describe('Unit: v3/utils/validators/input/tags', function () { return validators.input.tags.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -222,7 +224,7 @@ describe('Unit: v3/utils/validators/input/tags', function () { return validators.input.tags.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); diff --git a/test/unit/api/v3/utils/validators/input/webhooks_spec.js b/test/unit/api/v3/utils/validators/input/webhooks_spec.js index 8d2701cb80..9c3507aef3 100644 --- a/test/unit/api/v3/utils/validators/input/webhooks_spec.js +++ b/test/unit/api/v3/utils/validators/input/webhooks_spec.js @@ -12,7 +12,8 @@ describe('Unit: v3/utils/validators/input/webhooks', function () { describe('add', function () { const apiConfig = { - docName: 'webhooks' + docName: 'webhooks', + method: 'add' }; describe('required fields', function () { @@ -25,7 +26,7 @@ describe('Unit: v3/utils/validators/input/webhooks', function () { return validators.input.webhooks.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -40,7 +41,7 @@ describe('Unit: v3/utils/validators/input/webhooks', function () { return validators.input.webhooks.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -55,7 +56,7 @@ describe('Unit: v3/utils/validators/input/webhooks', function () { return validators.input.webhooks.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -71,7 +72,7 @@ describe('Unit: v3/utils/validators/input/webhooks', function () { return validators.input.webhooks.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -88,7 +89,7 @@ describe('Unit: v3/utils/validators/input/webhooks', function () { return validators.input.webhooks.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -176,7 +177,7 @@ describe('Unit: v3/utils/validators/input/webhooks', function () { return validators.input.webhooks.add(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -188,7 +189,8 @@ describe('Unit: v3/utils/validators/input/webhooks', function () { describe('edit', function () { const apiConfig = { - docName: 'webhooks' + docName: 'webhooks', + method: 'edit' }; describe('required fields', function () { @@ -201,7 +203,7 @@ describe('Unit: v3/utils/validators/input/webhooks', function () { return validators.input.webhooks.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -216,7 +218,7 @@ describe('Unit: v3/utils/validators/input/webhooks', function () { return validators.input.webhooks.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); @@ -232,7 +234,7 @@ describe('Unit: v3/utils/validators/input/webhooks', function () { return validators.input.webhooks.edit(apiConfig, frame) .then(Promise.reject) .catch((err) => { - (err instanceof errors.ValidationError).should.be.true(); + err.errorType.should.equal('ValidationError'); }); }); diff --git a/yarn.lock b/yarn.lock index 489c8a869a..5fe3243c26 100644 --- a/yarn.lock +++ b/yarn.lock @@ -378,6 +378,16 @@ dependencies: "@tryghost/errors" "^0.2.4" +"@tryghost/admin-api-schema@1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@tryghost/admin-api-schema/-/admin-api-schema-1.0.0.tgz#7da26b8589fc75b73ea2ef8e744a8d9b2d41d7f1" + integrity sha512-FDEw4oEX3AsPugBbHT/1RuDqcyvPZhrwum+2mfk1OW9buw10opERFzhAdZz+Jrf4C8WAuoMXFk7BLm4xi30+9w== + dependencies: + "@tryghost/errors" "0.2.4" + bluebird "^3.5.3" + ghost-ignition "4.2.2" + lodash "^4.17.11" + "@tryghost/bootstrap-socket@0.2.2": version "0.2.2" resolved "https://registry.yarnpkg.com/@tryghost/bootstrap-socket/-/bootstrap-socket-0.2.2.tgz#e365c75d7822394553077c3bf05a3bbfde986829"