How to use the swagger2openapi.convert 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-webconverter / api.js View on Github external
}).then(function(body) {
            var obj = getObj(body,payload);
            var globalOptions = options = {};
            options.origin = true;
            options.source = req.query.url;
            options.patch = true;
            options.resolve = true;
            try {
                converter.convert(obj,options,async function(err,options){
                    if (err) {
                        result.error = err.message;
                        result.options = sanitise(globalOptions);
                    }
                    else result = options.openapi;
                    if (req.query.validate && options.openapi) {
                        status.validations++;
                        try {
                            result = {};
                            result.status = await validator.validateSync(options.openapi,options);
                        }
                        catch (ex) {
                            result.status = false; // reset
                            if (options.context) {
                                result.context = options.context.pop();
                            }
github Mermade / openapi-webconverter / api.js View on Github external
var body = (req.body ? req.body.source : '')||(req.file ? req.file.buffer.toString() : '');
    var validate = (req.body && req.body.validate); // on or undefined

    var payload = parseRequest(req);

    if (req.headers['content-type'].startsWith('application/x-www-form-urlencoded')) {
        result.warning = `Your client sent the wrong Content-Type header (${req.headers['content-type']}). Try pasting your document`;
        payload.status = 400;
        if (!req.body.source && !req.file) payload.status = 200; // Dredd
    }
    var obj = getObj(body,payload);
    var options = {};
    options.patch = true;
    options.resolve = false;
    try {
        converter.convert(obj,options,async function(err,options){
            if (err) {
                result.message = err.message||'no message';
                result.options = sanitise(result.options);
            }
            else {
                result = options.openapi;
                if (options.openapi && options.openapi.openapi && options.openapi.openapi.startsWith('3.')) payload.status = 200;
            }
            if (validate && !err) {
                status.validations++;
                try {
                    result = {};
                    result.status = await validator.validateSync(options.openapi,options);
                    if (result.status === true) payload.status = 200;
                }
                catch (ex) {
github LucyBot-Inc / api-spec-converter / lib / formats / swagger_2.js View on Github external
  this.converters.openapi_3 = Promise.method(swagger => swagger2openapi.convert(swagger.spec,{direct:true,patch:true}));
}