Fix finch package name. (#4755)

This commit is contained in:
clasnake
2017-02-13 22:33:55 +08:00
committed by wing328
parent 56251bf214
commit ee23f8e50c
24 changed files with 709 additions and 912 deletions

View File

@@ -15,12 +15,12 @@ import java.util.List;
import java.util.Map;
public class FinchServerCodegen extends DefaultCodegen implements CodegenConfig {
protected String invokerPackage = "io.swagger.petstore.client";
protected String invokerPackage = "io.swagger.client";
protected String groupId = "io.swagger";
protected String artifactId = "finch-server";
protected String artifactVersion = "1.0.0";
protected String sourceFolder = "src/main/scala";
protected String packageName = "io.swagger.petstore";
protected String packageName = "io.swagger";
public FinchServerCodegen() {
super();
@@ -156,7 +156,7 @@ public class FinchServerCodegen extends DefaultCodegen implements CodegenConfig
importMapping.put("LocalTime", "java.time.LocalTime");
cliOptions.clear();
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Finch package name (e.g. io.swagger.petstore).")
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Finch package name (e.g. io.swagger).")
.defaultValue(this.packageName));
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));

View File

@@ -1,201 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -1,133 +1,133 @@
package io.swagger.petstore
package io.swagger
// TODO: properly handle custom imports
import java.io._
import java.util.Date
import io.swagger.petstore.models._
import io.swagger.models._
trait DataAccessor {
// TODO: apiInfo -> apis -> operations = ???
// NOTE: ??? throws a not implemented exception
// TODO: apiInfo -> apis -> operations = ???
// NOTE: ??? throws a not implemented exception
/**
*
* @return A Unit
*/
def Pet_addPet(body: Pet): Unit = ???
/**
*
* @return A Unit
*/
def Pet_addPet(body: Pet): Unit = ???
/**
*
* @return A Unit
*/
def Pet_deletePet(petId: Long, apiKey: String): Unit = ???
/**
*
* @return A Unit
*/
def Pet_deletePet(petId: Long, apiKey: String): Unit = ???
/**
*
* @return A Seq[Pet]
*/
def Pet_findPetsByStatus(status: Seq[String]): Seq[Pet] = ???
/**
*
* @return A Seq[Pet]
*/
def Pet_findPetsByStatus(status: Seq[String]): Seq[Pet] = ???
/**
*
* @return A Seq[Pet]
*/
def Pet_findPetsByTags(tags: Seq[String]): Seq[Pet] = ???
/**
*
* @return A Seq[Pet]
*/
def Pet_findPetsByTags(tags: Seq[String]): Seq[Pet] = ???
/**
*
* @return A Pet
*/
def Pet_getPetById(petId: Long): Pet = ???
/**
*
* @return A Pet
*/
def Pet_getPetById(petId: Long): Pet = ???
/**
*
* @return A Unit
*/
def Pet_updatePet(body: Pet): Unit = ???
/**
*
* @return A Unit
*/
def Pet_updatePet(body: Pet): Unit = ???
/**
*
* @return A Unit
*/
def Pet_updatePetWithForm(petId: Long, name: String, status: String): Unit = ???
/**
*
* @return A Unit
*/
def Pet_updatePetWithForm(petId: Long, name: String, status: String): Unit = ???
/**
*
* @return A ApiResponse
*/
def Pet_uploadFile(petId: Long, additionalMetadata: String, file: File): ApiResponse = ???
/**
*
* @return A ApiResponse
*/
def Pet_uploadFile(petId: Long, additionalMetadata: String, file: File): ApiResponse = ???
/**
*
* @return A Unit
*/
def Store_deleteOrder(orderId: String): Unit = ???
/**
*
* @return A Unit
*/
def Store_deleteOrder(orderId: String): Unit = ???
/**
*
* @return A Map[String, Int]
*/
def Store_getInventory(): Map[String, Int] = ???
/**
*
* @return A Map[String, Int]
*/
def Store_getInventory(): Map[String, Int] = ???
/**
*
* @return A Order
*/
def Store_getOrderById(orderId: Long): Order = ???
/**
*
* @return A Order
*/
def Store_getOrderById(orderId: Long): Order = ???
/**
*
* @return A Order
*/
def Store_placeOrder(body: Order): Order = ???
/**
*
* @return A Order
*/
def Store_placeOrder(body: Order): Order = ???
/**
*
* @return A Unit
*/
def User_createUser(body: User): Unit = ???
/**
*
* @return A Unit
*/
def User_createUser(body: User): Unit = ???
/**
*
* @return A Unit
*/
def User_createUsersWithArrayInput(body: Seq[User]): Unit = ???
/**
*
* @return A Unit
*/
def User_createUsersWithArrayInput(body: Seq[User]): Unit = ???
/**
*
* @return A Unit
*/
def User_createUsersWithListInput(body: Seq[User]): Unit = ???
/**
*
* @return A Unit
*/
def User_createUsersWithListInput(body: Seq[User]): Unit = ???
/**
*
* @return A Unit
*/
def User_deleteUser(username: String): Unit = ???
/**
*
* @return A Unit
*/
def User_deleteUser(username: String): Unit = ???
/**
*
* @return A User
*/
def User_getUserByName(username: String): User = ???
/**
*
* @return A User
*/
def User_getUserByName(username: String): User = ???
/**
*
* @return A String
*/
def User_loginUser(username: String, password: String): String = ???
/**
*
* @return A String
*/
def User_loginUser(username: String, password: String): String = ???
/**
*
* @return A Unit
*/
def User_logoutUser(): Unit = ???
/**
*
* @return A Unit
*/
def User_logoutUser(): Unit = ???
/**
*
* @return A Unit
*/
def User_updateUser(username: String, body: User): Unit = ???
/**
*
* @return A Unit
*/
def User_updateUser(username: String, body: User): Unit = ???
}

