Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

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

Open
feikiss opened this issue May 30, 2016 · 2 comments
Open

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

feikiss opened this issue May 30, 2016 · 2 comments

Comments

@feikiss
Copy link

feikiss commented May 30, 2016

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?

@JamesMessinger
Copy link
Owner

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

@feikiss
Copy link
Author

feikiss commented Jun 1, 2016

@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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants