UNPKG

@flawiddsouza/httpsnippet

Version:

HTTP Request snippet generator for *most* languages

515 lines (514 loc) 55.3 kB
"use strict"; module.exports = validate10; module.exports["default"] = validate10; var schema11 = { "$id": "request.json#", "$schema": "http://json-schema.org/draft-06/schema#", "type": "object", "required": ["method", "url", "httpVersion", "cookies", "headers", "queryString", "headersSize", "bodySize"], "properties": { "method": { "type": "string" }, "url": { "type": "string", "format": "uri" }, "httpVersion": { "type": "string" }, "cookies": { "type": "array", "items": { "$ref": "cookie.json#" } }, "headers": { "type": "array", "items": { "$ref": "header.json#" } }, "queryString": { "type": "array", "items": { "$ref": "query.json#" } }, "postData": { "$ref": "postData.json#" }, "headersSize": { "type": "integer" }, "bodySize": { "type": "integer" }, "comment": { "type": "string" } } }; var schema12 = { "$id": "cookie.json#", "$schema": "http://json-schema.org/draft-06/schema#", "type": "object", "required": ["name", "value"], "properties": { "name": { "type": "string" }, "value": { "type": "string" }, "path": { "type": "string" }, "domain": { "type": "string" }, "expires": { "type": ["string", "null"], "format": "date-time" }, "httpOnly": { "type": "boolean" }, "secure": { "type": "boolean" }, "comment": { "type": "string" } } }; var schema13 = { "$id": "header.json#", "$schema": "http://json-schema.org/draft-06/schema#", "type": "object", "required": ["name", "value"], "properties": { "name": { "type": "string" }, "value": { "type": "string" }, "comment": { "type": "string" } } }; var schema14 = { "$id": "query.json#", "$schema": "http://json-schema.org/draft-06/schema#", "type": "object", "required": ["name", "value"], "properties": { "name": { "type": "string" }, "value": { "type": "string" }, "comment": { "type": "string" } } }; var schema15 = { "$id": "postData.json#", "$schema": "http://json-schema.org/draft-06/schema#", "type": "object", "optional": true, "required": ["mimeType"], "properties": { "mimeType": { "type": "string" }, "text": { "type": "string" }, "params": { "type": "array", "required": ["name"], "properties": { "name": { "type": "string" }, "value": { "type": "string" }, "fileName": { "type": "string" }, "contentType": { "type": "string" }, "comment": { "type": "string" } } }, "comment": { "type": "string" } } }; var formats0 = require("ajv-formats/dist/formats").fullFormats.uri; var formats2 = require("ajv-formats/dist/formats").fullFormats["date-time"]; function validate10(data, _a) { var _b = _a === void 0 ? {} : _a, _c = _b.instancePath, instancePath = _c === void 0 ? "" : _c, parentData = _b.parentData, parentDataProperty = _b.parentDataProperty, _d = _b.rootData, rootData = _d === void 0 ? data : _d; ; var vErrors = null; var errors = 0; if (errors === 0) { if (data && typeof data == "object" && !Array.isArray(data)) { var missing0 = void 0; if (((((((((data.method === undefined) && (missing0 = "method")) || ((data.url === undefined) && (missing0 = "url"))) || ((data.httpVersion === undefined) && (missing0 = "httpVersion"))) || ((data.cookies === undefined) && (missing0 = "cookies"))) || ((data.headers === undefined) && (missing0 = "headers"))) || ((data.queryString === undefined) && (missing0 = "queryString"))) || ((data.headersSize === undefined) && (missing0 = "headersSize"))) || ((data.bodySize === undefined) && (missing0 = "bodySize"))) { validate10.errors = [{ instancePath: instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }]; return false; } else { if (data.method !== undefined) { var _errs1 = errors; if (typeof data.method !== "string") { validate10.errors = [{ instancePath: instancePath + "/method", schemaPath: "#/properties/method/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid0 = _errs1 === errors; } else { var valid0 = true; } if (valid0) { if (data.url !== undefined) { var data1 = data.url; var _errs3 = errors; if (errors === _errs3) { if (errors === _errs3) { if (typeof data1 === "string") { if (!(formats0(data1))) { validate10.errors = [{ instancePath: instancePath + "/url", schemaPath: "#/properties/url/format", keyword: "format", params: { format: "uri" }, message: "must match format \"" + "uri" + "\"" }]; return false; } } else { validate10.errors = [{ instancePath: instancePath + "/url", schemaPath: "#/properties/url/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } } } var valid0 = _errs3 === errors; } else { var valid0 = true; } if (valid0) { if (data.httpVersion !== undefined) { var _errs5 = errors; if (typeof data.httpVersion !== "string") { validate10.errors = [{ instancePath: instancePath + "/httpVersion", schemaPath: "#/properties/httpVersion/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid0 = _errs5 === errors; } else { var valid0 = true; } if (valid0) { if (data.cookies !== undefined) { var data3 = data.cookies; var _errs7 = errors; if (errors === _errs7) { if (Array.isArray(data3)) { var valid1 = true; var len0 = data3.length; for (var i0 = 0; i0 < len0; i0++) { var data4 = data3[i0]; var _errs9 = errors; var _errs10 = errors; if (errors === _errs10) { if (data4 && typeof data4 == "object" && !Array.isArray(data4)) { var missing1 = void 0; if (((data4.name === undefined) && (missing1 = "name")) || ((data4.value === undefined) && (missing1 = "value"))) { validate10.errors = [{ instancePath: instancePath + "/cookies/" + i0, schemaPath: "cookie.json#/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" }]; return false; } else { if (data4.name !== undefined) { var _errs12 = errors; if (typeof data4.name !== "string") { validate10.errors = [{ instancePath: instancePath + "/cookies/" + i0 + "/name", schemaPath: "cookie.json#/properties/name/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid3 = _errs12 === errors; } else { var valid3 = true; } if (valid3) { if (data4.value !== undefined) { var _errs14 = errors; if (typeof data4.value !== "string") { validate10.errors = [{ instancePath: instancePath + "/cookies/" + i0 + "/value", schemaPath: "cookie.json#/properties/value/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid3 = _errs14 === errors; } else { var valid3 = true; } if (valid3) { if (data4.path !== undefined) { var _errs16 = errors; if (typeof data4.path !== "string") { validate10.errors = [{ instancePath: instancePath + "/cookies/" + i0 + "/path", schemaPath: "cookie.json#/properties/path/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid3 = _errs16 === errors; } else { var valid3 = true; } if (valid3) { if (data4.domain !== undefined) { var _errs18 = errors; if (typeof data4.domain !== "string") { validate10.errors = [{ instancePath: instancePath + "/cookies/" + i0 + "/domain", schemaPath: "cookie.json#/properties/domain/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid3 = _errs18 === errors; } else { var valid3 = true; } if (valid3) { if (data4.expires !== undefined) { var data9 = data4.expires; var _errs20 = errors; if ((typeof data9 !== "string") && (data9 !== null)) { validate10.errors = [{ instancePath: instancePath + "/cookies/" + i0 + "/expires", schemaPath: "cookie.json#/properties/expires/type", keyword: "type", params: { type: schema12.properties.expires.type }, message: "must be string,null" }]; return false; } if (errors === _errs20) { if (errors === _errs20) { if (typeof data9 === "string") { if (!(formats2.validate(data9))) { validate10.errors = [{ instancePath: instancePath + "/cookies/" + i0 + "/expires", schemaPath: "cookie.json#/properties/expires/format", keyword: "format", params: { format: "date-time" }, message: "must match format \"" + "date-time" + "\"" }]; return false; } } } } var valid3 = _errs20 === errors; } else { var valid3 = true; } if (valid3) { if (data4.httpOnly !== undefined) { var _errs22 = errors; if (typeof data4.httpOnly !== "boolean") { validate10.errors = [{ instancePath: instancePath + "/cookies/" + i0 + "/httpOnly", schemaPath: "cookie.json#/properties/httpOnly/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }]; return false; } var valid3 = _errs22 === errors; } else { var valid3 = true; } if (valid3) { if (data4.secure !== undefined) { var _errs24 = errors; if (typeof data4.secure !== "boolean") { validate10.errors = [{ instancePath: instancePath + "/cookies/" + i0 + "/secure", schemaPath: "cookie.json#/properties/secure/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }]; return false; } var valid3 = _errs24 === errors; } else { var valid3 = true; } if (valid3) { if (data4.comment !== undefined) { var _errs26 = errors; if (typeof data4.comment !== "string") { validate10.errors = [{ instancePath: instancePath + "/cookies/" + i0 + "/comment", schemaPath: "cookie.json#/properties/comment/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid3 = _errs26 === errors; } else { var valid3 = true; } } } } } } } } } } else { validate10.errors = [{ instancePath: instancePath + "/cookies/" + i0, schemaPath: "cookie.json#/type", keyword: "type", params: { type: "object" }, message: "must be object" }]; return false; } } var valid1 = _errs9 === errors; if (!valid1) { break; } } } else { validate10.errors = [{ instancePath: instancePath + "/cookies", schemaPath: "#/properties/cookies/type", keyword: "type", params: { type: "array" }, message: "must be array" }]; return false; } } var valid0 = _errs7 === errors; } else { var valid0 = true; } if (valid0) { if (data.headers !== undefined) { var data13 = data.headers; var _errs28 = errors; if (errors === _errs28) { if (Array.isArray(data13)) { var valid4 = true; var len1 = data13.length; for (var i1 = 0; i1 < len1; i1++) { var data14 = data13[i1]; var _errs30 = errors; var _errs31 = errors; if (errors === _errs31) { if (data14 && typeof data14 == "object" && !Array.isArray(data14)) { var missing2 = void 0; if (((data14.name === undefined) && (missing2 = "name")) || ((data14.value === undefined) && (missing2 = "value"))) { validate10.errors = [{ instancePath: instancePath + "/headers/" + i1, schemaPath: "header.json#/required", keyword: "required", params: { missingProperty: missing2 }, message: "must have required property '" + missing2 + "'" }]; return false; } else { if (data14.name !== undefined) { var _errs33 = errors; if (typeof data14.name !== "string") { validate10.errors = [{ instancePath: instancePath + "/headers/" + i1 + "/name", schemaPath: "header.json#/properties/name/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid6 = _errs33 === errors; } else { var valid6 = true; } if (valid6) { if (data14.value !== undefined) { var _errs35 = errors; if (typeof data14.value !== "string") { validate10.errors = [{ instancePath: instancePath + "/headers/" + i1 + "/value", schemaPath: "header.json#/properties/value/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid6 = _errs35 === errors; } else { var valid6 = true; } if (valid6) { if (data14.comment !== undefined) { var _errs37 = errors; if (typeof data14.comment !== "string") { validate10.errors = [{ instancePath: instancePath + "/headers/" + i1 + "/comment", schemaPath: "header.json#/properties/comment/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid6 = _errs37 === errors; } else { var valid6 = true; } } } } } else { validate10.errors = [{ instancePath: instancePath + "/headers/" + i1, schemaPath: "header.json#/type", keyword: "type", params: { type: "object" }, message: "must be object" }]; return false; } } var valid4 = _errs30 === errors; if (!valid4) { break; } } } else { validate10.errors = [{ instancePath: instancePath + "/headers", schemaPath: "#/properties/headers/type", keyword: "type", params: { type: "array" }, message: "must be array" }]; return false; } } var valid0 = _errs28 === errors; } else { var valid0 = true; } if (valid0) { if (data.queryString !== undefined) { var data18 = data.queryString; var _errs39 = errors; if (errors === _errs39) { if (Array.isArray(data18)) { var valid7 = true; var len2 = data18.length; for (var i2 = 0; i2 < len2; i2++) { var data19 = data18[i2]; var _errs41 = errors; var _errs42 = errors; if (errors === _errs42) { if (data19 && typeof data19 == "object" && !Array.isArray(data19)) { var missing3 = void 0; if (((data19.name === undefined) && (missing3 = "name")) || ((data19.value === undefined) && (missing3 = "value"))) { validate10.errors = [{ instancePath: instancePath + "/queryString/" + i2, schemaPath: "query.json#/required", keyword: "required", params: { missingProperty: missing3 }, message: "must have required property '" + missing3 + "'" }]; return false; } else { if (data19.name !== undefined) { var _errs44 = errors; if (typeof data19.name !== "string") { validate10.errors = [{ instancePath: instancePath + "/queryString/" + i2 + "/name", schemaPath: "query.json#/properties/name/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid9 = _errs44 === errors; } else { var valid9 = true; } if (valid9) { if (data19.value !== undefined) { var _errs46 = errors; if (typeof data19.value !== "string") { validate10.errors = [{ instancePath: instancePath + "/queryString/" + i2 + "/value", schemaPath: "query.json#/properties/value/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid9 = _errs46 === errors; } else { var valid9 = true; } if (valid9) { if (data19.comment !== undefined) { var _errs48 = errors; if (typeof data19.comment !== "string") { validate10.errors = [{ instancePath: instancePath + "/queryString/" + i2 + "/comment", schemaPath: "query.json#/properties/comment/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid9 = _errs48 === errors; } else { var valid9 = true; } } } } } else { validate10.errors = [{ instancePath: instancePath + "/queryString/" + i2, schemaPath: "query.json#/type", keyword: "type", params: { type: "object" }, message: "must be object" }]; return false; } } var valid7 = _errs41 === errors; if (!valid7) { break; } } } else { validate10.errors = [{ instancePath: instancePath + "/queryString", schemaPath: "#/properties/queryString/type", keyword: "type", params: { type: "array" }, message: "must be array" }]; return false; } } var valid0 = _errs39 === errors; } else { var valid0 = true; } if (valid0) { if (data.postData !== undefined) { var data23 = data.postData; var _errs50 = errors; var _errs51 = errors; if (errors === _errs51) { if (data23 && typeof data23 == "object" && !Array.isArray(data23)) { var missing4 = void 0; if ((data23.mimeType === undefined) && (missing4 = "mimeType")) { validate10.errors = [{ instancePath: instancePath + "/postData", schemaPath: "postData.json#/required", keyword: "required", params: { missingProperty: missing4 }, message: "must have required property '" + missing4 + "'" }]; return false; } else { if (data23.mimeType !== undefined) { var _errs53 = errors; if (typeof data23.mimeType !== "string") { validate10.errors = [{ instancePath: instancePath + "/postData/mimeType", schemaPath: "postData.json#/properties/mimeType/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid11 = _errs53 === errors; } else { var valid11 = true; } if (valid11) { if (data23.text !== undefined) { var _errs55 = errors; if (typeof data23.text !== "string") { validate10.errors = [{ instancePath: instancePath + "/postData/text", schemaPath: "postData.json#/properties/text/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid11 = _errs55 === errors; } else { var valid11 = true; } if (valid11) { if (data23.params !== undefined) { var data26 = data23.params; var _errs57 = errors; if (!(Array.isArray(data26))) { validate10.errors = [{ instancePath: instancePath + "/postData/params", schemaPath: "postData.json#/properties/params/type", keyword: "type", params: { type: "array" }, message: "must be array" }]; return false; } if (errors === _errs57) { if (data26 && typeof data26 == "object" && !Array.isArray(data26)) { var missing5 = void 0; if ((data26.name === undefined) && (missing5 = "name")) { validate10.errors = [{ instancePath: instancePath + "/postData/params", schemaPath: "postData.json#/properties/params/required", keyword: "required", params: { missingProperty: missing5 }, message: "must have required property '" + missing5 + "'" }]; return false; } else { if (data26.name !== undefined) { var _errs59 = errors; if (typeof data26.name !== "string") { validate10.errors = [{ instancePath: instancePath + "/postData/params/name", schemaPath: "postData.json#/properties/params/properties/name/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid12 = _errs59 === errors; } else { var valid12 = true; } if (valid12) { if (data26.value !== undefined) { var _errs61 = errors; if (typeof data26.value !== "string") { validate10.errors = [{ instancePath: instancePath + "/postData/params/value", schemaPath: "postData.json#/properties/params/properties/value/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid12 = _errs61 === errors; } else { var valid12 = true; } if (valid12) { if (data26.fileName !== undefined) { var _errs63 = errors; if (typeof data26.fileName !== "string") { validate10.errors = [{ instancePath: instancePath + "/postData/params/fileName", schemaPath: "postData.json#/properties/params/properties/fileName/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid12 = _errs63 === errors; } else { var valid12 = true; } if (valid12) { if (data26.contentType !== undefined) { var _errs65 = errors; if (typeof data26.contentType !== "string") { validate10.errors = [{ instancePath: instancePath + "/postData/params/contentType", schemaPath: "postData.json#/properties/params/properties/contentType/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid12 = _errs65 === errors; } else { var valid12 = true; } if (valid12) { if (data26.comment !== undefined) { var _errs67 = errors; if (typeof data26.comment !== "string") { validate10.errors = [{ instancePath: instancePath + "/postData/params/comment", schemaPath: "postData.json#/properties/params/properties/comment/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false; } var valid12 = _errs67 === errors; } else { var valid12 = true; } } } } } } } } var valid11 = _errs57 === errors; } else { var valid11 = true; } if (valid11) { if (data23.comment !== undefined) { var _errs69 = errors; if (typeof data23.comment !== "string") { validate10.errors = [{ instancePath: instancePath + "/postData/comment", schemaPath: "postData.json#/properties/comment/type", keyword: "type", params: { type: "string" }, message: "must be string" }]; return false;