mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-25 14:57:09 +00:00
Compare commits
1 Commits
ue4-docker
...
python-nul
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26c0d991c0 |
@@ -2,11 +2,6 @@ kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
# test ue4 cpp client
|
||||
- name: cpp-ue4
|
||||
image: adamrehn/ue4-full:4.21.0
|
||||
commands:
|
||||
- (cd samples/client/petstore/cpp-ue4/ && ue4 build)
|
||||
# test aspnetcore 3.x
|
||||
- name: aspnetcore-test
|
||||
image: mcr.microsoft.com/dotnet/core/sdk:3.1
|
||||
|
||||
@@ -122,6 +122,7 @@ public class ApiClientTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("There is no more basic auth in petstore security definitions")
|
||||
@Test
|
||||
public void testSetUsernameAndPassword() {
|
||||
HttpBasicAuth auth = null;
|
||||
|
||||
@@ -122,6 +122,7 @@ public class ApiClientTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("There is no more basic auth in petstore security definitions")
|
||||
@Test
|
||||
public void testSetUsernameAndPassword() {
|
||||
HttpBasicAuth auth = null;
|
||||
|
||||
@@ -128,6 +128,7 @@ public class ApiClientTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("There is no more basic auth in petstore security definitions")
|
||||
@Test
|
||||
public void testSetUsernameAndPassword() {
|
||||
HttpBasicAuth auth = null;
|
||||
|
||||
@@ -745,11 +745,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
|
||||
- 2020-03-15 - [Load Testing Your API with Swagger/OpenAPI and k6](https://k6.io/blog/load-testing-your-api-with-swagger-openapi-and-k6)
|
||||
- 2020-04-13 - [俺的【OAS】との向き合い方 (爆速でOpenAPIと友達になろう)](https://tech-blog.optim.co.jp/entry/2020/04/13/100000) in [OPTim Blog](https://tech-blog.optim.co.jp/)
|
||||
- 2020-04-22 - [Introduction to OpenAPI Generator](https://nordicapis.com/introduction-to-openapi-generator/) by [Kristopher Sandoval](https://nordicapis.com/author/sandovaleffect/) in [Nordic APIs](https://nordicapis.com/)
|
||||
- 2020-04-27 - [How we use Open API v3 specification to auto-generate API documentation, code-snippets and clients](https://medium.com/pdf-generator-api/how-we-use-open-api-v3-specification-to-auto-generate-api-documentation-code-snippets-and-clients-d127a3cea784) by [Tanel Tähepõld](https://medium.com/@tanel.tahepold)
|
||||
- 2020-05-09 - [OpenAPIでお手軽にモックAPIサーバーを動かす](https://qiita.com/kasa_le/items/97ca6a8dd4605695c25c) by [Sachie Kamba](https://qiita.com/kasa_le)
|
||||
- 2020-05-18 - [Spring Boot REST with OpenAPI 3](https://dev.to/alfonzjanfrithz/spring-boot-rest-with-openapi-3-59jm) by [Alfonz Jan Frithz](https://dev.to/alfonzjanfrithz)
|
||||
- 2020-05-19 - [Dead Simple APIs with Open API](https://www.youtube.com/watch?v=sIaXmR6xRAw) by [Chris Tankersley](https://github.com/dragonmantank) at [Nexmo](https://developer.nexmo.com/)
|
||||
- 2020-05-22 - [TypeScript REST API Client](https://dev.to/unhurried/typescript-rest-api-client-4in3) by ["unhurried"](https://dev.to/unhurried)
|
||||
|
||||
## [6 - About Us](#table-of-contents)
|
||||
|
||||
@@ -779,7 +775,6 @@ Here is a list of template creators:
|
||||
* Bash: @bkryza
|
||||
* C: @PowerOfCreation @zhemant [:heart:](https://www.patreon.com/zhemant)
|
||||
* C++ REST: @Danielku15
|
||||
* C++ UE4: @Kahncode
|
||||
* C# (.NET 2.0): @who
|
||||
* C# (.NET Standard 1.3 ): @Gronsak
|
||||
* C# (.NET 4.5 refactored): @jimschubert [:heart:](https://www.patreon.com/jimschubert)
|
||||
@@ -823,7 +818,6 @@ Here is a list of template creators:
|
||||
* Perl: @wing328 [:heart:](https://www.patreon.com/wing328)
|
||||
* PHP (Guzzle): @baartosz
|
||||
* PowerShell: @beatcracker
|
||||
* PowerShell (refactored in 5.0.0): @wing328
|
||||
* Python-experimental: @spacether
|
||||
* R: @ramnov
|
||||
* Ruby (Faraday): @meganemura @dkliban
|
||||
@@ -963,7 +957,7 @@ If you want to join the committee, please kindly apply by sending an email to te
|
||||
| OCaml | @cgensoul (2019/08) |
|
||||
| Perl | @wing328 (2017/07) [:heart:](https://www.patreon.com/wing328) @yue9944882 (2019/06) |
|
||||
| PHP | @jebentier (2017/07), @dkarlovi (2017/07), @mandrean (2017/08), @jfastnacht (2017/09), @ackintosh (2017/09) [:heart:](https://www.patreon.com/ackintosh/overview), @ybelenko (2018/07), @renepardon (2018/12) |
|
||||
| PowerShell | @wing328 (2020/05) |
|
||||
| PowerShell | |
|
||||
| Python | @taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11) @tomplus (2018/10) @Jyhess (2019/01) @arun-nalla (2019/11) @spacether (2019/11) |
|
||||
| R | @Ramanth (2019/07) @saigiridhar21 (2019/07) |
|
||||
| Ruby | @cliffano (2017/07) @zlx (2017/09) @autopp (2019/02) |
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -t modules/openapi-generator/src/main/resources/cpp-ue4 -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cpp-ue4 -o samples/client/petstore/cpp-ue4"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/nodejs-express-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g nodejs-express-server -o samples/server/petstore/nodejs-express-server $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/nodejs-express-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g nodejs-express-server -o samples/server/petstore/nodejs-express-server -Dservice $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -28,7 +28,7 @@ fi
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
|
||||
args="generate -t modules/openapi-generator/src/main/resources/ocaml -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g ocaml -o samples/client/petstore/ocaml --additional-properties packageName=petstore_client $@"
|
||||
args="generate -t modules/openapi-generator/src/main/resources/ocaml -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g ocaml -o samples/client/petstore/ocaml --additional-properties packageName=petstore_client $@"
|
||||
|
||||
echo "java ${JAVA_OPTS} -jar ${executable} ${args}"
|
||||
java $JAVA_OPTS -jar $executable $args
|
||||
|
||||
@@ -26,7 +26,9 @@ then
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/3_0/composed-schemas.yaml -g typescript-axios -o samples/client/petstore/typescript-axios/builds/composed-schemas $@"
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DdebugOperations -DloggerPath=conf/log4j.properties"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
args="generate -t modules/openapi-generator/src/main/resources/ocaml -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g ocaml -o samples/openapi3/client/petstore/ocaml/ --additional-properties packageName=petstore_client $@"
|
||||
|
||||
echo "java ${JAVA_OPTS} -jar ${executable} ${args}"
|
||||
java $JAVA_OPTS -jar $executable $args
|
||||
@@ -37,8 +37,8 @@ ags="generate -t $resources -i $input -g $generator -o $out_folder $@"
|
||||
rm -rf $out_folder/.openapi*
|
||||
rm -rf $out_folder/openapi_server
|
||||
rm -rf $out_folder/tests*
|
||||
rm -f $out_folder/README.md
|
||||
rm -f $out_folder/requirements.txt
|
||||
rm -f $out_folder/test-requirements.txt
|
||||
rm $out_folder/README.md
|
||||
rm $out_folder/requirements.txt
|
||||
rm $out_folder/test-requirements.txt
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -6,5 +6,4 @@
|
||||
./bin/typescript-axios-petstore-with-complex-headers.sh
|
||||
./bin/typescript-axios-petstore-with-single-request-parameters.sh
|
||||
./bin/typescript-axios-petstore-interfaces.sh
|
||||
./bin/typescript-axios-petstore-composed-schemas.sh
|
||||
./bin/typescript-axios-petstore.sh
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g cpp-ue4 -o samples\client\petstore\cpp-ue4
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -1,24 +1,24 @@
|
||||
call .\bin\windows\java-petstore-feign-10x.bat
|
||||
call .\bin\windows\java-petstore-feign.bat
|
||||
call .\bin\windows\java-petstore-google-api-client.bat
|
||||
call .\bin\windows\java-petstore-jersey1.bat
|
||||
call .\bin\windows\java-petstore-jersey2-java6.bat
|
||||
call .\bin\windows\java-petstore-jersey2-java7.bat
|
||||
call .\bin\windows\java-petstore-jersey2-java8.bat
|
||||
call .\bin\windows\java-petstore-feign.bat
|
||||
call .\bin\windows\java-petstore-feign-10x.bat
|
||||
call .\bin\windows\java-petstore-native.bat
|
||||
call .\bin\windows\java-petstore-okhttp-gson-parcelable.bat
|
||||
call .\bin\windows\java-petstore-okhttp-gson.bat
|
||||
call .\bin\windows\java-petstore-rest-assured.bat
|
||||
call .\bin\windows\java-petstore-rest-assured-jackson.bat
|
||||
call .\bin\windows\java-petstore-resteasy.bat
|
||||
call .\bin\windows\java-petstore-resttemplate-withxml.bat
|
||||
call .\bin\windows\java-petstore-resttemplate.bat
|
||||
call .\bin\windows\java-petstore-okhttp-gson-parcelable.bat
|
||||
call .\bin\windows\java-petstore-retrofit.bat
|
||||
call .\bin\windows\java-petstore-retrofit2-play24.bat
|
||||
call .\bin\windows\java-petstore-retrofit2-play25.bat
|
||||
call .\bin\windows\java-petstore-retrofit2-play26.bat
|
||||
call .\bin\windows\java-petstore-retrofit2.bat
|
||||
call .\bin\windows\java-petstore-retrofit2rx.bat
|
||||
call .\bin\windows\java-petstore-retrofit2rx2.bat
|
||||
call .\bin\windows\java-petstore-vertx.bat
|
||||
call .\bin\windows\java8-petstore-jersey2.bat
|
||||
call .\bin\windows\java-petstore-retrofit2-play24.bat
|
||||
call .\bin\windows\java-petstore-retrofit2-play25.bat
|
||||
call .\bin\windows\java-petstore-retrofit2-play26.bat
|
||||
call .\bin\windows\java-petstore-jersey2-java6.bat
|
||||
call .\bin\windows\java-petstore-resttemplate.bat
|
||||
call .\bin\windows\java-petstore-resttemplate-withxml.bat
|
||||
call .\bin\windows\java-petstore-webclient.bat
|
||||
call .\bin\windows\java-petstore-resteasy.bat
|
||||
call .\bin\windows\java-petstore-google-api-client.bat
|
||||
call .\bin\windows\java-petstore-rest-assured.bat
|
||||
call .\bin\windows\java-petstore-rest-assured-jackson.bat
|
||||
call .\bin\windows\java-petstore-vertx.bat
|
||||
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate --artifact-id petstore-java-client-jersey1 -t modules\openapi-generator\src\main\resources\Java -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -o samples\client\petstore\java\jersey1 --additional-properties hideGenerationTimestamp=true --library=jersey1
|
||||
set ags=generate --artifact-id petstore-java-client-jersey1 -t modules\openapi-generator\src\main\resources\Java -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -o samples\client\petstore\java\jersey1 --additional-properties hideGenerationTimestamp=true --library=jersey1 --additional-properties useNullForUnknownEnumValue=true
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-jersey2-java7.json -o samples\client\petstore\java\jersey2-java7 --additional-properties hideGenerationTimestamp=true
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-jersey2-java8.json -o samples\client\petstore\java\jersey2-java8 --additional-properties hideGenerationTimestamp=true
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-jersey2-java7.json -o samples\client\petstore\java\jersey2 --additional-properties hideGenerationTimestamp=true
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -t modules\openapi-generator\src\main\resources\Java\libraries\rest-assured -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-rest-assured.json -o samples\client\petstore\java\rest-assured --additional-properties hideGenerationTimestamp=true --additional-properties useBeanValidation=true --additional-properties performBeanValidation=true --additional-properties booleanGetterPrefix=is
|
||||
set ags=generate -t modules\openapi-generator\src\main\resources\Java\libraries\rest-assured -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-rest-assured.json -o samples\client\petstore\java\rest-assured --additional-properties hideGenerationTimestamp=true,booleanGetterPrefix=is
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-webclient.json -o samples/client/petstore/java/webclient --additional-properties hideGenerationTimestamp=true
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\3_0\petstore.yaml -g ocaml -o samples\client\petstore\ocaml
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g ocaml -o samples\client\petstore\ocaml
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
@@ -6,5 +6,4 @@ call bin\windows\typescript-axios-petstore-with-complex-headers.bat
|
||||
call bin\windows\typescript-axios-petstore-with-single-request-parameters.bat
|
||||
call bin\windows\typescript-axios-petstore-with-npm-version.bat
|
||||
call bin\windows\typescript-axios-petstore-interfaces.bat
|
||||
call bin\windows\typescript-axios-petstore-composed-schemas.bat
|
||||
call bin\windows\typescript-axios-petstore-with-npm-version-and-separate-models-and-api.bat
|
||||
@@ -1,14 +0,0 @@
|
||||
@ECHO OFF
|
||||
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
|
||||
echo
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\3_0\composed-schemas.yaml -g typescript-axios -o samples\client\petstore\typescript-axios\builds\composed-schemas
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -15,7 +15,6 @@ The following generators are available:
|
||||
* [cpp-qt5-client](generators/cpp-qt5-client.md)
|
||||
* [cpp-restsdk](generators/cpp-restsdk.md)
|
||||
* [cpp-tizen](generators/cpp-tizen.md)
|
||||
* [cpp-ue4 (beta)](generators/cpp-ue4.md)
|
||||
* [csharp](generators/csharp.md)
|
||||
* [csharp-dotnet2 (deprecated)](generators/csharp-dotnet2.md)
|
||||
* [csharp-netcore](generators/csharp-netcore.md)
|
||||
@@ -104,6 +103,7 @@ The following generators are available:
|
||||
* [kotlin-spring](generators/kotlin-spring.md)
|
||||
* [kotlin-vertx (beta)](generators/kotlin-vertx.md)
|
||||
* [nodejs-express-server (beta)](generators/nodejs-express-server.md)
|
||||
* [nodejs-server-deprecated (deprecated)](generators/nodejs-server-deprecated.md)
|
||||
* [php-laravel](generators/php-laravel.md)
|
||||
* [php-lumen](generators/php-lumen.md)
|
||||
* [php-silex-deprecated (deprecated)](generators/php-silex-deprecated.md)
|
||||
|
||||
@@ -1,248 +0,0 @@
|
||||
---
|
||||
title: Config Options for cpp-ue4
|
||||
sidebar_label: cpp-ue4
|
||||
---
|
||||
|
||||
| Option | Description | Values | Default |
|
||||
| ------ | ----------- | ------ | ------- |
|
||||
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|
||||
|cppNamespace|C++ namespace (convention: name::space::for::api).| |OpenAPI|
|
||||
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|
||||
|legacyDiscriminatorBehavior|This flag is used by OpenAPITools codegen to influence the processing of the discriminator attribute in OpenAPI documents. This flag has no impact if the OAS document does not use the discriminator attribute. The default value of this flag is set in each language-specific code generator (e.g. Python, Java, go...)using the method toModelName. Note to developers supporting a language generator in OpenAPITools; to fully support the discriminator attribute as defined in the OAS specification 3.x, language generators should set this flag to true by default; however this requires updating the mustache templates to generate a language-specific discriminator lookup function that iterates over {{#mappedModels}} and does not iterate over {{children}}, {{#anyOf}}, or {{#oneOf}}.|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
|
||||
|optionalProjectFile|Generate Build.cs| |true|
|
||||
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
||||
|reservedWordPrefix|Prefix to prepend to reserved words in order to avoid conflicts| |r_|
|
||||
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|
||||
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||
|unrealModuleName|Name of the generated unreal module (optional)| |OpenAPI|
|
||||
|variableNameFirstCharacterUppercase|Make first character of variable name uppercase (eg. value -> Value)| |true|
|
||||
|
||||
## IMPORT MAPPING
|
||||
|
||||
| Type/Alias | Imports |
|
||||
| ---------- | ------- |
|
||||
|HttpFileInput|#include "OpenAPIHelpers.h"|
|
||||
|
||||
|
||||
## INSTANTIATION TYPES
|
||||
|
||||
| Type/Alias | Instantiated By |
|
||||
| ---------- | --------------- |
|
||||
|
||||
|
||||
## LANGUAGE PRIMITIVES
|
||||
|
||||
<ul class="column-ul">
|
||||
<li>FDateTime</li>
|
||||
<li>FGuid</li>
|
||||
<li>FString</li>
|
||||
<li>TArray</li>
|
||||
<li>TArray<uint8></li>
|
||||
<li>TMap</li>
|
||||
<li>TSharedPtr<FJsonObject></li>
|
||||
<li>bool</li>
|
||||
<li>double</li>
|
||||
<li>float</li>
|
||||
<li>int32</li>
|
||||
<li>int64</li>
|
||||
</ul>
|
||||
|
||||
## RESERVED WORDS
|
||||
|
||||
<ul class="column-ul">
|
||||
<li>alignas</li>
|
||||
<li>alignof</li>
|
||||
<li>and</li>
|
||||
<li>and_eq</li>
|
||||
<li>asm</li>
|
||||
<li>auto</li>
|
||||
<li>bitand</li>
|
||||
<li>bitor</li>
|
||||
<li>bool</li>
|
||||
<li>break</li>
|
||||
<li>case</li>
|
||||
<li>catch</li>
|
||||
<li>char</li>
|
||||
<li>char16_t</li>
|
||||
<li>char32_t</li>
|
||||
<li>class</li>
|
||||
<li>compl</li>
|
||||
<li>concept</li>
|
||||
<li>const</li>
|
||||
<li>const_cast</li>
|
||||
<li>constexpr</li>
|
||||
<li>continue</li>
|
||||
<li>decltype</li>
|
||||
<li>default</li>
|
||||
<li>delete</li>
|
||||
<li>do</li>
|
||||
<li>double</li>
|
||||
<li>dynamic_cast</li>
|
||||
<li>else</li>
|
||||
<li>enum</li>
|
||||
<li>explicit</li>
|
||||
<li>export</li>
|
||||
<li>extern</li>
|
||||
<li>false</li>
|
||||
<li>float</li>
|
||||
<li>for</li>
|
||||
<li>friend</li>
|
||||
<li>goto</li>
|
||||
<li>if</li>
|
||||
<li>inline</li>
|
||||
<li>int</li>
|
||||
<li>linux</li>
|
||||
<li>long</li>
|
||||
<li>mutable</li>
|
||||
<li>namespace</li>
|
||||
<li>new</li>
|
||||
<li>noexcept</li>
|
||||
<li>not</li>
|
||||
<li>not_eq</li>
|
||||
<li>nullptr</li>
|
||||
<li>operator</li>
|
||||
<li>or</li>
|
||||
<li>or_eq</li>
|
||||
<li>private</li>
|
||||
<li>protected</li>
|
||||
<li>public</li>
|
||||
<li>register</li>
|
||||
<li>reinterpret_cast</li>
|
||||
<li>requires</li>
|
||||
<li>return</li>
|
||||
<li>short</li>
|
||||
<li>signed</li>
|
||||
<li>sizeof</li>
|
||||
<li>static</li>
|
||||
<li>static_assert</li>
|
||||
<li>static_cast</li>
|
||||
<li>struct</li>
|
||||
<li>switch</li>
|
||||
<li>template</li>
|
||||
<li>this</li>
|
||||
<li>thread_local</li>
|
||||
<li>throw</li>
|
||||
<li>true</li>
|
||||
<li>try</li>
|
||||
<li>typedef</li>
|
||||
<li>typeid</li>
|
||||
<li>typename</li>
|
||||
<li>union</li>
|
||||
<li>unsigned</li>
|
||||
<li>using</li>
|
||||
<li>virtual</li>
|
||||
<li>void</li>
|
||||
<li>volatile</li>
|
||||
<li>wchar_t</li>
|
||||
<li>while</li>
|
||||
<li>xor</li>
|
||||
<li>xor_eq</li>
|
||||
</ul>
|
||||
|
||||
## FEATURE SET
|
||||
|
||||
|
||||
### Client Modification Feature
|
||||
| Name | Supported | Defined By |
|
||||
| ---- | --------- | ---------- |
|
||||
|BasePath|✗|ToolingExtension
|
||||
|Authorizations|✗|ToolingExtension
|
||||
|UserAgent|✗|ToolingExtension
|
||||
|
||||
### Data Type Feature
|
||||
| Name | Supported | Defined By |
|
||||
| ---- | --------- | ---------- |
|
||||
|Custom|✗|OAS2,OAS3
|
||||
|Int32|✓|OAS2,OAS3
|
||||
|Int64|✓|OAS2,OAS3
|
||||
|Float|✓|OAS2,OAS3
|
||||
|Double|✓|OAS2,OAS3
|
||||
|Decimal|✓|ToolingExtension
|
||||
|String|✓|OAS2,OAS3
|
||||
|Byte|✓|OAS2,OAS3
|
||||
|Binary|✓|OAS2,OAS3
|
||||
|Boolean|✓|OAS2,OAS3
|
||||
|Date|✓|OAS2,OAS3
|
||||
|DateTime|✓|OAS2,OAS3
|
||||
|Password|✓|OAS2,OAS3
|
||||
|File|✓|OAS2
|
||||
|Array|✓|OAS2,OAS3
|
||||
|Maps|✓|ToolingExtension
|
||||
|CollectionFormat|✓|OAS2
|
||||
|CollectionFormatMulti|✓|OAS2
|
||||
|Enum|✓|OAS2,OAS3
|
||||
|ArrayOfEnum|✓|ToolingExtension
|
||||
|ArrayOfModel|✓|ToolingExtension
|
||||
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
|
||||
|ArrayOfCollectionOfModel|✓|ToolingExtension
|
||||
|ArrayOfCollectionOfEnum|✓|ToolingExtension
|
||||
|MapOfEnum|✓|ToolingExtension
|
||||
|MapOfModel|✓|ToolingExtension
|
||||
|MapOfCollectionOfPrimitives|✓|ToolingExtension
|
||||
|MapOfCollectionOfModel|✓|ToolingExtension
|
||||
|MapOfCollectionOfEnum|✓|ToolingExtension
|
||||
|
||||
### Documentation Feature
|
||||
| Name | Supported | Defined By |
|
||||
| ---- | --------- | ---------- |
|
||||
|Readme|✗|ToolingExtension
|
||||
|Model|✓|ToolingExtension
|
||||
|Api|✓|ToolingExtension
|
||||
|
||||
### Global Feature
|
||||
| Name | Supported | Defined By |
|
||||
| ---- | --------- | ---------- |
|
||||
|Host|✓|OAS2,OAS3
|
||||
|BasePath|✓|OAS2,OAS3
|
||||
|Info|✓|OAS2,OAS3
|
||||
|Schemes|✗|OAS2,OAS3
|
||||
|PartialSchemes|✓|OAS2,OAS3
|
||||
|Consumes|✓|OAS2
|
||||
|Produces|✓|OAS2
|
||||
|ExternalDocumentation|✓|OAS2,OAS3
|
||||
|Examples|✓|OAS2,OAS3
|
||||
|XMLStructureDefinitions|✗|OAS2,OAS3
|
||||
|MultiServer|✗|OAS3
|
||||
|ParameterizedServer|✗|OAS3
|
||||
|ParameterStyling|✗|OAS3
|
||||
|Callbacks|✓|OAS3
|
||||
|LinkObjects|✗|OAS3
|
||||
|
||||
### Parameter Feature
|
||||
| Name | Supported | Defined By |
|
||||
| ---- | --------- | ---------- |
|
||||
|Path|✓|OAS2,OAS3
|
||||
|Query|✓|OAS2,OAS3
|
||||
|Header|✓|OAS2,OAS3
|
||||
|Body|✓|OAS2
|
||||
|FormUnencoded|✓|OAS2
|
||||
|FormMultipart|✓|OAS2
|
||||
|Cookie|✓|OAS3
|
||||
|
||||
### Schema Support Feature
|
||||
| Name | Supported | Defined By |
|
||||
| ---- | --------- | ---------- |
|
||||
|Simple|✓|OAS2,OAS3
|
||||
|Composite|✓|OAS2,OAS3
|
||||
|Polymorphism|✓|OAS2,OAS3
|
||||
|Union|✗|OAS3
|
||||
|
||||
### Security Feature
|
||||
| Name | Supported | Defined By |
|
||||
| ---- | --------- | ---------- |
|
||||
|BasicAuth|✓|OAS2,OAS3
|
||||
|ApiKey|✓|OAS2,OAS3
|
||||
|OpenIDConnect|✗|OAS3
|
||||
|BearerToken|✓|OAS3
|
||||
|OAuth2_Implicit|✓|OAS2,OAS3
|
||||
|OAuth2_Password|✓|OAS2,OAS3
|
||||
|OAuth2_ClientCredentials|✓|OAS2,OAS3
|
||||
|OAuth2_AuthorizationCode|✓|OAS2,OAS3
|
||||
|
||||
### Wire Format Feature
|
||||
| Name | Supported | Defined By |
|
||||
| ---- | --------- | ---------- |
|
||||
|JSON|✓|OAS2,OAS3
|
||||
|XML|✓|OAS2,OAS3
|
||||
|PROTOBUF|✗|ToolingExtension
|
||||
|Custom|✗|OAS2,OAS3
|
||||
@@ -30,7 +30,6 @@ import io.swagger.v3.oas.models.parameters.Parameter;
|
||||
import io.swagger.v3.oas.models.security.*;
|
||||
import io.swagger.v3.oas.models.tags.Tag;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.io.comparator.PathFileComparator;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.config.GlobalSettings;
|
||||
@@ -50,7 +49,6 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.*;
|
||||
@@ -59,7 +57,6 @@ import static org.openapitools.codegen.utils.OnceLogger.once;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
private static final String METADATA_DIR = ".openapi-generator";
|
||||
protected final Logger LOGGER = LoggerFactory.getLogger(DefaultGenerator.class);
|
||||
protected CodegenConfig config;
|
||||
protected ClientOptInput opts;
|
||||
@@ -863,7 +860,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
));
|
||||
}
|
||||
|
||||
String versionMetadata = config.outputFolder() + File.separator + METADATA_DIR + File.separator + "VERSION";
|
||||
String versionMetadata = config.outputFolder() + File.separator + ".openapi-generator" + File.separator + "VERSION";
|
||||
if (generateMetadata) {
|
||||
File versionMetadataFile = new File(versionMetadata);
|
||||
try {
|
||||
@@ -933,6 +930,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
bundle.put("hasOAuthMethods", true);
|
||||
bundle.put("oauthMethods", ProcessUtils.getOAuthMethods(authMethods));
|
||||
}
|
||||
|
||||
if (ProcessUtils.hasHttpBearerMethods(authMethods)) {
|
||||
bundle.put("hasHttpBearerMethods", true);
|
||||
}
|
||||
@@ -1059,38 +1057,6 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
sb.append(System.lineSeparator());
|
||||
|
||||
System.err.println(sb.toString());
|
||||
} else {
|
||||
if (generateMetadata) {
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
File outDir = new File(this.config.getOutputDir());
|
||||
|
||||
List<File> filesToSort = new ArrayList<>();
|
||||
|
||||
// Avoid side-effecting sort in this path when generateMetadata=true
|
||||
files.forEach(f -> {
|
||||
// We have seen NPE on CI for getPath() returning null, so guard against this (to be fixed in 5.0 template management refactor)
|
||||
//noinspection ConstantConditions
|
||||
if (f != null && f.getPath() != null) {
|
||||
filesToSort.add(f);
|
||||
}
|
||||
});
|
||||
|
||||
filesToSort.sort(PathFileComparator.PATH_COMPARATOR);
|
||||
filesToSort.forEach(f -> {
|
||||
String relativePath = outDir.toPath().relativize(f.toPath()).toString();
|
||||
if (!relativePath.equals(METADATA_DIR + File.separator + "VERSION")) {
|
||||
sb.append(relativePath).append(System.lineSeparator());
|
||||
}
|
||||
});
|
||||
|
||||
String targetFile = config.outputFolder() + File.separator + METADATA_DIR + File.separator + "FILES";
|
||||
File filesFile = writeToFile(targetFile, sb.toString().getBytes(StandardCharsets.UTF_8));
|
||||
files.add(filesFile);
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Failed to write FILES metadata to track generated files.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reset GlobalSettings, so that the running thread can be reused for another generator-run
|
||||
@@ -1479,6 +1445,8 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected File writeInputStreamToFile(String filename, InputStream in, String templateFile) throws IOException {
|
||||
if (in != null) {
|
||||
byte[] bytes = IOUtils.toByteArray(in);
|
||||
|
||||
@@ -164,7 +164,6 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
typeMapping.put("UUID", "string");
|
||||
typeMapping.put("URI", "string");
|
||||
typeMapping.put("Error", "Error");
|
||||
typeMapping.put("AnyType", "any");
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.ENUM_NAME_SUFFIX, CodegenConstants.ENUM_NAME_SUFFIX_DESC).defaultValue(this.enumSuffix));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ENUM_PROPERTY_NAMING, CodegenConstants.ENUM_PROPERTY_NAMING_DESC).defaultValue(this.enumPropertyNaming.name()));
|
||||
@@ -809,38 +808,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
|
||||
@Override
|
||||
public String toAnyOfName(List<String> names, ComposedSchema composedSchema) {
|
||||
List<String> types = getTypesFromSchemas(composedSchema.getAnyOf());
|
||||
|
||||
return String.join(" | ", types);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOneOfName(List<String> names, ComposedSchema composedSchema) {
|
||||
List<String> types = getTypesFromSchemas(composedSchema.getOneOf());
|
||||
|
||||
return String.join(" | ", types);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toAllOfName(List<String> names, ComposedSchema composedSchema) {
|
||||
List<String> types = getTypesFromSchemas(composedSchema.getAllOf());
|
||||
|
||||
return String.join(" & ", types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the list of type names from a list of schemas.
|
||||
* Excludes `AnyType` if there are other valid types extracted.
|
||||
*
|
||||
* @param schemas list of schemas
|
||||
* @return list of types
|
||||
*/
|
||||
protected List<String> getTypesFromSchemas(List<Schema> schemas) {
|
||||
List<Schema> filteredSchemas = schemas.size() > 1
|
||||
? schemas.stream().filter(schema -> super.getSchemaType(schema) != "AnyType").collect(Collectors.toList())
|
||||
: schemas;
|
||||
|
||||
return filteredSchemas.stream().map(schema -> {
|
||||
List<String> types = composedSchema.getAnyOf().stream().map(schema -> {
|
||||
String schemaType = getSchemaType(schema);
|
||||
if (ModelUtils.isArraySchema(schema)) {
|
||||
ArraySchema ap = (ArraySchema) schema;
|
||||
@@ -849,5 +817,34 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
}
|
||||
return schemaType;
|
||||
}).distinct().collect(Collectors.toList());
|
||||
return String.join(" | ", types);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOneOfName(List<String> names, ComposedSchema composedSchema) {
|
||||
List<String> types = composedSchema.getOneOf().stream().map(schema -> {
|
||||
String schemaType = getSchemaType(schema);
|
||||
if (ModelUtils.isArraySchema(schema)) {
|
||||
ArraySchema ap = (ArraySchema) schema;
|
||||
Schema inner = ap.getItems();
|
||||
schemaType = schemaType + "<" + getSchemaType(inner) + ">";
|
||||
}
|
||||
return schemaType;
|
||||
}).distinct().collect(Collectors.toList());
|
||||
return String.join(" | ", types);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toAllOfName(List<String> names, ComposedSchema composedSchema) {
|
||||
List<String> types = composedSchema.getAllOf().stream().map(schema -> {
|
||||
String schemaType = getSchemaType(schema);
|
||||
if (ModelUtils.isArraySchema(schema)) {
|
||||
ArraySchema ap = (ArraySchema) schema;
|
||||
Schema inner = ap.getItems();
|
||||
schemaType = schemaType + "<" + getSchemaType(inner) + ">";
|
||||
}
|
||||
return schemaType;
|
||||
}).distinct().collect(Collectors.toList());
|
||||
return String.join(" & ", types);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,544 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.meta.GeneratorMetadata;
|
||||
import org.openapitools.codegen.meta.Stability;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class CppUE4ClientCodegen extends AbstractCppCodegen {
|
||||
public static final String CPP_NAMESPACE = "cppNamespace";
|
||||
public static final String CPP_NAMESPACE_DESC = "C++ namespace (convention: name::space::for::api).";
|
||||
public static final String UNREAL_MODULE_NAME = "unrealModuleName";
|
||||
public static final String UNREAL_MODULE_NAME_DESC = "Name of the generated unreal module (optional)";
|
||||
public static final String OPTIONAL_PROJECT_FILE_DESC = "Generate Build.cs";
|
||||
|
||||
protected String unrealModuleName = "OpenAPI";
|
||||
// Will be treated as pointer
|
||||
protected Set<String> pointerClasses = new HashSet<String>();
|
||||
// source folder where to write the files
|
||||
protected String privateFolder = "Private";
|
||||
protected String publicFolder = "Public";
|
||||
protected String apiVersion = "1.0.0";
|
||||
protected Map<String, String> namespaces = new HashMap<String, String>();
|
||||
// Will be included using the <> syntax, not used in Unreal's coding convention
|
||||
protected Set<String> systemIncludes = new HashSet<String>();
|
||||
protected String cppNamespace = unrealModuleName;
|
||||
protected boolean optionalProjectFileFlag = true;
|
||||
|
||||
public CppUE4ClientCodegen() {
|
||||
super();
|
||||
|
||||
generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata)
|
||||
.stability(Stability.BETA)
|
||||
.build();
|
||||
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/cpp-ue4";
|
||||
|
||||
// set modelNamePrefix as default for cpp-ue4
|
||||
if ("".equals(modelNamePrefix)) {
|
||||
modelNamePrefix = unrealModuleName;
|
||||
}
|
||||
|
||||
/*
|
||||
* Models. You can write model files using the modelTemplateFiles map.
|
||||
* if you want to create one template for file, you can do so here.
|
||||
* for multiple files for model, just put another entry in the `modelTemplateFiles` with
|
||||
* a different extension
|
||||
*/
|
||||
modelTemplateFiles.put(
|
||||
"model-header.mustache",
|
||||
".h");
|
||||
|
||||
modelTemplateFiles.put(
|
||||
"model-source.mustache",
|
||||
".cpp");
|
||||
|
||||
/*
|
||||
* Api classes. You can write classes for each Api file with the apiTemplateFiles map.
|
||||
* as with models, add multiple entries with different extensions for multiple files per
|
||||
* class
|
||||
*/
|
||||
apiTemplateFiles.put(
|
||||
"api-header.mustache", // the template to use
|
||||
".h"); // the extension for each file to write
|
||||
|
||||
apiTemplateFiles.put(
|
||||
"api-source.mustache", // the template to use
|
||||
".cpp"); // the extension for each file to write
|
||||
|
||||
apiTemplateFiles.put(
|
||||
"api-operations-header.mustache", // the template to use
|
||||
".h"); // the extension for each file to write
|
||||
|
||||
apiTemplateFiles.put(
|
||||
"api-operations-source.mustache", // the template to use
|
||||
".cpp"); // the extension for each file to write
|
||||
|
||||
/*
|
||||
* Template Location. This is the location which templates will be read from. The generator
|
||||
* will use the resource stream to attempt to read the templates.
|
||||
*/
|
||||
embeddedTemplateDir = templateDir = "cpp-ue4";
|
||||
|
||||
// CLI options
|
||||
addOption(CPP_NAMESPACE, CPP_NAMESPACE_DESC, this.cppNamespace);
|
||||
addOption(UNREAL_MODULE_NAME, UNREAL_MODULE_NAME_DESC, this.unrealModuleName);
|
||||
addSwitch(CodegenConstants.OPTIONAL_PROJECT_FILE, OPTIONAL_PROJECT_FILE_DESC, this.optionalProjectFileFlag);
|
||||
|
||||
/*
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
* are available in models, apis, and supporting files
|
||||
*/
|
||||
additionalProperties.put("apiVersion", apiVersion);
|
||||
additionalProperties().put("modelNamePrefix", modelNamePrefix);
|
||||
additionalProperties().put("modelPackage", modelPackage);
|
||||
additionalProperties().put("apiPackage", apiPackage);
|
||||
additionalProperties().put("dllapi", unrealModuleName.toUpperCase(Locale.ROOT) + "_API");
|
||||
additionalProperties().put("unrealModuleName", unrealModuleName);
|
||||
|
||||
// Write defaults namespace in properties so that it can be accessible in templates.
|
||||
// At this point command line has not been parsed so if value is given
|
||||
// in command line it will superseed this content
|
||||
additionalProperties.put("cppNamespace", cppNamespace);
|
||||
additionalProperties.put("unrealModuleName", unrealModuleName);
|
||||
|
||||
/*
|
||||
* Language Specific Primitives. These types will not trigger imports by
|
||||
* the client generator
|
||||
*/
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"bool",
|
||||
"int32",
|
||||
"int64",
|
||||
"float",
|
||||
"double",
|
||||
"FString",
|
||||
"FDateTime",
|
||||
"FGuid",
|
||||
"TArray",
|
||||
"TArray<uint8>", // For byte arrays
|
||||
"TMap",
|
||||
"TSharedPtr<FJsonObject>")
|
||||
);
|
||||
|
||||
supportingFiles.add(new SupportingFile("model-base-header.mustache", publicFolder, modelNamePrefix + "BaseModel.h"));
|
||||
supportingFiles.add(new SupportingFile("model-base-source.mustache", privateFolder, modelNamePrefix + "BaseModel.cpp"));
|
||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", publicFolder, modelNamePrefix + "Helpers.h"));
|
||||
supportingFiles.add(new SupportingFile("helpers-source.mustache", privateFolder, modelNamePrefix + "Helpers.cpp"));
|
||||
if (optionalProjectFileFlag) {
|
||||
supportingFiles.add(new SupportingFile("Build.cs.mustache", unrealModuleName + ".Build.cs"));
|
||||
supportingFiles.add(new SupportingFile("module-header.mustache", privateFolder, unrealModuleName + "Module.h"));
|
||||
supportingFiles.add(new SupportingFile("module-source.mustache", privateFolder, unrealModuleName + "Module.cpp"));
|
||||
}
|
||||
|
||||
super.typeMapping = new HashMap<String, String>();
|
||||
|
||||
// Maps C++ types during call to getSchemaType, see DefaultCodegen.getSchemaType and not the types/formats
|
||||
// defined in openapi specification "array" is also used explicitly in the generator for containers
|
||||
typeMapping.clear();
|
||||
typeMapping.put("integer", "int32");
|
||||
typeMapping.put("long", "int64");
|
||||
typeMapping.put("float", "float");
|
||||
typeMapping.put("number", "double");
|
||||
typeMapping.put("double", "double");
|
||||
typeMapping.put("string", "FString");
|
||||
typeMapping.put("byte", "uint8");
|
||||
typeMapping.put("binary", "TArray<uint8>");
|
||||
typeMapping.put("ByteArray", "TArray<uint8>");
|
||||
typeMapping.put("password", "FString");
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("date", "FDateTime");
|
||||
typeMapping.put("Date", "FDateTime");
|
||||
typeMapping.put("date-time", "FDateTime");
|
||||
typeMapping.put("DateTime", "FDateTime");
|
||||
typeMapping.put("array", "TArray");
|
||||
typeMapping.put("list", "TArray");
|
||||
typeMapping.put("map", "TMap");
|
||||
typeMapping.put("object", "TSharedPtr<FJsonObject>");
|
||||
typeMapping.put("Object", "TSharedPtr<FJsonObject>");
|
||||
typeMapping.put("file", "HttpFileInput");
|
||||
typeMapping.put("UUID", "FGuid");
|
||||
|
||||
importMapping = new HashMap<String, String>();
|
||||
importMapping.put("HttpFileInput", "#include \"" + modelNamePrefix + "Helpers.h\"");
|
||||
|
||||
namespaces = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey("cppNamespace")) {
|
||||
cppNamespace = (String) additionalProperties.get("cppNamespace");
|
||||
}
|
||||
|
||||
additionalProperties.put("cppNamespaceDeclarations", cppNamespace.split("\\::"));
|
||||
|
||||
boolean updateSupportingFiles = false;
|
||||
if (additionalProperties.containsKey("unrealModuleName")) {
|
||||
unrealModuleName = (String) additionalProperties.get("unrealModuleName");
|
||||
additionalProperties().put("dllapi", unrealModuleName.toUpperCase(Locale.ROOT) + "_API");
|
||||
modelNamePrefix = unrealModuleName;
|
||||
updateSupportingFiles = true;
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("modelNamePrefix")) {
|
||||
modelNamePrefix = (String) additionalProperties.get("modelNamePrefix");
|
||||
updateSupportingFiles = true;
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.OPTIONAL_PROJECT_FILE)) {
|
||||
setOptionalProjectFileFlag(convertPropertyToBooleanAndWriteBack(CodegenConstants.OPTIONAL_PROJECT_FILE));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.OPTIONAL_PROJECT_FILE, optionalProjectFileFlag);
|
||||
}
|
||||
|
||||
if (updateSupportingFiles) {
|
||||
supportingFiles.clear();
|
||||
|
||||
supportingFiles.add(new SupportingFile("model-base-header.mustache", publicFolder, modelNamePrefix + "BaseModel.h"));
|
||||
supportingFiles.add(new SupportingFile("model-base-source.mustache", privateFolder, modelNamePrefix + "BaseModel.cpp"));
|
||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", publicFolder, modelNamePrefix + "Helpers.h"));
|
||||
supportingFiles.add(new SupportingFile("helpers-source.mustache", privateFolder, modelNamePrefix + "Helpers.cpp"));
|
||||
if (optionalProjectFileFlag) {
|
||||
supportingFiles.add(new SupportingFile("Build.cs.mustache", unrealModuleName + ".Build.cs"));
|
||||
supportingFiles.add(new SupportingFile("module-header.mustache", privateFolder, unrealModuleName + "Module.h"));
|
||||
supportingFiles.add(new SupportingFile("module-source.mustache", privateFolder, unrealModuleName + "Module.cpp"));
|
||||
}
|
||||
|
||||
importMapping.put("HttpFileInput", "#include \"" + modelNamePrefix + "Helpers.h\"");
|
||||
}
|
||||
}
|
||||
|
||||
public void setOptionalProjectFileFlag(boolean flag) {
|
||||
this.optionalProjectFileFlag = flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the type of generator.
|
||||
*
|
||||
* @return the CodegenType for this generator
|
||||
* @see org.openapitools.codegen.CodegenType
|
||||
*/
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a friendly name for the generator. This will be used by the generator
|
||||
* to select the library with the -l flag.
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "cpp-ue4";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns human-friendly help for the generator. Provide the consumer with help
|
||||
* tips, parameters here
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Unreal Engine 4 C++ Module (beta).";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
if (namespaces.containsKey(name)) {
|
||||
return "using " + namespaces.get(name) + ";";
|
||||
} else if (systemIncludes.contains(name)) {
|
||||
return "#include <" + name + ">";
|
||||
}
|
||||
|
||||
String folder = modelPackage().replace("::", File.separator);
|
||||
if (!folder.isEmpty())
|
||||
folder += File.separator;
|
||||
|
||||
return "#include \"" + folder + name + ".h\"";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needToImport(String type) {
|
||||
boolean shouldImport = super.needToImport(type);
|
||||
if (shouldImport)
|
||||
return !languageSpecificPrimitives.contains(type);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
|
||||
* those terms here. This logic is only called if a variable matches the reserved words
|
||||
*
|
||||
* @return the escaped term
|
||||
*/
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
if (this.reservedWordsMappings().containsKey(name)) {
|
||||
return this.reservedWordsMappings().get(name);
|
||||
}
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write model files. You can use the modelPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + modelPackage().replace("::", File.separator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write api files. You can use the apiPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + apiPackage().replace("::", File.separator);
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public String modelFilename(String templateName, String tag) {
|
||||
String suffix = modelTemplateFiles().get(templateName);
|
||||
String folder = privateFolder;
|
||||
if (suffix == ".h") {
|
||||
folder = publicFolder;
|
||||
}
|
||||
|
||||
return modelFileFolder() + File.separator + folder + File.separator + toModelFilename(tag) + suffix;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
name = sanitizeName(name);
|
||||
return modelNamePrefix + camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
String suffix = apiTemplateFiles().get(templateName);
|
||||
String folder = privateFolder;
|
||||
if (".h".equals(suffix)) {
|
||||
folder = publicFolder;
|
||||
}
|
||||
|
||||
if (templateName.startsWith("api-operations")) {
|
||||
return apiFileFolder() + File.separator + folder + File.separator + toApiFilename(tag) + "Operations" + suffix;
|
||||
} else {
|
||||
return apiFileFolder() + File.separator + folder + File.separator + toApiFilename(tag) + suffix;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
name = sanitizeName(name);
|
||||
return modelNamePrefix + camelize(name) + "Api";
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - type declaration. This is a String which is used by the templates to instantiate your
|
||||
* types. There is typically special handling for different property types
|
||||
*
|
||||
* @return a string value used as the `dataType` field for model templates, `returnType` for api templates
|
||||
*/
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
String openAPIType = getSchemaType(p);
|
||||
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
String inner = getSchemaType(ap.getItems());
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType(ModelUtils.getAdditionalProperties(p));
|
||||
return getSchemaType(p) + "<FString, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
|
||||
if (pointerClasses.contains(openAPIType)) {
|
||||
return openAPIType + "*";
|
||||
} else if (languageSpecificPrimitives.contains(openAPIType)) {
|
||||
return toModelName(openAPIType);
|
||||
} else {
|
||||
return openAPIType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "TEXT(\"" + p.getDefault().toString() + "\")";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "false";
|
||||
}
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
return "FDateTime(0)";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
return "FDateTime(0)";
|
||||
} else if (ModelUtils.isDoubleSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "0.0";
|
||||
}
|
||||
} else if (ModelUtils.isFloatSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "0.0f";
|
||||
}
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "0";
|
||||
}
|
||||
} else if (ModelUtils.isLongSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - OpenAPI type conversion. This is used to map OpenAPI types in a `Property` into
|
||||
* either language specific types via `typeMapping` or into complex models if there is not a mapping.
|
||||
*
|
||||
* @return a string value of the type or complex model for this property
|
||||
* @see io.swagger.v3.oas.models.media.Schema
|
||||
*/
|
||||
@Override
|
||||
public String getSchemaType(Schema p) {
|
||||
String openAPIType = super.getSchemaType(p);
|
||||
String type = null;
|
||||
if (typeMapping.containsKey(openAPIType)) {
|
||||
type = typeMapping.get(openAPIType);
|
||||
if (languageSpecificPrimitives.contains(type)) {
|
||||
return toModelName(type);
|
||||
}
|
||||
if (pointerClasses.contains(type)) {
|
||||
return type;
|
||||
}
|
||||
} else {
|
||||
type = openAPIType;
|
||||
}
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String type) {
|
||||
if (typeMapping.keySet().contains(type) ||
|
||||
typeMapping.values().contains(type) ||
|
||||
importMapping.values().contains(type) ||
|
||||
defaultIncludes.contains(type) ||
|
||||
languageSpecificPrimitives.contains(type)) {
|
||||
return type;
|
||||
} else {
|
||||
return modelNamePrefix + camelize(sanitizeName(type), false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
//Unreal variable names are CamelCase
|
||||
return camelize(name, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumVarName(String name, String datatype) {
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String type) {
|
||||
return modelNamePrefix + camelize(type, false) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove " to avoid code injection
|
||||
return input.replace("\"", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||
}
|
||||
|
||||
public String toBooleanGetter(String name) {
|
||||
return "Is" + getterAndSetterCapitalize(name);
|
||||
}
|
||||
|
||||
public String toGetter(String name) {
|
||||
return "Get" + getterAndSetterCapitalize(name);
|
||||
}
|
||||
|
||||
public String toSetter(String name) {
|
||||
return "Set" + getterAndSetterCapitalize(name);
|
||||
}
|
||||
}
|
||||
@@ -380,9 +380,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
} else if (JERSEY2.equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
|
||||
supportingFiles.add(new SupportingFile("ApiResponse.mustache", invokerFolder, "ApiResponse.java"));
|
||||
if (ProcessUtils.hasHttpSignatureMethods(openAPI)) {
|
||||
supportingFiles.add(new SupportingFile("auth/HttpSignatureAuth.mustache", authFolder, "HttpSignatureAuth.java"));
|
||||
}
|
||||
supportingFiles.add(new SupportingFile("auth/HttpSignatureAuth.mustache", authFolder, "HttpSignatureAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("AbstractOpenApiSchema.mustache", (sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar), "AbstractOpenApiSchema.java"));
|
||||
forceSerializationLibrary(SERIALIZATION_LIBRARY_JACKSON);
|
||||
} else if (NATIVE.equals(getLibrary())) {
|
||||
|
||||
@@ -0,0 +1,479 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.PathItem;
|
||||
import io.swagger.v3.oas.models.PathItem.HttpMethod;
|
||||
import io.swagger.v3.oas.models.Paths;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.config.GlobalSettings;
|
||||
import org.openapitools.codegen.meta.GeneratorMetadata;
|
||||
import org.openapitools.codegen.meta.Stability;
|
||||
import org.openapitools.codegen.meta.features.*;
|
||||
import org.openapitools.codegen.utils.URLPathUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
|
||||
public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NodeJSServerCodegen.class);
|
||||
protected String implFolder = "service";
|
||||
public static final String GOOGLE_CLOUD_FUNCTIONS = "googleCloudFunctions";
|
||||
public static final String EXPORTED_NAME = "exportedName";
|
||||
public static final String SERVER_PORT = "serverPort";
|
||||
|
||||
protected String apiVersion = "1.0.0";
|
||||
protected String projectName = "openapi-server";
|
||||
protected String defaultServerPort = "8080";
|
||||
|
||||
protected boolean googleCloudFunctions;
|
||||
protected String exportedName;
|
||||
|
||||
public NodeJSServerCodegen() {
|
||||
super();
|
||||
|
||||
modifyFeatureSet(features -> features
|
||||
.includeDocumentationFeatures(DocumentationFeature.Readme)
|
||||
.wireFormatFeatures(EnumSet.of(WireFormatFeature.JSON))
|
||||
.securityFeatures(EnumSet.noneOf(SecurityFeature.class))
|
||||
.excludeGlobalFeatures(
|
||||
GlobalFeature.XMLStructureDefinitions,
|
||||
GlobalFeature.Callbacks,
|
||||
GlobalFeature.LinkObjects,
|
||||
GlobalFeature.ParameterStyling
|
||||
)
|
||||
.excludeSchemaSupportFeatures(
|
||||
SchemaSupportFeature.Polymorphism
|
||||
)
|
||||
.excludeParameterFeatures(
|
||||
ParameterFeature.Cookie
|
||||
)
|
||||
);
|
||||
|
||||
// mark the generator as deprecated in the documentation
|
||||
generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata)
|
||||
.stability(Stability.DEPRECATED)
|
||||
.build();
|
||||
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/nodejs";
|
||||
|
||||
/*
|
||||
* Models. You can write model files using the modelTemplateFiles map.
|
||||
* if you want to create one template for file, you can do so here.
|
||||
* for multiple files for model, just put another entry in the `modelTemplateFiles` with
|
||||
* a different extension
|
||||
*/
|
||||
modelTemplateFiles.clear();
|
||||
|
||||
/*
|
||||
* Api classes. You can write classes for each Api file with the apiTemplateFiles map.
|
||||
* as with models, add multiple entries with different extensions for multiple files per
|
||||
* class
|
||||
*/
|
||||
apiTemplateFiles.put(
|
||||
"controller.mustache", // the template to use
|
||||
".js"); // the extension for each file to write
|
||||
|
||||
/*
|
||||
* Template Location. This is the location which templates will be read from. The generator
|
||||
* will use the resource stream to attempt to read the templates.
|
||||
*/
|
||||
embeddedTemplateDir = templateDir = "nodejs";
|
||||
|
||||
/*
|
||||
* Reserved words. Override this with reserved words specific to your language
|
||||
*/
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"break", "case", "class", "catch", "const", "continue", "debugger",
|
||||
"default", "delete", "do", "else", "enum", "export", "extends", "finally",
|
||||
"for", "function", "if", "import", "in", "instanceof", "let", "new",
|
||||
"return", "super", "switch", "this", "throw", "try", "typeof", "var",
|
||||
"void", "while", "with", "yield")
|
||||
);
|
||||
|
||||
/*
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
* are available in models, apis, and supporting files
|
||||
*/
|
||||
additionalProperties.put("apiVersion", apiVersion);
|
||||
additionalProperties.put("implFolder", implFolder);
|
||||
|
||||
supportingFiles.add(new SupportingFile("writer.mustache", ("utils").replace(".", File.separator), "writer.js"));
|
||||
|
||||
cliOptions.add(CliOption.newBoolean(GOOGLE_CLOUD_FUNCTIONS,
|
||||
"When specified, it will generate the code which runs within Google Cloud Functions "
|
||||
+ "instead of standalone Node.JS server. See "
|
||||
+ "https://cloud.google.com/functions/docs/quickstart for the details of how to "
|
||||
+ "deploy the generated code."));
|
||||
cliOptions.add(new CliOption(EXPORTED_NAME,
|
||||
"When the generated code will be deployed to Google Cloud Functions, this option can be "
|
||||
+ "used to update the name of the exported function. By default, it refers to the "
|
||||
+ "basePath. This does not affect normal standalone nodejs server code."));
|
||||
cliOptions.add(new CliOption(SERVER_PORT,
|
||||
"TCP port to listen on."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiPackage() {
|
||||
return "controllers";
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the type of generator.
|
||||
*
|
||||
* @return the CodegenType for this generator
|
||||
* @see org.openapitools.codegen.CodegenType
|
||||
*/
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a friendly name for the generator. This will be used by the generator
|
||||
* to select the library with the -g flag.
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "nodejs-server-deprecated";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns human-friendly help for the generator. Provide the consumer with help
|
||||
* tips, parameters here
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "[DEPRECATED] Generates a nodejs server library using the swagger-tools project. By default, " +
|
||||
"it will also generate service classes--which you can disable with the `-Dnoservice` environment variable.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultController";
|
||||
}
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
return toApiName(name);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
String result = super.apiFilename(templateName, tag);
|
||||
|
||||
if (templateName.equals("service.mustache")) {
|
||||
String stringToMatch = File.separator + "controllers" + File.separator;
|
||||
String replacement = File.separator + implFolder + File.separator;
|
||||
result = result.replaceAll(Pattern.quote(stringToMatch), replacement);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String implFileFolder(String output) {
|
||||
return outputFolder + File.separator + output + File.separator + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
|
||||
* those terms here. This logic is only called if a variable matches the reserved words
|
||||
*
|
||||
* @return the escaped term
|
||||
*/
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
if (this.reservedWordsMappings().containsKey(name)) {
|
||||
return this.reservedWordsMappings().get(name);
|
||||
}
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write api files. You can use the apiPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public boolean getGoogleCloudFunctions() {
|
||||
return googleCloudFunctions;
|
||||
}
|
||||
|
||||
public void setGoogleCloudFunctions(boolean value) {
|
||||
googleCloudFunctions = value;
|
||||
}
|
||||
|
||||
public String getExportedName() {
|
||||
return exportedName;
|
||||
}
|
||||
|
||||
public void setExportedName(String name) {
|
||||
exportedName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> objectMap = (Map<String, Object>) objs.get("operations");
|
||||
@SuppressWarnings("unchecked")
|
||||
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
||||
for (CodegenOperation operation : operations) {
|
||||
operation.httpMethod = operation.httpMethod.toLowerCase(Locale.ROOT);
|
||||
|
||||
List<CodegenParameter> params = operation.allParams;
|
||||
if (params != null && params.size() == 0) {
|
||||
operation.allParams = null;
|
||||
}
|
||||
List<CodegenResponse> responses = operation.responses;
|
||||
if (responses != null) {
|
||||
for (CodegenResponse resp : responses) {
|
||||
if ("0".equals(resp.code)) {
|
||||
resp.code = "default";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (operation.examples != null && !operation.examples.isEmpty()) {
|
||||
// Leave application/json* items only
|
||||
for (Iterator<Map<String, String>> it = operation.examples.iterator(); it.hasNext(); ) {
|
||||
final Map<String, String> example = it.next();
|
||||
final String contentType = example.get("contentType");
|
||||
if (contentType == null || !contentType.startsWith("application/json")) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<Map<String, Object>> getOperations(Map<String, Object> objs) {
|
||||
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
|
||||
Map<String, Object> apiInfo = (Map<String, Object>) objs.get("apiInfo");
|
||||
List<Map<String, Object>> apis = (List<Map<String, Object>>) apiInfo.get("apis");
|
||||
for (Map<String, Object> api : apis) {
|
||||
result.add((Map<String, Object>) api.get("operations"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<Map<String, Object>> sortOperationsByPath(List<CodegenOperation> ops) {
|
||||
Multimap<String, CodegenOperation> opsByPath = ArrayListMultimap.create();
|
||||
|
||||
for (CodegenOperation op : ops) {
|
||||
opsByPath.put(op.path, op);
|
||||
}
|
||||
|
||||
List<Map<String, Object>> opsByPathList = new ArrayList<Map<String, Object>>();
|
||||
for (Entry<String, Collection<CodegenOperation>> entry : opsByPath.asMap().entrySet()) {
|
||||
Map<String, Object> opsByPathEntry = new HashMap<String, Object>();
|
||||
opsByPathList.add(opsByPathEntry);
|
||||
opsByPathEntry.put("path", entry.getKey());
|
||||
opsByPathEntry.put("operation", entry.getValue());
|
||||
List<CodegenOperation> operationsForThisPath = Lists.newArrayList(entry.getValue());
|
||||
operationsForThisPath.get(operationsForThisPath.size() - 1).hasMore = false;
|
||||
if (opsByPathList.size() < opsByPath.asMap().size()) {
|
||||
opsByPathEntry.put("hasMore", "true");
|
||||
}
|
||||
}
|
||||
|
||||
return opsByPathList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
StringBuilder message = new StringBuilder();
|
||||
message.append(System.lineSeparator()).append(System.lineSeparator())
|
||||
.append("=======================================================================================")
|
||||
.append(System.lineSeparator())
|
||||
.append("IMPORTANT: The nodejs-server generator has been deprecated.")
|
||||
.append(System.lineSeparator())
|
||||
.append("Currently, Node.js server doesn't work as its dependency doesn't support OpenAPI Spec3.")
|
||||
.append(System.lineSeparator())
|
||||
.append("For further details, see https://github.com/OpenAPITools/openapi-generator/issues/34")
|
||||
.append(System.lineSeparator())
|
||||
.append("=======================================================================================")
|
||||
.append(System.lineSeparator()).append(System.lineSeparator());
|
||||
LOGGER.warn(message.toString());
|
||||
|
||||
if (additionalProperties.containsKey(GOOGLE_CLOUD_FUNCTIONS)) {
|
||||
setGoogleCloudFunctions(
|
||||
Boolean.valueOf(additionalProperties.get(GOOGLE_CLOUD_FUNCTIONS).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(EXPORTED_NAME)) {
|
||||
setExportedName((String) additionalProperties.get(EXPORTED_NAME));
|
||||
}
|
||||
|
||||
/*
|
||||
* Supporting Files. You can write single files for the generator with the
|
||||
* entire object tree available. If the input file has a suffix of `.mustache
|
||||
* it will be processed by the template engine. Otherwise, it will be copied
|
||||
*/
|
||||
// supportingFiles.add(new SupportingFile("controller.mustache",
|
||||
// "controllers",
|
||||
// "controller.js")
|
||||
// );
|
||||
supportingFiles.add(new SupportingFile("openapi.mustache",
|
||||
"api",
|
||||
"openapi.yaml")
|
||||
);
|
||||
if (getGoogleCloudFunctions()) {
|
||||
supportingFiles.add(new SupportingFile("index-gcf.mustache", "", "index.js")
|
||||
.doNotOverwrite());
|
||||
} else {
|
||||
supportingFiles.add(new SupportingFile("index.mustache", "", "index.js")
|
||||
.doNotOverwrite());
|
||||
}
|
||||
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json")
|
||||
.doNotOverwrite());
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")
|
||||
.doNotOverwrite());
|
||||
if (GlobalSettings.getProperty("noservice") == null) {
|
||||
apiTemplateFiles.put(
|
||||
"service.mustache", // the template to use
|
||||
"Service.js"); // the extension for each file to write
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessOpenAPI(OpenAPI openAPI) {
|
||||
URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides());
|
||||
String host = URLPathUtils.getProtocolAndHost(url);
|
||||
String port = URLPathUtils.getPort(url, defaultServerPort) ;
|
||||
String basePath = url.getPath();
|
||||
|
||||
if (additionalProperties.containsKey(SERVER_PORT)) {
|
||||
port = additionalProperties.get(SERVER_PORT).toString();
|
||||
}
|
||||
this.additionalProperties.put(SERVER_PORT, port);
|
||||
|
||||
if (openAPI.getInfo() != null) {
|
||||
Info info = openAPI.getInfo();
|
||||
if (info.getTitle() != null) {
|
||||
// when info.title is defined, use it for projectName
|
||||
// used in package.json
|
||||
projectName = info.getTitle()
|
||||
.replaceAll("[^a-zA-Z0-9]", "-")
|
||||
.replaceAll("^[-]*", "")
|
||||
.replaceAll("[-]*$", "")
|
||||
.replaceAll("[-]{2,}", "-")
|
||||
.toLowerCase(Locale.ROOT);
|
||||
this.additionalProperties.put("projectName", projectName);
|
||||
}
|
||||
}
|
||||
|
||||
if (getGoogleCloudFunctions()) {
|
||||
// Note that Cloud Functions don't allow customizing port name, simply checking host
|
||||
// is good enough.
|
||||
if (!host.endsWith(".cloudfunctions.net")) {
|
||||
LOGGER.warn("Host " + host + " seems not matching with cloudfunctions.net URL.");
|
||||
}
|
||||
if (!additionalProperties.containsKey(EXPORTED_NAME)) {
|
||||
if (basePath == null || basePath.equals("/")) {
|
||||
LOGGER.warn("Cannot find the exported name properly. Using 'openapi' as the exported name");
|
||||
basePath = "/openapi";
|
||||
}
|
||||
additionalProperties.put(EXPORTED_NAME, basePath.substring(1));
|
||||
}
|
||||
}
|
||||
|
||||
// need vendor extensions for x-swagger-router-controller
|
||||
Paths paths = openAPI.getPaths();
|
||||
if (paths != null) {
|
||||
for (String pathname : paths.keySet()) {
|
||||
PathItem path = paths.get(pathname);
|
||||
Map<HttpMethod, Operation> operationMap = path.readOperationsMap();
|
||||
if (operationMap != null) {
|
||||
for (HttpMethod method : operationMap.keySet()) {
|
||||
Operation operation = operationMap.get(method);
|
||||
String tag = "default";
|
||||
if (operation.getTags() != null && operation.getTags().size() > 0) {
|
||||
tag = toApiName(operation.getTags().get(0));
|
||||
}
|
||||
if (operation.getOperationId() == null) {
|
||||
operation.setOperationId(getOrGenerateOperationId(operation, pathname, method.toString()));
|
||||
}
|
||||
if (operation.getExtensions() == null ||
|
||||
operation.getExtensions().get("x-swagger-router-controller") == null) {
|
||||
operation.addExtension("x-swagger-router-controller", sanitizeTag(tag));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
generateYAMLSpecFile(objs);
|
||||
|
||||
for (Map<String, Object> operations : getOperations(objs)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
|
||||
List<Map<String, Object>> opsByPathList = sortOperationsByPath(ops);
|
||||
operations.put("operationsByPath", opsByPathList);
|
||||
}
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String removeNonNameElementToCamelCase(String name) {
|
||||
return removeNonNameElementToCamelCase(name, "[-:;#]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove " to avoid code injection
|
||||
return input.replace("\"", "");
|
||||
}
|
||||
}
|
||||
@@ -888,25 +888,12 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
|
||||
// add x-data-type to store powershell type
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> _model = (Map<String, Object>) _mo;
|
||||
CodegenModel model = (CodegenModel) _model.get("model");
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
|
||||
for (CodegenProperty cp : model.allVars) {
|
||||
for (CodegenProperty cp : cm.allVars) {
|
||||
cp.vendorExtensions.put("x-powershell-data-type", getPSDataType(cp));
|
||||
}
|
||||
|
||||
// if oneOf contains "null" type
|
||||
if (model.oneOf != null && !model.oneOf.isEmpty() && model.oneOf.contains("ModelNull")) {
|
||||
model.isNullable = true;
|
||||
model.oneOf.remove("ModelNull");
|
||||
}
|
||||
|
||||
// if anyOf contains "null" type
|
||||
if (model.anyOf != null && !model.anyOf.isEmpty() && model.anyOf.contains("ModelNull")) {
|
||||
model.isNullable = true;
|
||||
model.anyOf.remove("ModelNull");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return objs;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -710,7 +710,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
for (int i=0 ; i< indentation ; i++) indentation_string += " ";
|
||||
String example = super.toExampleValue(schema);
|
||||
|
||||
if (ModelUtils.isNullType(schema) && null != example) {
|
||||
if (ModelUtils.isNullType(schema)) {
|
||||
// The 'null' type is allowed in OAS 3.1 and above. It is not supported by OAS 3.0.x,
|
||||
// though this tooling supports it.
|
||||
return "None";
|
||||
|
||||
@@ -108,7 +108,7 @@ public class ProcessUtils {
|
||||
public static boolean hasHttpBearerMethods(List<CodegenSecurity> authMethods) {
|
||||
if (authMethods != null && !authMethods.isEmpty()) {
|
||||
for (CodegenSecurity cs : authMethods) {
|
||||
if (Boolean.TRUE.equals(cs.isBasicBearer)) {
|
||||
if (Boolean.TRUE.equals(cs.isBasicBasic)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,15 +53,9 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.text.DateFormat;
|
||||
|
||||
import {{invokerPackage}}.auth.Authentication;
|
||||
{{#hasHttpBasicMethods}}
|
||||
import {{invokerPackage}}.auth.HttpBasicAuth;
|
||||
{{/hasHttpBasicMethods}}
|
||||
{{#hasHttpBearerMethods}}
|
||||
import {{invokerPackage}}.auth.HttpBearerAuth;
|
||||
{{/hasHttpBearerMethods}}
|
||||
{{#hasApiKeyMethods}}
|
||||
import {{invokerPackage}}.auth.ApiKeyAuth;
|
||||
{{/hasApiKeyMethods}}
|
||||
{{#hasOAuthMethods}}
|
||||
import {{invokerPackage}}.auth.OAuth;
|
||||
{{/hasOAuthMethods}}
|
||||
@@ -273,24 +267,6 @@ public class ApiClient {
|
||||
return authentications.get(authName);
|
||||
}
|
||||
|
||||
{{#hasHttpBearerMethods}}
|
||||
/**
|
||||
* Helper method to set access token for the first Bearer authentication.
|
||||
* @param bearerToken Bearer token
|
||||
*/
|
||||
public void setBearerToken(String bearerToken) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof HttpBearerAuth) {
|
||||
((HttpBearerAuth) auth).setBearerToken(bearerToken);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No Bearer authentication configured!");
|
||||
}
|
||||
|
||||
{{/hasHttpBearerMethods}}
|
||||
|
||||
{{#hasHttpBasicMethods}}
|
||||
/**
|
||||
* Helper method to set username for the first HTTP basic authentication.
|
||||
* @param username Username
|
||||
@@ -319,9 +295,6 @@ public class ApiClient {
|
||||
throw new RuntimeException("No HTTP basic authentication configured!");
|
||||
}
|
||||
|
||||
{{/hasHttpBasicMethods}}
|
||||
|
||||
{{#hasApiKeyMethods}}
|
||||
/**
|
||||
* Helper method to set API key value for the first API key authentication.
|
||||
* @param apiKey the API key
|
||||
@@ -350,8 +323,6 @@ public class ApiClient {
|
||||
throw new RuntimeException("No API key authentication configured!");
|
||||
}
|
||||
|
||||
{{/hasApiKeyMethods}}
|
||||
|
||||
{{#hasOAuthMethods}}
|
||||
/**
|
||||
* Helper method to set access token for the first OAuth2 authentication.
|
||||
@@ -369,6 +340,20 @@ public class ApiClient {
|
||||
|
||||
{{/hasOAuthMethods}}
|
||||
|
||||
/**
|
||||
* Helper method to set access token for the first Bearer authentication.
|
||||
* @param bearerToken Bearer token
|
||||
*/
|
||||
public void setBearerToken(String bearerToken) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof HttpBearerAuth) {
|
||||
((HttpBearerAuth) auth).setBearerToken(bearerToken);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No Bearer authentication configured!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the User-Agent header's value (by adding to the default header map).
|
||||
* @param userAgent User agent
|
||||
|
||||
@@ -3,13 +3,10 @@
|
||||
package {{invokerPackage}}.model;
|
||||
|
||||
import {{invokerPackage}}.ApiException;
|
||||
import java.util.Objects;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import javax.ws.rs.core.GenericType;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
/**
|
||||
* Abstract class for oneOf,anyOf schemas defined in OpenAPI spec
|
||||
*/
|
||||
@@ -42,7 +39,6 @@ public abstract class AbstractOpenApiSchema {
|
||||
*
|
||||
* @return an instance of the actual schema/object
|
||||
*/
|
||||
@JsonValue
|
||||
public Object getActualInstance() {return instance;}
|
||||
|
||||
/***
|
||||
@@ -61,46 +57,6 @@ public abstract class AbstractOpenApiSchema {
|
||||
return schemaType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class ").append(getClass()).append(" {\n");
|
||||
sb.append(" instance: ").append(toIndentedString(instance)).append("\n");
|
||||
sb.append(" isNullable: ").append(toIndentedString(isNullable)).append("\n");
|
||||
sb.append(" schemaType: ").append(toIndentedString(schemaType)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(java.lang.Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
AbstractOpenApiSchema a = (AbstractOpenApiSchema) o;
|
||||
return Objects.equals(this.instance, a.instance) &&
|
||||
Objects.equals(this.isNullable, a.isNullable) &&
|
||||
Objects.equals(this.schemaType, a.schemaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(instance, isNullable, schemaType);
|
||||
}
|
||||
|
||||
/***
|
||||
* Is nullalble
|
||||
*
|
||||
|
||||
@@ -59,9 +59,7 @@ import java.util.regex.Pattern;
|
||||
import {{invokerPackage}}.auth.Authentication;
|
||||
import {{invokerPackage}}.auth.HttpBasicAuth;
|
||||
import {{invokerPackage}}.auth.HttpBearerAuth;
|
||||
{{#hasHttpSignatureMethods}}
|
||||
import {{invokerPackage}}.auth.HttpSignatureAuth;
|
||||
{{/hasHttpSignatureMethods}}
|
||||
import {{invokerPackage}}.auth.ApiKeyAuth;
|
||||
{{#hasOAuthMethods}}
|
||||
import {{invokerPackage}}.auth.OAuth;
|
||||
@@ -154,19 +152,7 @@ public class ApiClient {
|
||||
|
||||
protected DateFormat dateFormat;
|
||||
|
||||
/**
|
||||
* Constructs a new ApiClient with default parameters.
|
||||
*/
|
||||
public ApiClient() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ApiClient with the specified authentication parameters.
|
||||
*
|
||||
* @param authMap A hash map containing authentication parameters.
|
||||
*/
|
||||
public ApiClient(Map<String, Authentication> authMap) {
|
||||
json = new JSON();
|
||||
httpClient = buildHttpClient(debugging);
|
||||
|
||||
@@ -177,47 +163,23 @@ public class ApiClient {
|
||||
|
||||
// Setup authentications (key: authentication name, value: authentication).
|
||||
authentications = new HashMap<String, Authentication>();
|
||||
Authentication auth = null;
|
||||
{{#authMethods}}
|
||||
if (authMap != null) {
|
||||
auth = authMap.get("{{name}}");
|
||||
}
|
||||
{{#isBasic}}
|
||||
{{#isBasicBasic}}
|
||||
if (auth instanceof HttpBasicAuth) {
|
||||
authentications.put("{{name}}", auth);
|
||||
} else {
|
||||
authentications.put("{{name}}", new HttpBasicAuth());
|
||||
}
|
||||
authentications.put("{{name}}", new HttpBasicAuth());
|
||||
{{/isBasicBasic}}
|
||||
{{#isBasicBearer}}
|
||||
if (auth instanceof HttpBearerAuth) {
|
||||
authentications.put("{{name}}", auth);
|
||||
} else {
|
||||
authentications.put("{{name}}", new HttpBearerAuth("{{scheme}}"));
|
||||
}
|
||||
authentications.put("{{name}}", new HttpBearerAuth("{{scheme}}"));
|
||||
{{/isBasicBearer}}
|
||||
{{#isHttpSignature}}
|
||||
if (auth instanceof HttpSignatureAuth) {
|
||||
authentications.put("{{name}}", auth);
|
||||
} else {
|
||||
authentications.put("{{name}}", null);
|
||||
}
|
||||
authentications.put("{{name}}", new HttpSignatureAuth("{{name}}", null, null));
|
||||
{{/isHttpSignature}}
|
||||
{{/isBasic}}
|
||||
{{#isApiKey}}
|
||||
if (auth instanceof ApiKeyAuth) {
|
||||
authentications.put("{{name}}", auth);
|
||||
} else {
|
||||
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));
|
||||
}
|
||||
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));
|
||||
{{/isApiKey}}
|
||||
{{#isOAuth}}
|
||||
if (auth instanceof OAuth) {
|
||||
authentications.put("{{name}}", auth);
|
||||
} else {
|
||||
authentications.put("{{name}}", new OAuth(basePath, "{{tokenUrl}}"));
|
||||
}
|
||||
authentications.put("{{name}}", new OAuth(basePath, "{{tokenUrl}}"));
|
||||
{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
// Prevent the authentications from being modified.
|
||||
|
||||
@@ -1,51 +1,11 @@
|
||||
import javax.ws.rs.core.GenericType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
|
||||
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{>xmlAnnotation}}
|
||||
@JsonDeserialize(using={{classname}}.{{classname}}Deserializer.class)
|
||||
public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-implements}}, {{{.}}}{{/vendorExtensions.x-implements}} {
|
||||
public static class {{classname}}Deserializer extends StdDeserializer<{{classname}}> {
|
||||
public {{classname}}Deserializer() {
|
||||
this({{classname}}.class);
|
||||
}
|
||||
|
||||
public {{classname}}Deserializer(Class<?> vc) {
|
||||
super(vc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public {{classname}} deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
JsonNode tree = jp.readValueAsTree();
|
||||
|
||||
int match = 0;
|
||||
Object deserialized = null;
|
||||
{{#oneOf}}
|
||||
try {
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs({{{.}}}.class);
|
||||
match++;
|
||||
} catch (Exception e) {
|
||||
// deserialization failed, continue
|
||||
}
|
||||
{{/oneOf}}
|
||||
if (match == 1) {
|
||||
{{classname}} ret = new {{classname}}();
|
||||
ret.setActualInstance(deserialized);
|
||||
return ret;
|
||||
}
|
||||
throw new IOException(String.format("Failed deserialization for {{classname}}: %d classes match result, expected 1", match));
|
||||
}
|
||||
}
|
||||
|
||||
// store a list of schema names defined in oneOf
|
||||
public final static Map<String, GenericType> schemas = new HashMap<String, GenericType>();
|
||||
@@ -54,13 +14,6 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
super("oneOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
|
||||
}
|
||||
|
||||
{{#oneOf}}
|
||||
public {{classname}}({{{.}}} o) {
|
||||
super("oneOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
|
||||
setActualInstance(o);
|
||||
}
|
||||
{{/oneOf}}
|
||||
|
||||
static {
|
||||
{{#oneOf}}
|
||||
schemas.put("{{{.}}}", new GenericType<{{{.}}}>() {
|
||||
|
||||
@@ -338,13 +338,13 @@
|
||||
<version>${commons-io-version}</version>
|
||||
</dependency>
|
||||
{{/supportJava6}}
|
||||
{{#hasHttpSignatureMethods}}
|
||||
{{#hasHttpBasicMethods}}
|
||||
<dependency>
|
||||
<groupId>org.tomitribe</groupId>
|
||||
<artifactId>tomitribe-http-signatures</artifactId>
|
||||
<version>${http-signature-version}</version>
|
||||
</dependency>
|
||||
{{/hasHttpSignatureMethods}}
|
||||
{{/hasHttpBasicMethods}}
|
||||
{{#hasOAuthMethods}}
|
||||
<dependency>
|
||||
<groupId>com.github.scribejava</groupId>
|
||||
@@ -387,9 +387,9 @@
|
||||
<threetenbp-version>2.9.10</threetenbp-version>
|
||||
{{/threetenbp}}
|
||||
<junit-version>4.13</junit-version>
|
||||
{{#hasHttpSignatureMethods}}
|
||||
{{#hasHttpBasicMethods}}
|
||||
<http-signature-version>1.4</http-signature-version>
|
||||
{{/hasHttpSignatureMethods}}
|
||||
{{/hasHttpBasicMethods}}
|
||||
{{#hasOAuthMethods}}
|
||||
<scribejava-apis-version>6.9.0</scribejava-apis-version>
|
||||
{{/hasOAuthMethods}}
|
||||
|
||||
@@ -66,15 +66,9 @@ import java.util.Map.Entry;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import {{invokerPackage}}.auth.Authentication;
|
||||
{{#hasHttpBasicMethods}}
|
||||
import {{invokerPackage}}.auth.HttpBasicAuth;
|
||||
{{/hasHttpBasicMethods}}
|
||||
{{#hasHttpBearerMethods}}
|
||||
import {{invokerPackage}}.auth.HttpBearerAuth;
|
||||
{{/hasHttpBearerMethods}}
|
||||
{{#hasApiKeyMethods}}
|
||||
import {{invokerPackage}}.auth.ApiKeyAuth;
|
||||
{{/hasApiKeyMethods}}
|
||||
{{#hasOAuthMethods}}
|
||||
import {{invokerPackage}}.auth.OAuth;
|
||||
{{/hasOAuthMethods}}
|
||||
@@ -176,103 +170,93 @@ public class ApiClient {
|
||||
return authentications.get(authName);
|
||||
}
|
||||
|
||||
{{#hasHttpBearerMethods}}
|
||||
/**
|
||||
* Helper method to set token for HTTP bearer authentication.
|
||||
* @param bearerToken the token
|
||||
*/
|
||||
public void setBearerToken(String bearerToken) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof HttpBearerAuth) {
|
||||
((HttpBearerAuth) auth).setBearerToken(bearerToken);
|
||||
return;
|
||||
/**
|
||||
* Helper method to set token for HTTP bearer authentication.
|
||||
* @param bearerToken the token
|
||||
*/
|
||||
public void setBearerToken(String bearerToken) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof HttpBearerAuth) {
|
||||
((HttpBearerAuth) auth).setBearerToken(bearerToken);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No Bearer authentication configured!");
|
||||
}
|
||||
throw new RuntimeException("No Bearer authentication configured!");
|
||||
}
|
||||
|
||||
{{/hasHttpBearerMethods}}
|
||||
|
||||
{{#hasHttpBasicMethods}}
|
||||
/**
|
||||
* Helper method to set username for the first HTTP basic authentication.
|
||||
* @param username Username
|
||||
*/
|
||||
public void setUsername(String username) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof HttpBasicAuth) {
|
||||
((HttpBasicAuth) auth).setUsername(username);
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Helper method to set username for the first HTTP basic authentication.
|
||||
* @param username the username
|
||||
*/
|
||||
public void setUsername(String username) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof HttpBasicAuth) {
|
||||
((HttpBasicAuth) auth).setUsername(username);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No HTTP basic authentication configured!");
|
||||
}
|
||||
throw new RuntimeException("No HTTP basic authentication configured!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set password for the first HTTP basic authentication.
|
||||
* @param password Password
|
||||
*/
|
||||
public void setPassword(String password) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof HttpBasicAuth) {
|
||||
((HttpBasicAuth) auth).setPassword(password);
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Helper method to set password for the first HTTP basic authentication.
|
||||
* @param password the password
|
||||
*/
|
||||
public void setPassword(String password) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof HttpBasicAuth) {
|
||||
((HttpBasicAuth) auth).setPassword(password);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No HTTP basic authentication configured!");
|
||||
}
|
||||
throw new RuntimeException("No HTTP basic authentication configured!");
|
||||
}
|
||||
|
||||
{{/hasHttpBasicMethods}}
|
||||
|
||||
{{#hasApiKeyMethods}}
|
||||
/**
|
||||
* Helper method to set API key value for the first API key authentication.
|
||||
* @param apiKey the API key
|
||||
*/
|
||||
public void setApiKey(String apiKey) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof ApiKeyAuth) {
|
||||
((ApiKeyAuth) auth).setApiKey(apiKey);
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Helper method to set API key value for the first API key authentication.
|
||||
* @param apiKey the API key
|
||||
*/
|
||||
public void setApiKey(String apiKey) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof ApiKeyAuth) {
|
||||
((ApiKeyAuth) auth).setApiKey(apiKey);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No API key authentication configured!");
|
||||
}
|
||||
throw new RuntimeException("No API key authentication configured!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set API key prefix for the first API key authentication.
|
||||
* @param apiKeyPrefix API key prefix
|
||||
*/
|
||||
public void setApiKeyPrefix(String apiKeyPrefix) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof ApiKeyAuth) {
|
||||
((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix);
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Helper method to set API key prefix for the first API key authentication.
|
||||
* @param apiKeyPrefix the API key prefix
|
||||
*/
|
||||
public void setApiKeyPrefix(String apiKeyPrefix) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof ApiKeyAuth) {
|
||||
((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No API key authentication configured!");
|
||||
}
|
||||
throw new RuntimeException("No API key authentication configured!");
|
||||
}
|
||||
|
||||
{{/hasApiKeyMethods}}
|
||||
|
||||
{{#hasOAuthMethods}}
|
||||
/**
|
||||
* Helper method to set access token for the first OAuth2 authentication.
|
||||
* @param accessToken Access token
|
||||
*/
|
||||
public void setAccessToken(String accessToken) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof OAuth) {
|
||||
((OAuth) auth).setAccessToken(accessToken);
|
||||
return;
|
||||
}
|
||||
{{#hasOAuthMethods}}
|
||||
/**
|
||||
* Helper method to set access token for the first OAuth2 authentication.
|
||||
* @param accessToken the access token
|
||||
*/
|
||||
public void setAccessToken(String accessToken) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof OAuth) {
|
||||
((OAuth) auth).setAccessToken(accessToken);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No OAuth2 authentication configured!");
|
||||
}
|
||||
throw new RuntimeException("No OAuth2 authentication configured!");
|
||||
}
|
||||
|
||||
{{/hasOAuthMethods}}
|
||||
|
||||
/**
|
||||
{{/hasOAuthMethods}}
|
||||
/**
|
||||
* Set the User-Agent header's value (by adding to the default header map).
|
||||
* @param userAgent the user agent string
|
||||
* @return ApiClient this client
|
||||
|
||||
@@ -16,7 +16,6 @@ org.openapitools.codegen.languages.CppPistacheServerCodegen
|
||||
org.openapitools.codegen.languages.CppRestbedServerCodegen
|
||||
org.openapitools.codegen.languages.CppRestSdkClientCodegen
|
||||
org.openapitools.codegen.languages.CppTizenClientCodegen
|
||||
org.openapitools.codegen.languages.CppUE4ClientCodegen
|
||||
org.openapitools.codegen.languages.CSharpClientCodegen
|
||||
org.openapitools.codegen.languages.CSharpNetCoreClientCodegen
|
||||
org.openapitools.codegen.languages.CSharpDotNet2ClientCodegen
|
||||
@@ -72,6 +71,7 @@ org.openapitools.codegen.languages.LuaClientCodegen
|
||||
org.openapitools.codegen.languages.MarkdownDocumentationCodegen
|
||||
org.openapitools.codegen.languages.MysqlSchemaCodegen
|
||||
org.openapitools.codegen.languages.NimClientCodegen
|
||||
org.openapitools.codegen.languages.NodeJSServerCodegen
|
||||
org.openapitools.codegen.languages.NodeJSExpressServerCodegen
|
||||
org.openapitools.codegen.languages.ObjcClientCodegen
|
||||
org.openapitools.codegen.languages.OCamlClientCodegen
|
||||
@@ -125,4 +125,4 @@ org.openapitools.codegen.languages.TypeScriptInversifyClientCodegen
|
||||
org.openapitools.codegen.languages.TypeScriptJqueryClientCodegen
|
||||
org.openapitools.codegen.languages.TypeScriptNodeClientCodegen
|
||||
org.openapitools.codegen.languages.TypeScriptReduxQueryClientCodegen
|
||||
org.openapitools.codegen.languages.TypeScriptRxjsClientCodegen
|
||||
org.openapitools.codegen.languages.TypeScriptRxjsClientCodegen
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
{{>licenseInfo}}
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnrealBuildTool;
|
||||
|
||||
public class {{unrealModuleName}} : ModuleRules
|
||||
{
|
||||
public {{unrealModuleName}}(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PublicDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"Core",
|
||||
"Http",
|
||||
"Json",
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
{{>licenseInfo}}
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "{{modelNamePrefix}}BaseModel.h"
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}}
|
||||
{
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
||||
class {{dllapi}} {{classname}}
|
||||
{
|
||||
public:
|
||||
{{classname}}();
|
||||
~{{classname}}();
|
||||
|
||||
void SetURL(const FString& Url);
|
||||
void AddHeaderParam(const FString& Key, const FString& Value);
|
||||
void ClearHeaderParams();
|
||||
|
||||
{{#operations}}{{#operation}}class {{operationIdCamelCase}}Request;
|
||||
class {{operationIdCamelCase}}Response;
|
||||
{{/operation}}{{/operations}}
|
||||
{{#operations}}{{#operation}}DECLARE_DELEGATE_OneParam(F{{operationIdCamelCase}}Delegate, const {{operationIdCamelCase}}Response&);
|
||||
{{/operation}}{{/operations}}
|
||||
{{#operations}}{{#operation}}{{#description}}/* {{{description}}} */
|
||||
{{/description}}bool {{operationIdCamelCase}}(const {{operationIdCamelCase}}Request& Request, const F{{operationIdCamelCase}}Delegate& Delegate = F{{operationIdCamelCase}}Delegate()) const;
|
||||
{{/operation}}{{/operations}}
|
||||
private:
|
||||
{{#operations}}{{#operation}}void On{{operationIdCamelCase}}Response(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, F{{operationIdCamelCase}}Delegate Delegate) const;
|
||||
{{/operation}}{{/operations}}
|
||||
bool IsValid() const;
|
||||
void HandleResponse(FHttpResponsePtr HttpResponse, bool bSucceeded, Response& InOutResponse) const;
|
||||
|
||||
FString Url;
|
||||
TMap<FString,FString> AdditionalHeaderParams;
|
||||
};
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
}
|
||||
{{/cppNamespaceDeclarations}}
|
||||
@@ -1,64 +0,0 @@
|
||||
{{>licenseInfo}}
|
||||
#pragma once
|
||||
|
||||
#include "{{modelNamePrefix}}BaseModel.h"
|
||||
#include "{{classname}}.h"
|
||||
|
||||
{{#imports}}{{{import}}}
|
||||
{{/imports}}
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}}
|
||||
{
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
/* {{summary}}
|
||||
{{#notes}} *
|
||||
* {{notes}}{{/notes}}
|
||||
*/
|
||||
class {{dllapi}} {{classname}}::{{operationIdCamelCase}}Request : public Request
|
||||
{
|
||||
public:
|
||||
virtual ~{{operationIdCamelCase}}Request() {}
|
||||
void SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const final;
|
||||
FString ComputePath() const final;
|
||||
|
||||
{{#allParams}}
|
||||
{{#isEnum}}
|
||||
{{#allowableValues}}
|
||||
enum class {{{enumName}}}
|
||||
{
|
||||
{{#enumVars}}
|
||||
{{name}},
|
||||
{{/enumVars}}
|
||||
};
|
||||
{{/allowableValues}}
|
||||
{{#description}}/* {{{description}}} */
|
||||
{{/description}}{{^required}}TOptional<{{/required}}{{{datatypeWithEnum}}}{{^required}}>{{/required}} {{paramName}}{{#required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{/required}};
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{#description}}/* {{{description}}} */
|
||||
{{/description}}{{^required}}TOptional<{{/required}}{{{dataType}}}{{^required}}>{{/required}} {{paramName}}{{#required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{/required}};
|
||||
{{/isEnum}}
|
||||
{{/allParams}}
|
||||
};
|
||||
|
||||
class {{dllapi}} {{classname}}::{{operationIdCamelCase}}Response : public Response
|
||||
{
|
||||
public:
|
||||
virtual ~{{operationIdCamelCase}}Response() {}
|
||||
{{#responses.0}}
|
||||
void SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode) final;
|
||||
{{/responses.0}}
|
||||
bool FromJson(const TSharedPtr<FJsonValue>& JsonObject) final;
|
||||
|
||||
{{#returnType}}{{{returnType}}} Content;{{/returnType}}
|
||||
};
|
||||
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
{{#cppNamespaceDeclarations}}
|
||||
}
|
||||
{{/cppNamespaceDeclarations}}
|
||||
@@ -1,286 +0,0 @@
|
||||
{{>licenseInfo}}
|
||||
#include "{{classname}}Operations.h"
|
||||
|
||||
#include "{{unrealModuleName}}Module.h"
|
||||
#include "{{modelNamePrefix}}Helpers.h"
|
||||
|
||||
#include "Dom/JsonObject.h"
|
||||
#include "Templates/SharedPointer.h"
|
||||
#include "HttpModule.h"
|
||||
#include "PlatformHttp.h"
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}}
|
||||
{
|
||||
{{/cppNamespaceDeclarations}}
|
||||
{{#operations}}{{#operation}}
|
||||
{{#allParams}}
|
||||
{{#isEnum}}
|
||||
inline FString ToString(const {{classname}}::{{operationIdCamelCase}}Request::{{{enumName}}}& Value)
|
||||
{
|
||||
{{#allowableValues}}
|
||||
switch (Value)
|
||||
{
|
||||
{{#enumVars}}
|
||||
case {{classname}}::{{operationIdCamelCase}}Request::{{{enumName}}}::{{name}}:
|
||||
return TEXT({{{value}}});
|
||||
{{/enumVars}}
|
||||
}
|
||||
{{/allowableValues}}
|
||||
|
||||
UE_LOG(Log{{unrealModuleName}}, Error, TEXT("Invalid {{classname}}::{{operationIdCamelCase}}Request::{{{enumName}}} Value (%d)"), (int)Value);
|
||||
return TEXT("");
|
||||
}
|
||||
|
||||
inline FStringFormatArg ToStringFormatArg(const {{classname}}::{{operationIdCamelCase}}Request::{{{enumName}}}& Value)
|
||||
{
|
||||
return FStringFormatArg(ToString(Value));
|
||||
}
|
||||
|
||||
inline void WriteJsonValue(JsonWriter& Writer, const {{classname}}::{{operationIdCamelCase}}Request::{{{enumName}}}& Value)
|
||||
{
|
||||
WriteJsonValue(Writer, ToString(Value));
|
||||
}
|
||||
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, {{classname}}::{{operationIdCamelCase}}Request::{{{enumName}}}& Value)
|
||||
{
|
||||
{{#allowableValues}}
|
||||
FString TmpValue;
|
||||
if (JsonValue->TryGetString(TmpValue))
|
||||
{
|
||||
static TMap<FString, {{classname}}::{{operationIdCamelCase}}Request::{{{enumName}}}> StringToEnum = { {{#enumVars}}
|
||||
{ TEXT({{{value}}}), {{classname}}::{{operationIdCamelCase}}Request::{{{enumName}}}::{{name}} },{{/enumVars}} };
|
||||
|
||||
const auto Found = StringToEnum.Find(TmpValue);
|
||||
if(Found)
|
||||
{
|
||||
Value = *Found;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
{{/allowableValues}}
|
||||
return false;
|
||||
}
|
||||
|
||||
{{/isEnum}}
|
||||
{{/allParams}}
|
||||
FString {{classname}}::{{operationIdCamelCase}}Request::ComputePath() const
|
||||
{
|
||||
{{^pathParams.0}}
|
||||
FString Path(TEXT("{{{path}}}"));
|
||||
{{/pathParams.0}}
|
||||
{{#pathParams.0}}
|
||||
TMap<FString, FStringFormatArg> PathParams = { {{#pathParams}}
|
||||
{ TEXT("{{baseName}}"), ToStringFormatArg({{paramName}}) }{{#hasMore}},{{/hasMore}}{{/pathParams}} };
|
||||
|
||||
FString Path = FString::Format(TEXT("{{{path}}}"), PathParams);
|
||||
|
||||
{{/pathParams.0}}
|
||||
{{#queryParams.0}}
|
||||
TArray<FString> QueryParams;
|
||||
{{#queryParams}}
|
||||
{{#required}}
|
||||
{{^collectionFormat}}
|
||||
QueryParams.Add(FString(TEXT("{{baseName}}=")) + ToUrlString({{paramName}}));
|
||||
{{/collectionFormat}}
|
||||
{{#collectionFormat}}
|
||||
QueryParams.Add(FString(TEXT("{{baseName}}=")) + CollectionToUrlString_{{collectionFormat}}({{paramName}}, TEXT("{{baseName}}")));
|
||||
{{/collectionFormat}}
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
{{^collectionFormat}}
|
||||
if({{paramName}}.IsSet())
|
||||
{
|
||||
QueryParams.Add(FString(TEXT("{{baseName}}=")) + ToUrlString({{paramName}}.GetValue()));
|
||||
}
|
||||
{{/collectionFormat}}
|
||||
{{#collectionFormat}}
|
||||
if({{paramName}}.IsSet())
|
||||
{
|
||||
QueryParams.Add(FString(TEXT("{{baseName}}=")) + CollectionToUrlString_{{collectionFormat}}({{paramName}}.GetValue(), TEXT("{{baseName}}")));
|
||||
}
|
||||
{{/collectionFormat}}
|
||||
{{/required}}
|
||||
{{/queryParams}}
|
||||
Path += TCHAR('?');
|
||||
Path += FString::Join(QueryParams, TEXT("&"));
|
||||
|
||||
{{/queryParams.0}}
|
||||
return Path;
|
||||
}
|
||||
|
||||
void {{classname}}::{{operationIdCamelCase}}Request::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { {{#consumes}}TEXT("{{{mediaType}}}"){{#hasMore}}, {{/hasMore}}{{/consumes}} };
|
||||
//static const TArray<FString> Produces = { {{#produces}}TEXT("{{{mediaType}}}"){{#hasMore}}, {{/hasMore}}{{/produces}} };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("{{httpMethod}}"));
|
||||
{{#headerParams.0}}
|
||||
|
||||
// Header parameters
|
||||
{{#headerParams}}
|
||||
{{#required}}
|
||||
HttpRequest->SetHeader(TEXT("{{baseName}}"), {{paramName}});
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
if ({{paramName}}.IsSet())
|
||||
{
|
||||
HttpRequest->SetHeader(TEXT("{{baseName}}"), {{paramName}}.GetValue());
|
||||
}
|
||||
{{/required}}
|
||||
{{/headerParams}}
|
||||
{{/headerParams.0}}
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
{{#bodyParams.0}}
|
||||
// Body parameters
|
||||
FString JsonBody;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
|
||||
|
||||
Writer->WriteObjectStart();
|
||||
{{#bodyParams}}
|
||||
{{#required}}
|
||||
Writer->WriteIdentifierPrefix(TEXT("{{baseName}}")); WriteJsonValue(Writer, {{paramName}});
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
if ({{paramName}}.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("{{baseName}}")); WriteJsonValue(Writer, {{paramName}}.GetValue());
|
||||
}
|
||||
{{/required}}
|
||||
{{/bodyParams}}
|
||||
Writer->WriteObjectEnd();
|
||||
Writer->Close();
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
|
||||
HttpRequest->SetContentAsString(JsonBody);
|
||||
{{/bodyParams.0}}
|
||||
{{#formParams.0}}
|
||||
{{#formParams}}
|
||||
UE_LOG(Log{{unrealModuleName}}, Error, TEXT("Form parameter ({{baseName}}) was ignored, cannot be used in JsonBody"));
|
||||
{{/formParams}}
|
||||
{{/formParams.0}}
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
{{#formParams.0}}
|
||||
HttpMultipartFormData FormData;
|
||||
{{#formParams}}
|
||||
{{#isContainer}}
|
||||
UE_LOG(Log{{unrealModuleName}}, Error, TEXT("Form parameter ({{baseName}}) was ignored, Collections are not supported in multipart form"));
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
{{#required}}
|
||||
{{#isFile}}
|
||||
FormData.AddFilePart(TEXT("{{baseName}}"), {{paramName}});
|
||||
{{/isFile}}
|
||||
{{#isBinary}}
|
||||
FormData.AddBinaryPart(TEXT("{{baseName}}"), {{paramName}});
|
||||
{{/isBinary}}
|
||||
{{#isBinary}}
|
||||
{{^isFile}}
|
||||
FormData.AddStringPart(TEXT("{{baseName}}"), *ToUrlString({{paramName}}));
|
||||
{{/isFile}}
|
||||
{{/isBinary}}
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
if({{paramName}}.IsSet())
|
||||
{
|
||||
{{#isFile}}
|
||||
FormData.AddFilePart(TEXT("{{baseName}}"), {{paramName}}.GetValue());
|
||||
{{/isFile}}
|
||||
{{#isBinary}}
|
||||
FormData.AddBinaryPart(TEXT("{{baseName}}"), {{paramName}}.GetValue());
|
||||
{{/isBinary}}
|
||||
{{^isBinary}}
|
||||
{{^isFile}}
|
||||
FormData.AddStringPart(TEXT("{{baseName}}"), *ToUrlString({{paramName}}.GetValue()));
|
||||
{{/isFile}}
|
||||
{{/isBinary}}
|
||||
}
|
||||
{{/required}}
|
||||
{{/isContainer}}
|
||||
{{/formParams}}
|
||||
|
||||
FormData.SetupHttpRequest(HttpRequest);
|
||||
{{/formParams.0}}
|
||||
{{#bodyParams.0}}
|
||||
{{#bodyParams}}
|
||||
UE_LOG(Log{{unrealModuleName}}, Error, TEXT("Body parameter ({{baseName}}) was ignored, not supported in multipart form"));
|
||||
{{/bodyParams}}
|
||||
{{/bodyParams.0}}
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
{{#formParams.0}}
|
||||
TArray<FString> FormParams;
|
||||
{{#formParams}}
|
||||
{{#isContainer}}
|
||||
UE_LOG(Log{{unrealModuleName}}, Error, TEXT("Form parameter ({{baseName}}) was ignored, Collections are not supported in urlencoded requests"));
|
||||
{{/isContainer}}
|
||||
{{#isFile}}
|
||||
UE_LOG(Log{{unrealModuleName}}, Error, TEXT("Form parameter ({{baseName}}) was ignored, Files are not supported in urlencoded requests"));
|
||||
{{/isFile}}
|
||||
{{^isFile}}
|
||||
{{^isContainer}}
|
||||
{{#required}}
|
||||
FormParams.Add(FString(TEXT("{{baseName}}=")) + ToUrlString({{paramName}}));
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
if({{paramName}}.IsSet())
|
||||
{
|
||||
FormParams.Add(FString(TEXT("{{baseName}}=")) + ToUrlString({{paramName}}.GetValue()));
|
||||
}
|
||||
{{/required}}
|
||||
{{/isContainer}}
|
||||
{{/isFile}}
|
||||
{{/formParams}}
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/x-www-form-urlencoded; charset=utf-8"));
|
||||
HttpRequest->SetContentAsString(FString::Join(FormParams, TEXT("&")));
|
||||
{{/formParams.0}}
|
||||
{{#bodyParams.0}}
|
||||
{{#bodyParams}}
|
||||
UE_LOG(Log{{unrealModuleName}}, Error, TEXT("Body parameter ({{baseName}}) was ignored, not supported in urlencoded requests"));
|
||||
{{/bodyParams}}
|
||||
{{/bodyParams.0}}
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(Log{{unrealModuleName}}, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
{{#responses.0}}
|
||||
void {{classname}}::{{operationIdCamelCase}}Response::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
{{#responses}}
|
||||
case {{code}}:
|
||||
{{#isDefault}}
|
||||
default:
|
||||
{{/isDefault}}
|
||||
SetResponseString(TEXT("{{message}}"));
|
||||
break;
|
||||
{{/responses}}
|
||||
}
|
||||
}
|
||||
{{/responses.0}}
|
||||
|
||||
bool {{classname}}::{{operationIdCamelCase}}Response::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
{{#returnType}}
|
||||
return TryGetJsonValue(JsonValue, Content);
|
||||
{{/returnType}}
|
||||
{{^returnType}}
|
||||
return true;
|
||||
{{/returnType}}
|
||||
}
|
||||
{{/operation}}{{/operations}}
|
||||
{{#cppNamespaceDeclarations}}
|
||||
}
|
||||
{{/cppNamespaceDeclarations}}
|
||||
@@ -1,120 +0,0 @@
|
||||
{{>licenseInfo}}
|
||||
#include "{{classname}}.h"
|
||||
|
||||
#include "{{classname}}Operations.h"
|
||||
#include "{{unrealModuleName}}Module.h"
|
||||
|
||||
#include "HttpModule.h"
|
||||
#include "Serialization/JsonSerializer.h"
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}}
|
||||
{
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
||||
{{classname}}::{{classname}}()
|
||||
: Url(TEXT("{{basePath}}"))
|
||||
{
|
||||
}
|
||||
|
||||
{{classname}}::~{{classname}}() {}
|
||||
|
||||
void {{classname}}::SetURL(const FString& InUrl)
|
||||
{
|
||||
Url = InUrl;
|
||||
}
|
||||
|
||||
void {{classname}}::AddHeaderParam(const FString& Key, const FString& Value)
|
||||
{
|
||||
AdditionalHeaderParams.Add(Key, Value);
|
||||
}
|
||||
|
||||
void {{classname}}::ClearHeaderParams()
|
||||
{
|
||||
AdditionalHeaderParams.Reset();
|
||||
}
|
||||
|
||||
bool {{classname}}::IsValid() const
|
||||
{
|
||||
if (Url.IsEmpty())
|
||||
{
|
||||
UE_LOG(Log{{unrealModuleName}}, Error, TEXT("{{classname}}: Endpoint Url is not set, request cannot be performed"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void {{classname}}::HandleResponse(FHttpResponsePtr HttpResponse, bool bSucceeded, Response& InOutResponse) const
|
||||
{
|
||||
InOutResponse.SetHttpResponse(HttpResponse);
|
||||
InOutResponse.SetSuccessful(bSucceeded);
|
||||
|
||||
if (bSucceeded && HttpResponse.IsValid())
|
||||
{
|
||||
InOutResponse.SetHttpResponseCode((EHttpResponseCodes::Type)HttpResponse->GetResponseCode());
|
||||
FString ContentType = HttpResponse->GetContentType();
|
||||
FString Content;
|
||||
|
||||
if (ContentType == TEXT("application/json"))
|
||||
{
|
||||
Content = HttpResponse->GetContentAsString();
|
||||
|
||||
TSharedPtr<FJsonValue> JsonValue;
|
||||
auto Reader = TJsonReaderFactory<>::Create(Content);
|
||||
|
||||
if (FJsonSerializer::Deserialize(Reader, JsonValue) && JsonValue.IsValid())
|
||||
{
|
||||
if (InOutResponse.FromJson(JsonValue))
|
||||
return; // Successfully parsed
|
||||
}
|
||||
}
|
||||
else if(ContentType == TEXT("text/plain"))
|
||||
{
|
||||
Content = HttpResponse->GetContentAsString();
|
||||
InOutResponse.SetResponseString(Content);
|
||||
return; // Successfully parsed
|
||||
}
|
||||
|
||||
// Report the parse error but do not mark the request as unsuccessful. Data could be partial or malformed, but the request succeeded.
|
||||
UE_LOG(Log{{unrealModuleName}}, Error, TEXT("Failed to deserialize Http response content (type:%s):\n%s"), *ContentType , *Content);
|
||||
return;
|
||||
}
|
||||
|
||||
// By default, assume we failed to establish connection
|
||||
InOutResponse.SetHttpResponseCode(EHttpResponseCodes::RequestTimeout);
|
||||
}
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
bool {{classname}}::{{operationIdCamelCase}}(const {{operationIdCamelCase}}Request& Request, const F{{operationIdCamelCase}}Delegate& Delegate /*= F{{operationIdCamelCase}}Delegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &{{classname}}::On{{operationIdCamelCase}}Response, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void {{classname}}::On{{operationIdCamelCase}}Response(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, F{{operationIdCamelCase}}Delegate Delegate) const
|
||||
{
|
||||
{{operationIdCamelCase}}Response Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
{{#cppNamespaceDeclarations}}
|
||||
}
|
||||
{{/cppNamespaceDeclarations}}
|
||||
@@ -1,405 +0,0 @@
|
||||
{{>licenseInfo}}
|
||||
#pragma once
|
||||
|
||||
#include "{{modelNamePrefix}}BaseModel.h"
|
||||
|
||||
#include "Serialization/JsonSerializer.h"
|
||||
#include "Dom/JsonObject.h"
|
||||
#include "Misc/Base64.h"
|
||||
|
||||
class IHttpRequest;
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}}
|
||||
{
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
||||
typedef TSharedRef<TJsonWriter<>> JsonWriter;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class {{dllapi}} HttpFileInput
|
||||
{
|
||||
public:
|
||||
HttpFileInput(const TCHAR* InFilePath);
|
||||
HttpFileInput(const FString& InFilePath);
|
||||
|
||||
// This will automatically set the content type if not already set
|
||||
void SetFilePath(const TCHAR* InFilePath);
|
||||
void SetFilePath(const FString& InFilePath);
|
||||
|
||||
// Optional if it can be deduced from the FilePath
|
||||
void SetContentType(const TCHAR* ContentType);
|
||||
|
||||
HttpFileInput& operator=(const HttpFileInput& Other) = default;
|
||||
HttpFileInput& operator=(const FString& InFilePath) { SetFilePath(*InFilePath); return*this; }
|
||||
HttpFileInput& operator=(const TCHAR* InFilePath) { SetFilePath(InFilePath); return*this; }
|
||||
|
||||
const FString& GetFilePath() const { return FilePath; }
|
||||
const FString& GetContentType() const { return ContentType; }
|
||||
|
||||
// Returns the filename with extension
|
||||
FString GetFilename() const;
|
||||
|
||||
private:
|
||||
FString FilePath;
|
||||
FString ContentType;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class HttpMultipartFormData
|
||||
{
|
||||
public:
|
||||
void SetBoundary(const TCHAR* InBoundary);
|
||||
void SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest);
|
||||
|
||||
void AddStringPart(const TCHAR* Name, const TCHAR* Data);
|
||||
void AddJsonPart(const TCHAR* Name, const FString& JsonString);
|
||||
void AddBinaryPart(const TCHAR* Name, const TArray<uint8>& ByteArray);
|
||||
void AddFilePart(const TCHAR* Name, const HttpFileInput& File);
|
||||
|
||||
private:
|
||||
void AppendString(const TCHAR* Str);
|
||||
const FString& GetBoundary() const;
|
||||
|
||||
mutable FString Boundary;
|
||||
TArray<uint8> FormData;
|
||||
|
||||
static const TCHAR* Delimiter;
|
||||
static const TCHAR* Newline;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Decodes Base64Url encoded strings, see https://en.wikipedia.org/wiki/Base64#Variants_summary_table
|
||||
template<typename T>
|
||||
bool Base64UrlDecode(const FString& Base64String, T& Value)
|
||||
{
|
||||
FString TmpCopy(Base64String);
|
||||
TmpCopy.ReplaceInline(TEXT("-"), TEXT("+"));
|
||||
TmpCopy.ReplaceInline(TEXT("_"), TEXT("/"));
|
||||
|
||||
return FBase64::Decode(TmpCopy, Value);
|
||||
}
|
||||
|
||||
// Encodes strings in Base64Url, see https://en.wikipedia.org/wiki/Base64#Variants_summary_table
|
||||
template<typename T>
|
||||
FString Base64UrlEncode(const T& Value)
|
||||
{
|
||||
FString Base64String = FBase64::Encode(Value);
|
||||
Base64String.ReplaceInline(TEXT("+"), TEXT("-"));
|
||||
Base64String.ReplaceInline(TEXT("/"), TEXT("_"));
|
||||
return Base64String;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline FStringFormatArg ToStringFormatArg(const T& Value)
|
||||
{
|
||||
return FStringFormatArg(Value);
|
||||
}
|
||||
|
||||
inline FStringFormatArg ToStringFormatArg(const FDateTime& Value)
|
||||
{
|
||||
return FStringFormatArg(Value.ToIso8601());
|
||||
}
|
||||
|
||||
inline FStringFormatArg ToStringFormatArg(const TArray<uint8>& Value)
|
||||
{
|
||||
return FStringFormatArg(Base64UrlEncode(Value));
|
||||
}
|
||||
|
||||
template<typename T, typename std::enable_if<!std::is_base_of<Model, T>::value, int>::type = 0>
|
||||
inline FString ToString(const T& Value)
|
||||
{
|
||||
return FString::Format(TEXT("{0}"), { ToStringFormatArg(Value) });
|
||||
}
|
||||
|
||||
inline FString ToString(const FString& Value)
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
inline FString ToString(const TArray<uint8>& Value)
|
||||
{
|
||||
return Base64UrlEncode(Value);
|
||||
}
|
||||
|
||||
inline FString ToString(const Model& Value)
|
||||
{
|
||||
FString String;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&String);
|
||||
Value.WriteJson(Writer);
|
||||
Writer->Close();
|
||||
return String;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline FString ToUrlString(const T& Value)
|
||||
{
|
||||
return FPlatformHttp::UrlEncode(ToString(Value));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline FString CollectionToUrlString(const TArray<T>& Collection, const TCHAR* Separator)
|
||||
{
|
||||
FString Output;
|
||||
if(Collection.Num() == 0)
|
||||
return Output;
|
||||
|
||||
Output += ToUrlString(Collection[0]);
|
||||
for(int i = 1; i < Collection.Num(); i++)
|
||||
{
|
||||
Output += FString::Format(TEXT("{0}{1}"), { Separator, *ToUrlString(Collection[i]) });
|
||||
}
|
||||
return Output;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline FString CollectionToUrlString_csv(const TArray<T>& Collection, const TCHAR* BaseName)
|
||||
{
|
||||
return CollectionToUrlString(Collection, TEXT(","));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline FString CollectionToUrlString_ssv(const TArray<T>& Collection, const TCHAR* BaseName)
|
||||
{
|
||||
return CollectionToUrlString(Collection, TEXT(" "));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline FString CollectionToUrlString_tsv(const TArray<T>& Collection, const TCHAR* BaseName)
|
||||
{
|
||||
return CollectionToUrlString(Collection, TEXT("\t"));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline FString CollectionToUrlString_pipes(const TArray<T>& Collection, const TCHAR* BaseName)
|
||||
{
|
||||
return CollectionToUrlString(Collection, TEXT("|"));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline FString CollectionToUrlString_multi(const TArray<T>& Collection, const TCHAR* BaseName)
|
||||
{
|
||||
FString Output;
|
||||
if(Collection.Num() == 0)
|
||||
return Output;
|
||||
|
||||
Output += FString::Format(TEXT("{0}={1}"), { FStringFormatArg(BaseName), ToUrlString(Collection[0]) });
|
||||
for(int i = 1; i < Collection.Num(); i++)
|
||||
{
|
||||
Output += FString::Format(TEXT("&{0}={1}"), { FStringFormatArg(BaseName), ToUrlString(Collection[i]) });
|
||||
}
|
||||
return Output;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename T, typename std::enable_if<!std::is_base_of<Model, T>::value, int>::type = 0>
|
||||
inline void WriteJsonValue(JsonWriter& Writer, const T& Value)
|
||||
{
|
||||
Writer->WriteValue(Value);
|
||||
}
|
||||
|
||||
inline void WriteJsonValue(JsonWriter& Writer, const FDateTime& Value)
|
||||
{
|
||||
Writer->WriteValue(Value.ToIso8601());
|
||||
}
|
||||
|
||||
inline void WriteJsonValue(JsonWriter& Writer, const Model& Value)
|
||||
{
|
||||
Value.WriteJson(Writer);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void WriteJsonValue(JsonWriter& Writer, const TArray<T>& Value)
|
||||
{
|
||||
Writer->WriteArrayStart();
|
||||
for (const auto& Element : Value)
|
||||
{
|
||||
WriteJsonValue(Writer, Element);
|
||||
}
|
||||
Writer->WriteArrayEnd();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void WriteJsonValue(JsonWriter& Writer, const TMap<FString, T>& Value)
|
||||
{
|
||||
Writer->WriteObjectStart();
|
||||
for (const auto& It : Value)
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(It.Key);
|
||||
WriteJsonValue(Writer, It.Value);
|
||||
}
|
||||
Writer->WriteObjectEnd();
|
||||
}
|
||||
|
||||
inline void WriteJsonValue(JsonWriter& Writer, const TSharedPtr<FJsonObject>& Value)
|
||||
{
|
||||
if (Value.IsValid())
|
||||
{
|
||||
FJsonSerializer::Serialize(Value.ToSharedRef(), Writer, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Writer->WriteObjectStart();
|
||||
Writer->WriteObjectEnd();
|
||||
}
|
||||
}
|
||||
|
||||
inline void WriteJsonValue(JsonWriter& Writer, const TArray<uint8>& Value)
|
||||
{
|
||||
Writer->WriteValue(ToString(Value));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename T>
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonObject>& JsonObject, const FString& Key, T& Value)
|
||||
{
|
||||
const TSharedPtr<FJsonValue> JsonValue = JsonObject->TryGetField(Key);
|
||||
if (JsonValue.IsValid() && !JsonValue->IsNull())
|
||||
{
|
||||
return TryGetJsonValue(JsonValue, Value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonObject>& JsonObject, const FString& Key, TOptional<T>& OptionalValue)
|
||||
{
|
||||
if(JsonObject->HasField(Key))
|
||||
{
|
||||
T Value;
|
||||
if (TryGetJsonValue(JsonObject, Key, Value))
|
||||
{
|
||||
OptionalValue = Value;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return true; // Absence of optional value is not a parsing error
|
||||
}
|
||||
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, FString& Value)
|
||||
{
|
||||
FString TmpValue;
|
||||
if (JsonValue->TryGetString(TmpValue))
|
||||
{
|
||||
Value = TmpValue;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, FDateTime& Value)
|
||||
{
|
||||
FString TmpValue;
|
||||
if (JsonValue->TryGetString(TmpValue))
|
||||
return FDateTime::Parse(TmpValue, Value);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, bool& Value)
|
||||
{
|
||||
bool TmpValue;
|
||||
if (JsonValue->TryGetBool(TmpValue))
|
||||
{
|
||||
Value = TmpValue;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T, typename std::enable_if<!std::is_base_of<Model, T>::value, int>::type = 0>
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, T& Value)
|
||||
{
|
||||
T TmpValue;
|
||||
if (JsonValue->TryGetNumber(TmpValue))
|
||||
{
|
||||
Value = TmpValue;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, Model& Value)
|
||||
{
|
||||
const TSharedPtr<FJsonObject>* Object;
|
||||
if (JsonValue->TryGetObject(Object))
|
||||
return Value.FromJson(*Object);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, TArray<T>& ArrayValue)
|
||||
{
|
||||
const TArray<TSharedPtr<FJsonValue>>* JsonArray;
|
||||
if (JsonValue->TryGetArray(JsonArray))
|
||||
{
|
||||
bool ParseSuccess = true;
|
||||
const int32 Count = JsonArray->Num();
|
||||
ArrayValue.Reset(Count);
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
T TmpValue;
|
||||
ParseSuccess &= TryGetJsonValue((*JsonArray)[i], TmpValue);
|
||||
ArrayValue.Emplace(MoveTemp(TmpValue));
|
||||
}
|
||||
return ParseSuccess;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, TMap<FString, T>& MapValue)
|
||||
{
|
||||
const TSharedPtr<FJsonObject>* Object;
|
||||
if (JsonValue->TryGetObject(Object))
|
||||
{
|
||||
MapValue.Reset();
|
||||
bool ParseSuccess = true;
|
||||
for (const auto& It : (*Object)->Values)
|
||||
{
|
||||
T TmpValue;
|
||||
ParseSuccess &= TryGetJsonValue(It.Value, TmpValue);
|
||||
MapValue.Emplace(It.Key, MoveTemp(TmpValue));
|
||||
}
|
||||
return ParseSuccess;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, TSharedPtr<FJsonObject>& JsonObjectValue)
|
||||
{
|
||||
const TSharedPtr<FJsonObject>* Object;
|
||||
if (JsonValue->TryGetObject(Object))
|
||||
{
|
||||
JsonObjectValue = *Object;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, TArray<uint8>& Value)
|
||||
{
|
||||
FString TmpValue;
|
||||
if (JsonValue->TryGetString(TmpValue))
|
||||
{
|
||||
Base64UrlDecode(TmpValue, Value);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
}
|
||||
{{/cppNamespaceDeclarations}}
|
||||
@@ -1,187 +0,0 @@
|
||||
{{>licenseInfo}}
|
||||
#include "{{modelNamePrefix}}Helpers.h"
|
||||
|
||||
#include "{{unrealModuleName}}Module.h"
|
||||
|
||||
#include "Interfaces/IHttpRequest.h"
|
||||
#include "PlatformHttp.h"
|
||||
#include "Misc/FileHelper.h"
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}}
|
||||
{
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
||||
HttpFileInput::HttpFileInput(const TCHAR* InFilePath)
|
||||
{
|
||||
SetFilePath(InFilePath);
|
||||
}
|
||||
|
||||
HttpFileInput::HttpFileInput(const FString& InFilePath)
|
||||
{
|
||||
SetFilePath(InFilePath);
|
||||
}
|
||||
|
||||
void HttpFileInput::SetFilePath(const TCHAR* InFilePath)
|
||||
{
|
||||
FilePath = InFilePath;
|
||||
if(ContentType.IsEmpty())
|
||||
{
|
||||
ContentType = FPlatformHttp::GetMimeType(InFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
void HttpFileInput::SetFilePath(const FString& InFilePath)
|
||||
{
|
||||
SetFilePath(*InFilePath);
|
||||
}
|
||||
|
||||
void HttpFileInput::SetContentType(const TCHAR* InContentType)
|
||||
{
|
||||
ContentType = InContentType;
|
||||
}
|
||||
|
||||
FString HttpFileInput::GetFilename() const
|
||||
{
|
||||
return FPaths::GetCleanFilename(FilePath);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const TCHAR* HttpMultipartFormData::Delimiter = TEXT("--");
|
||||
const TCHAR* HttpMultipartFormData::Newline = TEXT("\r\n");
|
||||
|
||||
void HttpMultipartFormData::SetBoundary(const TCHAR* InBoundary)
|
||||
{
|
||||
checkf(Boundary.IsEmpty(), TEXT("Boundary must be set before usage"));
|
||||
Boundary = InBoundary;
|
||||
}
|
||||
|
||||
const FString& HttpMultipartFormData::GetBoundary() const
|
||||
{
|
||||
if (Boundary.IsEmpty())
|
||||
{
|
||||
// Generate a random boundary with enough entropy, should avoid occurences of the boundary in the data.
|
||||
// Since the boundary is generated at every request, in case of failure, retries should succeed.
|
||||
Boundary = FGuid::NewGuid().ToString(EGuidFormats::Short);
|
||||
}
|
||||
|
||||
return Boundary;
|
||||
}
|
||||
|
||||
void HttpMultipartFormData::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest)
|
||||
{
|
||||
if(HttpRequest->GetVerb() != TEXT("POST"))
|
||||
{
|
||||
UE_LOG(Log{{unrealModuleName}}, Error, TEXT("Expected POST verb when using multipart form data"));
|
||||
}
|
||||
|
||||
// Append final boundary
|
||||
AppendString(Delimiter);
|
||||
AppendString(*GetBoundary());
|
||||
AppendString(Delimiter);
|
||||
|
||||
HttpRequest->SetHeader("Content-Type", FString::Printf(TEXT("multipart/form-data; boundary=%s"), *GetBoundary()));
|
||||
HttpRequest->SetContent(FormData);
|
||||
}
|
||||
|
||||
void HttpMultipartFormData::AddStringPart(const TCHAR* Name, const TCHAR* Data)
|
||||
{
|
||||
// Add boundary
|
||||
AppendString(Delimiter);
|
||||
AppendString(*GetBoundary());
|
||||
AppendString(Newline);
|
||||
|
||||
// Add header
|
||||
AppendString(*FString::Printf(TEXT("Content-Disposition: form-data; name = \"%s\""), Name));
|
||||
AppendString(Newline);
|
||||
AppendString(*FString::Printf(TEXT("Content-Type: text/plain; charset=utf-8")));
|
||||
AppendString(Newline);
|
||||
|
||||
// Add header to body splitter
|
||||
AppendString(Newline);
|
||||
|
||||
// Add Data
|
||||
AppendString(Data);
|
||||
AppendString(Newline);
|
||||
}
|
||||
|
||||
void HttpMultipartFormData::AddJsonPart(const TCHAR* Name, const FString& JsonString)
|
||||
{
|
||||
// Add boundary
|
||||
AppendString(Delimiter);
|
||||
AppendString(*GetBoundary());
|
||||
AppendString(Newline);
|
||||
|
||||
// Add header
|
||||
AppendString(*FString::Printf(TEXT("Content-Disposition: form-data; name=\"%s\""), Name));
|
||||
AppendString(Newline);
|
||||
AppendString(*FString::Printf(TEXT("Content-Type: application/json; charset=utf-8")));
|
||||
AppendString(Newline);
|
||||
|
||||
// Add header to body splitter
|
||||
AppendString(Newline);
|
||||
|
||||
// Add Data
|
||||
AppendString(*JsonString);
|
||||
AppendString(Newline);
|
||||
}
|
||||
|
||||
void HttpMultipartFormData::AddBinaryPart(const TCHAR* Name, const TArray<uint8>& ByteArray)
|
||||
{
|
||||
// Add boundary
|
||||
AppendString(Delimiter);
|
||||
AppendString(*GetBoundary());
|
||||
AppendString(Newline);
|
||||
|
||||
// Add header
|
||||
AppendString(*FString::Printf(TEXT("Content-Disposition: form-data; name=\"%s\""), Name));
|
||||
AppendString(Newline);
|
||||
AppendString(*FString::Printf(TEXT("Content-Type: application/octet-stream")));
|
||||
AppendString(Newline);
|
||||
|
||||
// Add header to body splitter
|
||||
AppendString(Newline);
|
||||
|
||||
// Add Data
|
||||
FormData.Append(ByteArray);
|
||||
AppendString(Newline);
|
||||
}
|
||||
|
||||
void HttpMultipartFormData::AddFilePart(const TCHAR* Name, const HttpFileInput& File)
|
||||
{
|
||||
TArray<uint8> FileContents;
|
||||
if (!FFileHelper::LoadFileToArray(FileContents, *File.GetFilePath()))
|
||||
{
|
||||
UE_LOG(Log{{unrealModuleName}}, Error, TEXT("Failed to load file (%s)"), *File.GetFilePath());
|
||||
return;
|
||||
}
|
||||
|
||||
// Add boundary
|
||||
AppendString(Delimiter);
|
||||
AppendString(*GetBoundary());
|
||||
AppendString(Newline);
|
||||
|
||||
// Add header
|
||||
AppendString(*FString::Printf(TEXT("Content-Disposition: form-data; name=\"%s\"; filename=\"%s\""), Name, *File.GetFilename()));
|
||||
AppendString(Newline);
|
||||
AppendString(*FString::Printf(TEXT("Content-Type: %s"), *File.GetContentType()));
|
||||
AppendString(Newline);
|
||||
|
||||
// Add header to body splitter
|
||||
AppendString(Newline);
|
||||
|
||||
// Add Data
|
||||
FormData.Append(FileContents);
|
||||
AppendString(Newline);
|
||||
}
|
||||
|
||||
void HttpMultipartFormData::AppendString(const TCHAR* Str)
|
||||
{
|
||||
FTCHARToUTF8 utf8Str(Str);
|
||||
FormData.Append((uint8*)utf8Str.Get(), utf8Str.Length());
|
||||
}
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
}
|
||||
{{/cppNamespaceDeclarations}}
|
||||
@@ -1,11 +0,0 @@
|
||||
/**
|
||||
* {{{appName}}}
|
||||
* {{{appDescription}}}
|
||||
*
|
||||
* {{#version}}OpenAPI spec version: {{{version}}}{{/version}}
|
||||
* {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@@ -1,59 +0,0 @@
|
||||
{{>licenseInfo}}
|
||||
#pragma once
|
||||
|
||||
#include "Interfaces/IHttpRequest.h"
|
||||
#include "Interfaces/IHttpResponse.h"
|
||||
#include "Serialization/JsonWriter.h"
|
||||
#include "Dom/JsonObject.h"
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}}
|
||||
{
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
||||
typedef TSharedRef<TJsonWriter<>> JsonWriter;
|
||||
|
||||
class {{dllapi}} Model
|
||||
{
|
||||
public:
|
||||
virtual ~Model() {}
|
||||
virtual void WriteJson(JsonWriter& Writer) const = 0;
|
||||
virtual bool FromJson(const TSharedPtr<FJsonObject>& JsonObject) = 0;
|
||||
};
|
||||
|
||||
class {{dllapi}} Request
|
||||
{
|
||||
public:
|
||||
virtual ~Request() {}
|
||||
virtual void SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const = 0;
|
||||
virtual FString ComputePath() const = 0;
|
||||
};
|
||||
|
||||
class {{dllapi}} Response
|
||||
{
|
||||
public:
|
||||
virtual ~Response() {}
|
||||
virtual bool FromJson(const TSharedPtr<FJsonValue>& JsonObject) = 0;
|
||||
|
||||
void SetSuccessful(bool InSuccessful) { Successful = InSuccessful; }
|
||||
bool IsSuccessful() const { return Successful; }
|
||||
|
||||
virtual void SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode);
|
||||
EHttpResponseCodes::Type GetHttpResponseCode() const { return ResponseCode; }
|
||||
|
||||
void SetResponseString(const FString& InResponseString) { ResponseString = InResponseString; }
|
||||
const FString& GetResponseString() const { return ResponseString; }
|
||||
|
||||
void SetHttpResponse(const FHttpResponsePtr& InHttpResponse) { HttpResponse = InHttpResponse; }
|
||||
const FHttpResponsePtr& GetHttpResponse() const { return HttpResponse; }
|
||||
|
||||
private:
|
||||
bool Successful;
|
||||
EHttpResponseCodes::Type ResponseCode;
|
||||
FString ResponseString;
|
||||
FHttpResponsePtr HttpResponse;
|
||||
};
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
}
|
||||
{{/cppNamespaceDeclarations}}
|
||||
@@ -1,21 +0,0 @@
|
||||
{{>licenseInfo}}
|
||||
#include "{{modelNamePrefix}}BaseModel.h"
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}}
|
||||
{
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
||||
void Response::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
ResponseCode = InHttpResponseCode;
|
||||
SetSuccessful(EHttpResponseCodes::IsOk(InHttpResponseCode));
|
||||
if(InHttpResponseCode == EHttpResponseCodes::RequestTimeout)
|
||||
{
|
||||
SetResponseString(TEXT("Request Timeout"));
|
||||
}
|
||||
}
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
}
|
||||
{{/cppNamespaceDeclarations}}
|
||||
@@ -1,51 +0,0 @@
|
||||
{{>licenseInfo}}
|
||||
#pragma once
|
||||
|
||||
#include "{{modelNamePrefix}}BaseModel.h"
|
||||
{{#imports}}{{{import}}}
|
||||
{{/imports}}
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}}
|
||||
{
|
||||
{{/cppNamespaceDeclarations}}
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
|
||||
/*
|
||||
* {{classname}}
|
||||
*
|
||||
* {{description}}
|
||||
*/
|
||||
class {{dllapi}} {{classname}} : public Model
|
||||
{
|
||||
public:
|
||||
virtual ~{{classname}}() {}
|
||||
bool FromJson(const TSharedPtr<FJsonObject>& JsonObject) final;
|
||||
void WriteJson(JsonWriter& Writer) const final;
|
||||
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
{{#allowableValues}}
|
||||
enum class {{{enumName}}}
|
||||
{
|
||||
{{#enumVars}}
|
||||
{{name}},
|
||||
{{/enumVars}}
|
||||
};
|
||||
{{/allowableValues}}
|
||||
{{#description}}/* {{{description}}} */
|
||||
{{/description}}{{^required}}TOptional<{{/required}}{{{datatypeWithEnum}}}{{^required}}>{{/required}} {{name}}{{#required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{/required}};
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{#description}}/* {{{description}}} */
|
||||
{{/description}}{{^required}}TOptional<{{/required}}{{{datatype}}}{{^required}}>{{/required}} {{name}}{{#required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{/required}};
|
||||
{{/isEnum}}
|
||||
{{/vars}}
|
||||
};
|
||||
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
{{#cppNamespaceDeclarations}}
|
||||
}
|
||||
{{/cppNamespaceDeclarations}}
|
||||
@@ -1,98 +0,0 @@
|
||||
{{>licenseInfo}}
|
||||
#include "{{classname}}.h"
|
||||
|
||||
#include "{{unrealModuleName}}Module.h"
|
||||
#include "{{modelNamePrefix}}Helpers.h"
|
||||
|
||||
#include "Templates/SharedPointer.h"
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}}
|
||||
{
|
||||
{{/cppNamespaceDeclarations}}
|
||||
{{#models}}{{#model}}
|
||||
{{#hasEnums}}
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
inline FString ToString(const {{classname}}::{{{enumName}}}& Value)
|
||||
{
|
||||
{{#allowableValues}}
|
||||
switch (Value)
|
||||
{
|
||||
{{#enumVars}}
|
||||
case {{classname}}::{{{enumName}}}::{{name}}:
|
||||
return TEXT({{{value}}});
|
||||
{{/enumVars}}
|
||||
}
|
||||
{{/allowableValues}}
|
||||
|
||||
UE_LOG(Log{{unrealModuleName}}, Error, TEXT("Invalid {{classname}}::{{{enumName}}} Value (%d)"), (int)Value);
|
||||
return TEXT("");
|
||||
}
|
||||
|
||||
inline FStringFormatArg ToStringFormatArg(const {{classname}}::{{{enumName}}}& Value)
|
||||
{
|
||||
return FStringFormatArg(ToString(Value));
|
||||
}
|
||||
|
||||
inline void WriteJsonValue(JsonWriter& Writer, const {{classname}}::{{{enumName}}}& Value)
|
||||
{
|
||||
WriteJsonValue(Writer, ToString(Value));
|
||||
}
|
||||
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, {{classname}}::{{{enumName}}}& Value)
|
||||
{
|
||||
FString TmpValue;
|
||||
if (JsonValue->TryGetString(TmpValue))
|
||||
{
|
||||
static TMap<FString, {{classname}}::{{{enumName}}}> StringToEnum = { {{#enumVars}}
|
||||
{ TEXT({{{value}}}), {{classname}}::{{{enumName}}}::{{name}} },{{/enumVars}} };
|
||||
|
||||
const auto Found = StringToEnum.Find(TmpValue);
|
||||
if(Found)
|
||||
{
|
||||
Value = *Found;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
{{/isEnum}}
|
||||
{{/vars}}
|
||||
{{/hasEnums}}
|
||||
void {{classname}}::WriteJson(JsonWriter& Writer) const
|
||||
{
|
||||
{{#parent}}
|
||||
#error inheritance not handled right now
|
||||
{{/parent}}
|
||||
Writer->WriteObjectStart();
|
||||
{{#vars}}
|
||||
{{#required}}
|
||||
Writer->WriteIdentifierPrefix(TEXT("{{baseName}}")); WriteJsonValue(Writer, {{name}});
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
if ({{name}}.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("{{baseName}}")); WriteJsonValue(Writer, {{name}}.GetValue());
|
||||
}
|
||||
{{/required}}
|
||||
{{/vars}}
|
||||
Writer->WriteObjectEnd();
|
||||
}
|
||||
|
||||
bool {{classname}}::FromJson(const TSharedPtr<FJsonObject>& JsonObject)
|
||||
{
|
||||
bool ParseSuccess = true;
|
||||
|
||||
{{#vars}}
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("{{baseName}}"), {{name}});
|
||||
{{/vars}}
|
||||
|
||||
return ParseSuccess;
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
{{#cppNamespaceDeclarations}}
|
||||
}
|
||||
{{/cppNamespaceDeclarations}}
|
||||
@@ -1,15 +0,0 @@
|
||||
{{>licenseInfo}}
|
||||
#pragma once
|
||||
|
||||
#include "Modules/ModuleInterface.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
#include "Logging/LogMacros.h"
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(Log{{unrealModuleName}}, Log, All);
|
||||
|
||||
class {{dllapi}} {{unrealModuleName}}Module : public IModuleInterface
|
||||
{
|
||||
public:
|
||||
void StartupModule() final;
|
||||
void ShutdownModule() final;
|
||||
};
|
||||
@@ -1,14 +0,0 @@
|
||||
{{>licenseInfo}}
|
||||
#include "{{unrealModuleName}}Module.h"
|
||||
|
||||
IMPLEMENT_MODULE({{unrealModuleName}}Module, {{unrealModuleName}});
|
||||
DEFINE_LOG_CATEGORY(Log{{unrealModuleName}});
|
||||
|
||||
void {{unrealModuleName}}Module::StartupModule()
|
||||
{
|
||||
}
|
||||
|
||||
void {{unrealModuleName}}Module::ShutdownModule()
|
||||
{
|
||||
}
|
||||
|
||||
27
modules/openapi-generator/src/main/resources/nodejs/README.mustache
vendored
Normal file
27
modules/openapi-generator/src/main/resources/nodejs/README.mustache
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
# OpenAPI generated server
|
||||
|
||||
## Overview
|
||||
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub.
|
||||
|
||||
{{^googleCloudFunctions}}
|
||||
### Running the server
|
||||
To run the server, run:
|
||||
|
||||
```
|
||||
npm start
|
||||
```
|
||||
|
||||
To view the Swagger UI interface:
|
||||
|
||||
```
|
||||
open http://localhost:{{serverPort}}/docs
|
||||
```
|
||||
{{/googleCloudFunctions}}
|
||||
{{#googleCloudFunctions}}
|
||||
### Deploying the function
|
||||
To deploy this module into Google Cloud Functions, you will have to use Google Cloud SDK commandline tool.
|
||||
|
||||
See [Google Cloud Functions quick start guide](https://cloud.google.com/functions/docs/quickstart) and [Deploying Cloud Functions](https://cloud.google.com/functions/docs/deploying/) for the details.
|
||||
{{/googleCloudFunctions}}
|
||||
|
||||
This project leverages the mega-awesome [swagger-tools](https://github.com/apigee-127/swagger-tools) middleware which does most all the work.
|
||||
21
modules/openapi-generator/src/main/resources/nodejs/controller.mustache
vendored
Normal file
21
modules/openapi-generator/src/main/resources/nodejs/controller.mustache
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('../utils/writer.js');
|
||||
{{#operations}}
|
||||
var {{classname}} = require('../{{implFolder}}/{{classname}}Service');
|
||||
{{#operation}}
|
||||
|
||||
module.exports.{{nickname}} = function {{nickname}} (req, res, next) {
|
||||
{{#allParams}}
|
||||
var {{paramName}} = req.swagger.params['{{baseName}}'].value;
|
||||
{{/allParams}}
|
||||
{{classname}}.{{nickname}}({{#allParams}}{{paramName}}{{#hasMore}},{{/hasMore}}{{/allParams}})
|
||||
.then(function (response) {
|
||||
utils.writeJson(res, response);
|
||||
})
|
||||
.catch(function (response) {
|
||||
utils.writeJson(res, response);
|
||||
});
|
||||
};
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
44
modules/openapi-generator/src/main/resources/nodejs/index-gcf.mustache
vendored
Normal file
44
modules/openapi-generator/src/main/resources/nodejs/index-gcf.mustache
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
var swaggerTools = require('swagger-tools');
|
||||
var jsyaml = require('js-yaml');
|
||||
var fs = require('fs');
|
||||
|
||||
// swaggerRouter configuration
|
||||
var options = {
|
||||
controllers: './controllers',
|
||||
useStubs: false
|
||||
};
|
||||
|
||||
// The Swagger document (require it, build it programmatically, fetch it from a URL, ...)
|
||||
var spec = fs.readFileSync('./api/openapi.yaml', 'utf8');
|
||||
var swaggerDoc = jsyaml.safeLoad(spec);
|
||||
|
||||
function toPromise(f, req, res) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
f(req, res, function(err) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.{{exportedName}} = function(req, res) {
|
||||
swaggerTools.initializeMiddleware(swaggerDoc, function(middleware) {
|
||||
var metadata = middleware.swaggerMetadata();
|
||||
var validator = middleware.swaggerValidator();
|
||||
var router = middleware.swaggerRouter(options);
|
||||
req.url = swaggerDoc.basePath + req.url;
|
||||
toPromise(metadata, req, res).then(function() {
|
||||
return toPromise(validator, req, res);
|
||||
}).then(function() {
|
||||
return toPromise(router, req, res);
|
||||
}).catch(function(err) {
|
||||
console.error(err);
|
||||
res.status(res.statusCode || 400).send(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
44
modules/openapi-generator/src/main/resources/nodejs/index.mustache
vendored
Normal file
44
modules/openapi-generator/src/main/resources/nodejs/index.mustache
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
http = require('http');
|
||||
|
||||
var app = require('connect')();
|
||||
var swaggerTools = require('swagger-tools');
|
||||
var jsyaml = require('js-yaml');
|
||||
var serverPort = {{serverPort}};
|
||||
|
||||
// swaggerRouter configuration
|
||||
var options = {
|
||||
swaggerUi: path.join(__dirname, '/openapi.json'),
|
||||
controllers: path.join(__dirname, './controllers'),
|
||||
useStubs: process.env.NODE_ENV === 'development' // Conditionally turn on stubs (mock mode)
|
||||
};
|
||||
|
||||
// The Swagger document (require it, build it programmatically, fetch it from a URL, ...)
|
||||
var spec = fs.readFileSync(path.join(__dirname,'api/openapi.yaml'), 'utf8');
|
||||
var swaggerDoc = jsyaml.safeLoad(spec);
|
||||
|
||||
// Initialize the Swagger middleware
|
||||
swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
|
||||
|
||||
// Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain
|
||||
app.use(middleware.swaggerMetadata());
|
||||
|
||||
// Validate Swagger requests
|
||||
app.use(middleware.swaggerValidator());
|
||||
|
||||
// Route validated requests to appropriate controller
|
||||
app.use(middleware.swaggerRouter(options));
|
||||
|
||||
// Serve the Swagger documents and Swagger UI
|
||||
app.use(middleware.swaggerUi());
|
||||
|
||||
// Start the server
|
||||
http.createServer(app).listen(serverPort, function () {
|
||||
console.log('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort);
|
||||
console.log('Swagger-ui is available on http://localhost:%d/docs', serverPort);
|
||||
});
|
||||
|
||||
});
|
||||
1
modules/openapi-generator/src/main/resources/nodejs/openapi.mustache
vendored
Normal file
1
modules/openapi-generator/src/main/resources/nodejs/openapi.mustache
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{{{openapi-yaml}}}
|
||||
24
modules/openapi-generator/src/main/resources/nodejs/package.mustache
vendored
Normal file
24
modules/openapi-generator/src/main/resources/nodejs/package.mustache
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "{{projectName}}",
|
||||
"version": "{{appVersion}}",
|
||||
"description": "{{{appDescription}}}",
|
||||
"main": "index.js",
|
||||
{{^googleCloudFunctions}}
|
||||
"scripts": {
|
||||
"prestart": "npm install",
|
||||
"start": "node index.js"
|
||||
},
|
||||
{{/googleCloudFunctions}}
|
||||
"keywords": [
|
||||
"openapi-tools"
|
||||
],
|
||||
"license": "Unlicense",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
{{^googleCloudFunctions}}
|
||||
"connect": "^3.2.0",
|
||||
{{/googleCloudFunctions}}
|
||||
"js-yaml": "^3.3.0",
|
||||
"swagger-tools": "0.10.1"
|
||||
}
|
||||
}
|
||||
44
modules/openapi-generator/src/main/resources/nodejs/service.mustache
vendored
Normal file
44
modules/openapi-generator/src/main/resources/nodejs/service.mustache
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
|
||||
/**
|
||||
{{#summary}}
|
||||
* {{{summary}}}
|
||||
{{/summary}}
|
||||
{{#notes}}
|
||||
* {{{notes}}}
|
||||
{{/notes}}
|
||||
*
|
||||
{{#allParams}}
|
||||
* {{paramName}} {{{dataType}}} {{{description}}}{{^required}} (optional){{/required}}
|
||||
{{/allParams}}
|
||||
{{^returnType}}
|
||||
* no response value expected for this operation
|
||||
{{/returnType}}
|
||||
{{#returnType}}
|
||||
* returns {{{returnType}}}
|
||||
{{/returnType}}
|
||||
**/
|
||||
exports.{{{operationId}}} = function({{#allParams}}{{paramName}}{{#hasMore}},{{/hasMore}}{{/allParams}}) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
{{#returnType}}
|
||||
var examples = {};
|
||||
{{#examples}}
|
||||
examples['{{contentType}}'] = {{{example}}};
|
||||
{{/examples}}
|
||||
if (Object.keys(examples).length > 0) {
|
||||
resolve(examples[Object.keys(examples)[0]]);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
{{/returnType}}
|
||||
{{^returnType}}
|
||||
resolve();
|
||||
{{/returnType}}
|
||||
});
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
43
modules/openapi-generator/src/main/resources/nodejs/writer.mustache
vendored
Normal file
43
modules/openapi-generator/src/main/resources/nodejs/writer.mustache
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
var ResponsePayload = function(code, payload) {
|
||||
this.code = code;
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
exports.respondWithCode = function(code, payload) {
|
||||
return new ResponsePayload(code, payload);
|
||||
}
|
||||
|
||||
var writeJson = exports.writeJson = function(response, arg1, arg2) {
|
||||
var code;
|
||||
var payload;
|
||||
|
||||
if(arg1 && arg1 instanceof ResponsePayload) {
|
||||
writeJson(response, arg1.payload, arg1.code);
|
||||
return;
|
||||
}
|
||||
|
||||
if(arg2 && Number.isInteger(arg2)) {
|
||||
code = arg2;
|
||||
}
|
||||
else {
|
||||
if(arg1 && Number.isInteger(arg1)) {
|
||||
code = arg1;
|
||||
}
|
||||
}
|
||||
if(code && arg1) {
|
||||
payload = arg1;
|
||||
}
|
||||
else if(arg1) {
|
||||
payload = arg1;
|
||||
}
|
||||
|
||||
if(!code) {
|
||||
// if no response code given, we default to 200
|
||||
code = 200;
|
||||
}
|
||||
if(typeof payload === 'object') {
|
||||
payload = JSON.stringify(payload, null, 2);
|
||||
}
|
||||
response.writeHead(code, {'Content-Type': 'application/json'});
|
||||
response.end(payload);
|
||||
}
|
||||
@@ -27,17 +27,6 @@ function ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{classname}}} {
|
||||
$matchType = $null
|
||||
$matchInstance = $null
|
||||
|
||||
{{#isNullable}}
|
||||
# nullalble check
|
||||
if ([string]::IsNullOrEmpty($Json) -or $Json -eq "{}") {
|
||||
return [PSCustomObject]@{
|
||||
"ActualType" = $null
|
||||
"ActualInstance" = $null
|
||||
"AnyOfSchemas" = @({{#anyOf}}"{{{.}}}"{{^-last}}, {{/-last}}{{/anyOf}})
|
||||
}
|
||||
}
|
||||
|
||||
{{/isNullable}}
|
||||
{{#anyOf}}
|
||||
if ($match -ne 0) { # no match yet
|
||||
# try to match {{{.}}} defined in the anyOf schemas
|
||||
|
||||
@@ -27,17 +27,6 @@ function ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{classname}}} {
|
||||
$matchType = $null
|
||||
$matchInstance = $null
|
||||
|
||||
{{#isNullable}}
|
||||
# nullalble check
|
||||
if ([string]::IsNullOrEmpty($Json) -or $Json -eq "{}") {
|
||||
return [PSCustomObject]@{
|
||||
"ActualType" = $null
|
||||
"ActualInstance" = $null
|
||||
"OneOfSchemas" = @({{#oneOf}}"{{{.}}}"{{^-last}}, {{/-last}}{{/oneOf}})
|
||||
}
|
||||
}
|
||||
|
||||
{{/isNullable}}
|
||||
{{#oneOf}}
|
||||
# try to match {{{.}}} defined in the oneOf schemas
|
||||
try {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
required_properties = set([
|
||||
'_data_store',
|
||||
'_check_type',
|
||||
'_spec_property_naming',
|
||||
'_from_server',
|
||||
'_path_to_item',
|
||||
'_configuration',
|
||||
'_visited_composed_classes',
|
||||
@@ -15,7 +15,7 @@
|
||||
constant_args = {
|
||||
'_check_type': _check_type,
|
||||
'_path_to_item': _path_to_item,
|
||||
'_spec_property_naming': _spec_property_naming,
|
||||
'_from_server': _from_server,
|
||||
'_configuration': _configuration,
|
||||
'_visited_composed_classes': self._visited_composed_classes,
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
required_properties = set([
|
||||
'_data_store',
|
||||
'_check_type',
|
||||
'_spec_property_naming',
|
||||
'_from_server',
|
||||
'_path_to_item',
|
||||
'_configuration',
|
||||
'_visited_composed_classes',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@convert_js_args_to_python_args
|
||||
def __init__(self{{#requiredVars}}{{^defaultValue}}, {{name}}{{/defaultValue}}{{/requiredVars}}{{#requiredVars}}{{#defaultValue}}, {{name}}={{{defaultValue}}}{{/defaultValue}}{{/requiredVars}}, _check_type=True, _spec_property_naming=False, _path_to_item=(), _configuration=None, _visited_composed_classes=(), **kwargs): # noqa: E501
|
||||
def __init__(self{{#requiredVars}}{{^defaultValue}}, {{name}}{{/defaultValue}}{{/requiredVars}}{{#requiredVars}}{{#defaultValue}}, {{name}}={{{defaultValue}}}{{/defaultValue}}{{/requiredVars}}, _check_type=True, _from_server=False, _path_to_item=(), _configuration=None, _visited_composed_classes=(), **kwargs): # noqa: E501
|
||||
"""{{classname}} - a model defined in OpenAPI
|
||||
|
||||
{{#requiredVars}}
|
||||
@@ -26,10 +26,8 @@
|
||||
_path_to_item (tuple/list): This is a list of keys or values to
|
||||
drill down to the model in received_data
|
||||
when deserializing a response
|
||||
_spec_property_naming (bool): True if the variable names in the input data
|
||||
are serialized names, as specified in the OpenAPI document.
|
||||
False if the variable names in the input data
|
||||
are pythonic names, e.g. snake case (default)
|
||||
_from_server (bool): True if the data is from the server
|
||||
False if the data is from the client (default)
|
||||
_configuration (Configuration): the instance to use when
|
||||
deserializing a file_type parameter.
|
||||
If passed, type conversion is attempted
|
||||
@@ -56,7 +54,7 @@
|
||||
|
||||
self._data_store = {}
|
||||
self._check_type = _check_type
|
||||
self._spec_property_naming = _spec_property_naming
|
||||
self._from_server = _from_server
|
||||
self._path_to_item = _path_to_item
|
||||
self._configuration = _configuration
|
||||
self._visited_composed_classes = _visited_composed_classes + (self.__class__,)
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
if self._check_type:
|
||||
value = validate_and_convert_types(
|
||||
value, required_types_mixed, path_to_item, self._spec_property_naming,
|
||||
value, required_types_mixed, path_to_item, self._from_server,
|
||||
self._check_type, configuration=self._configuration)
|
||||
if (name,) in self.allowed_values:
|
||||
check_allowed_values(
|
||||
|
||||
@@ -564,17 +564,15 @@ def order_response_types(required_types):
|
||||
return sorted_types
|
||||
|
||||
|
||||
def remove_uncoercible(required_types_classes, current_item, spec_property_naming,
|
||||
def remove_uncoercible(required_types_classes, current_item, from_server,
|
||||
must_convert=True):
|
||||
"""Only keeps the type conversions that are possible
|
||||
|
||||
Args:
|
||||
required_types_classes (tuple): tuple of classes that are required
|
||||
these should be ordered by COERCION_INDEX_BY_TYPE
|
||||
spec_property_naming (bool): True if the variable names in the input
|
||||
data are serialized names as specified in the OpenAPI document.
|
||||
False if the variables names in the input data are python
|
||||
variable names in PEP-8 snake case.
|
||||
from_server (bool): a boolean of whether the data is from the server
|
||||
if false, the data is from the client
|
||||
current_item (any): the current item (input data) to be converted
|
||||
|
||||
Keyword Args:
|
||||
@@ -604,7 +602,7 @@ def remove_uncoercible(required_types_classes, current_item, spec_property_namin
|
||||
continue
|
||||
|
||||
class_pair = (current_type_simple, required_type_class_simplified)
|
||||
if must_convert and class_pair in COERCIBLE_TYPE_PAIRS[spec_property_naming]:
|
||||
if must_convert and class_pair in COERCIBLE_TYPE_PAIRS[from_server]:
|
||||
results_classes.append(required_type_class)
|
||||
elif class_pair in UPCONVERSION_TYPE_PAIRS:
|
||||
results_classes.append(required_type_class)
|
||||
@@ -727,14 +725,14 @@ def deserialize_primitive(data, klass, path_to_item):
|
||||
# '7' -> 7.0 -> '7.0' != '7'
|
||||
raise ValueError('This is not a float')
|
||||
return converted_value
|
||||
except (OverflowError, ValueError) as ex:
|
||||
except (OverflowError, ValueError):
|
||||
# parse can raise OverflowError
|
||||
six.raise_from(ApiValueError(
|
||||
raise ApiValueError(
|
||||
"{0}Failed to parse {1} as {2}".format(
|
||||
additional_message, repr(data), get_py3_class_name(klass)
|
||||
),
|
||||
path_to_item=path_to_item
|
||||
), ex)
|
||||
)
|
||||
|
||||
|
||||
def get_discriminator_class(model_class,
|
||||
@@ -779,7 +777,7 @@ def get_discriminator_class(model_class,
|
||||
model_class._composed_schemas.get('allOf', ())
|
||||
for cls in composed_children:
|
||||
# Check if the schema has inherited discriminators.
|
||||
if hasattr(cls, 'discriminator') and cls.discriminator is not None:
|
||||
if cls.discriminator is not None:
|
||||
used_model_class = get_discriminator_class(
|
||||
cls, discr_name, discr_value, cls_visited)
|
||||
if used_model_class is not None:
|
||||
@@ -788,7 +786,7 @@ def get_discriminator_class(model_class,
|
||||
|
||||
|
||||
def deserialize_model(model_data, model_class, path_to_item, check_type,
|
||||
configuration, spec_property_naming):
|
||||
configuration, from_server):
|
||||
"""Deserializes model_data to model instance.
|
||||
|
||||
Args:
|
||||
@@ -798,10 +796,8 @@ def deserialize_model(model_data, model_class, path_to_item, check_type,
|
||||
check_type (bool): whether to check the data tupe for the values in
|
||||
the model
|
||||
configuration (Configuration): the instance to use to convert files
|
||||
spec_property_naming (bool): True if the variable names in the input
|
||||
data are serialized names as specified in the OpenAPI document.
|
||||
False if the variables names in the input data are python
|
||||
variable names in PEP-8 snake case.
|
||||
from_server (bool): True if the data is from the server
|
||||
False if the data is from the client
|
||||
|
||||
Returns:
|
||||
model instance
|
||||
@@ -815,7 +811,7 @@ def deserialize_model(model_data, model_class, path_to_item, check_type,
|
||||
kw_args = dict(_check_type=check_type,
|
||||
_path_to_item=path_to_item,
|
||||
_configuration=configuration,
|
||||
_spec_property_naming=spec_property_naming)
|
||||
_from_server=from_server)
|
||||
|
||||
if issubclass(model_class, ModelSimple):
|
||||
instance = model_class(value=model_data, **kw_args)
|
||||
@@ -866,7 +862,7 @@ def deserialize_file(response_data, configuration, content_disposition=None):
|
||||
|
||||
|
||||
def attempt_convert_item(input_value, valid_classes, path_to_item,
|
||||
configuration, spec_property_naming, key_type=False,
|
||||
configuration, from_server, key_type=False,
|
||||
must_convert=False, check_type=True):
|
||||
"""
|
||||
Args:
|
||||
@@ -874,10 +870,8 @@ def attempt_convert_item(input_value, valid_classes, path_to_item,
|
||||
valid_classes (any): the classes that are valid
|
||||
path_to_item (list): the path to the item to convert
|
||||
configuration (Configuration): the instance to use to convert files
|
||||
spec_property_naming (bool): True if the variable names in the input
|
||||
data are serialized names as specified in the OpenAPI document.
|
||||
False if the variables names in the input data are python
|
||||
variable names in PEP-8 snake case.
|
||||
from_server (bool): True if data is from the server, False is data is
|
||||
from the client
|
||||
key_type (bool): if True we need to convert a key type (not supported)
|
||||
must_convert (bool): if True we must convert
|
||||
check_type (bool): if True we check the type or the returned data in
|
||||
@@ -893,7 +887,7 @@ def attempt_convert_item(input_value, valid_classes, path_to_item,
|
||||
"""
|
||||
valid_classes_ordered = order_response_types(valid_classes)
|
||||
valid_classes_coercible = remove_uncoercible(
|
||||
valid_classes_ordered, input_value, spec_property_naming)
|
||||
valid_classes_ordered, input_value, from_server)
|
||||
if not valid_classes_coercible or key_type:
|
||||
# we do not handle keytype errors, json will take care
|
||||
# of this for us
|
||||
@@ -905,7 +899,7 @@ def attempt_convert_item(input_value, valid_classes, path_to_item,
|
||||
if issubclass(valid_class, OpenApiModel):
|
||||
return deserialize_model(input_value, valid_class,
|
||||
path_to_item, check_type,
|
||||
configuration, spec_property_naming)
|
||||
configuration, from_server)
|
||||
elif valid_class == file_type:
|
||||
return deserialize_file(input_value, configuration)
|
||||
return deserialize_primitive(input_value, valid_class,
|
||||
@@ -977,7 +971,7 @@ def is_valid_type(input_class_simple, valid_classes):
|
||||
|
||||
|
||||
def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
|
||||
spec_property_naming, _check_type, configuration=None):
|
||||
from_server, _check_type, configuration=None):
|
||||
"""Raises a TypeError is there is a problem, otherwise returns value
|
||||
|
||||
Args:
|
||||
@@ -988,10 +982,8 @@ def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
|
||||
path_to_item: (list) the path to the data being validated
|
||||
this stores a list of keys or indices to get to the data being
|
||||
validated
|
||||
spec_property_naming (bool): True if the variable names in the input
|
||||
data are serialized names as specified in the OpenAPI document.
|
||||
False if the variables names in the input data are python
|
||||
variable names in PEP-8 snake case.
|
||||
from_server (bool): True if data is from the server
|
||||
False if data is from the client
|
||||
_check_type: (boolean) if true, type will be checked and conversion
|
||||
will be attempted.
|
||||
configuration: (Configuration): the configuration class to use
|
||||
@@ -1019,7 +1011,7 @@ def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
|
||||
valid_classes,
|
||||
path_to_item,
|
||||
configuration,
|
||||
spec_property_naming,
|
||||
from_server,
|
||||
key_type=False,
|
||||
must_convert=True
|
||||
)
|
||||
@@ -1032,14 +1024,14 @@ def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
|
||||
if len(valid_classes) > 1 and configuration:
|
||||
# there are valid classes which are not the current class
|
||||
valid_classes_coercible = remove_uncoercible(
|
||||
valid_classes, input_value, spec_property_naming, must_convert=False)
|
||||
valid_classes, input_value, from_server, must_convert=False)
|
||||
if valid_classes_coercible:
|
||||
converted_instance = attempt_convert_item(
|
||||
input_value,
|
||||
valid_classes_coercible,
|
||||
path_to_item,
|
||||
configuration,
|
||||
spec_property_naming,
|
||||
from_server,
|
||||
key_type=False,
|
||||
must_convert=False
|
||||
)
|
||||
@@ -1066,7 +1058,7 @@ def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
|
||||
inner_value,
|
||||
inner_required_types,
|
||||
inner_path,
|
||||
spec_property_naming,
|
||||
from_server,
|
||||
_check_type,
|
||||
configuration=configuration
|
||||
)
|
||||
@@ -1084,7 +1076,7 @@ def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
|
||||
inner_val,
|
||||
inner_required_types,
|
||||
inner_path,
|
||||
spec_property_naming,
|
||||
from_server,
|
||||
_check_type,
|
||||
configuration=configuration
|
||||
)
|
||||
@@ -1190,8 +1182,8 @@ def convert_js_args_to_python_args(fn):
|
||||
from functools import wraps
|
||||
@wraps(fn)
|
||||
def wrapped_init(self, *args, **kwargs):
|
||||
spec_property_naming = kwargs.get('_spec_property_naming', False)
|
||||
if spec_property_naming:
|
||||
from_server = kwargs.get('_from_server', False)
|
||||
if from_server:
|
||||
kwargs = change_keys_js_to_python(kwargs, self.__class__)
|
||||
return fn(self, *args, **kwargs)
|
||||
return wrapped_init
|
||||
@@ -1228,7 +1220,7 @@ def get_allof_instances(self, model_args, constant_args):
|
||||
allof_instance = allof_class(**kwargs)
|
||||
composed_instances.append(allof_instance)
|
||||
except Exception as ex:
|
||||
six.raise_from(ApiValueError(
|
||||
raise ApiValueError(
|
||||
"Invalid inputs given to generate an instance of '%s'. The "
|
||||
"input data was invalid for the allOf schema '%s' in the composed "
|
||||
"schema '%s'. Error=%s" % (
|
||||
@@ -1237,7 +1229,7 @@ def get_allof_instances(self, model_args, constant_args):
|
||||
self.__class__.__name__,
|
||||
str(ex)
|
||||
)
|
||||
), ex)
|
||||
)
|
||||
return composed_instances
|
||||
|
||||
|
||||
|
||||
@@ -298,6 +298,7 @@ public class SpringCodegenTest {
|
||||
final String multipartMixedApi = files.get("/src/main/java/org/openapitools/api/MultipartMixedApi.java");
|
||||
Assert.assertTrue(multipartMixedApi.contains("MultipartFile file"));
|
||||
Assert.assertTrue(multipartMixedApi.contains("@RequestPart(value = \"file\", required = true)"));
|
||||
System.out.println(multipartMixedApi);
|
||||
Assert.assertTrue(multipartMixedApi.contains("@Valid @RequestPart(value = \"marker\", required = false)"));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
|
||||
|
||||
openapi: 3.0.1
|
||||
info:
|
||||
version: 1.0.0
|
||||
title: Example
|
||||
license:
|
||||
name: MIT
|
||||
servers:
|
||||
- url: http://api.example.xyz/v1
|
||||
paths:
|
||||
/pets:
|
||||
patch:
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/Cat'
|
||||
- $ref: '#/components/schemas/Dog'
|
||||
# This field will not match to any type.
|
||||
- description: Any kind of pet
|
||||
discriminator:
|
||||
propertyName: pet_type
|
||||
responses:
|
||||
'200':
|
||||
description: Updated
|
||||
|
||||
/pets-filtered:
|
||||
patch:
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
anyOf:
|
||||
- $ref: '#/components/schemas/PetByAge'
|
||||
- $ref: '#/components/schemas/PetByType'
|
||||
# This field will not match to any type.
|
||||
- description: Any kind of filter
|
||||
responses:
|
||||
'200':
|
||||
description: Updated
|
||||
|
||||
/file:
|
||||
post:
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
file:
|
||||
allOf:
|
||||
- type: file
|
||||
# This field will not match to any type.
|
||||
- description: The file to upload
|
||||
responses:
|
||||
'200':
|
||||
description: File uploaded
|
||||
|
||||
components:
|
||||
schemas:
|
||||
Pet:
|
||||
type: object
|
||||
required:
|
||||
- pet_type
|
||||
Dog:
|
||||
allOf:
|
||||
# This field will not match to any type.
|
||||
- description: Dog information
|
||||
- $ref: '#/components/schemas/Pet'
|
||||
- type: object
|
||||
properties:
|
||||
bark:
|
||||
type: boolean
|
||||
breed:
|
||||
type: string
|
||||
enum: [Dingo, Husky, Retriever, Shepherd]
|
||||
Cat:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/Pet'
|
||||
- type: object
|
||||
properties:
|
||||
hunts:
|
||||
type: boolean
|
||||
age:
|
||||
type: integer
|
||||
PetByAge:
|
||||
type: object
|
||||
properties:
|
||||
age:
|
||||
type: integer
|
||||
nickname:
|
||||
type: string
|
||||
required:
|
||||
- age
|
||||
|
||||
PetByType:
|
||||
type: object
|
||||
properties:
|
||||
pet_type:
|
||||
type: string
|
||||
enum: [Cat, Dog]
|
||||
hunts:
|
||||
type: boolean
|
||||
required:
|
||||
- pet_type
|
||||
@@ -1,28 +0,0 @@
|
||||
.Rbuildignore
|
||||
.gitignore
|
||||
.travis.yml
|
||||
DESCRIPTION
|
||||
NAMESPACE
|
||||
R/api_client.R
|
||||
R/api_response.R
|
||||
R/category.R
|
||||
R/model_api_response.R
|
||||
R/order.R
|
||||
R/pet.R
|
||||
R/pet_api.R
|
||||
R/store_api.R
|
||||
R/tag.R
|
||||
R/user.R
|
||||
R/user_api.R
|
||||
README.md
|
||||
docs/Category.md
|
||||
docs/ModelApiResponse.md
|
||||
docs/Order.md
|
||||
docs/Pet.md
|
||||
docs/PetApi.md
|
||||
docs/StoreApi.md
|
||||
docs/Tag.md
|
||||
docs/User.md
|
||||
docs/UserApi.md
|
||||
git_push.sh
|
||||
tests/testthat.R
|
||||
@@ -1,30 +0,0 @@
|
||||
README.md
|
||||
config/project-scratch-def.json
|
||||
force-app/main/default/classes/OAS.cls
|
||||
force-app/main/default/classes/OAS.cls-meta.xml
|
||||
force-app/main/default/classes/OASApiResponse.cls
|
||||
force-app/main/default/classes/OASApiResponse.cls-meta.xml
|
||||
force-app/main/default/classes/OASCategory.cls
|
||||
force-app/main/default/classes/OASCategory.cls-meta.xml
|
||||
force-app/main/default/classes/OASClient.cls
|
||||
force-app/main/default/classes/OASClient.cls-meta.xml
|
||||
force-app/main/default/classes/OASOrder.cls
|
||||
force-app/main/default/classes/OASOrder.cls-meta.xml
|
||||
force-app/main/default/classes/OASPet.cls
|
||||
force-app/main/default/classes/OASPet.cls-meta.xml
|
||||
force-app/main/default/classes/OASPetApi.cls
|
||||
force-app/main/default/classes/OASPetApi.cls-meta.xml
|
||||
force-app/main/default/classes/OASResponseMock.cls
|
||||
force-app/main/default/classes/OASResponseMock.cls-meta.xml
|
||||
force-app/main/default/classes/OASStoreApi.cls
|
||||
force-app/main/default/classes/OASStoreApi.cls-meta.xml
|
||||
force-app/main/default/classes/OASTag.cls
|
||||
force-app/main/default/classes/OASTag.cls-meta.xml
|
||||
force-app/main/default/classes/OASTest.cls
|
||||
force-app/main/default/classes/OASTest.cls-meta.xml
|
||||
force-app/main/default/classes/OASUser.cls
|
||||
force-app/main/default/classes/OASUser.cls-meta.xml
|
||||
force-app/main/default/classes/OASUserApi.cls
|
||||
force-app/main/default/classes/OASUserApi.cls-meta.xml
|
||||
force-app/main/default/namedCredentials/OpenAPI_Petstore.namedCredential-meta.xml
|
||||
sfdx-project.json
|
||||
@@ -1 +1 @@
|
||||
5.0.0-SNAPSHOT
|
||||
4.3.1-SNAPSHOT
|
||||
@@ -1,39 +0,0 @@
|
||||
.gitignore
|
||||
ApiClient.cpp
|
||||
ApiClient.h
|
||||
ApiConfiguration.cpp
|
||||
ApiConfiguration.h
|
||||
ApiException.cpp
|
||||
ApiException.h
|
||||
CMakeLists.txt
|
||||
HttpContent.cpp
|
||||
HttpContent.h
|
||||
IHttpBody.h
|
||||
JsonBody.cpp
|
||||
JsonBody.h
|
||||
ModelBase.cpp
|
||||
ModelBase.h
|
||||
MultipartFormData.cpp
|
||||
MultipartFormData.h
|
||||
Object.cpp
|
||||
Object.h
|
||||
README.md
|
||||
api/PetApi.cpp
|
||||
api/PetApi.h
|
||||
api/StoreApi.cpp
|
||||
api/StoreApi.h
|
||||
api/UserApi.cpp
|
||||
api/UserApi.h
|
||||
git_push.sh
|
||||
model/ApiResponse.cpp
|
||||
model/ApiResponse.h
|
||||
model/Category.cpp
|
||||
model/Category.h
|
||||
model/Order.cpp
|
||||
model/Order.h
|
||||
model/Pet.cpp
|
||||
model/Pet.h
|
||||
model/Tag.cpp
|
||||
model/Tag.h
|
||||
model/User.cpp
|
||||
model/User.h
|
||||
@@ -1 +0,0 @@
|
||||
5.0.0-SNAPSHOT
|
||||
@@ -1,30 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnrealBuildTool;
|
||||
|
||||
public class OpenAPI : ModuleRules
|
||||
{
|
||||
public OpenAPI(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PublicDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"Core",
|
||||
"Http",
|
||||
"Json",
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#include "OpenAPIApiResponse.h"
|
||||
|
||||
#include "OpenAPIModule.h"
|
||||
#include "OpenAPIHelpers.h"
|
||||
|
||||
#include "Templates/SharedPointer.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
void OpenAPIApiResponse::WriteJson(JsonWriter& Writer) const
|
||||
{
|
||||
Writer->WriteObjectStart();
|
||||
if (Code.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("code")); WriteJsonValue(Writer, Code.GetValue());
|
||||
}
|
||||
if (Type.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("type")); WriteJsonValue(Writer, Type.GetValue());
|
||||
}
|
||||
if (Message.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("message")); WriteJsonValue(Writer, Message.GetValue());
|
||||
}
|
||||
Writer->WriteObjectEnd();
|
||||
}
|
||||
|
||||
bool OpenAPIApiResponse::FromJson(const TSharedPtr<FJsonObject>& JsonObject)
|
||||
{
|
||||
bool ParseSuccess = true;
|
||||
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("code"), Code);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("type"), Type);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("message"), Message);
|
||||
|
||||
return ParseSuccess;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "OpenAPIBaseModel.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
/*
|
||||
* OpenAPIApiResponse
|
||||
*
|
||||
* Describes the result of uploading an image resource
|
||||
*/
|
||||
class OPENAPI_API OpenAPIApiResponse : public Model
|
||||
{
|
||||
public:
|
||||
virtual ~OpenAPIApiResponse() {}
|
||||
bool FromJson(const TSharedPtr<FJsonObject>& JsonObject) final;
|
||||
void WriteJson(JsonWriter& Writer) const final;
|
||||
|
||||
TOptional<int32> Code;
|
||||
TOptional<FString> Type;
|
||||
TOptional<FString> Message;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#include "OpenAPICategory.h"
|
||||
|
||||
#include "OpenAPIModule.h"
|
||||
#include "OpenAPIHelpers.h"
|
||||
|
||||
#include "Templates/SharedPointer.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
void OpenAPICategory::WriteJson(JsonWriter& Writer) const
|
||||
{
|
||||
Writer->WriteObjectStart();
|
||||
if (Id.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("id")); WriteJsonValue(Writer, Id.GetValue());
|
||||
}
|
||||
if (Name.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("name")); WriteJsonValue(Writer, Name.GetValue());
|
||||
}
|
||||
Writer->WriteObjectEnd();
|
||||
}
|
||||
|
||||
bool OpenAPICategory::FromJson(const TSharedPtr<FJsonObject>& JsonObject)
|
||||
{
|
||||
bool ParseSuccess = true;
|
||||
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("id"), Id);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("name"), Name);
|
||||
|
||||
return ParseSuccess;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "OpenAPIBaseModel.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
/*
|
||||
* OpenAPICategory
|
||||
*
|
||||
* A category for a pet
|
||||
*/
|
||||
class OPENAPI_API OpenAPICategory : public Model
|
||||
{
|
||||
public:
|
||||
virtual ~OpenAPICategory() {}
|
||||
bool FromJson(const TSharedPtr<FJsonObject>& JsonObject) final;
|
||||
void WriteJson(JsonWriter& Writer) const final;
|
||||
|
||||
TOptional<int64> Id;
|
||||
TOptional<FString> Name;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#include "OpenAPIOrder.h"
|
||||
|
||||
#include "OpenAPIModule.h"
|
||||
#include "OpenAPIHelpers.h"
|
||||
|
||||
#include "Templates/SharedPointer.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
inline FString ToString(const OpenAPIOrder::StatusEnum& Value)
|
||||
{
|
||||
switch (Value)
|
||||
{
|
||||
case OpenAPIOrder::StatusEnum::Placed:
|
||||
return TEXT("placed");
|
||||
case OpenAPIOrder::StatusEnum::Approved:
|
||||
return TEXT("approved");
|
||||
case OpenAPIOrder::StatusEnum::Delivered:
|
||||
return TEXT("delivered");
|
||||
}
|
||||
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Invalid OpenAPIOrder::StatusEnum Value (%d)"), (int)Value);
|
||||
return TEXT("");
|
||||
}
|
||||
|
||||
inline FStringFormatArg ToStringFormatArg(const OpenAPIOrder::StatusEnum& Value)
|
||||
{
|
||||
return FStringFormatArg(ToString(Value));
|
||||
}
|
||||
|
||||
inline void WriteJsonValue(JsonWriter& Writer, const OpenAPIOrder::StatusEnum& Value)
|
||||
{
|
||||
WriteJsonValue(Writer, ToString(Value));
|
||||
}
|
||||
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, OpenAPIOrder::StatusEnum& Value)
|
||||
{
|
||||
FString TmpValue;
|
||||
if (JsonValue->TryGetString(TmpValue))
|
||||
{
|
||||
static TMap<FString, OpenAPIOrder::StatusEnum> StringToEnum = { };
|
||||
|
||||
const auto Found = StringToEnum.Find(TmpValue);
|
||||
if(Found)
|
||||
{
|
||||
Value = *Found;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void OpenAPIOrder::WriteJson(JsonWriter& Writer) const
|
||||
{
|
||||
Writer->WriteObjectStart();
|
||||
if (Id.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("id")); WriteJsonValue(Writer, Id.GetValue());
|
||||
}
|
||||
if (PetId.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("petId")); WriteJsonValue(Writer, PetId.GetValue());
|
||||
}
|
||||
if (Quantity.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("quantity")); WriteJsonValue(Writer, Quantity.GetValue());
|
||||
}
|
||||
if (ShipDate.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("shipDate")); WriteJsonValue(Writer, ShipDate.GetValue());
|
||||
}
|
||||
if (Status.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("status")); WriteJsonValue(Writer, Status.GetValue());
|
||||
}
|
||||
if (Complete.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("complete")); WriteJsonValue(Writer, Complete.GetValue());
|
||||
}
|
||||
Writer->WriteObjectEnd();
|
||||
}
|
||||
|
||||
bool OpenAPIOrder::FromJson(const TSharedPtr<FJsonObject>& JsonObject)
|
||||
{
|
||||
bool ParseSuccess = true;
|
||||
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("id"), Id);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("petId"), PetId);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("quantity"), Quantity);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("shipDate"), ShipDate);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("status"), Status);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("complete"), Complete);
|
||||
|
||||
return ParseSuccess;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "OpenAPIBaseModel.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
/*
|
||||
* OpenAPIOrder
|
||||
*
|
||||
* An order for a pets from the pet store
|
||||
*/
|
||||
class OPENAPI_API OpenAPIOrder : public Model
|
||||
{
|
||||
public:
|
||||
virtual ~OpenAPIOrder() {}
|
||||
bool FromJson(const TSharedPtr<FJsonObject>& JsonObject) final;
|
||||
void WriteJson(JsonWriter& Writer) const final;
|
||||
|
||||
TOptional<int64> Id;
|
||||
TOptional<int64> PetId;
|
||||
TOptional<int32> Quantity;
|
||||
TOptional<FDateTime> ShipDate;
|
||||
enum class StatusEnum
|
||||
{
|
||||
Placed,
|
||||
Approved,
|
||||
Delivered,
|
||||
};
|
||||
/* Order Status */
|
||||
TOptional<StatusEnum> Status;
|
||||
TOptional<bool> Complete;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#include "OpenAPIPet.h"
|
||||
|
||||
#include "OpenAPIModule.h"
|
||||
#include "OpenAPIHelpers.h"
|
||||
|
||||
#include "Templates/SharedPointer.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
inline FString ToString(const OpenAPIPet::StatusEnum& Value)
|
||||
{
|
||||
switch (Value)
|
||||
{
|
||||
case OpenAPIPet::StatusEnum::Available:
|
||||
return TEXT("available");
|
||||
case OpenAPIPet::StatusEnum::Pending:
|
||||
return TEXT("pending");
|
||||
case OpenAPIPet::StatusEnum::Sold:
|
||||
return TEXT("sold");
|
||||
}
|
||||
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Invalid OpenAPIPet::StatusEnum Value (%d)"), (int)Value);
|
||||
return TEXT("");
|
||||
}
|
||||
|
||||
inline FStringFormatArg ToStringFormatArg(const OpenAPIPet::StatusEnum& Value)
|
||||
{
|
||||
return FStringFormatArg(ToString(Value));
|
||||
}
|
||||
|
||||
inline void WriteJsonValue(JsonWriter& Writer, const OpenAPIPet::StatusEnum& Value)
|
||||
{
|
||||
WriteJsonValue(Writer, ToString(Value));
|
||||
}
|
||||
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, OpenAPIPet::StatusEnum& Value)
|
||||
{
|
||||
FString TmpValue;
|
||||
if (JsonValue->TryGetString(TmpValue))
|
||||
{
|
||||
static TMap<FString, OpenAPIPet::StatusEnum> StringToEnum = { };
|
||||
|
||||
const auto Found = StringToEnum.Find(TmpValue);
|
||||
if(Found)
|
||||
{
|
||||
Value = *Found;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void OpenAPIPet::WriteJson(JsonWriter& Writer) const
|
||||
{
|
||||
Writer->WriteObjectStart();
|
||||
if (Id.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("id")); WriteJsonValue(Writer, Id.GetValue());
|
||||
}
|
||||
if (Category.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("category")); WriteJsonValue(Writer, Category.GetValue());
|
||||
}
|
||||
Writer->WriteIdentifierPrefix(TEXT("name")); WriteJsonValue(Writer, Name);
|
||||
Writer->WriteIdentifierPrefix(TEXT("photoUrls")); WriteJsonValue(Writer, PhotoUrls);
|
||||
if (Tags.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("tags")); WriteJsonValue(Writer, Tags.GetValue());
|
||||
}
|
||||
if (Status.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("status")); WriteJsonValue(Writer, Status.GetValue());
|
||||
}
|
||||
Writer->WriteObjectEnd();
|
||||
}
|
||||
|
||||
bool OpenAPIPet::FromJson(const TSharedPtr<FJsonObject>& JsonObject)
|
||||
{
|
||||
bool ParseSuccess = true;
|
||||
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("id"), Id);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("category"), Category);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("name"), Name);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("photoUrls"), PhotoUrls);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("tags"), Tags);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("status"), Status);
|
||||
|
||||
return ParseSuccess;
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "OpenAPIBaseModel.h"
|
||||
#include "OpenAPICategory.h"
|
||||
#include "OpenAPITag.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
/*
|
||||
* OpenAPIPet
|
||||
*
|
||||
* A pet for sale in the pet store
|
||||
*/
|
||||
class OPENAPI_API OpenAPIPet : public Model
|
||||
{
|
||||
public:
|
||||
virtual ~OpenAPIPet() {}
|
||||
bool FromJson(const TSharedPtr<FJsonObject>& JsonObject) final;
|
||||
void WriteJson(JsonWriter& Writer) const final;
|
||||
|
||||
TOptional<int64> Id;
|
||||
TOptional<OpenAPICategory> Category;
|
||||
FString Name;
|
||||
TArray<std::shared_ptr<FString>> PhotoUrls;
|
||||
TOptional<TArray<std::shared_ptr<OpenAPIOpenAPITag>>> Tags;
|
||||
enum class StatusEnum
|
||||
{
|
||||
Available,
|
||||
Pending,
|
||||
Sold,
|
||||
};
|
||||
/* pet status in the store */
|
||||
TOptional<StatusEnum> Status;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#include "OpenAPITag.h"
|
||||
|
||||
#include "OpenAPIModule.h"
|
||||
#include "OpenAPIHelpers.h"
|
||||
|
||||
#include "Templates/SharedPointer.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
void OpenAPITag::WriteJson(JsonWriter& Writer) const
|
||||
{
|
||||
Writer->WriteObjectStart();
|
||||
if (Id.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("id")); WriteJsonValue(Writer, Id.GetValue());
|
||||
}
|
||||
if (Name.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("name")); WriteJsonValue(Writer, Name.GetValue());
|
||||
}
|
||||
Writer->WriteObjectEnd();
|
||||
}
|
||||
|
||||
bool OpenAPITag::FromJson(const TSharedPtr<FJsonObject>& JsonObject)
|
||||
{
|
||||
bool ParseSuccess = true;
|
||||
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("id"), Id);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("name"), Name);
|
||||
|
||||
return ParseSuccess;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "OpenAPIBaseModel.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
/*
|
||||
* OpenAPITag
|
||||
*
|
||||
* A tag for a pet
|
||||
*/
|
||||
class OPENAPI_API OpenAPITag : public Model
|
||||
{
|
||||
public:
|
||||
virtual ~OpenAPITag() {}
|
||||
bool FromJson(const TSharedPtr<FJsonObject>& JsonObject) final;
|
||||
void WriteJson(JsonWriter& Writer) const final;
|
||||
|
||||
TOptional<int64> Id;
|
||||
TOptional<FString> Name;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#include "OpenAPIUser.h"
|
||||
|
||||
#include "OpenAPIModule.h"
|
||||
#include "OpenAPIHelpers.h"
|
||||
|
||||
#include "Templates/SharedPointer.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
void OpenAPIUser::WriteJson(JsonWriter& Writer) const
|
||||
{
|
||||
Writer->WriteObjectStart();
|
||||
if (Id.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("id")); WriteJsonValue(Writer, Id.GetValue());
|
||||
}
|
||||
if (Username.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("username")); WriteJsonValue(Writer, Username.GetValue());
|
||||
}
|
||||
if (FirstName.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("firstName")); WriteJsonValue(Writer, FirstName.GetValue());
|
||||
}
|
||||
if (LastName.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("lastName")); WriteJsonValue(Writer, LastName.GetValue());
|
||||
}
|
||||
if (Email.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("email")); WriteJsonValue(Writer, Email.GetValue());
|
||||
}
|
||||
if (Password.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("password")); WriteJsonValue(Writer, Password.GetValue());
|
||||
}
|
||||
if (Phone.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("phone")); WriteJsonValue(Writer, Phone.GetValue());
|
||||
}
|
||||
if (UserStatus.IsSet())
|
||||
{
|
||||
Writer->WriteIdentifierPrefix(TEXT("userStatus")); WriteJsonValue(Writer, UserStatus.GetValue());
|
||||
}
|
||||
Writer->WriteObjectEnd();
|
||||
}
|
||||
|
||||
bool OpenAPIUser::FromJson(const TSharedPtr<FJsonObject>& JsonObject)
|
||||
{
|
||||
bool ParseSuccess = true;
|
||||
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("id"), Id);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("username"), Username);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("firstName"), FirstName);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("lastName"), LastName);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("email"), Email);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("password"), Password);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("phone"), Phone);
|
||||
ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("userStatus"), UserStatus);
|
||||
|
||||
return ParseSuccess;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "OpenAPIBaseModel.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
/*
|
||||
* OpenAPIUser
|
||||
*
|
||||
* A User who is purchasing from the pet store
|
||||
*/
|
||||
class OPENAPI_API OpenAPIUser : public Model
|
||||
{
|
||||
public:
|
||||
virtual ~OpenAPIUser() {}
|
||||
bool FromJson(const TSharedPtr<FJsonObject>& JsonObject) final;
|
||||
void WriteJson(JsonWriter& Writer) const final;
|
||||
|
||||
TOptional<int64> Id;
|
||||
TOptional<FString> Username;
|
||||
TOptional<FString> FirstName;
|
||||
TOptional<FString> LastName;
|
||||
TOptional<FString> Email;
|
||||
TOptional<FString> Password;
|
||||
TOptional<FString> Phone;
|
||||
/* User Status */
|
||||
TOptional<int32> UserStatus;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#include "OpenAPIBaseModel.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
void Response::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
ResponseCode = InHttpResponseCode;
|
||||
SetSuccessful(EHttpResponseCodes::IsOk(InHttpResponseCode));
|
||||
if(InHttpResponseCode == EHttpResponseCodes::RequestTimeout)
|
||||
{
|
||||
SetResponseString(TEXT("Request Timeout"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,194 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#include "OpenAPIHelpers.h"
|
||||
|
||||
#include "OpenAPIModule.h"
|
||||
|
||||
#include "Interfaces/IHttpRequest.h"
|
||||
#include "PlatformHttp.h"
|
||||
#include "Misc/FileHelper.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
HttpFileInput::HttpFileInput(const TCHAR* InFilePath)
|
||||
{
|
||||
SetFilePath(InFilePath);
|
||||
}
|
||||
|
||||
HttpFileInput::HttpFileInput(const FString& InFilePath)
|
||||
{
|
||||
SetFilePath(InFilePath);
|
||||
}
|
||||
|
||||
void HttpFileInput::SetFilePath(const TCHAR* InFilePath)
|
||||
{
|
||||
FilePath = InFilePath;
|
||||
if(ContentType.IsEmpty())
|
||||
{
|
||||
ContentType = FPlatformHttp::GetMimeType(InFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
void HttpFileInput::SetFilePath(const FString& InFilePath)
|
||||
{
|
||||
SetFilePath(*InFilePath);
|
||||
}
|
||||
|
||||
void HttpFileInput::SetContentType(const TCHAR* InContentType)
|
||||
{
|
||||
ContentType = InContentType;
|
||||
}
|
||||
|
||||
FString HttpFileInput::GetFilename() const
|
||||
{
|
||||
return FPaths::GetCleanFilename(FilePath);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const TCHAR* HttpMultipartFormData::Delimiter = TEXT("--");
|
||||
const TCHAR* HttpMultipartFormData::Newline = TEXT("\r\n");
|
||||
|
||||
void HttpMultipartFormData::SetBoundary(const TCHAR* InBoundary)
|
||||
{
|
||||
checkf(Boundary.IsEmpty(), TEXT("Boundary must be set before usage"));
|
||||
Boundary = InBoundary;
|
||||
}
|
||||
|
||||
const FString& HttpMultipartFormData::GetBoundary() const
|
||||
{
|
||||
if (Boundary.IsEmpty())
|
||||
{
|
||||
// Generate a random boundary with enough entropy, should avoid occurences of the boundary in the data.
|
||||
// Since the boundary is generated at every request, in case of failure, retries should succeed.
|
||||
Boundary = FGuid::NewGuid().ToString(EGuidFormats::Short);
|
||||
}
|
||||
|
||||
return Boundary;
|
||||
}
|
||||
|
||||
void HttpMultipartFormData::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest)
|
||||
{
|
||||
if(HttpRequest->GetVerb() != TEXT("POST"))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Expected POST verb when using multipart form data"));
|
||||
}
|
||||
|
||||
// Append final boundary
|
||||
AppendString(Delimiter);
|
||||
AppendString(*GetBoundary());
|
||||
AppendString(Delimiter);
|
||||
|
||||
HttpRequest->SetHeader("Content-Type", FString::Printf(TEXT("multipart/form-data; boundary=%s"), *GetBoundary()));
|
||||
HttpRequest->SetContent(FormData);
|
||||
}
|
||||
|
||||
void HttpMultipartFormData::AddStringPart(const TCHAR* Name, const TCHAR* Data)
|
||||
{
|
||||
// Add boundary
|
||||
AppendString(Delimiter);
|
||||
AppendString(*GetBoundary());
|
||||
AppendString(Newline);
|
||||
|
||||
// Add header
|
||||
AppendString(*FString::Printf(TEXT("Content-Disposition: form-data; name = \"%s\""), Name));
|
||||
AppendString(Newline);
|
||||
AppendString(*FString::Printf(TEXT("Content-Type: text/plain; charset=utf-8")));
|
||||
AppendString(Newline);
|
||||
|
||||
// Add header to body splitter
|
||||
AppendString(Newline);
|
||||
|
||||
// Add Data
|
||||
AppendString(Data);
|
||||
AppendString(Newline);
|
||||
}
|
||||
|
||||
void HttpMultipartFormData::AddJsonPart(const TCHAR* Name, const FString& JsonString)
|
||||
{
|
||||
// Add boundary
|
||||
AppendString(Delimiter);
|
||||
AppendString(*GetBoundary());
|
||||
AppendString(Newline);
|
||||
|
||||
// Add header
|
||||
AppendString(*FString::Printf(TEXT("Content-Disposition: form-data; name=\"%s\""), Name));
|
||||
AppendString(Newline);
|
||||
AppendString(*FString::Printf(TEXT("Content-Type: application/json; charset=utf-8")));
|
||||
AppendString(Newline);
|
||||
|
||||
// Add header to body splitter
|
||||
AppendString(Newline);
|
||||
|
||||
// Add Data
|
||||
AppendString(*JsonString);
|
||||
AppendString(Newline);
|
||||
}
|
||||
|
||||
void HttpMultipartFormData::AddBinaryPart(const TCHAR* Name, const TArray<uint8>& ByteArray)
|
||||
{
|
||||
// Add boundary
|
||||
AppendString(Delimiter);
|
||||
AppendString(*GetBoundary());
|
||||
AppendString(Newline);
|
||||
|
||||
// Add header
|
||||
AppendString(*FString::Printf(TEXT("Content-Disposition: form-data; name=\"%s\""), Name));
|
||||
AppendString(Newline);
|
||||
AppendString(*FString::Printf(TEXT("Content-Type: application/octet-stream")));
|
||||
AppendString(Newline);
|
||||
|
||||
// Add header to body splitter
|
||||
AppendString(Newline);
|
||||
|
||||
// Add Data
|
||||
FormData.Append(ByteArray);
|
||||
AppendString(Newline);
|
||||
}
|
||||
|
||||
void HttpMultipartFormData::AddFilePart(const TCHAR* Name, const HttpFileInput& File)
|
||||
{
|
||||
TArray<uint8> FileContents;
|
||||
if (!FFileHelper::LoadFileToArray(FileContents, *File.GetFilePath()))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Failed to load file (%s)"), *File.GetFilePath());
|
||||
return;
|
||||
}
|
||||
|
||||
// Add boundary
|
||||
AppendString(Delimiter);
|
||||
AppendString(*GetBoundary());
|
||||
AppendString(Newline);
|
||||
|
||||
// Add header
|
||||
AppendString(*FString::Printf(TEXT("Content-Disposition: form-data; name=\"%s\"; filename=\"%s\""), Name, *File.GetFilename()));
|
||||
AppendString(Newline);
|
||||
AppendString(*FString::Printf(TEXT("Content-Type: %s"), *File.GetContentType()));
|
||||
AppendString(Newline);
|
||||
|
||||
// Add header to body splitter
|
||||
AppendString(Newline);
|
||||
|
||||
// Add Data
|
||||
FormData.Append(FileContents);
|
||||
AppendString(Newline);
|
||||
}
|
||||
|
||||
void HttpMultipartFormData::AppendString(const TCHAR* Str)
|
||||
{
|
||||
FTCHARToUTF8 utf8Str(Str);
|
||||
FormData.Append((uint8*)utf8Str.Get(), utf8Str.Length());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#include "OpenAPIModule.h"
|
||||
|
||||
IMPLEMENT_MODULE(OpenAPIModule, OpenAPI);
|
||||
DEFINE_LOG_CATEGORY(LogOpenAPI);
|
||||
|
||||
void OpenAPIModule::StartupModule()
|
||||
{
|
||||
}
|
||||
|
||||
void OpenAPIModule::ShutdownModule()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Modules/ModuleInterface.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
#include "Logging/LogMacros.h"
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(LogOpenAPI, Log, All);
|
||||
|
||||
class OPENAPI_API OpenAPIModule : public IModuleInterface
|
||||
{
|
||||
public:
|
||||
void StartupModule() final;
|
||||
void ShutdownModule() final;
|
||||
};
|
||||
@@ -1,305 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#include "OpenAPIPetApi.h"
|
||||
|
||||
#include "OpenAPIPetApiOperations.h"
|
||||
#include "OpenAPIModule.h"
|
||||
|
||||
#include "HttpModule.h"
|
||||
#include "Serialization/JsonSerializer.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
OpenAPIPetApi::OpenAPIPetApi()
|
||||
: Url(TEXT("http://petstore.swagger.io/v2"))
|
||||
{
|
||||
}
|
||||
|
||||
OpenAPIPetApi::~OpenAPIPetApi() {}
|
||||
|
||||
void OpenAPIPetApi::SetURL(const FString& InUrl)
|
||||
{
|
||||
Url = InUrl;
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::AddHeaderParam(const FString& Key, const FString& Value)
|
||||
{
|
||||
AdditionalHeaderParams.Add(Key, Value);
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::ClearHeaderParams()
|
||||
{
|
||||
AdditionalHeaderParams.Reset();
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::IsValid() const
|
||||
{
|
||||
if (Url.IsEmpty())
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("OpenAPIPetApi: Endpoint Url is not set, request cannot be performed"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::HandleResponse(FHttpResponsePtr HttpResponse, bool bSucceeded, Response& InOutResponse) const
|
||||
{
|
||||
InOutResponse.SetHttpResponse(HttpResponse);
|
||||
InOutResponse.SetSuccessful(bSucceeded);
|
||||
|
||||
if (bSucceeded && HttpResponse.IsValid())
|
||||
{
|
||||
InOutResponse.SetHttpResponseCode((EHttpResponseCodes::Type)HttpResponse->GetResponseCode());
|
||||
FString ContentType = HttpResponse->GetContentType();
|
||||
FString Content;
|
||||
|
||||
if (ContentType == TEXT("application/json"))
|
||||
{
|
||||
Content = HttpResponse->GetContentAsString();
|
||||
|
||||
TSharedPtr<FJsonValue> JsonValue;
|
||||
auto Reader = TJsonReaderFactory<>::Create(Content);
|
||||
|
||||
if (FJsonSerializer::Deserialize(Reader, JsonValue) && JsonValue.IsValid())
|
||||
{
|
||||
if (InOutResponse.FromJson(JsonValue))
|
||||
return; // Successfully parsed
|
||||
}
|
||||
}
|
||||
else if(ContentType == TEXT("text/plain"))
|
||||
{
|
||||
Content = HttpResponse->GetContentAsString();
|
||||
InOutResponse.SetResponseString(Content);
|
||||
return; // Successfully parsed
|
||||
}
|
||||
|
||||
// Report the parse error but do not mark the request as unsuccessful. Data could be partial or malformed, but the request succeeded.
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Failed to deserialize Http response content (type:%s):\n%s"), *ContentType , *Content);
|
||||
return;
|
||||
}
|
||||
|
||||
// By default, assume we failed to establish connection
|
||||
InOutResponse.SetHttpResponseCode(EHttpResponseCodes::RequestTimeout);
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::AddPet(const AddPetRequest& Request, const FAddPetDelegate& Delegate /*= FAddPetDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIPetApi::OnAddPetResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::OnAddPetResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FAddPetDelegate Delegate) const
|
||||
{
|
||||
AddPetResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::DeletePet(const DeletePetRequest& Request, const FDeletePetDelegate& Delegate /*= FDeletePetDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIPetApi::OnDeletePetResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::OnDeletePetResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FDeletePetDelegate Delegate) const
|
||||
{
|
||||
DeletePetResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::FindPetsByStatus(const FindPetsByStatusRequest& Request, const FFindPetsByStatusDelegate& Delegate /*= FFindPetsByStatusDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIPetApi::OnFindPetsByStatusResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::OnFindPetsByStatusResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FFindPetsByStatusDelegate Delegate) const
|
||||
{
|
||||
FindPetsByStatusResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::FindPetsByTags(const FindPetsByTagsRequest& Request, const FFindPetsByTagsDelegate& Delegate /*= FFindPetsByTagsDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIPetApi::OnFindPetsByTagsResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::OnFindPetsByTagsResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FFindPetsByTagsDelegate Delegate) const
|
||||
{
|
||||
FindPetsByTagsResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::GetPetById(const GetPetByIdRequest& Request, const FGetPetByIdDelegate& Delegate /*= FGetPetByIdDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIPetApi::OnGetPetByIdResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::OnGetPetByIdResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FGetPetByIdDelegate Delegate) const
|
||||
{
|
||||
GetPetByIdResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::UpdatePet(const UpdatePetRequest& Request, const FUpdatePetDelegate& Delegate /*= FUpdatePetDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIPetApi::OnUpdatePetResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::OnUpdatePetResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FUpdatePetDelegate Delegate) const
|
||||
{
|
||||
UpdatePetResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::UpdatePetWithForm(const UpdatePetWithFormRequest& Request, const FUpdatePetWithFormDelegate& Delegate /*= FUpdatePetWithFormDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIPetApi::OnUpdatePetWithFormResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::OnUpdatePetWithFormResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FUpdatePetWithFormDelegate Delegate) const
|
||||
{
|
||||
UpdatePetWithFormResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::UploadFile(const UploadFileRequest& Request, const FUploadFileDelegate& Delegate /*= FUploadFileDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIPetApi::OnUploadFileResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::OnUploadFileResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FUploadFileDelegate Delegate) const
|
||||
{
|
||||
UploadFileResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,560 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#include "OpenAPIPetApiOperations.h"
|
||||
|
||||
#include "OpenAPIModule.h"
|
||||
#include "OpenAPIHelpers.h"
|
||||
|
||||
#include "Dom/JsonObject.h"
|
||||
#include "Templates/SharedPointer.h"
|
||||
#include "HttpModule.h"
|
||||
#include "PlatformHttp.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
FString OpenAPIPetApi::AddPetRequest::ComputePath() const
|
||||
{
|
||||
FString Path(TEXT("/pet"));
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::AddPetRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { TEXT("application/json"), TEXT("application/xml") };
|
||||
//static const TArray<FString> Produces = { };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("POST"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
// Body parameters
|
||||
FString JsonBody;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
|
||||
|
||||
Writer->WriteObjectStart();
|
||||
Writer->WriteIdentifierPrefix(TEXT("body")); WriteJsonValue(Writer, Body);
|
||||
Writer->WriteObjectEnd();
|
||||
Writer->Close();
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
|
||||
HttpRequest->SetContentAsString(JsonBody);
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Body parameter (body) was ignored, not supported in multipart form"));
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Body parameter (body) was ignored, not supported in urlencoded requests"));
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::AddPetResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 405:
|
||||
SetResponseString(TEXT("Invalid input"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::AddPetResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
FString OpenAPIPetApi::DeletePetRequest::ComputePath() const
|
||||
{
|
||||
TMap<FString, FStringFormatArg> PathParams = {
|
||||
{ TEXT("petId"), ToStringFormatArg(PetId) } };
|
||||
|
||||
FString Path = FString::Format(TEXT("/pet/{petId}"), PathParams);
|
||||
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::DeletePetRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { };
|
||||
//static const TArray<FString> Produces = { };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("DELETE"));
|
||||
|
||||
// Header parameters
|
||||
if (ApiKey.IsSet())
|
||||
{
|
||||
HttpRequest->SetHeader(TEXT("api_key"), ApiKey.GetValue());
|
||||
}
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::DeletePetResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 400:
|
||||
SetResponseString(TEXT("Invalid pet value"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::DeletePetResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
inline FString ToString(const OpenAPIPetApi::FindPetsByStatusRequest::StatusEnum& Value)
|
||||
{
|
||||
switch (Value)
|
||||
{
|
||||
case OpenAPIPetApi::FindPetsByStatusRequest::StatusEnum::Available:
|
||||
return TEXT("available");
|
||||
case OpenAPIPetApi::FindPetsByStatusRequest::StatusEnum::Pending:
|
||||
return TEXT("pending");
|
||||
case OpenAPIPetApi::FindPetsByStatusRequest::StatusEnum::Sold:
|
||||
return TEXT("sold");
|
||||
}
|
||||
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Invalid OpenAPIPetApi::FindPetsByStatusRequest::StatusEnum Value (%d)"), (int)Value);
|
||||
return TEXT("");
|
||||
}
|
||||
|
||||
inline FStringFormatArg ToStringFormatArg(const OpenAPIPetApi::FindPetsByStatusRequest::StatusEnum& Value)
|
||||
{
|
||||
return FStringFormatArg(ToString(Value));
|
||||
}
|
||||
|
||||
inline void WriteJsonValue(JsonWriter& Writer, const OpenAPIPetApi::FindPetsByStatusRequest::StatusEnum& Value)
|
||||
{
|
||||
WriteJsonValue(Writer, ToString(Value));
|
||||
}
|
||||
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, OpenAPIPetApi::FindPetsByStatusRequest::StatusEnum& Value)
|
||||
{
|
||||
FString TmpValue;
|
||||
if (JsonValue->TryGetString(TmpValue))
|
||||
{
|
||||
static TMap<FString, OpenAPIPetApi::FindPetsByStatusRequest::StatusEnum> StringToEnum = {
|
||||
{ TEXT("available"), OpenAPIPetApi::FindPetsByStatusRequest::StatusEnum::Available },
|
||||
{ TEXT("pending"), OpenAPIPetApi::FindPetsByStatusRequest::StatusEnum::Pending },
|
||||
{ TEXT("sold"), OpenAPIPetApi::FindPetsByStatusRequest::StatusEnum::Sold }, };
|
||||
|
||||
const auto Found = StringToEnum.Find(TmpValue);
|
||||
if(Found)
|
||||
{
|
||||
Value = *Found;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
FString OpenAPIPetApi::FindPetsByStatusRequest::ComputePath() const
|
||||
{
|
||||
FString Path(TEXT("/pet/findByStatus"));
|
||||
TArray<FString> QueryParams;
|
||||
QueryParams.Add(FString(TEXT("status=")) + CollectionToUrlString_csv(Status, TEXT("status")));
|
||||
Path += TCHAR('?');
|
||||
Path += FString::Join(QueryParams, TEXT("&"));
|
||||
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::FindPetsByStatusRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { };
|
||||
//static const TArray<FString> Produces = { TEXT("application/xml"), TEXT("application/json") };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("GET"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::FindPetsByStatusResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 200:
|
||||
default:
|
||||
SetResponseString(TEXT("successful operation"));
|
||||
break;
|
||||
case 400:
|
||||
SetResponseString(TEXT("Invalid status value"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::FindPetsByStatusResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return TryGetJsonValue(JsonValue, Content);
|
||||
}
|
||||
|
||||
FString OpenAPIPetApi::FindPetsByTagsRequest::ComputePath() const
|
||||
{
|
||||
FString Path(TEXT("/pet/findByTags"));
|
||||
TArray<FString> QueryParams;
|
||||
QueryParams.Add(FString(TEXT("tags=")) + CollectionToUrlString_csv(Tags, TEXT("tags")));
|
||||
Path += TCHAR('?');
|
||||
Path += FString::Join(QueryParams, TEXT("&"));
|
||||
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::FindPetsByTagsRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { };
|
||||
//static const TArray<FString> Produces = { TEXT("application/xml"), TEXT("application/json") };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("GET"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::FindPetsByTagsResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 200:
|
||||
default:
|
||||
SetResponseString(TEXT("successful operation"));
|
||||
break;
|
||||
case 400:
|
||||
SetResponseString(TEXT("Invalid tag value"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::FindPetsByTagsResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return TryGetJsonValue(JsonValue, Content);
|
||||
}
|
||||
|
||||
FString OpenAPIPetApi::GetPetByIdRequest::ComputePath() const
|
||||
{
|
||||
TMap<FString, FStringFormatArg> PathParams = {
|
||||
{ TEXT("petId"), ToStringFormatArg(PetId) } };
|
||||
|
||||
FString Path = FString::Format(TEXT("/pet/{petId}"), PathParams);
|
||||
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::GetPetByIdRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { };
|
||||
//static const TArray<FString> Produces = { TEXT("application/xml"), TEXT("application/json") };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("GET"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::GetPetByIdResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 200:
|
||||
default:
|
||||
SetResponseString(TEXT("successful operation"));
|
||||
break;
|
||||
case 400:
|
||||
SetResponseString(TEXT("Invalid ID supplied"));
|
||||
break;
|
||||
case 404:
|
||||
SetResponseString(TEXT("Pet not found"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::GetPetByIdResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return TryGetJsonValue(JsonValue, Content);
|
||||
}
|
||||
|
||||
FString OpenAPIPetApi::UpdatePetRequest::ComputePath() const
|
||||
{
|
||||
FString Path(TEXT("/pet"));
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::UpdatePetRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { TEXT("application/json"), TEXT("application/xml") };
|
||||
//static const TArray<FString> Produces = { };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("PUT"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
// Body parameters
|
||||
FString JsonBody;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
|
||||
|
||||
Writer->WriteObjectStart();
|
||||
Writer->WriteIdentifierPrefix(TEXT("body")); WriteJsonValue(Writer, Body);
|
||||
Writer->WriteObjectEnd();
|
||||
Writer->Close();
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
|
||||
HttpRequest->SetContentAsString(JsonBody);
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Body parameter (body) was ignored, not supported in multipart form"));
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Body parameter (body) was ignored, not supported in urlencoded requests"));
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::UpdatePetResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 400:
|
||||
SetResponseString(TEXT("Invalid ID supplied"));
|
||||
break;
|
||||
case 404:
|
||||
SetResponseString(TEXT("Pet not found"));
|
||||
break;
|
||||
case 405:
|
||||
SetResponseString(TEXT("Validation exception"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::UpdatePetResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
FString OpenAPIPetApi::UpdatePetWithFormRequest::ComputePath() const
|
||||
{
|
||||
TMap<FString, FStringFormatArg> PathParams = {
|
||||
{ TEXT("petId"), ToStringFormatArg(PetId) } };
|
||||
|
||||
FString Path = FString::Format(TEXT("/pet/{petId}"), PathParams);
|
||||
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::UpdatePetWithFormRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { TEXT("application/x-www-form-urlencoded") };
|
||||
//static const TArray<FString> Produces = { };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("POST"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Form parameter (name) was ignored, cannot be used in JsonBody"));
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Form parameter (status) was ignored, cannot be used in JsonBody"));
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
HttpMultipartFormData FormData;
|
||||
if(Name.IsSet())
|
||||
{
|
||||
FormData.AddStringPart(TEXT("name"), *ToUrlString(Name.GetValue()));
|
||||
}
|
||||
if(Status.IsSet())
|
||||
{
|
||||
FormData.AddStringPart(TEXT("status"), *ToUrlString(Status.GetValue()));
|
||||
}
|
||||
|
||||
FormData.SetupHttpRequest(HttpRequest);
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
TArray<FString> FormParams;
|
||||
if(Name.IsSet())
|
||||
{
|
||||
FormParams.Add(FString(TEXT("name=")) + ToUrlString(Name.GetValue()));
|
||||
}
|
||||
if(Status.IsSet())
|
||||
{
|
||||
FormParams.Add(FString(TEXT("status=")) + ToUrlString(Status.GetValue()));
|
||||
}
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/x-www-form-urlencoded; charset=utf-8"));
|
||||
HttpRequest->SetContentAsString(FString::Join(FormParams, TEXT("&")));
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::UpdatePetWithFormResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 405:
|
||||
SetResponseString(TEXT("Invalid input"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::UpdatePetWithFormResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
FString OpenAPIPetApi::UploadFileRequest::ComputePath() const
|
||||
{
|
||||
TMap<FString, FStringFormatArg> PathParams = {
|
||||
{ TEXT("petId"), ToStringFormatArg(PetId) } };
|
||||
|
||||
FString Path = FString::Format(TEXT("/pet/{petId}/uploadImage"), PathParams);
|
||||
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::UploadFileRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { TEXT("multipart/form-data") };
|
||||
//static const TArray<FString> Produces = { TEXT("application/json") };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("POST"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Form parameter (additionalMetadata) was ignored, cannot be used in JsonBody"));
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Form parameter (file) was ignored, cannot be used in JsonBody"));
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
HttpMultipartFormData FormData;
|
||||
if(AdditionalMetadata.IsSet())
|
||||
{
|
||||
FormData.AddStringPart(TEXT("additionalMetadata"), *ToUrlString(AdditionalMetadata.GetValue()));
|
||||
}
|
||||
if(File.IsSet())
|
||||
{
|
||||
FormData.AddFilePart(TEXT("file"), File.GetValue());
|
||||
FormData.AddBinaryPart(TEXT("file"), File.GetValue());
|
||||
}
|
||||
|
||||
FormData.SetupHttpRequest(HttpRequest);
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
TArray<FString> FormParams;
|
||||
if(AdditionalMetadata.IsSet())
|
||||
{
|
||||
FormParams.Add(FString(TEXT("additionalMetadata=")) + ToUrlString(AdditionalMetadata.GetValue()));
|
||||
}
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Form parameter (file) was ignored, Files are not supported in urlencoded requests"));
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/x-www-form-urlencoded; charset=utf-8"));
|
||||
HttpRequest->SetContentAsString(FString::Join(FormParams, TEXT("&")));
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIPetApi::UploadFileResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 200:
|
||||
default:
|
||||
SetResponseString(TEXT("successful operation"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIPetApi::UploadFileResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return TryGetJsonValue(JsonValue, Content);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#include "OpenAPIStoreApi.h"
|
||||
|
||||
#include "OpenAPIStoreApiOperations.h"
|
||||
#include "OpenAPIModule.h"
|
||||
|
||||
#include "HttpModule.h"
|
||||
#include "Serialization/JsonSerializer.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
OpenAPIStoreApi::OpenAPIStoreApi()
|
||||
: Url(TEXT("http://petstore.swagger.io/v2"))
|
||||
{
|
||||
}
|
||||
|
||||
OpenAPIStoreApi::~OpenAPIStoreApi() {}
|
||||
|
||||
void OpenAPIStoreApi::SetURL(const FString& InUrl)
|
||||
{
|
||||
Url = InUrl;
|
||||
}
|
||||
|
||||
void OpenAPIStoreApi::AddHeaderParam(const FString& Key, const FString& Value)
|
||||
{
|
||||
AdditionalHeaderParams.Add(Key, Value);
|
||||
}
|
||||
|
||||
void OpenAPIStoreApi::ClearHeaderParams()
|
||||
{
|
||||
AdditionalHeaderParams.Reset();
|
||||
}
|
||||
|
||||
bool OpenAPIStoreApi::IsValid() const
|
||||
{
|
||||
if (Url.IsEmpty())
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("OpenAPIStoreApi: Endpoint Url is not set, request cannot be performed"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void OpenAPIStoreApi::HandleResponse(FHttpResponsePtr HttpResponse, bool bSucceeded, Response& InOutResponse) const
|
||||
{
|
||||
InOutResponse.SetHttpResponse(HttpResponse);
|
||||
InOutResponse.SetSuccessful(bSucceeded);
|
||||
|
||||
if (bSucceeded && HttpResponse.IsValid())
|
||||
{
|
||||
InOutResponse.SetHttpResponseCode((EHttpResponseCodes::Type)HttpResponse->GetResponseCode());
|
||||
FString ContentType = HttpResponse->GetContentType();
|
||||
FString Content;
|
||||
|
||||
if (ContentType == TEXT("application/json"))
|
||||
{
|
||||
Content = HttpResponse->GetContentAsString();
|
||||
|
||||
TSharedPtr<FJsonValue> JsonValue;
|
||||
auto Reader = TJsonReaderFactory<>::Create(Content);
|
||||
|
||||
if (FJsonSerializer::Deserialize(Reader, JsonValue) && JsonValue.IsValid())
|
||||
{
|
||||
if (InOutResponse.FromJson(JsonValue))
|
||||
return; // Successfully parsed
|
||||
}
|
||||
}
|
||||
else if(ContentType == TEXT("text/plain"))
|
||||
{
|
||||
Content = HttpResponse->GetContentAsString();
|
||||
InOutResponse.SetResponseString(Content);
|
||||
return; // Successfully parsed
|
||||
}
|
||||
|
||||
// Report the parse error but do not mark the request as unsuccessful. Data could be partial or malformed, but the request succeeded.
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Failed to deserialize Http response content (type:%s):\n%s"), *ContentType , *Content);
|
||||
return;
|
||||
}
|
||||
|
||||
// By default, assume we failed to establish connection
|
||||
InOutResponse.SetHttpResponseCode(EHttpResponseCodes::RequestTimeout);
|
||||
}
|
||||
|
||||
bool OpenAPIStoreApi::DeleteOrder(const DeleteOrderRequest& Request, const FDeleteOrderDelegate& Delegate /*= FDeleteOrderDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIStoreApi::OnDeleteOrderResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIStoreApi::OnDeleteOrderResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FDeleteOrderDelegate Delegate) const
|
||||
{
|
||||
DeleteOrderResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIStoreApi::GetInventory(const GetInventoryRequest& Request, const FGetInventoryDelegate& Delegate /*= FGetInventoryDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIStoreApi::OnGetInventoryResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIStoreApi::OnGetInventoryResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FGetInventoryDelegate Delegate) const
|
||||
{
|
||||
GetInventoryResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIStoreApi::GetOrderById(const GetOrderByIdRequest& Request, const FGetOrderByIdDelegate& Delegate /*= FGetOrderByIdDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIStoreApi::OnGetOrderByIdResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIStoreApi::OnGetOrderByIdResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FGetOrderByIdDelegate Delegate) const
|
||||
{
|
||||
GetOrderByIdResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIStoreApi::PlaceOrder(const PlaceOrderRequest& Request, const FPlaceOrderDelegate& Delegate /*= FPlaceOrderDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIStoreApi::OnPlaceOrderResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIStoreApi::OnPlaceOrderResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FPlaceOrderDelegate Delegate) const
|
||||
{
|
||||
PlaceOrderResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,242 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#include "OpenAPIStoreApiOperations.h"
|
||||
|
||||
#include "OpenAPIModule.h"
|
||||
#include "OpenAPIHelpers.h"
|
||||
|
||||
#include "Dom/JsonObject.h"
|
||||
#include "Templates/SharedPointer.h"
|
||||
#include "HttpModule.h"
|
||||
#include "PlatformHttp.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
FString OpenAPIStoreApi::DeleteOrderRequest::ComputePath() const
|
||||
{
|
||||
TMap<FString, FStringFormatArg> PathParams = {
|
||||
{ TEXT("orderId"), ToStringFormatArg(OrderId) } };
|
||||
|
||||
FString Path = FString::Format(TEXT("/store/order/{orderId}"), PathParams);
|
||||
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIStoreApi::DeleteOrderRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { };
|
||||
//static const TArray<FString> Produces = { };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("DELETE"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIStoreApi::DeleteOrderResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 400:
|
||||
SetResponseString(TEXT("Invalid ID supplied"));
|
||||
break;
|
||||
case 404:
|
||||
SetResponseString(TEXT("Order not found"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIStoreApi::DeleteOrderResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
FString OpenAPIStoreApi::GetInventoryRequest::ComputePath() const
|
||||
{
|
||||
FString Path(TEXT("/store/inventory"));
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIStoreApi::GetInventoryRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { };
|
||||
//static const TArray<FString> Produces = { TEXT("application/json") };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("GET"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIStoreApi::GetInventoryResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 200:
|
||||
default:
|
||||
SetResponseString(TEXT("successful operation"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIStoreApi::GetInventoryResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return TryGetJsonValue(JsonValue, Content);
|
||||
}
|
||||
|
||||
FString OpenAPIStoreApi::GetOrderByIdRequest::ComputePath() const
|
||||
{
|
||||
TMap<FString, FStringFormatArg> PathParams = {
|
||||
{ TEXT("orderId"), ToStringFormatArg(OrderId) } };
|
||||
|
||||
FString Path = FString::Format(TEXT("/store/order/{orderId}"), PathParams);
|
||||
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIStoreApi::GetOrderByIdRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { };
|
||||
//static const TArray<FString> Produces = { TEXT("application/xml"), TEXT("application/json") };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("GET"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIStoreApi::GetOrderByIdResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 200:
|
||||
default:
|
||||
SetResponseString(TEXT("successful operation"));
|
||||
break;
|
||||
case 400:
|
||||
SetResponseString(TEXT("Invalid ID supplied"));
|
||||
break;
|
||||
case 404:
|
||||
SetResponseString(TEXT("Order not found"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIStoreApi::GetOrderByIdResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return TryGetJsonValue(JsonValue, Content);
|
||||
}
|
||||
|
||||
FString OpenAPIStoreApi::PlaceOrderRequest::ComputePath() const
|
||||
{
|
||||
FString Path(TEXT("/store/order"));
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIStoreApi::PlaceOrderRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { };
|
||||
//static const TArray<FString> Produces = { TEXT("application/xml"), TEXT("application/json") };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("POST"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
// Body parameters
|
||||
FString JsonBody;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
|
||||
|
||||
Writer->WriteObjectStart();
|
||||
Writer->WriteIdentifierPrefix(TEXT("body")); WriteJsonValue(Writer, Body);
|
||||
Writer->WriteObjectEnd();
|
||||
Writer->Close();
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
|
||||
HttpRequest->SetContentAsString(JsonBody);
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Body parameter (body) was ignored, not supported in multipart form"));
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Body parameter (body) was ignored, not supported in urlencoded requests"));
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIStoreApi::PlaceOrderResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 200:
|
||||
default:
|
||||
SetResponseString(TEXT("successful operation"));
|
||||
break;
|
||||
case 400:
|
||||
SetResponseString(TEXT("Invalid Order"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIStoreApi::PlaceOrderResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return TryGetJsonValue(JsonValue, Content);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,305 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#include "OpenAPIUserApi.h"
|
||||
|
||||
#include "OpenAPIUserApiOperations.h"
|
||||
#include "OpenAPIModule.h"
|
||||
|
||||
#include "HttpModule.h"
|
||||
#include "Serialization/JsonSerializer.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
OpenAPIUserApi::OpenAPIUserApi()
|
||||
: Url(TEXT("http://petstore.swagger.io/v2"))
|
||||
{
|
||||
}
|
||||
|
||||
OpenAPIUserApi::~OpenAPIUserApi() {}
|
||||
|
||||
void OpenAPIUserApi::SetURL(const FString& InUrl)
|
||||
{
|
||||
Url = InUrl;
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::AddHeaderParam(const FString& Key, const FString& Value)
|
||||
{
|
||||
AdditionalHeaderParams.Add(Key, Value);
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::ClearHeaderParams()
|
||||
{
|
||||
AdditionalHeaderParams.Reset();
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::IsValid() const
|
||||
{
|
||||
if (Url.IsEmpty())
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("OpenAPIUserApi: Endpoint Url is not set, request cannot be performed"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::HandleResponse(FHttpResponsePtr HttpResponse, bool bSucceeded, Response& InOutResponse) const
|
||||
{
|
||||
InOutResponse.SetHttpResponse(HttpResponse);
|
||||
InOutResponse.SetSuccessful(bSucceeded);
|
||||
|
||||
if (bSucceeded && HttpResponse.IsValid())
|
||||
{
|
||||
InOutResponse.SetHttpResponseCode((EHttpResponseCodes::Type)HttpResponse->GetResponseCode());
|
||||
FString ContentType = HttpResponse->GetContentType();
|
||||
FString Content;
|
||||
|
||||
if (ContentType == TEXT("application/json"))
|
||||
{
|
||||
Content = HttpResponse->GetContentAsString();
|
||||
|
||||
TSharedPtr<FJsonValue> JsonValue;
|
||||
auto Reader = TJsonReaderFactory<>::Create(Content);
|
||||
|
||||
if (FJsonSerializer::Deserialize(Reader, JsonValue) && JsonValue.IsValid())
|
||||
{
|
||||
if (InOutResponse.FromJson(JsonValue))
|
||||
return; // Successfully parsed
|
||||
}
|
||||
}
|
||||
else if(ContentType == TEXT("text/plain"))
|
||||
{
|
||||
Content = HttpResponse->GetContentAsString();
|
||||
InOutResponse.SetResponseString(Content);
|
||||
return; // Successfully parsed
|
||||
}
|
||||
|
||||
// Report the parse error but do not mark the request as unsuccessful. Data could be partial or malformed, but the request succeeded.
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Failed to deserialize Http response content (type:%s):\n%s"), *ContentType , *Content);
|
||||
return;
|
||||
}
|
||||
|
||||
// By default, assume we failed to establish connection
|
||||
InOutResponse.SetHttpResponseCode(EHttpResponseCodes::RequestTimeout);
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::CreateUser(const CreateUserRequest& Request, const FCreateUserDelegate& Delegate /*= FCreateUserDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIUserApi::OnCreateUserResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::OnCreateUserResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FCreateUserDelegate Delegate) const
|
||||
{
|
||||
CreateUserResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::CreateUsersWithArrayInput(const CreateUsersWithArrayInputRequest& Request, const FCreateUsersWithArrayInputDelegate& Delegate /*= FCreateUsersWithArrayInputDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIUserApi::OnCreateUsersWithArrayInputResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::OnCreateUsersWithArrayInputResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FCreateUsersWithArrayInputDelegate Delegate) const
|
||||
{
|
||||
CreateUsersWithArrayInputResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::CreateUsersWithListInput(const CreateUsersWithListInputRequest& Request, const FCreateUsersWithListInputDelegate& Delegate /*= FCreateUsersWithListInputDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIUserApi::OnCreateUsersWithListInputResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::OnCreateUsersWithListInputResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FCreateUsersWithListInputDelegate Delegate) const
|
||||
{
|
||||
CreateUsersWithListInputResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::DeleteUser(const DeleteUserRequest& Request, const FDeleteUserDelegate& Delegate /*= FDeleteUserDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIUserApi::OnDeleteUserResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::OnDeleteUserResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FDeleteUserDelegate Delegate) const
|
||||
{
|
||||
DeleteUserResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::GetUserByName(const GetUserByNameRequest& Request, const FGetUserByNameDelegate& Delegate /*= FGetUserByNameDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIUserApi::OnGetUserByNameResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::OnGetUserByNameResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FGetUserByNameDelegate Delegate) const
|
||||
{
|
||||
GetUserByNameResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::LoginUser(const LoginUserRequest& Request, const FLoginUserDelegate& Delegate /*= FLoginUserDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIUserApi::OnLoginUserResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::OnLoginUserResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FLoginUserDelegate Delegate) const
|
||||
{
|
||||
LoginUserResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::LogoutUser(const LogoutUserRequest& Request, const FLogoutUserDelegate& Delegate /*= FLogoutUserDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIUserApi::OnLogoutUserResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::OnLogoutUserResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FLogoutUserDelegate Delegate) const
|
||||
{
|
||||
LogoutUserResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::UpdateUser(const UpdateUserRequest& Request, const FUpdateUserDelegate& Delegate /*= FUpdateUserDelegate()*/) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
|
||||
HttpRequest->SetURL(*(Url + Request.ComputePath()));
|
||||
|
||||
for(const auto& It : AdditionalHeaderParams)
|
||||
{
|
||||
HttpRequest->SetHeader(It.Key, It.Value);
|
||||
}
|
||||
|
||||
Request.SetupHttpRequest(HttpRequest);
|
||||
|
||||
HttpRequest->OnProcessRequestComplete().BindRaw(this, &OpenAPIUserApi::OnUpdateUserResponse, Delegate);
|
||||
return HttpRequest->ProcessRequest();
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::OnUpdateUserResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FUpdateUserDelegate Delegate) const
|
||||
{
|
||||
UpdateUserResponse Response;
|
||||
HandleResponse(HttpResponse, bSucceeded, Response);
|
||||
Delegate.ExecuteIfBound(Response);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,477 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#include "OpenAPIUserApiOperations.h"
|
||||
|
||||
#include "OpenAPIModule.h"
|
||||
#include "OpenAPIHelpers.h"
|
||||
|
||||
#include "Dom/JsonObject.h"
|
||||
#include "Templates/SharedPointer.h"
|
||||
#include "HttpModule.h"
|
||||
#include "PlatformHttp.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
FString OpenAPIUserApi::CreateUserRequest::ComputePath() const
|
||||
{
|
||||
FString Path(TEXT("/user"));
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::CreateUserRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { };
|
||||
//static const TArray<FString> Produces = { };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("POST"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
// Body parameters
|
||||
FString JsonBody;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
|
||||
|
||||
Writer->WriteObjectStart();
|
||||
Writer->WriteIdentifierPrefix(TEXT("body")); WriteJsonValue(Writer, Body);
|
||||
Writer->WriteObjectEnd();
|
||||
Writer->Close();
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
|
||||
HttpRequest->SetContentAsString(JsonBody);
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Body parameter (body) was ignored, not supported in multipart form"));
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Body parameter (body) was ignored, not supported in urlencoded requests"));
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::CreateUserResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 0:
|
||||
default:
|
||||
SetResponseString(TEXT("successful operation"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::CreateUserResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
FString OpenAPIUserApi::CreateUsersWithArrayInputRequest::ComputePath() const
|
||||
{
|
||||
FString Path(TEXT("/user/createWithArray"));
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::CreateUsersWithArrayInputRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { };
|
||||
//static const TArray<FString> Produces = { };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("POST"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
// Body parameters
|
||||
FString JsonBody;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
|
||||
|
||||
Writer->WriteObjectStart();
|
||||
Writer->WriteIdentifierPrefix(TEXT("body")); WriteJsonValue(Writer, Body);
|
||||
Writer->WriteObjectEnd();
|
||||
Writer->Close();
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
|
||||
HttpRequest->SetContentAsString(JsonBody);
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Body parameter (body) was ignored, not supported in multipart form"));
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Body parameter (body) was ignored, not supported in urlencoded requests"));
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::CreateUsersWithArrayInputResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 0:
|
||||
default:
|
||||
SetResponseString(TEXT("successful operation"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::CreateUsersWithArrayInputResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
FString OpenAPIUserApi::CreateUsersWithListInputRequest::ComputePath() const
|
||||
{
|
||||
FString Path(TEXT("/user/createWithList"));
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::CreateUsersWithListInputRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { };
|
||||
//static const TArray<FString> Produces = { };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("POST"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
// Body parameters
|
||||
FString JsonBody;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
|
||||
|
||||
Writer->WriteObjectStart();
|
||||
Writer->WriteIdentifierPrefix(TEXT("body")); WriteJsonValue(Writer, Body);
|
||||
Writer->WriteObjectEnd();
|
||||
Writer->Close();
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
|
||||
HttpRequest->SetContentAsString(JsonBody);
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Body parameter (body) was ignored, not supported in multipart form"));
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Body parameter (body) was ignored, not supported in urlencoded requests"));
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::CreateUsersWithListInputResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 0:
|
||||
default:
|
||||
SetResponseString(TEXT("successful operation"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::CreateUsersWithListInputResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
FString OpenAPIUserApi::DeleteUserRequest::ComputePath() const
|
||||
{
|
||||
TMap<FString, FStringFormatArg> PathParams = {
|
||||
{ TEXT("username"), ToStringFormatArg(Username) } };
|
||||
|
||||
FString Path = FString::Format(TEXT("/user/{username}"), PathParams);
|
||||
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::DeleteUserRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { };
|
||||
//static const TArray<FString> Produces = { };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("DELETE"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::DeleteUserResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 400:
|
||||
SetResponseString(TEXT("Invalid username supplied"));
|
||||
break;
|
||||
case 404:
|
||||
SetResponseString(TEXT("User not found"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::DeleteUserResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
FString OpenAPIUserApi::GetUserByNameRequest::ComputePath() const
|
||||
{
|
||||
TMap<FString, FStringFormatArg> PathParams = {
|
||||
{ TEXT("username"), ToStringFormatArg(Username) } };
|
||||
|
||||
FString Path = FString::Format(TEXT("/user/{username}"), PathParams);
|
||||
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::GetUserByNameRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { };
|
||||
//static const TArray<FString> Produces = { TEXT("application/xml"), TEXT("application/json") };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("GET"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::GetUserByNameResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 200:
|
||||
default:
|
||||
SetResponseString(TEXT("successful operation"));
|
||||
break;
|
||||
case 400:
|
||||
SetResponseString(TEXT("Invalid username supplied"));
|
||||
break;
|
||||
case 404:
|
||||
SetResponseString(TEXT("User not found"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::GetUserByNameResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return TryGetJsonValue(JsonValue, Content);
|
||||
}
|
||||
|
||||
FString OpenAPIUserApi::LoginUserRequest::ComputePath() const
|
||||
{
|
||||
FString Path(TEXT("/user/login"));
|
||||
TArray<FString> QueryParams;
|
||||
QueryParams.Add(FString(TEXT("username=")) + ToUrlString(Username));
|
||||
QueryParams.Add(FString(TEXT("password=")) + ToUrlString(Password));
|
||||
Path += TCHAR('?');
|
||||
Path += FString::Join(QueryParams, TEXT("&"));
|
||||
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::LoginUserRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { };
|
||||
//static const TArray<FString> Produces = { TEXT("application/xml"), TEXT("application/json") };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("GET"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::LoginUserResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 200:
|
||||
default:
|
||||
SetResponseString(TEXT("successful operation"));
|
||||
break;
|
||||
case 400:
|
||||
SetResponseString(TEXT("Invalid username/password supplied"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::LoginUserResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return TryGetJsonValue(JsonValue, Content);
|
||||
}
|
||||
|
||||
FString OpenAPIUserApi::LogoutUserRequest::ComputePath() const
|
||||
{
|
||||
FString Path(TEXT("/user/logout"));
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::LogoutUserRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { };
|
||||
//static const TArray<FString> Produces = { };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("GET"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::LogoutUserResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 0:
|
||||
default:
|
||||
SetResponseString(TEXT("successful operation"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::LogoutUserResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
FString OpenAPIUserApi::UpdateUserRequest::ComputePath() const
|
||||
{
|
||||
TMap<FString, FStringFormatArg> PathParams = {
|
||||
{ TEXT("username"), ToStringFormatArg(Username) } };
|
||||
|
||||
FString Path = FString::Format(TEXT("/user/{username}"), PathParams);
|
||||
|
||||
return Path;
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::UpdateUserRequest::SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const
|
||||
{
|
||||
static const TArray<FString> Consumes = { };
|
||||
//static const TArray<FString> Produces = { };
|
||||
|
||||
HttpRequest->SetVerb(TEXT("PUT"));
|
||||
|
||||
// Default to Json Body request
|
||||
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
|
||||
{
|
||||
// Body parameters
|
||||
FString JsonBody;
|
||||
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
|
||||
|
||||
Writer->WriteObjectStart();
|
||||
Writer->WriteIdentifierPrefix(TEXT("body")); WriteJsonValue(Writer, Body);
|
||||
Writer->WriteObjectEnd();
|
||||
Writer->Close();
|
||||
|
||||
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
|
||||
HttpRequest->SetContentAsString(JsonBody);
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("multipart/form-data")))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Body parameter (body) was ignored, not supported in multipart form"));
|
||||
}
|
||||
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Body parameter (body) was ignored, not supported in urlencoded requests"));
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOpenAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAPIUserApi::UpdateUserResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
|
||||
{
|
||||
Response::SetHttpResponseCode(InHttpResponseCode);
|
||||
switch ((int)InHttpResponseCode)
|
||||
{
|
||||
case 400:
|
||||
SetResponseString(TEXT("Invalid user supplied"));
|
||||
break;
|
||||
case 404:
|
||||
SetResponseString(TEXT("User not found"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenAPIUserApi::UpdateUserResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator
|
||||
* https://github.com/OpenAPITools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Interfaces/IHttpRequest.h"
|
||||
#include "Interfaces/IHttpResponse.h"
|
||||
#include "Serialization/JsonWriter.h"
|
||||
#include "Dom/JsonObject.h"
|
||||
|
||||
namespace OpenAPI
|
||||
{
|
||||
|
||||
typedef TSharedRef<TJsonWriter<>> JsonWriter;
|
||||
|
||||
class OPENAPI_API Model
|
||||
{
|
||||
public:
|
||||
virtual ~Model() {}
|
||||
virtual void WriteJson(JsonWriter& Writer) const = 0;
|
||||
virtual bool FromJson(const TSharedPtr<FJsonObject>& JsonObject) = 0;
|
||||
};
|
||||
|
||||
class OPENAPI_API Request
|
||||
{
|
||||
public:
|
||||
virtual ~Request() {}
|
||||
virtual void SetupHttpRequest(const TSharedRef<IHttpRequest>& HttpRequest) const = 0;
|
||||
virtual FString ComputePath() const = 0;
|
||||
};
|
||||
|
||||
class OPENAPI_API Response
|
||||
{
|
||||
public:
|
||||
virtual ~Response() {}
|
||||
virtual bool FromJson(const TSharedPtr<FJsonValue>& JsonObject) = 0;
|
||||
|
||||
void SetSuccessful(bool InSuccessful) { Successful = InSuccessful; }
|
||||
bool IsSuccessful() const { return Successful; }
|
||||
|
||||
virtual void SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode);
|
||||
EHttpResponseCodes::Type GetHttpResponseCode() const { return ResponseCode; }
|
||||
|
||||
void SetResponseString(const FString& InResponseString) { ResponseString = InResponseString; }
|
||||
const FString& GetResponseString() const { return ResponseString; }
|
||||
|
||||
void SetHttpResponse(const FHttpResponsePtr& InHttpResponse) { HttpResponse = InHttpResponse; }
|
||||
const FHttpResponsePtr& GetHttpResponse() const { return HttpResponse; }
|
||||
|
||||
private:
|
||||
bool Successful;
|
||||
EHttpResponseCodes::Type ResponseCode;
|
||||
FString ResponseString;
|
||||
FHttpResponsePtr HttpResponse;
|
||||
};
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user