Skip to content

Commit

Permalink
Added option to mustache template that allows passing of non JSON req…
Browse files Browse the repository at this point in the history
…uest bodies
  • Loading branch information
mHejlesen committed Jan 18, 2024
1 parent d810d7c commit d77baef
Show file tree
Hide file tree
Showing 45 changed files with 153 additions and 125 deletions.
2 changes: 1 addition & 1 deletion docs/generators/fsharp-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|sourceFolder|source folder for generated code| |OpenAPI/src|
|sourceFolder|source folder for generated code| |OpenAPI\src|

## IMPORT MAPPING

Expand Down
2 changes: 1 addition & 1 deletion docs/generators/fsharp-giraffe-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|packageVersion|F# package version.| |1.0.0|
|returnICollection|Return ICollection<T> instead of the concrete type.| |false|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|sourceFolder|source folder for generated code| |OpenAPI/src|
|sourceFolder|source folder for generated code| |OpenAPI\src|
|useCollection|Deserialize array types to Collection<T> instead of List<T>.| |false|
|useDateTimeOffset|Use DateTimeOffset to model date-time properties| |false|
|useSwashbuckle|Uses the Swashbuckle.AspNetCore NuGet package for documentation.| |false|
Expand Down
2 changes: 1 addition & 1 deletion docs/generators/java-inflector.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|snapshotVersion|Uses a SNAPSHOT version.|<dl><dt>**true**</dt><dd>Use a SnapShot Version</dd><dt>**false**</dt><dd>Use a Release Version</dd></dl>|null|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|sourceFolder|source folder for generated code| |src/gen/java|
|sourceFolder|source folder for generated code| |src\gen\java|
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
Expand Down
2 changes: 1 addition & 1 deletion docs/generators/jaxrs-cxf-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|snapshotVersion|Uses a SNAPSHOT version.|<dl><dt>**true**</dt><dd>Use a SnapShot Version</dd><dt>**false**</dt><dd>Use a Release Version</dd></dl>|null|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|sourceFolder|source folder for generated code| |src/gen/java|
|sourceFolder|source folder for generated code| |src\gen\java|
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
|useAbstractionForFiles|Use alternative types instead of java.io.File to allow passing bytes without a file on disk.| |false|
|useBeanValidation|Use BeanValidation API annotations| |false|
Expand Down
4 changes: 2 additions & 2 deletions docs/generators/swift5.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|responseAs|Optionally use libraries to manage response. Currently PromiseKit, RxSwift, Result, Combine, AsyncAwait are available.| |null|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|swiftPackagePath|Set a custom source path instead of OpenAPIClient/Classes/OpenAPIs.| |null|
|swiftPackagePath|Set a custom source path instead of OpenAPIClient\Classes\OpenAPIs.| |null|
|swiftUseApiNamespace|Flag to make all the API classes inner-class of {{projectName}}API| |null|
|useBacktickEscapes|Escape reserved words using backticks (default: false)| |false|
|useClasses|Use final classes for models instead of structs (default: false)| |false|
|useCustomDateWithoutTime|Uses a custom type to decode and encode dates without time information to support OpenAPIs date format (default: false)| |false|
|useJsonEncodable|Make models conform to JSONEncodable protocol (default: true)| |true|
|useSPMFileStructure|Use SPM file structure and set the source path to Sources/{{projectName}} (default: false).| |null|
|useSPMFileStructure|Use SPM file structure and set the source path to Sources\{{projectName}} (default: false).| |null|
|validatable|Make validation rules and validator for model properies (default: true)| |true|

