{% module %}
<%
var currentData;
var swaggerTypes = ['byte', 'boolean', 'int', 'long', 'float', 'double', 'string', 'date', 'array'];
function getModelChain(model, chain) {
if (!model) {
return [];
}
if (chain === undefined || chain === null) {
chain = [];
}
chain.push(model);
_.each(model.properties, function(prop) {
if (prop.type.toLowerCase() == "array" && prop.items !== undefined && prop.items.$ref !== undefined) {
candidate = currentData.models[prop.items.$ref]
} else {
candidate = currentData.models[prop.type];
}
if (candidate !== undefined && !_.contains(chain, candidate)) {
chain = getModelChain(candidate, chain);
}
});
return chain;
}
function getDtoChain(model, modelsAlreadyProcessed) {
modelsAlreadyProcessed = modelsAlreadyProcessed || {};
modelsAlreadyProcessed[model.id] = true;
var obj = {};
if (model === undefined || model === null) {
return {};
}
_.each(model.properties, function(prop, key) {
if (prop.type.toLowerCase() == "array" && prop.items !== undefined && prop.items.$ref !== undefined) {
candidate = currentData.models[prop.items.$ref]
} else {
candidate = currentData.models[prop.type];
}
if (candidate !== undefined && !modelsAlreadyProcessed[candidate.id]) {
obj[key] = getDtoChain(candidate, modelsAlreadyProcessed);
} else {
obj[key] = toSwaggerType(prop);
}
});
return obj;
}
function toSwaggerType(prop) {
if (prop.type.toLowerCase() == "array") {
var type = prop.items.type === undefined ? prop.items.$ref : prop.items.type;
return "Array<" + type + ">";
} else {
return prop.type;
}
}
function getVerbClass(verb) {
switch (verb.toLowerCase()) {
case "get":
return "info";
case "post":
return "success";
case "delete":
return "danger";
case "patch":
case "put":
return "warning";
default:
return "default"
}
}
// http://stackoverflow.com/a/7220510
function syntaxHighlight(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 2);
}
json = json.replace(/&/g, '&').replace(//g, '>');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '' + match + '';
});
}
function notUndefinedNullOrZeroLength(obj) {
return obj !== undefined && obj !== null && obj.length > 0;
}
%>
{% function name="apiAccordion" %}
% _.each(a.models, function(model) {
%{ modelTable(model) }
% });
% _.each(a.models, function(model) {
${ model.description || model.id }
%{ syntaxHighlight(model.properties) }
% });
% _.each(a.models, function(model) {
${ model.description || model.id }
%{ syntaxHighlight(getDtoChain(model)) }
% });
{% end %}
{% function name="modelTable" %}