Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[finch] Allow finch server to compile for CI checks #7

Merged
merged 1 commit into from
May 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,7 @@ public String modelFileFolder() {
return outputFolder + File.separator + sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar);
}

/**
* Convert OpenAPI Model object to Codegen Model object
*
* @param name the name of the model
* @param model OpenAPI Model object
* @param allDefinitions a map of all OpenAPI models from the spec
* @return Codegen Model object
*/
@Override
public CodegenModel fromModel(String name, Schema model, Map<String, Schema> allDefinitions) {
CodegenModel codegenModel = super.fromModel(name, model, allDefinitions);
return codegenModel;
}

@SuppressWarnings("unchecked")
@Override
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
Expand All @@ -244,6 +231,7 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
}


@SuppressWarnings("Duplicates")
@Override
public String getTypeDeclaration(Schema p) {
if (ModelUtils.isArraySchema(p)) {
Expand All @@ -261,7 +249,7 @@ public String getTypeDeclaration(Schema p) {
@Override
public String getSchemaType(Schema p) {
String schemaType = super.getSchemaType(p);
String type = null;
String type;
if (typeMapping.containsKey(schemaType)) {
type = typeMapping.get(schemaType);
if (languageSpecificPrimitives.contains(type)) {
Expand Down Expand Up @@ -371,9 +359,9 @@ private void generateScalaPath(CodegenOperation op) {
String scalaPath = "";
Integer pathParamIndex = 0;

for (int i = 0; i < items.length; ++i) {
for (String item : items) {

if (items[i].matches("^\\{(.*)\\}$")) { // wrap in {}
if (item.matches("^\\{(.*)}$")) { // wrap in {}
// find the datatype of the parameter
final CodegenParameter cp = op.pathParams.get(pathParamIndex);

Expand All @@ -382,7 +370,7 @@ private void generateScalaPath(CodegenOperation op) {

pathParamIndex++;
} else {
scalaPath = colConcat(scalaPath, "\"" + items[i] + "\"");
scalaPath = colConcat(scalaPath, "\"" + item + "\"");
}
}

Expand Down Expand Up @@ -431,7 +419,14 @@ private void generateInputParameters(CodegenOperation op) {
p.vendorExtensions.put("x-codegen-normalized-path-type", "fileUpload(\"" + p.paramName + "\")");
p.vendorExtensions.put("x-codegen-normalized-input-type", "FileUpload");
} else if (p.isPrimitiveType && !p.isPathParam) {
p.vendorExtensions.put("x-codegen-normalized-path-type", p.dataType.toLowerCase());
if (!p.required) {
// Generator's current version of Finch doesn't support something like stringOption, but finch aggregates all
// parameter types under "param", so optional params can be grabbed by "paramOption".
p.vendorExtensions.put("x-codegen-normalized-path-type", toPathParameter(p, "param", true));
} else {
// If parameter is primitive and required, we can rely on data types like "string" or "long"
p.vendorExtensions.put("x-codegen-normalized-path-type", p.dataType.toLowerCase());
}
p.vendorExtensions.put("x-codegen-normalized-input-type", toInputParameter(p));
} else {
//Path paremeters are handled in generateScalaPath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ package {{packageName}}
import java.io._
import java.util.UUID
import java.time._

import com.twitter.finagle.http.exp.Multipart.{FileUpload, InMemoryFileUpload, OnDiskFileUpload}

import {{modelPackage}}._

trait DataAccessor {
// TODO: apiInfo -> apis -> operations = ???
// NOTE: ??? throws a not implemented exception
// TODO: apiInfo -> apis -> operations = TODO error
private object TODO extends CommonError("Not implemented") {
def message = "Not implemented"
}

{{#apiInfo}}
{{#apis}}
Expand All @@ -20,7 +22,7 @@ trait DataAccessor {
* {{{description}}}
* @return A {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}
*/
def {{baseName}}_{{operationId}}({{{vendorExtensions.x-codegen-typedParams}}}): Either[CommonError,{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}] = ???
def {{baseName}}_{{operationId}}({{{vendorExtensions.x-codegen-typedParams}}}): Either[CommonError,{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}] = Left(TODO)

{{/operation}}
{{/operations}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ object {{classname}} {
* @return An endpoint representing a {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}
*/
private def {{operationId}}(da: DataAccessor): Endpoint[{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}] =
{{httpMethod}}({{{vendorExtensions.x-codegen-paths}}}) { {{#hasParams}}({{{vendorExtensions.x-codegen-typedParams}}}) => {{/hasParams}}
{{httpMethod}}({{{vendorExtensions.x-codegen-paths}}}) { {{#vendorExtensions.x-codegen-typedParams}}({{{vendorExtensions.x-codegen-typedParams}}}) =>{{/vendorExtensions.x-codegen-typedParams}}
da.{{baseName}}_{{operationId}}({{{vendorExtensions.x-codegen-params}}}) match {
case Left(error) => checkError(error)
case Right(data) => Ok(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name := "finch-sample"

version := "0.1.0-SNAPSHOT"

scalaVersion := "2.11.12"
scalaVersion := "2.12.3"

resolvers += Resolver.sonatypeRepo("snapshots")

Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/finch/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name := "finch-sample"

version := "0.1.0-SNAPSHOT"

scalaVersion := "2.11.12"
scalaVersion := "2.12.3"

resolvers += Resolver.sonatypeRepo("snapshots")

Expand Down
48 changes: 25 additions & 23 deletions samples/server/petstore/finch/src/main/scala/DataAccessor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,132 +4,134 @@ package org.openapitools
import java.io._
import java.util.UUID
import java.time._

import com.twitter.finagle.http.exp.Multipart.{FileUpload, InMemoryFileUpload, OnDiskFileUpload}

import org.openapitools.models._

trait DataAccessor {
// TODO: apiInfo -> apis -> operations = ???
// NOTE: ??? throws a not implemented exception
// TODO: apiInfo -> apis -> operations = TODO error
private object TODO extends CommonError("Not implemented") {
def message = "Not implemented"
}

/**
*
* @return A Unit
*/
def Pet_addPet(pet: Pet): Either[CommonError,Unit] = ???
def Pet_addPet(pet: Pet): Either[CommonError,Unit] = Left(TODO)

/**
*
* @return A Unit
*/
def Pet_deletePet(petId: Long, apiKey: Option[String]): Either[CommonError,Unit] = ???
def Pet_deletePet(petId: Long, apiKey: Option[String]): Either[CommonError,Unit] = Left(TODO)

/**
*
* @return A Seq[Pet]
*/
def Pet_findPetsByStatus(status: Seq[String]): Either[CommonError,Seq[Pet]] = ???
def Pet_findPetsByStatus(status: Seq[String]): Either[CommonError,Seq[Pet]] = Left(TODO)

/**
*
* @return A Seq[Pet]
*/
def Pet_findPetsByTags(tags: Seq[String]): Either[CommonError,Seq[Pet]] = ???
def Pet_findPetsByTags(tags: Seq[String]): Either[CommonError,Seq[Pet]] = Left(TODO)

/**
*
* @return A Pet
*/
def Pet_getPetById(petId: Long, authParamapi_key: String): Either[CommonError,Pet] = ???
def Pet_getPetById(petId: Long, authParamapi_key: String): Either[CommonError,Pet] = Left(TODO)

/**
*
* @return A Unit
*/
def Pet_updatePet(pet: Pet): Either[CommonError,Unit] = ???
def Pet_updatePet(pet: Pet): Either[CommonError,Unit] = Left(TODO)

/**
*
* @return A Unit
*/
def Pet_updatePetWithForm(petId: Long, name: Option[String], status: Option[String]): Either[CommonError,Unit] = ???
def Pet_updatePetWithForm(petId: Long, name: Option[String], status: Option[String]): Either[CommonError,Unit] = Left(TODO)

/**
*
* @return A ApiResponse
*/
def Pet_uploadFile(petId: Long, additionalMetadata: Option[String], file: FileUpload): Either[CommonError,ApiResponse] = ???
def Pet_uploadFile(petId: Long, additionalMetadata: Option[String], file: FileUpload): Either[CommonError,ApiResponse] = Left(TODO)

/**
*
* @return A Unit
*/
def Store_deleteOrder(orderId: String): Either[CommonError,Unit] = ???
def Store_deleteOrder(orderId: String): Either[CommonError,Unit] = Left(TODO)

/**
*
* @return A Map[String, Int]
*/
def Store_getInventory(authParamapi_key: String): Either[CommonError,Map[String, Int]] = ???
def Store_getInventory(authParamapi_key: String): Either[CommonError,Map[String, Int]] = Left(TODO)

/**
*
* @return A Order
*/
def Store_getOrderById(orderId: Long): Either[CommonError,Order] = ???
def Store_getOrderById(orderId: Long): Either[CommonError,Order] = Left(TODO)

/**
*
* @return A Order
*/
def Store_placeOrder(order: Order): Either[CommonError,Order] = ???
def Store_placeOrder(order: Order): Either[CommonError,Order] = Left(TODO)

/**
*
* @return A Unit
*/
def User_createUser(user: User): Either[CommonError,Unit] = ???
def User_createUser(user: User): Either[CommonError,Unit] = Left(TODO)

/**
*
* @return A Unit
*/
def User_createUsersWithArrayInput(user: Seq[User]): Either[CommonError,Unit] = ???
def User_createUsersWithArrayInput(user: Seq[User]): Either[CommonError,Unit] = Left(TODO)

/**
*
* @return A Unit
*/
def User_createUsersWithListInput(user: Seq[User]): Either[CommonError,Unit] = ???
def User_createUsersWithListInput(user: Seq[User]): Either[CommonError,Unit] = Left(TODO)

/**
*
* @return A Unit
*/
def User_deleteUser(username: String): Either[CommonError,Unit] = ???
def User_deleteUser(username: String): Either[CommonError,Unit] = Left(TODO)

/**
*
* @return A User
*/
def User_getUserByName(username: String): Either[CommonError,User] = ???
def User_getUserByName(username: String): Either[CommonError,User] = Left(TODO)

/**
*
* @return A String
*/
def User_loginUser(username: String, password: String): Either[CommonError,String] = ???
def User_loginUser(username: String, password: String): Either[CommonError,String] = Left(TODO)

/**
*
* @return A Unit
*/
def User_logoutUser(): Either[CommonError,Unit] = ???
def User_logoutUser(): Either[CommonError,Unit] = Left(TODO)

/**
*
* @return A Unit
*/
def User_updateUser(username: String, user: User): Either[CommonError,Unit] = ???
def User_updateUser(username: String, user: User): Either[CommonError,Unit] = Left(TODO)

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ object PetApi {
* @return An endpoint representing a Unit
*/
private def addPet(da: DataAccessor): Endpoint[Unit] =
post("pet" :: jsonBody[Pet]) { (pet: Pet) =>
post("pet" :: jsonBody[Pet]) { (pet: Pet) =>
da.Pet_addPet(pet) match {
case Left(error) => checkError(error)
case Right(data) => Ok(data)
Expand All @@ -74,7 +74,7 @@ object PetApi {
* @return An endpoint representing a Unit
*/
private def deletePet(da: DataAccessor): Endpoint[Unit] =
delete("pet" :: long :: headerOption("api_key")) { (petId: Long, apiKey: Option[String]) =>
delete("pet" :: long :: headerOption("api_key")) { (petId: Long, apiKey: Option[String]) =>
da.Pet_deletePet(petId, apiKey) match {
case Left(error) => checkError(error)
case Right(data) => Ok(data)
Expand All @@ -88,7 +88,7 @@ object PetApi {
* @return An endpoint representing a Seq[Pet]
*/
private def findPetsByStatus(da: DataAccessor): Endpoint[Seq[Pet]] =
get("pet" :: "findByStatus" :: params("status")) { (status: Seq[String]) =>
get("pet" :: "findByStatus" :: params("status")) { (status: Seq[String]) =>
da.Pet_findPetsByStatus(status) match {
case Left(error) => checkError(error)
case Right(data) => Ok(data)
Expand All @@ -102,7 +102,7 @@ object PetApi {
* @return An endpoint representing a Seq[Pet]
*/
private def findPetsByTags(da: DataAccessor): Endpoint[Seq[Pet]] =
get("pet" :: "findByTags" :: params("tags")) { (tags: Seq[String]) =>
get("pet" :: "findByTags" :: params("tags")) { (tags: Seq[String]) =>
da.Pet_findPetsByTags(tags) match {
case Left(error) => checkError(error)
case Right(data) => Ok(data)
Expand All @@ -116,7 +116,7 @@ object PetApi {
* @return An endpoint representing a Pet
*/
private def getPetById(da: DataAccessor): Endpoint[Pet] =
get("pet" :: long :: header("api_key")) { (petId: Long, authParamapi_key: String) =>
get("pet" :: long :: header("api_key")) { (petId: Long, authParamapi_key: String) =>
da.Pet_getPetById(petId, authParamapi_key) match {
case Left(error) => checkError(error)
case Right(data) => Ok(data)
Expand All @@ -130,7 +130,7 @@ object PetApi {
* @return An endpoint representing a Unit
*/
private def updatePet(da: DataAccessor): Endpoint[Unit] =
put("pet" :: jsonBody[Pet]) { (pet: Pet) =>
put("pet" :: jsonBody[Pet]) { (pet: Pet) =>
da.Pet_updatePet(pet) match {
case Left(error) => checkError(error)
case Right(data) => Ok(data)
Expand All @@ -144,7 +144,7 @@ object PetApi {
* @return An endpoint representing a Unit
*/
private def updatePetWithForm(da: DataAccessor): Endpoint[Unit] =
post("pet" :: long :: string :: string) { (petId: Long, name: Option[String], status: Option[String]) =>
post("pet" :: long :: paramOption("name") :: paramOption("status")) { (petId: Long, name: Option[String], status: Option[String]) =>
da.Pet_updatePetWithForm(petId, name, status) match {
case Left(error) => checkError(error)
case Right(data) => Ok(data)
Expand All @@ -158,7 +158,7 @@ object PetApi {
* @return An endpoint representing a ApiResponse
*/
private def uploadFile(da: DataAccessor): Endpoint[ApiResponse] =
post("pet" :: long :: "uploadImage" :: string :: fileUpload("file")) { (petId: Long, additionalMetadata: Option[String], file: FileUpload) =>
post("pet" :: long :: "uploadImage" :: paramOption("additionalMetadata") :: fileUpload("file")) { (petId: Long, additionalMetadata: Option[String], file: FileUpload) =>
da.Pet_uploadFile(petId, additionalMetadata, file) match {
case Left(error) => checkError(error)
case Right(data) => Ok(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ object StoreApi {
* @return An endpoint representing a Unit
*/
private def deleteOrder(da: DataAccessor): Endpoint[Unit] =
delete("store" :: "order" :: string) { (orderId: String) =>
delete("store" :: "order" :: string) { (orderId: String) =>
da.Store_deleteOrder(orderId) match {
case Left(error) => checkError(error)
case Right(data) => Ok(data)
Expand All @@ -68,7 +68,7 @@ object StoreApi {
* @return An endpoint representing a Map[String, Int]
*/
private def getInventory(da: DataAccessor): Endpoint[Map[String, Int]] =
get("store" :: "inventory" :: header("api_key")) {
get("store" :: "inventory" :: header("api_key")) { (authParamapi_key: String) =>
da.Store_getInventory(authParamapi_key) match {
case Left(error) => checkError(error)
case Right(data) => Ok(data)
Expand All @@ -82,7 +82,7 @@ object StoreApi {
* @return An endpoint representing a Order
*/
private def getOrderById(da: DataAccessor): Endpoint[Order] =
get("store" :: "order" :: long) { (orderId: Long) =>
get("store" :: "order" :: long) { (orderId: Long) =>
da.Store_getOrderById(orderId) match {
case Left(error) => checkError(error)
case Right(data) => Ok(data)
Expand All @@ -96,7 +96,7 @@ object StoreApi {
* @return An endpoint representing a Order
*/
private def placeOrder(da: DataAccessor): Endpoint[Order] =
post("store" :: "order" :: jsonBody[Order]) { (order: Order) =>
post("store" :: "order" :: jsonBody[Order]) { (order: Order) =>
da.Store_placeOrder(order) match {
case Left(error) => checkError(error)
case Right(data) => Ok(data)
Expand Down
Loading