View File

@@ -1,22 +1,23 @@
package io.swagger.petstore
package io.swagger
import io.finch._
import io.finch.circe._
import io.circe.{ Decoder, ObjectEncoder }
import io.circe.{Decoder, ObjectEncoder}
import io.circe.generic.auto._
import io.circe.generic.semiauto
import io.circe.generic.semiauto._
import io.circe.java8.time._
import com.twitter.finagle.Http
import com.twitter.finagle.util.LoadService
import com.twitter.util.{ Await, Future }
import com.twitter.util.{Await, Future}
class Server {
// Loads implementation defined in resources/META-INF/services/io.swagger.petstore.DataAccessor
// Loads implementation defined in resources/META-INF/services/io.swagger.DataAccessor
val db = LoadService[DataAccessor]() match {
case accessor :: _ => accessor
case _ => new DataAccessor {}
case _ => new DataAccessor { }
}
val service = endpoint.makeService(db)

View File

@@ -1,15 +1,15 @@
package io.swagger.petstore
package io.swagger
import com.twitter.finagle.Service
import com.twitter.finagle.http.{ Request, Response }
import com.twitter.finagle.http.{Request, Response}
import com.twitter.finagle.http.exp.Multipart.FileUpload
import com.twitter.util.Future
import io.finch._, items._
import io.circe.{ Encoder, Json }
import io.circe.{Encoder, Json}
import io.finch.circe._
import io.circe.generic.semiauto._
import io.swagger.petstore.apis._
import io.swagger.apis._
/**
* Provides the paths and endpoints for all the API's public service methods.
@@ -17,32 +17,32 @@ import io.swagger.petstore.apis._
object endpoint {
def errorToJson(e: Exception): Json = e match {
case Error.NotPresent(_) =>
Json.obj("error" -> Json.fromString("something_not_present"))
case Error.NotParsed(_, _, _) =>
Json.obj("error" -> Json.fromString("something_not_parsed"))
case Error.NotValid(_, _) =>
Json.obj("error" -> Json.fromString("something_not_valid"))
case error: PetstoreError =>
Json.obj("error" -> Json.fromString(error.message))
case Error.NotPresent(_) =>
Json.obj("error" -> Json.fromString("something_not_present"))
case Error.NotParsed(_, _, _) =>
Json.obj("error" -> Json.fromString("something_not_parsed"))
case Error.NotValid(_, _) =>
Json.obj("error" -> Json.fromString("something_not_valid"))
case error: PetstoreError =>
Json.obj("error" -> Json.fromString(error.message))
}
implicit val ee: Encoder[Exception] = Encoder.instance {
case e: Error => errorToJson(e)
case Errors(nel) => Json.arr(nel.toList.map(errorToJson): _*)
case e: Error => errorToJson(e)
case Errors(nel) => Json.arr(nel.toList.map(errorToJson): _*)
}
/**
* Compiles together all the endpoints relating to public service methods.
*
* @return A service that contains all provided endpoints of the API.
*/
* Compiles together all the endpoints relating to public service methods.
*
* @return A service that contains all provided endpoints of the API.
*/
def makeService(da: DataAccessor): Service[Request, Response] = (
PetApi.endpoints(da) :+:
StoreApi.endpoints(da) :+:
UserApi.endpoints(da)
PetApi.endpoints(da) :+:
StoreApi.endpoints(da) :+:
UserApi.endpoints(da)
).handle({
case e: PetstoreError => NotFound(e)
}).toService
}).toService
}

