maxdome / swagger-combine

Combines multiple Swagger schemas into one dereferenced schema.
MIT License
132 stars 36 forks source link

Add '-w | --watch' Flag to Continuously Recombine #75

Closed ziadsawalha closed 5 years ago

ziadsawalha commented 5 years ago

I'm not a seasoned JavaScript developer, so I'm happy to receive guidance on this implementation.

We're using swagger-combine in a project and we want to be able to view our changes in near realtime. So we added a --watch flag that keeps the process running, keeps track of all files read from disk, watches for changes in them using node-watch and re-run's swagger-combine on a change.

To not interrupt the development process when an error is saved to a watched file, we only log them and continue watching.

Happy to add tests once the direction is approved and advice on the solution is given.

fabsrc commented 5 years ago

Hi @ziadsawalha.

Thanks for your pull request.

While I understand your need for this feature, I'm not quite convinced to add this functionality to the package itself. It adds more complexity, although this is something which can be easily solved with tools like nodemon.

The example you added:

swagger-combine config.json -o combinedSchema.json -w

can be done with nodemon like this:

nodemon -w config.json -x swagger-combine config.json -o combinedSchema.json
ziadsawalha commented 4 years ago

Coming back to this after a while. I just tried to solve this using nodemon as you suggested and while nodemon can watch the spec (or a list of files or directories), it cannot do what this PR does, which is just watch the files that were actually used in the spec.

Needless to say, the point of using swagger-combine for us is to combine many specs (and files referenced from within those specs).

For example, when I run the command below, the 39 files that swagger-combine knows were referenced from my specs are watched. These come from a variety of sources on my drive (specs, schema files, shared parameter definitions, etc...). I'm not sure how I could do that with nodemon without knowing the list of files beforehand.

% bin/swagger-combine ../../platform/api/main.yaml -o api.yaml -w                                        
Watching 39 files

I appreciate, however, that it does add complexity. Any suggestions on how to simplify it maybe?