Converting a Swagger YAML file to JSON from the command line

I think that you are looking for the swagger-codegen (now OpenApi-generator) functionality:

Running

swagger-codegen generate -i swagger.yaml -l swagger

will out put a swagger.json in the same location.

Update For CI:
If you can install it on your build machine- good for you.
If you can’t – the github page has a link to a docker image with a nodejs server is available (to convert using a curl command as suggested in a different answer).

Update For Docker:
If you use Docker, try swaggerapi/swagger-codegen-cli, there is an example for docker-compose that might help a few answers down by Fabian & ckeeney.

Update about OpenApi:

This question is about swagger, and a few years old. If you’re just starting to use Swagger you should switch to OpenApi instead, and if you have existing swagger files, i suggest migrating.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)