cask fix for response encoding (#18375)

This commit is contained in:
Aaron Pritzlaff
2024-04-13 02:34:08 +01:00
committed by GitHub
parent 359ff9e457
commit 24c1968002
4 changed files with 37 additions and 30 deletions

View File

@@ -46,16 +46,12 @@ class {{classname}}Routes(service : {{classname}}Service) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
{{#vendorExtensions.x-has-response-types}}
{{#responses}}
{{#dataType}}
case Right(value : {{dataType}}) => cask.Response(data = write(value), {{code}}, headers = Seq("Content-Type" -> "application/json"))
{{/dataType}}
{{/responses}}
{{/vendorExtensions.x-has-response-types}}
{{^vendorExtensions.x-has-response-types}}
case Right(_) => cask.Response("", 200)
{{/vendorExtensions.x-has-response-types}}
{{#responses}}
{{#dataType}}
case Right(value : {{dataType}}) => cask.Response(data = write(value), {{code}}, headers = Seq("Content-Type" -> "application/json"))
{{/dataType}}
{{/responses}}
case Right(other) => cask.Response(s"$other", 200)
}
}
{{/operation}}

View File

@@ -67,7 +67,8 @@ class PetRoutes(service : PetService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(value : Pet) => cask.Response(data = write(value), 200, headers = Seq("Content-Type" -> "application/json"))
case Right(other) => cask.Response(s"$other", 200)
}
}
/** Deletes a pet
@@ -87,7 +88,7 @@ class PetRoutes(service : PetService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(other) => cask.Response(s"$other", 200)
}
}
/** Finds Pets by status
@@ -105,7 +106,8 @@ class PetRoutes(service : PetService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(value : List[Pet]) => cask.Response(data = write(value), 200, headers = Seq("Content-Type" -> "application/json"))
case Right(other) => cask.Response(s"$other", 200)
}
}
/** Finds Pets by tags
@@ -123,7 +125,8 @@ class PetRoutes(service : PetService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(value : List[Pet]) => cask.Response(data = write(value), 200, headers = Seq("Content-Type" -> "application/json"))
case Right(other) => cask.Response(s"$other", 200)
}
}
/** Find pet by ID
@@ -142,7 +145,8 @@ class PetRoutes(service : PetService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(value : Pet) => cask.Response(data = write(value), 200, headers = Seq("Content-Type" -> "application/json"))
case Right(other) => cask.Response(s"$other", 200)
}
}
/** Update an existing pet
@@ -162,7 +166,8 @@ class PetRoutes(service : PetService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(value : Pet) => cask.Response(data = write(value), 200, headers = Seq("Content-Type" -> "application/json"))
case Right(other) => cask.Response(s"$other", 200)
}
}
/** Updates a pet in the store with form data
@@ -183,7 +188,7 @@ class PetRoutes(service : PetService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(other) => cask.Response(s"$other", 200)
}
}
/** uploads an image
@@ -204,7 +209,8 @@ class PetRoutes(service : PetService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(value : ApiResponse) => cask.Response(data = write(value), 200, headers = Seq("Content-Type" -> "application/json"))
case Right(other) => cask.Response(s"$other", 200)
}
}

View File

@@ -43,7 +43,7 @@ class StoreRoutes(service : StoreService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(other) => cask.Response(s"$other", 200)
}
}
/** Returns pet inventories by status
@@ -61,7 +61,8 @@ class StoreRoutes(service : StoreService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(value : Map[String, Int]) => cask.Response(data = write(value), 200, headers = Seq("Content-Type" -> "application/json"))
case Right(other) => cask.Response(s"$other", 200)
}
}
/** Find purchase order by ID
@@ -79,7 +80,8 @@ class StoreRoutes(service : StoreService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(value : Order) => cask.Response(data = write(value), 200, headers = Seq("Content-Type" -> "application/json"))
case Right(other) => cask.Response(s"$other", 200)
}
}
/** Place an order for a pet
@@ -98,7 +100,8 @@ class StoreRoutes(service : StoreService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(value : Order) => cask.Response(data = write(value), 200, headers = Seq("Content-Type" -> "application/json"))
case Right(other) => cask.Response(s"$other", 200)
}
}

View File

@@ -56,7 +56,7 @@ class UserRoutes(service : UserService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(other) => cask.Response(s"$other", 200)
}
}
/** Creates list of users with given input array
@@ -75,7 +75,7 @@ class UserRoutes(service : UserService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(other) => cask.Response(s"$other", 200)
}
}
/** Creates list of users with given input array
@@ -94,7 +94,7 @@ class UserRoutes(service : UserService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(other) => cask.Response(s"$other", 200)
}
}
/** Delete user
@@ -113,7 +113,7 @@ class UserRoutes(service : UserService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(other) => cask.Response(s"$other", 200)
}
}
/** Get user by user name
@@ -131,7 +131,8 @@ class UserRoutes(service : UserService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(value : User) => cask.Response(data = write(value), 200, headers = Seq("Content-Type" -> "application/json"))
case Right(other) => cask.Response(s"$other", 200)
}
}
/** Logs user into the system
@@ -148,7 +149,8 @@ class UserRoutes(service : UserService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(value : String) => cask.Response(data = write(value), 200, headers = Seq("Content-Type" -> "application/json"))
case Right(other) => cask.Response(s"$other", 200)
}
}
/** Logs out current logged in user session
@@ -166,7 +168,7 @@ class UserRoutes(service : UserService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(other) => cask.Response(s"$other", 200)
}
}
/** Updated user
@@ -187,7 +189,7 @@ class UserRoutes(service : UserService) extends cask.Routes {
result match {
case Left(error) => cask.Response(error, 500)
case Right(_) => cask.Response("", 200)
case Right(other) => cask.Response(s"$other", 200)
}
}