Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
update petstore sample with scalafmt
  • Loading branch information
wing328 committed Sep 29, 2018
commit 7379f64aa999f92cf98fece1baf29b693b3c34a4
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.api

import org.openapitools.client.model._
Expand All @@ -17,30 +17,32 @@ import scala.reflect.ClassTag

object EnumsSerializers {

def all: Seq[Serializer[_]] = Seq[Serializer[_]]() :+
new EnumNameSerializer(OrderEnums.Status) :+
new EnumNameSerializer(PetEnums.Status)
def all: Seq[Serializer[_]] =
Seq[Serializer[_]]() :+
new EnumNameSerializer(OrderEnums.Status) :+
new EnumNameSerializer(PetEnums.Status)

private class EnumNameSerializer[E <: Enumeration: ClassTag](enum: E)
extends Serializer[E#Value] {
extends Serializer[E#Value] {
import JsonDSL._

val EnumerationClass: Class[E#Value] = classOf[E#Value]

def deserialize(implicit format: Formats):
PartialFunction[(TypeInfo, JValue), E#Value] = {
def deserialize(implicit format: Formats)
: PartialFunction[(TypeInfo, JValue), E#Value] = {
case (t @ TypeInfo(EnumerationClass, _), json) if isValid(json) =>
json match {
case JString(value) =>
enum.withName(value)
case value =>
throw new MappingException(s"Can't convert $value to $EnumerationClass")
throw new MappingException(
s"Can't convert $value to $EnumerationClass")
}
}

private[this] def isValid(json: JValue) = json match {
case JString(value) if enum.values.exists(_.toString == value) => true
case _ => false
case _ => false
}

def serialize(implicit format: Formats): PartialFunction[Any, JValue] = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.api

import org.openapitools.client.model.ApiResponse
Expand All @@ -21,118 +21,151 @@ import org.openapitools.client.core.ApiKeyLocations._
object PetApi {

/**
* Expected answers:
* code 405 : (Invalid input)
*
* @param pet Pet object that needs to be added to the store
*/
* Expected answers:
* code 405 : (Invalid input)
*
* @param pet Pet object that needs to be added to the store
*/
def addPet(pet: Pet): ApiRequest[Unit] =
ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/pet", "application/json")
ApiRequest[Unit](ApiMethods.POST,
"http://petstore.swagger.io/v2",
"/pet",
"application/json")
.withBody(pet)
.withErrorResponse[Unit](405)
/**
* Expected answers:
* code 400 : (Invalid pet value)
*
* @param petId Pet id to delete
* @param apiKey
*/

/**
* Expected answers:
* code 400 : (Invalid pet value)
*
* @param petId Pet id to delete
* @param apiKey
*/
def deletePet(petId: Long, apiKey: Option[String] = None): ApiRequest[Unit] =
ApiRequest[Unit](ApiMethods.DELETE, "http://petstore.swagger.io/v2", "/pet/{petId}", "application/json")
ApiRequest[Unit](ApiMethods.DELETE,
"http://petstore.swagger.io/v2",
"/pet/{petId}",
"application/json")
.withPathParam("petId", petId)
.withHeaderParam("api_key", apiKey)
.withErrorResponse[Unit](400)
/**
* Multiple status values can be provided with comma separated strings
*
* Expected answers:
* code 200 : Seq[Pet] (successful operation)
* code 400 : (Invalid status value)
*
* @param status Status values that need to be considered for filter
*/

/**
* Multiple status values can be provided with comma separated strings
*
* Expected answers:
* code 200 : Seq[Pet] (successful operation)
* code 400 : (Invalid status value)
*
* @param status Status values that need to be considered for filter
*/
def findPetsByStatus(status: Seq[String]): ApiRequest[Seq[Pet]] =
ApiRequest[Seq[Pet]](ApiMethods.GET, "http://petstore.swagger.io/v2", "/pet/findByStatus", "application/json")
ApiRequest[Seq[Pet]](ApiMethods.GET,
"http://petstore.swagger.io/v2",
"/pet/findByStatus",
"application/json")
.withQueryParam("status", ArrayValues(status, CSV))
.withSuccessResponse[Seq[Pet]](200)
.withErrorResponse[Unit](400)
/**
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
*
* Expected answers:
* code 200 : Seq[Pet] (successful operation)
* code 400 : (Invalid tag value)
*
* @param tags Tags to filter by
*/

/**
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
*
* Expected answers:
* code 200 : Seq[Pet] (successful operation)
* code 400 : (Invalid tag value)
*
* @param tags Tags to filter by
*/
def findPetsByTags(tags: Seq[String]): ApiRequest[Seq[Pet]] =
ApiRequest[Seq[Pet]](ApiMethods.GET, "http://petstore.swagger.io/v2", "/pet/findByTags", "application/json")
ApiRequest[Seq[Pet]](ApiMethods.GET,
"http://petstore.swagger.io/v2",
"/pet/findByTags",
"application/json")
.withQueryParam("tags", ArrayValues(tags, CSV))
.withSuccessResponse[Seq[Pet]](200)
.withErrorResponse[Unit](400)
/**
* Returns a single pet
*
* Expected answers:
* code 200 : Pet (successful operation)
* code 400 : (Invalid ID supplied)
* code 404 : (Pet not found)
*
* Available security schemes:
* api_key (apiKey)
*
* @param petId ID of pet to return
*/

/**
* Returns a single pet
*
* Expected answers:
* code 200 : Pet (successful operation)
* code 400 : (Invalid ID supplied)
* code 404 : (Pet not found)
*
* Available security schemes:
* api_key (apiKey)
*
* @param petId ID of pet to return
*/
def getPetById(petId: Long)(implicit apiKey: ApiKeyValue): ApiRequest[Unit] =
ApiRequest[Unit](ApiMethods.GET, "http://petstore.swagger.io/v2", "/pet/{petId}", "application/json")
ApiRequest[Unit](ApiMethods.GET,
"http://petstore.swagger.io/v2",
"/pet/{petId}",
"application/json")
.withApiKey(apiKey, "api_key", HEADER)
.withPathParam("petId", petId)
.withSuccessResponse[Pet](200)
.withErrorResponse[Unit](400)
.withErrorResponse[Unit](404)
/**
* Expected answers:
* code 400 : (Invalid ID supplied)
* code 404 : (Pet not found)
* code 405 : (Validation exception)
*
* @param pet Pet object that needs to be added to the store
*/

/**
* Expected answers:
* code 400 : (Invalid ID supplied)
* code 404 : (Pet not found)
* code 405 : (Validation exception)
*
* @param pet Pet object that needs to be added to the store
*/
def updatePet(pet: Pet): ApiRequest[Unit] =
ApiRequest[Unit](ApiMethods.PUT, "http://petstore.swagger.io/v2", "/pet", "application/json")
ApiRequest[Unit](ApiMethods.PUT,
"http://petstore.swagger.io/v2",
"/pet",
"application/json")
.withBody(pet)
.withErrorResponse[Unit](400)
.withErrorResponse[Unit](404)
.withErrorResponse[Unit](405)
/**
* Expected answers:
* code 405 : (Invalid input)
*
* @param petId ID of pet that needs to be updated
* @param name Updated name of the pet
* @param status Updated status of the pet
*/
def updatePetWithForm(petId: Long, name: Option[String] = None, status: Option[String] = None): ApiRequest[Unit] =
ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/pet/{petId}", "application/x-www-form-urlencoded")

/**
* Expected answers:
* code 405 : (Invalid input)
*
* @param petId ID of pet that needs to be updated
* @param name Updated name of the pet
* @param status Updated status of the pet
*/
def updatePetWithForm(petId: Long,
name: Option[String] = None,
status: Option[String] = None): ApiRequest[Unit] =
ApiRequest[Unit](ApiMethods.POST,
"http://petstore.swagger.io/v2",
"/pet/{petId}",
"application/x-www-form-urlencoded")
.withFormParam("name", name)
.withFormParam("status", status)
.withPathParam("petId", petId)
.withErrorResponse[Unit](405)
/**
* Expected answers:
* code 200 : ApiResponse (successful operation)
*
* @param petId ID of pet to update
* @param additionalMetadata Additional data to pass to server
* @param file file to upload
*/
def uploadFile(petId: Long, additionalMetadata: Option[String] = None, file: Option[File] = None): ApiRequest[Unit] =
ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/pet/{petId}/uploadImage", "multipart/form-data")

/**
* Expected answers:
* code 200 : ApiResponse (successful operation)
*
* @param petId ID of pet to update
* @param additionalMetadata Additional data to pass to server
* @param file file to upload
*/
def uploadFile(petId: Long,
additionalMetadata: Option[String] = None,
file: Option[File] = None): ApiRequest[Unit] =
ApiRequest[Unit](ApiMethods.POST,
"http://petstore.swagger.io/v2",
"/pet/{petId}/uploadImage",
"multipart/form-data")
.withFormParam("additionalMetadata", additionalMetadata)
.withFormParam("file", file)
.withPathParam("petId", petId)
.withSuccessResponse[ApiResponse](200)


}

Loading