## IMPORT MAPPING
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ docs/Model/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md
docs/Model/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md
git_push.sh
phpunit.xml.dist
src/ApiException.php
src/Api/AuthApi.php
src/Api/BodyApi.php
src/Api/FormApi.php
src/Api/HeaderApi.php
src/Api/PathApi.php
src/Api/QueryApi.php
src/ApiException.php
src/Configuration.php
src/HeaderSelector.php
src/Model/Bird.php
Expand Down
4 changes: 2 additions & 2 deletions samples/client/echo_api/php-nextgen/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src/Api</directory>
<directory suffix=".php">./src/Model</directory>
<directory suffix=".php">./src\/Api</directory>
<directory suffix=".php">./src\/Model</directory>
</include>
</coverage>
<testsuites>
Expand Down
2 changes: 1 addition & 1 deletion samples/client/echo_api/r/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.travis.yml
DESCRIPTION
NAMESPACE
README.md
R/api_client.R
R/api_response.R
R/auth_api.R
Expand All @@ -24,7 +25,6 @@ R/string_enum_ref.R
R/tag.R
R/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.R
R/test_query_style_form_explode_true_array_string_query_object_parameter.R
README.md
docs/AuthApi.md
docs/Bird.md
docs/BodyApi.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.travis.yml
DESCRIPTION
NAMESPACE
README.md
R/allof_tag_api_response.R
R/animal.R
R/any_of_pig.R
Expand Down Expand Up @@ -38,7 +39,6 @@ R/user.R
R/user_api.R
R/whale.R
R/zebra.R
README.md
docs/AllofTagApiResponse.md
docs/Animal.md
docs/AnyOfPig.md
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/R-httr2/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.travis.yml
DESCRIPTION
NAMESPACE
README.md
R/allof_tag_api_response.R
R/animal.R
R/any_of_pig.R
Expand Down Expand Up @@ -37,7 +38,6 @@ R/user.R
R/user_api.R
R/whale.R
R/zebra.R
README.md
docs/AllofTagApiResponse.md
docs/Animal.md
docs/AnyOfPig.md
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/R/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.travis.yml
DESCRIPTION
NAMESPACE
README.md
R/allof_tag_api_response.R
R/animal.R
R/any_of_pig.R
Expand Down Expand Up @@ -37,7 +38,6 @@ R/user.R
R/user_api.R
R/whale.R
R/zebra.R
README.md
docs/AllofTagApiResponse.md
docs/Animal.md
docs/AnyOfPig.md
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ docs/Model/TestInlineFreeformAdditionalPropertiesRequest.md
docs/Model/User.md
git_push.sh
phpunit.xml.dist
src/ApiException.php
src/Api/AnotherFakeApi.php
src/Api/DefaultApi.php
src/Api/FakeApi.php
src/Api/FakeClassnameTags123Api.php
src/Api/PetApi.php
src/Api/StoreApi.php
src/Api/UserApi.php
src/ApiException.php
src/Configuration.php
src/HeaderSelector.php
src/Model/AdditionalPropertiesClass.php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src/Api</directory>
<directory suffix=".php">./src/Model</directory>
<directory suffix=".php">./src\/Api</directory>
<directory suffix=".php">./src\/Model</directory>
</include>
</coverage>
<testsuites>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ docs/Model/Tag.md
docs/Model/TestInlineFreeformAdditionalPropertiesRequest.md
docs/Model/User.md
git_push.sh
lib/ApiException.php
lib/Api/AnotherFakeApi.php
lib/Api/DefaultApi.php
lib/Api/FakeApi.php
lib/Api/FakeClassnameTags123Api.php
lib/Api/PetApi.php
lib/Api/StoreApi.php
lib/Api/UserApi.php
lib/ApiException.php
lib/Configuration.php
lib/HeaderSelector.php
lib/Model/AdditionalPropertiesClass.php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ docs/Model/Tag.md
docs/Model/TestInlineFreeformAdditionalPropertiesRequest.md
docs/Model/User.md
git_push.sh
lib/ApiException.php
lib/Api/AnotherFakeApi.php
lib/Api/DefaultApi.php
lib/Api/FakeApi.php
lib/Api/FakeClassnameTags123Api.php
lib/Api/PetApi.php
lib/Api/StoreApi.php
lib/Api/UserApi.php
lib/ApiException.php
lib/Configuration.php
lib/DebugPlugin.php
lib/HeaderSelector.php
Expand Down
4 changes: 2 additions & 2 deletions samples/schema/postman-collection/postman.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
],
"body": {
"mode": "raw",
"raw": "{\n \"firstName\" : \"Rebecca\"\n}",
"raw": "{\n \"firstName\" : \"Rebecca\"\n}",
"options": {
"raw": {
"language": "json"
Expand Down Expand Up @@ -223,7 +223,7 @@
],
"body": {
"mode": "raw",
"raw": "{\n \"id\" : 777,\n \"firstName\" : \"Alotta\",\n \"lastName\" : \"Rotta\",\n \"email\" : \"[email protected]\",\n \"dateOfBirth\" : \"1997-10-31\",\n \"emailVerified\" : true,\n \"createDate\" : \"2019-08-24\"\n}",
"raw": "{\n \"id\" : 777,\n \"firstName\" : \"Alotta\",\n \"lastName\" : \"Rotta\",\n \"email\" : \"[email protected]\",\n \"dateOfBirth\" : \"1997-10-31\",\n \"emailVerified\" : true,\n \"createDate\" : \"2019-08-24\"\n}",
"options": {
"raw": {
"language": "json"
Expand Down
Loading

0 comments on commit d77baef

Please sign in to comment.