How to use the swagger2openapi.convertStr function in swagger2openapi

To help you get started, we’ve selected a few swagger2openapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Mermade / openapi-lint-vscode / extension.js View on Github external
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);
            });
        }
    });
}