View File

@@ -1,4 +1,4 @@
package io.swagger.petstore
package io.swagger
/**
* The parent error from which most PetstoreAPI errors extend. Thrown whenever something in the api goes wrong.

View File

@@ -0,0 +1,149 @@
package io.swagger.apis
import java.io._
import java.util.Date
import io.swagger._
import io.swagger.models._
import io.swagger.models.ApiResponse
import java.io.File
import io.swagger.models.Pet
import io.finch.circe._
import io.circe.generic.semiauto._
import com.twitter.concurrent.AsyncStream
import com.twitter.finagle.Service
import com.twitter.finagle.Http
import com.twitter.finagle.http.{Request, Response}
import com.twitter.finagle.http.exp.Multipart.{FileUpload, InMemoryFileUpload, OnDiskFileUpload}
import com.twitter.util.Future
import com.twitter.io.Buf
import io.finch._, items._
import java.io.File
object PetApi {
/**
* Compiles all service endpoints.
* @return Bundled compilation of all service endpoints.
*/
def endpoints(da: DataAccessor) =
addPet(da) :+:
deletePet(da) :+:
findPetsByStatus(da) :+:
findPetsByTags(da) :+:
getPetById(da) :+:
updatePet(da) :+:
updatePetWithForm(da) :+:
uploadFile(da)
/**
*
* @return And endpoint representing a Unit
*/
private def addPet(da: DataAccessor): Endpoint[Unit] =
post("pet" :: jsonBody[Pet]) { (body: Pet) =>
da.Pet_addPet(body)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Unit
*/
private def deletePet(da: DataAccessor): Endpoint[Unit] =
delete("pet" :: long :: string) { (petId: Long, apiKey: String) =>
da.Pet_deletePet(petId, apiKey)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Seq[Pet]
*/
private def findPetsByStatus(da: DataAccessor): Endpoint[Seq[Pet]] =
get("pet" :: "findByStatus" :: params("status")) { (status: Seq[String]) =>
Ok(da.Pet_findPetsByStatus(status))
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Seq[Pet]
*/
private def findPetsByTags(da: DataAccessor): Endpoint[Seq[Pet]] =
get("pet" :: "findByTags" :: params("tags")) { (tags: Seq[String]) =>
Ok(da.Pet_findPetsByTags(tags))
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Pet
*/
private def getPetById(da: DataAccessor): Endpoint[Pet] =
get("pet" :: long ) { (petId: Long) =>
Ok(da.Pet_getPetById(petId))
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Unit
*/
private def updatePet(da: DataAccessor): Endpoint[Unit] =
put("pet" :: jsonBody[Pet]) { (body: Pet) =>
da.Pet_updatePet(body)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Unit
*/
private def updatePetWithForm(da: DataAccessor): Endpoint[Unit] =
post("pet" :: long :: string :: string) { (petId: Long, name: String, status: String) =>
da.Pet_updatePetWithForm(petId, name, status)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a ApiResponse
*/
private def uploadFile(da: DataAccessor): Endpoint[ApiResponse] =
post("pet" :: long :: "uploadImage" :: string :: fileUpload("file")) { (petId: Long, additionalMetadata: String, file: FileUpload) =>
Ok(da.Pet_uploadFile(petId, additionalMetadata, file))
} handle {
case e: Exception => BadRequest(e)
}
implicit private def fileUploadToFile(fileUpload: FileUpload) : File = {
fileUpload match {
case upload: InMemoryFileUpload =>
bytesToFile(Buf.ByteArray.Owned.extract(upload.content))
case upload: OnDiskFileUpload =>
upload.content
case _ => null
}
}
private def bytesToFile(input: Array[Byte]): java.io.File = {
val file = File.createTempFile("tmpPetApi", null)
val output = new FileOutputStream(file)
output.write(input)
file
}
// This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere.
implicit def seqList[A](input: Seq[A]): List[A] = input.toList
}

View File

@@ -0,0 +1,96 @@
package io.swagger.apis
import java.io._
import java.util.Date
import io.swagger._
import io.swagger.models._
import io.swagger.models.Order
import io.finch.circe._
import io.circe.generic.semiauto._
import com.twitter.concurrent.AsyncStream
import com.twitter.finagle.Service
import com.twitter.finagle.Http
import com.twitter.finagle.http.{Request, Response}
import com.twitter.finagle.http.exp.Multipart.{FileUpload, InMemoryFileUpload, OnDiskFileUpload}
import com.twitter.util.Future
import com.twitter.io.Buf
import io.finch._, items._
import java.io.File
object StoreApi {
/**
* Compiles all service endpoints.
* @return Bundled compilation of all service endpoints.
*/
def endpoints(da: DataAccessor) =
deleteOrder(da) :+:
getInventory(da) :+:
getOrderById(da) :+:
placeOrder(da)
/**
*
* @return And endpoint representing a Unit
*/
private def deleteOrder(da: DataAccessor): Endpoint[Unit] =
delete("store" :: "order" :: string ) { (orderId: String) =>
da.Store_deleteOrder(orderId)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Map[String, Int]
*/
private def getInventory(da: DataAccessor): Endpoint[Map[String, Int]] =
get("store" :: "inventory" ) {
Ok(da.Store_getInventory())
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Order
*/
private def getOrderById(da: DataAccessor): Endpoint[Order] =
get("store" :: "order" :: long ) { (orderId: Long) =>
Ok(da.Store_getOrderById(orderId))
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Order
*/
private def placeOrder(da: DataAccessor): Endpoint[Order] =
post("store" :: "order" :: jsonBody[Order]) { (body: Order) =>
Ok(da.Store_placeOrder(body))
} handle {
case e: Exception => BadRequest(e)
}
implicit private def fileUploadToFile(fileUpload: FileUpload) : File = {
fileUpload match {
case upload: InMemoryFileUpload =>
bytesToFile(Buf.ByteArray.Owned.extract(upload.content))
case upload: OnDiskFileUpload =>
upload.content
case _ => null
}
}
private def bytesToFile(input: Array[Byte]): java.io.File = {
val file = File.createTempFile("tmpStoreApi", null)
val output = new FileOutputStream(file)
output.write(input)
file
}
// This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere.
implicit def seqList[A](input: Seq[A]): List[A] = input.toList
}

View File

@@ -0,0 +1,150 @@
package io.swagger.apis
import java.io._
import java.util.Date
import io.swagger._
import io.swagger.models._
import scala.collection.immutable.Seq
import io.swagger.models.User
import io.finch.circe._
import io.circe.generic.semiauto._
import com.twitter.concurrent.AsyncStream
import com.twitter.finagle.Service
import com.twitter.finagle.Http
import com.twitter.finagle.http.{Request, Response}
import com.twitter.finagle.http.exp.Multipart.{FileUpload, InMemoryFileUpload, OnDiskFileUpload}
import com.twitter.util.Future
import com.twitter.io.Buf
import io.finch._, items._
import java.io.File
object UserApi {
/**
* Compiles all service endpoints.
* @return Bundled compilation of all service endpoints.
*/
def endpoints(da: DataAccessor) =
createUser(da) :+:
createUsersWithArrayInput(da) :+:
createUsersWithListInput(da) :+:
deleteUser(da) :+:
getUserByName(da) :+:
loginUser(da) :+:
logoutUser(da) :+:
updateUser(da)
/**
*
* @return And endpoint representing a Unit
*/
private def createUser(da: DataAccessor): Endpoint[Unit] =
post("user" :: jsonBody[User]) { (body: User) =>
da.User_createUser(body)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Unit
*/
private def createUsersWithArrayInput(da: DataAccessor): Endpoint[Unit] =
post("user" :: "createWithArray" :: jsonBody[Seq[User]]) { (body: Seq[User]) =>
da.User_createUsersWithArrayInput(body)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Unit
*/
private def createUsersWithListInput(da: DataAccessor): Endpoint[Unit] =
post("user" :: "createWithList" :: jsonBody[Seq[User]]) { (body: Seq[User]) =>
da.User_createUsersWithListInput(body)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Unit
*/
private def deleteUser(da: DataAccessor): Endpoint[Unit] =
delete("user" :: string ) { (username: String) =>
da.User_deleteUser(username)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a User
*/
private def getUserByName(da: DataAccessor): Endpoint[User] =
get("user" :: string ) { (username: String) =>
Ok(da.User_getUserByName(username))
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a String
*/
private def loginUser(da: DataAccessor): Endpoint[String] =
get("user" :: "login" :: string :: string) { (username: String, password: String) =>
Ok(da.User_loginUser(username, password))
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Unit
*/
private def logoutUser(da: DataAccessor): Endpoint[Unit] =
get("user" :: "logout" ) {
da.User_logoutUser()
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And 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)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
implicit private def fileUploadToFile(fileUpload: FileUpload) : File = {
fileUpload match {
case upload: InMemoryFileUpload =>
bytesToFile(Buf.ByteArray.Owned.extract(upload.content))
case upload: OnDiskFileUpload =>
upload.content
case _ => null
}
}
private def bytesToFile(input: Array[Byte]): java.io.File = {
val file = File.createTempFile("tmpUserApi", null)
val output = new FileOutputStream(file)
output.write(input)
file
}
// This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere.
implicit def seqList[A](input: Seq[A]): List[A] = input.toList
}

View File

@@ -0,0 +1,26 @@
package io.swagger.models
import io.circe._
import io.finch.circe._
import io.circe.generic.semiauto._
import io.circe.java8.time._
import io.swagger._
/**
* Describes the result of uploading an image resource
* @param code
* @param _type
* @param message
*/
case class ApiResponse(code: Option[Int],
_type: Option[String],
message: Option[String]
)
object ApiResponse {
/**
* Creates the codec for converting ApiResponse from and to JSON.
*/
implicit val decoder: Decoder[ApiResponse] = deriveDecoder
implicit val encoder: ObjectEncoder[ApiResponse] = deriveEncoder
}

View File

@@ -0,0 +1,24 @@
package io.swagger.models
import io.circe._
import io.finch.circe._
import io.circe.generic.semiauto._
import io.circe.java8.time._
import io.swagger._
/**
* A category for a pet
* @param id
* @param name
*/
case class Category(id: Option[Long],
name: Option[String]
)
object Category {
/**
* Creates the codec for converting Category from and to JSON.
*/
implicit val decoder: Decoder[Category] = deriveDecoder
implicit val encoder: ObjectEncoder[Category] = deriveEncoder
}

View File

@@ -0,0 +1,33 @@
package io.swagger.models
import io.circe._
import io.finch.circe._
import io.circe.generic.semiauto._
import io.circe.java8.time._
import io.swagger._
import java.time.LocalDateTime
/**
* An order for a pets from the pet store
* @param id
* @param petId
* @param quantity
* @param shipDate
* @param status Order Status
* @param complete
*/
case class Order(id: Option[Long],
petId: Option[Long],
quantity: Option[Int],
shipDate: Option[LocalDateTime],
status: Option[String],
complete: Option[Boolean]
)
object Order {
/**
* Creates the codec for converting Order from and to JSON.
*/
implicit val decoder: Decoder[Order] = deriveDecoder
implicit val encoder: ObjectEncoder[Order] = deriveEncoder
}

View File

@@ -0,0 +1,35 @@
package io.swagger.models
import io.circe._
import io.finch.circe._
import io.circe.generic.semiauto._
import io.circe.java8.time._
import io.swagger._
import io.swagger.models.Category
import io.swagger.models.Tag
import scala.collection.immutable.Seq
/**
* A pet for sale in the pet store
* @param id
* @param category
* @param name
* @param photoUrls
* @param tags
* @param status pet status in the store
*/
case class Pet(id: Option[Long],
category: Option[Category],
name: String,
photoUrls: Seq[String],
tags: Option[Seq[Tag]],
status: Option[String]
)
object Pet {
/**
* Creates the codec for converting Pet from and to JSON.
*/
implicit val decoder: Decoder[Pet] = deriveDecoder
implicit val encoder: ObjectEncoder[Pet] = deriveEncoder
}

View File

@@ -0,0 +1,24 @@
package io.swagger.models
import io.circe._
import io.finch.circe._
import io.circe.generic.semiauto._
import io.circe.java8.time._
import io.swagger._
/**
* A tag for a pet
* @param id
* @param name
*/
case class Tag(id: Option[Long],
name: Option[String]
)
object Tag {
/**
* Creates the codec for converting Tag from and to JSON.
*/
implicit val decoder: Decoder[Tag] = deriveDecoder
implicit val encoder: ObjectEncoder[Tag] = deriveEncoder
}

View File

@@ -0,0 +1,36 @@
package io.swagger.models
import io.circe._
import io.finch.circe._
import io.circe.generic.semiauto._
import io.circe.java8.time._
import io.swagger._
/**
* A User who is purchasing from the pet store
* @param id
* @param username
* @param firstName
* @param lastName
* @param email
* @param password
* @param phone
* @param userStatus User Status
*/
case class User(id: Option[Long],
username: Option[String],
firstName: Option[String],
lastName: Option[String],
email: Option[String],
password: Option[String],
phone: Option[String],
userStatus: Option[Int]
)
object User {
/**
* Creates the codec for converting User from and to JSON.
*/
implicit val decoder: Decoder[User] = deriveDecoder
implicit val encoder: ObjectEncoder[User] = deriveEncoder
}

View File

@@ -1,148 +0,0 @@
package io.swagger.petstore.apis
import java.io._
import java.util.Date
import io.swagger.petstore._
import io.swagger.petstore.models._
import io.swagger.petstore.models.Pet
import java.io.File
import io.swagger.petstore.models.ApiResponse
import io.finch.circe._
import io.circe.generic.semiauto._
import com.twitter.concurrent.AsyncStream
import com.twitter.finagle.Service
import com.twitter.finagle.Http
import com.twitter.finagle.http.{ Request, Response }
import com.twitter.finagle.http.exp.Multipart.{ FileUpload, InMemoryFileUpload, OnDiskFileUpload }
import com.twitter.util.Future
import com.twitter.io.Buf
import io.finch._, items._
import java.io.File
object PetApi {
/**
* Compiles all service endpoints.
* @return Bundled compilation of all service endpoints.
*/
def endpoints(da: DataAccessor) =
addPet(da) :+:
deletePet(da) :+:
findPetsByStatus(da) :+:
findPetsByTags(da) :+:
getPetById(da) :+:
updatePet(da) :+:
updatePetWithForm(da) :+:
uploadFile(da)
/**
*
* @return And endpoint representing a Unit
*/
private def addPet(da: DataAccessor): Endpoint[Unit] =
post("pet" :: jsonBody[Pet]) { (body: Pet) =>
da.Pet_addPet(body)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Unit
*/
private def deletePet(da: DataAccessor): Endpoint[Unit] =
delete("pet" :: long :: string) { (petId: Long, apiKey: String) =>
da.Pet_deletePet(petId, apiKey)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Seq[Pet]
*/
private def findPetsByStatus(da: DataAccessor): Endpoint[Seq[Pet]] =
get("pet" :: "findByStatus" :: params("status")) { (status: Seq[String]) =>
Ok(da.Pet_findPetsByStatus(status))
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Seq[Pet]
*/
private def findPetsByTags(da: DataAccessor): Endpoint[Seq[Pet]] =
get("pet" :: "findByTags" :: params("tags")) { (tags: Seq[String]) =>
Ok(da.Pet_findPetsByTags(tags))
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Pet
*/
private def getPetById(da: DataAccessor): Endpoint[Pet] =
get("pet" :: long) { (petId: Long) =>
Ok(da.Pet_getPetById(petId))
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Unit
*/
private def updatePet(da: DataAccessor): Endpoint[Unit] =
put("pet" :: jsonBody[Pet]) { (body: Pet) =>
da.Pet_updatePet(body)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Unit
*/
private def updatePetWithForm(da: DataAccessor): Endpoint[Unit] =
post("pet" :: long :: string :: string) { (petId: Long, name: String, status: String) =>
da.Pet_updatePetWithForm(petId, name, status)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a ApiResponse
*/
private def uploadFile(da: DataAccessor): Endpoint[ApiResponse] =
post("pet" :: long :: "uploadImage" :: string :: fileUpload("file")) { (petId: Long, additionalMetadata: String, file: FileUpload) =>
Ok(da.Pet_uploadFile(petId, additionalMetadata, file))
} handle {
case e: Exception => BadRequest(e)
}
implicit private def fileUploadToFile(fileUpload: FileUpload): File = {
fileUpload match {
case upload: InMemoryFileUpload =>
bytesToFile(Buf.ByteArray.Owned.extract(upload.content))
case upload: OnDiskFileUpload =>
upload.content
case _ => null
}
}
private def bytesToFile(input: Array[Byte]): java.io.File = {
val file = File.createTempFile("tmpPetApi", null)
val output = new FileOutputStream(file)
output.write(input)
file
}
// This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere.
implicit def seqList[A](input: Seq[A]): List[A] = input.toList
}

View File

@@ -1,95 +0,0 @@
package io.swagger.petstore.apis
import java.io._
import java.util.Date
import io.swagger.petstore._
import io.swagger.petstore.models._
import io.swagger.petstore.models.Order
import io.finch.circe._
import io.circe.generic.semiauto._
import com.twitter.concurrent.AsyncStream
import com.twitter.finagle.Service
import com.twitter.finagle.Http
import com.twitter.finagle.http.{ Request, Response }
import com.twitter.finagle.http.exp.Multipart.{ FileUpload, InMemoryFileUpload, OnDiskFileUpload }
import com.twitter.util.Future
import com.twitter.io.Buf
import io.finch._, items._
import java.io.File
object StoreApi {
/**
* Compiles all service endpoints.
* @return Bundled compilation of all service endpoints.
*/
def endpoints(da: DataAccessor) =
deleteOrder(da) :+:
getInventory(da) :+:
getOrderById(da) :+:
placeOrder(da)
/**
*
* @return And endpoint representing a Unit
*/
private def deleteOrder(da: DataAccessor): Endpoint[Unit] =
delete("store" :: "order" :: string) { (orderId: String) =>
da.Store_deleteOrder(orderId)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Map[String, Int]
*/
private def getInventory(da: DataAccessor): Endpoint[Map[String, Int]] =
get("store" :: "inventory") {
Ok(da.Store_getInventory())
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Order
*/
private def getOrderById(da: DataAccessor): Endpoint[Order] =
get("store" :: "order" :: long) { (orderId: Long) =>
Ok(da.Store_getOrderById(orderId))
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Order
*/
private def placeOrder(da: DataAccessor): Endpoint[Order] =
post("store" :: "order" :: jsonBody[Order]) { (body: Order) =>
Ok(da.Store_placeOrder(body))
} handle {
case e: Exception => BadRequest(e)
}
implicit private def fileUploadToFile(fileUpload: FileUpload): File = {
fileUpload match {
case upload: InMemoryFileUpload =>
bytesToFile(Buf.ByteArray.Owned.extract(upload.content))
case upload: OnDiskFileUpload =>
upload.content
case _ => null
}
}
private def bytesToFile(input: Array[Byte]): java.io.File = {
val file = File.createTempFile("tmpStoreApi", null)
val output = new FileOutputStream(file)
output.write(input)
file
}
// This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere.
implicit def seqList[A](input: Seq[A]): List[A] = input.toList
}

View File

@@ -1,149 +0,0 @@
package io.swagger.petstore.apis
import java.io._
import java.util.Date
import io.swagger.petstore._
import io.swagger.petstore.models._
import io.swagger.petstore.models.User
import scala.collection.immutable.Seq
import io.finch.circe._
import io.circe.generic.semiauto._
import com.twitter.concurrent.AsyncStream
import com.twitter.finagle.Service
import com.twitter.finagle.Http
import com.twitter.finagle.http.{ Request, Response }
import com.twitter.finagle.http.exp.Multipart.{ FileUpload, InMemoryFileUpload, OnDiskFileUpload }
import com.twitter.util.Future
import com.twitter.io.Buf
import io.finch._, items._
import java.io.File
object UserApi {
/**
* Compiles all service endpoints.
* @return Bundled compilation of all service endpoints.
*/
def endpoints(da: DataAccessor) =
createUser(da) :+:
createUsersWithArrayInput(da) :+:
createUsersWithListInput(da) :+:
deleteUser(da) :+:
getUserByName(da) :+:
loginUser(da) :+:
logoutUser(da) :+:
updateUser(da)
/**
*
* @return And endpoint representing a Unit
*/
private def createUser(da: DataAccessor): Endpoint[Unit] =
post("user" :: jsonBody[User]) { (body: User) =>
da.User_createUser(body)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Unit
*/
private def createUsersWithArrayInput(da: DataAccessor): Endpoint[Unit] =
post("user" :: "createWithArray" :: jsonBody[Seq[User]]) { (body: Seq[User]) =>
da.User_createUsersWithArrayInput(body)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Unit
*/
private def createUsersWithListInput(da: DataAccessor): Endpoint[Unit] =
post("user" :: "createWithList" :: jsonBody[Seq[User]]) { (body: Seq[User]) =>
da.User_createUsersWithListInput(body)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Unit
*/
private def deleteUser(da: DataAccessor): Endpoint[Unit] =
delete("user" :: string) { (username: String) =>
da.User_deleteUser(username)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a User
*/
private def getUserByName(da: DataAccessor): Endpoint[User] =
get("user" :: string) { (username: String) =>
Ok(da.User_getUserByName(username))
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a String
*/
private def loginUser(da: DataAccessor): Endpoint[String] =
get("user" :: "login" :: string :: string) { (username: String, password: String) =>
Ok(da.User_loginUser(username, password))
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And endpoint representing a Unit
*/
private def logoutUser(da: DataAccessor): Endpoint[Unit] =
get("user" :: "logout") {
da.User_logoutUser()
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
/**
*
* @return And 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)
NoContent[Unit]
} handle {
case e: Exception => BadRequest(e)
}
implicit private def fileUploadToFile(fileUpload: FileUpload): File = {
fileUpload match {
case upload: InMemoryFileUpload =>
bytesToFile(Buf.ByteArray.Owned.extract(upload.content))
case upload: OnDiskFileUpload =>
upload.content
case _ => null
}
}
private def bytesToFile(input: Array[Byte]): java.io.File = {
val file = File.createTempFile("tmpUserApi", null)
val output = new FileOutputStream(file)
output.write(input)
file
}
// This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere.
implicit def seqList[A](input: Seq[A]): List[A] = input.toList
}

View File

@@ -1,27 +0,0 @@
package io.swagger.petstore.models
import io.circe._
import io.finch.circe._
import io.circe.generic.semiauto._
import io.circe.java8.time._
import io.swagger.petstore._
/**
* Describes the result of uploading an image resource
* @param code
* @param _type
* @param message
*/
case class ApiResponse(
code: Option[Int],
_type: Option[String],
message: Option[String]
)
object ApiResponse {
/**
* Creates the codec for converting ApiResponse from and to JSON.
*/
implicit val decoder: Decoder[ApiResponse] = deriveDecoder
implicit val encoder: ObjectEncoder[ApiResponse] = deriveEncoder
}

View File

@@ -1,25 +0,0 @@
package io.swagger.petstore.models
import io.circe._
import io.finch.circe._
import io.circe.generic.semiauto._
import io.circe.java8.time._
import io.swagger.petstore._
/**
* A category for a pet
* @param id
* @param name
*/
case class Category(
id: Option[Long],
name: Option[String]
)
object Category {
/**
* Creates the codec for converting Category from and to JSON.
*/
implicit val decoder: Decoder[Category] = deriveDecoder
implicit val encoder: ObjectEncoder[Category] = deriveEncoder
}

View File

@@ -1,34 +0,0 @@
package io.swagger.petstore.models
import io.circe._
import io.finch.circe._
import io.circe.generic.semiauto._
import io.circe.java8.time._
import io.swagger.petstore._
import java.time.LocalDateTime
/**
* An order for a pets from the pet store
* @param id
* @param petId
* @param quantity
* @param shipDate
* @param status Order Status
* @param complete
*/
case class Order(
id: Option[Long],
petId: Option[Long],
quantity: Option[Int],
shipDate: Option[LocalDateTime],
status: Option[String],
complete: Option[Boolean]
)
object Order {
/**
* Creates the codec for converting Order from and to JSON.
*/
implicit val decoder: Decoder[Order] = deriveDecoder
implicit val encoder: ObjectEncoder[Order] = deriveEncoder
}

View File

@@ -1,36 +0,0 @@
package io.swagger.petstore.models
import io.circe._
import io.finch.circe._
import io.circe.generic.semiauto._
import io.circe.java8.time._
import io.swagger.petstore._
import io.swagger.petstore.models.Category
import io.swagger.petstore.models.Tag
import scala.collection.immutable.Seq
/**
* A pet for sale in the pet store
* @param id
* @param category
* @param name
* @param photoUrls
* @param tags
* @param status pet status in the store
*/
case class Pet(
id: Option[Long],
category: Option[Category],
name: String,
photoUrls: Seq[String],
tags: Option[Seq[Tag]],
status: Option[String]
)
object Pet {
/**
* Creates the codec for converting Pet from and to JSON.
*/
implicit val decoder: Decoder[Pet] = deriveDecoder
implicit val encoder: ObjectEncoder[Pet] = deriveEncoder
}

View File

@@ -1,25 +0,0 @@
package io.swagger.petstore.models
import io.circe._
import io.finch.circe._
import io.circe.generic.semiauto._
import io.circe.java8.time._
import io.swagger.petstore._
/**
* A tag for a pet
* @param id
* @param name
*/
case class Tag(
id: Option[Long],
name: Option[String]
)
object Tag {
/**
* Creates the codec for converting Tag from and to JSON.
*/
implicit val decoder: Decoder[Tag] = deriveDecoder
implicit val encoder: ObjectEncoder[Tag] = deriveEncoder
}

View File

@@ -1,37 +0,0 @@
package io.swagger.petstore.models
import io.circe._
import io.finch.circe._
import io.circe.generic.semiauto._
import io.circe.java8.time._
import io.swagger.petstore._
/**
* A User who is purchasing from the pet store
* @param id
* @param username
* @param firstName
* @param lastName
* @param email
* @param password
* @param phone
* @param userStatus User Status
*/
case class User(
id: Option[Long],
username: Option[String],
firstName: Option[String],
lastName: Option[String],
email: Option[String],
password: Option[String],
phone: Option[String],
userStatus: Option[Int]
)
object User {
/**
* Creates the codec for converting User from and to JSON.
*/
implicit val decoder: Decoder[User] = deriveDecoder
implicit val encoder: ObjectEncoder[User] = deriveEncoder
}