Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
vscode.window.showWarningMessage('You must have an open editor window to resolve an OpenAPI document');
return; // No open text editor
}
if (editor.document.isUntitled) {
vscode.window.showWarningMessage('Document must be saved in order to resolve correctly');
return; // No open text editor
}
let text = editor.document.getText();
let yamlMode = false;
let obj = {};
try {
obj = JSON.parse(text);
}
catch (ex) {
try {
obj = yaml.parse(text);
yamlMode = true;
}
catch (ex) {
vscode.window.showErrorMessage('Could not parse OpenAPI document as JSON or YAML');
console.warn(ex.message);
return;
}
}
resolver.resolve(obj, editor.document.fileName, {})
.then(function(options){
if (yamlMode) {
vscode.workspace.openTextDocument({ language: 'yaml', content: yaml.stringify(options.openapi) })
.then(function(doc) {
vscode.window.showTextDocument(doc);
})
.then(function(ex) {
function doit(s) {
var api = {};
try {
api = yaml.parse(s);
}
catch(ex) {
console.error('Failed to parse YAML/JSON, falling back to API Blueprint');
console.error(ex.message);
api = s;
}
converter.convert(api,options,function(err,output){
if (err) {
console.warn(err);
}
else {
var outfile = argv.outfile||argv._[1];
if (outfile) {
fs.writeFileSync(path.resolve(outfile),output,'utf8');
}
function main(str,source,options){
let input = yaml.parse(str,{schema:'core'});
resolver.resolve(input,source,options)
.then(function(options){
if (options.agent) {
options.agent.destroy();
}
fs.writeFileSync(argv.output,yaml.stringify(options.openapi),'utf8');
})
.catch(function(err){
console.warn(err);
});
}
function getObj(body,payload){
var obj = {};
try {
obj = JSON.parse(body);
}
catch(ex) {
try {
obj = yaml.parse(body);
payload.yaml = true;
}
catch(ex) {
console.log(body);
}
}
return obj;
}
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const yaml = require('yaml');
const jsy = require('./lib/js-yaml.min.js');
if (process.argv.length<3) {
console.log('Usage: j2y {infile} {outfile}');
}
else {
const s = fs.readFileSync(process.argv[2],'utf8');
let obj;
try {
obj = yaml.parse(s);
}
catch (ex) {
console.warn(ex.message);
console.warn('Falling back to js-yaml');
obj = jsy.safeLoad(s,{json:true});
}
fs.writeFileSync(process.argv[3],yaml.stringify(obj),'utf8');
}
return maybe(callback, new Promise(function (resolve, reject) {
let obj = null;
let error = null;
try {
obj = JSON.parse(str);
options.text = JSON.stringify(obj,null,2);
}
catch (ex) {
error = ex;
try {
obj = yaml.parse(str, { schema: 'core' });
options.sourceYaml = true;
options.text = str;
}
catch (ex) {
error = ex;
}
}
if (obj) {
convertObj(obj, options)
.then(options => resolve(options))
.catch(ex => reject(ex));
}
else {
reject(new S2OError(error ? error.message : 'Could not parse string'));
}
}));
Deserialize (scriptData) {
return YAML.parse(scriptData)
}
}
function loadRules(s,schema,instance) {
let data = fs.readFileSync(s,'utf8');
let ruleData = yaml.parse(data,{schema:'core'});
applyRules(ruleData,s);
return rules;
}
function loadConfigFromModule(path, moduleName) {
var files = fs.readdirSync(path);
if (files.includes(CONFIG_FILE_NAME)) {
var data = fs.readFileSync(path + "/" + CONFIG_FILE_NAME);
var cfg = yaml.parse(data.toString());
if (moduleName != null) {
var moduleConfig = {};
moduleConfig[moduleName] = cfg;
cfg = moduleConfig;
}
cfg = parseConfig(cfg);
if (moduleName != null) {
objectEditor.replaceValue(
[moduleName],
appConfig,
(entry) => {
Object.assign(entry, cfg[moduleName]);
});
} else {
for (var key in cfg) {
var cfgAtKey = cfg[key];