From ee23f8e50c9ac6e184b1e94a6eaba78be38a909b Mon Sep 17 00:00:00 2001 From: clasnake Date: Mon, 13 Feb 2017 22:33:55 +0800 Subject: [PATCH] Fix finch package name. (#4755) --- .../codegen/languages/FinchServerCodegen.java | 6 +- samples/server/petstore/finch/LICENSE | 201 ----------------- .../finch/src/main/scala/DataAccessor.scala | 208 +++++++++--------- .../finch/src/main/scala/Server.scala | 11 +- .../finch/src/main/scala/endpoint.scala | 44 ++-- .../finch/src/main/scala/errors.scala | 2 +- .../main/scala/io/swagger/apis/PetApi.scala | 149 +++++++++++++ .../main/scala/io/swagger/apis/StoreApi.scala | 96 ++++++++ .../main/scala/io/swagger/apis/UserApi.scala | 150 +++++++++++++ .../scala/io/swagger/models/ApiResponse.scala | 26 +++ .../scala/io/swagger/models/Category.scala | 24 ++ .../main/scala/io/swagger/models/Order.scala | 33 +++ .../main/scala/io/swagger/models/Pet.scala | 35 +++ .../main/scala/io/swagger/models/Tag.scala | 24 ++ .../main/scala/io/swagger/models/User.scala | 36 +++ .../io/swagger/petstore/apis/PetApi.scala | 148 ------------- .../io/swagger/petstore/apis/StoreApi.scala | 95 -------- .../io/swagger/petstore/apis/UserApi.scala | 149 ------------- .../swagger/petstore/models/ApiResponse.scala | 27 --- .../io/swagger/petstore/models/Category.scala | 25 --- .../io/swagger/petstore/models/Order.scala | 34 --- .../io/swagger/petstore/models/Pet.scala | 36 --- .../io/swagger/petstore/models/Tag.scala | 25 --- .../io/swagger/petstore/models/User.scala | 37 ---- 24 files changed, 709 insertions(+), 912 deletions(-) delete mode 100644 samples/server/petstore/finch/LICENSE create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/apis/PetApi.scala create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/apis/StoreApi.scala create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/apis/UserApi.scala create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/models/ApiResponse.scala create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/models/Category.scala create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/models/Order.scala create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/models/Pet.scala create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/models/Tag.scala create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/models/User.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/PetApi.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/StoreApi.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/UserApi.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/ApiResponse.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Category.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Order.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Pet.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Tag.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/User.scala diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FinchServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FinchServerCodegen.java index 4a3eed3a01bb..f807325c1442 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FinchServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FinchServerCodegen.java @@ -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)); diff --git a/samples/server/petstore/finch/LICENSE b/samples/server/petstore/finch/LICENSE deleted file mode 100644 index 8dada3edaf50..000000000000 --- a/samples/server/petstore/finch/LICENSE +++ /dev/null @@ -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. diff --git a/samples/server/petstore/finch/src/main/scala/DataAccessor.scala b/samples/server/petstore/finch/src/main/scala/DataAccessor.scala index bcbd036637c3..4c9d06b2ea91 100644 --- a/samples/server/petstore/finch/src/main/scala/DataAccessor.scala +++ b/samples/server/petstore/finch/src/main/scala/DataAccessor.scala @@ -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 = ??? } \ No newline at end of file diff --git a/samples/server/petstore/finch/src/main/scala/Server.scala b/samples/server/petstore/finch/src/main/scala/Server.scala index 716b6eae52e8..ec3ed482e274 100644 --- a/samples/server/petstore/finch/src/main/scala/Server.scala +++ b/samples/server/petstore/finch/src/main/scala/Server.scala @@ -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) diff --git a/samples/server/petstore/finch/src/main/scala/endpoint.scala b/samples/server/petstore/finch/src/main/scala/endpoint.scala index df0093b7b130..5241b51bbd8d 100644 --- a/samples/server/petstore/finch/src/main/scala/endpoint.scala +++ b/samples/server/petstore/finch/src/main/scala/endpoint.scala @@ -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 } \ No newline at end of file diff --git a/samples/server/petstore/finch/src/main/scala/errors.scala b/samples/server/petstore/finch/src/main/scala/errors.scala index 69e3831c15dd..162549e0f23c 100644 --- a/samples/server/petstore/finch/src/main/scala/errors.scala +++ b/samples/server/petstore/finch/src/main/scala/errors.scala @@ -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. diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/apis/PetApi.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/apis/PetApi.scala new file mode 100644 index 000000000000..74a01c56f51c --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/apis/PetApi.scala @@ -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 +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/apis/StoreApi.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/apis/StoreApi.scala new file mode 100644 index 000000000000..02186ce1f65e --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/apis/StoreApi.scala @@ -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 +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/apis/UserApi.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/apis/UserApi.scala new file mode 100644 index 000000000000..dfb49b4291a8 --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/apis/UserApi.scala @@ -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 +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/models/ApiResponse.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/models/ApiResponse.scala new file mode 100644 index 000000000000..9e603aadec68 --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/models/ApiResponse.scala @@ -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 +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/models/Category.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/models/Category.scala new file mode 100644 index 000000000000..be697aa298e5 --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/models/Category.scala @@ -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 +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/models/Order.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/models/Order.scala new file mode 100644 index 000000000000..2934ee921b3c --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/models/Order.scala @@ -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 +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/models/Pet.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/models/Pet.scala new file mode 100644 index 000000000000..e78617c7db81 --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/models/Pet.scala @@ -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 +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/models/Tag.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/models/Tag.scala new file mode 100644 index 000000000000..242ffcfc86e6 --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/models/Tag.scala @@ -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 +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/models/User.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/models/User.scala new file mode 100644 index 000000000000..18253b5deae0 --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/models/User.scala @@ -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 +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/PetApi.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/PetApi.scala deleted file mode 100644 index 420279685d3f..000000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/PetApi.scala +++ /dev/null @@ -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 -} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/StoreApi.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/StoreApi.scala deleted file mode 100644 index 38dda7b47867..000000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/StoreApi.scala +++ /dev/null @@ -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 -} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/UserApi.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/UserApi.scala deleted file mode 100644 index 560509a349c3..000000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/UserApi.scala +++ /dev/null @@ -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 -} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/ApiResponse.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/ApiResponse.scala deleted file mode 100644 index 248833a4e750..000000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/ApiResponse.scala +++ /dev/null @@ -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 -} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Category.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Category.scala deleted file mode 100644 index ceb17f6b7e74..000000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Category.scala +++ /dev/null @@ -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 -} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Order.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Order.scala deleted file mode 100644 index 08743ebbf13a..000000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Order.scala +++ /dev/null @@ -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 -} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Pet.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Pet.scala deleted file mode 100644 index 4a17021b726c..000000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Pet.scala +++ /dev/null @@ -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 -} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Tag.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Tag.scala deleted file mode 100644 index 5fb213c0c3f9..000000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Tag.scala +++ /dev/null @@ -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 -} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/User.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/User.scala deleted file mode 100644 index 6556cdb437a0..000000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/User.scala +++ /dev/null @@ -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 -}