diff --git a/modules/swagger-codegen/src/main/resources/bash/client.mustache b/modules/swagger-codegen/src/main/resources/bash/client.mustache index bd17edbb3c5..e4c7ee2b61e 100644 --- a/modules/swagger-codegen/src/main/resources/bash/client.mustache +++ b/modules/swagger-codegen/src/main/resources/bash/client.mustache @@ -25,6 +25,9 @@ # {{#externalDocs}}{{url}}{{/externalDocs}} # +# For improved pattern matching in case statemets +shopt -s extglob + ############################################################################### # # Make sure Bash is at least in version 4.3 @@ -62,6 +65,32 @@ declare -A header_arguments # can be provided for the same parameter if allowed by API specification declare -A operation_parameters +## +# Declare colors with autodection if output is terminal +if [ -t 1 ]; then + RED="$(tput setaf 1)" + GREEN="$(tput setaf 2)" + YELLOW="$(tput setaf 3)" + BLUE="$(tput setaf 4)" + MAGENTA="$(tput setaf 5)" + CYAN="$(tput setaf 6)" + WHITE="$(tput setaf 7)" + BOLD="$(tput bold)" + OFF="$(tput sgr0)" +else + RED="" + GREEN="" + YELLOW="" + BLUE="" + MAGENTA="" + CYAN="" + WHITE="" + BOLD="" + OFF="" +fi + +declare -a result_color_table=( "$WHITE" "$WHITE" "$GREEN" "$YELLOW" "$WHITE" "$MAGENTA" "$WHITE" ) + ## # This array stores the minimum number of required occurences for parameter # 0 - optional @@ -208,6 +237,7 @@ url_escape() { -e 's/(/%28/g' \ -e 's/)/%29/g' \ -e 's/:/%3A/g' \ + -e 's/\t/%09/g' \ -e 's/?/%3F/g' <<<$raw_url); echo $value @@ -288,11 +318,10 @@ body_parameters_to_json() { local body_parameter_count=${#body_parameters[@]} local count=0 for key in "${!body_parameters[@]}"; do - body_json+="\"${key}\": ${body_parameters[${key}]}" - if [[ $count -lt $body_parameter_count-1 ]]; then + if [[ $((count++)) -gt 0 ]]; then body_json+=", " fi - ((count+=1)) + body_json+="\"${key}\": ${body_parameters[${key}]}" done body_json+="}'" @@ -305,127 +334,24 @@ body_parameters_to_json() { ############################################################################## # -# Check if provided parameters match specification requirements +# Helper method for showing error because for example echo in +# build_request_path() is evaluated as part of command line not printed on +# output. Anyway better idea for resource clean up ;-). # ############################################################################## -validate_request_parameters() { - local path_template=$1 - local -n path_params=$2 - local -n query_params=$3 - - # First replace all path parameters in the path - for pparam in "${path_params[@]}"; do - regexp="(.*)(\{$pparam\})(.*)" - if [[ $path_template =~ $regexp ]]; then - path_template=${BASH_REMATCH[1]}${operation_parameters[$pparam]}${BASH_REMATCH[3]} - fi - done - - # Now append query parameters - if any - if [[ ${#query_params[@]} -gt 0 ]]; then - path_template+="?" +ERROR_MSG="" +function finish { + if [[ -n "$ERROR_MSG" ]]; then + echo >&2 "${OFF}${RED}$ERROR_MSG" + echo >&2 "${OFF}Check usage: '${script_name} --help'" fi - - local query_parameter_count=${#query_params[@]} - local count=0 - for qparam in "${query_params[@]}"; do - # Get the array of parameter values - local parameter_values=($(echo "${operation_parameters[$qparam]}" | sed -e 's/'":::"'/\n/g' | while read line; do echo $line | sed 's/[\t ]/'":::"'/g'; done)) - - # - # Check if the number of provided values is not less than minimum - # required - # - if [[ "$force" = false ]]; then - if [[ ${#parameter_values[@]} -lt ${operation_parameters_minimum_occurences["${operation}:::${qparam}"]} ]]; then - echo "Error: Too few values provided for '${qparam}' parameter" - exit 1 - fi - - # - # Check if the number of provided values is not more than maximum - # - if [[ ${operation_parameters_maximum_occurences["${operation}:::${qparam}"]} -gt 0 \ - && ${#parameter_values[@]} -gt ${operation_parameters_maximum_occurences["${operation}:::${qparam}"]} ]]; then - if [[ "$force" = false ]]; then - echo "Error: Too many values provided for '${qparam}' parameter" - exit 1 - fi - fi - fi - - if [[ "${operation_parameters_collection_type[${operation}:::${qparam}]}" == "" ]]; then - local vcount=0 - for qvalue in "${parameter_values[@]}"; do - path_template+="${qparam}=${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then - path_template+="&" - fi - ((vcount+=1)) - done - elif [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "multi" ]]; then - local vcount=0 - for qvalue in "${parameter_values[@]}"; do - path_template+="${qparam}=${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then - path_template+="&" - fi - ((vcount+=1)) - done - elif [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "csv" ]]; then - path_template+="${qparam}=" - local vcount=0 - for qvalue in "${parameter_values[@]}"; do - path_template+="${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then - path_template+="," - fi - ((vcount+=1)) - done - elif [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "ssv" ]]; then - path_template+="${qparam}=" - for qvalue in "${parameter_values[@]}"; do - path_template+="${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then - path_template+=" " - fi - ((vcount+=1)) - done - elif [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "tsv" ]]; then - path_template+="${qparam}=" - for qvalue in "${parameter_values[@]}"; do - path_template+="${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then - path_template+="\t" - fi - ((vcount+=1)) - done - else - echo -e "" - echo -e "Error: Unsupported collection format " - echo -e "" - exit 1 - fi - - - if [[ $count -lt $query_parameter_count-1 ]]; then - path_template+="&" - fi - ((count+=1)) - done - } - +trap finish EXIT ############################################################################## # -# Build request path including query parameters +# Validate and build request path including query parameters # ############################################################################## build_request_path() { @@ -434,10 +360,39 @@ build_request_path() { local -n query_params=$3 + # + # Check input paramaters count against minimum and maximum required + # + if [[ "$force" = false ]]; then + local was_error="" + for qparam in "${query_params[@]}" "${path_params[@]}"; do + local parameter_values=($(sed -e 's/'":::"'/\n/g' <<<"${operation_parameters[$qparam]}")) + + # + # Check if the number of provided values is not less than minimum required + # + if [[ ${#parameter_values[@]} -lt ${operation_parameters_minimum_occurences["${operation}:::${qparam}"]} ]]; then + echo "ERROR: Too few values provided for '${qparam}' parameter." + was_error=true + fi + + # + # Check if the number of provided values is not more than maximum + # + if [[ ${operation_parameters_maximum_occurences["${operation}:::${qparam}"]} -gt 0 \ + && ${#parameter_values[@]} -gt ${operation_parameters_maximum_occurences["${operation}:::${qparam}"]} ]]; then + echo "ERROR: Too many values provided for '${qparam}' parameter" + was_error=true + fi + done + if [[ -n "$was_error" ]]; then + exit 1 + fi + fi + # First replace all path parameters in the path for pparam in "${path_params[@]}"; do - regexp="(.*)(\{$pparam\})(.*)" - if [[ $path_template =~ $regexp ]]; then + if [[ $path_template =~ (.*)(\{$pparam\})(.*) ]]; then path_template=${BASH_REMATCH[1]}${operation_parameters[$pparam]}${BASH_REMATCH[3]} fi done @@ -448,116 +403,105 @@ build_request_path() { local count=0 for qparam in "${query_params[@]}"; do # Get the array of parameter values - local parameter_values=($(echo "${operation_parameters[$qparam]}" | sed -e 's/'":::"'/\n/g' | while read line; do echo $line | sed 's/[\t ]/'":::"'/g'; done)) + local parameter_values=($(sed -e 's/'":::"'/\n/g' <<<"${operation_parameters[$qparam]}")) local parameter_value="" - # - # Check if the number of provided values is not less than minimum - # required - # - if [[ "$force" = false ]]; then - if [[ ${#parameter_values[@]} -lt ${operation_parameters_minimum_occurences["${operation}:::${qparam}"]} ]]; then - echo "Error: Too few values provided for '${qparam}' parameter" - exit 1 - fi - - # - # Check if the number of provided values is not more than maximum - # - if [[ ${operation_parameters_maximum_occurences["${operation}:::${qparam}"]} -gt 0 \ - && ${#parameter_values[@]} -gt ${operation_parameters_maximum_occurences["${operation}:::${qparam}"]} ]]; then - if [[ "$force" = false ]]; then - echo "Error: Too many values provided for '${qparam}' parameter" - exit 1 - fi + if [[ -n "${parameter_values[@]}" ]]; then + if [[ $((count++)) -gt 0 ]]; then + query_request_part+="&" fi fi # # Append parameters without specific cardinality # - if [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "" ]]; then + local collection_type="${operation_parameters_collection_type["${operation}:::${qparam}"]}" +{{#hasAuthMethods}} +{{#authMethods}} +{{#isApiKey}} +{{#isKeyInQuery}} + if [[ ${qparam} == "{{keyParamName}}" ]]; then + if [[ -n "${parameter_values[@]}" ]]; then + parameter_value+="${qparam}=${parameter_values}" +{{#x-codegen-apikey-env}} + elif [[ -n "$MATRIX_API_KEY" ]]; then + parameter_value+="${qparam}=${{x-codegen-apikey-env}}" +{{/x-codegen-apikey-env}} + else + echo "Missing ApiKey!!! {{#x-codegen-apikey-env}}Define env variable {{x-codegen-apikey-env}} like 'export {{x-codegen-apikey-env}}=...' or{{/x-codegen-apikey-env}}{{^x-codegen-apikey-env}}You have to{{/x-codegen-apikey-env}} provide on command line option '{{keyParamName}}=...'" + exit 1 + fi + elif{{/isKeyInQuery}}{{^isKeyInQuery}} + if{{/isKeyInQuery}}{{/isApiKey}}{{/authMethods}}{{/hasAuthMethods}} [[ "${collection_type}" == "" ]]; then local vcount=0 for qvalue in "${parameter_values[@]}"; do - parameter_value+="${qparam}=${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then + if [[ $((vcount++)) -gt 0 ]]; then parameter_value+="&" fi - ((vcount+=1)) + parameter_value+="${qparam}=${qvalue}" done # # Append parameters specified as 'mutli' collections i.e. param=value1¶m=value2&... # - elif [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "multi" ]]; then + elif [[ "${collection_type}" == "multi" ]]; then local vcount=0 for qvalue in "${parameter_values[@]}"; do - parameter_value+="${qparam}=${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then + if [[ $((vcount++)) -gt 0 ]]; then parameter_value+="&" fi - ((vcount+=1)) + parameter_value+="${qparam}=${qvalue}" done # # Append parameters specified as 'csv' collections i.e. param=value1,value2,... # - elif [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "csv" ]]; then + elif [[ "${collection_type}" == "csv" ]]; then parameter_value+="${qparam}=" local vcount=0 for qvalue in "${parameter_values[@]}"; do - parameter_value+="${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then + if [[ $((vcount++)) -gt 0 ]]; then parameter_value+="," fi - ((vcount+=1)) + parameter_value+="${qvalue}" done # # Append parameters specified as 'ssv' collections i.e. param="value1 value2 ..." # - elif [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "ssv" ]]; then + elif [[ "${collection_type}" == "ssv" ]]; then parameter_value+="${qparam}=" local vcount=0 for qvalue in "${parameter_values[@]}"; do - parameter_value+="${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then + if [[ $((vcount++)) -gt 0 ]]; then parameter_value+=" " fi - ((vcount+=1)) + parameter_value+="${qvalue}" done # # Append parameters specified as 'tsv' collections i.e. param="value1\tvalue2\t..." # - elif [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "tsv" ]]; then + elif [[ "${collection_type}" == "tsv" ]]; then parameter_value+="${qparam}=" local vcount=0 for qvalue in "${parameter_values[@]}"; do - parameter_value+="${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then + if [[ $((vcount++)) -gt 0 ]]; then parameter_value+="\t" fi - ((vcount+=1)) + parameter_value+="${qvalue}" done + else + echo "Unsupported collection format \"${collection_type}\"" + exit 1 fi if [[ -n "${parameter_value}" ]]; then query_request_part+="${parameter_value}" fi - if [[ $count -lt $query_parameter_count-1 && -n "${parameter_value}" ]]; then - query_request_part+="&" - fi - - ((count+=1)) done # Now append query parameters - if any if [[ -n "${query_request_part}" ]]; then - path_template+="?$(echo ${query_request_part} | sed s'/&$//')" + path_template+="?${query_request_part}" fi echo $path_template @@ -573,52 +517,52 @@ build_request_path() { print_help() { cat <$(tput sgr0)] - [-ac|--accept $(tput setaf 2)$(tput sgr0)] [-ct,--content-type $(tput setaf 2)$(tput sgr0)] - [--host $(tput setaf 6)$(tput sgr0)] [--dry-run] $(tput setaf 3)$(tput sgr0) [-h|--help] [$(tput setaf 4)$(tput sgr0)] - [$(tput setaf 5)$(tput sgr0)] [$(tput setaf 5)$(tput sgr0)] + ${GREEN}${script_name}${OFF} [-h|--help] [-V|--version] [--about] [${RED}${OFF}] + [-ac|--accept ${GREEN}${OFF}] [-ct,--content-type ${GREEN}${OFF}] + [--host ${CYAN}${OFF}] [--dry-run] [-nc|--no-colors] ${YELLOW}${OFF} [-h|--help] + [${BLUE}${OFF}] [${MAGENTA}${OFF}] [${MAGENTA}${OFF}] - - $(tput setaf 6)$(tput sgr0) - endpoint of the REST service without basepath + - ${CYAN}${OFF} - endpoint of the REST service without basepath {{#x-codegen-host-env}} Can also be specified in {{x-codegen-host-env}} environment variable.{{/x-codegen-host-env}} - - $(tput setaf 1)$(tput sgr0) - any valid cURL options can be passed before $(tput setaf 3)$(tput sgr0) - - $(tput setaf 2)$(tput sgr0) - either full mime-type or one of supported abbreviations: + - ${RED}${OFF} - any valid cURL options can be passed before ${YELLOW}${OFF} + - ${GREEN}${OFF} - either full mime-type or one of supported abbreviations: (text, html, md, csv, css, rtf, json, xml, yaml, js, bin, rdf, jpg, png, gif, bmp, tiff) - - $(tput setaf 4)$(tput sgr0) - HTTP headers can be passed in the form $(tput setaf 3)HEADER$(tput sgr0):$(tput setaf 4)VALUE$(tput sgr0) - - $(tput setaf 5)$(tput sgr0) - REST operation parameters can be passed in the following + - ${BLUE}${OFF} - HTTP headers can be passed in the form ${YELLOW}HEADER${OFF}:${BLUE}VALUE${OFF} + - ${MAGENTA}${OFF} - REST operation parameters can be passed in the following forms: - * $(tput setaf 3)KEY$(tput sgr0)=$(tput setaf 4)VALUE$(tput sgr0) - path or query parameters - - $(tput setaf 5)$(tput sgr0) - simple JSON body content (first level only) can be build + * ${YELLOW}KEY${OFF}=${BLUE}VALUE${OFF} - path or query parameters + - ${MAGENTA}${OFF} - simple JSON body content (first level only) can be build using the following arguments: - * $(tput setaf 3)KEY$(tput sgr0)==$(tput setaf 4)VALUE$(tput sgr0) - body parameters which will be added to body - JSON as '{ ..., "$(tput setaf 3)KEY$(tput sgr0)": "$(tput setaf 4)VALUE$(tput sgr0)", ... }' - * $(tput setaf 3)KEY$(tput sgr0):=$(tput setaf 4)VALUE$(tput sgr0) - body parameters which will be added to body - JSON as '{ ..., "$(tput setaf 3)KEY$(tput sgr0)": $(tput setaf 4)VALUE$(tput sgr0), ... }' + * ${YELLOW}KEY${OFF}==${BLUE}VALUE${OFF} - body parameters which will be added to body + JSON as '{ ..., "${YELLOW}KEY${OFF}": "${BLUE}VALUE${OFF}", ... }' + * ${YELLOW}KEY${OFF}:=${BLUE}VALUE${OFF} - body parameters which will be added to body + JSON as '{ ..., "${YELLOW}KEY${OFF}": ${BLUE}VALUE${OFF}, ... }' EOF {{#hasAuthMethods}} - echo -e "$(tput bold)$(tput setaf 7)Authentication methods$(tput sgr0)" + echo -e "${BOLD}${WHITE}Authentication methods${OFF}" echo -e "" {{#authMethods}} {{#isBasic}} - echo -e " - $(tput setaf 4)Basic AUTH$(tput sgr0) - add '-u :' before $(tput setaf 3)$(tput sgr0)" - {{#x-codegen-basicauth-env}}echo -e " or export $(tput setaf 1){{x-codegen-basicauth-env}}=':'$(tput sgr0)"{{/x-codegen-basicauth-env}} + echo -e " - ${BLUE}Basic AUTH${OFF} - add '-u :' before ${YELLOW}${OFF}" + {{#x-codegen-basicauth-env}}echo -e " or export ${RED}{{x-codegen-basicauth-env}}=':'${OFF}"{{/x-codegen-basicauth-env}} {{/isBasic}} {{#isApiKey}} {{#isKeyInHeader}} - echo -e " - $(tput setaf 4)Api-key$(tput sgr0) - add '$(tput setaf 1){{keyParamName}}:$(tput sgr0)' after $(tput setaf 3)$(tput sgr0)" + echo -e " - ${BLUE}Api-key${OFF} - add '${RED}{{keyParamName}}:${OFF}' after ${YELLOW}${OFF}" {{/isKeyInHeader}} {{#isKeyInQuery}} - echo -e " - $(tput setaf 4)Api-key$(tput sgr0) - add '$(tput setaf 1){{keyParamName}}=$(tput sgr0)' after $(tput setaf 3)$(tput sgr0)" + echo -e " - ${BLUE}Api-key${OFF} - add '${RED}{{keyParamName}}=${OFF}' after ${YELLOW}${OFF}" {{/isKeyInQuery}} - {{#x-codegen-apikey-env}}echo -e " or export $(tput setaf 1){{x-codegen-apikey-env}}=''$(tput sgr0)"{{/x-codegen-apikey-env}} + {{#x-codegen-apikey-env}}echo -e " or export ${RED}{{x-codegen-apikey-env}}=''${OFF}"{{/x-codegen-apikey-env}} {{/isApiKey}} {{#isOAuth}} - echo -e " - $(tput setaf 5)OAuth2 (flow: {{flow}})$(tput sgr0)" + echo -e " - ${MAGENTA}OAuth2 (flow: {{flow}})${OFF}" echo -e " Authorization URL: " echo -e " * {{authorizationUrl}}" echo -e " Scopes:" @@ -629,15 +573,15 @@ EOF {{/authMethods}} echo "" {{/hasAuthMethods}} - echo -e "$(tput bold)$(tput setaf 7)Operations (grouped by tags)$(tput sgr0)" + echo -e "${BOLD}${WHITE}Operations (grouped by tags)${OFF}" {{#apiInfo}} {{#apis}} echo "" - echo -e "$(tput bold)$(tput setaf 7)[{{classVarName}}]$(tput sgr0)" + echo -e "${BOLD}${WHITE}[{{classVarName}}]${OFF}" read -d '' ops <$(tput sgr0)\t\t\t\tSpecify the host URL " + echo -e " --host ${CYAN}${OFF}\t\t\t\tSpecify the host URL " {{#swagger}} {{#host}}echo -e " \t\t\t\t(e.g. 'https://{{host}}')"{{/host}} {{^host}}echo -e " \t\t\t\t(e.g. 'https://127.0.0.1:8080')"{{/host}} @@ -658,8 +602,9 @@ echo " $ops" | column -t -s ';' echo -e " \t\t\t\trequired parameters or wrong content type" echo -e " --dry-run\t\t\t\tPrint out the cURL command without" echo -e " \t\t\t\texecuting it" - echo -e " -ac,--accept $(tput setaf 3)$(tput sgr0)\t\tSet the 'Accept' header in the request" - echo -e " -ct,--content-type $(tput setaf 3)$(tput sgr0)\tSet the 'Content-type' header in " + echo -e " -nc,--no-colors\t\t\tEnforce print without colors, otherwise autodected" + echo -e " -ac,--accept ${YELLOW}${OFF}\t\tSet the 'Accept' header in the request" + echo -e " -ct,--content-type ${YELLOW}${OFF}\tSet the 'Content-type' header in " echo -e " \tthe request" echo "" } @@ -672,7 +617,7 @@ echo " $ops" | column -t -s ';' ############################################################################## print_about() { echo "" - echo -e "$(tput bold)$(tput setaf 7){{appName}} command line client (API version {{#swagger}}{{#info}}{{version}}{{/info}}{{/swagger}})$(tput sgr0)" + echo -e "${BOLD}${WHITE}{{appName}} command line client (API version {{#swagger}}{{#info}}{{version}}{{/info}}{{/swagger}})${OFF}" echo "" echo -e "License: {{#swagger}}{{#info}}{{#license}}{{name}}{{/license}}{{/info}}{{/swagger}}" echo -e "Contact: {{#swagger}}{{#info}}{{#contact}}{{email}}{{/contact}}{{/info}}{{/swagger}}" @@ -681,7 +626,7 @@ read -d '' appdescription </dev/null 2>&1 || { echo >&2 "Error: You do not have 'cURL' installed."; exit 1; } -type sed >/dev/null 2>&1 || { echo >&2 "Error: You do not have 'sed' installed."; exit 1; } -type column >/dev/null 2>&1 || { echo >&2 "Error: You do not have 'bsdmainutils' installed."; exit 1; } +type curl >/dev/null 2>&1 || { echo >&2 "ERROR: You do not have 'cURL' installed."; exit 1; } +type sed >/dev/null 2>&1 || { echo >&2 "ERROR: You do not have 'sed' installed."; exit 1; } +type column >/dev/null 2>&1 || { echo >&2 "ERROR: You do not have 'bsdmainutils' installed."; exit 1; } # # Process command line @@ -988,6 +916,18 @@ case $key in --dry-run) print_curl=true ;; + -nc|--no-colors) + RED="" + GREEN="" + YELLOW="" + BLUE="" + MAGENTA="" + CYAN="" + WHITE="" + BOLD="" + OFF="" + result_color_table=( "" "" "" "" "" "" "" ) + ;; {{#apiInfo}} {{#apis}} {{#operations}} @@ -1015,7 +955,7 @@ case $key in body_parameters[${body_key}]=${body_value} fi ;; - *:*) + +([^=]):*) # Parse header arguments and convert them into curl # only after the operation argument if [[ "$operation" ]]; then @@ -1076,15 +1016,13 @@ done # Check if user provided host name if [[ -z "$host" ]]; then - echo "Error: No hostname provided!!!" - echo "Check usage: '${script_name} --help'" + ERROR_MSG="ERROR: No hostname provided!!! {{#x-codegen-host-env}}Define env variable {{x-codegen-host-env}} like 'export {{x-codegen-host-env}}=...' or{{/x-codegen-host-env}}{{^x-codegen-host-env}}You have to {{/x-codegen-host-env}} provide on command line option '--host ...'" exit 1 fi # Check if user specified operation ID if [[ -z "$operation" ]]; then - echo "Error: No operation specified!" - echo "Check available operations: '${script_name} --help'" + ERROR_MSG="ERROR: No operation specified!!!" exit 1 fi @@ -1103,8 +1041,6 @@ case $operation in {{/apis}} {{/apiInfo}} *) - echo "Error: Unknown operation: $operation" - echo "" - print_help + ERROR_MSG="ERROR: Unknown operation: $operation" exit 1 esac diff --git a/samples/client/petstore/bash/.swagger-codegen/VERSION b/samples/client/petstore/bash/.swagger-codegen/VERSION index 7fea99011a6..f9f7450d135 100644 --- a/samples/client/petstore/bash/.swagger-codegen/VERSION +++ b/samples/client/petstore/bash/.swagger-codegen/VERSION @@ -1 +1 @@ -2.2.3-SNAPSHOT \ No newline at end of file +2.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/bash/_petstore-cli b/samples/client/petstore/bash/_petstore-cli index 10cd43c62b7..dc33ceaabf8 100644 --- a/samples/client/petstore/bash/_petstore-cli +++ b/samples/client/petstore/bash/_petstore-cli @@ -305,7 +305,8 @@ case $state in 假端點 偽のエンドポイント 가짜 엔드 포인트]" \ - "testEnumParameters[To test enum parameters]" "testClassname[To test class name in snake case]" "addPet[Add a new pet to the store]" \ + "testEnumParameters[To test enum parameters]" \ + "testJsonFormData[test json serialization of form data]" "testClassname[To test class name in snake case]" "addPet[Add a new pet to the store]" \ "deletePet[Deletes a pet]" \ "findPetsByStatus[Finds Pets by status]" \ "findPetsByTags[Finds Pets by tags]" \ @@ -376,6 +377,12 @@ case $state in ) _describe -t actions 'operations' _op_arguments -S '' && ret=0 ;; + testJsonFormData) + local -a _op_arguments + _op_arguments=( + ) + _describe -t actions 'operations' _op_arguments -S '' && ret=0 + ;; testClassname) local -a _op_arguments _op_arguments=( diff --git a/samples/client/petstore/bash/petstore-cli b/samples/client/petstore/bash/petstore-cli index 6d3dffc15f8..bbf14fc9e01 100755 --- a/samples/client/petstore/bash/petstore-cli +++ b/samples/client/petstore/bash/petstore-cli @@ -24,6 +24,9 @@ # http://swagger.io # +# For improved pattern matching in case statemets +shopt -s extglob + ############################################################################### # # Make sure Bash is at least in version 4.3 @@ -61,6 +64,32 @@ declare -A header_arguments # can be provided for the same parameter if allowed by API specification declare -A operation_parameters +## +# Declare colors with autodection if output is terminal +if [ -t 1 ]; then + RED="$(tput setaf 1)" + GREEN="$(tput setaf 2)" + YELLOW="$(tput setaf 3)" + BLUE="$(tput setaf 4)" + MAGENTA="$(tput setaf 5)" + CYAN="$(tput setaf 6)" + WHITE="$(tput setaf 7)" + BOLD="$(tput bold)" + OFF="$(tput sgr0)" +else + RED="" + GREEN="" + YELLOW="" + BLUE="" + MAGENTA="" + CYAN="" + WHITE="" + BOLD="" + OFF="" +fi + +declare -a result_color_table=( "$WHITE" "$WHITE" "$GREEN" "$YELLOW" "$WHITE" "$MAGENTA" "$WHITE" ) + ## # This array stores the minimum number of required occurences for parameter # 0 - optional @@ -93,6 +122,8 @@ operation_parameters_minimum_occurences["testEnumParameters:::enum_query_string_ operation_parameters_minimum_occurences["testEnumParameters:::enum_query_string"]=0 operation_parameters_minimum_occurences["testEnumParameters:::enum_query_integer"]=0 operation_parameters_minimum_occurences["testEnumParameters:::enum_query_double"]=0 +operation_parameters_minimum_occurences["testJsonFormData:::param"]=1 +operation_parameters_minimum_occurences["testJsonFormData:::param2"]=1 operation_parameters_minimum_occurences["testClassname:::body"]=1 operation_parameters_minimum_occurences["addPet:::body"]=1 operation_parameters_minimum_occurences["deletePet:::petId"]=1 @@ -154,6 +185,8 @@ operation_parameters_maximum_occurences["testEnumParameters:::enum_query_string_ operation_parameters_maximum_occurences["testEnumParameters:::enum_query_string"]=0 operation_parameters_maximum_occurences["testEnumParameters:::enum_query_integer"]=0 operation_parameters_maximum_occurences["testEnumParameters:::enum_query_double"]=0 +operation_parameters_maximum_occurences["testJsonFormData:::param"]=0 +operation_parameters_maximum_occurences["testJsonFormData:::param2"]=0 operation_parameters_maximum_occurences["testClassname:::body"]=0 operation_parameters_maximum_occurences["addPet:::body"]=0 operation_parameters_maximum_occurences["deletePet:::petId"]=0 @@ -212,6 +245,8 @@ operation_parameters_collection_type["testEnumParameters:::enum_query_string_arr operation_parameters_collection_type["testEnumParameters:::enum_query_string"]="" operation_parameters_collection_type["testEnumParameters:::enum_query_integer"]="" operation_parameters_collection_type["testEnumParameters:::enum_query_double"]="" +operation_parameters_collection_type["testJsonFormData:::param"]="" +operation_parameters_collection_type["testJsonFormData:::param2"]="" operation_parameters_collection_type["testClassname:::body"]="" operation_parameters_collection_type["addPet:::body"]="" operation_parameters_collection_type["deletePet:::petId"]="" @@ -333,6 +368,7 @@ url_escape() { -e 's/(/%28/g' \ -e 's/)/%29/g' \ -e 's/:/%3A/g' \ + -e 's/\t/%09/g' \ -e 's/?/%3F/g' <<<$raw_url); echo $value @@ -397,11 +433,10 @@ body_parameters_to_json() { local body_parameter_count=${#body_parameters[@]} local count=0 for key in "${!body_parameters[@]}"; do - body_json+="\"${key}\": ${body_parameters[${key}]}" - if [[ $count -lt $body_parameter_count-1 ]]; then + if [[ $((count++)) -gt 0 ]]; then body_json+=", " fi - ((count+=1)) + body_json+="\"${key}\": ${body_parameters[${key}]}" done body_json+="}'" @@ -414,127 +449,24 @@ body_parameters_to_json() { ############################################################################## # -# Check if provided parameters match specification requirements +# Helper method for showing error because for example echo in +# build_request_path() is evaluated as part of command line not printed on +# output. Anyway better idea for resource clean up ;-). # ############################################################################## -validate_request_parameters() { - local path_template=$1 - local -n path_params=$2 - local -n query_params=$3 - - # First replace all path parameters in the path - for pparam in "${path_params[@]}"; do - regexp="(.*)(\{$pparam\})(.*)" - if [[ $path_template =~ $regexp ]]; then - path_template=${BASH_REMATCH[1]}${operation_parameters[$pparam]}${BASH_REMATCH[3]} - fi - done - - # Now append query parameters - if any - if [[ ${#query_params[@]} -gt 0 ]]; then - path_template+="?" +ERROR_MSG="" +function finish { + if [[ -n "$ERROR_MSG" ]]; then + echo >&2 "${OFF}${RED}$ERROR_MSG" + echo >&2 "${OFF}Check usage: '${script_name} --help'" fi - - local query_parameter_count=${#query_params[@]} - local count=0 - for qparam in "${query_params[@]}"; do - # Get the array of parameter values - local parameter_values=($(echo "${operation_parameters[$qparam]}" | sed -e 's/'":::"'/\n/g' | while read line; do echo $line | sed 's/[\t ]/'":::"'/g'; done)) - - # - # Check if the number of provided values is not less than minimum - # required - # - if [[ "$force" = false ]]; then - if [[ ${#parameter_values[@]} -lt ${operation_parameters_minimum_occurences["${operation}:::${qparam}"]} ]]; then - echo "Error: Too few values provided for '${qparam}' parameter" - exit 1 - fi - - # - # Check if the number of provided values is not more than maximum - # - if [[ ${operation_parameters_maximum_occurences["${operation}:::${qparam}"]} -gt 0 \ - && ${#parameter_values[@]} -gt ${operation_parameters_maximum_occurences["${operation}:::${qparam}"]} ]]; then - if [[ "$force" = false ]]; then - echo "Error: Too many values provided for '${qparam}' parameter" - exit 1 - fi - fi - fi - - if [[ "${operation_parameters_collection_type[${operation}:::${qparam}]}" == "" ]]; then - local vcount=0 - for qvalue in "${parameter_values[@]}"; do - path_template+="${qparam}=${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then - path_template+="&" - fi - ((vcount+=1)) - done - elif [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "multi" ]]; then - local vcount=0 - for qvalue in "${parameter_values[@]}"; do - path_template+="${qparam}=${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then - path_template+="&" - fi - ((vcount+=1)) - done - elif [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "csv" ]]; then - path_template+="${qparam}=" - local vcount=0 - for qvalue in "${parameter_values[@]}"; do - path_template+="${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then - path_template+="," - fi - ((vcount+=1)) - done - elif [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "ssv" ]]; then - path_template+="${qparam}=" - for qvalue in "${parameter_values[@]}"; do - path_template+="${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then - path_template+=" " - fi - ((vcount+=1)) - done - elif [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "tsv" ]]; then - path_template+="${qparam}=" - for qvalue in "${parameter_values[@]}"; do - path_template+="${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then - path_template+="\t" - fi - ((vcount+=1)) - done - else - echo -e "" - echo -e "Error: Unsupported collection format " - echo -e "" - exit 1 - fi - - - if [[ $count -lt $query_parameter_count-1 ]]; then - path_template+="&" - fi - ((count+=1)) - done - } - +trap finish EXIT ############################################################################## # -# Build request path including query parameters +# Validate and build request path including query parameters # ############################################################################## build_request_path() { @@ -543,10 +475,39 @@ build_request_path() { local -n query_params=$3 + # + # Check input paramaters count against minimum and maximum required + # + if [[ "$force" = false ]]; then + local was_error="" + for qparam in "${query_params[@]}" "${path_params[@]}"; do + local parameter_values=($(sed -e 's/'":::"'/\n/g' <<<"${operation_parameters[$qparam]}")) + + # + # Check if the number of provided values is not less than minimum required + # + if [[ ${#parameter_values[@]} -lt ${operation_parameters_minimum_occurences["${operation}:::${qparam}"]} ]]; then + echo "ERROR: Too few values provided for '${qparam}' parameter." + was_error=true + fi + + # + # Check if the number of provided values is not more than maximum + # + if [[ ${operation_parameters_maximum_occurences["${operation}:::${qparam}"]} -gt 0 \ + && ${#parameter_values[@]} -gt ${operation_parameters_maximum_occurences["${operation}:::${qparam}"]} ]]; then + echo "ERROR: Too many values provided for '${qparam}' parameter" + was_error=true + fi + done + if [[ -n "$was_error" ]]; then + exit 1 + fi + fi + # First replace all path parameters in the path for pparam in "${path_params[@]}"; do - regexp="(.*)(\{$pparam\})(.*)" - if [[ $path_template =~ $regexp ]]; then + if [[ $path_template =~ (.*)(\{$pparam\})(.*) ]]; then path_template=${BASH_REMATCH[1]}${operation_parameters[$pparam]}${BASH_REMATCH[3]} fi done @@ -557,116 +518,90 @@ build_request_path() { local count=0 for qparam in "${query_params[@]}"; do # Get the array of parameter values - local parameter_values=($(echo "${operation_parameters[$qparam]}" | sed -e 's/'":::"'/\n/g' | while read line; do echo $line | sed 's/[\t ]/'":::"'/g'; done)) + local parameter_values=($(sed -e 's/'":::"'/\n/g' <<<"${operation_parameters[$qparam]}")) local parameter_value="" - # - # Check if the number of provided values is not less than minimum - # required - # - if [[ "$force" = false ]]; then - if [[ ${#parameter_values[@]} -lt ${operation_parameters_minimum_occurences["${operation}:::${qparam}"]} ]]; then - echo "Error: Too few values provided for '${qparam}' parameter" - exit 1 - fi - - # - # Check if the number of provided values is not more than maximum - # - if [[ ${operation_parameters_maximum_occurences["${operation}:::${qparam}"]} -gt 0 \ - && ${#parameter_values[@]} -gt ${operation_parameters_maximum_occurences["${operation}:::${qparam}"]} ]]; then - if [[ "$force" = false ]]; then - echo "Error: Too many values provided for '${qparam}' parameter" - exit 1 - fi + if [[ -n "${parameter_values[@]}" ]]; then + if [[ $((count++)) -gt 0 ]]; then + query_request_part+="&" fi fi # # Append parameters without specific cardinality # - if [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "" ]]; then + local collection_type="${operation_parameters_collection_type["${operation}:::${qparam}"]}" + + if [[ "${collection_type}" == "" ]]; then local vcount=0 for qvalue in "${parameter_values[@]}"; do - parameter_value+="${qparam}=${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then + if [[ $((vcount++)) -gt 0 ]]; then parameter_value+="&" fi - ((vcount+=1)) + parameter_value+="${qparam}=${qvalue}" done # # Append parameters specified as 'mutli' collections i.e. param=value1¶m=value2&... # - elif [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "multi" ]]; then + elif [[ "${collection_type}" == "multi" ]]; then local vcount=0 for qvalue in "${parameter_values[@]}"; do - parameter_value+="${qparam}=${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then + if [[ $((vcount++)) -gt 0 ]]; then parameter_value+="&" fi - ((vcount+=1)) + parameter_value+="${qparam}=${qvalue}" done # # Append parameters specified as 'csv' collections i.e. param=value1,value2,... # - elif [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "csv" ]]; then + elif [[ "${collection_type}" == "csv" ]]; then parameter_value+="${qparam}=" local vcount=0 for qvalue in "${parameter_values[@]}"; do - parameter_value+="${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then + if [[ $((vcount++)) -gt 0 ]]; then parameter_value+="," fi - ((vcount+=1)) + parameter_value+="${qvalue}" done # # Append parameters specified as 'ssv' collections i.e. param="value1 value2 ..." # - elif [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "ssv" ]]; then + elif [[ "${collection_type}" == "ssv" ]]; then parameter_value+="${qparam}=" local vcount=0 for qvalue in "${parameter_values[@]}"; do - parameter_value+="${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then + if [[ $((vcount++)) -gt 0 ]]; then parameter_value+=" " fi - ((vcount+=1)) + parameter_value+="${qvalue}" done # # Append parameters specified as 'tsv' collections i.e. param="value1\tvalue2\t..." # - elif [[ "${operation_parameters_collection_type["${operation}:::${qparam}"]}" == "tsv" ]]; then + elif [[ "${collection_type}" == "tsv" ]]; then parameter_value+="${qparam}=" local vcount=0 for qvalue in "${parameter_values[@]}"; do - parameter_value+="${qvalue}" - - if [[ $vcount -lt ${#parameter_values[@]}-1 ]]; then + if [[ $((vcount++)) -gt 0 ]]; then parameter_value+="\t" fi - ((vcount+=1)) + parameter_value+="${qvalue}" done + else + echo "Unsupported collection format \"${collection_type}\"" + exit 1 fi if [[ -n "${parameter_value}" ]]; then query_request_part+="${parameter_value}" fi - if [[ $count -lt $query_parameter_count-1 && -n "${parameter_value}" ]]; then - query_request_part+="&" - fi - - ((count+=1)) done # Now append query parameters - if any if [[ -n "${query_request_part}" ]]; then - path_template+="?$(echo ${query_request_part} | sed s'/&$//')" + path_template+="?${query_request_part}" fi echo $path_template @@ -682,117 +617,119 @@ build_request_path() { print_help() { cat <$(tput sgr0)] - [-ac|--accept $(tput setaf 2)$(tput sgr0)] [-ct,--content-type $(tput setaf 2)$(tput sgr0)] - [--host $(tput setaf 6)$(tput sgr0)] [--dry-run] $(tput setaf 3)$(tput sgr0) [-h|--help] [$(tput setaf 4)$(tput sgr0)] - [$(tput setaf 5)$(tput sgr0)] [$(tput setaf 5)$(tput sgr0)] + ${GREEN}${script_name}${OFF} [-h|--help] [-V|--version] [--about] [${RED}${OFF}] + [-ac|--accept ${GREEN}${OFF}] [-ct,--content-type ${GREEN}${OFF}] + [--host ${CYAN}${OFF}] [--dry-run] [-nc|--no-colors] ${YELLOW}${OFF} [-h|--help] + [${BLUE}${OFF}] [${MAGENTA}${OFF}] [${MAGENTA}${OFF}] - - $(tput setaf 6)$(tput sgr0) - endpoint of the REST service without basepath + - ${CYAN}${OFF} - endpoint of the REST service without basepath Can also be specified in PETSTORE_HOST environment variable. - - $(tput setaf 1)$(tput sgr0) - any valid cURL options can be passed before $(tput setaf 3)$(tput sgr0) - - $(tput setaf 2)$(tput sgr0) - either full mime-type or one of supported abbreviations: + - ${RED}${OFF} - any valid cURL options can be passed before ${YELLOW}${OFF} + - ${GREEN}${OFF} - either full mime-type or one of supported abbreviations: (text, html, md, csv, css, rtf, json, xml, yaml, js, bin, rdf, jpg, png, gif, bmp, tiff) - - $(tput setaf 4)$(tput sgr0) - HTTP headers can be passed in the form $(tput setaf 3)HEADER$(tput sgr0):$(tput setaf 4)VALUE$(tput sgr0) - - $(tput setaf 5)$(tput sgr0) - REST operation parameters can be passed in the following + - ${BLUE}${OFF} - HTTP headers can be passed in the form ${YELLOW}HEADER${OFF}:${BLUE}VALUE${OFF} + - ${MAGENTA}${OFF} - REST operation parameters can be passed in the following forms: - * $(tput setaf 3)KEY$(tput sgr0)=$(tput setaf 4)VALUE$(tput sgr0) - path or query parameters - - $(tput setaf 5)$(tput sgr0) - simple JSON body content (first level only) can be build + * ${YELLOW}KEY${OFF}=${BLUE}VALUE${OFF} - path or query parameters + - ${MAGENTA}${OFF} - simple JSON body content (first level only) can be build using the following arguments: - * $(tput setaf 3)KEY$(tput sgr0)==$(tput setaf 4)VALUE$(tput sgr0) - body parameters which will be added to body - JSON as '{ ..., "$(tput setaf 3)KEY$(tput sgr0)": "$(tput setaf 4)VALUE$(tput sgr0)", ... }' - * $(tput setaf 3)KEY$(tput sgr0):=$(tput setaf 4)VALUE$(tput sgr0) - body parameters which will be added to body - JSON as '{ ..., "$(tput setaf 3)KEY$(tput sgr0)": $(tput setaf 4)VALUE$(tput sgr0), ... }' + * ${YELLOW}KEY${OFF}==${BLUE}VALUE${OFF} - body parameters which will be added to body + JSON as '{ ..., "${YELLOW}KEY${OFF}": "${BLUE}VALUE${OFF}", ... }' + * ${YELLOW}KEY${OFF}:=${BLUE}VALUE${OFF} - body parameters which will be added to body + JSON as '{ ..., "${YELLOW}KEY${OFF}": ${BLUE}VALUE${OFF}, ... }' EOF - echo -e "$(tput bold)$(tput setaf 7)Authentication methods$(tput sgr0)" + echo -e "${BOLD}${WHITE}Authentication methods${OFF}" echo -e "" - echo -e " - $(tput setaf 4)Api-key$(tput sgr0) - add '$(tput setaf 1)api_key:$(tput sgr0)' after $(tput setaf 3)$(tput sgr0)" - echo -e " or export $(tput setaf 1)PETSTORE_API_KEY=''$(tput sgr0)" - echo -e " - $(tput setaf 4)Basic AUTH$(tput sgr0) - add '-u :' before $(tput setaf 3)$(tput sgr0)" - echo -e " or export $(tput setaf 1)PETSTORE_BASIC_AUTH=':'$(tput sgr0)" - echo -e " - $(tput setaf 5)OAuth2 (flow: implicit)$(tput sgr0)" + echo -e " - ${BLUE}Api-key${OFF} - add '${RED}api_key:${OFF}' after ${YELLOW}${OFF}" + echo -e " or export ${RED}PETSTORE_API_KEY=''${OFF}" + echo -e " - ${BLUE}Basic AUTH${OFF} - add '-u :' before ${YELLOW}${OFF}" + echo -e " or export ${RED}PETSTORE_BASIC_AUTH=':'${OFF}" + echo -e " - ${MAGENTA}OAuth2 (flow: implicit)${OFF}" echo -e " Authorization URL: " echo -e " * http://petstore.swagger.io/api/oauth/dialog" echo -e " Scopes:" echo -e " * write:pets - modify pets in your account" echo -e " * read:pets - read your pets" echo "" - echo -e "$(tput bold)$(tput setaf 7)Operations (grouped by tags)$(tput sgr0)" + echo -e "${BOLD}${WHITE}Operations (grouped by tags)${OFF}" echo "" - echo -e "$(tput bold)$(tput setaf 7)[fake]$(tput sgr0)" + echo -e "${BOLD}${WHITE}[fake]${OFF}" read -d '' ops <$(tput sgr0)\t\t\t\tSpecify the host URL " + echo -e " --host ${CYAN}${OFF}\t\t\t\tSpecify the host URL " echo -e " \t\t\t\t(e.g. 'https://petstore.swagger.io:80')" echo -e " --force\t\t\t\tForce command invocation in spite of missing" echo -e " \t\t\t\trequired parameters or wrong content type" echo -e " --dry-run\t\t\t\tPrint out the cURL command without" echo -e " \t\t\t\texecuting it" - echo -e " -ac,--accept $(tput setaf 3)$(tput sgr0)\t\tSet the 'Accept' header in the request" - echo -e " -ct,--content-type $(tput setaf 3)$(tput sgr0)\tSet the 'Content-type' header in " + echo -e " -nc,--no-colors\t\t\tEnforce print without colors, otherwise autodected" + echo -e " -ac,--accept ${YELLOW}${OFF}\t\tSet the 'Accept' header in the request" + echo -e " -ct,--content-type ${YELLOW}${OFF}\tSet the 'Content-type' header in " echo -e " \tthe request" echo "" } @@ -805,7 +742,7 @@ echo -e " \t\t\t\t(e.g. 'https://petstore.swagger.io:80')" ############################################################################## print_about() { echo "" - echo -e "$(tput bold)$(tput setaf 7)Swagger Petstore command line client (API version 1.0.0)$(tput sgr0)" + echo -e "${BOLD}${WHITE}Swagger Petstore command line client (API version 1.0.0)${OFF}" echo "" echo -e "License: Apache 2.0" echo -e "Contact: apiteam@swagger.io" @@ -814,7 +751,7 @@ read -d '' appdescription < 10. Other values will generated exceptions" | fold -sw 80 + echo -e "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions" | paste -sd' ' | fold -sw 80 echo -e "" - echo -e "$(tput bold)$(tput setaf 7)Parameters$(tput sgr0)" - echo -e " * $(tput setaf 2)order_id$(tput sgr0) $(tput setaf 4)[Integer]$(tput sgr0) $(tput setaf 1)(required)$(tput sgr0)$(tput sgr0) - ID of pet that needs to be fetched $(tput setaf 3)Specify as: order_id=value$(tput sgr0)" | fold -sw 80 | sed '2,$s/^/ /' + echo -e "${BOLD}${WHITE}Parameters${OFF}" + echo -e " * ${GREEN}order_id${OFF} ${BLUE}[Integer]${OFF} ${RED}(required)${OFF}${OFF} - ID of pet that needs to be fetched ${YELLOW}Specify as: order_id=value${OFF}" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo "" - echo -e "$(tput bold)$(tput setaf 7)Responses$(tput sgr0)" - case 200 in - 1*) - echo -e "$(tput setaf 7) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac - case 400 in - 1*) - echo -e "$(tput setaf 7) 400;Invalid ID supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 400;Invalid ID supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 400;Invalid ID supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 400;Invalid ID supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 400;Invalid ID supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 400;Invalid ID supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac - case 404 in - 1*) - echo -e "$(tput setaf 7) 404;Order not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 404;Order not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 404;Order not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 404;Order not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 404;Order not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 404;Order not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac + echo -e "${BOLD}${WHITE}Responses${OFF}" + code=200 + echo -e "${result_color_table[${code:0:1}]} 200;successful operation${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' + code=400 + echo -e "${result_color_table[${code:0:1}]} 400;Invalid ID supplied${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' + code=404 + echo -e "${result_color_table[${code:0:1}]} 404;Order not found${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' } ############################################################################## # @@ -1759,55 +1173,19 @@ print_getOrderById_help() { ############################################################################## print_placeOrder_help() { echo "" - echo -e "$(tput bold)$(tput setaf 7)placeOrder - Place an order for a pet$(tput sgr0)" + echo -e "${BOLD}${WHITE}placeOrder - Place an order for a pet${OFF}" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo -e "" - echo -e "" | fold -sw 80 + echo -e "" | paste -sd' ' | fold -sw 80 echo -e "" - echo -e "$(tput bold)$(tput setaf 7)Parameters$(tput sgr0)" - echo -e " * $(tput setaf 2)body$(tput sgr0) $(tput setaf 4)[]$(tput sgr0) $(tput setaf 1)(required)$(tput sgr0)$(tput sgr0) - order placed for purchasing the pet" | fold -sw 80 | sed '2,$s/^/ /' + echo -e "${BOLD}${WHITE}Parameters${OFF}" + echo -e " * ${GREEN}body${OFF} ${BLUE}[]${OFF} ${RED}(required)${OFF}${OFF} - order placed for purchasing the pet" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo -e "" echo "" - echo -e "$(tput bold)$(tput setaf 7)Responses$(tput sgr0)" - case 200 in - 1*) - echo -e "$(tput setaf 7) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac - case 400 in - 1*) - echo -e "$(tput setaf 7) 400;Invalid Order$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 400;Invalid Order$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 400;Invalid Order$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 400;Invalid Order$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 400;Invalid Order$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 400;Invalid Order$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac + echo -e "${BOLD}${WHITE}Responses${OFF}" + code=200 + echo -e "${result_color_table[${code:0:1}]} 200;successful operation${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' + code=400 + echo -e "${result_color_table[${code:0:1}]} 400;Invalid Order${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' } ############################################################################## # @@ -1816,35 +1194,17 @@ print_placeOrder_help() { ############################################################################## print_createUser_help() { echo "" - echo -e "$(tput bold)$(tput setaf 7)createUser - Create user$(tput sgr0)" + echo -e "${BOLD}${WHITE}createUser - Create user${OFF}" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo -e "" - echo -e "This can only be done by the logged in user." | fold -sw 80 + echo -e "This can only be done by the logged in user." | paste -sd' ' | fold -sw 80 echo -e "" - echo -e "$(tput bold)$(tput setaf 7)Parameters$(tput sgr0)" - echo -e " * $(tput setaf 2)body$(tput sgr0) $(tput setaf 4)[]$(tput sgr0) $(tput setaf 1)(required)$(tput sgr0)$(tput sgr0) - Created user object" | fold -sw 80 | sed '2,$s/^/ /' + echo -e "${BOLD}${WHITE}Parameters${OFF}" + echo -e " * ${GREEN}body${OFF} ${BLUE}[]${OFF} ${RED}(required)${OFF}${OFF} - Created user object" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo -e "" echo "" - echo -e "$(tput bold)$(tput setaf 7)Responses$(tput sgr0)" - case 0 in - 1*) - echo -e "$(tput setaf 7) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac + echo -e "${BOLD}${WHITE}Responses${OFF}" + code=0 + echo -e "${result_color_table[${code:0:1}]} 0;successful operation${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' } ############################################################################## # @@ -1853,35 +1213,17 @@ print_createUser_help() { ############################################################################## print_createUsersWithArrayInput_help() { echo "" - echo -e "$(tput bold)$(tput setaf 7)createUsersWithArrayInput - Creates list of users with given input array$(tput sgr0)" + echo -e "${BOLD}${WHITE}createUsersWithArrayInput - Creates list of users with given input array${OFF}" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo -e "" - echo -e "" | fold -sw 80 + echo -e "" | paste -sd' ' | fold -sw 80 echo -e "" - echo -e "$(tput bold)$(tput setaf 7)Parameters$(tput sgr0)" - echo -e " * $(tput setaf 2)body$(tput sgr0) $(tput setaf 4)[]$(tput sgr0) $(tput setaf 1)(required)$(tput sgr0)$(tput sgr0) - List of user object" | fold -sw 80 | sed '2,$s/^/ /' + echo -e "${BOLD}${WHITE}Parameters${OFF}" + echo -e " * ${GREEN}body${OFF} ${BLUE}[]${OFF} ${RED}(required)${OFF}${OFF} - List of user object" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo -e "" echo "" - echo -e "$(tput bold)$(tput setaf 7)Responses$(tput sgr0)" - case 0 in - 1*) - echo -e "$(tput setaf 7) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac + echo -e "${BOLD}${WHITE}Responses${OFF}" + code=0 + echo -e "${result_color_table[${code:0:1}]} 0;successful operation${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' } ############################################################################## # @@ -1890,35 +1232,17 @@ print_createUsersWithArrayInput_help() { ############################################################################## print_createUsersWithListInput_help() { echo "" - echo -e "$(tput bold)$(tput setaf 7)createUsersWithListInput - Creates list of users with given input array$(tput sgr0)" + echo -e "${BOLD}${WHITE}createUsersWithListInput - Creates list of users with given input array${OFF}" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo -e "" - echo -e "" | fold -sw 80 + echo -e "" | paste -sd' ' | fold -sw 80 echo -e "" - echo -e "$(tput bold)$(tput setaf 7)Parameters$(tput sgr0)" - echo -e " * $(tput setaf 2)body$(tput sgr0) $(tput setaf 4)[]$(tput sgr0) $(tput setaf 1)(required)$(tput sgr0)$(tput sgr0) - List of user object" | fold -sw 80 | sed '2,$s/^/ /' + echo -e "${BOLD}${WHITE}Parameters${OFF}" + echo -e " * ${GREEN}body${OFF} ${BLUE}[]${OFF} ${RED}(required)${OFF}${OFF} - List of user object" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo -e "" echo "" - echo -e "$(tput bold)$(tput setaf 7)Responses$(tput sgr0)" - case 0 in - 1*) - echo -e "$(tput setaf 7) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac + echo -e "${BOLD}${WHITE}Responses${OFF}" + code=0 + echo -e "${result_color_table[${code:0:1}]} 0;successful operation${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' } ############################################################################## # @@ -1927,54 +1251,18 @@ print_createUsersWithListInput_help() { ############################################################################## print_deleteUser_help() { echo "" - echo -e "$(tput bold)$(tput setaf 7)deleteUser - Delete user$(tput sgr0)" + echo -e "${BOLD}${WHITE}deleteUser - Delete user${OFF}" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo -e "" - echo -e "This can only be done by the logged in user." | fold -sw 80 + echo -e "This can only be done by the logged in user." | paste -sd' ' | fold -sw 80 echo -e "" - echo -e "$(tput bold)$(tput setaf 7)Parameters$(tput sgr0)" - echo -e " * $(tput setaf 2)username$(tput sgr0) $(tput setaf 4)[String]$(tput sgr0) $(tput setaf 1)(required)$(tput sgr0)$(tput sgr0) - The name that needs to be deleted $(tput setaf 3)Specify as: username=value$(tput sgr0)" | fold -sw 80 | sed '2,$s/^/ /' + echo -e "${BOLD}${WHITE}Parameters${OFF}" + echo -e " * ${GREEN}username${OFF} ${BLUE}[String]${OFF} ${RED}(required)${OFF}${OFF} - The name that needs to be deleted ${YELLOW}Specify as: username=value${OFF}" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo "" - echo -e "$(tput bold)$(tput setaf 7)Responses$(tput sgr0)" - case 400 in - 1*) - echo -e "$(tput setaf 7) 400;Invalid username supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 400;Invalid username supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 400;Invalid username supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 400;Invalid username supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 400;Invalid username supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 400;Invalid username supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac - case 404 in - 1*) - echo -e "$(tput setaf 7) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac + echo -e "${BOLD}${WHITE}Responses${OFF}" + code=400 + echo -e "${result_color_table[${code:0:1}]} 400;Invalid username supplied${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' + code=404 + echo -e "${result_color_table[${code:0:1}]} 404;User not found${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' } ############################################################################## # @@ -1983,74 +1271,20 @@ print_deleteUser_help() { ############################################################################## print_getUserByName_help() { echo "" - echo -e "$(tput bold)$(tput setaf 7)getUserByName - Get user by user name$(tput sgr0)" + echo -e "${BOLD}${WHITE}getUserByName - Get user by user name${OFF}" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo -e "" - echo -e "" | fold -sw 80 + echo -e "" | paste -sd' ' | fold -sw 80 echo -e "" - echo -e "$(tput bold)$(tput setaf 7)Parameters$(tput sgr0)" - echo -e " * $(tput setaf 2)username$(tput sgr0) $(tput setaf 4)[String]$(tput sgr0) $(tput setaf 1)(required)$(tput sgr0)$(tput sgr0) - The name that needs to be fetched. Use user1 for testing. $(tput setaf 3)Specify as: username=value$(tput sgr0)" | fold -sw 80 | sed '2,$s/^/ /' + echo -e "${BOLD}${WHITE}Parameters${OFF}" + echo -e " * ${GREEN}username${OFF} ${BLUE}[String]${OFF} ${RED}(required)${OFF}${OFF} - The name that needs to be fetched. Use user1 for testing. ${YELLOW}Specify as: username=value${OFF}" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo "" - echo -e "$(tput bold)$(tput setaf 7)Responses$(tput sgr0)" - case 200 in - 1*) - echo -e "$(tput setaf 7) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac - case 400 in - 1*) - echo -e "$(tput setaf 7) 400;Invalid username supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 400;Invalid username supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 400;Invalid username supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 400;Invalid username supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 400;Invalid username supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 400;Invalid username supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac - case 404 in - 1*) - echo -e "$(tput setaf 7) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac + echo -e "${BOLD}${WHITE}Responses${OFF}" + code=200 + echo -e "${result_color_table[${code:0:1}]} 200;successful operation${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' + code=400 + echo -e "${result_color_table[${code:0:1}]} 400;Invalid username supplied${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' + code=404 + echo -e "${result_color_table[${code:0:1}]} 404;User not found${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' } ############################################################################## # @@ -2059,60 +1293,24 @@ print_getUserByName_help() { ############################################################################## print_loginUser_help() { echo "" - echo -e "$(tput bold)$(tput setaf 7)loginUser - Logs user into the system$(tput sgr0)" + echo -e "${BOLD}${WHITE}loginUser - Logs user into the system${OFF}" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo -e "" - echo -e "" | fold -sw 80 + echo -e "" | paste -sd' ' | fold -sw 80 echo -e "" - echo -e "$(tput bold)$(tput setaf 7)Parameters$(tput sgr0)" - echo -e " * $(tput setaf 2)username$(tput sgr0) $(tput setaf 4)[String]$(tput sgr0) $(tput setaf 1)(required)$(tput sgr0)$(tput sgr0) - The user name for login$(tput setaf 3) Specify as: username=value$(tput sgr0)" \ - | fold -sw 80 | sed '2,$s/^/ /' - echo -e " * $(tput setaf 2)password$(tput sgr0) $(tput setaf 4)[String]$(tput sgr0) $(tput setaf 1)(required)$(tput sgr0)$(tput sgr0) - The password for login in clear text$(tput setaf 3) Specify as: password=value$(tput sgr0)" \ - | fold -sw 80 | sed '2,$s/^/ /' + echo -e "${BOLD}${WHITE}Parameters${OFF}" + echo -e " * ${GREEN}username${OFF} ${BLUE}[String]${OFF} ${RED}(required)${OFF}${OFF} - The user name for login${YELLOW} Specify as: username=value${OFF}" \ + | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' + echo -e " * ${GREEN}password${OFF} ${BLUE}[String]${OFF} ${RED}(required)${OFF}${OFF} - The password for login in clear text${YELLOW} Specify as: password=value${OFF}" \ + | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo "" - echo -e "$(tput bold)$(tput setaf 7)Responses$(tput sgr0)" - case 200 in - 1*) - echo -e "$(tput setaf 7) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 200;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac - echo -e " $(tput bold)$(tput setaf 7)Response headers$(tput sgr0)" - echo -e " $(tput setaf 4)X-Rate-Limit$(tput sgr0) - calls per hour allowed by the user" | fold -sw 80 | sed '2,$s/^/ /' - echo -e " $(tput setaf 4)X-Expires-After$(tput sgr0) - date in UTC when toekn expires" | fold -sw 80 | sed '2,$s/^/ /' - case 400 in - 1*) - echo -e "$(tput setaf 7) 400;Invalid username/password supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 400;Invalid username/password supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 400;Invalid username/password supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 400;Invalid username/password supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 400;Invalid username/password supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 400;Invalid username/password supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac + echo -e "${BOLD}${WHITE}Responses${OFF}" + code=200 + echo -e "${result_color_table[${code:0:1}]} 200;successful operation${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' + echo -e " ${BOLD}${WHITE}Response headers${OFF}" + echo -e " ${BLUE}X-Rate-Limit${OFF} - calls per hour allowed by the user" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' + echo -e " ${BLUE}X-Expires-After${OFF} - date in UTC when toekn expires" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' + code=400 + echo -e "${result_color_table[${code:0:1}]} 400;Invalid username/password supplied${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' } ############################################################################## # @@ -2121,32 +1319,14 @@ print_loginUser_help() { ############################################################################## print_logoutUser_help() { echo "" - echo -e "$(tput bold)$(tput setaf 7)logoutUser - Logs out current logged in user session$(tput sgr0)" + echo -e "${BOLD}${WHITE}logoutUser - Logs out current logged in user session${OFF}" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo -e "" - echo -e "" | fold -sw 80 + echo -e "" | paste -sd' ' | fold -sw 80 echo -e "" echo "" - echo -e "$(tput bold)$(tput setaf 7)Responses$(tput sgr0)" - case 0 in - 1*) - echo -e "$(tput setaf 7) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 0;successful operation$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac + echo -e "${BOLD}${WHITE}Responses${OFF}" + code=0 + echo -e "${result_color_table[${code:0:1}]} 0;successful operation${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' } ############################################################################## # @@ -2155,56 +1335,20 @@ print_logoutUser_help() { ############################################################################## print_updateUser_help() { echo "" - echo -e "$(tput bold)$(tput setaf 7)updateUser - Updated user$(tput sgr0)" + echo -e "${BOLD}${WHITE}updateUser - Updated user${OFF}" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo -e "" - echo -e "This can only be done by the logged in user." | fold -sw 80 + echo -e "This can only be done by the logged in user." | paste -sd' ' | fold -sw 80 echo -e "" - echo -e "$(tput bold)$(tput setaf 7)Parameters$(tput sgr0)" - echo -e " * $(tput setaf 2)username$(tput sgr0) $(tput setaf 4)[String]$(tput sgr0) $(tput setaf 1)(required)$(tput sgr0)$(tput sgr0) - name that need to be deleted $(tput setaf 3)Specify as: username=value$(tput sgr0)" | fold -sw 80 | sed '2,$s/^/ /' - echo -e " * $(tput setaf 2)body$(tput sgr0) $(tput setaf 4)[]$(tput sgr0) $(tput setaf 1)(required)$(tput sgr0)$(tput sgr0) - Updated user object" | fold -sw 80 | sed '2,$s/^/ /' + echo -e "${BOLD}${WHITE}Parameters${OFF}" + echo -e " * ${GREEN}username${OFF} ${BLUE}[String]${OFF} ${RED}(required)${OFF}${OFF} - name that need to be deleted ${YELLOW}Specify as: username=value${OFF}" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' + echo -e " * ${GREEN}body${OFF} ${BLUE}[]${OFF} ${RED}(required)${OFF}${OFF} - Updated user object" | paste -sd' ' | fold -sw 80 | sed '2,$s/^/ /' echo -e "" echo "" - echo -e "$(tput bold)$(tput setaf 7)Responses$(tput sgr0)" - case 400 in - 1*) - echo -e "$(tput setaf 7) 400;Invalid user supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 400;Invalid user supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 400;Invalid user supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 400;Invalid user supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 400;Invalid user supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 400;Invalid user supplied$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac - case 404 in - 1*) - echo -e "$(tput setaf 7) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 2*) - echo -e "$(tput setaf 2) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 3*) - echo -e "$(tput setaf 3) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 4*) - echo -e "$(tput setaf 1) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - 5*) - echo -e "$(tput setaf 5) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - *) - echo -e "$(tput setaf 7) 404;User not found$(tput sgr0)" | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' - ;; - esac + echo -e "${BOLD}${WHITE}Responses${OFF}" + code=400 + echo -e "${result_color_table[${code:0:1}]} 400;Invalid user supplied${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' + code=404 + echo -e "${result_color_table[${code:0:1}]} 404;User not found${OFF}" | paste -sd' ' | column -t -s ';' | fold -sw 80 | sed '2,$s/^/ /' } @@ -2216,12 +1360,13 @@ print_updateUser_help() { call_fakeOuterBooleanSerialize() { local path_parameter_names=() local query_parameter_names=() + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/fake/outer/boolean" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/fake/outer/boolean" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/fake/outer/boolean" path_parameter_names query_parameter_names) local method="POST" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -2280,12 +1425,13 @@ call_fakeOuterBooleanSerialize() { call_fakeOuterCompositeSerialize() { local path_parameter_names=() local query_parameter_names=() + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/fake/outer/composite" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/fake/outer/composite" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/fake/outer/composite" path_parameter_names query_parameter_names) local method="POST" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -2344,12 +1490,13 @@ call_fakeOuterCompositeSerialize() { call_fakeOuterNumberSerialize() { local path_parameter_names=() local query_parameter_names=() + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/fake/outer/number" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/fake/outer/number" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/fake/outer/number" path_parameter_names query_parameter_names) local method="POST" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -2408,12 +1555,13 @@ call_fakeOuterNumberSerialize() { call_fakeOuterStringSerialize() { local path_parameter_names=() local query_parameter_names=() + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/fake/outer/string" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/fake/outer/string" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/fake/outer/string" path_parameter_names query_parameter_names) local method="POST" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -2472,12 +1620,13 @@ call_fakeOuterStringSerialize() { call_testClientModel() { local path_parameter_names=() local query_parameter_names=() + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/fake" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/fake" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/fake" path_parameter_names query_parameter_names) local method="PATCH" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -2502,7 +1651,7 @@ call_testClientModel() { if [[ -z $header_content_type && "$force" = false ]]; then : - echo "Error: Request's content-type not specified!!!" + echo "ERROR: Request's content-type not specified!!!" echo "This operation expects content-type in one of the following formats:" echo -e "\t- application/json" echo "" @@ -2544,13 +1693,14 @@ call_testClientModel() { ############################################################################## call_testEndpointParameters() { local path_parameter_names=() - local query_parameter_names=() + local query_parameter_names=( ) + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/fake" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/fake" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/fake" path_parameter_names query_parameter_names) local method="POST" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -2576,12 +1726,45 @@ call_testEndpointParameters() { call_testEnumParameters() { local path_parameter_names=() local query_parameter_names=(enum_query_string_array enum_query_string enum_query_integer) + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/fake" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/fake" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 + fi + local method="GET" + local headers_curl=$(header_arguments_to_curl) + if [[ -n $header_accept ]]; then + headers_curl="${headers_curl} -H 'Accept: ${header_accept}'" fi - local path=$(build_request_path "/v2/fake" path_parameter_names query_parameter_names) + local basic_auth_option="" + if [[ -n $basic_auth_credential ]]; then + basic_auth_option="-u ${basic_auth_credential}" + fi + if [[ "$print_curl" = true ]]; then + echo "curl ${basic_auth_option} ${curl_arguments} ${headers_curl} -X ${method} \"${host}${path}\"" + else + eval "curl ${basic_auth_option} ${curl_arguments} ${headers_curl} -X ${method} \"${host}${path}\"" + fi +} + +############################################################################## +# +# Call testJsonFormData operation +# +############################################################################## +call_testJsonFormData() { + local path_parameter_names=() + local query_parameter_names=() + local path + + path=$(build_request_path "/v2/fake/jsonFormData" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 + fi local method="GET" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -2607,12 +1790,13 @@ call_testEnumParameters() { call_testClassname() { local path_parameter_names=() local query_parameter_names=() + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/fake_classname_test" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/fake_classname_test" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/fake_classname_test" path_parameter_names query_parameter_names) local method="PATCH" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -2637,7 +1821,7 @@ call_testClassname() { if [[ -z $header_content_type && "$force" = false ]]; then : - echo "Error: Request's content-type not specified!!!" + echo "ERROR: Request's content-type not specified!!!" echo "This operation expects content-type in one of the following formats:" echo -e "\t- application/json" echo "" @@ -2679,13 +1863,14 @@ call_testClassname() { ############################################################################## call_addPet() { local path_parameter_names=() - local query_parameter_names=() + local query_parameter_names=( ) + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/pet" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/pet" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/pet" path_parameter_names query_parameter_names) local method="POST" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -2707,7 +1892,7 @@ call_addPet() { if [[ -z $header_content_type && "$force" = false ]]; then : - echo "Error: Request's content-type not specified!!!" + echo "ERROR: Request's content-type not specified!!!" echo "This operation expects content-type in one of the following formats:" echo -e "\t- application/json" echo -e "\t- application/xml" @@ -2750,13 +1935,14 @@ call_addPet() { ############################################################################## call_deletePet() { local path_parameter_names=(petId) - local query_parameter_names=() + local query_parameter_names=( ) + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/pet/{petId}" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/pet/{petId}" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/pet/{petId}" path_parameter_names query_parameter_names) local method="DELETE" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -2781,13 +1967,14 @@ call_deletePet() { ############################################################################## call_findPetsByStatus() { local path_parameter_names=() - local query_parameter_names=(status) + local query_parameter_names=(status ) + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/pet/findByStatus" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/pet/findByStatus" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/pet/findByStatus" path_parameter_names query_parameter_names) local method="GET" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -2812,13 +1999,14 @@ call_findPetsByStatus() { ############################################################################## call_findPetsByTags() { local path_parameter_names=() - local query_parameter_names=(tags) + local query_parameter_names=(tags ) + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/pet/findByTags" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/pet/findByTags" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/pet/findByTags" path_parameter_names query_parameter_names) local method="GET" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -2843,13 +2031,14 @@ call_findPetsByTags() { ############################################################################## call_getPetById() { local path_parameter_names=(petId) - local query_parameter_names=() + local query_parameter_names=( ) + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/pet/{petId}" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/pet/{petId}" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/pet/{petId}" path_parameter_names query_parameter_names) local method="GET" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -2874,13 +2063,14 @@ call_getPetById() { ############################################################################## call_updatePet() { local path_parameter_names=() - local query_parameter_names=() + local query_parameter_names=( ) + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/pet" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/pet" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/pet" path_parameter_names query_parameter_names) local method="PUT" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -2902,7 +2092,7 @@ call_updatePet() { if [[ -z $header_content_type && "$force" = false ]]; then : - echo "Error: Request's content-type not specified!!!" + echo "ERROR: Request's content-type not specified!!!" echo "This operation expects content-type in one of the following formats:" echo -e "\t- application/json" echo -e "\t- application/xml" @@ -2945,13 +2135,14 @@ call_updatePet() { ############################################################################## call_updatePetWithForm() { local path_parameter_names=(petId) - local query_parameter_names=() + local query_parameter_names=( ) + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/pet/{petId}" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/pet/{petId}" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/pet/{petId}" path_parameter_names query_parameter_names) local method="POST" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -2976,13 +2167,14 @@ call_updatePetWithForm() { ############################################################################## call_uploadFile() { local path_parameter_names=(petId) - local query_parameter_names=() + local query_parameter_names=( ) + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/pet/{petId}/uploadImage" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/pet/{petId}/uploadImage" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/pet/{petId}/uploadImage" path_parameter_names query_parameter_names) local method="POST" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -3008,12 +2200,13 @@ call_uploadFile() { call_deleteOrder() { local path_parameter_names=(order_id) local query_parameter_names=() + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/store/order/{order_id}" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/store/order/{order_id}" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/store/order/{order_id}" path_parameter_names query_parameter_names) local method="DELETE" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -3038,13 +2231,14 @@ call_deleteOrder() { ############################################################################## call_getInventory() { local path_parameter_names=() - local query_parameter_names=() + local query_parameter_names=( ) + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/store/inventory" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/store/inventory" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/store/inventory" path_parameter_names query_parameter_names) local method="GET" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -3070,12 +2264,13 @@ call_getInventory() { call_getOrderById() { local path_parameter_names=(order_id) local query_parameter_names=() + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/store/order/{order_id}" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/store/order/{order_id}" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/store/order/{order_id}" path_parameter_names query_parameter_names) local method="GET" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -3101,12 +2296,13 @@ call_getOrderById() { call_placeOrder() { local path_parameter_names=() local query_parameter_names=() + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/store/order" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/store/order" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/store/order" path_parameter_names query_parameter_names) local method="POST" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -3165,12 +2361,13 @@ call_placeOrder() { call_createUser() { local path_parameter_names=() local query_parameter_names=() + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/user" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/user" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/user" path_parameter_names query_parameter_names) local method="POST" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -3229,12 +2426,13 @@ call_createUser() { call_createUsersWithArrayInput() { local path_parameter_names=() local query_parameter_names=() + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/user/createWithArray" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/user/createWithArray" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/user/createWithArray" path_parameter_names query_parameter_names) local method="POST" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -3293,12 +2491,13 @@ call_createUsersWithArrayInput() { call_createUsersWithListInput() { local path_parameter_names=() local query_parameter_names=() + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/user/createWithList" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/user/createWithList" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/user/createWithList" path_parameter_names query_parameter_names) local method="POST" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -3357,12 +2556,13 @@ call_createUsersWithListInput() { call_deleteUser() { local path_parameter_names=(username) local query_parameter_names=() + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/user/{username}" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/user/{username}" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/user/{username}" path_parameter_names query_parameter_names) local method="DELETE" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -3388,12 +2588,13 @@ call_deleteUser() { call_getUserByName() { local path_parameter_names=(username) local query_parameter_names=() + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/user/{username}" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/user/{username}" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/user/{username}" path_parameter_names query_parameter_names) local method="GET" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -3419,12 +2620,13 @@ call_getUserByName() { call_loginUser() { local path_parameter_names=() local query_parameter_names=(username password) + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/user/login" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/user/login" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/user/login" path_parameter_names query_parameter_names) local method="GET" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -3450,12 +2652,13 @@ call_loginUser() { call_logoutUser() { local path_parameter_names=() local query_parameter_names=() + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/user/logout" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/user/logout" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/user/logout" path_parameter_names query_parameter_names) local method="GET" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -3481,12 +2684,13 @@ call_logoutUser() { call_updateUser() { local path_parameter_names=(username) local query_parameter_names=() + local path - if [[ $force = false ]]; then - validate_request_parameters "/v2/user/{username}" path_parameter_names query_parameter_names + path=$(build_request_path "/v2/user/{username}" path_parameter_names query_parameter_names) + if [ $? -ne 0 ]; then + ERROR_MSG=$path + exit 1 fi - - local path=$(build_request_path "/v2/user/{username}" path_parameter_names query_parameter_names) local method="PUT" local headers_curl=$(header_arguments_to_curl) if [[ -n $header_accept ]]; then @@ -3547,9 +2751,9 @@ call_updateUser() { # Check dependencies -type curl >/dev/null 2>&1 || { echo >&2 "Error: You do not have 'cURL' installed."; exit 1; } -type sed >/dev/null 2>&1 || { echo >&2 "Error: You do not have 'sed' installed."; exit 1; } -type column >/dev/null 2>&1 || { echo >&2 "Error: You do not have 'bsdmainutils' installed."; exit 1; } +type curl >/dev/null 2>&1 || { echo >&2 "ERROR: You do not have 'cURL' installed."; exit 1; } +type sed >/dev/null 2>&1 || { echo >&2 "ERROR: You do not have 'sed' installed."; exit 1; } +type column >/dev/null 2>&1 || { echo >&2 "ERROR: You do not have 'bsdmainutils' installed."; exit 1; } # # Process command line @@ -3622,6 +2826,18 @@ case $key in --dry-run) print_curl=true ;; + -nc|--no-colors) + RED="" + GREEN="" + YELLOW="" + BLUE="" + MAGENTA="" + CYAN="" + WHITE="" + BOLD="" + OFF="" + result_color_table=( "" "" "" "" "" "" "" ) + ;; fakeOuterBooleanSerialize) operation="fakeOuterBooleanSerialize" ;; @@ -3643,6 +2859,9 @@ case $key in testEnumParameters) operation="testEnumParameters" ;; + testJsonFormData) + operation="testJsonFormData" + ;; testClassname) operation="testClassname" ;; @@ -3722,7 +2941,7 @@ case $key in body_parameters[${body_key}]=${body_value} fi ;; - *:*) + +([^=]):*) # Parse header arguments and convert them into curl # only after the operation argument if [[ "$operation" ]]; then @@ -3775,15 +2994,13 @@ done # Check if user provided host name if [[ -z "$host" ]]; then - echo "Error: No hostname provided!!!" - echo "Check usage: '${script_name} --help'" + ERROR_MSG="ERROR: No hostname provided!!! Define env variable PETSTORE_HOST like 'export PETSTORE_HOST=...' or provide on command line option '--host ...'" exit 1 fi # Check if user specified operation ID if [[ -z "$operation" ]]; then - echo "Error: No operation specified!" - echo "Check available operations: '${script_name} --help'" + ERROR_MSG="ERROR: No operation specified!!!" exit 1 fi @@ -3811,6 +3028,9 @@ case $operation in testEnumParameters) call_testEnumParameters ;; + testJsonFormData) + call_testJsonFormData + ;; testClassname) call_testClassname ;; @@ -3875,8 +3095,6 @@ case $operation in call_updateUser ;; *) - echo "Error: Unknown operation: $operation" - echo "" - print_help + ERROR_MSG="ERROR: Unknown operation: $operation" exit 1 esac diff --git a/samples/client/petstore/bash/petstore-cli.bash-completion b/samples/client/petstore/bash/petstore-cli.bash-completion index 6202d109e40..09abb323307 100644 --- a/samples/client/petstore/bash/petstore-cli.bash-completion +++ b/samples/client/petstore/bash/petstore-cli.bash-completion @@ -75,6 +75,7 @@ _petstore-cli() operations["testClientModel"]=1 operations["testEndpointParameters"]=1 operations["testEnumParameters"]=1 + operations["testJsonFormData"]=1 operations["testClassname"]=1 operations["addPet"]=1 operations["deletePet"]=1 @@ -107,6 +108,7 @@ _petstore-cli() operation_parameters["testClientModel"]="" operation_parameters["testEndpointParameters"]="" operation_parameters["testEnumParameters"]="enum_query_string_array= enum_query_string= enum_query_integer= enum_header_string_array: enum_header_string: " + operation_parameters["testJsonFormData"]="" operation_parameters["testClassname"]="" operation_parameters["addPet"]="" operation_parameters["deletePet"]="petId= api_key: "