Update Scala petstore with OAS2, OAS3 (#162)

* update pestore with oas2

* update scala petstore oas3 (no diff)
This commit is contained in:
William Cheng 2018-04-22 22:00:49 +08:00 committed by GitHub
parent c32ef12c8e
commit a7da9039a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 98 additions and 68 deletions

31
bin/openapi3/scala-petstore.sh Executable file
View File

@ -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

View File

@ -1 +1 @@
2.4.0-SNAPSHOT 3.0.0-SNAPSHOT

View File

@ -124,8 +124,7 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version> <version>3.6.1</version>
<configuration> <configuration>
<source> <source>1.7</source>
1.7</source>
<target>1.7</target> <target>1.7</target>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -85,11 +85,11 @@ class PetApi(
* Add a new pet to the store * 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 * @return void
*/ */
def addPet(body: Pet) = { def addPet(pet: Pet) = {
val await = Try(Await.result(addPetAsync(body), Duration.Inf)) val await = Try(Await.result(addPetAsync(pet), Duration.Inf))
await match { await match {
case Success(i) => Some(await.get) case Success(i) => Some(await.get)
case Failure(t) => None case Failure(t) => None
@ -100,11 +100,11 @@ class PetApi(
* Add a new pet to the store asynchronously * 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) * @return Future(void)
*/ */
def addPetAsync(body: Pet) = { def addPetAsync(pet: Pet) = {
helper.addPet(body) helper.addPet(pet)
} }
/** /**
@ -217,11 +217,11 @@ class PetApi(
* Update an existing pet * 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 * @return void
*/ */
def updatePet(body: Pet) = { def updatePet(pet: Pet) = {
val await = Try(Await.result(updatePetAsync(body), Duration.Inf)) val await = Try(Await.result(updatePetAsync(pet), Duration.Inf))
await match { await match {
case Success(i) => Some(await.get) case Success(i) => Some(await.get)
case Failure(t) => None case Failure(t) => None
@ -232,11 +232,11 @@ class PetApi(
* Update an existing pet asynchronously * 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) * @return Future(void)
*/ */
def updatePetAsync(body: Pet) = { def updatePetAsync(pet: Pet) = {
helper.updatePet(body) helper.updatePet(pet)
} }
/** /**
@ -303,7 +303,7 @@ class PetApi(
class PetApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) { 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 // create path and map variables
val path = (addFmt("/pet")) val path = (addFmt("/pet"))
@ -311,9 +311,9 @@ class PetApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = 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 => resFuture flatMap { resp =>
process(reader.read(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 // create path and map variables
val path = (addFmt("/pet")) val path = (addFmt("/pet"))
@ -399,9 +399,9 @@ class PetApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = 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 => resFuture flatMap { resp =>
process(reader.read(resp)) process(reader.read(resp))
} }

View File

@ -159,11 +159,11 @@ class StoreApi(
* Place an order for a pet * Place an order for a pet
* *
* *
* @param body order placed for purchasing the pet * @param order order placed for purchasing the pet
* @return Order * @return Order
*/ */
def placeOrder(body: Order): Option[Order] = { def placeOrder(order: Order): Option[Order] = {
val await = Try(Await.result(placeOrderAsync(body), Duration.Inf)) val await = Try(Await.result(placeOrderAsync(order), Duration.Inf))
await match { await match {
case Success(i) => Some(await.get) case Success(i) => Some(await.get)
case Failure(t) => None case Failure(t) => None
@ -174,11 +174,11 @@ class StoreApi(
* Place an order for a pet asynchronously * 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) * @return Future(Order)
*/ */
def placeOrderAsync(body: Order): Future[Order] = { def placeOrderAsync(order: Order): Future[Order] = {
helper.placeOrder(body) 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 // create path and map variables
val path = (addFmt("/store/order")) val path = (addFmt("/store/order"))
@ -242,9 +242,9 @@ class StoreApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extend
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = 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 => resFuture flatMap { resp =>
process(reader.read(resp)) process(reader.read(resp))
} }

View File

@ -83,11 +83,11 @@ class UserApi(
* Create user * Create user
* This can only be done by the logged in user. * This can only be done by the logged in user.
* *
* @param body Created user object * @param user Created user object
* @return void * @return void
*/ */
def createUser(body: User) = { def createUser(user: User) = {
val await = Try(Await.result(createUserAsync(body), Duration.Inf)) val await = Try(Await.result(createUserAsync(user), Duration.Inf))
await match { await match {
case Success(i) => Some(await.get) case Success(i) => Some(await.get)
case Failure(t) => None case Failure(t) => None
@ -98,22 +98,22 @@ class UserApi(
* Create user asynchronously * Create user asynchronously
* This can only be done by the logged in user. * This can only be done by the logged in user.
* *
* @param body Created user object * @param user Created user object
* @return Future(void) * @return Future(void)
*/ */
def createUserAsync(body: User) = { def createUserAsync(user: User) = {
helper.createUser(body) helper.createUser(user)
} }
/** /**
* Creates list of users with given input array * Creates list of users with given input array
* *
* *
* @param body List of user object * @param user List of user object
* @return void * @return void
*/ */
def createUsersWithArrayInput(body: List[User]) = { def createUsersWithArrayInput(user: List[User]) = {
val await = Try(Await.result(createUsersWithArrayInputAsync(body), Duration.Inf)) val await = Try(Await.result(createUsersWithArrayInputAsync(user), Duration.Inf))
await match { await match {
case Success(i) => Some(await.get) case Success(i) => Some(await.get)
case Failure(t) => None case Failure(t) => None
@ -124,22 +124,22 @@ class UserApi(
* Creates list of users with given input array asynchronously * Creates list of users with given input array asynchronously
* *
* *
* @param body List of user object * @param user List of user object
* @return Future(void) * @return Future(void)
*/ */
def createUsersWithArrayInputAsync(body: List[User]) = { def createUsersWithArrayInputAsync(user: List[User]) = {
helper.createUsersWithArrayInput(body) helper.createUsersWithArrayInput(user)
} }
/** /**
* Creates list of users with given input array * Creates list of users with given input array
* *
* *
* @param body List of user object * @param user List of user object
* @return void * @return void
*/ */
def createUsersWithListInput(body: List[User]) = { def createUsersWithListInput(user: List[User]) = {
val await = Try(Await.result(createUsersWithListInputAsync(body), Duration.Inf)) val await = Try(Await.result(createUsersWithListInputAsync(user), Duration.Inf))
await match { await match {
case Success(i) => Some(await.get) case Success(i) => Some(await.get)
case Failure(t) => None case Failure(t) => None
@ -150,11 +150,11 @@ class UserApi(
* Creates list of users with given input array asynchronously * Creates list of users with given input array asynchronously
* *
* *
* @param body List of user object * @param user List of user object
* @return Future(void) * @return Future(void)
*/ */
def createUsersWithListInputAsync(body: List[User]) = { def createUsersWithListInputAsync(user: List[User]) = {
helper.createUsersWithListInput(body) helper.createUsersWithListInput(user)
} }
/** /**
@ -187,7 +187,7 @@ class UserApi(
* Get user by user name * 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 * @return User
*/ */
def getUserByName(username: String): Option[User] = { def getUserByName(username: String): Option[User] = {
@ -202,7 +202,7 @@ class UserApi(
* Get user by user name asynchronously * 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) * @return Future(User)
*/ */
def getUserByNameAsync(username: String): Future[User] = { def getUserByNameAsync(username: String): Future[User] = {
@ -266,11 +266,11 @@ class UserApi(
* This can only be done by the logged in user. * This can only be done by the logged in user.
* *
* @param username name that need to be deleted * @param username name that need to be deleted
* @param body Updated user object * @param user Updated user object
* @return void * @return void
*/ */
def updateUser(username: String, body: User) = { def updateUser(username: String, user: User) = {
val await = Try(Await.result(updateUserAsync(username, body), Duration.Inf)) val await = Try(Await.result(updateUserAsync(username, user), Duration.Inf))
await match { await match {
case Success(i) => Some(await.get) case Success(i) => Some(await.get)
case Failure(t) => None case Failure(t) => None
@ -282,18 +282,18 @@ class UserApi(
* This can only be done by the logged in user. * This can only be done by the logged in user.
* *
* @param username name that need to be deleted * @param username name that need to be deleted
* @param body Updated user object * @param user Updated user object
* @return Future(void) * @return Future(void)
*/ */
def updateUserAsync(username: String, body: User) = { def updateUserAsync(username: String, user: User) = {
helper.updateUser(username, body) helper.updateUser(username, user)
} }
} }
class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) { 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 // create path and map variables
val path = (addFmt("/user")) val path = (addFmt("/user"))
@ -301,15 +301,15 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = 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 => resFuture flatMap { resp =>
process(reader.read(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 // create path and map variables
val path = (addFmt("/user/createWithArray")) val path = (addFmt("/user/createWithArray"))
@ -317,15 +317,15 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = 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 => resFuture flatMap { resp =>
process(reader.read(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 // create path and map variables
val path = (addFmt("/user/createWithList")) val path = (addFmt("/user/createWithList"))
@ -333,9 +333,9 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = 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 => resFuture flatMap { resp =>
process(reader.read(resp)) process(reader.read(resp))
} }
@ -415,7 +415,7 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
} }
def updateUser(username: String, 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 // create path and map variables
val path = (addFmt("/user/{username}") val path = (addFmt("/user/{username}")
replaceAll("\\{" + "username" + "\\}", username.toString)) 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 (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 => resFuture flatMap { resp =>
process(reader.read(resp)) process(reader.read(resp))
} }