From 6abc4fdab2dc7bd53515ac80dae978e88e80e4e5 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 25 May 2020 23:09:34 +0800 Subject: [PATCH] Migrate all scala generators to use OAS3 (#6407) * migrate all scala generators to use oas3 * add back pom.xml for scala-sttp * skip form model in scalaz * fix scala lagom tests * add new files * skip form models in scala finch petstore * update samples --- bin/openapi3/scala-akka-petstore.sh | 32 -- bin/openapi3/scala-httpclient-petstore.sh | 32 -- bin/openapi3/scalatra-petstore-server.sh | 32 -- bin/openapi3/scalaz-petstore.sh | 32 -- bin/scala-akka-http-server-petstore.sh | 2 +- bin/scala-akka-petstore.sh | 4 +- bin/scala-finch-petstore-server.sh | 2 +- bin/scala-gatling-petstore.sh | 2 +- bin/scala-httpclient-petstore.sh | 4 +- bin/scala-lagom-server-petstore.sh | 2 +- bin/scala-play-framework-petstore.sh | 2 +- bin/{openapi3 => }/scala-sttp-petstore.sh | 2 +- bin/scalatra-petstore-server.sh | 4 +- bin/scalaz-petstore.sh | 4 +- bin/utils/ensure-up-to-date | 3 +- pom.xml | 6 +- .../scala-akka/.openapi-generator/FILES | 2 + samples/client/petstore/scala-akka/README.md | 8 + .../scala-akka/project/build.properties | 1 - .../org/openapitools/client/api/PetApi.scala | 22 +- .../openapitools/client/api/StoreApi.scala | 6 +- .../org/openapitools/client/api/UserApi.scala | 54 ++- .../src/test/scala/PetApiTest.scala | 0 .../scala-gatling/.openapi-generator/VERSION | 2 +- .../client/model/InlineObject.scala | 18 + .../client/model/InlineObject1.scala | 19 ++ .../.openapi-generator/VERSION | 2 +- .../org/openapitools/client/api/PetApi.scala | 44 +-- .../openapitools/client/api/StoreApi.scala | 18 +- .../org/openapitools/client/api/UserApi.scala | 72 ++-- .../client/model/InlineObject.scala | 22 ++ .../client/model/InlineObject1.scala | 23 ++ .../scala-sttp}/.openapi-generator-ignore | 0 .../scala-sttp}/.openapi-generator/FILES | 4 - .../scala-sttp}/.openapi-generator/VERSION | 0 .../petstore/scala-sttp}/README.md | 32 +- samples/client/petstore/scala-sttp/build.sbt | 24 ++ samples/client/petstore/scala-sttp/pom.xml | 32 ++ .../client/api/EnumsSerializers.scala | 0 .../org/openapitools/client/api/PetApi.scala | 124 ++++--- .../openapitools/client/api/StoreApi.scala | 62 ++-- .../org/openapitools/client/api/UserApi.scala | 170 ++++++++++ .../openapitools/client/core/ApiInvoker.scala | 60 ++++ .../client/core/Serializers.scala | 15 +- .../openapitools/client/core/requests.scala | 58 ++++ .../client/model/ApiResponse.scala | 6 +- .../openapitools/client/model/Category.scala | 6 +- .../client/model/InlineObject.scala | 2 +- .../client/model/InlineObject1.scala | 2 +- .../org/openapitools/client/model/Order.scala | 6 +- .../org/openapitools/client/model/Pet.scala | 6 +- .../org/openapitools/client/model/Tag.scala | 6 +- .../org/openapitools/client/model/User.scala | 6 +- .../scalaz/.openapi-generator/VERSION | 2 +- .../client/api/DateTimeCodecs.scala | 3 + .../org/openapitools/client/api/PetApi.scala | 32 +- .../openapitools/client/api/StoreApi.scala | 8 +- .../org/openapitools/client/api/UserApi.scala | 32 +- .../client/petstore/scala-akka/build.sbt | 27 -- .../client/petstore/scala-akka/pom.xml | 254 -------------- .../src/main/resources/reference.conf | 24 -- .../org/openapitools/client/api/UserApi.scala | 175 ---------- .../openapitools/client/core/ApiInvoker.scala | 291 ---------------- .../openapitools/client/core/ApiRequest.scala | 65 ---- .../client/core/ApiSettings.scala | 45 --- .../openapitools/client/core/requests.scala | 200 ----------- .../.openapi-generator/VERSION | 2 +- .../org/openapitools/server/api/PetApi.scala | 20 +- .../openapitools/server/api/StoreApi.scala | 6 +- .../org/openapitools/server/api/UserApi.scala | 24 +- .../server/model/InlineObject.scala | 12 + .../server/model/InlineObject1.scala | 13 + .../scala-finch/.openapi-generator/FILES | 18 + .../scala-finch/.openapi-generator/VERSION | 2 +- .../src/main/scala/DataAccessor.scala | 22 +- .../scala/org/openapitools/apis/PetApi.scala | 16 +- .../org/openapitools/apis/StoreApi.scala | 4 +- .../scala/org/openapitools/apis/UserApi.scala | 24 +- .../.openapi-generator/FILES | 14 + .../.openapi-generator/VERSION | 2 +- .../scala/io/swagger/client/api/PetApi.scala | 8 +- .../.openapi-generator/VERSION | 2 +- .../scala-play-server/app/api/PetApi.scala | 8 +- .../app/api/PetApiController.scala | 26 +- .../app/api/PetApiImpl.scala | 8 +- .../scala-play-server/app/api/StoreApi.scala | 4 +- .../app/api/StoreApiController.scala | 6 +- .../app/api/StoreApiImpl.scala | 2 +- .../scala-play-server/app/api/UserApi.scala | 16 +- .../app/api/UserApiController.scala | 24 +- .../app/api/UserApiImpl.scala | 8 +- .../app/model/InlineObject.scala | 19 ++ .../app/model/InlineObject1.scala | 20 ++ .../scala-play-server/public/openapi.json | 320 +++++++++++------- .../scalatra/.openapi-generator/VERSION | 2 +- 95 files changed, 1194 insertions(+), 1715 deletions(-) delete mode 100755 bin/openapi3/scala-akka-petstore.sh delete mode 100755 bin/openapi3/scala-httpclient-petstore.sh delete mode 100755 bin/openapi3/scalatra-petstore-server.sh delete mode 100755 bin/openapi3/scalaz-petstore.sh rename bin/{openapi3 => }/scala-sttp-petstore.sh (94%) delete mode 100644 samples/client/petstore/scala-akka/project/build.properties rename samples/{openapi3 => }/client/petstore/scala-akka/src/test/scala/PetApiTest.scala (100%) create mode 100644 samples/client/petstore/scala-gatling/src/gatling/scala/org/openapitools/client/model/InlineObject.scala create mode 100644 samples/client/petstore/scala-gatling/src/gatling/scala/org/openapitools/client/model/InlineObject1.scala create mode 100644 samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/model/InlineObject.scala create mode 100644 samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/model/InlineObject1.scala rename samples/{openapi3/client/petstore/scala-akka => client/petstore/scala-sttp}/.openapi-generator-ignore (100%) rename samples/{openapi3/client/petstore/scala-akka => client/petstore/scala-sttp}/.openapi-generator/FILES (84%) rename samples/{openapi3/client/petstore/scala-akka => client/petstore/scala-sttp}/.openapi-generator/VERSION (100%) rename samples/{openapi3/client/petstore/scala-akka => client/petstore/scala-sttp}/README.md (71%) create mode 100644 samples/client/petstore/scala-sttp/build.sbt create mode 100644 samples/client/petstore/scala-sttp/pom.xml rename samples/{openapi3/client/petstore/scala-akka => client/petstore/scala-sttp}/src/main/scala/org/openapitools/client/api/EnumsSerializers.scala (100%) rename samples/{openapi3/client/petstore/scala-akka => client/petstore/scala-sttp}/src/main/scala/org/openapitools/client/api/PetApi.scala (51%) rename samples/{openapi3/client/petstore/scala-akka => client/petstore/scala-sttp}/src/main/scala/org/openapitools/client/api/StoreApi.scala (53%) create mode 100644 samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/UserApi.scala create mode 100644 samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/core/ApiInvoker.scala rename samples/{openapi3/client/petstore/scala-akka => client/petstore/scala-sttp}/src/main/scala/org/openapitools/client/core/Serializers.scala (75%) create mode 100644 samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/core/requests.scala rename samples/{openapi3/client/petstore/scala-akka => client/petstore/scala-sttp}/src/main/scala/org/openapitools/client/model/ApiResponse.scala (82%) rename samples/{openapi3/client/petstore/scala-akka => client/petstore/scala-sttp}/src/main/scala/org/openapitools/client/model/Category.scala (87%) rename samples/{openapi3/client/petstore/scala-akka => client/petstore/scala-sttp}/src/main/scala/org/openapitools/client/model/InlineObject.scala (95%) rename samples/{openapi3/client/petstore/scala-akka => client/petstore/scala-sttp}/src/main/scala/org/openapitools/client/model/InlineObject1.scala (95%) rename samples/{openapi3/client/petstore/scala-akka => client/petstore/scala-sttp}/src/main/scala/org/openapitools/client/model/Order.scala (91%) rename samples/{openapi3/client/petstore/scala-akka => client/petstore/scala-sttp}/src/main/scala/org/openapitools/client/model/Pet.scala (92%) rename samples/{openapi3/client/petstore/scala-akka => client/petstore/scala-sttp}/src/main/scala/org/openapitools/client/model/Tag.scala (89%) rename samples/{openapi3/client/petstore/scala-akka => client/petstore/scala-sttp}/src/main/scala/org/openapitools/client/model/User.scala (89%) delete mode 100644 samples/openapi3/client/petstore/scala-akka/build.sbt delete mode 100644 samples/openapi3/client/petstore/scala-akka/pom.xml delete mode 100644 samples/openapi3/client/petstore/scala-akka/src/main/resources/reference.conf delete mode 100644 samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/UserApi.scala delete mode 100644 samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiInvoker.scala delete mode 100644 samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiRequest.scala delete mode 100644 samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiSettings.scala delete mode 100644 samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/requests.scala create mode 100644 samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/model/InlineObject.scala create mode 100644 samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/model/InlineObject1.scala create mode 100644 samples/server/petstore/scala-finch/.openapi-generator/FILES create mode 100644 samples/server/petstore/scala-lagom-server/.openapi-generator/FILES create mode 100644 samples/server/petstore/scala-play-server/app/model/InlineObject.scala create mode 100644 samples/server/petstore/scala-play-server/app/model/InlineObject1.scala diff --git a/bin/openapi3/scala-akka-petstore.sh b/bin/openapi3/scala-akka-petstore.sh deleted file mode 100755 index 5443c58f8fb7..000000000000 --- a/bin/openapi3/scala-akka-petstore.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -SCRIPT="$0" -echo "# START SCRIPT: $SCRIPT" - -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} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate --artifact-id "scala-akka-petstore-client" -t modules/openapi-generator/src/main/resources/scala-akka-client -i modules/openapi-generator/src/test/resources/3_0/scala-akka/petstore.yaml -g scala-akka -o samples/openapi3/client/petstore/scala-akka $@" - -java $JAVA_OPTS -jar $executable $ags diff --git a/bin/openapi3/scala-httpclient-petstore.sh b/bin/openapi3/scala-httpclient-petstore.sh deleted file mode 100755 index d3629abc4741..000000000000 --- a/bin/openapi3/scala-httpclient-petstore.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -SCRIPT="$0" -echo "# START SCRIPT: $SCRIPT" - -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} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/scala-httpclient -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g scala-httpclient-deprecated -o samples/client/petstore/scala-httpclient $@" - -java $JAVA_OPTS -jar $executable $ags diff --git a/bin/openapi3/scalatra-petstore-server.sh b/bin/openapi3/scalatra-petstore-server.sh deleted file mode 100755 index 04d037b89ce7..000000000000 --- a/bin/openapi3/scalatra-petstore-server.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -SCRIPT="$0" -echo "# START SCRIPT: $SCRIPT" - -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} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/scalatra -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g scalatra -o samples/server/petstore/scalatra $@" - -java $JAVA_OPTS -jar $executable $ags diff --git a/bin/openapi3/scalaz-petstore.sh b/bin/openapi3/scalaz-petstore.sh deleted file mode 100755 index 9c6ae8d0e344..000000000000 --- a/bin/openapi3/scalaz-petstore.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -SCRIPT="$0" -echo "# START SCRIPT: $SCRIPT" - -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} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/scalaz -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g scalaz -o samples/client/petstore/scalaz $@" - -java $JAVA_OPTS -jar $executable $ags diff --git a/bin/scala-akka-http-server-petstore.sh b/bin/scala-akka-http-server-petstore.sh index 80d49b4e9336..83f97fca797d 100755 --- a/bin/scala-akka-http-server-petstore.sh +++ b/bin/scala-akka-http-server-petstore.sh @@ -26,6 +26,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 -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g scala-akka-http-server -o samples/server/petstore/scala-akka-http-server $@" +ags="generate -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g scala-akka-http-server -o samples/server/petstore/scala-akka-http-server $@" java ${JAVA_OPTS} -jar ${executable} ${ags} diff --git a/bin/scala-akka-petstore.sh b/bin/scala-akka-petstore.sh index 9df1bf7f4558..037fa6a962e3 100755 --- a/bin/scala-akka-petstore.sh +++ b/bin/scala-akka-petstore.sh @@ -22,11 +22,11 @@ executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" if [ ! -f "$executable" ] then - mvn -B clean package + mvn clean package 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 --artifact-id "scala-akka-petstore-client" -t modules/openapi-generator/src/main/resources/scala-akka-client -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g scala-akka -o samples/client/petstore/scala-akka $@" +ags="generate --artifact-id "scala-akka-petstore-client" -t modules/openapi-generator/src/main/resources/scala-akka-client -i modules/openapi-generator/src/test/resources/3_0/scala-akka/petstore.yaml -g scala-akka -o samples/client/petstore/scala-akka $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/scala-finch-petstore-server.sh b/bin/scala-finch-petstore-server.sh index 31d835180898..080d338ae7f3 100755 --- a/bin/scala-finch-petstore-server.sh +++ b/bin/scala-finch-petstore-server.sh @@ -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/scala-finch -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g scala-finch -o samples/server/petstore/scala-finch $@" +ags="generate -t modules/openapi-generator/src/main/resources/scala-finch -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g scala-finch -o samples/server/petstore/scala-finch -DskipFormModel=true $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/scala-gatling-petstore.sh b/bin/scala-gatling-petstore.sh index e9e6fa576661..227ad58c3d10 100755 --- a/bin/scala-gatling-petstore.sh +++ b/bin/scala-gatling-petstore.sh @@ -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/scala-gatling -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g scala-gatling -o samples/client/petstore/scala-gatling $@" +ags="generate -t modules/openapi-generator/src/main/resources/scala-gatling -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g scala-gatling -o samples/client/petstore/scala-gatling $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/scala-httpclient-petstore.sh b/bin/scala-httpclient-petstore.sh index 421e3abbf4aa..d3629abc4741 100755 --- a/bin/scala-httpclient-petstore.sh +++ b/bin/scala-httpclient-petstore.sh @@ -22,11 +22,11 @@ executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" if [ ! -f "$executable" ] then - mvn -B clean package + mvn clean package 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/scala-httpclient -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g scala-httpclient-deprecated -o samples/client/petstore/scala-httpclient $@" +ags="generate -t modules/openapi-generator/src/main/resources/scala-httpclient -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g scala-httpclient-deprecated -o samples/client/petstore/scala-httpclient $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/scala-lagom-server-petstore.sh b/bin/scala-lagom-server-petstore.sh index 0ba8b57ebedf..ab3720b618e8 100755 --- a/bin/scala-lagom-server-petstore.sh +++ b/bin/scala-lagom-server-petstore.sh @@ -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/scala-lagom-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g scala-lagom-server -o samples/server/petstore/scala-lagom-server $@" +ags="generate -t modules/openapi-generator/src/main/resources/scala-lagom-server -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g scala-lagom-server -o samples/server/petstore/scala-lagom-server -DskipFormModel=true $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/scala-play-framework-petstore.sh b/bin/scala-play-framework-petstore.sh index f1fe5bc1637f..90258c2a597e 100755 --- a/bin/scala-play-framework-petstore.sh +++ b/bin/scala-play-framework-petstore.sh @@ -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/scala-play-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g scala-play-server -o samples/server/petstore/scala-play-server --additional-properties hideGenerationTimestamp=true $@" +ags="generate -t modules/openapi-generator/src/main/resources/scala-play-server -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g scala-play-server -o samples/server/petstore/scala-play-server --additional-properties hideGenerationTimestamp=true $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/openapi3/scala-sttp-petstore.sh b/bin/scala-sttp-petstore.sh similarity index 94% rename from bin/openapi3/scala-sttp-petstore.sh rename to bin/scala-sttp-petstore.sh index 9157368acfb0..3521fd6e419a 100755 --- a/bin/openapi3/scala-sttp-petstore.sh +++ b/bin/scala-sttp-petstore.sh @@ -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 --artifact-id 'scala-sttp-petstore' -t modules/openapi-generator/src/main/resources/scala-sttp -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g scala-sttp -o samples/openapi3/client/petstore/scala-sttp $@" +ags="generate --artifact-id 'scala-sttp-petstore' -t modules/openapi-generator/src/main/resources/scala-sttp -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g scala-sttp -o samples/client/petstore/scala-sttp $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/scalatra-petstore-server.sh b/bin/scalatra-petstore-server.sh index 4c92bd14dc3d..04d037b89ce7 100755 --- a/bin/scalatra-petstore-server.sh +++ b/bin/scalatra-petstore-server.sh @@ -22,11 +22,11 @@ executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" if [ ! -f "$executable" ] then - mvn -B clean package + mvn clean package 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/scalatra -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g scalatra -o samples/server/petstore/scalatra $@" +ags="generate -t modules/openapi-generator/src/main/resources/scalatra -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g scalatra -o samples/server/petstore/scalatra $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/scalaz-petstore.sh b/bin/scalaz-petstore.sh index acbd705caa69..ff35e33a52b3 100755 --- a/bin/scalaz-petstore.sh +++ b/bin/scalaz-petstore.sh @@ -22,11 +22,11 @@ executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" if [ ! -f "$executable" ] then - mvn -B clean package + mvn clean package 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/scalaz -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g scalaz -o samples/client/petstore/scalaz $@" +ags="generate -t modules/openapi-generator/src/main/resources/scalaz -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g scalaz -o samples/client/petstore/scalaz -DskipFormModel=true $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/utils/ensure-up-to-date b/bin/utils/ensure-up-to-date index df1f7a32d687..7d5d10f075ce 100755 --- a/bin/utils/ensure-up-to-date +++ b/bin/utils/ensure-up-to-date @@ -84,8 +84,7 @@ declare -a samples=( "${root}/bin/cpp-qt5-qhttpengine-server-petstore.sh" #"${root}/bin/openapi3/powershell-experimental-petstore.sh" "${root}/bin/scala-akka-petstore.sh" -"${root}/bin/openapi3/scala-akka-petstore.sh" -"${root}/bin/openapi3/scala-sttp-petstore.sh" +"${root}/bin/scala-sttp-petstore.sh" "${root}/bin/lua-petstore.sh" ) diff --git a/pom.xml b/pom.xml index ad6d60e0ea9e..1ffcbe0f1537 100644 --- a/pom.xml +++ b/pom.xml @@ -1293,8 +1293,8 @@ samples/openapi3/client/petstore/go-experimental samples/openapi3/client/petstore/go - samples/openapi3/client/petstore/scala-akka - samples/openapi3/client/petstore/scala-sttp + samples/client/petstore/scala-akka + samples/client/petstore/scala-sttp samples/client/petstore/scala-httpclient samples/client/petstore/scalaz samples/client/petstore/clojure @@ -1387,10 +1387,10 @@ samples/client/petstore/ruby - samples/openapi3/client/petstore/scala-akka samples/client/petstore/dart2/petstore samples/client/petstore/dart-jaguar/openapi samples/client/petstore/dart-jaguar/flutter_petstore/openapi + samples/client/petstore/scala-akka samples/client/petstore/scala-httpclient samples/client/petstore/java/feign samples/client/petstore/java/jersey1 diff --git a/samples/client/petstore/scala-akka/.openapi-generator/FILES b/samples/client/petstore/scala-akka/.openapi-generator/FILES index b0774944ac37..13da3010a5a3 100644 --- a/samples/client/petstore/scala-akka/.openapi-generator/FILES +++ b/samples/client/petstore/scala-akka/.openapi-generator/FILES @@ -13,6 +13,8 @@ src/main/scala/org/openapitools/client/core/Serializers.scala src/main/scala/org/openapitools/client/core/requests.scala src/main/scala/org/openapitools/client/model/ApiResponse.scala src/main/scala/org/openapitools/client/model/Category.scala +src/main/scala/org/openapitools/client/model/InlineObject.scala +src/main/scala/org/openapitools/client/model/InlineObject1.scala src/main/scala/org/openapitools/client/model/Order.scala src/main/scala/org/openapitools/client/model/Pet.scala src/main/scala/org/openapitools/client/model/Tag.scala diff --git a/samples/client/petstore/scala-akka/README.md b/samples/client/petstore/scala-akka/README.md index d0566cdbf506..effa8f548ebd 100644 --- a/samples/client/petstore/scala-akka/README.md +++ b/samples/client/petstore/scala-akka/README.md @@ -91,6 +91,8 @@ Class | Method | HTTP request | Description - [ApiResponse](ApiResponse.md) - [Category](Category.md) + - [InlineObject](InlineObject.md) + - [InlineObject1](InlineObject1.md) - [Order](Order.md) - [Pet](Pet.md) - [Tag](Tag.md) @@ -106,6 +108,12 @@ Authentication schemes defined for the API: - **API key parameter name**: api_key - **Location**: HTTP header +### auth_cookie + +- **Type**: API key +- **API key parameter name**: AUTH_KEY +- **Location**: + ## Author diff --git a/samples/client/petstore/scala-akka/project/build.properties b/samples/client/petstore/scala-akka/project/build.properties deleted file mode 100644 index 00b48d978b25..000000000000 --- a/samples/client/petstore/scala-akka/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.3.6 diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/PetApi.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/PetApi.scala index 658f7fb8fe31..c0ba5d4c6ae2 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/PetApi.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/PetApi.scala @@ -27,13 +27,15 @@ class PetApi(baseUrl: String) { /** * Expected answers: + * code 200 : Pet (successful operation) * code 405 : (Invalid input) * - * @param body Pet object that needs to be added to the store + * @param pet Pet object that needs to be added to the store */ - def addPet(body: Pet): ApiRequest[Unit] = - ApiRequest[Unit](ApiMethods.POST, baseUrl, "/pet", "application/json") - .withBody(body) + def addPet(pet: Pet): ApiRequest[Pet] = + ApiRequest[Pet](ApiMethods.POST, baseUrl, "/pet", "application/json") + .withBody(pet) + .withSuccessResponse[Pet](200) .withErrorResponse[Unit](405) @@ -107,15 +109,17 @@ class PetApi(baseUrl: String) { /** * Expected answers: + * code 200 : Pet (successful operation) * code 400 : (Invalid ID supplied) * code 404 : (Pet not found) * code 405 : (Validation exception) * - * @param body Pet object that needs to be added to the store + * @param pet Pet object that needs to be added to the store */ - def updatePet(body: Pet): ApiRequest[Unit] = - ApiRequest[Unit](ApiMethods.PUT, baseUrl, "/pet", "application/json") - .withBody(body) + def updatePet(pet: Pet): ApiRequest[Pet] = + ApiRequest[Pet](ApiMethods.PUT, baseUrl, "/pet", "application/json") + .withBody(pet) + .withSuccessResponse[Pet](200) .withErrorResponse[Unit](400) .withErrorResponse[Unit](404) .withErrorResponse[Unit](405) @@ -123,6 +127,7 @@ class PetApi(baseUrl: String) { /** * Expected answers: + * code 200 : (successful operation) * code 405 : (Invalid input) * * @param petId ID of pet that needs to be updated @@ -134,6 +139,7 @@ class PetApi(baseUrl: String) { .withFormParam("name", name) .withFormParam("status", status) .withPathParam("petId", petId) + .withSuccessResponse[Unit](200) .withErrorResponse[Unit](405) diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/StoreApi.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/StoreApi.scala index 534b3a4949a7..ba8a34ef6ec8 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/StoreApi.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/StoreApi.scala @@ -77,11 +77,11 @@ class StoreApi(baseUrl: String) { * code 200 : Order (successful operation) * code 400 : (Invalid Order) * - * @param body order placed for purchasing the pet + * @param order order placed for purchasing the pet */ - def placeOrder(body: Order): ApiRequest[Order] = + def placeOrder(order: Order): ApiRequest[Order] = ApiRequest[Order](ApiMethods.POST, baseUrl, "/store/order", "application/json") - .withBody(body) + .withBody(order) .withSuccessResponse[Order](200) .withErrorResponse[Unit](400) diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/UserApi.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/UserApi.scala index 4c1c94d26a45..54809067608d 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/UserApi.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/UserApi.scala @@ -29,11 +29,15 @@ class UserApi(baseUrl: String) { * Expected answers: * code 0 : (successful operation) * - * @param body Created user object + * Available security schemes: + * auth_cookie (apiKey) + * + * @param user Created user object */ - def createUser(body: User): ApiRequest[Unit] = + def createUser(user: User)(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.POST, baseUrl, "/user", "application/json") - .withBody(body) + .withApiKey(apiKey, "AUTH_KEY", COOKIE) + .withBody(user) .withDefaultSuccessResponse[Unit] @@ -41,11 +45,15 @@ class UserApi(baseUrl: String) { * Expected answers: * code 0 : (successful operation) * - * @param body List of user object + * Available security schemes: + * auth_cookie (apiKey) + * + * @param user List of user object */ - def createUsersWithArrayInput(body: Seq[User]): ApiRequest[Unit] = + def createUsersWithArrayInput(user: Seq[User])(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.POST, baseUrl, "/user/createWithArray", "application/json") - .withBody(body) + .withApiKey(apiKey, "AUTH_KEY", COOKIE) + .withBody(user) .withDefaultSuccessResponse[Unit] @@ -53,11 +61,15 @@ class UserApi(baseUrl: String) { * Expected answers: * code 0 : (successful operation) * - * @param body List of user object + * Available security schemes: + * auth_cookie (apiKey) + * + * @param user List of user object */ - def createUsersWithListInput(body: Seq[User]): ApiRequest[Unit] = + def createUsersWithListInput(user: Seq[User])(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.POST, baseUrl, "/user/createWithList", "application/json") - .withBody(body) + .withApiKey(apiKey, "AUTH_KEY", COOKIE) + .withBody(user) .withDefaultSuccessResponse[Unit] @@ -68,10 +80,14 @@ class UserApi(baseUrl: String) { * code 400 : (Invalid username supplied) * code 404 : (User not found) * + * Available security schemes: + * auth_cookie (apiKey) + * * @param username The name that needs to be deleted */ - def deleteUser(username: String): ApiRequest[Unit] = + def deleteUser(username: String)(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.DELETE, baseUrl, "/user/{username}", "application/json") + .withApiKey(apiKey, "AUTH_KEY", COOKIE) .withPathParam("username", username) .withErrorResponse[Unit](400) .withErrorResponse[Unit](404) @@ -97,6 +113,7 @@ class UserApi(baseUrl: String) { * Expected answers: * code 200 : String (successful operation) * Headers : + * Set-Cookie - Cookie authentication key for use with the `auth_cookie` apiKey authentication. * X-Rate-Limit - calls per hour allowed by the user * X-Expires-After - date in UTC when toekn expires * code 400 : (Invalid username/password supplied) @@ -112,6 +129,7 @@ class UserApi(baseUrl: String) { .withErrorResponse[Unit](400) object LoginUserHeaders { + def setCookie(r: ApiReturnWithHeaders) = r.getStringHeader("Set-Cookie") def xRateLimit(r: ApiReturnWithHeaders) = r.getIntHeader("X-Rate-Limit") def xExpiresAfter(r: ApiReturnWithHeaders) = r.getOffsetDateTimeHeader("X-Expires-After") } @@ -119,9 +137,13 @@ class UserApi(baseUrl: String) { /** * Expected answers: * code 0 : (successful operation) + * + * Available security schemes: + * auth_cookie (apiKey) */ - def logoutUser(): ApiRequest[Unit] = + def logoutUser()(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.GET, baseUrl, "/user/logout", "application/json") + .withApiKey(apiKey, "AUTH_KEY", COOKIE) .withDefaultSuccessResponse[Unit] @@ -132,12 +154,16 @@ class UserApi(baseUrl: String) { * code 400 : (Invalid user supplied) * code 404 : (User not found) * + * Available security schemes: + * auth_cookie (apiKey) + * * @param username name that need to be deleted - * @param body Updated user object + * @param user Updated user object */ - def updateUser(username: String, body: User): ApiRequest[Unit] = + def updateUser(username: String, user: User)(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.PUT, baseUrl, "/user/{username}", "application/json") - .withBody(body) + .withApiKey(apiKey, "AUTH_KEY", COOKIE) + .withBody(user) .withPathParam("username", username) .withErrorResponse[Unit](400) .withErrorResponse[Unit](404) diff --git a/samples/openapi3/client/petstore/scala-akka/src/test/scala/PetApiTest.scala b/samples/client/petstore/scala-akka/src/test/scala/PetApiTest.scala similarity index 100% rename from samples/openapi3/client/petstore/scala-akka/src/test/scala/PetApiTest.scala rename to samples/client/petstore/scala-akka/src/test/scala/PetApiTest.scala diff --git a/samples/client/petstore/scala-gatling/.openapi-generator/VERSION b/samples/client/petstore/scala-gatling/.openapi-generator/VERSION index bfbf77eb7fad..d99e7162d01f 100644 --- a/samples/client/petstore/scala-gatling/.openapi-generator/VERSION +++ b/samples/client/petstore/scala-gatling/.openapi-generator/VERSION @@ -1 +1 @@ -4.3.0-SNAPSHOT \ No newline at end of file +5.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/scala-gatling/src/gatling/scala/org/openapitools/client/model/InlineObject.scala b/samples/client/petstore/scala-gatling/src/gatling/scala/org/openapitools/client/model/InlineObject.scala new file mode 100644 index 000000000000..672c7cb6a701 --- /dev/null +++ b/samples/client/petstore/scala-gatling/src/gatling/scala/org/openapitools/client/model/InlineObject.scala @@ -0,0 +1,18 @@ + +package org.openapitools.client.model + + +case class InlineObject ( + /* Updated name of the pet */ + _name: Option[String], + /* Updated status of the pet */ + _status: Option[String] +) +object InlineObject { + def toStringBody(var_name: Object, var_status: Object) = + s""" + | { + | "name":$var_name,"status":$var_status + | } + """.stripMargin +} diff --git a/samples/client/petstore/scala-gatling/src/gatling/scala/org/openapitools/client/model/InlineObject1.scala b/samples/client/petstore/scala-gatling/src/gatling/scala/org/openapitools/client/model/InlineObject1.scala new file mode 100644 index 000000000000..60e7afd58786 --- /dev/null +++ b/samples/client/petstore/scala-gatling/src/gatling/scala/org/openapitools/client/model/InlineObject1.scala @@ -0,0 +1,19 @@ + +package org.openapitools.client.model + +import java.io.File + +case class InlineObject1 ( + /* Additional data to pass to server */ + _additionalMetadata: Option[String], + /* file to upload */ + _file: Option[File] +) +object InlineObject1 { + def toStringBody(var_additionalMetadata: Object, var_file: Object) = + s""" + | { + | "additionalMetadata":$var_additionalMetadata,"file":$var_file + | } + """.stripMargin +} diff --git a/samples/client/petstore/scala-httpclient/.openapi-generator/VERSION b/samples/client/petstore/scala-httpclient/.openapi-generator/VERSION index bfbf77eb7fad..d99e7162d01f 100644 --- a/samples/client/petstore/scala-httpclient/.openapi-generator/VERSION +++ b/samples/client/petstore/scala-httpclient/.openapi-generator/VERSION @@ -1 +1 @@ -4.3.0-SNAPSHOT \ No newline at end of file +5.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/api/PetApi.scala b/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/api/PetApi.scala index 768cb5c0b5f3..7ef67d6a3cdb 100644 --- a/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/api/PetApi.scala +++ b/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/api/PetApi.scala @@ -80,11 +80,11 @@ class PetApi( * Add a new pet to the store * * - * @param body Pet object that needs to be added to the store - * @return void + * @param pet Pet object that needs to be added to the store + * @return Pet */ - def addPet(body: Pet) = { - val await = Try(Await.result(addPetAsync(body), Duration.Inf)) + def addPet(pet: Pet): Option[Pet] = { + val await = Try(Await.result(addPetAsync(pet), Duration.Inf)) await match { case Success(i) => Some(await.get) case Failure(t) => None @@ -95,11 +95,11 @@ class PetApi( * Add a new pet to the store asynchronously * * - * @param body Pet object that needs to be added to the store - * @return Future(void) + * @param pet Pet object that needs to be added to the store + * @return Future(Pet) */ - def addPetAsync(body: Pet) = { - helper.addPet(body) + def addPetAsync(pet: Pet): Future[Pet] = { + helper.addPet(pet) } /** @@ -212,11 +212,11 @@ class PetApi( * Update an existing pet * * - * @param body Pet object that needs to be added to the store - * @return void + * @param pet Pet object that needs to be added to the store + * @return Pet */ - def updatePet(body: Pet) = { - val await = Try(Await.result(updatePetAsync(body), Duration.Inf)) + def updatePet(pet: Pet): Option[Pet] = { + val await = Try(Await.result(updatePetAsync(pet), Duration.Inf)) await match { case Success(i) => Some(await.get) case Failure(t) => None @@ -227,11 +227,11 @@ class PetApi( * Update an existing pet asynchronously * * - * @param body Pet object that needs to be added to the store - * @return Future(void) + * @param pet Pet object that needs to be added to the store + * @return Future(Pet) */ - def updatePetAsync(body: Pet) = { - helper.updatePet(body) + def updatePetAsync(pet: Pet): Future[Pet] = { + helper.updatePet(pet) } /** @@ -298,7 +298,7 @@ class PetApi( class PetApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) { - def addPet(body: Pet)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Pet]): Future[Unit] = { + def addPet(pet: Pet)(implicit reader: ClientResponseReader[Pet], writer: RequestWriter[Pet]): Future[Pet] = { // create path and map variables val path = (addFmt("/pet")) @@ -306,9 +306,9 @@ class PetApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends val queryParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String] - if (body == null) throw new Exception("Missing required parameter 'body' when calling PetApi->addPet") + if (pet == null) throw new Exception("Missing required parameter 'pet' when calling PetApi->addPet") - val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body)) + val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(pet)) resFuture flatMap { resp => val status = Response.Status.fromStatusCode(resp.statusCode) status.getFamily match { @@ -406,7 +406,7 @@ class PetApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends } } - def updatePet(body: Pet)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Pet]): Future[Unit] = { + def updatePet(pet: Pet)(implicit reader: ClientResponseReader[Pet], writer: RequestWriter[Pet]): Future[Pet] = { // create path and map variables val path = (addFmt("/pet")) @@ -414,9 +414,9 @@ class PetApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends val queryParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String] - if (body == null) throw new Exception("Missing required parameter 'body' when calling PetApi->updatePet") + if (pet == null) throw new Exception("Missing required parameter 'pet' when calling PetApi->updatePet") - val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(body)) + val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(pet)) resFuture flatMap { resp => val status = Response.Status.fromStatusCode(resp.statusCode) status.getFamily match { diff --git a/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/api/StoreApi.scala b/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/api/StoreApi.scala index 4328080db938..51b392338505 100644 --- a/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/api/StoreApi.scala +++ b/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/api/StoreApi.scala @@ -154,11 +154,11 @@ class StoreApi( * Place an order for a pet * * - * @param body order placed for purchasing the pet + * @param order order placed for purchasing the pet * @return Order */ - def placeOrder(body: Order): Option[Order] = { - val await = Try(Await.result(placeOrderAsync(body), Duration.Inf)) + def placeOrder(order: Order): Option[Order] = { + val await = Try(Await.result(placeOrderAsync(order), Duration.Inf)) await match { case Success(i) => Some(await.get) case Failure(t) => None @@ -169,11 +169,11 @@ class StoreApi( * Place an order for a pet asynchronously * * - * @param body order placed for purchasing the pet + * @param order order placed for purchasing the pet * @return Future(Order) */ - def placeOrderAsync(body: Order): Future[Order] = { - helper.placeOrder(body) + def placeOrderAsync(order: Order): Future[Order] = { + helper.placeOrder(order) } } @@ -241,7 +241,7 @@ class StoreApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extend } } - def placeOrder(body: Order)(implicit reader: ClientResponseReader[Order], writer: RequestWriter[Order]): Future[Order] = { + def placeOrder(order: Order)(implicit reader: ClientResponseReader[Order], writer: RequestWriter[Order]): Future[Order] = { // create path and map variables val path = (addFmt("/store/order")) @@ -249,9 +249,9 @@ class StoreApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extend val queryParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String] - if (body == null) throw new Exception("Missing required parameter 'body' when calling StoreApi->placeOrder") + if (order == null) throw new Exception("Missing required parameter 'order' when calling StoreApi->placeOrder") - val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body)) + val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(order)) resFuture flatMap { resp => val status = Response.Status.fromStatusCode(resp.statusCode) status.getFamily match { diff --git a/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/api/UserApi.scala b/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/api/UserApi.scala index efd7f1ef97fa..585fd19ee512 100644 --- a/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/api/UserApi.scala +++ b/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/api/UserApi.scala @@ -78,11 +78,11 @@ class UserApi( * Create user * This can only be done by the logged in user. * - * @param body Created user object + * @param user Created user object * @return void */ - def createUser(body: User) = { - val await = Try(Await.result(createUserAsync(body), Duration.Inf)) + def createUser(user: User) = { + val await = Try(Await.result(createUserAsync(user), Duration.Inf)) await match { case Success(i) => Some(await.get) case Failure(t) => None @@ -93,22 +93,22 @@ class UserApi( * Create user asynchronously * This can only be done by the logged in user. * - * @param body Created user object + * @param user Created user object * @return Future(void) */ - def createUserAsync(body: User) = { - helper.createUser(body) + def createUserAsync(user: User) = { + helper.createUser(user) } /** * Creates list of users with given input array * * - * @param body List of user object + * @param user List of user object * @return void */ - def createUsersWithArrayInput(body: List[User]) = { - val await = Try(Await.result(createUsersWithArrayInputAsync(body), Duration.Inf)) + def createUsersWithArrayInput(user: List[User]) = { + val await = Try(Await.result(createUsersWithArrayInputAsync(user), Duration.Inf)) await match { case Success(i) => Some(await.get) case Failure(t) => None @@ -119,22 +119,22 @@ class UserApi( * Creates list of users with given input array asynchronously * * - * @param body List of user object + * @param user List of user object * @return Future(void) */ - def createUsersWithArrayInputAsync(body: List[User]) = { - helper.createUsersWithArrayInput(body) + def createUsersWithArrayInputAsync(user: List[User]) = { + helper.createUsersWithArrayInput(user) } /** * Creates list of users with given input array * * - * @param body List of user object + * @param user List of user object * @return void */ - def createUsersWithListInput(body: List[User]) = { - val await = Try(Await.result(createUsersWithListInputAsync(body), Duration.Inf)) + def createUsersWithListInput(user: List[User]) = { + val await = Try(Await.result(createUsersWithListInputAsync(user), Duration.Inf)) await match { case Success(i) => Some(await.get) case Failure(t) => None @@ -145,11 +145,11 @@ class UserApi( * Creates list of users with given input array asynchronously * * - * @param body List of user object + * @param user List of user object * @return Future(void) */ - def createUsersWithListInputAsync(body: List[User]) = { - helper.createUsersWithListInput(body) + def createUsersWithListInputAsync(user: List[User]) = { + helper.createUsersWithListInput(user) } /** @@ -261,11 +261,11 @@ class UserApi( * This can only be done by the logged in user. * * @param username name that need to be deleted - * @param body Updated user object + * @param user Updated user object * @return void */ - def updateUser(username: String, body: User) = { - val await = Try(Await.result(updateUserAsync(username, body), Duration.Inf)) + def updateUser(username: String, user: User) = { + val await = Try(Await.result(updateUserAsync(username, user), Duration.Inf)) await match { case Success(i) => Some(await.get) case Failure(t) => None @@ -277,18 +277,18 @@ class UserApi( * This can only be done by the logged in user. * * @param username name that need to be deleted - * @param body Updated user object + * @param user Updated user object * @return Future(void) */ - def updateUserAsync(username: String, body: User) = { - helper.updateUser(username, body) + def updateUserAsync(username: String, user: User) = { + helper.updateUser(username, user) } } class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) { - def createUser(body: User)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = { + def createUser(user: User)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = { // create path and map variables val path = (addFmt("/user")) @@ -296,9 +296,9 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends val queryParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String] - if (body == null) throw new Exception("Missing required parameter 'body' when calling UserApi->createUser") + if (user == null) throw new Exception("Missing required parameter 'user' when calling UserApi->createUser") - val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body)) + val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(user)) resFuture flatMap { resp => val status = Response.Status.fromStatusCode(resp.statusCode) status.getFamily match { @@ -308,7 +308,7 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends } } - def createUsersWithArrayInput(body: List[User])(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = { + def createUsersWithArrayInput(user: List[User])(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = { // create path and map variables val path = (addFmt("/user/createWithArray")) @@ -316,9 +316,9 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends val queryParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String] - if (body == null) throw new Exception("Missing required parameter 'body' when calling UserApi->createUsersWithArrayInput") + if (user == null) throw new Exception("Missing required parameter 'user' when calling UserApi->createUsersWithArrayInput") - val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body)) + val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(user)) resFuture flatMap { resp => val status = Response.Status.fromStatusCode(resp.statusCode) status.getFamily match { @@ -328,7 +328,7 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends } } - def createUsersWithListInput(body: List[User])(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = { + def createUsersWithListInput(user: List[User])(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = { // create path and map variables val path = (addFmt("/user/createWithList")) @@ -336,9 +336,9 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends val queryParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String] - if (body == null) throw new Exception("Missing required parameter 'body' when calling UserApi->createUsersWithListInput") + if (user == null) throw new Exception("Missing required parameter 'user' when calling UserApi->createUsersWithListInput") - val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body)) + val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(user)) resFuture flatMap { resp => val status = Response.Status.fromStatusCode(resp.statusCode) status.getFamily match { @@ -438,7 +438,7 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends } def updateUser(username: String, - body: User)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = { + user: User)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = { // create path and map variables val path = (addFmt("/user/{username}") replaceAll("\\{" + "username" + "\\}", username.toString)) @@ -449,9 +449,9 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends if (username == null) throw new Exception("Missing required parameter 'username' when calling UserApi->updateUser") - if (body == null) throw new Exception("Missing required parameter 'body' when calling UserApi->updateUser") + if (user == null) throw new Exception("Missing required parameter 'user' when calling UserApi->updateUser") - val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(body)) + val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(user)) resFuture flatMap { resp => val status = Response.Status.fromStatusCode(resp.statusCode) status.getFamily match { diff --git a/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/model/InlineObject.scala b/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/model/InlineObject.scala new file mode 100644 index 000000000000..071b023e1a57 --- /dev/null +++ b/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/model/InlineObject.scala @@ -0,0 +1,22 @@ +/** + * 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. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.openapitools.client.model + + +case class InlineObject ( + // Updated name of the pet + name: Option[String] = None, + // Updated status of the pet + status: Option[String] = None +) + diff --git a/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/model/InlineObject1.scala b/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/model/InlineObject1.scala new file mode 100644 index 000000000000..520d5858eb9a --- /dev/null +++ b/samples/client/petstore/scala-httpclient/src/main/scala/org/openapitools/client/model/InlineObject1.scala @@ -0,0 +1,23 @@ +/** + * 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. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.openapitools.client.model + +import java.io.File + +case class InlineObject1 ( + // Additional data to pass to server + additionalMetadata: Option[String] = None, + // file to upload + file: Option[File] = None +) + diff --git a/samples/openapi3/client/petstore/scala-akka/.openapi-generator-ignore b/samples/client/petstore/scala-sttp/.openapi-generator-ignore similarity index 100% rename from samples/openapi3/client/petstore/scala-akka/.openapi-generator-ignore rename to samples/client/petstore/scala-sttp/.openapi-generator-ignore diff --git a/samples/openapi3/client/petstore/scala-akka/.openapi-generator/FILES b/samples/client/petstore/scala-sttp/.openapi-generator/FILES similarity index 84% rename from samples/openapi3/client/petstore/scala-akka/.openapi-generator/FILES rename to samples/client/petstore/scala-sttp/.openapi-generator/FILES index 13da3010a5a3..ffe27d280813 100644 --- a/samples/openapi3/client/petstore/scala-akka/.openapi-generator/FILES +++ b/samples/client/petstore/scala-sttp/.openapi-generator/FILES @@ -1,14 +1,10 @@ README.md build.sbt -pom.xml -src/main/resources/reference.conf src/main/scala/org/openapitools/client/api/EnumsSerializers.scala src/main/scala/org/openapitools/client/api/PetApi.scala src/main/scala/org/openapitools/client/api/StoreApi.scala src/main/scala/org/openapitools/client/api/UserApi.scala src/main/scala/org/openapitools/client/core/ApiInvoker.scala -src/main/scala/org/openapitools/client/core/ApiRequest.scala -src/main/scala/org/openapitools/client/core/ApiSettings.scala src/main/scala/org/openapitools/client/core/Serializers.scala src/main/scala/org/openapitools/client/core/requests.scala src/main/scala/org/openapitools/client/model/ApiResponse.scala diff --git a/samples/openapi3/client/petstore/scala-akka/.openapi-generator/VERSION b/samples/client/petstore/scala-sttp/.openapi-generator/VERSION similarity index 100% rename from samples/openapi3/client/petstore/scala-akka/.openapi-generator/VERSION rename to samples/client/petstore/scala-sttp/.openapi-generator/VERSION diff --git a/samples/openapi3/client/petstore/scala-akka/README.md b/samples/client/petstore/scala-sttp/README.md similarity index 71% rename from samples/openapi3/client/petstore/scala-akka/README.md rename to samples/client/petstore/scala-sttp/README.md index effa8f548ebd..891ebf40fc01 100644 --- a/samples/openapi3/client/petstore/scala-akka/README.md +++ b/samples/client/petstore/scala-sttp/README.md @@ -1,4 +1,4 @@ -# scala-akka-petstore-client +# 'scala-sttp-petstore' OpenAPI Petstore - API version: 1.0.0 @@ -37,7 +37,7 @@ Add this dependency to your project's POM: ```xml org.openapitools - scala-akka-petstore-client + 'scala-sttp-petstore' 1.0.0 compile @@ -48,13 +48,13 @@ Add this dependency to your project's POM: Add this dependency to your project's build file: ```groovy -compile "org.openapitools:scala-akka-petstore-client:1.0.0" +compile "org.openapitools:'scala-sttp-petstore':1.0.0" ``` ### SBT users ```scala -libraryDependencies += "org.openapitools" % "scala-akka-petstore-client" % "1.0.0" +libraryDependencies += "org.openapitools" % "'scala-sttp-petstore'" % "1.0.0" ``` ## Getting Started @@ -66,25 +66,25 @@ All URIs are relative to *http://petstore.swagger.io/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- *PetApi* | **addPet** | **POST** /pet | Add a new pet to the store -*PetApi* | **deletePet** | **DELETE** /pet/{petId} | Deletes a pet +*PetApi* | **deletePet** | **DELETE** /pet/${petId} | Deletes a pet *PetApi* | **findPetsByStatus** | **GET** /pet/findByStatus | Finds Pets by status *PetApi* | **findPetsByTags** | **GET** /pet/findByTags | Finds Pets by tags -*PetApi* | **getPetById** | **GET** /pet/{petId} | Find pet by ID +*PetApi* | **getPetById** | **GET** /pet/${petId} | Find pet by ID *PetApi* | **updatePet** | **PUT** /pet | Update an existing pet -*PetApi* | **updatePetWithForm** | **POST** /pet/{petId} | Updates a pet in the store with form data -*PetApi* | **uploadFile** | **POST** /pet/{petId}/uploadImage | uploads an image -*StoreApi* | **deleteOrder** | **DELETE** /store/order/{orderId} | Delete purchase order by ID +*PetApi* | **updatePetWithForm** | **POST** /pet/${petId} | Updates a pet in the store with form data +*PetApi* | **uploadFile** | **POST** /pet/${petId}/uploadImage | uploads an image +*StoreApi* | **deleteOrder** | **DELETE** /store/order/${orderId} | Delete purchase order by ID *StoreApi* | **getInventory** | **GET** /store/inventory | Returns pet inventories by status -*StoreApi* | **getOrderById** | **GET** /store/order/{orderId} | Find purchase order by ID +*StoreApi* | **getOrderById** | **GET** /store/order/${orderId} | Find purchase order by ID *StoreApi* | **placeOrder** | **POST** /store/order | Place an order for a pet *UserApi* | **createUser** | **POST** /user | Create user *UserApi* | **createUsersWithArrayInput** | **POST** /user/createWithArray | Creates list of users with given input array *UserApi* | **createUsersWithListInput** | **POST** /user/createWithList | Creates list of users with given input array -*UserApi* | **deleteUser** | **DELETE** /user/{username} | Delete user -*UserApi* | **getUserByName** | **GET** /user/{username} | Get user by user name +*UserApi* | **deleteUser** | **DELETE** /user/${username} | Delete user +*UserApi* | **getUserByName** | **GET** /user/${username} | Get user by user name *UserApi* | **loginUser** | **GET** /user/login | Logs user into the system *UserApi* | **logoutUser** | **GET** /user/logout | Logs out current logged in user session -*UserApi* | **updateUser** | **PUT** /user/{username} | Updated user +*UserApi* | **updateUser** | **PUT** /user/${username} | Updated user ## Documentation for Models @@ -108,12 +108,6 @@ Authentication schemes defined for the API: - **API key parameter name**: api_key - **Location**: HTTP header -### auth_cookie - -- **Type**: API key -- **API key parameter name**: AUTH_KEY -- **Location**: - ## Author diff --git a/samples/client/petstore/scala-sttp/build.sbt b/samples/client/petstore/scala-sttp/build.sbt new file mode 100644 index 000000000000..68b09b1d6dd8 --- /dev/null +++ b/samples/client/petstore/scala-sttp/build.sbt @@ -0,0 +1,24 @@ +version := "1.0.0" +name := "'scala-sttp-petstore'" +organization := "org.openapitools" + +scalaVersion := "2.13.0" + +crossScalaVersions := Seq(scalaVersion.value, "2.12.10", "2.11.12") + +libraryDependencies ++= Seq( + "com.softwaremill.sttp.client" %% "core" % "2.0.0", + "com.softwaremill.sttp.client" %% "json4s" % "2.0.0", + "org.json4s" %% "json4s-jackson" % "3.6.7", + // test dependencies + "org.scalatest" %% "scalatest" % "3.0.8" % Test, + "junit" % "junit" % "4.13" % "test" +) + +scalacOptions := Seq( + "-unchecked", + "-deprecation", + "-feature" +) + +publishArtifact in (Compile, packageDoc) := false \ No newline at end of file diff --git a/samples/client/petstore/scala-sttp/pom.xml b/samples/client/petstore/scala-sttp/pom.xml new file mode 100644 index 000000000000..6b6a83b21e2d --- /dev/null +++ b/samples/client/petstore/scala-sttp/pom.xml @@ -0,0 +1,32 @@ + + 4.0.0 + org.openapitools + scalaz-sttp-petstore-client + pom + 1.0-SNAPSHOT + scala-sttp-petstore-client + + + + org.codehaus.mojo + exec-maven-plugin + 1.5.0 + + + sbt-test + integration-test + + exec + + + sbt + + test + + + + + + + + diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/EnumsSerializers.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/EnumsSerializers.scala similarity index 100% rename from samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/EnumsSerializers.scala rename to samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/EnumsSerializers.scala diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/PetApi.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/PetApi.scala similarity index 51% rename from samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/PetApi.scala rename to samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/PetApi.scala index c0ba5d4c6ae2..5211d09c9c5c 100644 --- a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/PetApi.scala +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/PetApi.scala @@ -15,16 +15,20 @@ import org.openapitools.client.model.ApiResponse import java.io.File import org.openapitools.client.model.Pet import org.openapitools.client.core._ -import org.openapitools.client.core.CollectionFormats._ -import org.openapitools.client.core.ApiKeyLocations._ +import alias._ +import sttp.client._ +import sttp.model.Method object PetApi { - def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new PetApi(baseUrl) + def apply(baseUrl: String = "http://petstore.swagger.io/v2")(implicit serializer: SttpSerializer) = new PetApi(baseUrl) } -class PetApi(baseUrl: String) { - +class PetApi(baseUrl: String)(implicit serializer: SttpSerializer) { + + import Helpers._ + import serializer._ + /** * Expected answers: * code 200 : Pet (successful operation) @@ -32,12 +36,12 @@ class PetApi(baseUrl: String) { * * @param pet Pet object that needs to be added to the store */ - def addPet(pet: Pet): ApiRequest[Pet] = - ApiRequest[Pet](ApiMethods.POST, baseUrl, "/pet", "application/json") - .withBody(pet) - .withSuccessResponse[Pet](200) - .withErrorResponse[Unit](405) - + def addPet(pet: Pet): ApiRequestT[Pet] = + basicRequest + .method(Method.POST, uri"$baseUrl/pet") + .contentType("application/json") + .body(pet) + .response(asJson[Pet]) /** * Expected answers: @@ -46,12 +50,12 @@ class PetApi(baseUrl: String) { * @param petId Pet id to delete * @param apiKey */ - def deletePet(petId: Long, apiKey: Option[String] = None): ApiRequest[Unit] = - ApiRequest[Unit](ApiMethods.DELETE, baseUrl, "/pet/{petId}", "application/json") - .withPathParam("petId", petId) - .withHeaderParam("api_key", apiKey) - .withErrorResponse[Unit](400) - + def deletePet(petId: Long, apiKey: Option[String] = None): ApiRequestT[Unit] = + basicRequest + .method(Method.DELETE, uri"$baseUrl/pet/${petId}") + .contentType("application/json") + .header("api_key", apiKey) + .response(asJson[Unit]) /** * Multiple status values can be provided with comma separated strings @@ -62,12 +66,11 @@ class PetApi(baseUrl: String) { * * @param status Status values that need to be considered for filter */ - def findPetsByStatus(status: Seq[String]): ApiRequest[Seq[Pet]] = - ApiRequest[Seq[Pet]](ApiMethods.GET, baseUrl, "/pet/findByStatus", "application/json") - .withQueryParam("status", ArrayValues(status, CSV)) - .withSuccessResponse[Seq[Pet]](200) - .withErrorResponse[Unit](400) - + def findPetsByStatus(status: Seq[String]): ApiRequestT[Seq[Pet]] = + basicRequest + .method(Method.GET, uri"$baseUrl/pet/findByStatus?status=$status") + .contentType("application/json") + .response(asJson[Seq[Pet]]) /** * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -78,12 +81,11 @@ class PetApi(baseUrl: String) { * * @param tags Tags to filter by */ - def findPetsByTags(tags: Seq[String]): ApiRequest[Seq[Pet]] = - ApiRequest[Seq[Pet]](ApiMethods.GET, baseUrl, "/pet/findByTags", "application/json") - .withQueryParam("tags", ArrayValues(tags, CSV)) - .withSuccessResponse[Seq[Pet]](200) - .withErrorResponse[Unit](400) - + def findPetsByTags(tags: Seq[String]): ApiRequestT[Seq[Pet]] = + basicRequest + .method(Method.GET, uri"$baseUrl/pet/findByTags?tags=$tags") + .contentType("application/json") + .response(asJson[Seq[Pet]]) /** * Returns a single pet @@ -98,14 +100,12 @@ class PetApi(baseUrl: String) { * * @param petId ID of pet to return */ - def getPetById(petId: Long)(implicit apiKey: ApiKeyValue): ApiRequest[Pet] = - ApiRequest[Pet](ApiMethods.GET, baseUrl, "/pet/{petId}", "application/json") - .withApiKey(apiKey, "api_key", HEADER) - .withPathParam("petId", petId) - .withSuccessResponse[Pet](200) - .withErrorResponse[Unit](400) - .withErrorResponse[Unit](404) - + def getPetById(petId: Long)(implicit apiKey: ApiKeyValue): ApiRequestT[Pet] = + basicRequest + .method(Method.GET, uri"$baseUrl/pet/${petId}") + .contentType("application/json") + .header("api_key", apiKey.value) + .response(asJson[Pet]) /** * Expected answers: @@ -116,32 +116,30 @@ class PetApi(baseUrl: String) { * * @param pet Pet object that needs to be added to the store */ - def updatePet(pet: Pet): ApiRequest[Pet] = - ApiRequest[Pet](ApiMethods.PUT, baseUrl, "/pet", "application/json") - .withBody(pet) - .withSuccessResponse[Pet](200) - .withErrorResponse[Unit](400) - .withErrorResponse[Unit](404) - .withErrorResponse[Unit](405) - + def updatePet(pet: Pet): ApiRequestT[Pet] = + basicRequest + .method(Method.PUT, uri"$baseUrl/pet") + .contentType("application/json") + .body(pet) + .response(asJson[Pet]) /** * Expected answers: - * code 200 : (successful operation) * code 405 : (Invalid input) * * @param petId ID of pet that needs to be updated * @param name Updated name of the pet * @param status Updated status of the pet */ - def updatePetWithForm(petId: Long, name: Option[String] = None, status: Option[String] = None): ApiRequest[Unit] = - ApiRequest[Unit](ApiMethods.POST, baseUrl, "/pet/{petId}", "application/x-www-form-urlencoded") - .withFormParam("name", name) - .withFormParam("status", status) - .withPathParam("petId", petId) - .withSuccessResponse[Unit](200) - .withErrorResponse[Unit](405) - + def updatePetWithForm(petId: Long, name: Option[String] = None, status: Option[String] = None): ApiRequestT[Unit] = + basicRequest + .method(Method.POST, uri"$baseUrl/pet/${petId}") + .contentType("application/x-www-form-urlencoded") + .body(Map( + "name" -> name, + "status" -> status, + )) + .response(asJson[Unit]) /** * Expected answers: @@ -151,15 +149,15 @@ class PetApi(baseUrl: String) { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - def uploadFile(petId: Long, additionalMetadata: Option[String] = None, file: Option[File] = None): ApiRequest[ApiResponse] = - ApiRequest[ApiResponse](ApiMethods.POST, baseUrl, "/pet/{petId}/uploadImage", "multipart/form-data") - .withFormParam("additionalMetadata", additionalMetadata) - .withFormParam("file", file) - .withPathParam("petId", petId) - .withSuccessResponse[ApiResponse](200) - - - + def uploadFile(petId: Long, additionalMetadata: Option[String] = None, file: Option[File] = None): ApiRequestT[ApiResponse] = + basicRequest + .method(Method.POST, uri"$baseUrl/pet/${petId}/uploadImage") + .contentType("multipart/form-data") + .body(Map( + "additionalMetadata" -> additionalMetadata, + "file" -> file, + )) + .response(asJson[ApiResponse]) } diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/StoreApi.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/StoreApi.scala similarity index 53% rename from samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/StoreApi.scala rename to samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/StoreApi.scala index ba8a34ef6ec8..907cc9f42f0f 100644 --- a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/StoreApi.scala +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/StoreApi.scala @@ -13,16 +13,20 @@ package org.openapitools.client.api import org.openapitools.client.model.Order import org.openapitools.client.core._ -import org.openapitools.client.core.CollectionFormats._ -import org.openapitools.client.core.ApiKeyLocations._ +import alias._ +import sttp.client._ +import sttp.model.Method object StoreApi { - def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new StoreApi(baseUrl) + def apply(baseUrl: String = "http://petstore.swagger.io/v2")(implicit serializer: SttpSerializer) = new StoreApi(baseUrl) } -class StoreApi(baseUrl: String) { - +class StoreApi(baseUrl: String)(implicit serializer: SttpSerializer) { + + import Helpers._ + import serializer._ + /** * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @@ -32,12 +36,11 @@ class StoreApi(baseUrl: String) { * * @param orderId ID of the order that needs to be deleted */ - def deleteOrder(orderId: String): ApiRequest[Unit] = - ApiRequest[Unit](ApiMethods.DELETE, baseUrl, "/store/order/{orderId}", "application/json") - .withPathParam("orderId", orderId) - .withErrorResponse[Unit](400) - .withErrorResponse[Unit](404) - + def deleteOrder(orderId: String): ApiRequestT[Unit] = + basicRequest + .method(Method.DELETE, uri"$baseUrl/store/order/${orderId}") + .contentType("application/json") + .response(asJson[Unit]) /** * Returns a map of status codes to quantities @@ -48,11 +51,12 @@ class StoreApi(baseUrl: String) { * Available security schemes: * api_key (apiKey) */ - def getInventory()(implicit apiKey: ApiKeyValue): ApiRequest[Map[String, Int]] = - ApiRequest[Map[String, Int]](ApiMethods.GET, baseUrl, "/store/inventory", "application/json") - .withApiKey(apiKey, "api_key", HEADER) - .withSuccessResponse[Map[String, Int]](200) - + def getInventory()(implicit apiKey: ApiKeyValue): ApiRequestT[Map[String, Int]] = + basicRequest + .method(Method.GET, uri"$baseUrl/store/inventory") + .contentType("application/json") + .header("api_key", apiKey.value) + .response(asJson[Map[String, Int]]) /** * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions @@ -64,13 +68,11 @@ class StoreApi(baseUrl: String) { * * @param orderId ID of pet that needs to be fetched */ - def getOrderById(orderId: Long): ApiRequest[Order] = - ApiRequest[Order](ApiMethods.GET, baseUrl, "/store/order/{orderId}", "application/json") - .withPathParam("orderId", orderId) - .withSuccessResponse[Order](200) - .withErrorResponse[Unit](400) - .withErrorResponse[Unit](404) - + def getOrderById(orderId: Long): ApiRequestT[Order] = + basicRequest + .method(Method.GET, uri"$baseUrl/store/order/${orderId}") + .contentType("application/json") + .response(asJson[Order]) /** * Expected answers: @@ -79,14 +81,12 @@ class StoreApi(baseUrl: String) { * * @param order order placed for purchasing the pet */ - def placeOrder(order: Order): ApiRequest[Order] = - ApiRequest[Order](ApiMethods.POST, baseUrl, "/store/order", "application/json") - .withBody(order) - .withSuccessResponse[Order](200) - .withErrorResponse[Unit](400) - - - + def placeOrder(order: Order): ApiRequestT[Order] = + basicRequest + .method(Method.POST, uri"$baseUrl/store/order") + .contentType("application/json") + .body(order) + .response(asJson[Order]) } diff --git a/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/UserApi.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/UserApi.scala new file mode 100644 index 000000000000..34679dea5d7a --- /dev/null +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/UserApi.scala @@ -0,0 +1,170 @@ +/** + * 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. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package org.openapitools.client.api + +import org.openapitools.client.model.User +import org.openapitools.client.core._ +import alias._ +import sttp.client._ +import sttp.model.Method + +object UserApi { + + def apply(baseUrl: String = "http://petstore.swagger.io/v2")(implicit serializer: SttpSerializer) = new UserApi(baseUrl) +} + +class UserApi(baseUrl: String)(implicit serializer: SttpSerializer) { + + import Helpers._ + import serializer._ + + /** + * This can only be done by the logged in user. + * + * Expected answers: + * code 0 : (successful operation) + * + * Available security schemes: + * api_key (apiKey) + * + * @param user Created user object + */ + def createUser(user: User)(implicit apiKey: ApiKeyValue): ApiRequestT[Unit] = + basicRequest + .method(Method.POST, uri"$baseUrl/user") + .contentType("application/json") + .header("api_key", apiKey.value) + .body(user) + .response(asJson[Unit]) + + /** + * Expected answers: + * code 0 : (successful operation) + * + * Available security schemes: + * api_key (apiKey) + * + * @param user List of user object + */ + def createUsersWithArrayInput(user: Seq[User])(implicit apiKey: ApiKeyValue): ApiRequestT[Unit] = + basicRequest + .method(Method.POST, uri"$baseUrl/user/createWithArray") + .contentType("application/json") + .header("api_key", apiKey.value) + .body(user) + .response(asJson[Unit]) + + /** + * Expected answers: + * code 0 : (successful operation) + * + * Available security schemes: + * api_key (apiKey) + * + * @param user List of user object + */ + def createUsersWithListInput(user: Seq[User])(implicit apiKey: ApiKeyValue): ApiRequestT[Unit] = + basicRequest + .method(Method.POST, uri"$baseUrl/user/createWithList") + .contentType("application/json") + .header("api_key", apiKey.value) + .body(user) + .response(asJson[Unit]) + + /** + * This can only be done by the logged in user. + * + * Expected answers: + * code 400 : (Invalid username supplied) + * code 404 : (User not found) + * + * Available security schemes: + * api_key (apiKey) + * + * @param username The name that needs to be deleted + */ + def deleteUser(username: String)(implicit apiKey: ApiKeyValue): ApiRequestT[Unit] = + basicRequest + .method(Method.DELETE, uri"$baseUrl/user/${username}") + .contentType("application/json") + .header("api_key", apiKey.value) + .response(asJson[Unit]) + + /** + * Expected answers: + * code 200 : User (successful operation) + * code 400 : (Invalid username supplied) + * code 404 : (User not found) + * + * @param username The name that needs to be fetched. Use user1 for testing. + */ + def getUserByName(username: String): ApiRequestT[User] = + basicRequest + .method(Method.GET, uri"$baseUrl/user/${username}") + .contentType("application/json") + .response(asJson[User]) + + /** + * Expected answers: + * code 200 : String (successful operation) + * Headers : + * Set-Cookie - Cookie authentication key for use with the `api_key` apiKey authentication. + * X-Rate-Limit - calls per hour allowed by the user + * X-Expires-After - date in UTC when toekn expires + * code 400 : (Invalid username/password supplied) + * + * @param username The user name for login + * @param password The password for login in clear text + */ + def loginUser(username: String, password: String): ApiRequestT[String] = + basicRequest + .method(Method.GET, uri"$baseUrl/user/login?username=$username&password=$password") + .contentType("application/json") + .response(asJson[String]) + + /** + * Expected answers: + * code 0 : (successful operation) + * + * Available security schemes: + * api_key (apiKey) + */ + def logoutUser()(implicit apiKey: ApiKeyValue): ApiRequestT[Unit] = + basicRequest + .method(Method.GET, uri"$baseUrl/user/logout") + .contentType("application/json") + .header("api_key", apiKey.value) + .response(asJson[Unit]) + + /** + * This can only be done by the logged in user. + * + * Expected answers: + * code 400 : (Invalid user supplied) + * code 404 : (User not found) + * + * Available security schemes: + * api_key (apiKey) + * + * @param username name that need to be deleted + * @param user Updated user object + */ + def updateUser(username: String, user: User)(implicit apiKey: ApiKeyValue): ApiRequestT[Unit] = + basicRequest + .method(Method.PUT, uri"$baseUrl/user/${username}") + .contentType("application/json") + .header("api_key", apiKey.value) + .body(user) + .response(asJson[Unit]) + +} + diff --git a/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/core/ApiInvoker.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/core/ApiInvoker.scala new file mode 100644 index 000000000000..dc98ff4d1365 --- /dev/null +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/core/ApiInvoker.scala @@ -0,0 +1,60 @@ +/** + * 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. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package org.openapitools.client.core + +import org.json4s._ +import sttp.client._ +import sttp.model.StatusCode +import org.openapitools.client.api.EnumsSerializers +import sttp.client.json4s.SttpJson4sApi +import sttp.client.monad.MonadError + +class SttpSerializer(implicit val format: Formats = DefaultFormats ++ EnumsSerializers.all ++ Serializers.all, + implicit val serialization: org.json4s.Serialization = org.json4s.jackson.Serialization) extends SttpJson4sApi + +class HttpException(val statusCode: StatusCode, val statusText: String, val message: String) extends Exception(s"[$statusCode] $statusText: $message") + +object Helpers { + + // Helper to handle Optional header parameters + implicit class optionalParams(val request: RequestT[Identity, Either[String, String], Nothing]) extends AnyVal { + def header( header: String, optValue: Option[Any]): RequestT[Identity, Either[String, String], Nothing] = { + optValue.map( value => request.header(header, value.toString)).getOrElse(request) + } + } + +} + +object ApiInvoker { + + /** + * Allows request execution without calling apiInvoker.execute(request) + * request.result can be used to get a monad wrapped content. + * + * @param request the apiRequest to be executed + */ + implicit class ApiRequestImprovements[R[_], T](request: RequestT[Identity, Either[ResponseError[Exception], T], Nothing]) { + + def result(implicit backend: SttpBackend[R, Nothing, Nothing]): R[T] = { + val responseT = request.send() + val ME: MonadError[R] = backend.responseMonad + ME.flatMap(responseT) { + response => + response.body match { + case Left(ex) => ME.error[T](new HttpException(response.code, response.statusText, ex.body)) + case Right(value) => ME.unit(value) + } + } + } + } + +} diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/Serializers.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/core/Serializers.scala similarity index 75% rename from samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/Serializers.scala rename to samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/core/Serializers.scala index 93d491af589a..dbd13545c738 100644 --- a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/Serializers.scala +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/core/Serializers.scala @@ -2,17 +2,17 @@ package org.openapitools.client.core import java.time.{LocalDate, LocalDateTime, OffsetDateTime, ZoneId} import java.time.format.DateTimeFormatter +import scala.util.Try import org.json4s.{Serializer, CustomSerializer, JNull} import org.json4s.JsonAST.JString -import scala.util.Try - object Serializers { - case object DateTimeSerializer extends CustomSerializer[OffsetDateTime]( _ => ( { + case object DateTimeSerializer extends CustomSerializer[OffsetDateTime](_ => ( { case JString(s) => Try(OffsetDateTime.parse(s, DateTimeFormatter.ISO_OFFSET_DATE_TIME)) orElse - Try(LocalDateTime.parse(s).atZone(ZoneId.systemDefault()).toOffsetDateTime) getOrElse null + Try(LocalDateTime.parse(s).atZone(ZoneId.systemDefault()).toOffsetDateTime) getOrElse (null) + case JNull => null }, { case d: OffsetDateTime => JString(d.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)) @@ -20,11 +20,12 @@ object Serializers { case object LocalDateSerializer extends CustomSerializer[LocalDate]( _ => ( { case JString(s) => LocalDate.parse(s) + case JNull => null }, { case d: LocalDate => - JString(d.format(DateTimeFormatter.ISO_LOCAL_DATE)) + JString(d.format(DateTimeFormatter.ISO_LOCAL_DATE)) })) - def all: Seq[Serializer[_]] = Seq[Serializer[_]]() :+ DateTimeSerializer :+ LocalDateSerializer + def all: Seq[Serializer[_]] = Seq[Serializer[_]]() :+ LocalDateSerializer :+ DateTimeSerializer -} \ No newline at end of file +} diff --git a/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/core/requests.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/core/requests.scala new file mode 100644 index 000000000000..1f45be8103e1 --- /dev/null +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/core/requests.scala @@ -0,0 +1,58 @@ +/** + * 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. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package org.openapitools.client.core + +import sttp.client.{Identity, RequestT, ResponseError} + +/** + * This trait needs to be added to any model defined by the api. + */ +trait ApiModel + +/** + * Sttp type aliases + */ +object alias { + type ApiRequestT[T] = RequestT[Identity, Either[ResponseError[Exception], T], Nothing] +} + +/** + * Single trait defining a credential that can be transformed to a paramName / paramValue tupple + */ +sealed trait Credentials { + def asQueryParam: Option[(String, String)] = None +} + +sealed case class BasicCredentials(user: String, password: String) extends Credentials + +sealed case class BearerToken(token: String) extends Credentials + +sealed case class ApiKeyCredentials(key: ApiKeyValue, keyName: String, location: ApiKeyLocation) extends Credentials { + override def asQueryParam: Option[(String, String)] = location match { + case ApiKeyLocations.QUERY => Some((keyName, key.value)) + case _ => None + } +} + +sealed case class ApiKeyValue(value: String) + +sealed trait ApiKeyLocation + +object ApiKeyLocations { + + case object QUERY extends ApiKeyLocation + + case object HEADER extends ApiKeyLocation + + case object COOKIE extends ApiKeyLocation + +} diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/ApiResponse.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/ApiResponse.scala similarity index 82% rename from samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/ApiResponse.scala rename to samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/ApiResponse.scala index 3ddf32c9bda7..3a3b6d6f499a 100644 --- a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/ApiResponse.scala +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/ApiResponse.scala @@ -13,7 +13,11 @@ package org.openapitools.client.model import org.openapitools.client.core.ApiModel -case class ApiResponse ( + /** + * An uploaded response + * Describes the result of uploading an image resource + */ +case class ApiResponse( code: Option[Int] = None, `type`: Option[String] = None, message: Option[String] = None diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Category.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/Category.scala similarity index 87% rename from samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Category.scala rename to samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/Category.scala index e62645a38b2a..011164617cfb 100644 --- a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Category.scala +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/Category.scala @@ -13,7 +13,11 @@ package org.openapitools.client.model import org.openapitools.client.core.ApiModel -case class Category ( + /** + * Pet category + * A category for a pet + */ +case class Category( id: Option[Long] = None, name: Option[String] = None ) extends ApiModel diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/InlineObject.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/InlineObject.scala similarity index 95% rename from samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/InlineObject.scala rename to samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/InlineObject.scala index 3d9ec200c9fc..a8c5493161a1 100644 --- a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/InlineObject.scala +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/InlineObject.scala @@ -13,7 +13,7 @@ package org.openapitools.client.model import org.openapitools.client.core.ApiModel -case class InlineObject ( +case class InlineObject( /* Updated name of the pet */ name: Option[String] = None, /* Updated status of the pet */ diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/InlineObject1.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/InlineObject1.scala similarity index 95% rename from samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/InlineObject1.scala rename to samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/InlineObject1.scala index c41794c43d43..480cf8c2e10a 100644 --- a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/InlineObject1.scala +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/InlineObject1.scala @@ -14,7 +14,7 @@ package org.openapitools.client.model import java.io.File import org.openapitools.client.core.ApiModel -case class InlineObject1 ( +case class InlineObject1( /* Additional data to pass to server */ additionalMetadata: Option[String] = None, /* file to upload */ diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Order.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/Order.scala similarity index 91% rename from samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Order.scala rename to samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/Order.scala index 95204d35e5df..baa0c0cb14a6 100644 --- a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Order.scala +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/Order.scala @@ -14,7 +14,11 @@ package org.openapitools.client.model import java.time.OffsetDateTime import org.openapitools.client.core.ApiModel -case class Order ( + /** + * Pet Order + * An order for a pets from the pet store + */ +case class Order( id: Option[Long] = None, petId: Option[Long] = None, quantity: Option[Int] = None, diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Pet.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/Pet.scala similarity index 92% rename from samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Pet.scala rename to samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/Pet.scala index 3a78a7c3f183..75b528c3c0a1 100644 --- a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Pet.scala +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/Pet.scala @@ -13,7 +13,11 @@ package org.openapitools.client.model import org.openapitools.client.core.ApiModel -case class Pet ( + /** + * a Pet + * A pet for sale in the pet store + */ +case class Pet( id: Option[Long] = None, category: Option[Category] = None, name: String, diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Tag.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/Tag.scala similarity index 89% rename from samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Tag.scala rename to samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/Tag.scala index ac0c7763720c..299ee5161a8b 100644 --- a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Tag.scala +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/Tag.scala @@ -13,7 +13,11 @@ package org.openapitools.client.model import org.openapitools.client.core.ApiModel -case class Tag ( + /** + * Pet Tag + * A tag for a pet + */ +case class Tag( id: Option[Long] = None, name: Option[String] = None ) extends ApiModel diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/User.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/User.scala similarity index 89% rename from samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/User.scala rename to samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/User.scala index aad2117b16d5..bd2e6c3ba2a7 100644 --- a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/User.scala +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/model/User.scala @@ -13,7 +13,11 @@ package org.openapitools.client.model import org.openapitools.client.core.ApiModel -case class User ( + /** + * a User + * A User who is purchasing from the pet store + */ +case class User( id: Option[Long] = None, username: Option[String] = None, firstName: Option[String] = None, diff --git a/samples/client/petstore/scalaz/.openapi-generator/VERSION b/samples/client/petstore/scalaz/.openapi-generator/VERSION index bfbf77eb7fad..d99e7162d01f 100644 --- a/samples/client/petstore/scalaz/.openapi-generator/VERSION +++ b/samples/client/petstore/scalaz/.openapi-generator/VERSION @@ -1 +1 @@ -4.3.0-SNAPSHOT \ No newline at end of file +5.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/scalaz/src/main/scala/org/openapitools/client/api/DateTimeCodecs.scala b/samples/client/petstore/scalaz/src/main/scala/org/openapitools/client/api/DateTimeCodecs.scala index 890338a8ffb6..b91da00368d2 100644 --- a/samples/client/petstore/scalaz/src/main/scala/org/openapitools/client/api/DateTimeCodecs.scala +++ b/samples/client/petstore/scalaz/src/main/scala/org/openapitools/client/api/DateTimeCodecs.scala @@ -4,6 +4,9 @@ import argonaut._ import argonaut.EncodeJson._ import argonaut.DecodeJson._ +import org.http4s._ +import org.http4s.{EntityDecoder, EntityEncoder} +import org.http4s.argonaut._ import java.time.OffsetDateTime object DateTimeCodecs { diff --git a/samples/client/petstore/scalaz/src/main/scala/org/openapitools/client/api/PetApi.scala b/samples/client/petstore/scalaz/src/main/scala/org/openapitools/client/api/PetApi.scala index 79636d5560a8..5cbbe7896637 100644 --- a/samples/client/petstore/scalaz/src/main/scala/org/openapitools/client/api/PetApi.scala +++ b/samples/client/petstore/scalaz/src/main/scala/org/openapitools/client/api/PetApi.scala @@ -31,7 +31,9 @@ object PetApi { def escape(value: String): String = URLEncoder.encode(value, "utf-8").replaceAll("\\+", "%20") - def addPet(host: String, body: Pet): Task[Unit] = { + def addPet(host: String, pet: Pet): Task[Pet] = { + implicit val returnTypeDecoder: EntityDecoder[Pet] = jsonOf[Pet] + val path = "/pet" val httpMethod = Method.POST @@ -44,8 +46,8 @@ object PetApi { for { uri <- Task.fromDisjunction(Uri.fromString(host + path)) uriWithParams = uri.copy(query = queryParams) - req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(body) - resp <- client.fetch[Unit](req)(_ => Task.now(())) + req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(pet) + resp <- client.expect[Pet](req) } yield resp } @@ -132,7 +134,9 @@ object PetApi { } yield resp } - def updatePet(host: String, body: Pet): Task[Unit] = { + def updatePet(host: String, pet: Pet): Task[Pet] = { + implicit val returnTypeDecoder: EntityDecoder[Pet] = jsonOf[Pet] + val path = "/pet" val httpMethod = Method.PUT @@ -145,8 +149,8 @@ object PetApi { for { uri <- Task.fromDisjunction(Uri.fromString(host + path)) uriWithParams = uri.copy(query = queryParams) - req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(body) - resp <- client.fetch[Unit](req)(_ => Task.now(())) + req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(pet) + resp <- client.expect[Pet](req) } yield resp } @@ -198,7 +202,9 @@ class HttpServicePetApi(service: HttpService) { def escape(value: String): String = URLEncoder.encode(value, "utf-8").replaceAll("\\+", "%20") - def addPet(body: Pet): Task[Unit] = { + def addPet(pet: Pet): Task[Pet] = { + implicit val returnTypeDecoder: EntityDecoder[Pet] = jsonOf[Pet] + val path = "/pet" val httpMethod = Method.POST @@ -211,8 +217,8 @@ class HttpServicePetApi(service: HttpService) { for { uri <- Task.fromDisjunction(Uri.fromString(path)) uriWithParams = uri.copy(query = queryParams) - req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(body) - resp <- client.fetch[Unit](req)(_ => Task.now(())) + req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(pet) + resp <- client.expect[Pet](req) } yield resp } @@ -299,7 +305,9 @@ class HttpServicePetApi(service: HttpService) { } yield resp } - def updatePet(body: Pet): Task[Unit] = { + def updatePet(pet: Pet): Task[Pet] = { + implicit val returnTypeDecoder: EntityDecoder[Pet] = jsonOf[Pet] + val path = "/pet" val httpMethod = Method.PUT @@ -312,8 +320,8 @@ class HttpServicePetApi(service: HttpService) { for { uri <- Task.fromDisjunction(Uri.fromString(path)) uriWithParams = uri.copy(query = queryParams) - req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(body) - resp <- client.fetch[Unit](req)(_ => Task.now(())) + req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(pet) + resp <- client.expect[Pet](req) } yield resp } diff --git a/samples/client/petstore/scalaz/src/main/scala/org/openapitools/client/api/StoreApi.scala b/samples/client/petstore/scalaz/src/main/scala/org/openapitools/client/api/StoreApi.scala index ccb0607174a3..abb92a3d3b87 100644 --- a/samples/client/petstore/scalaz/src/main/scala/org/openapitools/client/api/StoreApi.scala +++ b/samples/client/petstore/scalaz/src/main/scala/org/openapitools/client/api/StoreApi.scala @@ -90,7 +90,7 @@ object StoreApi { } yield resp } - def placeOrder(host: String, body: Order): Task[Order] = { + def placeOrder(host: String, order: Order): Task[Order] = { implicit val returnTypeDecoder: EntityDecoder[Order] = jsonOf[Order] val path = "/store/order" @@ -105,7 +105,7 @@ object StoreApi { for { uri <- Task.fromDisjunction(Uri.fromString(host + path)) uriWithParams = uri.copy(query = queryParams) - req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(body) + req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(order) resp <- client.expect[Order](req) } yield resp @@ -179,7 +179,7 @@ class HttpServiceStoreApi(service: HttpService) { } yield resp } - def placeOrder(body: Order): Task[Order] = { + def placeOrder(order: Order): Task[Order] = { implicit val returnTypeDecoder: EntityDecoder[Order] = jsonOf[Order] val path = "/store/order" @@ -194,7 +194,7 @@ class HttpServiceStoreApi(service: HttpService) { for { uri <- Task.fromDisjunction(Uri.fromString(path)) uriWithParams = uri.copy(query = queryParams) - req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(body) + req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(order) resp <- client.expect[Order](req) } yield resp diff --git a/samples/client/petstore/scalaz/src/main/scala/org/openapitools/client/api/UserApi.scala b/samples/client/petstore/scalaz/src/main/scala/org/openapitools/client/api/UserApi.scala index ff45c31941ff..770b3f7163c7 100644 --- a/samples/client/petstore/scalaz/src/main/scala/org/openapitools/client/api/UserApi.scala +++ b/samples/client/petstore/scalaz/src/main/scala/org/openapitools/client/api/UserApi.scala @@ -29,7 +29,7 @@ object UserApi { def escape(value: String): String = URLEncoder.encode(value, "utf-8").replaceAll("\\+", "%20") - def createUser(host: String, body: User): Task[Unit] = { + def createUser(host: String, user: User): Task[Unit] = { val path = "/user" val httpMethod = Method.POST @@ -42,13 +42,13 @@ object UserApi { for { uri <- Task.fromDisjunction(Uri.fromString(host + path)) uriWithParams = uri.copy(query = queryParams) - req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(body) + req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(user) resp <- client.fetch[Unit](req)(_ => Task.now(())) } yield resp } - def createUsersWithArrayInput(host: String, body: List[User]): Task[Unit] = { + def createUsersWithArrayInput(host: String, user: List[User]): Task[Unit] = { val path = "/user/createWithArray" val httpMethod = Method.POST @@ -61,13 +61,13 @@ object UserApi { for { uri <- Task.fromDisjunction(Uri.fromString(host + path)) uriWithParams = uri.copy(query = queryParams) - req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(body) + req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(user) resp <- client.fetch[Unit](req)(_ => Task.now(())) } yield resp } - def createUsersWithListInput(host: String, body: List[User]): Task[Unit] = { + def createUsersWithListInput(host: String, user: List[User]): Task[Unit] = { val path = "/user/createWithList" val httpMethod = Method.POST @@ -80,7 +80,7 @@ object UserApi { for { uri <- Task.fromDisjunction(Uri.fromString(host + path)) uriWithParams = uri.copy(query = queryParams) - req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(body) + req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(user) resp <- client.fetch[Unit](req)(_ => Task.now(())) } yield resp @@ -166,7 +166,7 @@ object UserApi { } yield resp } - def updateUser(host: String, username: String, body: User): Task[Unit] = { + def updateUser(host: String, username: String, user: User): Task[Unit] = { val path = "/user/{username}".replaceAll("\\{" + "username" + "\\}",escape(username.toString)) val httpMethod = Method.PUT @@ -179,7 +179,7 @@ object UserApi { for { uri <- Task.fromDisjunction(Uri.fromString(host + path)) uriWithParams = uri.copy(query = queryParams) - req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(body) + req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(user) resp <- client.fetch[Unit](req)(_ => Task.now(())) } yield resp @@ -192,7 +192,7 @@ class HttpServiceUserApi(service: HttpService) { def escape(value: String): String = URLEncoder.encode(value, "utf-8").replaceAll("\\+", "%20") - def createUser(body: User): Task[Unit] = { + def createUser(user: User): Task[Unit] = { val path = "/user" val httpMethod = Method.POST @@ -205,13 +205,13 @@ class HttpServiceUserApi(service: HttpService) { for { uri <- Task.fromDisjunction(Uri.fromString(path)) uriWithParams = uri.copy(query = queryParams) - req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(body) + req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(user) resp <- client.fetch[Unit](req)(_ => Task.now(())) } yield resp } - def createUsersWithArrayInput(body: List[User]): Task[Unit] = { + def createUsersWithArrayInput(user: List[User]): Task[Unit] = { val path = "/user/createWithArray" val httpMethod = Method.POST @@ -224,13 +224,13 @@ class HttpServiceUserApi(service: HttpService) { for { uri <- Task.fromDisjunction(Uri.fromString(path)) uriWithParams = uri.copy(query = queryParams) - req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(body) + req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(user) resp <- client.fetch[Unit](req)(_ => Task.now(())) } yield resp } - def createUsersWithListInput(body: List[User]): Task[Unit] = { + def createUsersWithListInput(user: List[User]): Task[Unit] = { val path = "/user/createWithList" val httpMethod = Method.POST @@ -243,7 +243,7 @@ class HttpServiceUserApi(service: HttpService) { for { uri <- Task.fromDisjunction(Uri.fromString(path)) uriWithParams = uri.copy(query = queryParams) - req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(body) + req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(user) resp <- client.fetch[Unit](req)(_ => Task.now(())) } yield resp @@ -329,7 +329,7 @@ class HttpServiceUserApi(service: HttpService) { } yield resp } - def updateUser(username: String, body: User): Task[Unit] = { + def updateUser(username: String, user: User): Task[Unit] = { val path = "/user/{username}".replaceAll("\\{" + "username" + "\\}",escape(username.toString)) val httpMethod = Method.PUT @@ -342,7 +342,7 @@ class HttpServiceUserApi(service: HttpService) { for { uri <- Task.fromDisjunction(Uri.fromString(path)) uriWithParams = uri.copy(query = queryParams) - req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(body) + req = Request(method = httpMethod, uri = uriWithParams, headers = headers.put(contentType)).withBody(user) resp <- client.fetch[Unit](req)(_ => Task.now(())) } yield resp diff --git a/samples/openapi3/client/petstore/scala-akka/build.sbt b/samples/openapi3/client/petstore/scala-akka/build.sbt deleted file mode 100644 index d19487cbe0df..000000000000 --- a/samples/openapi3/client/petstore/scala-akka/build.sbt +++ /dev/null @@ -1,27 +0,0 @@ -version := "1.0.0" -name := "scala-akka-petstore-client" -organization := "org.openapitools" -scalaVersion := "2.12.8" - -libraryDependencies ++= Seq( - "com.typesafe" % "config" % "1.3.3", - "com.typesafe.akka" %% "akka-actor" % "2.5.21", - "com.typesafe.akka" %% "akka-stream" % "2.5.21", - "com.typesafe.akka" %% "akka-http" % "10.1.7", - "org.json4s" %% "json4s-jackson" % "3.6.5", - "org.json4s" %% "json4s-ext" % "3.6.5", - "de.heikoseeberger" %% "akka-http-json4s" % "1.25.2", - // test dependencies - "org.scalatest" %% "scalatest" % "3.0.5" % "test", - "junit" % "junit" % "4.13" % "test" -) - -resolvers ++= Seq(Resolver.mavenLocal) - -scalacOptions := Seq( - "-unchecked", - "-deprecation", - "-feature" -) - -publishArtifact in (Compile, packageDoc) := false \ No newline at end of file diff --git a/samples/openapi3/client/petstore/scala-akka/pom.xml b/samples/openapi3/client/petstore/scala-akka/pom.xml deleted file mode 100644 index a88eaa5a41ef..000000000000 --- a/samples/openapi3/client/petstore/scala-akka/pom.xml +++ /dev/null @@ -1,254 +0,0 @@ - - 4.0.0 - - scala-akka-petstore-client - - org.openapitools - scala-akka-petstore-client - 1.0.0 - - jar - - - UTF-8 - UTF-8 - - 1.8 - 2.12.8 - 3.5.3 - 3.2.11 - 2.5.21 - 10.1.7 - 1.3.3 - 1.25.2 - 4.13 - 3.0.5 - - 3.3.1 - - - - - org.scala-lang - scala-library - ${scala.version} - provided - - - com.typesafe - config - ${typesafeconfig.version} - - - com.typesafe.akka - akka-actor_2.12 - ${akka.version} - - - com.typesafe.akka - akka-stream_2.12 - ${akka.version} - - - com.typesafe.akka - akka-http_2.12 - ${akka.http.version} - - - org.json4s - json4s-jackson_2.12 - ${json4s.jackson.version} - - - org.json4s - json4s-ext_2.12 - ${json4s.jackson.version} - - - de.heikoseeberger - akka-http-json4s_2.12 - ${akka.http.json4s.version} - - - - - org.scalatest - scalatest_2.12 - ${scala.test.version} - test - - - junit - junit - ${junit.version} - test - - - - - - - org.apache.maven.plugins - maven-deploy-plugin - 2.8.2 - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.0.0 - - - org.apache.maven.plugins - maven-source-plugin - 3.0.1 - - - org.apache.maven.plugins - maven-enforcer-plugin - 3.0.0-M1 - - - enforce-maven - - enforce - - - - - 2.2.0 - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M4 - - - - loggerPath - conf/log4j.properties - - - -Xms512m -Xmx1500m - methods - 4 - pertest - - - - org.apache.maven.plugins - maven-dependency-plugin - 3.0.2 - - - package - - copy-dependencies - - - ${project.build.directory}/lib - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.6 - - - - jar - test-jar - - - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - 3.0.0 - - - add_sources - generate-sources - - add-source - - - - - src/main/java - - - - - - add_test_sources - generate-test-sources - - add-test-source - - - - - src/test/java - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - ${java.version} - ${java.version} - - - - net.alchim31.maven - scala-maven-plugin - ${scala.maven.plugin.version} - - - scala-compile-first - process-resources - - add-source - compile - - - - scala-test-compile - process-test-resources - - testCompile - - - - - - -feature - - - -Xms128m - -Xmx1500m - - - - - - diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/resources/reference.conf b/samples/openapi3/client/petstore/scala-akka/src/main/resources/reference.conf deleted file mode 100644 index 6d419f988eba..000000000000 --- a/samples/openapi3/client/petstore/scala-akka/src/main/resources/reference.conf +++ /dev/null @@ -1,24 +0,0 @@ -org.openapitools.client { - - apiRequest { - - compression { - enabled: false - size-threshold: 0 - } - - trust-certificates: true - - connection-timeout: 5000ms - - default-headers { - "userAgent": "scala-akka-petstore-client_1.0.0" - } - - // let you define custom http status code, as in : - // { code: 601, reason: "some custom http status code", success: false } - custom-codes : [] - } -} - -spray.can.host-connector.max-redirects = 10 \ No newline at end of file diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/UserApi.scala b/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/UserApi.scala deleted file mode 100644 index 54809067608d..000000000000 --- a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/UserApi.scala +++ /dev/null @@ -1,175 +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. - * - * The version of the OpenAPI document: 1.0.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ -package org.openapitools.client.api - -import org.openapitools.client.model.User -import org.openapitools.client.core._ -import org.openapitools.client.core.CollectionFormats._ -import org.openapitools.client.core.ApiKeyLocations._ - -object UserApi { - - def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new UserApi(baseUrl) -} - -class UserApi(baseUrl: String) { - - /** - * This can only be done by the logged in user. - * - * Expected answers: - * code 0 : (successful operation) - * - * Available security schemes: - * auth_cookie (apiKey) - * - * @param user Created user object - */ - def createUser(user: User)(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = - ApiRequest[Unit](ApiMethods.POST, baseUrl, "/user", "application/json") - .withApiKey(apiKey, "AUTH_KEY", COOKIE) - .withBody(user) - .withDefaultSuccessResponse[Unit] - - - /** - * Expected answers: - * code 0 : (successful operation) - * - * Available security schemes: - * auth_cookie (apiKey) - * - * @param user List of user object - */ - def createUsersWithArrayInput(user: Seq[User])(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = - ApiRequest[Unit](ApiMethods.POST, baseUrl, "/user/createWithArray", "application/json") - .withApiKey(apiKey, "AUTH_KEY", COOKIE) - .withBody(user) - .withDefaultSuccessResponse[Unit] - - - /** - * Expected answers: - * code 0 : (successful operation) - * - * Available security schemes: - * auth_cookie (apiKey) - * - * @param user List of user object - */ - def createUsersWithListInput(user: Seq[User])(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = - ApiRequest[Unit](ApiMethods.POST, baseUrl, "/user/createWithList", "application/json") - .withApiKey(apiKey, "AUTH_KEY", COOKIE) - .withBody(user) - .withDefaultSuccessResponse[Unit] - - - /** - * This can only be done by the logged in user. - * - * Expected answers: - * code 400 : (Invalid username supplied) - * code 404 : (User not found) - * - * Available security schemes: - * auth_cookie (apiKey) - * - * @param username The name that needs to be deleted - */ - def deleteUser(username: String)(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = - ApiRequest[Unit](ApiMethods.DELETE, baseUrl, "/user/{username}", "application/json") - .withApiKey(apiKey, "AUTH_KEY", COOKIE) - .withPathParam("username", username) - .withErrorResponse[Unit](400) - .withErrorResponse[Unit](404) - - - /** - * Expected answers: - * code 200 : User (successful operation) - * code 400 : (Invalid username supplied) - * code 404 : (User not found) - * - * @param username The name that needs to be fetched. Use user1 for testing. - */ - def getUserByName(username: String): ApiRequest[User] = - ApiRequest[User](ApiMethods.GET, baseUrl, "/user/{username}", "application/json") - .withPathParam("username", username) - .withSuccessResponse[User](200) - .withErrorResponse[Unit](400) - .withErrorResponse[Unit](404) - - - /** - * Expected answers: - * code 200 : String (successful operation) - * Headers : - * Set-Cookie - Cookie authentication key for use with the `auth_cookie` apiKey authentication. - * X-Rate-Limit - calls per hour allowed by the user - * X-Expires-After - date in UTC when toekn expires - * code 400 : (Invalid username/password supplied) - * - * @param username The user name for login - * @param password The password for login in clear text - */ - def loginUser(username: String, password: String): ApiRequest[String] = - ApiRequest[String](ApiMethods.GET, baseUrl, "/user/login", "application/json") - .withQueryParam("username", username) - .withQueryParam("password", password) - .withSuccessResponse[String](200) - .withErrorResponse[Unit](400) - - object LoginUserHeaders { - def setCookie(r: ApiReturnWithHeaders) = r.getStringHeader("Set-Cookie") - def xRateLimit(r: ApiReturnWithHeaders) = r.getIntHeader("X-Rate-Limit") - def xExpiresAfter(r: ApiReturnWithHeaders) = r.getOffsetDateTimeHeader("X-Expires-After") - } - - /** - * Expected answers: - * code 0 : (successful operation) - * - * Available security schemes: - * auth_cookie (apiKey) - */ - def logoutUser()(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = - ApiRequest[Unit](ApiMethods.GET, baseUrl, "/user/logout", "application/json") - .withApiKey(apiKey, "AUTH_KEY", COOKIE) - .withDefaultSuccessResponse[Unit] - - - /** - * This can only be done by the logged in user. - * - * Expected answers: - * code 400 : (Invalid user supplied) - * code 404 : (User not found) - * - * Available security schemes: - * auth_cookie (apiKey) - * - * @param username name that need to be deleted - * @param user Updated user object - */ - def updateUser(username: String, user: User)(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = - ApiRequest[Unit](ApiMethods.PUT, baseUrl, "/user/{username}", "application/json") - .withApiKey(apiKey, "AUTH_KEY", COOKIE) - .withBody(user) - .withPathParam("username", username) - .withErrorResponse[Unit](400) - .withErrorResponse[Unit](404) - - - - -} - diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiInvoker.scala b/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiInvoker.scala deleted file mode 100644 index 3e6c1dbeb442..000000000000 --- a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiInvoker.scala +++ /dev/null @@ -1,291 +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. - * - * The version of the OpenAPI document: 1.0.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ -package org.openapitools.client.core - -import java.io.File - -import akka.actor.ActorSystem -import akka.http.scaladsl.Http -import akka.http.scaladsl.coding._ -import akka.http.scaladsl.model.Multipart.FormData.BodyPart -import akka.http.scaladsl.model.Uri.Query -import akka.http.scaladsl.model._ -import akka.http.scaladsl.model.headers._ -import akka.http.scaladsl.unmarshalling.{ Unmarshal, Unmarshaller } -import akka.stream.ActorMaterializer -import akka.stream.scaladsl.Source -import akka.util.{ ByteString, Timeout } -import de.heikoseeberger.akkahttpjson4s.Json4sSupport -import org.json4s._ -import org.json4s.jackson.JsonMethods._ -import org.json4s.jackson.Serialization - -import scala.collection.immutable -import scala.concurrent.{ ExecutionContext, ExecutionContextExecutor, Future } -import scala.reflect.ClassTag - -object ApiInvoker { - - def apply()(implicit system: ActorSystem): ApiInvoker = - apply(DefaultFormats ++ Serializers.all) - - def apply(serializers: Iterable[Serializer[_]])(implicit system: ActorSystem): ApiInvoker = - apply(DefaultFormats ++ Serializers.all ++ serializers) - - def apply(formats: Formats)(implicit system: ActorSystem): ApiInvoker = new ApiInvoker(formats) - - - /** - * Allows request execution without calling apiInvoker.execute(request) - * request.response can be used to get a future of the ApiResponse generated. - * request.result can be used to get a future of the expected ApiResponse content. If content doesn't match, a - * Future will failed with a ClassCastException - * - * @param request the apiRequest to be executed - */ - implicit class ApiRequestImprovements[T: Manifest](request: ApiRequest[T]) { - - def response(invoker: ApiInvoker)(implicit ec: ExecutionContext, system: ActorSystem): Future[ApiResponse[T]] = - response(ec, system, invoker) - - def response(implicit ec: ExecutionContext, system: ActorSystem, invoker: ApiInvoker): Future[ApiResponse[T]] = - invoker.execute(request) - - def result[U <: T](implicit c: ClassTag[U], ec: ExecutionContext, system: ActorSystem, invoker: ApiInvoker): Future[U] = - invoker.execute(request).map(_.content).mapTo[U] - - } - - /** - * Allows transformation from ApiMethod to spray HttpMethods - * - * @param method the ApiMethod to be converted - */ - implicit class ApiMethodExtensions(val method: ApiMethod) { - def toAkkaHttpMethod: HttpMethod = HttpMethods.getForKey(method.value).getOrElse(HttpMethods.GET) - } - -} - -trait UnitJSONSupport { - -} - -class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomContentTypes with Json4sSupport { - - import org.openapitools.client.core.ApiInvoker._ - import org.openapitools.client.core.ParametersMap._ - - implicit val ec: ExecutionContextExecutor = system.dispatcher - implicit val jsonFormats: Formats = formats - - protected val settings: ApiSettings = ApiSettings(system) - - private implicit val materializer: ActorMaterializer = ActorMaterializer() - private implicit val serialization: Serialization = jackson.Serialization - - - private val http = Http() - - val CompressionFilter: HttpMessage ⇒ Boolean = (msg: HttpMessage) => - Seq( - { _: HttpMessage => settings.compressionEnabled }, - Encoder.DefaultFilter, - (message: HttpMessage) => { - val long = message.entity().getContentLengthOption() - if (long.isPresent) long.getAsLong > settings.compressionSizeThreshold else true - } - ) - .map(f => f(msg)) - .forall(identity) - - - private def addAuthentication(credentialsSeq: Seq[Credentials]) = { - request: HttpRequest => - credentialsSeq.foldLeft(request) { - case (req, BasicCredentials(login, password)) => - req.withHeaders(Authorization(BasicHttpCredentials(login, password))) - case (req, ApiKeyCredentials(keyValue, keyName, ApiKeyLocations.HEADER)) => - req.withHeaders(RawHeader(keyName, keyValue.value)) - case (req, BearerToken(token)) => - req.withHeaders(RawHeader("Authorization", s"Bearer $token")) - case (req, _) => req - } - } - - private def headers(headers: Map[String, Any]): immutable.Seq[HttpHeader] = - headers.asFormattedParams - .map { case (name, value) => RawHeader(name, value.toString) } - .to[immutable.Seq] - - - private def bodyPart(name: String, value: Any): BodyPart = { - value match { - case f: File => - BodyPart.fromFile( - name, - ContentType(MediaTypes.`application/octet-stream`), - f, - f.length().toInt - ) - case v: String => - BodyPart.Strict(name, v.toString) - case NumericValue(v) => - BodyPart.Strict(name, v.toString) - case m: ApiModel => - BodyPart.Strict(name, Serialization.write(m)) - } - } - - - private def formDataContent(request: ApiRequest[_]) = { - val params = request.formParams.asFormattedParams - if (params.isEmpty) - None - else - Some( - normalizedContentType(request.contentType).mediaType match { - case MediaTypes.`multipart/form-data` => - Multipart.FormData(Source(params.toList.map { case (name, value) => bodyPart(name, value) })) - case MediaTypes.`application/x-www-form-urlencoded` => - FormData(params.mapValues(_.toString)) - case _: MediaType => // Default : application/x-www-form-urlencoded. - FormData(params.mapValues(_.toString)) - } - ) - } - - private def bodyContent(request: ApiRequest[_]): Option[Any] = request - .bodyParam - .map(Extraction.decompose) - .map(compact) - - private def createRequest(uri: Uri, request: ApiRequest[_]): HttpRequest = { - val httpRequest = request.method.toAkkaHttpMethod match { - case m@(HttpMethods.GET | HttpMethods.DELETE) => HttpRequest(m, uri) - case m@(HttpMethods.POST | HttpMethods.PUT | HttpMethods.PATCH) => - formDataContent(request) orElse bodyContent(request) match { - case Some(c: FormData) => - HttpRequest(m, uri, entity = c.toEntity) - case Some(c: Multipart.FormData) => - HttpRequest(m, uri, entity = c.toEntity) - case Some(c: String) => - HttpRequest(m, uri, entity = HttpEntity(normalizedContentType(request.contentType), ByteString(c))) - case _ => - HttpRequest(m, uri, entity = HttpEntity(normalizedContentType(request.contentType), ByteString(" "))) - } - case m: HttpMethod => HttpRequest(m, uri) - } - - addAuthentication(request.credentials)( - httpRequest.withHeaders(headers(request.headerParams)) - ) - } - - def makeQuery(r: ApiRequest[_]): Query = { - r.credentials.foldLeft(r.queryParams) { - case (params, ApiKeyCredentials(key, keyName, ApiKeyLocations.QUERY)) => - params + (keyName -> key.value) - case (params, _) => params - }.asFormattedParams - .mapValues(_.toString) - .foldRight[Query](Uri.Query.Empty) { - case ((name, value), acc) => acc.+:(name, value) - } - } - - def makeUri(r: ApiRequest[_]): Uri = { - val opPath = r.operationPath.replaceAll("\\{format\\}", "json") - val opPathWithParams = r.pathParams.asFormattedParams - .mapValues(_.toString) - .foldLeft(opPath) { - case (path, (name, value)) => path.replaceAll(s"\\{$name\\}", value) - } - val query = makeQuery(r) - - Uri(r.basePath + opPathWithParams).withQuery(query) - } - - def execute[T: Manifest](r: ApiRequest[T]): Future[ApiResponse[T]] = { - implicit val timeout: Timeout = settings.connectionTimeout - - val request = createRequest(makeUri(r), r) - - http - .singleRequest(request) - .map { response => - val decoder: Coder with StreamDecoder = response.encoding match { - case HttpEncodings.gzip ⇒ - Gzip - case HttpEncodings.deflate ⇒ - Deflate - case HttpEncodings.identity ⇒ - NoCoding - case HttpEncoding(encoding) => - throw new IllegalArgumentException(s"Unsupported encoding: $encoding") - } - - decoder.decodeMessage(response) - } - .flatMap(unmarshallApiResponse(r)) - } - - def unmarshallApiResponse[T: Manifest](request: ApiRequest[T])(response: HttpResponse): Future[ApiResponse[T]] = { - def responseForState[V](state: ResponseState, value: V): ApiResponse[V] = { - state match { - case ResponseState.Success => - ApiResponse(response.status.intValue, value, response.headers.map(header => (header.name, header.value)).toMap) - case ResponseState.Error => - throw ApiError( - response.status.intValue, - "Error response received", - Some(value), - headers = response.headers.map(header => (header.name, header.value)).toMap - ) - } - } - val mf = implicitly(manifest[T]) - request - .responseForCode(response.status.intValue) match { - case Some((Manifest.Unit, state: ResponseState)) => - Future(responseForState(state, Unit).asInstanceOf[ApiResponse[T]]) - case Some((manifest, state: ResponseState)) if manifest == mf => - implicit val m: Unmarshaller[HttpEntity, T] = unmarshaller[T](mf, serialization, formats) - Unmarshal(response.entity) - .to[T] - .recoverWith { - case e ⇒ throw ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString), e) - } - .map(value => responseForState(state, value)) - case None | Some(_) => - Future.failed(ApiError(response.status.intValue, "Unexpected response code", Some(response.entity.toString))) - } - } -} - -sealed trait CustomContentTypes { - - protected def normalizedContentType(original: String): ContentType = - ContentType(parseContentType(original).mediaType, () => HttpCharsets.`UTF-8`) - - protected def parseContentType(contentType: String): ContentType = { - - ContentType.parse(contentType) match { - case Right(ct: ContentType) => - ct - case Left(error: List[ErrorInfo]) => - throw new IllegalArgumentException( - s"Error converting '$contentType' to a ContentType header: '${error.map(_.summary).mkString(", ")}'" - ) - } - } -} diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiRequest.scala b/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiRequest.scala deleted file mode 100644 index 3dfa61094de0..000000000000 --- a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiRequest.scala +++ /dev/null @@ -1,65 +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. - * - * The version of the OpenAPI document: 1.0.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ -package org.openapitools.client.core - -sealed trait ResponseState - -object ResponseState { - - case object Success extends ResponseState - - case object Error extends ResponseState - -} - -case class ApiRequest[U]( - // required fields - method: ApiMethod, - basePath: String, - operationPath: String, - contentType: String, - - // optional fields - responses: Map[Int, (Manifest[_], ResponseState)] = Map.empty, - bodyParam: Option[Any] = None, - formParams: Map[String, Any] = Map.empty, - pathParams: Map[String, Any] = Map.empty, - queryParams: Map[String, Any] = Map.empty, - headerParams: Map[String, Any] = Map.empty, - credentials: Seq[Credentials] = List.empty) { - - def withCredentials(cred: Credentials): ApiRequest[U] = copy[U](credentials = credentials :+ cred) - - def withApiKey(key: ApiKeyValue, keyName: String, location: ApiKeyLocation): ApiRequest[U] = withCredentials(ApiKeyCredentials(key, keyName, location)) - - def withSuccessResponse[T](code: Int)(implicit m: Manifest[T]): ApiRequest[U] = copy[U](responses = responses + (code -> (m, ResponseState.Success))) - - def withErrorResponse[T](code: Int)(implicit m: Manifest[T]): ApiRequest[U] = copy[U](responses = responses + (code -> (m, ResponseState.Error))) - - def withDefaultSuccessResponse[T](implicit m: Manifest[T]): ApiRequest[U] = withSuccessResponse[T](0) - - def withDefaultErrorResponse[T](implicit m: Manifest[T]): ApiRequest[U] = withErrorResponse[T](0) - - def responseForCode(statusCode: Int): Option[(Manifest[_], ResponseState)] = responses.get(statusCode) orElse responses.get(0) - - def withoutBody(): ApiRequest[U] = copy[U](bodyParam = None) - - def withBody(body: Any): ApiRequest[U] = copy[U](bodyParam = Some(body)) - - def withFormParam(name: String, value: Any): ApiRequest[U] = copy[U](formParams = formParams + (name -> value)) - - def withPathParam(name: String, value: Any): ApiRequest[U] = copy[U](pathParams = pathParams + (name -> value)) - - def withQueryParam(name: String, value: Any): ApiRequest[U] = copy[U](queryParams = queryParams + (name -> value)) - - def withHeaderParam(name: String, value: Any): ApiRequest[U] = copy[U](headerParams = headerParams + (name -> value)) -} diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiSettings.scala b/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiSettings.scala deleted file mode 100644 index 2553aeb3c875..000000000000 --- a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiSettings.scala +++ /dev/null @@ -1,45 +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. - * - * The version of the OpenAPI document: 1.0.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ -package org.openapitools.client.core - -import java.util.concurrent.TimeUnit - -import akka.actor.{ ExtendedActorSystem, Extension, ExtensionKey } -import akka.http.scaladsl.model.StatusCodes.CustomStatusCode -import akka.http.scaladsl.model.headers.RawHeader -import com.typesafe.config.Config - -import scala.collection.JavaConverters._ -import scala.concurrent.duration.FiniteDuration - -class ApiSettings(config: Config) extends Extension { - def this(system: ExtendedActorSystem) = this(system.settings.config) - - private def cfg = config.getConfig("org.openapitools.client.apiRequest") - - val alwaysTrustCertificates: Boolean = cfg.getBoolean("trust-certificates") - val defaultHeaders: List[RawHeader] = cfg.getConfig("default-headers").entrySet.asScala.toList.map(c => RawHeader(c.getKey, c.getValue.render)) - val connectionTimeout = FiniteDuration(cfg.getDuration("connection-timeout", TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS) - val compressionEnabled: Boolean = cfg.getBoolean("compression.enabled") - val compressionSizeThreshold: Int = cfg.getBytes("compression.size-threshold").toInt - val customCodes: List[CustomStatusCode] = cfg.getConfigList("custom-codes").asScala.toList.map { c => - CustomStatusCode( - c.getInt("code"))( - c.getString("reason"), - if (c.hasPath("defaultMessage")) c.getString("defaultMessage") else c.getString("reason"), - c.getBoolean("success"), - if (c.hasPath("allowsEntity")) c.getBoolean("allowsEntity") else true - ) - } -} - -object ApiSettings extends ExtensionKey[ApiSettings] diff --git a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/requests.scala b/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/requests.scala deleted file mode 100644 index 15b09453a973..000000000000 --- a/samples/openapi3/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/requests.scala +++ /dev/null @@ -1,200 +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. - * - * The version of the OpenAPI document: 1.0.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ -package org.openapitools.client.core - -import java.io.File -import java.net.URLEncoder -import java.time.OffsetDateTime - -import scala.util.Try - -sealed trait ApiReturnWithHeaders { - def headers: Map[String, String] - - def header(name: String): Option[String] = headers.get(name) - - def getStringHeader(name: String): Option[String] = header(name) - - // workaround: return date time header in string instead of datetime object - def getDateTimeHeader(name: String): Option[String] = header(name) - - def getIntHeader(name: String): Option[Int] = castedHeader(name, java.lang.Integer.parseInt) - - def getLongHeader(name: String): Option[Long] = castedHeader(name, java.lang.Long.parseLong) - - def getFloatHeader(name: String): Option[Float] = castedHeader(name, java.lang.Float.parseFloat) - - def getDoubleHeader(name: String): Option[Double] = castedHeader(name, java.lang.Double.parseDouble) - - def getBooleanHeader(name: String): Option[Boolean] = castedHeader(name, java.lang.Boolean.parseBoolean) - - def getOffsetDateTimeHeader(name: String): Option[OffsetDateTime] = castedHeader(name, java.time.OffsetDateTime.parse) - - private def castedHeader[U](name: String, conversion: String => U): Option[U] = { - Try { - header(name).map(conversion) - }.get - } -} - -sealed case class ApiResponse[T](code: Int, content: T, headers: Map[String, String] = Map.empty) - extends ApiReturnWithHeaders - -sealed case class ApiError[T](code: Int, message: String, responseContent: Option[T], cause: Throwable = null, headers: Map[String, String] = Map.empty) - extends Throwable(s"($code) $message.${responseContent.map(s => s" Content : $s").getOrElse("")}", cause) - with ApiReturnWithHeaders - -sealed case class ApiMethod(value: String) - -object ApiMethods { - val CONNECT = ApiMethod("CONNECT") - val DELETE = ApiMethod("DELETE") - val GET = ApiMethod("GET") - val HEAD = ApiMethod("HEAD") - val OPTIONS = ApiMethod("OPTIONS") - val PATCH = ApiMethod("PATCH") - val POST = ApiMethod("POST") - val PUT = ApiMethod("PUT") - val TRACE = ApiMethod("TRACE") -} - -/** - * This trait needs to be added to any model defined by the api. - */ -trait ApiModel - -/** - * Single trait defining a credential that can be transformed to a paramName / paramValue tupple - */ -sealed trait Credentials { - def asQueryParam: Option[(String, String)] = None -} - -sealed case class BasicCredentials(user: String, password: String) extends Credentials - -sealed case class BearerToken(token: String) extends Credentials - -sealed case class ApiKeyCredentials(key: ApiKeyValue, keyName: String, location: ApiKeyLocation) extends Credentials { - override def asQueryParam: Option[(String, String)] = location match { - case ApiKeyLocations.QUERY => Some((keyName, key.value)) - case _ => None - } -} - -sealed case class ApiKeyValue(value: String) - -sealed trait ApiKeyLocation - -object ApiKeyLocations { - - case object QUERY extends ApiKeyLocation - - case object HEADER extends ApiKeyLocation - - case object COOKIE extends ApiKeyLocation - -} - - -/** - * Case class used to unapply numeric values only in pattern matching - * - * @param value the string representation of the numeric value - */ -sealed case class NumericValue(value: String) { - override def toString: String = value -} - -object NumericValue { - def unapply(n: Any): Option[NumericValue] = n match { - case (_: Int | _: Long | _: Float | _: Double | _: Boolean | _: Byte) => Some(NumericValue(String.valueOf(n))) - case _ => None - } -} - -/** - * Used for params being arrays - */ -sealed case class ArrayValues(values: Seq[Any], format: CollectionFormat = CollectionFormats.CSV) - -object ArrayValues { - def apply(values: Option[Seq[Any]], format: CollectionFormat): ArrayValues = - ArrayValues(values.getOrElse(Seq.empty), format) - - def apply(values: Option[Seq[Any]]): ArrayValues = ArrayValues(values, CollectionFormats.CSV) -} - - -/** - * Defines how arrays should be rendered in query strings. - */ -sealed trait CollectionFormat - -trait MergedArrayFormat extends CollectionFormat { - def separator: String -} - -object CollectionFormats { - - case object CSV extends MergedArrayFormat { - override val separator = "," - } - - case object TSV extends MergedArrayFormat { - override val separator = "\t" - } - - case object SSV extends MergedArrayFormat { - override val separator = " " - } - - case object PIPES extends MergedArrayFormat { - override val separator = "|" - } - - case object MULTI extends CollectionFormat - -} - -object ParametersMap { - - /** - * Pimp parameters maps (Map[String, Any]) in order to transform them in a sequence of String -> Any tupples, - * with valid url-encoding, arrays handling, files preservation, ... - */ - implicit class ParametersMapImprovements(val m: Map[String, Any]) { - - def asFormattedParamsList: List[(String, Any)] = m.toList.flatMap(formattedParams) - - def asFormattedParams: Map[String, Any] = m.flatMap(formattedParams) - - private def urlEncode(v: Any) = URLEncoder.encode(String.valueOf(v), "utf-8").replaceAll("\\+", "%20") - - private def formattedParams(tuple: (String, Any)): Seq[(String, Any)] = formattedParams(tuple._1, tuple._2) - - private def formattedParams(name: String, value: Any): Seq[(String, Any)] = value match { - case arr: ArrayValues => - arr.format match { - case CollectionFormats.MULTI => arr.values.flatMap(formattedParams(name, _)) - case format: MergedArrayFormat => Seq((name, arr.values.mkString(format.separator))) - } - case None => Seq.empty - case Some(opt) => formattedParams(name, opt) - case s: Seq[Any] => formattedParams(name, ArrayValues(s)) - case v: String => Seq((name, urlEncode(v))) - case NumericValue(v) => Seq((name, urlEncode(v))) - case f: File => Seq((name, f)) - case m: ApiModel => Seq((name, m)) - } - } - -} diff --git a/samples/server/petstore/scala-akka-http-server/.openapi-generator/VERSION b/samples/server/petstore/scala-akka-http-server/.openapi-generator/VERSION index b5d898602c2c..d99e7162d01f 100644 --- a/samples/server/petstore/scala-akka-http-server/.openapi-generator/VERSION +++ b/samples/server/petstore/scala-akka-http-server/.openapi-generator/VERSION @@ -1 +1 @@ -4.3.1-SNAPSHOT \ No newline at end of file +5.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/api/PetApi.scala b/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/api/PetApi.scala index 4c437290a56c..d7c7a6dc8f67 100644 --- a/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/api/PetApi.scala +++ b/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/api/PetApi.scala @@ -30,8 +30,8 @@ class PetApi( lazy val route: Route = path("pet") { post { - entity(as[Pet]){ body => - petService.addPet(body = body) + entity(as[Pet]){ pet => + petService.addPet(pet = pet) } } } ~ @@ -63,8 +63,8 @@ class PetApi( } ~ path("pet") { put { - entity(as[Pet]){ body => - petService.updatePet(body = body) + entity(as[Pet]){ pet => + petService.updatePet(pet = pet) } } } ~ @@ -95,12 +95,16 @@ class PetApi( trait PetApiService { + def addPet200(responsePet: Pet)(implicit toEntityMarshallerPet: ToEntityMarshaller[Pet]): Route = + complete((200, responsePet)) def addPet405: Route = complete((405, "Invalid input")) /** + * Code: 200, Message: successful operation, DataType: Pet * Code: 405, Message: Invalid input */ - def addPet(body: Pet): Route + def addPet(pet: Pet) + (implicit toEntityMarshallerPet: ToEntityMarshaller[Pet]): Route def deletePet400: Route = complete((400, "Invalid pet value")) @@ -145,6 +149,8 @@ trait PetApiService { def getPetById(petId: Long) (implicit toEntityMarshallerPet: ToEntityMarshaller[Pet]): Route + def updatePet200(responsePet: Pet)(implicit toEntityMarshallerPet: ToEntityMarshaller[Pet]): Route = + complete((200, responsePet)) def updatePet400: Route = complete((400, "Invalid ID supplied")) def updatePet404: Route = @@ -152,11 +158,13 @@ trait PetApiService { def updatePet405: Route = complete((405, "Validation exception")) /** + * Code: 200, Message: successful operation, DataType: Pet * Code: 400, Message: Invalid ID supplied * Code: 404, Message: Pet not found * Code: 405, Message: Validation exception */ - def updatePet(body: Pet): Route + def updatePet(pet: Pet) + (implicit toEntityMarshallerPet: ToEntityMarshaller[Pet]): Route def updatePetWithForm405: Route = complete((405, "Invalid input")) diff --git a/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/api/StoreApi.scala b/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/api/StoreApi.scala index 7d8a1743b0e1..26cbeaec84b6 100644 --- a/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/api/StoreApi.scala +++ b/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/api/StoreApi.scala @@ -36,8 +36,8 @@ class StoreApi( } ~ path("store" / "order") { post { - entity(as[Order]){ body => - storeService.placeOrder(body = body) + entity(as[Order]){ order => + storeService.placeOrder(order = order) } } } @@ -85,7 +85,7 @@ trait StoreApiService { * Code: 200, Message: successful operation, DataType: Order * Code: 400, Message: Invalid Order */ - def placeOrder(body: Order) + def placeOrder(order: Order) (implicit toEntityMarshallerOrder: ToEntityMarshaller[Order]): Route } diff --git a/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/api/UserApi.scala b/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/api/UserApi.scala index 2470f1e036c1..2d2dc2a7c6e3 100644 --- a/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/api/UserApi.scala +++ b/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/api/UserApi.scala @@ -21,22 +21,22 @@ class UserApi( lazy val route: Route = path("user") { post { - entity(as[User]){ body => - userService.createUser(body = body) + entity(as[User]){ user => + userService.createUser(user = user) } } } ~ path("user" / "createWithArray") { post { - entity(as[Seq[User]]){ body => - userService.createUsersWithArrayInput(body = body) + entity(as[Seq[User]]){ user => + userService.createUsersWithArrayInput(user = user) } } } ~ path("user" / "createWithList") { post { - entity(as[Seq[User]]){ body => - userService.createUsersWithListInput(body = body) + entity(as[Seq[User]]){ user => + userService.createUsersWithListInput(user = user) } } } ~ @@ -64,8 +64,8 @@ class UserApi( } ~ path("user" / Segment) { (username) => put { - entity(as[User]){ body => - userService.updateUser(username = username, body = body) + entity(as[User]){ user => + userService.updateUser(username = username, user = user) } } } @@ -79,21 +79,21 @@ trait UserApiService { /** * Code: 0, Message: successful operation */ - def createUser(body: User): Route + def createUser(user: User): Route def createUsersWithArrayInputDefault(statusCode: Int): Route = complete((statusCode, "successful operation")) /** * Code: 0, Message: successful operation */ - def createUsersWithArrayInput(body: Seq[User]): Route + def createUsersWithArrayInput(user: Seq[User]): Route def createUsersWithListInputDefault(statusCode: Int): Route = complete((statusCode, "successful operation")) /** * Code: 0, Message: successful operation */ - def createUsersWithListInput(body: Seq[User]): Route + def createUsersWithListInput(user: Seq[User]): Route def deleteUser400: Route = complete((400, "Invalid username supplied")) @@ -144,7 +144,7 @@ trait UserApiService { * Code: 400, Message: Invalid user supplied * Code: 404, Message: User not found */ - def updateUser(username: String, body: User): Route + def updateUser(username: String, user: User): Route } diff --git a/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/model/InlineObject.scala b/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/model/InlineObject.scala new file mode 100644 index 000000000000..eba3cf1fa1ef --- /dev/null +++ b/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/model/InlineObject.scala @@ -0,0 +1,12 @@ +package org.openapitools.server.model + + +/** + * @param name Updated name of the pet for example: ''null'' + * @param status Updated status of the pet for example: ''null'' +*/ +final case class InlineObject ( + name: Option[String], + status: Option[String] +) + diff --git a/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/model/InlineObject1.scala b/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/model/InlineObject1.scala new file mode 100644 index 000000000000..36afc679abf0 --- /dev/null +++ b/samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/model/InlineObject1.scala @@ -0,0 +1,13 @@ +package org.openapitools.server.model + +import java.io.File + +/** + * @param additionalMetadata Additional data to pass to server for example: ''null'' + * @param file file to upload for example: ''null'' +*/ +final case class InlineObject1 ( + additionalMetadata: Option[String], + file: Option[File] +) + diff --git a/samples/server/petstore/scala-finch/.openapi-generator/FILES b/samples/server/petstore/scala-finch/.openapi-generator/FILES new file mode 100644 index 000000000000..6bfce1fa7c2b --- /dev/null +++ b/samples/server/petstore/scala-finch/.openapi-generator/FILES @@ -0,0 +1,18 @@ +README.md +build.sbt +project/build.properties +project/plugins.sbt +sbt +src/main/scala/DataAccessor.scala +src/main/scala/Server.scala +src/main/scala/endpoint.scala +src/main/scala/errors.scala +src/main/scala/org/openapitools/apis/PetApi.scala +src/main/scala/org/openapitools/apis/StoreApi.scala +src/main/scala/org/openapitools/apis/UserApi.scala +src/main/scala/org/openapitools/models/ApiResponse.scala +src/main/scala/org/openapitools/models/Category.scala +src/main/scala/org/openapitools/models/Order.scala +src/main/scala/org/openapitools/models/Pet.scala +src/main/scala/org/openapitools/models/Tag.scala +src/main/scala/org/openapitools/models/User.scala diff --git a/samples/server/petstore/scala-finch/.openapi-generator/VERSION b/samples/server/petstore/scala-finch/.openapi-generator/VERSION index bfbf77eb7fad..d99e7162d01f 100644 --- a/samples/server/petstore/scala-finch/.openapi-generator/VERSION +++ b/samples/server/petstore/scala-finch/.openapi-generator/VERSION @@ -1 +1 @@ -4.3.0-SNAPSHOT \ No newline at end of file +5.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/scala-finch/src/main/scala/DataAccessor.scala b/samples/server/petstore/scala-finch/src/main/scala/DataAccessor.scala index a3ed3acc25d1..ef1a3b8c79ae 100644 --- a/samples/server/petstore/scala-finch/src/main/scala/DataAccessor.scala +++ b/samples/server/petstore/scala-finch/src/main/scala/DataAccessor.scala @@ -16,9 +16,9 @@ trait DataAccessor { /** * - * @return A Unit + * @return A Pet */ - def Pet_addPet(body: Pet): Either[CommonError,Unit] = Left(TODO) + def Pet_addPet(pet: Pet): Either[CommonError,Pet] = Left(TODO) /** * @@ -46,9 +46,9 @@ trait DataAccessor { /** * - * @return A Unit + * @return A Pet */ - def Pet_updatePet(body: Pet): Either[CommonError,Unit] = Left(TODO) + def Pet_updatePet(pet: Pet): Either[CommonError,Pet] = Left(TODO) /** * @@ -84,31 +84,31 @@ trait DataAccessor { * * @return A Order */ - def Store_placeOrder(body: Order): Either[CommonError,Order] = Left(TODO) + def Store_placeOrder(order: Order): Either[CommonError,Order] = Left(TODO) /** * * @return A Unit */ - def User_createUser(body: User): Either[CommonError,Unit] = Left(TODO) + def User_createUser(user: User, authParamapi_key: String): Either[CommonError,Unit] = Left(TODO) /** * * @return A Unit */ - def User_createUsersWithArrayInput(body: Seq[User]): Either[CommonError,Unit] = Left(TODO) + def User_createUsersWithArrayInput(user: Seq[User], authParamapi_key: String): Either[CommonError,Unit] = Left(TODO) /** * * @return A Unit */ - def User_createUsersWithListInput(body: Seq[User]): Either[CommonError,Unit] = Left(TODO) + def User_createUsersWithListInput(user: Seq[User], authParamapi_key: String): Either[CommonError,Unit] = Left(TODO) /** * * @return A Unit */ - def User_deleteUser(username: String): Either[CommonError,Unit] = Left(TODO) + def User_deleteUser(username: String, authParamapi_key: String): Either[CommonError,Unit] = Left(TODO) /** * @@ -126,12 +126,12 @@ trait DataAccessor { * * @return A Unit */ - def User_logoutUser(): Either[CommonError,Unit] = Left(TODO) + def User_logoutUser(authParamapi_key: String): Either[CommonError,Unit] = Left(TODO) /** * * @return A Unit */ - def User_updateUser(username: String, body: User): Either[CommonError,Unit] = Left(TODO) + def User_updateUser(username: String, user: User, authParamapi_key: String): Either[CommonError,Unit] = Left(TODO) } \ No newline at end of file diff --git a/samples/server/petstore/scala-finch/src/main/scala/org/openapitools/apis/PetApi.scala b/samples/server/petstore/scala-finch/src/main/scala/org/openapitools/apis/PetApi.scala index 4739fcd42cd1..82a7751658a7 100644 --- a/samples/server/petstore/scala-finch/src/main/scala/org/openapitools/apis/PetApi.scala +++ b/samples/server/petstore/scala-finch/src/main/scala/org/openapitools/apis/PetApi.scala @@ -57,11 +57,11 @@ object PetApi { /** * - * @return An endpoint representing a Unit + * @return An endpoint representing a Pet */ - private def addPet(da: DataAccessor): Endpoint[Unit] = - post("pet" :: jsonBody[Pet]) { (body: Pet) => - da.Pet_addPet(body) match { + private def addPet(da: DataAccessor): Endpoint[Pet] = + post("pet" :: jsonBody[Pet]) { (pet: Pet) => + da.Pet_addPet(pet) match { case Left(error) => checkError(error) case Right(data) => Ok(data) } @@ -127,11 +127,11 @@ object PetApi { /** * - * @return An endpoint representing a Unit + * @return An endpoint representing a Pet */ - private def updatePet(da: DataAccessor): Endpoint[Unit] = - put("pet" :: jsonBody[Pet]) { (body: Pet) => - da.Pet_updatePet(body) match { + private def updatePet(da: DataAccessor): Endpoint[Pet] = + put("pet" :: jsonBody[Pet]) { (pet: Pet) => + da.Pet_updatePet(pet) match { case Left(error) => checkError(error) case Right(data) => Ok(data) } diff --git a/samples/server/petstore/scala-finch/src/main/scala/org/openapitools/apis/StoreApi.scala b/samples/server/petstore/scala-finch/src/main/scala/org/openapitools/apis/StoreApi.scala index 83d674624ce6..7fff45a72260 100644 --- a/samples/server/petstore/scala-finch/src/main/scala/org/openapitools/apis/StoreApi.scala +++ b/samples/server/petstore/scala-finch/src/main/scala/org/openapitools/apis/StoreApi.scala @@ -96,8 +96,8 @@ object StoreApi { * @return An endpoint representing a Order */ private def placeOrder(da: DataAccessor): Endpoint[Order] = - post("store" :: "order" :: jsonBody[Order]) { (body: Order) => - da.Store_placeOrder(body) match { + post("store" :: "order" :: jsonBody[Order]) { (order: Order) => + da.Store_placeOrder(order) match { case Left(error) => checkError(error) case Right(data) => Ok(data) } diff --git a/samples/server/petstore/scala-finch/src/main/scala/org/openapitools/apis/UserApi.scala b/samples/server/petstore/scala-finch/src/main/scala/org/openapitools/apis/UserApi.scala index e16a0fbcdb8a..66eda4c4d425 100644 --- a/samples/server/petstore/scala-finch/src/main/scala/org/openapitools/apis/UserApi.scala +++ b/samples/server/petstore/scala-finch/src/main/scala/org/openapitools/apis/UserApi.scala @@ -59,8 +59,8 @@ object UserApi { * @return An endpoint representing a Unit */ private def createUser(da: DataAccessor): Endpoint[Unit] = - post("user" :: jsonBody[User]) { (body: User) => - da.User_createUser(body) match { + post("user" :: jsonBody[User] :: header("api_key")) { (user: User, authParamapi_key: String) => + da.User_createUser(user, authParamapi_key) match { case Left(error) => checkError(error) case Right(data) => Ok(data) } @@ -73,8 +73,8 @@ object UserApi { * @return An endpoint representing a Unit */ private def createUsersWithArrayInput(da: DataAccessor): Endpoint[Unit] = - post("user" :: "createWithArray" :: jsonBody[Seq[User]]) { (body: Seq[User]) => - da.User_createUsersWithArrayInput(body) match { + post("user" :: "createWithArray" :: jsonBody[Seq[User]] :: header("api_key")) { (user: Seq[User], authParamapi_key: String) => + da.User_createUsersWithArrayInput(user, authParamapi_key) match { case Left(error) => checkError(error) case Right(data) => Ok(data) } @@ -87,8 +87,8 @@ object UserApi { * @return An endpoint representing a Unit */ private def createUsersWithListInput(da: DataAccessor): Endpoint[Unit] = - post("user" :: "createWithList" :: jsonBody[Seq[User]]) { (body: Seq[User]) => - da.User_createUsersWithListInput(body) match { + post("user" :: "createWithList" :: jsonBody[Seq[User]] :: header("api_key")) { (user: Seq[User], authParamapi_key: String) => + da.User_createUsersWithListInput(user, authParamapi_key) match { case Left(error) => checkError(error) case Right(data) => Ok(data) } @@ -101,8 +101,8 @@ object UserApi { * @return An endpoint representing a Unit */ private def deleteUser(da: DataAccessor): Endpoint[Unit] = - delete("user" :: string) { (username: String) => - da.User_deleteUser(username) match { + delete("user" :: string :: header("api_key")) { (username: String, authParamapi_key: String) => + da.User_deleteUser(username, authParamapi_key) match { case Left(error) => checkError(error) case Right(data) => Ok(data) } @@ -143,8 +143,8 @@ object UserApi { * @return An endpoint representing a Unit */ private def logoutUser(da: DataAccessor): Endpoint[Unit] = - get("user" :: "logout") { () => - da.User_logoutUser() match { + get("user" :: "logout" :: header("api_key")) { (authParamapi_key: String) => + da.User_logoutUser(authParamapi_key) match { case Left(error) => checkError(error) case Right(data) => Ok(data) } @@ -157,8 +157,8 @@ object UserApi { * @return An endpoint representing a Unit */ private def updateUser(da: DataAccessor): Endpoint[Unit] = - put("user" :: string :: jsonBody[User]) { (username: String, body: User) => - da.User_updateUser(username, body) match { + put("user" :: string :: jsonBody[User] :: header("api_key")) { (username: String, user: User, authParamapi_key: String) => + da.User_updateUser(username, user, authParamapi_key) match { case Left(error) => checkError(error) case Right(data) => Ok(data) } diff --git a/samples/server/petstore/scala-lagom-server/.openapi-generator/FILES b/samples/server/petstore/scala-lagom-server/.openapi-generator/FILES new file mode 100644 index 000000000000..2225d2f9f924 --- /dev/null +++ b/samples/server/petstore/scala-lagom-server/.openapi-generator/FILES @@ -0,0 +1,14 @@ +.gitignore +README.md +build.sbt +project/build.properties +project/plugins.sbt +src/main/scala/io/swagger/client/api/PetApi.scala +src/main/scala/io/swagger/client/api/StoreApi.scala +src/main/scala/io/swagger/client/api/UserApi.scala +src/main/scala/io/swagger/client/model/ApiResponse.scala +src/main/scala/io/swagger/client/model/Category.scala +src/main/scala/io/swagger/client/model/Order.scala +src/main/scala/io/swagger/client/model/Pet.scala +src/main/scala/io/swagger/client/model/Tag.scala +src/main/scala/io/swagger/client/model/User.scala diff --git a/samples/server/petstore/scala-lagom-server/.openapi-generator/VERSION b/samples/server/petstore/scala-lagom-server/.openapi-generator/VERSION index bfbf77eb7fad..d99e7162d01f 100644 --- a/samples/server/petstore/scala-lagom-server/.openapi-generator/VERSION +++ b/samples/server/petstore/scala-lagom-server/.openapi-generator/VERSION @@ -1 +1 @@ -4.3.0-SNAPSHOT \ No newline at end of file +5.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/scala-lagom-server/src/main/scala/io/swagger/client/api/PetApi.scala b/samples/server/petstore/scala-lagom-server/src/main/scala/io/swagger/client/api/PetApi.scala index 559f0820c428..c452652ee57b 100644 --- a/samples/server/petstore/scala-lagom-server/src/main/scala/io/swagger/client/api/PetApi.scala +++ b/samples/server/petstore/scala-lagom-server/src/main/scala/io/swagger/client/api/PetApi.scala @@ -44,9 +44,9 @@ trait PetApi extends Service { * Add a new pet to the store * * - * @return void Body Parameter Pet object that needs to be added to the store + * @return Pet Body Parameter Pet object that needs to be added to the store */ - def addPet(): ServiceCall[Pet ,Done] + def addPet(): ServiceCall[Pet ,Pet] // apiKey:String -- not yet supported heder params @@ -95,9 +95,9 @@ trait PetApi extends Service { * Update an existing pet * * - * @return void Body Parameter Pet object that needs to be added to the store + * @return Pet Body Parameter Pet object that needs to be added to the store */ - def updatePet(): ServiceCall[Pet ,Done] + def updatePet(): ServiceCall[Pet ,Pet] // name:String -- not yet supported x-www-form-urlencoded diff --git a/samples/server/petstore/scala-play-server/.openapi-generator/VERSION b/samples/server/petstore/scala-play-server/.openapi-generator/VERSION index bfbf77eb7fad..d99e7162d01f 100644 --- a/samples/server/petstore/scala-play-server/.openapi-generator/VERSION +++ b/samples/server/petstore/scala-play-server/.openapi-generator/VERSION @@ -1 +1 @@ -4.3.0-SNAPSHOT \ No newline at end of file +5.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/scala-play-server/app/api/PetApi.scala b/samples/server/petstore/scala-play-server/app/api/PetApi.scala index e19a3ae4acfc..7b2720c41d22 100644 --- a/samples/server/petstore/scala-play-server/app/api/PetApi.scala +++ b/samples/server/petstore/scala-play-server/app/api/PetApi.scala @@ -8,9 +8,9 @@ import play.api.libs.Files.TemporaryFile trait PetApi { /** * Add a new pet to the store - * @param body Pet object that needs to be added to the store + * @param pet Pet object that needs to be added to the store */ - def addPet(body: Pet): Unit + def addPet(pet: Pet): Pet /** * Deletes a pet @@ -41,9 +41,9 @@ trait PetApi { /** * Update an existing pet - * @param body Pet object that needs to be added to the store + * @param pet Pet object that needs to be added to the store */ - def updatePet(body: Pet): Unit + def updatePet(pet: Pet): Pet /** * Updates a pet in the store with form data diff --git a/samples/server/petstore/scala-play-server/app/api/PetApiController.scala b/samples/server/petstore/scala-play-server/app/api/PetApiController.scala index 1ecb6759060d..78474bbfc871 100644 --- a/samples/server/petstore/scala-play-server/app/api/PetApiController.scala +++ b/samples/server/petstore/scala-play-server/app/api/PetApiController.scala @@ -15,15 +15,16 @@ class PetApiController @Inject()(cc: ControllerComponents, api: PetApi) extends * POST /v2/pet */ def addPet(): Action[AnyContent] = Action { request => - def executeApi(): Unit = { - val body = request.body.asJson.map(_.as[Pet]).getOrElse { - throw new OpenApiExceptions.MissingRequiredParameterException("body", "body") + def executeApi(): Pet = { + val pet = request.body.asJson.map(_.as[Pet]).getOrElse { + throw new OpenApiExceptions.MissingRequiredParameterException("body", "pet") } - api.addPet(body) + api.addPet(pet) } - executeApi() - Ok + val result = executeApi() + val json = Json.toJson(result) + Ok(json) } /** @@ -95,15 +96,16 @@ class PetApiController @Inject()(cc: ControllerComponents, api: PetApi) extends * PUT /v2/pet */ def updatePet(): Action[AnyContent] = Action { request => - def executeApi(): Unit = { - val body = request.body.asJson.map(_.as[Pet]).getOrElse { - throw new OpenApiExceptions.MissingRequiredParameterException("body", "body") + def executeApi(): Pet = { + val pet = request.body.asJson.map(_.as[Pet]).getOrElse { + throw new OpenApiExceptions.MissingRequiredParameterException("body", "pet") } - api.updatePet(body) + api.updatePet(pet) } - executeApi() - Ok + val result = executeApi() + val json = Json.toJson(result) + Ok(json) } /** diff --git a/samples/server/petstore/scala-play-server/app/api/PetApiImpl.scala b/samples/server/petstore/scala-play-server/app/api/PetApiImpl.scala index f28822692299..9009943e2388 100644 --- a/samples/server/petstore/scala-play-server/app/api/PetApiImpl.scala +++ b/samples/server/petstore/scala-play-server/app/api/PetApiImpl.scala @@ -12,10 +12,10 @@ class PetApiImpl extends PetApi { /** * @inheritdoc */ - override def addPet(body: Pet): Unit = { + override def addPet(pet: Pet): Pet = { // TODO: Implement better logic - + Pet(None, None, "", List.empty[String], None, None) } /** @@ -57,10 +57,10 @@ class PetApiImpl extends PetApi { /** * @inheritdoc */ - override def updatePet(body: Pet): Unit = { + override def updatePet(pet: Pet): Pet = { // TODO: Implement better logic - + Pet(None, None, "", List.empty[String], None, None) } /** diff --git a/samples/server/petstore/scala-play-server/app/api/StoreApi.scala b/samples/server/petstore/scala-play-server/app/api/StoreApi.scala index 4c9ed54ecd34..0c0f205203f3 100644 --- a/samples/server/petstore/scala-play-server/app/api/StoreApi.scala +++ b/samples/server/petstore/scala-play-server/app/api/StoreApi.scala @@ -26,7 +26,7 @@ trait StoreApi { /** * Place an order for a pet - * @param body order placed for purchasing the pet + * @param order order placed for purchasing the pet */ - def placeOrder(body: Order): Order + def placeOrder(order: Order): Order } diff --git a/samples/server/petstore/scala-play-server/app/api/StoreApiController.scala b/samples/server/petstore/scala-play-server/app/api/StoreApiController.scala index 199267c1582a..41e06c35f05a 100644 --- a/samples/server/petstore/scala-play-server/app/api/StoreApiController.scala +++ b/samples/server/petstore/scala-play-server/app/api/StoreApiController.scala @@ -54,10 +54,10 @@ class StoreApiController @Inject()(cc: ControllerComponents, api: StoreApi) exte */ def placeOrder(): Action[AnyContent] = Action { request => def executeApi(): Order = { - val body = request.body.asJson.map(_.as[Order]).getOrElse { - throw new OpenApiExceptions.MissingRequiredParameterException("body", "body") + val order = request.body.asJson.map(_.as[Order]).getOrElse { + throw new OpenApiExceptions.MissingRequiredParameterException("body", "order") } - api.placeOrder(body) + api.placeOrder(order) } val result = executeApi() diff --git a/samples/server/petstore/scala-play-server/app/api/StoreApiImpl.scala b/samples/server/petstore/scala-play-server/app/api/StoreApiImpl.scala index bdb03b1cb089..ab21013f9abe 100644 --- a/samples/server/petstore/scala-play-server/app/api/StoreApiImpl.scala +++ b/samples/server/petstore/scala-play-server/app/api/StoreApiImpl.scala @@ -37,7 +37,7 @@ class StoreApiImpl extends StoreApi { /** * @inheritdoc */ - override def placeOrder(body: Order): Order = { + override def placeOrder(order: Order): Order = { // TODO: Implement better logic Order(None, None, None, None, None, None) diff --git a/samples/server/petstore/scala-play-server/app/api/UserApi.scala b/samples/server/petstore/scala-play-server/app/api/UserApi.scala index a0855be3a2f6..548ce3ae03a9 100644 --- a/samples/server/petstore/scala-play-server/app/api/UserApi.scala +++ b/samples/server/petstore/scala-play-server/app/api/UserApi.scala @@ -7,21 +7,21 @@ trait UserApi { /** * Create user * This can only be done by the logged in user. - * @param body Created user object + * @param user Created user object */ - def createUser(body: User): Unit + def createUser(user: User): Unit /** * Creates list of users with given input array - * @param body List of user object + * @param user List of user object */ - def createUsersWithArrayInput(body: List[User]): Unit + def createUsersWithArrayInput(user: List[User]): Unit /** * Creates list of users with given input array - * @param body List of user object + * @param user List of user object */ - def createUsersWithListInput(body: List[User]): Unit + def createUsersWithListInput(user: List[User]): Unit /** * Delete user @@ -52,7 +52,7 @@ trait UserApi { * Updated user * This can only be done by the logged in user. * @param username name that need to be deleted - * @param body Updated user object + * @param user Updated user object */ - def updateUser(username: String, body: User): Unit + def updateUser(username: String, user: User): Unit } diff --git a/samples/server/petstore/scala-play-server/app/api/UserApiController.scala b/samples/server/petstore/scala-play-server/app/api/UserApiController.scala index 6298be9d826f..f50910f852cb 100644 --- a/samples/server/petstore/scala-play-server/app/api/UserApiController.scala +++ b/samples/server/petstore/scala-play-server/app/api/UserApiController.scala @@ -14,10 +14,10 @@ class UserApiController @Inject()(cc: ControllerComponents, api: UserApi) extend */ def createUser(): Action[AnyContent] = Action { request => def executeApi(): Unit = { - val body = request.body.asJson.map(_.as[User]).getOrElse { - throw new OpenApiExceptions.MissingRequiredParameterException("body", "body") + val user = request.body.asJson.map(_.as[User]).getOrElse { + throw new OpenApiExceptions.MissingRequiredParameterException("body", "user") } - api.createUser(body) + api.createUser(user) } executeApi() @@ -29,10 +29,10 @@ class UserApiController @Inject()(cc: ControllerComponents, api: UserApi) extend */ def createUsersWithArrayInput(): Action[AnyContent] = Action { request => def executeApi(): Unit = { - val body = request.body.asJson.map(_.as[List[User]]).getOrElse { - throw new OpenApiExceptions.MissingRequiredParameterException("body", "body") + val user = request.body.asJson.map(_.as[List[User]]).getOrElse { + throw new OpenApiExceptions.MissingRequiredParameterException("body", "user") } - api.createUsersWithArrayInput(body) + api.createUsersWithArrayInput(user) } executeApi() @@ -44,10 +44,10 @@ class UserApiController @Inject()(cc: ControllerComponents, api: UserApi) extend */ def createUsersWithListInput(): Action[AnyContent] = Action { request => def executeApi(): Unit = { - val body = request.body.asJson.map(_.as[List[User]]).getOrElse { - throw new OpenApiExceptions.MissingRequiredParameterException("body", "body") + val user = request.body.asJson.map(_.as[List[User]]).getOrElse { + throw new OpenApiExceptions.MissingRequiredParameterException("body", "user") } - api.createUsersWithListInput(body) + api.createUsersWithListInput(user) } executeApi() @@ -120,10 +120,10 @@ class UserApiController @Inject()(cc: ControllerComponents, api: UserApi) extend */ def updateUser(username: String): Action[AnyContent] = Action { request => def executeApi(): Unit = { - val body = request.body.asJson.map(_.as[User]).getOrElse { - throw new OpenApiExceptions.MissingRequiredParameterException("body", "body") + val user = request.body.asJson.map(_.as[User]).getOrElse { + throw new OpenApiExceptions.MissingRequiredParameterException("body", "user") } - api.updateUser(username, body) + api.updateUser(username, user) } executeApi() diff --git a/samples/server/petstore/scala-play-server/app/api/UserApiImpl.scala b/samples/server/petstore/scala-play-server/app/api/UserApiImpl.scala index 952bcd745fd1..2a7a35c73616 100644 --- a/samples/server/petstore/scala-play-server/app/api/UserApiImpl.scala +++ b/samples/server/petstore/scala-play-server/app/api/UserApiImpl.scala @@ -10,7 +10,7 @@ class UserApiImpl extends UserApi { /** * @inheritdoc */ - override def createUser(body: User): Unit = { + override def createUser(user: User): Unit = { // TODO: Implement better logic @@ -19,7 +19,7 @@ class UserApiImpl extends UserApi { /** * @inheritdoc */ - override def createUsersWithArrayInput(body: List[User]): Unit = { + override def createUsersWithArrayInput(user: List[User]): Unit = { // TODO: Implement better logic @@ -28,7 +28,7 @@ class UserApiImpl extends UserApi { /** * @inheritdoc */ - override def createUsersWithListInput(body: List[User]): Unit = { + override def createUsersWithListInput(user: List[User]): Unit = { // TODO: Implement better logic @@ -73,7 +73,7 @@ class UserApiImpl extends UserApi { /** * @inheritdoc */ - override def updateUser(username: String, body: User): Unit = { + override def updateUser(username: String, user: User): Unit = { // TODO: Implement better logic diff --git a/samples/server/petstore/scala-play-server/app/model/InlineObject.scala b/samples/server/petstore/scala-play-server/app/model/InlineObject.scala new file mode 100644 index 000000000000..62b12791dd43 --- /dev/null +++ b/samples/server/petstore/scala-play-server/app/model/InlineObject.scala @@ -0,0 +1,19 @@ +package model + +import play.api.libs.json._ + +/** + * Represents the Swagger definition for inline_object. + * @param name Updated name of the pet + * @param status Updated status of the pet + */ + +case class InlineObject( + name: Option[String], + status: Option[String] +) + +object InlineObject { + implicit lazy val inlineObjectJsonFormat: Format[InlineObject] = Json.format[InlineObject] +} + diff --git a/samples/server/petstore/scala-play-server/app/model/InlineObject1.scala b/samples/server/petstore/scala-play-server/app/model/InlineObject1.scala new file mode 100644 index 000000000000..a21250d4cbf4 --- /dev/null +++ b/samples/server/petstore/scala-play-server/app/model/InlineObject1.scala @@ -0,0 +1,20 @@ +package model + +import play.api.libs.json._ +import play.api.libs.Files.TemporaryFile + +/** + * Represents the Swagger definition for inline_object_1. + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + */ + +case class InlineObject1( + additionalMetadata: Option[String], + file: Option[TemporaryFile] +) + +object InlineObject1 { + // NOTE: The JSON format for InlineObject1 was not generated because it contains a file variable which cannot be encoded to JSON. +} + diff --git a/samples/server/petstore/scala-play-server/public/openapi.json b/samples/server/petstore/scala-play-server/public/openapi.json index 8ebbe96756fd..75103813bb29 100644 --- a/samples/server/petstore/scala-play-server/public/openapi.json +++ b/samples/server/petstore/scala-play-server/public/openapi.json @@ -1,5 +1,5 @@ { - "openapi" : "3.0.1", + "openapi" : "3.0.0", "info" : { "description" : "This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.", "license" : { @@ -9,6 +9,10 @@ "title" : "OpenAPI Petstore", "version" : "1.0.0" }, + "externalDocs" : { + "description" : "Find out more about Swagger", + "url" : "http://swagger.io" + }, "servers" : [ { "url" : "http://petstore.swagger.io/v2" } ], @@ -27,24 +31,25 @@ "post" : { "operationId" : "addPet", "requestBody" : { - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/Pet" - } - }, - "application/xml" : { - "schema" : { - "$ref" : "#/components/schemas/Pet" - } - } - }, - "description" : "Pet object that needs to be added to the store", - "required" : true + "$ref" : "#/components/requestBodies/Pet" }, "responses" : { + "200" : { + "content" : { + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + }, + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + } + }, + "description" : "successful operation" + }, "405" : { - "content" : { }, "description" : "Invalid input" } }, @@ -52,38 +57,36 @@ "petstore_auth" : [ "write:pets", "read:pets" ] } ], "summary" : "Add a new pet to the store", - "tags" : [ "pet" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "pet" ] }, "put" : { "operationId" : "updatePet", "requestBody" : { - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/Pet" - } - }, - "application/xml" : { - "schema" : { - "$ref" : "#/components/schemas/Pet" - } - } - }, - "description" : "Pet object that needs to be added to the store", - "required" : true + "$ref" : "#/components/requestBodies/Pet" }, "responses" : { + "200" : { + "content" : { + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + }, + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + } + }, + "description" : "successful operation" + }, "400" : { - "content" : { }, "description" : "Invalid ID supplied" }, "404" : { - "content" : { }, "description" : "Pet not found" }, "405" : { - "content" : { }, "description" : "Validation exception" } }, @@ -91,8 +94,7 @@ "petstore_auth" : [ "write:pets", "read:pets" ] } ], "summary" : "Update an existing pet", - "tags" : [ "pet" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "pet" ] } }, "/pet/findByStatus" : { @@ -138,12 +140,11 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid status value" } }, "security" : [ { - "petstore_auth" : [ "write:pets", "read:pets" ] + "petstore_auth" : [ "read:pets" ] } ], "summary" : "Finds Pets by status", "tags" : [ "pet" ] @@ -191,12 +192,11 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid tag value" } }, "security" : [ { - "petstore_auth" : [ "write:pets", "read:pets" ] + "petstore_auth" : [ "read:pets" ] } ], "summary" : "Finds Pets by tags", "tags" : [ "pet" ] @@ -206,24 +206,28 @@ "delete" : { "operationId" : "deletePet", "parameters" : [ { + "explode" : false, "in" : "header", "name" : "api_key", + "required" : false, "schema" : { "type" : "string" - } + }, + "style" : "simple" }, { "description" : "Pet id to delete", + "explode" : false, "in" : "path", "name" : "petId", "required" : true, "schema" : { "format" : "int64", "type" : "integer" - } + }, + "style" : "simple" } ], "responses" : { "400" : { - "content" : { }, "description" : "Invalid pet value" } }, @@ -238,13 +242,15 @@ "operationId" : "getPetById", "parameters" : [ { "description" : "ID of pet to return", + "explode" : false, "in" : "path", "name" : "petId", "required" : true, "schema" : { "format" : "int64", "type" : "integer" - } + }, + "style" : "simple" } ], "responses" : { "200" : { @@ -263,11 +269,9 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid ID supplied" }, "404" : { - "content" : { }, "description" : "Pet not found" } }, @@ -281,15 +285,18 @@ "operationId" : "updatePetWithForm", "parameters" : [ { "description" : "ID of pet that needs to be updated", + "explode" : false, "in" : "path", "name" : "petId", "required" : true, "schema" : { "format" : "int64", "type" : "integer" - } + }, + "style" : "simple" } ], "requestBody" : { + "$ref" : "#/components/requestBodies/inline_object", "content" : { "application/x-www-form-urlencoded" : { "schema" : { @@ -302,14 +309,14 @@ "description" : "Updated status of the pet", "type" : "string" } - } + }, + "type" : "object" } } } }, "responses" : { "405" : { - "content" : { }, "description" : "Invalid input" } }, @@ -325,15 +332,18 @@ "operationId" : "uploadFile", "parameters" : [ { "description" : "ID of pet to update", + "explode" : false, "in" : "path", "name" : "petId", "required" : true, "schema" : { "format" : "int64", "type" : "integer" - } + }, + "style" : "simple" } ], "requestBody" : { + "$ref" : "#/components/requestBodies/inline_object_1", "content" : { "multipart/form-data" : { "schema" : { @@ -347,7 +357,8 @@ "format" : "binary", "type" : "string" } - } + }, + "type" : "object" } } } @@ -403,7 +414,7 @@ "operationId" : "placeOrder", "requestBody" : { "content" : { - "*/*" : { + "application/json" : { "schema" : { "$ref" : "#/components/schemas/Order" } @@ -429,13 +440,11 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid Order" } }, "summary" : "Place an order for a pet", - "tags" : [ "store" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "store" ] } }, "/store/order/{orderId}" : { @@ -444,20 +453,20 @@ "operationId" : "deleteOrder", "parameters" : [ { "description" : "ID of the order that needs to be deleted", + "explode" : false, "in" : "path", "name" : "orderId", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "simple" } ], "responses" : { "400" : { - "content" : { }, "description" : "Invalid ID supplied" }, "404" : { - "content" : { }, "description" : "Order not found" } }, @@ -469,6 +478,7 @@ "operationId" : "getOrderById", "parameters" : [ { "description" : "ID of pet that needs to be fetched", + "explode" : false, "in" : "path", "name" : "orderId", "required" : true, @@ -477,7 +487,8 @@ "maximum" : 5, "minimum" : 1, "type" : "integer" - } + }, + "style" : "simple" } ], "responses" : { "200" : { @@ -496,11 +507,9 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid ID supplied" }, "404" : { - "content" : { }, "description" : "Order not found" } }, @@ -514,7 +523,7 @@ "operationId" : "createUser", "requestBody" : { "content" : { - "*/*" : { + "application/json" : { "schema" : { "$ref" : "#/components/schemas/User" } @@ -525,69 +534,50 @@ }, "responses" : { "default" : { - "content" : { }, "description" : "successful operation" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Create user", - "tags" : [ "user" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "user" ] } }, "/user/createWithArray" : { "post" : { "operationId" : "createUsersWithArrayInput", "requestBody" : { - "content" : { - "*/*" : { - "schema" : { - "items" : { - "$ref" : "#/components/schemas/User" - }, - "type" : "array" - } - } - }, - "description" : "List of user object", - "required" : true + "$ref" : "#/components/requestBodies/UserArray" }, "responses" : { "default" : { - "content" : { }, "description" : "successful operation" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Creates list of users with given input array", - "tags" : [ "user" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "user" ] } }, "/user/createWithList" : { "post" : { "operationId" : "createUsersWithListInput", "requestBody" : { - "content" : { - "*/*" : { - "schema" : { - "items" : { - "$ref" : "#/components/schemas/User" - }, - "type" : "array" - } - } - }, - "description" : "List of user object", - "required" : true + "$ref" : "#/components/requestBodies/UserArray" }, "responses" : { "default" : { - "content" : { }, "description" : "successful operation" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Creates list of users with given input array", - "tags" : [ "user" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "user" ] } }, "/user/login" : { @@ -595,20 +585,25 @@ "operationId" : "loginUser", "parameters" : [ { "description" : "The user name for login", + "explode" : true, "in" : "query", "name" : "username", "required" : true, "schema" : { + "pattern" : "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$", "type" : "string" - } + }, + "style" : "form" }, { "description" : "The password for login in clear text", + "explode" : true, "in" : "query", "name" : "password", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "form" } ], "responses" : { "200" : { @@ -626,24 +621,36 @@ }, "description" : "successful operation", "headers" : { + "Set-Cookie" : { + "description" : "Cookie authentication key for use with the `api_key` apiKey authentication.", + "explode" : false, + "schema" : { + "example" : "AUTH_KEY=abcde12345; Path=/; HttpOnly", + "type" : "string" + }, + "style" : "simple" + }, "X-Rate-Limit" : { "description" : "calls per hour allowed by the user", + "explode" : false, "schema" : { "format" : "int32", "type" : "integer" - } + }, + "style" : "simple" }, "X-Expires-After" : { "description" : "date in UTC when toekn expires", + "explode" : false, "schema" : { "format" : "date-time", "type" : "string" - } + }, + "style" : "simple" } } }, "400" : { - "content" : { }, "description" : "Invalid username/password supplied" } }, @@ -656,10 +663,12 @@ "operationId" : "logoutUser", "responses" : { "default" : { - "content" : { }, "description" : "successful operation" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Logs out current logged in user session", "tags" : [ "user" ] } @@ -670,23 +679,26 @@ "operationId" : "deleteUser", "parameters" : [ { "description" : "The name that needs to be deleted", + "explode" : false, "in" : "path", "name" : "username", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "simple" } ], "responses" : { "400" : { - "content" : { }, "description" : "Invalid username supplied" }, "404" : { - "content" : { }, "description" : "User not found" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Delete user", "tags" : [ "user" ] }, @@ -694,12 +706,14 @@ "operationId" : "getUserByName", "parameters" : [ { "description" : "The name that needs to be fetched. Use user1 for testing.", + "explode" : false, "in" : "path", "name" : "username", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "simple" } ], "responses" : { "200" : { @@ -718,11 +732,9 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid username supplied" }, "404" : { - "content" : { }, "description" : "User not found" } }, @@ -734,16 +746,18 @@ "operationId" : "updateUser", "parameters" : [ { "description" : "name that need to be deleted", + "explode" : false, "in" : "path", "name" : "username", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "simple" } ], "requestBody" : { "content" : { - "*/*" : { + "application/json" : { "schema" : { "$ref" : "#/components/schemas/User" } @@ -754,21 +768,71 @@ }, "responses" : { "400" : { - "content" : { }, "description" : "Invalid user supplied" }, "404" : { - "content" : { }, "description" : "User not found" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Updated user", - "tags" : [ "user" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "user" ] } } }, "components" : { + "requestBodies" : { + "UserArray" : { + "content" : { + "application/json" : { + "schema" : { + "items" : { + "$ref" : "#/components/schemas/User" + }, + "type" : "array" + } + } + }, + "description" : "List of user object", + "required" : true + }, + "Pet" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + }, + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + } + }, + "description" : "Pet object that needs to be added to the store", + "required" : true + }, + "inline_object" : { + "content" : { + "application/x-www-form-urlencoded" : { + "schema" : { + "$ref" : "#/components/schemas/inline_object" + } + } + } + }, + "inline_object_1" : { + "content" : { + "multipart/form-data" : { + "schema" : { + "$ref" : "#/components/schemas/inline_object_1" + } + } + } + } + }, "schemas" : { "Order" : { "description" : "An order for a pets from the pet store", @@ -825,6 +889,7 @@ "type" : "integer" }, "name" : { + "pattern" : "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$", "type" : "string" } }, @@ -987,6 +1052,33 @@ }, "title" : "An uploaded response", "type" : "object" + }, + "inline_object" : { + "properties" : { + "name" : { + "description" : "Updated name of the pet", + "type" : "string" + }, + "status" : { + "description" : "Updated status of the pet", + "type" : "string" + } + }, + "type" : "object" + }, + "inline_object_1" : { + "properties" : { + "additionalMetadata" : { + "description" : "Additional data to pass to server", + "type" : "string" + }, + "file" : { + "description" : "file to upload", + "format" : "binary", + "type" : "string" + } + }, + "type" : "object" } }, "securitySchemes" : { diff --git a/samples/server/petstore/scalatra/.openapi-generator/VERSION b/samples/server/petstore/scalatra/.openapi-generator/VERSION index bfbf77eb7fad..d99e7162d01f 100644 --- a/samples/server/petstore/scalatra/.openapi-generator/VERSION +++ b/samples/server/petstore/scalatra/.openapi-generator/VERSION @@ -1 +1 @@ -4.3.0-SNAPSHOT \ No newline at end of file +5.0.0-SNAPSHOT \ No newline at end of file