From a7da9039a494c4c9f2a4b8f94c89965e41a3fe2f Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sun, 22 Apr 2018 22:00:49 +0800 Subject: [PATCH] Update Scala petstore with OAS2, OAS3 (#162) * update pestore with oas2 * update scala petstore oas3 (no diff) --- bin/openapi3/scala-petstore.sh | 31 ++++++++ .../petstore/scala/.swagger-codegen/VERSION | 2 +- samples/client/petstore/scala/pom.xml | 3 +- .../scala/io/swagger/client/api/PetApi.scala | 36 ++++----- .../io/swagger/client/api/StoreApi.scala | 18 ++--- .../scala/io/swagger/client/api/UserApi.scala | 76 +++++++++---------- 6 files changed, 98 insertions(+), 68 deletions(-) create mode 100755 bin/openapi3/scala-petstore.sh diff --git a/bin/openapi3/scala-petstore.sh b/bin/openapi3/scala-petstore.sh new file mode 100755 index 00000000000..9edea17d912 --- /dev/null +++ b/bin/openapi3/scala-petstore.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +SCRIPT="$0" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" + +if [ ! -f "$executable" ] +then + mvn clean package +fi + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" +ags="$@ generate -t modules/openapi-generator/src/main/resources/scala -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -l scala -o samples/client/petstore/scala" + +java $JAVA_OPTS -jar $executable $ags diff --git a/samples/client/petstore/scala/.swagger-codegen/VERSION b/samples/client/petstore/scala/.swagger-codegen/VERSION index b4308ebebb5..096bf47efe3 100644 --- a/samples/client/petstore/scala/.swagger-codegen/VERSION +++ b/samples/client/petstore/scala/.swagger-codegen/VERSION @@ -1 +1 @@ -2.4.0-SNAPSHOT +3.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/scala/pom.xml b/samples/client/petstore/scala/pom.xml index dc83c236251..c82ecc1cb2e 100644 --- a/samples/client/petstore/scala/pom.xml +++ b/samples/client/petstore/scala/pom.xml @@ -124,8 +124,7 @@ maven-compiler-plugin 3.6.1 - - 1.7 + 1.7 1.7 diff --git a/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/PetApi.scala b/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/PetApi.scala index 4763f547e1a..ccfec0fc377 100644 --- a/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/PetApi.scala +++ b/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/PetApi.scala @@ -85,11 +85,11 @@ class 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 * @return void */ - def addPet(body: Pet) = { - val await = Try(Await.result(addPetAsync(body), Duration.Inf)) + def addPet(pet: Pet) = { + val await = Try(Await.result(addPetAsync(pet), Duration.Inf)) await match { case Success(i) => Some(await.get) case Failure(t) => None @@ -100,11 +100,11 @@ class PetApi( * Add a new pet to the store asynchronously * * - * @param body Pet object that needs to be added to the store + * @param pet Pet object that needs to be added to the store * @return Future(void) */ - def addPetAsync(body: Pet) = { - helper.addPet(body) + def addPetAsync(pet: Pet) = { + helper.addPet(pet) } /** @@ -217,11 +217,11 @@ class 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 * @return void */ - def updatePet(body: Pet) = { - val await = Try(Await.result(updatePetAsync(body), Duration.Inf)) + def updatePet(pet: Pet) = { + val await = Try(Await.result(updatePetAsync(pet), Duration.Inf)) await match { case Success(i) => Some(await.get) case Failure(t) => None @@ -232,11 +232,11 @@ class PetApi( * Update an existing pet asynchronously * * - * @param body Pet object that needs to be added to the store + * @param pet Pet object that needs to be added to the store * @return Future(void) */ - def updatePetAsync(body: Pet) = { - helper.updatePet(body) + def updatePetAsync(pet: Pet) = { + helper.updatePet(pet) } /** @@ -303,7 +303,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[Unit], writer: RequestWriter[Pet]): Future[Unit] = { // create path and map variables val path = (addFmt("/pet")) @@ -311,9 +311,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 => process(reader.read(resp)) } @@ -391,7 +391,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[Unit], writer: RequestWriter[Pet]): Future[Unit] = { // create path and map variables val path = (addFmt("/pet")) @@ -399,9 +399,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 => process(reader.read(resp)) } diff --git a/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/StoreApi.scala b/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/StoreApi.scala index 5c2d86cd962..aa35712e026 100644 --- a/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/StoreApi.scala +++ b/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/StoreApi.scala @@ -159,11 +159,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 @@ -174,11 +174,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) } } @@ -234,7 +234,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")) @@ -242,9 +242,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 => process(reader.read(resp)) } diff --git a/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/UserApi.scala b/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/UserApi.scala index cd8690b7c3b..89044240950 100644 --- a/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/UserApi.scala +++ b/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/UserApi.scala @@ -83,11 +83,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 @@ -98,22 +98,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 @@ -124,22 +124,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 @@ -150,11 +150,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) } /** @@ -187,7 +187,7 @@ class UserApi( * Get user by user name * * - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. * @return User */ def getUserByName(username: String): Option[User] = { @@ -202,7 +202,7 @@ class UserApi( * Get user by user name asynchronously * * - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. * @return Future(User) */ def getUserByNameAsync(username: String): Future[User] = { @@ -266,11 +266,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 @@ -282,18 +282,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")) @@ -301,15 +301,15 @@ 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 => process(reader.read(resp)) } } - 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")) @@ -317,15 +317,15 @@ 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 => process(reader.read(resp)) } } - 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")) @@ -333,9 +333,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 => process(reader.read(resp)) } @@ -415,7 +415,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)) @@ -426,9 +426,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 => process(reader.read(resp)) }