Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function convert(yamlMode, resolve) {
let editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showWarningMessage('You must have an open editor window to convert an OpenAPI document');
return; // No open text editor
}
if (resolve && editor.document.isUntitled) {
vscode.window.showWarningMessage('Document must be saved in order to resolve correctly');
return; // No open text editor
}
converter.convertStr(editor.document.getText(),{ patch: true, warnOnly: true, resolve: resolve, source: editor.document.fileName, fatal: true }, function(err, options) {
if (yamlMode) {
vscode.workspace.openTextDocument({ language: 'yaml', content: yaml.stringify(options.openapi) })
.then(function(doc) {
vscode.window.showTextDocument(doc);
});
}
else {
vscode.workspace.openTextDocument({ language: 'json', content: JSON.stringify(options.openapi, null, 2)})
.then(function(doc) {
vscode.window.showTextDocument(doc);
});
}
});
}