openapi-generator/samples/client/petstore/bash
Pavel Tavoda d412bcfd6c Fix to #6141 - [BASH] Bug generating access_token when "in: query" (#6187)
* Fix to #6141 - [BASH] Bug generating access_token when "in: query"

* Fresh petstore scripts
2017-07-28 16:00:44 +08:00
..
.swagger-codegen Fix to #6141 - [BASH] Bug generating access_token when "in: query" (#6187) 2017-07-28 16:00:44 +08:00
tests [Bash] Bugfix default curl options fix (#4832) 2017-03-02 17:48:30 +08:00
_petstore-cli Fix to #6141 - [BASH] Bug generating access_token when "in: query" (#6187) 2017-07-28 16:00:44 +08:00
.swagger-codegen-ignore [Bash] Bash client script generator (#4541) 2017-01-12 16:48:25 +08:00
Dockerfile Update all the samples. 2017-03-13 19:50:10 +01:00
petstore-cli Fix to #6141 - [BASH] Bug generating access_token when "in: query" (#6187) 2017-07-28 16:00:44 +08:00
petstore-cli.bash-completion Fix to #6141 - [BASH] Bug generating access_token when "in: query" (#6187) 2017-07-28 16:00:44 +08:00
pom.xml [Bash] Bash client script generator (#4541) 2017-01-12 16:48:25 +08:00
README.md [Bash] Bash generator improvements (#4730) 2017-02-07 23:15:05 +08:00

Swagger Petstore Bash client

Overview

This is a Bash client script for accessing Swagger Petstore service.

The script uses cURL underneath for making all REST calls.

Usage

# Make sure the script has executable rights
$ chmod u+x petstore-cli

# Print the list of operations available on the service
$ ./petstore-cli -h

# Print the service description
$ ./petstore-cli --about

# Print detailed information about specific operation
$ ./petstore-cli <operationId> -h

# Make GET request
./petstore-cli --host http://<hostname>:<port> --accept xml <operationId> <queryParam1>=<value1> <header_key1>:<header_value2>

# Make GET request using arbitrary curl options (must be passed before <operationId>) to an SSL service using username:password
petstore-cli -k -sS --tlsv1.2 --host https://<hostname> -u <user>:<password> --accept xml <operationId> <queryParam1>=<value1> <header_key1>:<header_value2>

# Make POST request
$ echo '<body_content>' | petstore-cli --host <hostname> --content-type json <operationId> -

# Make POST request with simple JSON content, e.g.:
# {
#   "key1": "value1",
#   "key2": "value2",
#   "key3": 23
# }
$ echo '<body_content>' | petstore-cli --host <hostname> --content-type json <operationId> key1==value1 key2=value2 key3:=23 -

# Preview the cURL command without actually executing it
$ petstore-cli --host http://<hostname>:<port> --dry-run <operationid>

Docker image

You can easily create a Docker image containing a preconfigured environment for using the REST Bash client including working autocompletion and short welcome message with basic instructions, using the generated Dockerfile:

docker build -t my-rest-client .
docker run -it my-rest-client

By default you will be logged into a Zsh environment which has much more advanced auto completion, but you can switch to Bash, where basic autocompletion is also available.

Shell completion

Bash

The generated bash-completion script can be either directly loaded to the current Bash session using:

source petstore-cli.bash-completion

Alternatively, the script can be copied to the /etc/bash-completion.d (or on OSX with Homebrew to /usr/local/etc/bash-completion.d):

sudo cp petstore-cli.bash-completion /etc/bash-completion.d/petstore-cli

OS X

On OSX you might need to install bash-completion using Homebrew:

brew install bash-completion

and add the following to the ~/.bashrc:

if [ -f $(brew --prefix)/etc/bash_completion ]; then
  . $(brew --prefix)/etc/bash_completion
fi

Zsh

In Zsh, the generated _petstore-cli Zsh completion file must be copied to one of the folders under $FPATH variable.