apiAjax = function (that, opt, onError) {
/*
* this function will send a swagger-api ajax-req with the operation that
*/
let tmp;
local.objectSetDefault(opt, {
data: "",
operation: that,
paramDict: {},
url: ""
});
if (opt.modeDefault) {
local.normalizeSwaggerParamDict(opt);
}
// try to validate paramDict
opt.err = local.swaggerValidateDataParameters({
// normalize paramDict
data: local.normalizeSwaggerParamDict({
modeNoDefault: opt.modeNoDefault,
operation: that,
paramDict: local.jsonCopy(opt.paramDict)
}).paramDict,
dataReadonlyRemove: opt.paramDict,
prefix: [
"operation", that._methodPath
],
parameters: that.parameters,
swaggerJson: local.swaggerJson
})[0];
// init default
local.objectSetDefault(opt, {
inForm: (
that._consumes0 === "multipart/form-data"
? new local.FormData()
: ""
),
inHeader: {},
inPath: that._path.replace((
/#.*?$/
), ""),
inQuery: "",
headers: {},
method: that._method,
responseType: (
that._consumes0.indexOf("application/octet-stream") === 0
? "arraybuffer"
: ""
)
});
// init paramDict
that.parameters.forEach(function (schemaP) {
tmp = opt.paramDict[schemaP.name];
if (local.isNullOrUndefined(tmp)) {
return;
}
// serialize array
if (Array.isArray(tmp) && schemaP.in !== "body") {
switch (
schemaP.collectionFormat || schemaP["x-swgg-collectionFormat"]
) {
case "json":
tmp = JSON.stringify(tmp);
break;
case "multi":
tmp.forEach(function (value) {
opt[(
schemaP.in === "formData"
? "inForm"
: "inQuery"
)] += (
"&" + encodeURIComponent(schemaP.name) + "="
+ encodeURIComponent(
local.schemaPItemsType(schemaP) === "string"
? value
: JSON.stringify(value)
)
);
});
return;
case "pipes":
tmp = tmp.join("|");
break;
case "ssv":
tmp = tmp.join(" ");
break;
case "tsv":
tmp = tmp.join("\t");
break;
// default to csv
default:
tmp = tmp.join(",");
}
} else if (
typeof tmp !== "string"
&& !(tmp && tmp.constructor === local.Blob)
) {
tmp = JSON.stringify(tmp);
}
switch (schemaP.in) {
case "body":
opt.inBody = tmp;
break;
case "formData":
switch (that._consumes0) {
case "application/xml":
// init xml header
if (!opt.inForm) {
opt.inForm += "<?xml version=\"1.0\"?>";
}
opt.inForm += (
"\n<" + schemaP.name + ">" + "<![CDATA["
+ tmp.replace((
/\]\]>/g
), "]]>") + "]]></" + schemaP.name + ">"
);...
...
}
// update apiDict
that = local.jsonCopy(that);
local.apiDict[key.join(".")] = that;
local.apiDict[that._methodPath] = that;
// init ajax
that.ajax = function (swaggerJson, onError) {
return local.apiAjax(that, swaggerJson, onError);
};
that._ajaxToString = that.ajax.toString().replace("{", String(
"{\n"
+ "/*\n"
+ " * this function will run the api-call "
+ JSON.stringify(that._methodPath) + "\n"
+ " * example usage:" + String(
...
apiUpdate = function (swaggerJson) {
/*
* this function will update the swagger-api dict of api-calls
*/
let pathDict;
let tmp;
swaggerJson = swaggerJson || {};
// normalize swaggerJson
swaggerJson = local.normalizeSwaggerJson(swaggerJson, {
objectSetDescription: function (dict) {
if (typeof dict === "object" && dict && !dict.$ref) {
if (Array.isArray(dict["x-swgg-descriptionLineList"])) {
dict.description = (
dict["x-swgg-descriptionLineList"].join("\n")
);
}
if (!(
dict === swaggerJson.externalDocs
|| dict === swaggerJson.info
)) {
dict.description = dict.description || "no description";
}
}
}
});
// init apiDict
local.apiDict = local.apiDict || {};
// init swaggerJson
local.swaggerJson = local.swaggerJson || {
"basePath": "/api/v0",
"definitions": {
"BuiltinFile": {
"properties": {
"_id": {
"readOnly": true,
"type": "string"
},
"_timeCreated": {
"format": "date-time",
"readOnly": true,
"type": "string"
},
"_timeUpdated": {
"format": "date-time",
"readOnly": true,
"type": "string"
},
"fileBlob": {
"format": "byte",
"type": "string"
},
"fileContentType": {
"type": "string"
},
"fileDescription": {
"type": "string"
},
"fileFilename": {
"type": "string"
},
"fileInputName": {
"type": "string"
},
"fileSize": {
"minimum": 0,
"type": "integer"
},
"fileUrl": {
"type": "string"
},
"id": {
"type": "string"
}
}
},
"BuiltinJsonapiResponse": {
"properties": {
"data": {
"items": {
"type": "object"
},
"type": "array"
},
"errors": {
"items": {
"type": "object"
},
"type": "array"
},
"meta": {
"type": "object"
}
}
},
"BuiltinUser": {
"properties": {
"_id": {
"readOnly": true,...
...
* 2. npm install swgg\n\
* $ npm install swgg\n\
* 3. run code below to initialize nodejs swgg-client\n\
* 4. (optional) edit file swagger.json to suit your needs\n\
*/\n\
let swgg;\n\
swgg = require("swgg");\n\
swgg.apiUpdate(require("./swagger.json"));\n\
console.log("printing currently loaded apis ...");\n\
Object.keys(swgg.apiDict).sort().forEach(function (key) {\n\
console.log("swgg.apiDict[" + JSON.stringify(key) + "].ajax");\n\
});\n\
console.log("initialized nodejs swgg-client");\n\
</pre>\n\
<div class="color777 reset">[ <span>base url</span>: {{basePath}} ]</div>\n\
...
assertOrThrow = function (passed, message) {
/*
* this function will throw err.<message> if <passed> is falsy
*/
let err;
if (passed) {
return;
}
err = (
(
message
&& typeof message.message === "string"
&& typeof message.stack === "string"
)
// if message is errObj, then leave as is
? message
: new Error(
typeof message === "string"
// if message is a string, then leave as is
? message
// else JSON.stringify message
: JSON.stringify(message, null, 4)
)
);
throw err;
}
...
}
// read file
local.fs.readFile(opt.file, "utf8", opt.gotoNext);
break;
case 2:
// jslint
local.jslint.jslintAndPrint(data, opt.file);
local.assertOrThrow(
!local.jslint.jslintResult.errMsg,
local.jslint.jslintResult.errMsg.replace((
/\u001b\[\d*m/g
), "")
);
// validate
local.swgg.swaggerValidate(JSON.parse(data));
...
crudOptionsSetDefault = function (opt, defaults) {
/*
* this function will set default-values for <opt>
*/
opt = local.objectSetDefault(opt, defaults);
switch (opt._tags0) {
case "pet":
local.objectSetDefault(opt, {
crudGetOneById: local.apiDict["operationId.getPetById"],
crudRemoveOneById: local.apiDict["operationId.deletePet"],
crudSetOneById: local.apiDict["operationId.addPet"],
crudType: [
"undefined", "petId", "id"
],
crudUpdateOneById: local.apiDict["operationId.updatePetWithForm"]
});
break;
case "store":
local.objectSetDefault(opt, {
crudGetOneById: local.apiDict["operationId.getOrderById"],
crudRemoveOneById: local.apiDict["operationId.deleteOrder"],
crudSetOneById: local.apiDict["operationId.placeOrder"],
crudType: [
"undefined", "orderId", "id"
],
crudUpdateOneById: local.apiDict[
"operationId.store.crudUpdateOneById.id.id"
]
});
break;
case "user":
local.objectSetDefault(opt, {
crudGetOneById: local.apiDict["operationId.getUserByName"],
crudRemoveOneById: local.apiDict["operationId.deleteUser"],
crudSetOneById: local.apiDict["operationId.createUser"],
crudType: [
"undefined", "username", "username"
],
crudUpdateOneById: local.apiDict["operationId.updateUser"]
});
break;
default:
Object.keys(local.apiDict).forEach(function (key) {
key.replace((
/^operationId\.x-test\.(\w+)/
), function (ignore, match1) {
opt[match1] = opt[match1] || local.apiDict[key];
});
});
local.objectSetDefault(opt, {
crudType: [
"undefined", "id", "id"
]
});
}
local.idNameInit(opt);
// shallow-copy opt
return local.objectSetDefault({}, opt);
}
...
}, onError);
};
local.testCase_crudCountManyByQuery_default = function (opt, onError) {
/*
* this function will test crudCountManyByQuery's default handling-behavior
*/
opt = local.crudOptionsSetDefault(opt, {
idValue: "testCase_crudCountManyByQuery_default"
});
local.gotoNext(opt, function (err, data) {
switch (opt.gotoState) {
case 1:
// ajax - crudCountManyByQuery
opt.crudCountManyByQuery.ajax({
...
dbFieldRandomCreate = function (opt) {
/*
* this function will create a random dbField from <opt>.schemaP
*/
let depth;
let ii;
let max;
let min;
let schemaP;
let value;
depth = (
Number.isFinite(opt.depth)
? opt.depth
: 3
);
schemaP = opt.schemaP;
schemaP = schemaP.schema || schemaP;
if (schemaP.readOnly) {
return;
}
// init default
if (opt.modeNotRandom && !local.isNullOrUndefined(schemaP.default)) {
return local.jsonCopy(schemaP.default);
}
// init enum-value
if (schemaP.enum) {
value = (
opt.modeNotRandom
? schemaP.enum[0]
: local.listGetElementRandom(schemaP.enum)
);
return (
local.schemaPType(schemaP) === "array"
? [
value
]
: value
);
}
// init default
value = null;
switch (local.schemaPType(schemaP)) {
// 5.3. Validation keywords for arrays
case "array":
if (depth <= 0) {
break;
}
value = [];
ii = 0;
while (ii < Math.min(
// 5.3.2. maxItems
schemaP.maxItems || 2,
// 5.3.3. minItems
schemaP.minItems || 2,
// 5.3.4. uniqueItems
schemaP.uniqueItems
? 2
: 1
)) {
// recurse dbFieldRandomCreate
value.push(local.dbFieldRandomCreate({
depth: depth - 1,
modeNotRandom: opt.modeNotRandom,
schemaP: local.schemaPItems(schemaP)
}));
ii += 1;
}
break;
case "boolean":
value = (
opt.modeNotRandom
? false
: Boolean(Math.random() > 0.5)
);
break;
// 5.1. Validation keywords for numeric instances (number and integer)
case "integer":
case "number":
max = schemaP.maximum;
min = schemaP.minimum;
if (opt.modeNotRandom) {
value = (
!(0 < min || max < 0)
? 0
: min || max
);
} else {
if (!(Number.isFinite(max) && Number.isFinite(min))) {
if (!Number.isFinite(max) && !Number.isFinite(min)) {
max = 1000;
min = 0;
} else if (Number.isFinite(max)) {
min = max - 1000;
} else {
max = min + 1000;
}
}
// exclusiveMaximum and exclusiveMinimum for float
value = (
min
+ (max - min) * Math.max(Math.random(), min * 0.000000000000001)
);
if (local.schemaPType(schemaP) === "integer") {
value = Math.round(value);
}
}
max = schemaP.maximum;
min = schemaP.minimum;
// exclusiveMaximum for integer
if (schemaP.exclusiveMaximum && value === max) {
value -= 1;
}
// exclusiveMinimum for integer
if (schemaP.exclusiveMaximum && value === min) {
value += 1;
}
// multipleOf
if (schemaP.multipleOf > 0) {
value = schemaP.multipleOf * Math.floor(value / schemaP.multipleOf);
if (value < min || (schemaP.exclusiveMinimum && value <= min)) {
value += schemaP.multipleOf;
}
}
break;
// 5.2. Validation keywords for strings
case "string":
value = (
opt.modeNotRandom
? "abcd1234"
: Number(
(1 + Math.random()) * 0x10000000000000
).toString(36).slice(1)
);
switch (schemaP.format) {
case "byte":
value = local.b...
...
schemaP.minItems || 2,
// 5.3.4. uniqueItems
schemaP.uniqueItems
? 2
: 1
)) {
// recurse dbFieldRandomCreate
value.push(local.dbFieldRandomCreate({
depth: depth - 1,
modeNotRandom: opt.modeNotRandom,
schemaP: local.schemaPItems(schemaP)
}));
ii += 1;
}
break;
...
dbRowListRandomCreate = function (opt) {
/*
* this function will create a dbRowList of <opt>.length random dbRow's
*/
let ii;
ii = 0;
while (ii < opt.length) {
opt.dbRowList.push(local.dbRowRandomCreate(opt));
ii += 1;
}
return opt.dbRowList;
}
...
idIndexCreateList: [
{
name: "id"
}
],
name: "File"
}, {
dbRowList: local.swgg.dbRowListRandomCreate({
dbRowList: [
{
id: 0,
name: "birdie",
photoUrls: [],
status: "available",
tags: [
...
dbRowRandomCreate = function (opt) {
/*
* this function will create a random dbRow from opt.properties
*/
let dbRow;
let ii;
let properties;
dbRow = {};
opt = local.objectSetDefault(opt, {
override: local.nop,
prefix: [
"dbRow"
]
});
properties = local.swaggerValidateDataSchema({
// dereference property
modeDereference: true,
prefix: opt.prefix,
schema: opt.schema,
swaggerJson: local.swaggerJson
});
properties = local.jsonCopy((properties && properties.properties) || {});
ii = Object.keys(properties).length;
while (ii < (opt.schema && opt.schema.minProperties)) {
properties["property" + ii] = {
type: "string"
};
ii += 1;
}
Object.keys(properties).forEach(function (key) {
dbRow[key] = local.dbFieldRandomCreate({
depth: opt.depth,
modeNotRandom: opt.modeNotRandom,
schemaP: local.swaggerValidateDataSchema({
// dereference property
modeDereference: true,
prefix: opt.prefix.concat([
key
]),
schema: properties[key],
swaggerJson: local.swaggerJson
})
});
});
dbRow = local.jsonCopy(local.objectSetOverride(dbRow, opt.override(opt)));
// try to validate data
local.tryCatchOnError(function () {
local.swaggerValidateDataSchema({
data: dbRow,
prefix: opt.prefix,
schema: opt.schema,
swaggerJson: local.swaggerJson
});
}, local.onErrorDefault);
return dbRow;
}
...
break;
// 5.4. Validation keywords for objects
default:
if (depth <= 0) {
break;
}
// recurse dbRowRandomCreate
value = local.dbRowRandomCreate({
depth: depth - 1,
modeNotRandom: opt.modeNotRandom,
prefix: [
"schema<" + JSON.stringify(schemaP) + ">"
],
schema: schemaP
});
...
fsRmrfSync = function (dir) {
/*
* this function will sync "rm -rf" <dir>
*/
let child_process;
try {
child_process = require("child_process");
} catch (ignore) {
return;
}
child_process.spawnSync("rm", [
"-rf", dir
], {
stdio: [
"ignore", 1, 2
]
});
}
n/a
fsWriteFileWithMkdirpSync = function (file, data) {
/*
* this function will sync write <data> to <file> with "mkdir -p"
*/
let fs;
try {
fs = require("fs");
} catch (ignore) {
return;
}
// try to write file
try {
fs.writeFileSync(file, data);
} catch (ignore) {
// mkdir -p
require("child_process").spawnSync(
"mkdir",
[
"-p", require("path").dirname(file)
],
{
stdio: [
"ignore", 1, 2
]
}
);
// rewrite file
fs.writeFileSync(file, data);
}
}
n/a
functionOrNop = function (fnc) {
/*
* this function will if <fnc> exists,
* return <fnc>,
* else return <nop>
*/
return fnc || local.nop;
}
n/a
idDomElementCreate = function (seed) {
/*
* this function will create a deterministic and unique dom-element id
* from <seed> that is both dom-selector and url friendly
*/
local.idDomElementDict[seed] = (local.idDomElementDict[seed] || 0) + 1;
return encodeURIComponent(
seed + "_" + local.idDomElementDict[seed]
).replace((
/\W/g
), "_");
}
...
swaggerJson.resourceDict[tag] || swaggerJson.tagDict[tag],
{
description: "no description",
name: tag
}
);
resource = swaggerJson.resourceDict[tag];
resource.id = resource.id || local.idDomElementCreate(
"swgg_id_" + tag
);
resource.summary = resource.summary || String(
resource.description
).replace((
/\bhttps?:\/\/[^\s<]+[^<.,:;"')\]\s]/g
), "");
...
idNameInit = function (opt) {
/*
* this function will init <opt>.idBackend, <opt>.idName, and <opt>.queryById
*/
let idBackend;
let idName;
// init idName
idName = opt.crudType[1] || "id";
opt.idName = idName;
// init idBackend
idBackend = opt.crudType[2] || opt.idName;
opt.idBackend = idBackend;
// invert queryById
if (opt.modeQueryByIdInvert) {
idBackend = opt.idName;
idName = opt.idBackend;
}
// init queryById
opt.idValue = (opt.data && opt.data[idBackend]) || opt.idValue;
opt.queryById = {};
opt.queryById[idName] = opt.idValue;
return opt;
}
...
that._crudType = that._crudType || key.slice(2);
that._crudType[0] = that._crudType[0] || that.operationId;
// init _fileUploadNumber
that._fileUploadNumber = Number(
that._crudType[0] === "fileUploadManyByForm" && that._crudType[1]
) || 1;
// init _idBackend and _idName
tmp = local.idNameInit({
crudType: that._crudType
});
that._idBackend = tmp.idBackend;
that._idName = tmp.idName;
// init tags
that.tags = that.tags || [];
that.tags[0] = that.tags[0] || key[1];
...
middlewareBodyParse = function (req, res, next) {
/*
* this function will run middleware to parse <req>.bodyRaw
*/
let boundary;
let crlf;
let data;
let headerParse;
let ii;
let jj;
let name;
// if req is already parsed, then goto next
if (!req.swgg.operation || !local.isNullOrUndefined(req.swgg.bodyParsed)) {
next();
return;
}
headerParse = function () {
local.bufferToUtf8(req.bodyRaw.slice(ii, ii + 1024)).replace((
/^content-disposition:\u0020?form-data;(.+?)\r\n(?:content-type:\u0020?(.*?)$)?/im
), function (ignore, match1, match2) {
data = {
contentType: match2,
name: ""
};
match1.replace((
/(\w+)="([^"]+)/g
), function (ignore, match1, match2) {
data[match1.toLowerCase()] = match2;
});
name = data.name;
req.swgg.bodyMeta[name] = data;
});
};
switch (req.swgg.operation._consumes0) {
// parse application/x-www-form-urlencoded, e.g.
// aa=hello%20world&bb=bye%20world
case "application/x-www-form-urlencoded":
req.swgg.bodyParsed = local.bufferToUtf8(req.bodyRaw);
req.swgg.bodyParsed = local.urlParse(
"?" + req.swgg.bodyParsed,
true
).query;
break;
case "application/xml":
req.swgg.bodyParsed = {};
local.bufferToUtf8(req.bodyRaw).replace((
/<(.+?)><!\[CDATA\[([\S\s]+?)\]\]>/g
), function (name, match1, value) {
name = match1;
name = decodeURIComponent(name);
req.swgg.bodyParsed[name] = (
local.schemaPType(
req.swgg.operation._schemaPDict[name]
) === "string"
? value
: JSON.parse(value)
);
});
break;
/*
* parse multipart/form-data, e.g.
* --Boundary\r\n
* Content-Disposition: form-data; name="key"\r\n
* \r\n
* value\r\n
* --Boundary\r\n
* Content-Disposition: form-data; name="input1"; filename="file1.png"\r\n
* Content-Type: image/jpeg\r\n
* \r\n
* <data1>\r\n
* --Boundary\r\n
* Content-Disposition: form-data; name="input2"; filename="file2.png"\r\n
* Content-Type: image/jpeg\r\n
* \r\n
* <data2>\r\n
* --Boundary--\r\n
* https://tools.ietf.org/html/rfc7578
*/
case "multipart/form-data":
req.swgg.bodyParsed = {};
req.swgg.bodyMeta = {};
crlf = new Uint8Array([
0x0d, 0x0a
]);
// init boundary
ii = 0;
jj = local.bufferIndexOfSubBuffer(req.bodyRaw, crlf, ii);
if (jj <= 0) {
break;
}
boundary = local.bufferConcat([
crlf, req.bodyRaw.slice(ii, jj)
]);
ii = jj + 2;
while (true) {
jj = local.bufferIndexOfSubBuffer(
req.bodyRaw,
boundary,
ii
);
if (jj < 0) {
break;
}
headerParse();
ii = local.bufferIndexOfSubBuffer(
req.bodyRaw,
[
0x0d, 0x0a, 0x0d, 0x0a
],
ii + 2
) + 4;
data = req.bodyRaw.slice(ii, jj);
req.swgg.bodyParsed[name] = data;
ii = jj + boundary.length + 2;
}
break;
default:
req.swgg.bodyParsed = local.bufferToUtf8(req.bodyRaw);
// try to JSON.parse the string
local.tryCatchOnError(function () {
req.swgg.bodyParsed = JSON.parse(req.swgg.bodyParsed);
}, local.nop);
}
next(null, req, res);
}
n/a
middlewareCrudBuiltin = function (req, res, next) {
/*
* this function will run middleware to
* run the builtin crud-operations backed by db-lite
*/
let crud;
let onParallel;
let opt;
let tmp;
let user;
opt = {};
local.gotoNext(opt, function (err, data, meta) {
switch (opt.gotoState) {
case 1:
crud = req.swgg.crud;
user = req.swgg.user;
switch (crud.crudType[0]) {
case "crudCountManyByQuery":
crud.dbTable.crudCountManyByQuery(
crud.queryWhere,
opt.gotoNext
);
break;
case "crudSetManyById":
crud.dbTable.crudSetManyById(crud.body, opt.gotoNext);
break;
case "crudSetOneById":
// replace idName with idBackend in body
delete crud.body.id;
delete crud.body[crud.idName];
crud.body[crud.idBackend] = crud.data[crud.idName];
crud.dbTable.crudSetOneById(crud.body, opt.gotoNext);
break;
case "crudUpdateOneById":
// replace idName with idBackend in body
delete crud.body.id;
delete crud.body[crud.idName];
crud.body[crud.idBackend] = crud.data[crud.idName];
crud.dbTable.crudUpdateOneById(crud.body, opt.gotoNext);
break;
// hack-istanbul - test err handling-behavior
case "crudErrorDelete":
case "crudErrorGet":
case "crudErrorHead":
case "crudErrorOptions":
case "crudErrorPatch":
case "crudErrorPost":
case "crudErrorPut":
opt.gotoNext(local.errDefault);
break;
case "crudGetManyByQuery":
onParallel = local.onParallel(opt.gotoNext);
onParallel.counter += 1;
crud.dbTable.crudGetManyByQuery({
fieldList: crud.queryFields,
limit: crud.queryLimit,
query: crud.queryWhere,
skip: crud.querySkip,
sort: crud.querySort
}, function (err, data) {
crud.queryData = data;
onParallel(err);
});
onParallel.counter += 1;
crud.dbTable.crudCountAll(function (err, data) {
crud.paginationCountTotal = data;
onParallel(err);
});
break;
case "crudGetOneById":
crud.dbTable.crudGetOneById(crud.queryById, opt.gotoNext);
break;
case "crudGetOneByQuery":
crud.dbTable.crudGetOneByQuery({
query: crud.queryWhere
}, opt.gotoNext);
break;
case "crudNullDelete":
case "crudNullGet":
case "crudNullHead":
case "crudNullOptions":
case "crudNullPatch":
case "crudNullPost":
case "crudNullPut":
opt.gotoNext();
break;
case "crudRemoveManyByQuery":
crud.dbTable.crudRemoveManyByQuery(
crud.queryWhere,
opt.gotoNext
);
break;
case "crudRemoveOneById":
crud.dbTable.crudRemoveOneById(crud.queryById, opt.gotoNext);
break;
case "fileGetOneById":
local.dbTableFile = local.db.dbTableCreateOne({
name: "File"
});
crud.dbTable.crudGetOneById(crud.queryById, opt.g...
n/a
middlewareCrudCustom = function (req, response, nextMiddleware) {
/*
* this function will run the middleware to run custom-crud-operations
*/
let crud;
let opt;
let result;
opt = {};
local.gotoNext(opt, function (err, data) {
switch (opt.gotoState) {
case 1:
crud = req.swgg.crud;
switch (crud.crudType[0]) {
// hack-istanbul - test err handling-behavior
case "crudErrorPre":
opt.gotoNext(local.errDefault);
return;
case "getInventory":
crud.dbTable.crudGetManyByQuery({
query: {},
projection: [
"status"
]
}, opt.gotoNext);
break;
default:
opt.gotoState = Infinity;
opt.gotoNext();
}
break;
case 2:
switch (crud.crudType[0]) {
case "getInventory":
result = {};
data.forEach(function (element) {
result[element.status] = result[element.status] || 0;
result[element.status] += 1;
});
opt.gotoNext(null, result);
break;
}
break;
case 3:
local.swgg.serverRespondJsonapi(req, response, err, data);
break;
default:
nextMiddleware(err, data);
}
});
opt.gotoState = 0;
opt.gotoNext();
}
n/a
middlewareCrudEnd = function (req, res, next) {
/*
* this function will run middleware to end builtin crud-operations
*/
if (req.swgg.crud.endArgList) {
local.serverRespondJsonapi.apply(null, req.swgg.crud.endArgList);
return;
}
next(null, req, res);
}
n/a
middlewareInitCustom = function (req, response, nextMiddleware) {
/*
* this function will run the middleware to custom-init <req> and <res>
*/
// enable cors
// https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
response.setHeader(
"Access-Control-Allow-Methods",
"DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT"
);
response.setHeader("Access-Control-Allow-Origin", "*");
// init content-type
response.setHeader("Content-Type", "application/json; charset=UTF-8");
// ignore .map files
if (req.urlParsed.pathname.slice(-4) === ".map") {
local.serverRespondDefault(req, response, 404);
return;
}
nextMiddleware();
}
n/a
middlewareRouter = function (req, res, next) {
/*
* this function will run middleware to
* map the req's method-path to swagger's tags[0]-crudType
*/
let tmp;
// init swgg object
local.objectSetDefault(req, {
swgg: {
crud: {
crudType: []
},
user: {}
}
}, 3);
// if req.url is not prefixed with swaggerJsonBasePath,
// then default to next
if (req.urlParsed.pathname.indexOf(local.swaggerJsonBasePath) !== 0) {
next();
return;
}
// init methodPath
req.swgg.methodPath = (
req.method + " "
+ req.urlParsed.pathname.replace(local.swaggerJsonBasePath, "")
);
// init operation
while (req.swgg.methodPath !== tmp) {
req.swgg.operation = (
local.apiDict[req.swgg.methodPath]
// handle /foo/{id}/bar case
|| local.apiDict[req.swgg.methodPath.replace((
/\/[^\/]+\/([^\/]*?)$/
), "/{}/$1")]
);
// if operation exists, then break
if (req.swgg.operation) {
req.swgg.operation = local.jsonCopy(req.swgg.operation);
// init crud.crudType
req.swgg.crud.crudType = req.swgg.operation._crudType;
break;
}
tmp = req.swgg.methodPath;
// handle /foo/{id} case
req.swgg.methodPath = req.swgg.methodPath.replace((
/\/[^\/]+?(\/*?)$/
), "/$1{}");
}
next(null, req, res);
}
n/a
middlewareUserLogin = function (req, res, next) {
/*
* this function will run middleware to handle user login
*/
let crud;
let opt;
let user;
opt = {};
local.gotoNext(opt, function (err, data) {
switch (opt.gotoState) {
case 1:
local.dbTableUser = local.db.dbTableCreateOne({
name: "User"
});
crud = req.swgg.crud;
user = {};
req.swgg.user = user;
user.jwtEncrypted = (
req.headers.authorization
&& req.headers.authorization.replace("Bearer ", "")
);
user.jwtDecrypted = local.jwtAes256GcmDecrypt(user.jwtEncrypted);
switch (crud.crudType[0]) {
// hack-istanbul - test err handling-behavior
case "crudErrorLogin":
opt.gotoNext(local.errDefault);
return;
case "userLoginByPassword":
user.password = req.urlParsed.query.password;
user.username = req.urlParsed.query.username;
if (user.password && user.username) {
local.dbTableUser.crudGetOneById({
username: user.username
}, opt.gotoNext);
return;
}
break;
default:
if (user.jwtDecrypted.sub) {
// init username
user.username = user.jwtDecrypted.sub;
local.dbTableUser.crudGetOneById({
username: user.username
}, opt.gotoNext);
return;
}
}
opt.gotoState = Infinity;
opt.gotoNext();
break;
case 2:
switch (crud.crudType[0]) {
case "userLoginByPassword":
user.data = data;
if (!local.sjclHashScryptValidate(
user.password,
user.data && user.data.password
)) {
opt.gotoState = Infinity;
opt.gotoNext();
return;
}
// init isAuthenticated
user.isAuthenticated = true;
// create JSON Web Token (JWT)
// https://tools.ietf.org/html/rfc7519
user.jwtDecrypted = {};
user.jwtDecrypted.sub = user.data.username;
// update jwtEncrypted in client
user.jwtEncrypted = local.jwtAes256GcmEncrypt(
user.jwtDecrypted
);
local.serverRespondHeadSet(req, res, null, {
"swgg-jwt-encrypted": user.jwtEncrypted
});
// update jwtEncrypted in dbTableUser
local.dbTableUser.crudUpdateOneById({
jwtEncrypted: user.jwtEncrypted,
username: user.jwtDecrypted.sub
}, opt.gotoNext);
return;
default:
data = data || {};
user.data = data;
if (data.jwtEncrypted) {
// init isAuthenticated
user.isAuthenticated = true;
// update jwtEncrypted in client
if (data.jwtEncrypted !== user.jwtEncrypted) {
user.jwtEncrypted = data.jwtEncrypted;
user.jwtDecrypted = local.jwtAes256GcmDecrypt(
user.jwtEncrypted
);
local.serverRespondHeadSet(req, res, null, {
"swgg-jwt-encrypted": user.jwtEncrypted
});
}
}
}
opt.gotoNext();
break;
default:
next(err);
}
});
op...
n/a
middlewareValidate = function (req, res, next) {
/*
* this function will run middleware to validate the swagger-<req>
*/
let crud;
let opt;
let tmp;
opt = {};
local.gotoNext(opt, function (err) {
switch (opt.gotoState) {
case 1:
if (!req.swgg.operation) {
opt.gotoState = Infinity;
opt.gotoNext();
return;
}
// init paramDict
req.swgg.paramDict = {};
// parse path param
tmp = req.urlParsed.pathname.replace(
local.swaggerJsonBasePath,
""
).split("/");
req.swgg.operation._path.split("/").forEach(function (key, ii) {
if ((
/^\{\S*?\}$/
).test(key)) {
req.swgg.paramDict[key.slice(1, -1)] = (
decodeURIComponent(tmp[ii])
);
}
});
req.swgg.operation.parameters.forEach(function (schemaP) {
switch (schemaP.in) {
// parse body param
case "body":
req.swgg.paramDict[schemaP.name] = (
req.swgg.bodyParsed
|| undefined
);
break;
// parse formData param
case "formData":
switch (req.swgg.operation._consumes0) {
case "application/x-www-form-urlencoded":
case "application/xml":
req.swgg.paramDict[schemaP.name] = (
req.swgg.bodyParsed[schemaP.name]
);
break;
}
break;
// parse header param
case "header":
req.swgg.paramDict[schemaP.name] = (
req.headers[schemaP.name.toLowerCase()]
);
break;
// parse query param
case "query":
req.swgg.paramDict[schemaP.name] = (
req.urlParsed.query[schemaP.name]
);
break;
}
// parse array-multi
tmp = req.swgg.paramDict[schemaP.name];
if (
tmp
&& local.schemaPType(schemaP) === "array"
&& schemaP.collectionFormat === "multi"
) {
req.swgg.paramDict[schemaP.name] = (
encodeURIComponent(schemaP.name)
+ "=" + (
Array.isArray(tmp)
? tmp
: [
tmp
]
).join("&" + encodeURIComponent(schemaP.name) + "=")
);
}
// init default
if (
local.isNullOrUndefined(req.swgg.paramDict[schemaP.name])
&& schemaP.default !== undefined
) {
req.swgg.paramDict[schemaP.name] = local.jsonCopy(
schemaP.default
);
}
});
// normalize paramDict
local.normalizeSwaggerParamDict(req.swgg);
// validate paramDict
err = local.swaggerValidateDataParameters({
data: req.swgg.paramDict,
prefix: [
"operation", req.swgg.methodPath
],
parameters: req.swgg.operation.parameters,
swaggerJson: local.swaggerJson
})[0];
op...
n/a
nop = function () {
/*
* this function will do nothing
*/
return;
}
...
data,
errorType: "itemEnum",
prefix: opt.prefix,
schema,
tmp
});
// 5.5.2. type
local.nop();
// 5.5.3. allOf
local.valueOrEmptyList(schema.allOf).forEach(function (element) {
// recurse - schema.allOf
local.swaggerValidateDataSchema({
data,
prefix: opt.prefix,
modeSchema: opt.modeSchema,
...
normalizeSwaggerJson = function (swaggerJson, opt) {
/*
* this function will normalize swaggerJson and filter $npm_package_swggTags0
*/
let pathDict;
let tmp;
opt = local.objectSetDefault(opt, {
objectSetDescription: function (dict) {
if (
dict
&& dict.description
&& Array.isArray(dict["x-swgg-descriptionLineList"])
) {
delete dict.description;
}
}
});
local.objectSetDefault(swaggerJson, {
paths: {},
tags: []
});
// fix err - semanticPaths2
pathDict = {};
Object.keys(swaggerJson.paths).forEach(function (path) {
tmp = path.replace((
/\{.*?\}/g
), "{}");
pathDict[tmp] = pathDict[tmp] || {};
pathDict[tmp][path] = true;
});
Object.keys(pathDict).forEach(function (key) {
Object.keys(pathDict[key]).sort().forEach(function (path, ii) {
// fix err.semanticUniquePath
if (ii && swaggerJson["x-swgg-fixErrorSemanticUniquePath"]) {
swaggerJson.paths[path + "#" + ii] = swaggerJson.paths[path];
delete swaggerJson.paths[path];
}
});
});
Object.keys(swaggerJson.paths).forEach(function (path) {
Object.keys(swaggerJson.paths[path]).forEach(function (method) {
tmp = swaggerJson.paths[path][method];
// auto-create operationId from path
if (
swaggerJson["x-swgg-operationIdFromPath"]
|| tmp["x-swgg-operationIdFromPath"]
|| !tmp.operationId
) {
tmp.operationId = local.operationIdFromAjax({
method,
url: path
});
}
// normalize parameter.required
local.valueOrEmptyList(
tmp.parameters
).forEach(function (schemaP) {
if (schemaP.required === false) {
delete schemaP.required;
}
});
});
});
// override tag.description with x-swgg-tags0-override
if (swaggerJson["x-swgg-tags0-override"]) {
swaggerJson.tags.forEach(function (tag) {
tmp = local.objectSetDefault(
swaggerJson["x-swgg-tags0-override"][tag.name],
{
description: tag.description,
"x-swgg-descriptionLineList": (
tag["x-swgg-descriptionLineList"]
)
}
);
tag.description = tmp.description;
tag["x-swgg-descriptionLineList"] = (
tmp["x-swgg-descriptionLineList"]
);
// objectSetDescription
opt.objectSetDescription(tmp);
opt.objectSetDescription(tag);
});
}
// apply opt.objectSetDescription
([
swaggerJson.externalDocs, swaggerJson.info
]).forEach(opt.objectSetDescription);
([
swaggerJson.definitions, swaggerJson.parameters, swaggerJson.responses
]).forEach(function (dict) {
Object.keys(dict || {}).forEach(function (key) {
tmp = dict[key];
if (dict === swaggerJson.definitions) {
tmp = tmp.properties || {};
Object.keys(tmp).forEach(function (key) {
opt.objectSetDescription(tmp[key]);
});
return;
}
opt.objectSetDescription(tmp);
});
});
Object.keys(swaggerJson.paths).forEach(function (path) {
Object.keys(swaggerJson.paths[path]).forEach(function (method) {
tmp = swaggerJson.paths[path][method];
opt.objectSetDescription(tmp);
local.valueOrEmptyList(
tmp.parameters
).forEach(o...
...
/*
* this function will update the swagger-api dict of api-calls
*/
let pathDict;
let tmp;
swaggerJson = swaggerJson || {};
// normalize swaggerJson
swaggerJson = local.normalizeSwaggerJson(swaggerJson, {
objectSetDescription: function (dict) {
if (typeof dict === "object" && dict && !dict.$ref) {
if (Array.isArray(dict["x-swgg-descriptionLineList"])) {
dict.description = (
dict["x-swgg-descriptionLineList"].join("\n")
);
}
...
normalizeSwaggerParamDict = function (opt) {
/*
* this function will parse the <opt> according to <opt>.operation.parameters
*/
let tmp;
opt.operation.parameters.forEach(function (schemaP) {
tmp = opt.paramDict[schemaP.name];
// init default
if (
!opt.modeNoDefault
&& (opt.modeDefault || schemaP.required)
&& local.isNullOrUndefined(tmp)
) {
tmp = local.jsonCopy(schemaP.default);
}
if (opt.modeDefault && local.isNullOrUndefined(tmp)) {
tmp = local.dbFieldRandomCreate({
modeNotRandom: true,
schemaP
});
}
// parse array
if (local.schemaPType(schemaP) === "array" && schemaP.in !== "body") {
if (typeof tmp === "string") {
switch (
schemaP.collectionFormat
|| schemaP["x-swgg-collectionFormat"]
) {
case "json":
local.tryCatchOnError(function () {
tmp = JSON.parse(tmp);
}, local.nop);
opt.paramDict[schemaP.name] = tmp;
return;
case "multi":
tmp = local.urlParse("?" + tmp, true).query[schemaP.name];
if (!Array.isArray(tmp)) {
tmp = [
tmp
];
}
break;
case "pipes":
tmp = tmp.split("|");
break;
case "ssv":
tmp = tmp.split(" ");
break;
case "tsv":
tmp = tmp.split("\t");
break;
// default to csv
default:
tmp = tmp.split(",");
}
if (local.schemaPItemsType(schemaP) !== "string") {
// try to JSON.parse the string
local.tryCatchOnError(function () {
tmp = tmp.map(function (element) {
return JSON.parse(element);
});
}, local.nop);
}
}
// JSON.parse paramDict
} else if (
local.schemaPType(schemaP) !== "file"
&& local.schemaPType(schemaP) !== "string"
&& (
typeof tmp === "string"
|| Object.prototype.toString.call(tmp) === "[object Uint8Array]"
)
) {
// try to JSON.parse the string
local.tryCatchOnError(function () {
tmp = JSON.parse(local.bufferToUtf8(tmp));
}, local.nop);
}
opt.paramDict[schemaP.name] = tmp;
});
return opt;
}
...
local.objectSetDefault(opt, {
data: "",
operation: that,
paramDict: {},
url: ""
});
if (opt.modeDefault) {
local.normalizeSwaggerParamDict(opt);
}
// try to validate paramDict
opt.err = local.swaggerValidateDataParameters({
// normalize paramDict
data: local.normalizeSwaggerParamDict({
modeNoDefault: opt.modeNoDefault,
operation: that,
...
objectAssignDefault = function (target, source) {
/*
* this function will if items from <target> are
* null, undefined, or empty-string,
* then overwrite them with items from <source>
*/
target = target || {};
Object.keys(source || {}).forEach(function (key) {
if (
target[key] === null
|| target[key] === undefined
|| target[key] === ""
) {
target[key] = target[key] || source[key];
}
});
return target;
}
...
evt.preventDefault();
break;
}
evt.stopPropagation();
local.uiEventListenerDict[evt.targetOnEvent.dataset.onevent](evt);
};
local.uiEventListenerDict = local.objectAssignDefault(
globalThis.domOnEventDelegateDict
);
local.uiEventListenerDict.onEventDomDb = local.db.onEventDomDb;
local.uiEventListenerDict.onEventInputTextareaChange = function (evt) {
/*
...
onErrorJsonapi = function (onError) {
/*
* this function will normalize err and data to jsonapi format,
* and pass them to onError
* http://jsonapi.org/format/#errors
* http://jsonapi.org/format/#document-structure-resource-objects
*/
return function (err, data, meta) {
data = [
err, data
].map(function (data, ii) {
// if no err occurred, then return
if (
(ii === 0 && !data)
// if data is already normalized, then return it
|| (data && data.meta && data.meta.isJsonapiResponse)
) {
return data;
}
// normalize data-list
if (!Array.isArray(data)) {
data = [
data
];
}
// normalize errList to contain non-null objects
if (!ii) {
data = data.errList || data;
// normalize errList to be non-empty
if (!data.length) {
data.push(null);
}
data = data.map(function (element) {
if (!(typeof element === "object" && element)) {
element = {
message: String(element)
};
}
// normalize errObj to plain json-object
return {
message: element.message,
name: element.name,
stack: element.stack,
statusCode: Number(element.statusCode) || 500
};
});
err = local.jsonCopy(data[0]);
err.errors = data;
return err;
}
return {
data
};
});
// init data.meta
data.forEach(function (data, ii) {
if (!data) {
return;
}
data.meta = local.jsonCopy(meta || {});
data.meta.isJsonapiResponse = true;
if (ii) {
data.meta.dataLength = data.data.length;
} else {
data.meta.errorsLength = data.errors.length;
}
data.meta.statusCode = (
Number(data.meta.statusCode)
|| Number(data.statusCode)
|| 0
);
});
onError(data[0], data[1]);
};
}
...
local.serverRespondJsonapi = function (req, res, err, data, meta) {
/*
* this function will respond in jsonapi format
* http://jsonapi.org/format/#errors
* http://jsonapi.org/format/#document-structure-resource-objects
*/
local.onErrorJsonapi(function (err, data) {
local.serverRespondHeadSet(req, res, err && err.statusCode, {
"Content-Type": "application/json"
});
if (err) {
// debug statusCode / method / url
local.errorMessagePrepend(
err,
...
operationIdFromAjax = function (opt) {
/*
* this function will create a sortable operationId
* from given ajax-<opt>
*/
let urlParsed;
urlParsed = local.urlParseWithBraket(opt.url);
return encodeURIComponent(
urlParsed.pathname + urlParsed.hash + " " + opt.method.toUpperCase()
).replace((
/[^\w\-.]/g
), "_");
}
...
tmp = swaggerJson.paths[path][method];
// auto-create operationId from path
if (
swaggerJson["x-swgg-operationIdFromPath"]
|| tmp["x-swgg-operationIdFromPath"]
|| !tmp.operationId
) {
tmp.operationId = local.operationIdFromAjax({
method,
url: path
});
}
// normalize parameter.required
local.valueOrEmptyList(
tmp.parameters
...
schemaPItems = function (schemaP) {
/*
* this function will return schemaP.items
*/
return schemaP["x-swgg-items"] || schemaP.items;
}
...
? 2
: 1
)) {
// recurse dbFieldRandomCreate
value.push(local.dbFieldRandomCreate({
depth: depth - 1,
modeNotRandom: opt.modeNotRandom,
schemaP: local.schemaPItems(schemaP)
}));
ii += 1;
}
break;
case "boolean":
value = (
opt.modeNotRandom
...
schemaPItemsType = function (schemaP) {
/*
* this function will return schemaP.items.type
*/
return local.schemaPType(local.schemaPItems(schemaP) || {});
}
...
opt[(
schemaP.in === "formData"
? "inForm"
: "inQuery"
)] += (
"&" + encodeURIComponent(schemaP.name) + "="
+ encodeURIComponent(
local.schemaPItemsType(schemaP) === "string"
? value
: JSON.stringify(value)
)
);
});
return;
case "pipes":
...
schemaPType = function (schemaP) {
/*
* this function will return schemaP.type
*/
return schemaP && (schemaP["x-swgg-type"] || schemaP.type);
}
...
delete schemaP.$ref;
});
// init _idName.format and _idName.type
if (that._schemaName && schemaP.name === that._idName) {
schemaP.format = swaggerJson.definitions[
that._schemaName
].properties[that._idBackend].format;
schemaP.type = local.schemaPType(
swaggerJson.definitions[
that._schemaName
].properties[that._idBackend]
);
}
// init _schemaPDict
that._schemaPDict[schemaP.name] = schemaP;
...
serverRespondJsonapi = function (req, res, err, data, meta) {
/*
* this function will respond in jsonapi format
* http://jsonapi.org/format/#errors
* http://jsonapi.org/format/#document-structure-resource-objects
*/
local.onErrorJsonapi(function (err, data) {
local.serverRespondHeadSet(req, res, err && err.statusCode, {
"Content-Type": "application/json"
});
if (err) {
// debug statusCode / method / url
local.errorMessagePrepend(
err,
res.statusCode + " " + req.method + " " + req.url + "\n"
);
// print err.stack to stderr
local.onErrorDefault(err);
}
data = err || data;
res.statusCode = data.meta.statusCode || res.statusCode;
data.meta.statusCode = res.statusCode;
res.end(JSON.stringify(data));
})(err, data, meta);
}
...
result[element.status] += 1;
});
opt.gotoNext(null, result);
break;
}
break;
case 3:
local.swgg.serverRespondJsonapi(req, response, err, data);
break;
default:
nextMiddleware(err, data);
}
});
opt.gotoState = 0;
opt.gotoNext();
...
swaggerJsonFromAjax = function (swaggerJson, opt) {
/*
* this function will update swaggerJson
* with definitions and paths created from given ajax-<opt>
*/
let data;
let isArray;
let operation;
let pathDict;
let type;
let upsertSchemaP;
let urlParsed;
upsertSchemaP = function (schemaP) {
if (!operation.parameters.some(function (element) {
if (element.in === schemaP.in && element.name === schemaP.name) {
[
"default", "items", "schema"
].forEach(function (key) {
if (!local.isNullOrUndefined(schemaP[key])) {
element[key] = schemaP[key];
}
});
return true;
}
})) {
operation.parameters.push(schemaP);
}
};
// init swaggerJson
swaggerJson = local.objectSetDefault(swaggerJson, {
basePath: "/",
definitions: {},
info: {
title: "",
version: ""
},
paths: {},
swagger: "2.0"
});
// init opt
opt = local.objectSetDefault(opt, {
headers: {},
method: "GET"
});
// init urlParsed
urlParsed = local.urlParseWithBraket(opt.url);
// init operation
operation = {
operationId: opt.operationId || local.operationIdFromAjax(opt),
parameters: [],
responses: {
default: {
description: "default response"
}
},
tags: opt.tags || [
"undefined"
],
"x-swgg-tags0": opt["x-swgg-tags0"]
};
if ((
/^(?:http|https):\/\//
).test(opt.url)) {
operation["x-swgg-host"] = urlParsed.host;
operation["x-swgg-schemes"] = [
urlParsed.protocol.slice(0, -1)
];
}
pathDict = {};
pathDict[urlParsed.pathname + urlParsed.hash] = {};
pathDict[urlParsed.pathname + urlParsed.hash][
opt.method.toLowerCase()
] = operation;
local.objectSetDefault(swaggerJson, {
paths: pathDict
}, 3);
// init param in header
Object.keys(opt.headers).forEach(function (key) {
upsertSchemaP({
default: opt.headers[key],
in: "header",
name: key,
type: "string"
});
});
// init param in path
urlParsed.pathname.replace((
/\{[^}]+?\}/g
), function (match0) {
match0 = match0.slice(1, -1);
upsertSchemaP({
default: match0,
in: "path",
name: match0,
required: true,
type: "string"
});
});
// init param in query
Object.keys(urlParsed.query).forEach(function (key) {
upsertSchemaP({
default: urlParsed.query[key],
in: "query",
name: key,
type: "string"
});
});
data = opt.data;
if (!data) {
return swaggerJson;
}
// init param in body - text-data
upsertSchemaP({
in: "body",
name: "body",
schema: {
type: "string"
}
});
local.tryCatchOnError(function () {
data = JSON.parse(data);
}, local.nop);
if (typeof data !== "object") {
return swaggerJson;
}
// init param in body - json-data
isArray = Array.isArray(data);
type = local.swaggerJsonFromPostBody(swaggerJson, {
data: (
isArray
? data[0]
: data
),
depth: 2,
key: "body",
prefix: operation.operationId,
"x-swgg-tags0": opt["x-swgg-tags0"]
});
upsertSchemaP({
in: "body",
name: "body",...
...
case "-X":
opt.method = arg;
return;
}
if (arg === "curl") {
if (opt) {
opt.url = opt.url || argList[ii - 1];
swaggerJson = local.swaggerJsonFromAjax(swaggerJson, opt);
}
opt = {
headers: {},
method: "GET"
};
}
if ((
...
swaggerJsonFromCurl = function (swaggerJson, text) {
/*
* this function will update swaggerJson
* with definitions and paths created from given curl-command-text
*/
let arg;
let argList;
let doubleBackslash;
let opt;
let quote;
arg = "";
argList = [];
doubleBackslash = local.stringUniqueKey(text);
// parse doubleBackslash
text = text.replace((
/\\\\/g
), doubleBackslash);
// parse line-continuation
text = text.replace((
/\\\n/g
), "");
// parse quotes
text.replace((
/(\s*?)(\S+)/g
), function (match0, line, word) {
line = match0;
word.replace((
/^(["']?).*?(?:\\")?(["']?)$/
), function (quote1, match1, quote2) {
quote1 = match1;
if (quote) {
arg += line;
} else {
arg = word;
quote = quote1;
}
if (!quote || quote === quote2) {
switch (quote) {
// parse escapes in single-quotes
case "'":
arg = arg.replace((
/'"'"'/g
), "'");
arg = arg.slice(1, -1);
break;
// parse escapes in double-quotes
// https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html
case "\"":
arg = arg.replace((
/\\([$`"\n])/g
), "$1");
arg = arg.slice(1, -1);
break;
}
argList.push(arg);
arg = "";
quote = "";
}
});
});
// un-parse doubleBackslash
argList = argList.map(function (arg) {
return arg.replace(new RegExp(doubleBackslash, "g"), "\\\\");
});
argList.push("curl");
argList.forEach(function (arg, ii) {
switch (argList[ii - 1]) {
case "--data":
case "--data-ascii":
case "--data-binary":
case "--data-raw":
case "-d":
opt.data = arg;
return;
case "--header":
case "-H":
arg = arg.split(":");
arg[1] = arg.slice(1).join(":").trim();
opt.headers[arg[0].toLowerCase()] = arg[1];
return;
case "--request":
case "-X":
opt.method = arg;
return;
}
if (arg === "curl") {
if (opt) {
opt.url = opt.url || argList[ii - 1];
swaggerJson = local.swaggerJsonFromAjax(swaggerJson, opt);
}
opt = {
headers: {},
method: "GET"
};
}
if ((
/^(?:http|https):\/\//
).test(arg)) {
opt.url = arg;
}
});
return swaggerJson;
}
...
opt.gotoNext();
};
local.testCase_swaggerJsonFromCurl_default = function (opt, onError) {
/*
* this function will test swaggerJsonFromCurl's default handling-behavior
*/
opt = local.swaggerJsonFromCurl(
/* jslint ignore:start */
null,
'\
# test no-data handling-behavior\n\
curl https://example.com\n\
# test json-object-data handling-behavior\n\
curl --data {} https://example.com/json\n\
...
swaggerJsonFromPostBody = function (swaggerJson, opt) {
/*
* this function will update swaggerJson
* with definitions created from the post-body-data
*/
let definition;
let isArray;
let prefix;
let schemaP;
let type;
let value;
prefix = opt.prefix + "." + encodeURIComponent(opt.key);
definition = {
properties: {},
"x-swgg-tags0": opt["x-swgg-tags0"]
};
swaggerJson.definitions[prefix] = definition;
Object.keys(opt.data).forEach(function (key) {
value = opt.data[key];
isArray = Array.isArray(value);
if (isArray) {
value = value[0];
}
type = (
local.isNullOrUndefined(value)
? "string"
: typeof value
);
schemaP = (
isArray
? {
default: opt.data[key],
items: {
type
},
type: "array"
}
: {
default: value,
type
}
);
definition.properties[key] = schemaP;
if (!(type === "object" && opt.depth > 1)) {
return;
}
// recurse
type = local.swaggerJsonFromPostBody(swaggerJson, {
data: value,
depth: opt.depth - 1,
key,
prefix,
"x-swgg-tags0": opt["x-swgg-tags0"]
});
if (isArray) {
schemaP.items = type;
} else {
definition.properties[key] = type;
}
});
return {
$ref: "#/definitions/" + prefix
};
}
...
data = JSON.parse(data);
}, local.nop);
if (typeof data !== "object") {
return swaggerJson;
}
// init param in body - json-data
isArray = Array.isArray(data);
type = local.swaggerJsonFromPostBody(swaggerJson, {
data: (
isArray
? data[0]
: data
),
depth: 2,
key: "body",
...
swaggerValidate = function (swaggerJson) {
/*
* this function will validate the json-object swaggerJson
*/
let operation;
let operationIdDict;
let pathDict;
let prefix;
let test;
let tmp;
operationIdDict = {};
swaggerJson = swaggerJson || {};
local.swaggerValidateDataSchema({
data: swaggerJson,
modeSchema: true,
prefix: [
"swaggerJson"
],
schema: local.swaggerSchemaJson,
swaggerJson
});
pathDict = {};
Object.keys(swaggerJson.paths).forEach(function (path) {
prefix = [
"swaggerJson", "paths", path
];
// validate semanticPaths1
test = path.indexOf("?") < 0;
local.throwSwaggerError(!test && {
errorType: "semanticPaths1",
prefix
});
tmp = path.replace((
/\{.*?\}/g
), "{}");
// validate semanticPaths2
test = !pathDict[tmp];
local.throwSwaggerError(!test && {
errorType: "semanticPaths2",
pathList: [
pathDict[tmp], path
],
prefix
});
pathDict[tmp] = path;
// validate semanticPaths3
tmp = {};
path.replace((
/\{.*?\}/g
), function (match0) {
test = !tmp[match0];
local.throwSwaggerError(!test && {
errorType: "semanticPaths3",
name: match0,
prefix
});
tmp[match0] = true;
});
// validate semanticPaths5
test = path.indexOf("{}") < 0;
local.throwSwaggerError(!test && {
errorType: "semanticPaths5",
prefix
});
});
// validate swaggerJson.definitions[key].properties[ii].default
Object.keys(swaggerJson.definitions || {}).forEach(function (schemaName) {
tmp = local.swaggerValidateDataSchema({
// dereference definition
modeDereference: true,
prefix: [
"swaggerJson", "definitions", schemaName
],
schema: swaggerJson.definitions[schemaName],
swaggerJson
});
Object.keys(tmp.properties || {}).forEach(function (key) {
local.swaggerValidateDataSchema({
modeDefault: true,
prefix: [
"swaggerJson", "definitions", schemaName, "properties", key
],
schema: tmp.properties[key],
swaggerJson
});
});
});
// validate swaggerJson.parameters[key].default
Object.keys(swaggerJson.parameters || []).forEach(function (key) {
local.swaggerValidateDataSchema({
modeDefault: true,
prefix: [
"swaggerJson", "parameters", key
],
schema: swaggerJson.parameters[key],
swaggerJson
});
});
// validate swaggerJson.paths[key][key].parameters[ii].default
Object.keys(swaggerJson.paths).forEach(function (path) {
Object.keys(swaggerJson.paths[path]).forEach(function (method) {
prefix = [
"swaggerJson", "paths", path, method
];
operation = local.swaggerValidateDataSchema({
// dereference operation
modeDereference: true,
prefix,
schema: swaggerJson.paths[path][method],
swaggerJson
});
// validate semanticOperationIds1
test = !operationIdDict[operation.operationId];
local.throwSwaggerError(!test && {
data: operation.operationId,
errorType: "semanticOperationIds1",
prefix: prefix.conc...
...
paths: pathDict
}, 3);
});
// normalize swaggerJson
local.swaggerJson = JSON.parse(local.jsonStringifyOrdered(swaggerJson));
// try to validate swaggerJson
local.tryCatchOnError(function () {
local.swaggerValidate(local.swaggerJson);
}, local.onErrorDefault);
// init corsForwardProxyHost
local.corsForwardProxyHost = (
local.corsForwardProxyHost
|| local.swaggerJson["x-swgg-corsForwardProxyHost"]
);
// init assets.swgg.swagger.server.json
...
swaggerValidateDataParameters = function (opt) {
/*
* this function will validate the items in <opt>.paramDict
* against the schemaP's in <opt>.parameters
*/
let errList;
errList = [];
opt.parameters.forEach(function (schemaP) {
local.tryCatchOnError(function () {
local.swaggerValidateDataSchema({
data: opt.data[schemaP.name],
dataReadonlyRemove: [
opt.dataReadonlyRemove || {},
schemaP.name,
opt.dataReadonlyRemove
&& opt.dataReadonlyRemove[schemaP.name]
],
prefix: opt.prefix.concat([
schemaP.name
]),
schema: schemaP,
swaggerJson: local.swaggerJson
});
}, function (errCaught) {
console.error(errCaught.message);
errList.push(errCaught);
errCaught.errList = errList;
});
});
return errList;
}
...
paramDict: {},
url: ""
});
if (opt.modeDefault) {
local.normalizeSwaggerParamDict(opt);
}
// try to validate paramDict
opt.err = local.swaggerValidateDataParameters({
// normalize paramDict
data: local.normalizeSwaggerParamDict({
modeNoDefault: opt.modeNoDefault,
operation: that,
paramDict: local.jsonCopy(opt.paramDict)
}).paramDict,
dataReadonlyRemove: opt.paramDict,
...
swaggerValidateDataSchema = function (opt) {
/*
* this function will validate <opt>.data against the swagger <opt>.schema
* http://json-schema.org/draft-04/json-schema-validation.html#rfc.section.5
*/
let $ref;
let circularSet;
let data;
let dataReadonlyRemove2;
let ii;
let list;
let oneOf;
let schema;
let test;
let tmp;
if (!opt.schema) {
return;
}
data = opt.data;
opt.dataReadonlyRemove = opt.dataReadonlyRemove || [
{}, "", null
];
dataReadonlyRemove2 = opt.dataReadonlyRemove[2] || {};
schema = opt.schema;
circularSet = new Set();
while (true) {
// dereference schema.schema
while (schema.schema) {
schema = schema.schema;
}
// dereference schema.oneOf
oneOf = (data && schema.oneOf) || [];
ii = 0;
while (ii < oneOf.length) {
tmp = String(oneOf[ii] && oneOf[ii].$ref).replace(
"http://json-schema.org/draft-04/schema#",
"#"
);
switch (
tmp + " " + (!local.isNullOrUndefined(data.$ref) || data.in)
) {
case "#/definitions/bodyParameter body":
case "#/definitions/formDataParameterSubSchema formData":
case "#/definitions/headerParameterSubSchema header":
case "#/definitions/jsonReference true":
case "#/definitions/pathParameterSubSchema path":
case "#/definitions/queryParameterSubSchema query":
schema = local.swaggerSchemaJson.definitions[tmp.split("/")[2]];
break;
default:
switch (tmp) {
case "#/definitions/bodyParameter":
case "#/definitions/jsonReference":
schema = oneOf[ii ^ 1];
break;
}
}
if (!schema.oneOf) {
break;
}
ii += 1;
}
// dereference schema.$ref
$ref = schema && schema.$ref;
if (!$ref) {
break;
}
test = !circularSet.has($ref);
local.throwSwaggerError(!test && {
data,
errorType: "schemaDereferenceCircular",
prefix: opt.prefix,
schema
});
circularSet.add($ref);
// validate semanticWalker6
test = (
$ref.indexOf("#/") === 0
|| $ref.indexOf("http://json-schema.org/draft-04/schema#/") === 0
);
local.throwSwaggerError(!test && {
data: $ref,
errorType: "semanticWalker6",
prefix: opt.prefix.concat([
"$ref"
])
});
switch (opt.modeSchema && $ref) {
case "http://json-schema.org/draft-04/schema#/definitions/parameter":
// validate semanticFormData1
test = data.in !== "formdata";
local.throwSwaggerError(!test && {
data: data.in,
errorType: "semanticFormData1",
prefix: opt.prefix.concat([
"in"
])
});
// validate semanticFormData3
test = data.type !== "file" || data.in === "formData";
local.throwSwaggerError(!test && {
data,
errorType: "semanticFormData3",
prefix: opt.prefix
});
// validate semanticParameters2
test = data.in === "body" || !local.isNullOrUndefined(data.type);
local.throwSwaggerError(!test && {
data,
errorType: "semanticParameters2...
...
local.swaggerJsonBasePath = (
local.swaggerJson.basePath === "/"
? ""
: local.swaggerJson.basePath
);
Object.keys(swaggerJson.definitions).forEach(function (schemaName) {
swaggerJson.definitions[schemaName] = local.jsonCopy(
local.swaggerValidateDataSchema({
// dereference definition
modeDereference: true,
prefix: [
"swaggerJson", "definitions", schemaName
],
schema: swaggerJson.definitions[schemaName],
swaggerJson: local.swaggerJson
...
swaggerValidateFile = function (opt, onError) {
/*
* this function will validate the json-file <opt>.file
*/
local.gotoNext(opt, function (err, data) {
switch (opt.gotoState) {
case 1:
if (typeof opt.data === "string") {
opt.gotoNext(null, opt.data);
return;
}
// fetch url
if ((
/^(?:http|https):\/\//
).test(opt.file)) {
local.ajax({
url: opt.file
}, function (err, xhr) {
opt.gotoNext(err, xhr && xhr.responseText);
});
return;
}
// read file
local.fs.readFile(opt.file, "utf8", opt.gotoNext);
break;
case 2:
// jslint
local.jslint.jslintAndPrint(data, opt.file);
local.assertOrThrow(
!local.jslint.jslintResult.errMsg,
local.jslint.jslintResult.errMsg.replace((
/\u001b\[\d*m/g
), "")
);
// validate
local.swgg.swaggerValidate(JSON.parse(data));
opt.gotoNext();
break;
default:
console.error(
err
? "\u001b[31mswagger-validate - failed - " + opt.file + "\n"
+ err.message + "\u001b[39m"
: "swagger-validate - passed - " + opt.file
);
onError(err);
}
});
opt.gotoState = 0;
opt.gotoNext();
}
...
// test url handling-behavior
file: local.serverLocalHost
+ "/assets.swgg.swagger.petstore.json"
}
]
}, function (opt2, onParallel) {
onParallel.counter += 1;
local.swgg.swaggerValidateFile(opt2.elem, function (err) {
// validate no err occurred
local.assertOrThrow(!err || opt2.elem.file === "error.json", err);
onParallel(null, opt);
});
}, onError);
};
...
throwSwaggerError = function (opt) {
/*
* this function will throw a swaggerError with given <opt>.errorType
*/
let err;
if (!opt) {
return;
}
[
0, 2
].forEach(function (ii) {
opt["prefix" + ii] = opt.prefix[ii] + opt.prefix.slice(
ii + 1
).map(function (element) {
return "[" + JSON.stringify(element) + "]";
}).join("");
});
opt.prefix0 += " = " + local.stringTruncate(
JSON.stringify(opt.data) || "undefined",
100
);
opt.schema2 = local.stringTruncate(
JSON.stringify(opt.schema) || "undefined",
500
);
opt.type2 = (opt.schema && local.schemaPType(opt.schema)) || "object";
if (opt.schema && opt.schema.format) {
opt.type2 += " (" + opt.schema.format + ")";
}
err = new Error("error." + opt.errorType + " - " + local.templateRender(
local.swaggerErrorTypeDict[opt.errorType],
opt,
{
notHtmlSafe: true
}
));
err.messageShort = local.templateRender(
local.swaggerErrorTypeDict[opt.errorType].replace(
"{{prefix0}}",
"{{prefix2}}"
),
opt,
{
notHtmlSafe: true
}
);
err.opt = opt;
err.statusCode = 400;
throw err;
}
...
pathDict = {};
Object.keys(swaggerJson.paths).forEach(function (path) {
prefix = [
"swaggerJson", "paths", path
];
// validate semanticPaths1
test = path.indexOf("?") < 0;
local.throwSwaggerError(!test && {
errorType: "semanticPaths1",
prefix
});
tmp = path.replace((
/\{.*?\}/g
), "{}");
// validate semanticPaths2
...
uiEventDelegate = function (evt) { // filter non-input keyup-evt evt.targetOnEvent = evt.target.closest( "[data-onevent]" ); if (!evt.targetOnEvent) { return; } // rate-limit keyup if (evt.type === "keyup") { local.uiEventDelegateKeyupEvent = evt; if (local.uiEventDelegateKeyupTimerTimeout !== 2) { local.uiEventDelegateKeyupTimerTimeout = ( local.uiEventDelegateKeyupTimerTimeout || setTimeout(function () { local.uiEventDelegateKeyupTimerTimeout = 2; local.uiEventDelegate(local.uiEventDelegateKeyupEvent); }, 100) ); return; } local.uiEventDelegateKeyupTimerTimeout = null; if (!evt.target.closest( "input, option, select, textarea" )) { return; } } switch (evt.targetOnEvent.tagName) { case "BUTTON": case "FORM": evt.preventDefault(); break; } evt.stopPropagation(); local.uiEventListenerDict[evt.targetOnEvent.dataset.onevent](evt); }
...
if (evt.type === "keyup") {
local.uiEventDelegateKeyupEvent = evt;
if (local.uiEventDelegateKeyupTimerTimeout !== 2) {
local.uiEventDelegateKeyupTimerTimeout = (
local.uiEventDelegateKeyupTimerTimeout
|| setTimeout(function () {
local.uiEventDelegateKeyupTimerTimeout = 2;
local.uiEventDelegate(local.uiEventDelegateKeyupEvent);
}, 100)
);
return;
}
local.uiEventDelegateKeyupTimerTimeout = null;
if (!evt.target.closest(
"input, option, select, textarea"
...
uiRenderSchemaP = function (schemaP) {
/*
* this function will render schemaP
*/
// init schemaP.id
schemaP.id = local.idDomElementCreate("swgg_id_" + schemaP.name);
// init enum
schemaP.enum2 = (
schemaP.enum
|| local.valueOrEmptyObject(local.schemaPItems(schemaP)).enum
|| (local.schemaPType(schemaP) === "boolean" && [
false, true
])
);
// init input - file
if (local.schemaPType(schemaP) === "file") {
schemaP.isFile = true;
// init input - textarea
} else if (schemaP.in === "body") {
schemaP.isTextarea = true;
// init input - select
} else if (schemaP.enum2) {
// init enumDefault
schemaP.enumDefault = [];
if (schemaP.required && schemaP.default !== undefined) {
schemaP.enumDefault = (
local.schemaPType(schemaP) === "array"
? schemaP.default
: [
schemaP.default
]
);
}
schemaP.isSelectMultiple = local.schemaPType(schemaP) === "array";
schemaP.selectOptionList = schemaP.enum2.map(function (element) {
// init hasDefault
schemaP.hasDefault = (
schemaP.hasDefault
|| schemaP.enumDefault.indexOf(element) >= 0
);
return {
id: local.idDomElementCreate("swgg_id_" + schemaP.name),
selected: (
schemaP.enumDefault.indexOf(element) >= 0
? "selected"
: ""
),
type: (
local.schemaPItemsType(schemaP)
|| local.schemaPType(schemaP)
),
placeholder: (
typeof element === "string"
? element
: JSON.stringify(element)
),
valueSelectOption: element
};
});
// init 'undefined' value
if (!schemaP.required && !schemaP.hasDefault) {
schemaP.selectOptionList.unshift({
id: local.idDomElementCreate("swgg_id_" + schemaP.name),
selected: "selected",
type: local.schemaPType(schemaP),
placeholder: "<none>",
valueSelectOption: "$swggUndefined"
});
}
// select at least one value
schemaP.selectOptionList.some(function (element, ii) {
if (ii === 0 || element.selected) {
element.selected = "selected";
if (ii !== 0) {
schemaP.selectOptionList[0].selected = "";
return true;
}
}
});
// init input - textarea
} else if (local.schemaPType(schemaP) === "array" || (
schemaP.format === "json"
&& local.schemaPType(schemaP) === "string"
)) {
schemaP.isTextarea = true;
// init input - number
} else if (schemaP.type === "integer" || schemaP.type === "number") {
schemaP.isInputNumber = true;
// init input - text
} else {
schemaP.isInputText = true;
}
// init format2 / type2
Array.from([
schemaP, schemaP.schema || {}
]).some(function (element) {
local.objectSetDefault(schemaP, {
format2: local.schemaPItemsType(element) || element.format,
type2: local.schemaPType(element)
});
return schemaP.type2;
});
schemaP.type2 = schemaP.type2 || "object";
// init schema2
Array.from([
schemaP,
local.schemaPItems(schemaP),
schemaP.schema,
schemaP.schema && local.schemaPItems(schemaP.schema)...
n/a
urlParseWithBraket = function (url) {
/*
* this function will urlParse the url with curly-brackets preserved
*/
let tmp;
tmp = local.stringUniqueKey(url);
return JSON.parse(JSON.stringify(
local.urlParse(url.replace((
/\{/g
), tmp + 1).replace((
/\}/g
), tmp + 2))
).replace(
new RegExp(tmp + 1, "g"),
"{"
).replace(
new RegExp(tmp + 2, "g"),
"}"
));
}
...
local.operationIdFromAjax = function (opt) {
/*
* this function will create a sortable operationId
* from given ajax-<opt>
*/
let urlParsed;
urlParsed = local.urlParseWithBraket(opt.url);
return encodeURIComponent(
urlParsed.pathname + urlParsed.hash + " " + opt.method.toUpperCase()
).replace((
/[^\w\-.]/g
), "_");
};
...
userLoginByPassword = function (opt, onError) {
/*
* this function will send a login-by-password req
*/
local.apiDict["GET /user/userLoginByPassword"].ajax({
paramDict: {
password: opt.password,
username: opt.username
}
}, onError);
}
...
// test userLogout's default handling-behavior
local.userLogout({}, gotoNext);
break;
case 2:
// validate err occurred
local.assertOrThrow(err, err);
// test userLoginByPassword's 401 handling-behavior
local.userLoginByPassword({
password: "undefined",
username: "undefined"
}, gotoNext);
break;
case 3:
// validate err occurred
local.assertOrThrow(err, err);
...
userLogout = function (opt, onError) {
/*
* this function will send a logout req
*/
local.apiDict["GET /user/userLogout"].ajax(opt, onError);
}
...
gotoNext = function (err, data) {
gotoState += 1;
switch (gotoState) {
case 1:
// cleanup userJwtEncrypted
delete local.userJwtEncrypted;
// test userLogout's default handling-behavior
local.userLogout({}, gotoNext);
break;
case 2:
// validate err occurred
local.assertOrThrow(err, err);
// test userLoginByPassword's 401 handling-behavior
local.userLoginByPassword({
password: "undefined",
...
value = function (val) {
/*
* this function will return <val>
*/
return val;
}
...
opt.headers.Authorization
|| "Bearer " + opt.jwtEncrypted
);
}
// init url
opt.url = "";
opt.url += (
local.value(
that["x-swgg-schemes"] || local.swaggerJson.schemes || []
)[0] || local.urlParse("").protocol.slice(0, -1)
);
opt.url += "://";
opt.url += (
that["x-swgg-host"]
|| local.swaggerJson.host
...
valueOrEmptyList = function (val) {
/*
* this function will return <val> or []
*/
return val || [];
}
...
"swaggerJson", "definitions", schemaName
],
schema: swaggerJson.definitions[schemaName],
swaggerJson: local.swaggerJson
})
);
tmp = swaggerJson.definitions[schemaName];
local.valueOrEmptyList(tmp.allOf).forEach(function (element) {
local.objectSetDefault(
tmp,
local.jsonCopy(local.swaggerValidateDataSchema({
// dereference definition.allOf
modeDereference: true,
prefix: [
"swaggerJson", "definitions", schemaName, "allOf"
...
valueOrEmptyObject = function (val) {
/*
* this function will return <val> or {}
*/
return val || {};
}
...
* this function will render schemaP
*/
// init schemaP.id
schemaP.id = local.idDomElementCreate("swgg_id_" + schemaP.name);
// init enum
schemaP.enum2 = (
schemaP.enum
|| local.valueOrEmptyObject(local.schemaPItems(schemaP)).enum
|| (local.schemaPType(schemaP) === "boolean" && [
false, true
])
);
// init input - file
if (local.schemaPType(schemaP) === "file") {
schemaP.isFile = true;
...
valueOrEmptyString = function (val) {
/*
* this function will return <val> or ""
*/
return val || "";
}
n/a
operationId._2Fx-test_2Ftags0Filter_20GET.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /x-test/tags0Filter"
* example usage:
swgg.apiDict["operationId._2Fx-test_2Ftags0Filter_20GET"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.addPet.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "POST /pet"
* example usage:
swgg.apiDict["operationId.addPet"].ajax({
"body": {
"category": {
"id": 0,
"name": "abcd1234"
},
"id": 1,
"name": "abcd1234",
"photoUrls": [
"abcd1234"
],
"status": "available",
"tags": [
{
"id": 0,
"name": "abcd1234"
}
]
}
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.createUser.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "POST /user"
* example usage:
swgg.apiDict["operationId.createUser"].ajax({
"body": {
"email": "a@a.com",
"firstName": "abcd1234",
"id": 1,
"jwtEncrypted": "abcd1234",
"lastName": "abcd1234",
"password": "abcd1234",
"phone": "abcd1234",
"userStatus": 0,
"username": "abcd1234"
}
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.createUsersWithArrayInput.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "POST /user/createWithArray"
* example usage:
swgg.apiDict["operationId.createUsersWithArrayInput"].ajax({
"body": [
{
"email": "a@a.com",
"firstName": "abcd1234",
"id": 1,
"jwtEncrypted": "abcd1234",
"lastName": "abcd1234",
"password": "abcd1234",
"phone": "abcd1234",
"userStatus": 0,
"username": "abcd1234"
}
]
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.createUsersWithListInput.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "POST /user/createWithList"
* example usage:
swgg.apiDict["operationId.createUsersWithListInput"].ajax({
"body": [
{
"email": "a@a.com",
"firstName": "abcd1234",
"id": 1,
"jwtEncrypted": "abcd1234",
"lastName": "abcd1234",
"password": "abcd1234",
"phone": "abcd1234",
"userStatus": 0,
"username": "abcd1234"
}
]
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.deleteOrder.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "DELETE /store/order/{}"
* example usage:
swgg.apiDict["operationId.deleteOrder"].ajax({
"orderId": 1
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.deletePet.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "DELETE /pet/{}"
* example usage:
swgg.apiDict["operationId.deletePet"].ajax({
"api_key": "abcd1234",
"petId": 0
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.deleteUser.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "DELETE /user/{}"
* example usage:
swgg.apiDict["operationId.deleteUser"].ajax({
"username": "abcd1234"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.file.crudCountManyByQuery.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /file/crudCountManyByQuery"
* example usage:
swgg.apiDict["operationId.file.crudCountManyByQuery"].ajax({
"_queryWhere": "{\"id\":{\"$exists\":true}}"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.file.crudGetManyByQuery.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /file/crudGetManyByQuery"
* example usage:
swgg.apiDict["operationId.file.crudGetManyByQuery"].ajax({
"_queryWhere": "{\"id\":{\"$exists\":true}}",
"_queryFields": [
"abcd1234"
],
"_queryLimit": 20,
"_querySkip": 0,
"_querySort": [
{
"fieldName": "id"
},
{
"fieldName": "_timeUpdated",
"isDescending": true
}
]
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.file.crudRemoveOneById.id.id.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "DELETE /file/crudRemoveOneById.id.id"
* example usage:
swgg.apiDict["operationId.file.crudRemoveOneById.id.id"].ajax({
"id": "abcd1234"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.file.crudSetOneById.id.id.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "PUT /file/crudSetOneById.id.id"
* example usage:
swgg.apiDict["operationId.file.crudSetOneById.id.id"].ajax({
"id": "abcd1234",
"body": {
"fileBlob": "YWJjZDEyMzQ=",
"fileContentType": "abcd1234",
"fileDescription": "abcd1234",
"fileFilename": "abcd1234",
"fileInputName": "abcd1234",
"fileSize": 0,
"fileUrl": "abcd1234",
"id": "abcd1234"
}
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.file.crudUpdateOneById.id.id.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "PATCH /file/crudUpdateOneById.id.id"
* example usage:
swgg.apiDict["operationId.file.crudUpdateOneById.id.id"].ajax({
"id": "abcd1234",
"body": {
"fileBlob": "YWJjZDEyMzQ=",
"fileContentType": "abcd1234",
"fileDescription": "abcd1234",
"fileFilename": "abcd1234",
"fileInputName": "abcd1234",
"fileSize": 0,
"fileUrl": "abcd1234",
"id": "abcd1234"
}
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.file.fileGetOneById.id.id.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /file/fileGetOneById.id.id"
* example usage:
swgg.apiDict["operationId.file.fileGetOneById.id.id"].ajax({
"id": "testVideo1"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.file.fileUploadManyByForm.1.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "POST /file/fileUploadManyByForm.1"
* example usage:
swgg.apiDict["operationId.file.fileUploadManyByForm.1"].ajax({
"fileDescription": "abcd1234",
"file1": {}
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.file.fileUploadManyByForm.2.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "POST /file/fileUploadManyByForm.2"
* example usage:
swgg.apiDict["operationId.file.fileUploadManyByForm.2"].ajax({
"fileDescription": "abcd1234",
"file1": {},
"file2": {}
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.findPetsByStatus.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /pet/findByStatus"
* example usage:
swgg.apiDict["operationId.findPetsByStatus"].ajax({
"status": [
"available"
]
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.findPetsByTags.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /pet/findByTags"
* example usage:
swgg.apiDict["operationId.findPetsByTags"].ajax({
"tags": [
"abcd1234"
]
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.getInventory.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /store/inventory"
* example usage:
swgg.apiDict["operationId.getInventory"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.getOrderById.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /store/order/{}"
* example usage:
swgg.apiDict["operationId.getOrderById"].ajax({
"orderId": 1
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.getPetById.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /pet/{}"
* example usage:
swgg.apiDict["operationId.getPetById"].ajax({
"petId": 0
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.getUserByName.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /user/{}"
* example usage:
swgg.apiDict["operationId.getUserByName"].ajax({
"username": "abcd1234"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.loginUser.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /user/login"
* example usage:
swgg.apiDict["operationId.loginUser"].ajax({
"username": "abcd1234",
"password": "abcd1234"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.logoutUser.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /user/logout"
* example usage:
swgg.apiDict["operationId.logoutUser"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.pet.crudGetManyByQuery.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /pet/crudGetManyByQuery"
* example usage:
swgg.apiDict["operationId.pet.crudGetManyByQuery"].ajax({
"_queryWhere": "{\"id\":{\"$exists\":true}}",
"_queryFields": [
"abcd1234"
],
"_queryLimit": 20,
"_querySkip": 0,
"_querySort": [
{
"fieldName": "id"
},
{
"fieldName": "_timeUpdated",
"isDescending": true
}
]
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.placeOrder.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "POST /store/order"
* example usage:
swgg.apiDict["operationId.placeOrder"].ajax({
"body": {
"complete": false,
"id": 1,
"petId": 0,
"quantity": 0,
"shipDate": "2019-09-15T22:20:48.653Z",
"status": "placed"
}
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.store.crudGetManyByQuery.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /store/crudGetManyByQuery"
* example usage:
swgg.apiDict["operationId.store.crudGetManyByQuery"].ajax({
"_queryWhere": "{\"id\":{\"$exists\":true}}",
"_queryFields": [
"abcd1234"
],
"_queryLimit": 20,
"_querySkip": 0,
"_querySort": [
{
"fieldName": "id"
},
{
"fieldName": "_timeUpdated",
"isDescending": true
}
]
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.store.crudUpdateOneById.id.id.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "PATCH /store/crudUpdateOneById.id.id"
* example usage:
swgg.apiDict["operationId.store.crudUpdateOneById.id.id"].ajax({
"id": 0,
"body": {
"complete": false,
"id": 1,
"petId": 0,
"quantity": 0,
"shipDate": "2019-09-15T22:20:48.659Z",
"status": "placed"
}
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.updatePet.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "PUT /pet"
* example usage:
swgg.apiDict["operationId.updatePet"].ajax({
"body": {
"category": {
"id": 0,
"name": "abcd1234"
},
"id": 1,
"name": "abcd1234",
"photoUrls": [
"abcd1234"
],
"status": "available",
"tags": [
{
"id": 0,
"name": "abcd1234"
}
]
}
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.updatePetWithForm.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "POST /pet/{}"
* example usage:
swgg.apiDict["operationId.updatePetWithForm"].ajax({
"petId": 0,
"name": "abcd1234",
"status": "abcd1234"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.updateUser.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "PUT /user/{}"
* example usage:
swgg.apiDict["operationId.updateUser"].ajax({
"username": "abcd1234",
"body": {
"email": "a@a.com",
"firstName": "abcd1234",
"id": 1,
"jwtEncrypted": "abcd1234",
"lastName": "abcd1234",
"password": "abcd1234",
"phone": "abcd1234",
"userStatus": 0,
"username": "abcd1234"
}
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.uploadFile.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "POST /pet/{}/uploadImage"
* example usage:
swgg.apiDict["operationId.uploadFile"].ajax({
"petId": 0,
"file1": "abcd1234",
"file": {}
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.user.crudCountManyByQuery.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /user/crudCountManyByQuery"
* example usage:
swgg.apiDict["operationId.user.crudCountManyByQuery"].ajax({
"_queryWhere": "{\"id\":{\"$exists\":true}}"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.user.crudGetManyByQuery.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /user/crudGetManyByQuery"
* example usage:
swgg.apiDict["operationId.user.crudGetManyByQuery"].ajax({
"_queryWhere": "{\"id\":{\"$exists\":true}}",
"_queryFields": [
"abcd1234"
],
"_queryLimit": 20,
"_querySkip": 0,
"_querySort": [
{
"fieldName": "id"
},
{
"fieldName": "_timeUpdated",
"isDescending": true
}
]
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.user.crudRemoveOneById.username.username.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "DELETE /user/crudRemoveOneById.username.username"
* example usage:
swgg.apiDict["operationId.user.crudRemoveOneById.username.username"].ajax({
"username": "abcd1234"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.user.crudSetOneById.username.username.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "PUT /user/crudSetOneById.username.username"
* example usage:
swgg.apiDict["operationId.user.crudSetOneById.username.username"].ajax({
"username": "abcd1234",
"body": {
"email": "a@a.com",
"firstName": "abcd1234",
"id": 1,
"jwtEncrypted": "abcd1234",
"lastName": "abcd1234",
"password": "abcd1234",
"phone": "abcd1234",
"userStatus": 0,
"username": "abcd1234"
}
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.user.crudUpdateOneById.username.username.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "PATCH /user/crudUpdateOneById.username.username"
* example usage:
swgg.apiDict["operationId.user.crudUpdateOneById.username.username"].ajax({
"username": "abcd1234",
"body": {
"email": "a@a.com",
"firstName": "abcd1234",
"id": 1,
"jwtEncrypted": "abcd1234",
"lastName": "abcd1234",
"password": "abcd1234",
"phone": "abcd1234",
"userStatus": 0,
"username": "abcd1234"
}
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.user.userLoginByPassword.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /user/userLoginByPassword"
* example usage:
swgg.apiDict["operationId.user.userLoginByPassword"].ajax({
"username": "abcd1234",
"password": "abcd1234"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.user.userLogout.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /user/userLogout"
* example usage:
swgg.apiDict["operationId.user.userLogout"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test-markdown.description.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /x-test-markdown/description"
* example usage:
swgg.apiDict["operationId.x-test-markdown.description"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudCountManyByQuery.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /x-test/crudCountManyByQuery"
* example usage:
swgg.apiDict["operationId.x-test.crudCountManyByQuery"].ajax({
"_queryWhere": "{\"id\":{\"$exists\":true}}"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudErrorDelete.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "DELETE /x-test/crudErrorDelete"
* example usage:
swgg.apiDict["operationId.x-test.crudErrorDelete"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudErrorGet.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /x-test/crudErrorGet"
* example usage:
swgg.apiDict["operationId.x-test.crudErrorGet"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudErrorHead.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "HEAD /x-test/crudErrorHead"
* example usage:
swgg.apiDict["operationId.x-test.crudErrorHead"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudErrorLogin.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /x-test/crudErrorLogin"
* example usage:
swgg.apiDict["operationId.x-test.crudErrorLogin"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudErrorOptions.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "OPTIONS /x-test/crudErrorOptions"
* example usage:
swgg.apiDict["operationId.x-test.crudErrorOptions"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudErrorPatch.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "PATCH /x-test/crudErrorPatch"
* example usage:
swgg.apiDict["operationId.x-test.crudErrorPatch"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudErrorPost.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "POST /x-test/crudErrorPost"
* example usage:
swgg.apiDict["operationId.x-test.crudErrorPost"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudErrorPre.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /x-test/crudErrorPre"
* example usage:
swgg.apiDict["operationId.x-test.crudErrorPre"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudErrorPut.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "PUT /x-test/crudErrorPut"
* example usage:
swgg.apiDict["operationId.x-test.crudErrorPut"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudGetManyByQuery.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /x-test/crudGetManyByQuery"
* example usage:
swgg.apiDict["operationId.x-test.crudGetManyByQuery"].ajax({
"_queryWhere": "{\"id\":{\"$exists\":true}}",
"_queryFields": [
"abcd1234"
],
"_queryLimit": 20,
"_querySkip": 0,
"_querySort": [
{
"fieldName": "id"
},
{
"fieldName": "_timeUpdated",
"isDescending": true
}
]
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudGetOneById.id.id.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /x-test/crudGetOneById.id.id"
* example usage:
swgg.apiDict["operationId.x-test.crudGetOneById.id.id"].ajax({
"id": "abcd1234"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudGetOneByQuery.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /x-test/crudGetOneByQuery"
* example usage:
swgg.apiDict["operationId.x-test.crudGetOneByQuery"].ajax({
"_queryWhere": "{\"id\":{\"$exists\":true}}"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudNullDelete.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "DELETE /x-test/crudNullDelete"
* example usage:
swgg.apiDict["operationId.x-test.crudNullDelete"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudNullGet.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /x-test/crudNullGet"
* example usage:
swgg.apiDict["operationId.x-test.crudNullGet"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudNullHead.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "HEAD /x-test/crudNullHead"
* example usage:
swgg.apiDict["operationId.x-test.crudNullHead"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudNullOptions.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "OPTIONS /x-test/crudNullOptions"
* example usage:
swgg.apiDict["operationId.x-test.crudNullOptions"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudNullPatch.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "PATCH /x-test/crudNullPatch"
* example usage:
swgg.apiDict["operationId.x-test.crudNullPatch"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudNullPost.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "POST /x-test/crudNullPost"
* example usage:
swgg.apiDict["operationId.x-test.crudNullPost"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudNullPut.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "PUT /x-test/crudNullPut"
* example usage:
swgg.apiDict["operationId.x-test.crudNullPut"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudRemoveManyByQuery.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "DELETE /x-test/crudRemoveManyByQuery"
* example usage:
swgg.apiDict["operationId.x-test.crudRemoveManyByQuery"].ajax({
"_queryWhere": "{\"id\":\"undefined\"}"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudRemoveOneById.id.id.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "DELETE /x-test/crudRemoveOneById.id.id"
* example usage:
swgg.apiDict["operationId.x-test.crudRemoveOneById.id.id"].ajax({
"id": "abcd1234"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.crudSetManyById.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "PUT /x-test/crudSetManyById"
* example usage:
swgg.apiDict["operationId.x-test.crudSetManyById"].ajax({
"body": [
{
"id": "abcd1234",
"typeArrayItemsBoolean1": [
false,
true
],
"typeArrayItemsInteger1": [
0,
1
],
"typeArrayItemsNumber1": [
0.5,
1.5
],
"typeArrayItemsNumber2": [
0.5,
1.5
],
"typeArrayItemsNumberCollectionFormatMultiInFormData": [
0.5,
1.5
],
"typeArrayItemsString0": [
"abcd1234"
],
"typeArrayItemsString1": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatCsv": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatJson": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatMultiInFormData": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatPipes": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatSsv": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatTsv": [
"aa",
"bb"
],
"typeArrayItemsStringEnum": [
"aa",
"bb"
],
"typeBoolean0": false,
"typeBooleanRequired": true,
"typeInteger0": 0,
"typeInteger1": 2,
"typeInteger2": 2,
"typeNumber0": 0,
"typeNumber1": -1.5,
"typeNumber2": 0.5,
"typeNumberEnum": 0.5,
"typeNumberFormatDouble": 0.5,
"typeNumberFormatFloat": 0.5,
"typeString0": "abcd1234",
"typeString1": "0123456789012345",
"typeStringApiKey": "abcd1234",
"typeStringCharsetAscii": "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\
u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrst...
n/a
operationId.x-test.crudSetOneById.id.id.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "PUT /x-test/crudSetOneById.id.id"
* example usage:
swgg.apiDict["operationId.x-test.crudSetOneById.id.id"].ajax({
"id": "abcd1234",
"body": {
"id": "abcd1234",
"typeArrayItemsBoolean1": [
false,
true
],
"typeArrayItemsInteger1": [
0,
1
],
"typeArrayItemsNumber1": [
0.5,
1.5
],
"typeArrayItemsNumber2": [
0.5,
1.5
],
"typeArrayItemsNumberCollectionFormatMultiInFormData": [
0.5,
1.5
],
"typeArrayItemsString0": [
"abcd1234"
],
"typeArrayItemsString1": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatCsv": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatJson": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatMultiInFormData": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatPipes": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatSsv": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatTsv": [
"aa",
"bb"
],
"typeArrayItemsStringEnum": [
"aa",
"bb"
],
"typeBoolean0": false,
"typeBooleanRequired": true,
"typeInteger0": 0,
"typeInteger1": 2,
"typeInteger2": 2,
"typeNumber0": 0,
"typeNumber1": -1.5,
"typeNumber2": 0.5,
"typeNumberEnum": 0.5,
"typeNumberFormatDouble": 0.5,
"typeNumberFormatFloat": 0.5,
"typeString0": "abcd1234",
"typeString1": "0123456789012345",
"typeStringApiKey": "abcd1234",
"typeStringCharsetAscii": "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",
"typeStringFormatBinary": [
0,
1
],
"typeStringFormatByte": "AAECAwQFBgcICQoLDA0ODxAREh...
n/a
operationId.x-test.crudUpdateOneById.id.id.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "PATCH /x-test/crudUpdateOneById.id.id"
* example usage:
swgg.apiDict["operationId.x-test.crudUpdateOneById.id.id"].ajax({
"id": "abcd1234",
"body": {
"id": "abcd1234",
"typeArrayItemsBoolean1": [
false,
true
],
"typeArrayItemsInteger1": [
0,
1
],
"typeArrayItemsNumber1": [
0.5,
1.5
],
"typeArrayItemsNumber2": [
0.5,
1.5
],
"typeArrayItemsNumberCollectionFormatMultiInFormData": [
0.5,
1.5
],
"typeArrayItemsString0": [
"abcd1234"
],
"typeArrayItemsString1": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatCsv": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatJson": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatMultiInFormData": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatPipes": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatSsv": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatTsv": [
"aa",
"bb"
],
"typeArrayItemsStringEnum": [
"aa",
"bb"
],
"typeBoolean0": false,
"typeBooleanRequired": true,
"typeInteger0": 0,
"typeInteger1": 2,
"typeInteger2": 2,
"typeNumber0": 0,
"typeNumber1": -1.5,
"typeNumber2": 0.5,
"typeNumberEnum": 0.5,
"typeNumberFormatDouble": 0.5,
"typeNumberFormatFloat": 0.5,
"typeString0": "abcd1234",
"typeString1": "0123456789012345",
"typeStringApiKey": "abcd1234",
"typeStringCharsetAscii": "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",
"typeStringFormatBinary": [
0,
1
],
"typeStringFormatByte": "AAECAwQFBgcICQo...
n/a
operationId.x-test.errorUndefinedApi.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /x-test/errorUndefinedApi"
* example usage:
swgg.apiDict["operationId.x-test.errorUndefinedApi"].ajax({}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.fixErrorSemanticUniquePathAa.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /x-test/fixErrorSemanticUniquePath/{}"
* example usage:
swgg.apiDict["operationId.x-test.fixErrorSemanticUniquePathAa"].ajax({
"aa": "abcd1234"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.fixErrorSemanticUniquePathBb.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /x-test/fixErrorSemanticUniquePath/{}#1"
* example usage:
swgg.apiDict["operationId.x-test.fixErrorSemanticUniquePathBb"].ajax({
"bb": "abcd1234"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.onErrorJsonapi.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "GET /x-test/onErrorJsonapi"
* example usage:
swgg.apiDict["operationId.x-test.onErrorJsonapi"].ajax({
"data": "{\"foo\":\"abcd1234\"}",
"error": "{\"foo\":\"abcd1234\"}"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.parametersDefault.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "POST /x-test/parametersDefault/{}"
* example usage:
swgg.apiDict["operationId.x-test.parametersDefault"].ajax({
"typeArrayItemsBoolean1": [
false,
true
],
"typeArrayItemsInteger1": [
0,
1
],
"typeArrayItemsNumber1": [
0.5,
1.5
],
"typeArrayItemsNumber2": [
0.5,
1.5
],
"typeArrayItemsNumberCollectionFormatMultiInFormData": [
0.5,
1.5
],
"typeArrayItemsString0": [
"abcd1234"
],
"typeArrayItemsString1": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatCsv": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatJson": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatMultiInFormData": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatPipes": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatSsv": [
"aa",
"bb"
],
"typeArrayItemsStringCollectionFormatTsv": [
"aa",
"bb"
],
"typeArrayItemsStringEnum": [
"aa",
"bb"
],
"typeBoolean0": false,
"typeBooleanRequired": true,
"typeInteger0": 0,
"typeInteger1": 2,
"typeInteger2": 2,
"typeNumber0": 0,
"typeNumber1": -1.5,
"typeNumber2": 0.5,
"typeNumberEnum": 0.5,
"typeNumberFormatDouble": 0.5,
"typeNumberFormatFloat": 0.5,
"typeString0": "abcd1234",
"typeString1": "0123456789012345",
"typeStringApiKey": "abcd1234",
"typeStringCharsetAscii": "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",
"typeStringFormatBinary": [
0,
1
],
"typeStringFormatByte": "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn8
=",
"typeStringFormatDate": "1970.01.01",
"typeStringFormatDateTime": "1970-01-01T00:00:00.000Z",
"typeStringFormatEmail": "q@q.com",
"typeStringFormatJson": "{}&q...
n/a
operationId.x-test.parametersDefaultInFormDataXml.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "POST /x-test/parametersDefaultInFormDataXml"
* example usage:
swgg.apiDict["operationId.x-test.parametersDefaultInFormDataXml"].ajax({
"typeBoolean0": false,
"typeInteger0": 0,
"typeNumber0": 0,
"typeString0": "aa"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.parametersObjectInBody.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "POST /x-test/parametersObjectInBody"
* example usage:
swgg.apiDict["operationId.x-test.parametersObjectInBody"].ajax({
"typeObjectInBody": {
"typeArrayCircularReference": [
{
"typeArrayCircularReference": null,
"typeBooleanRequired": true,
"typeObjectCircularReference": null,
"typeObjectMisc": null,
"typeStringCharsetAscii": "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
}
],
"typeBooleanRequired": true,
"typeObjectCircularReference": {
"typeArrayCircularReference": [
null
],
"typeBooleanRequired": true,
"typeObjectCircularReference": {
"typeArrayCircularReference": null,
"typeBooleanRequired": true,
"typeObjectCircularReference": null,
"typeObjectMisc": null,
"typeStringCharsetAscii": "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
},
"typeObjectMisc": {
"property0": "abcd1234"
},
"typeStringCharsetAscii": "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\
u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
},
"typeObjectMisc": {
"property0": "abcd1234"
},
"typeStringCharsetAscii": "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
}
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.parametersStringInBody.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "POST /x-test/parametersStringInBody"
* example usage:
swgg.apiDict["operationId.x-test.parametersStringInBody"].ajax({
"typeStringInBody": "abcd1234"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
operationId.x-test.parametersStringInBodyRequired.ajax = function (swaggerJson, onError) {
/*
* this function will run the api-call "POST /x-test/parametersStringInBodyRequired"
* example usage:
swgg.apiDict["operationId.x-test.parametersStringInBodyRequired"].ajax({
"typeStringInBodyRequired": "abcd1234"
}, function (err, data) {
if (err) {
console.error(err);
return;
}
console.log(data.responseJson || data.responseText);
});
*/
return local.apiAjax(that, swaggerJson, onError);
}
n/a
onEventInputTextareaChange = function (evt) {
/*
* this function will show/hide the textarea's multiline placeholder
*/
let isTransparent;
let value;
isTransparent = evt.targetOnEvent.style.background.indexOf(
"transparent"
) >= 0;
value = evt.targetOnEvent.value;
if (value && isTransparent) {
evt.targetOnEvent.style.background = "";
}
if (!value && !isTransparent) {
evt.targetOnEvent.style.background = "transparent";
}
local.uiEventListenerDict.onEventInputValidateAndAjax({
targetOnEvent: evt.targetOnEvent
});
}
...
".swggUiContainer [data-value-text]"
).forEach(function (element) {
// render valueText
element.value = decodeURIComponent(element.dataset.valueText);
delete element.dataset.valueText;
// init textarea's multiline placeholder
if (element.tagName === "TEXTAREA") {
local.uiEventListenerDict.onEventInputTextareaChange({
targetOnEvent: element
});
}
});
// init evt-handling
[
"Change", "Click", "Keyup", "Submit"
...
onEventInputValidateAndAjax = function ( opt, onError ) {
/*
* this function will validate the input parameters
* against the schemas in <opt>.parameters
*/
let errorDict;
let jsonParse;
let tmp;
jsonParse = function (text) {
/*
* this function will try to JSON.parse(text)
*/
return local.tryCatchOnError(function () {
return JSON.parse(text);
}, function () {
return text;
});
};
// hack-jslint
opt.targetOnEvent = opt.targetOnEvent.closest(
".operation"
);
opt.api = local.apiDict[opt.targetOnEvent.dataset._methodPath];
opt.headers = {};
opt.modeAjax = opt.modeAjax || "validate";
opt.modeNoDefault = true;
opt.paramDict = {};
opt.url = "";
opt.api.parameters.forEach(function (schemaP) {
tmp = opt.targetOnEvent.querySelector(
".schemaP[data-name=" + JSON.stringify(schemaP.name) + "] .input"
);
switch (tmp.tagName) {
case "INPUT":
// parse file
if (local.schemaPType(tmp) === "file") {
tmp = tmp.files && tmp.files[0];
break;
}
tmp = tmp.value;
if (!tmp) {
return;
}
// parse string
if (local.schemaPType(schemaP) !== "string") {
tmp = jsonParse(tmp);
}
break;
case "SELECT":
tmp = Array.from(tmp.options).filter(function (element) {
return element.selected;
}).map(function (element) {
return jsonParse(decodeURIComponent(
element.dataset.valueSelectOption
));
});
if (!tmp.length || tmp[0] === "$swggUndefined") {
return;
}
if (local.schemaPType(schemaP) !== "array") {
tmp = tmp[0];
}
break;
case "TEXTAREA":
tmp = tmp.value;
if (!tmp) {
return;
}
// ignore string (json)
if (
schemaP.format === "json"
&& local.schemaPType(schemaP) === "string"
) {
break;
}
if (
schemaP.schema
&& local.schemaPType(schemaP.schema) === "string"
&& typeof tmp === "string"
) {
break;
}
// parse schema
if (schemaP.in === "body") {
tmp = jsonParse(tmp);
break;
}
// parse array
tmp = tmp.split("\n").map(function (element) {
return (
local.schemaPItemsType(schemaP) === "string"
? element
: jsonParse(element)
);
});
break;
}
opt.paramDict[schemaP.name] = tmp;
});
opt.api.ajax(opt, onError || local.nop);
// init errorDict
errorDict = {};
local.valueOrEmptyList(opt.err && opt.err.errList).forEach(function (err) {
errorDict[err.opt.prefix[2]] = err;
});
// shake input on err
Array.from(opt.targetOnEvent.querySelectorAll(
".schemaP[data-name]"
)).forEach(function (element) {
tmp = errorDict[element.dataset.name];
local.uiAnimateShakeIfError(tmp, element.querySelector(
".input"
));
element.querySelector(
".colorError"
).textContent = (
tmp
? tmp.messageShort
: ""
);
});
// shake submit-button on err
local.uiAnimateShakeIfError(
opt.err,
opt....
...
value = evt.targetOnEvent.value;
if (value && isTransparent) {
evt.targetOnEvent.style.background = "";
}
if (!value && !isTransparent) {
evt.targetOnEvent.style.background = "transparent";
}
local.uiEventListenerDict.onEventInputValidateAndAjax({
targetOnEvent: evt.targetOnEvent
});
};
local.uiEventListenerDict.onEventInputValidateAndAjax = function (
opt,
onError
...
onEventOperationAjax = function (opt) {
/*
* this function will submit the operation to the backend
*/
// ensure opt is stateless
opt = {
targetOnEvent: opt.targetOnEvent.closest(".operation")
};
local.gotoNext(opt, function (err, data) {
switch (opt.gotoState) {
case 1:
// force ajax
opt.modeAjax = "ajax";
// validate input
local.uiEventListenerDict.onEventInputValidateAndAjax(
opt,
opt.gotoNext
);
// reset res output
Array.from(opt.targetOnEvent.querySelectorAll(
".resBody, .resHeaders, .resStatusCode"
)).forEach(function (element) {
element.classList.remove("hasError");
element.textContent = "loading ...";
});
opt.targetOnEvent.querySelector(
".resMedia"
).innerHTML = "";
// scrollTo res
opt.targetOnEvent.querySelector(
".resStatusCode"
).focus();
break;
default:
local.onErrorDefault(err);
data = local.objectSetDefault(data, {
contentType: "undefined",
statusCode: "undefined"
});
// init resStatusCode
opt.targetOnEvent.querySelector(
".resStatusCode"
).textContent = (
data.statusCode
);
// init resHeaders
opt.targetOnEvent.querySelector(
".resHeaders"
).textContent = Object.keys(data.resHeaders).map(function (key) {
return key + ": " + data.resHeaders[key] + "\r\n";
}).join("");
// init resBody
opt.targetOnEvent.querySelector(
".resHeaders"
).textContent.replace((
/^content-type:(.*?)$/im
), function (ignore, match1) {
data.contentType = match1.trim();
});
data.mediaType = data.contentType.split("/")[0].replace(
"image",
"img"
);
switch (data.mediaType) {
case "audio":
case "img":
case "video":
opt.targetOnEvent.querySelector(
".resBody"
).textContent = (
data.contentType
);
opt.targetOnEvent.querySelector(
".resMedia"
).innerHTML = (
"<" + data.mediaType
+ " class=\"domOnEventMediaHotkeysInit\""
+ " controls src=\"data:"
+ data.contentType
+ ";base64," + local.base64FromBuffer(data.resBuffer)
+ "\"></" + data.mediaType + ">"
);
globalThis.domOnEventMediaHotkeys("init");
break;
default:
opt.targetOnEvent.querySelector(
".resBody"
).textContent = (
data.responseJson
? JSON.stringify(data.responseJson, null, 4)
: data.response
);
}
// shake res on err
Array.from(opt.targetOnEvent.querySelectorAll(
".resBody, .resHeaders, .resStatusCode"
)).forEach(function (element) {
local.uiAnimateShakeIfError(data.statusCode >= 400, element);
});
}
});
opt.gotoState = 0;
opt.gotoNext();
}
n/a
onEventOperationDisplayShow = function ( evt, onError ) {
/*
* this function will toggle the display of the operation
*/
let element;
element = evt.targetOnEvent;
element = element.querySelector(
".operation"
) || element.closest(
".operation"
);
location.hash = "!" + element.id;
element.closest(
".resource"
).classList.remove("expanded");
// show parent resource
local.uiAnimateSlideDown(element.closest(
".resource"
).querySelector(
".operationList"
));
// show the operation, but hide all other operations
local.uiAnimateSlideAccordian(
element.querySelector(
".operation > form"
),
Array.from(element.closest(
".operationList"
).querySelectorAll(
".operation > form"
)),
function () {
// scrollTo operation
element.querySelector(
"[tabIndex]"
).blur();
element.querySelector(
"[tabIndex]"
).focus();
// validate input
local.uiEventListenerDict.onEventInputValidateAndAjax({
targetOnEvent: element
});
local.setTimeoutOnError(onError, 0, null, element);
}
);
}
...
".operationList"
),
Array.from(document.querySelectorAll(
".swggUiContainer .operationList"
))
);
// show at least one operation in the resource
local.uiEventListenerDict.onEventOperationDisplayShow({
targetOnEvent: evt.currentTarget.querySelector(
".operation .uiAnimateSlide[style*=\"max-height: 100%\"]"
) || evt.currentTarget.querySelector(
".operation"
)
});
return true;
...
onEventResourceDisplayAction = function (evt) {
/*
* this function will toggle the display of the resource
*/
location.hash = "!" + evt.currentTarget.id;
evt.targetOnEvent.className.split(" ").some(function (className) {
switch (className) {
case "td1":
// show the resource, but hide all other resources
local.uiAnimateSlideAccordian(
evt.currentTarget.querySelector(
".operationList"
),
Array.from(document.querySelectorAll(
".swggUiContainer .operationList"
))
);
// show at least one operation in the resource
local.uiEventListenerDict.onEventOperationDisplayShow({
targetOnEvent: evt.currentTarget.querySelector(
".operation .uiAnimateSlide[style*=\"max-height: 100%\"]"
) || evt.currentTarget.querySelector(
".operation"
)
});
return true;
case "td2":
// show the resource, but hide all other resources
local.uiAnimateSlideAccordian(
evt.currentTarget.querySelector(
".operationList"
),
Array.from(document.querySelectorAll(
".swggUiContainer .operationList"
))
);
// collapse all operations in the resource
if (evt.currentTarget.classList.contains("expanded")) {
evt.currentTarget.classList.remove("expanded");
Array.from(evt.currentTarget.querySelectorAll(
".operation > form"
)).forEach(function (element) {
local.uiAnimateSlideUp(element);
});
// expand all operations in the resource
} else {
evt.currentTarget.classList.add("expanded");
Array.from(evt.currentTarget.querySelectorAll(
".operation > form"
)).forEach(function (element) {
local.uiAnimateSlideDown(element);
// validate input
local.uiEventListenerDict.onEventInputValidateAndAjax({
targetOnEvent: element
});
});
}
return true;
}
});
}
n/a
onEventUiReload = function (opt, onError) {
/*
* this function will reload the ui
*/
let resource;
let swaggerJson;
opt = opt || {};
swaggerJson = opt;
local.gotoNext(opt, function (err, data) {
switch (opt.gotoState) {
case 1:
if (
opt
&& opt.targetOnEvent
&& opt.targetOnEvent.classList
&& !opt.targetOnEvent.classList.contains(
"eventDelegate"
+ opt.type[0].toUpperCase()
+ opt.type.slice(1)
)
) {
return;
}
opt.inputUrl = document.querySelector(
".swggUiContainer > .thead > .td2"
);
// clear all apiKeyValue's from localStorage
if (
opt.targetOnEvent
&& opt.targetOnEvent.id === "buttonSwggApiKeyClear1"
) {
local.apiKeyValue = "";
Object.keys(localStorage).forEach(function (key) {
if (key.indexOf("utility2_swgg_apiKeyKey_") === 0) {
localStorage.removeItem(key);
}
});
// restore apiKeyValue
} else if (opt.swggInit) {
local.apiKeyKey = (
"utility2_swgg_apiKeyKey_" + encodeURIComponent(
local.urlParse(opt.inputUrl.value.replace((
/^\//
), "")).href
)
);
local.apiKeyValue = localStorage.getItem(local.apiKeyKey) || "";
// save apiKeyValue
} else {
local.apiKeyValue = document.querySelector(
"#swggApiKeyInput1"
).value;
local.localStorageSetItemOrClear(
local.apiKeyKey,
local.apiKeyValue
);
}
// if keyup-evt is not return-key, then return
if (
(opt.type === "keyup" && opt.code !== "Enter")
// do not reload ui during test
|| globalThis.utility2_modeTest >= 4
) {
opt.gotoState = Infinity;
opt.gotoNext();
return;
}
// reset ui
document.querySelector(
"#swggUiReloadErrorDiv1"
).textContent = "";
document.querySelectorAll(
".swggUiContainer > .reset"
).forEach(function (element) {
element.remove();
});
// normalize swaggerJsonUrl
opt.inputUrl.value = local.urlParse(
opt.inputUrl.value.replace((
/^\//
), "")
).href;
document.querySelector(
"#swggAjaxProgressDiv1 span"
).innerHTML = (
"loading swagger.json"
);
opt.gotoNext();
break;
case 2:
// fetch swagger.json file
local.ajax({
url: opt.inputUrl.value
}, opt.gotoNext);
break;
case 3:
// JSON.parse swagger.json string
local.tryCatchOnError(function () {
opt.gotoNext(null, JSON.parse(data.responseText));
}, opt.gotoNext);
break;
case 4:
// reset state
local.apiDict = null;
local.swaggerJson = null;
// apiUpdate swagger.json object
local.apiUpdate(data);
swaggerJson = local.jsonCopy(local.swaggerJson);
local.uiState = swaggerJson;
// init ajaxProgressText...
...
/\\bmodeSwaggerJsonUrl=([^&]+)|$/gm\n\
).exec(location.search)[1] || "assets.swgg.swagger.json");\n\
</script>\n\
<script src="assets.utility2.rollup.js"></script>\n\
<script>\n\
/* jslint utility2:true */\n\
window.local = window.local || window.swgg;\n\
window.swgg.uiEventListenerDict.onEventUiReload({\n\
swggInit: true\n\
});\n\
</script>\n\
<!-- swgg-script-extra-begin -->\n\
<!-- swgg-script-extra-end -->\n\
</body>\n\
</html>\n\
...