swagger-server icon indicating copy to clipboard operation
swagger-server copied to clipboard

Is it possible to parse multiple swagger files at one time?

Open feikiss opened this issue 8 years ago • 2 comments

In swagger server, I need to parse multiple swaggers (2.0) at one time, is it possible to achieve or is there any way I can implement locally?

feikiss avatar May 30 '16 03:05 feikiss

See Issue #19. The short answer is, yes, it's possible. The longer answer is that it's not quite as straightforward or easy as it should be, so I plan to make this easier in the future

JamesMessinger avatar May 30 '16 11:05 JamesMessinger

@BigstickCarpet Actually, I have tried the #1 solution in Issue #19 but failed... I've also tried to do it with the sample in the Node's cluster feature. The following is my codes:

// Set the DEBUG environment variable to enable debug output
process.env.DEBUG = 'swagger:*';
process.chdir(__dirname);

// Create a Swagger Server app from the PetStore.yaml file
var swaggerServer = require('swagger-server');
var arr = ["../swagger.json","../swagger-petstore.json"]
var cluster = require('cluster');



if (cluster.isMaster) {
    console.log('[master] ' + "start master...");

    for (var i = 0; i < arr.length; i++) {
        cluster.fork({"index":i});
    }

    cluster.on('listening', function (worker, address) {
        console.log('[master] ' + 'listening: worker' + worker.id + ',pid:' + worker.process.pid + ', Address:' + address.address + ":" + address.port);
    });
    cluster.on('fork',function (worker){
        // timeouts[worker.id] = setTimeout(errorMsg, 2000);

    });

} else if (cluster.isWorker) {
    var id = cluster.worker.id;
    var content = arr[id-1]

    console.log('[worker] ' + "start worker ..." + id+", index:"+cluster.worker.index+", content:"+content);
    var app = swaggerServer(content);

// Start listening on port 8000
    app.listen(8001, function() {
        console.log('The Swagger Pet Store is now running at http://localhost:8000');
    })
}

In this case, neither of the two swagger files can work... Is there anything wrong I configured?

feikiss avatar Jun 01 '16 05:06 feikiss