swagger-commander v0.6.7
Swagger Commander
Inspired by Swagger UI, Swagger Commander is a plug & play command-line (terminal, CLI, console, etc) tool to visualize and consume Swagger API's. Simply point the tool to a Swagger specification (file) URL and you can immediately view and consume your API endpoints. Under the covers, swagger-commander uses swagger-client.
Installation
Install globally as root:
# npm install -g swagger-commanderOn Ubuntu or Mac OS X systems install using sudo:
$ sudo npm install -g swagger-commanderUsage
Point swagger-commander to a Swagger spec (file) URL:
$ swagger-commander set-swagger-url <url>
example: swagger-commander set-swagger-url http://petstore.swagger.io/v2/swagger.jsonShow available resources/commands for the Swagger API you just set
$ swagger-commander -hExample using Swagger petstore demo
Show available sub-commands for the "pet" resource (output not shown)
$ swagger-commander pet -hShow detailed help for the "addPet" operation (output not shown)
$ swagger-commander pet addPet -hRun the addPet operation (notice the JSON enclosed in single quotes)
$ swagger-commander pet addPet '{"name":"Weasley", "status":"sold"}'
info: status: 200
info: data: {"id":1459973494707,"name":"Weasley","photoUrls":[],"tags":[],"status":"sold"}Optionally use file as argument
$ swagger-commander pet addPet @path/to/file/pet.jsonGet the pet object you just created
$ swagger-commander pet getPetById 1459973494707
info: status: 200
info: data: {"id":1459973494707,"name":"Weasley","photoUrls":[],"tags":[],"status":"sold"}Authorizations
One time auth using header key or password auth (more available through help commands):
$ swagger-commander pet addPet {} -K "someHeaderAuth,nameOfHeader,someValue"
$ swagger-commander pet addPet {} -W "somePasswordAuth,user_name,password"Note the authorization nickname, such as someHeaderAuth and somePasswordAuth in the above example, must match the security requirement in the specification (see the OAI Specification for details).
Store/save auth parameters:
$ TODO coming soonLocal swagger-commander config
By default, swagger-commander uses a global config file to run, but it will look in the current working directory for a file named ".swagger-commander.json" and use that instead.
Available config options for ".swagger-commander.json"
- "swagger_spec_url" - The full url to a Swagger spec.
- "auth" - A map of objects where the key matches the auth nickname defined in the Swagger spec, and the value is an auth object which varies depending on the type. See examples/.swagger-commander.json for complete details.
.swagger-commander.json example:
{
"swagger_spec_url": "http://petstore.swagger.io/v2/swagger.json",
"auth": {
"somePasswordAuth": {
"type": "password",
"userName": "someUser",
"password": "somePassword"
},
"api_key": {
"type": "header",
"nameOfHeader": "api_key",
"value": "special-key"
}
}
}Help
- JSON/Object arguments must be enclosed in single quotes and follow valid JSON rules (arguments enclosed in double quotes, etc)
Array arguments are comma seperated strings (DO NOT include array brackets)
$ swagger-commander pet findPetsByStatus "available, sold"
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago