Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
html: function (item, value) {
// console.log("Return function for ", e);
const val = YAML.stringify(JSON.parse(value)).replace(/\n/g, "<br>").replace(/\t/g, " ").replace(/ /g, " ")
return `<div class="input-cell">${value}</div>`
}
}
let namespace = {};
let parsed = filteredDoclets.map(doclet => parseDoclet(doclet, namespace)).filter(item => item);
parsed = parsed.reduce((accum, value) => [...accum, ...value], []);
let documentName = fileName.split('.')[0];
documentName = documentName[0].toUpperCase() + documentName.slice(1);
// Create master section to be converted to a YAML file
const fileDump = {
title: documentName,
description: 'Documented Methods',
sections: parsed,
};
// convert to YAML
const yml = converter.stringify(fileDump);
// get the path directory path where files will be written
let destination = config.opts.yaml;
let temp = fileName.split('-').join('').split('.');
temp[temp.length - 1] = 'yml';
let moduleFile = perFileDoclets.filter(doclet => doclet.kind === 'module' ? doclet : null);
moduleFile.map((file) => {
if (file.kind === 'module') {
temp[0] = file.name;
}
});
let ymlFileName = temp.join('.');
// If file is memberof a namespace, store it inside the appropriate namespace folder
// if (namespace.memberof) {
// destination = `${destination}${namespace.memberof}`;
// }
});
});
let yamlFiles = fs.readdirSync('./yaml');
yamlFiles = yamlFiles.map(file => file.toLowerCase());
for (let obj in segmentObj) {
const sameLevel = true;
let objParsed = segmentObj[obj].map(doclet => parseDoclet(doclet, sameLevel)).filter(item => item);
objParsed = objParsed.reduce((accum, value) => [...accum, ...value], []);
const fileDump = {
title: obj,
description: 'Documented Methods',
sections: objParsed
};
const yml = converter.stringify(fileDump);
let yamlFileName = `api-${obj}.yml`;
yamlFileName = yamlFileName.toLowerCase();
if (!yamlFiles.includes(yamlFileName)) {
fs.writeFile(`./yaml/${yamlFileName}`, yml, (err) => {
if (err) {
console.log(err);
}
});
} else {
// If a file with the same @segment name is present append data to that file
fs.readFile(`./yaml/${yamlFileName}`, 'utf-8', (error, content) => {
if (error) {
throw new Error(error.message);
}
const data = yaml.parse(content);
if (server.variables && server.variables.basePath && typeof server.variables.basePath == 'object') {
server.variables.basePath.default = server.variables.basePath.default.replace(
'{basePath}',
that.basePath
);
}
});
if (this.template.components && this.template.components.securitySchemes) {
for (let security in this.securityHeaders) {
this.template.components.securitySchemes[security] = this.securityHeaders[security];
}
}
if (this.pipe) {
console.log(this.json ? JSON.stringify(this.template) : YAML.stringify(this.template));
return;
}
if (this.json || path.extname(this.out) == '.json') {
if (this.out.endsWith('.yaml')) {
this.out = this.out.replace('.yaml', '.json');
}
let _path = this.out ? path.resolve(this.out) : path.join(process.cwd(), 'openapi.json');
fs.writeFileSync(_path, JSON.stringify(this.template, null, 4));
this.afterBuildComplete();
return;
}
fs.writeFileSync(
this.out ? path.resolve(this.out) : path.join(process.cwd(), 'openapi.yaml'),
YAML.stringify(this.template)
state_topic: 'zigbee2mqtt/',
availability_topic: 'zigbee2mqtt/bridge/state',
...device.discovery_payload,
};
if (payload.command_topic) {
if (payload.command_topic_prefix) {
payload.command_topic = `zigbee2mqtt//${payload.command_topic_prefix}/set`;
} else {
payload.command_topic = `zigbee2mqtt//set`;
}
}
delete payload.command_topic_prefix;
let yml = YAML.stringify([payload]);
yml = yml.replace(/(-) \n {4}/g, '- ');
yml = yml.replace('---', `${device.type}:`);
return yml;
};
state_topic: 'zigbee2mqtt/',
availability_topic: 'zigbee2mqtt/bridge/state',
...device.discovery_payload,
};
if (payload.command_topic) {
if (payload.command_topic_prefix) {
payload.command_topic = `zigbee2mqtt//${payload.command_topic_prefix}/set`;
} else {
payload.command_topic = `zigbee2mqtt//set`;
}
}
delete payload.command_topic_prefix;
let yml = YAML.stringify([payload]);
yml = yml.replace(/(-) \n {4}/g, '- ');
yml = yml.replace('---', `${device.type}:`);
return yml;
};
state_topic: "zigbee2mqtt/",
availability_topic: "zigbee2mqtt/bridge/state",
...device.discovery_payload,
};
if (payload.command_topic) {
if (payload.command_topic_prefix) {
payload.command_topic = `zigbee2mqtt//${payload.command_topic_prefix}/set`;
} else {
payload.command_topic = `zigbee2mqtt//set`;
}
}
delete payload.command_topic_prefix;
let yml = YAML.stringify([payload]);
yml = yml.replace(/(-) \n /g, '- ');
yml = yml.replace('---', `${device.type}:`)
return yml;
}
delete payload.command_topic_prefix;
if (!payload.state_topic) {
delete payload.state_topic;
}
if (payload.position_topic) {
payload.position_topic = 'zigbee2mqtt/';
}
if (payload.set_position_topic) {
payload.set_position_topic = 'zigbee2mqtt//set';
}
let yml = YAML.stringify([payload]);
yml = yml.replace(/(-) \n {4}/g, '- ');
yml = yml.replace('---', `${device.type}:`);
return yml;
}
export const saveSaml = (template: string) => {
if (!fs.existsSync(samlDirectory)) {
fs.mkdirSync(samlDirectory);
}
fs.writeFileSync(samlName, require("json2yaml").stringify(JSON.parse(template)));
};
return;
}
if (this.json || path.extname(this.out) == '.json') {
if (this.out.endsWith('.yaml')) {
this.out = this.out.replace('.yaml', '.json');
}
let _path = this.out ? path.resolve(this.out) : path.join(process.cwd(), 'openapi.json');
fs.writeFileSync(_path, JSON.stringify(this.template, null, 4));
this.afterBuildComplete();
return;
}
fs.writeFileSync(
this.out ? path.resolve(this.out) : path.join(process.cwd(), 'openapi.yaml'),
YAML.stringify(this.template)
);
this.afterBuildComplete();
return;
}