Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bash] Allow non-JSON request body payloads #17641

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions modules/openapi-generator/src/main/resources/bash/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -330,20 +330,24 @@ header_arguments_to_curl() {
#
##############################################################################
body_parameters_to_json() {
local body_json="-d '{"
local count=0
for key in "${!body_parameters[@]}"; do
if [[ $((count++)) -gt 0 ]]; then
body_json+=", "
fi
body_json+="\"${key}\": ${body_parameters[${key}]}"
done
body_json+="}'"

if [[ "${#body_parameters[@]}" -eq 0 ]]; then
echo ""
if [[ $RAW_BODY == "1" ]]; then
echo "-d '${body_parameters["RAW_BODY"]}'"
else
echo "${body_json}"
local body_json="-d '{"
local count=0
for key in "${!body_parameters[@]}"; do
if [[ $((count++)) -gt 0 ]]; then
body_json+=", "
fi
body_json+="\"${key}\": ${body_parameters[${key}]}"
done
body_json+="}'"

if [[ "${#body_parameters[@]}" -eq 0 ]]; then
echo ""
else
echo "${body_json}"
fi
fi
}

Expand Down Expand Up @@ -1002,6 +1006,16 @@ case $key in
body_parameters[${body_key}]="\"${body_value}\""
fi
;;
--body=*)
# Parse value of body as argument and convert it into only
# the raw body content
if [[ "$operation" ]]; then
IFS='--body=' read -r body_value <<< "$key"
body_value=${body_value##--body=}
body_parameters["RAW_BODY"]="${body_value}"
RAW_BODY=1
fi
;;
*:=*)
# Parse body arguments and convert them into top level
# JSON properties passed in the body content without quotes
Expand Down
40 changes: 27 additions & 13 deletions samples/client/petstore/bash/petstore-cli
Original file line number Diff line number Diff line change
Expand Up @@ -492,20 +492,24 @@ header_arguments_to_curl() {
#
##############################################################################
body_parameters_to_json() {
local body_json="-d '{"
local count=0
for key in "${!body_parameters[@]}"; do
if [[ $((count++)) -gt 0 ]]; then
body_json+=", "
fi
body_json+="\"${key}\": ${body_parameters[${key}]}"
done
body_json+="}'"

if [[ "${#body_parameters[@]}" -eq 0 ]]; then
echo ""
if [[ $RAW_BODY == "1" ]]; then
echo "-d '${body_parameters["RAW_BODY"]}'"
else
echo "${body_json}"
local body_json="-d '{"
local count=0
for key in "${!body_parameters[@]}"; do
if [[ $((count++)) -gt 0 ]]; then
body_json+=", "
fi
body_json+="\"${key}\": ${body_parameters[${key}]}"
done
body_json+="}'"

if [[ "${#body_parameters[@]}" -eq 0 ]]; then
echo ""
else
echo "${body_json}"
fi
fi
}

Expand Down Expand Up @@ -3843,6 +3847,16 @@ case $key in
body_parameters[${body_key}]="\"${body_value}\""
fi
;;
--body=*)
# Parse value of body as argument and convert it into only
# the raw body content
if [[ "$operation" ]]; then
IFS='--body=' read -r body_value <<< "$key"
body_value=${body_value##--body=}
body_parameters["RAW_BODY"]="${body_value}"
RAW_BODY=1
fi
;;
*:=*)
# Parse body arguments and convert them into top level
# JSON properties passed in the body content without quotes
Expand Down
Loading