mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-03-10 08:31:23 +00:00
[Bash] Allow non-JSON request body payloads (#17641)
* Added option to mustache template that allows passing of non JSON request bodies * Used linux terminal to run the generator scripts --------- Co-authored-by: mHejlesen <mads.hejlesen@secata.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user