forked from loafle/openapi-generator-original
Add option to enable scalafmt for code formatting (#1032)
* add option to enable scalafmt for code formatting * fix typo
This commit is contained in:
parent
48e66ed627
commit
fc35bb17d0
@ -21,6 +21,7 @@ import com.samskivert.mustache.Escapers;
|
|||||||
import com.samskivert.mustache.Mustache;
|
import com.samskivert.mustache.Mustache;
|
||||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||||
import io.swagger.v3.oas.models.media.Schema;
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.openapitools.codegen.CliOption;
|
import org.openapitools.codegen.CliOption;
|
||||||
import org.openapitools.codegen.CodegenConstants;
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
@ -113,6 +114,10 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
public void processOpts() {
|
public void processOpts() {
|
||||||
super.processOpts();
|
super.processOpts();
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(System.getenv("SCALAFMT_PATH"))) {
|
||||||
|
LOGGER.info("Environment variable SCALAFMT_PATH not defined so the Scala code may not be properly formatted. To define it, try 'export SCALAFMT_PATH=/usr/local/bin/scalafmt' (Linux/Mac)");
|
||||||
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) {
|
if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) {
|
||||||
this.setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER));
|
this.setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER));
|
||||||
}
|
}
|
||||||
@ -298,4 +303,31 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
return input.replace("\"", "");
|
return input.replace("\"", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postProcessFile(File file, String fileType) {
|
||||||
|
if (file == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String scalafmtPath = System.getenv("SCALAFMT_PATH");
|
||||||
|
if (StringUtils.isEmpty(scalafmtPath)) {
|
||||||
|
return; // skip if SCALAFMT_PATH env variable is not defined
|
||||||
|
}
|
||||||
|
|
||||||
|
// only process files with scala extension
|
||||||
|
if ("scala".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||||
|
String command = scalafmtPath + " " + file.toString();
|
||||||
|
try {
|
||||||
|
Process p = Runtime.getRuntime().exec(command);
|
||||||
|
p.waitFor();
|
||||||
|
if (p.exitValue() != 0) {
|
||||||
|
LOGGER.error("Error running the command ({}). Exit value: {}", command, p.exitValue());
|
||||||
|
}
|
||||||
|
LOGGER.info("Successfully executed: " + command);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
3.0.0-SNAPSHOT
|
3.3.0-SNAPSHOT
|
@ -240,4 +240,4 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
@ -1,14 +1,14 @@
|
|||||||
/**
|
/**
|
||||||
* OpenAPI Petstore
|
* 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.
|
* 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
|
* OpenAPI spec version: 1.0.0
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
* https://openapi-generator.tech
|
* https://openapi-generator.tech
|
||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
package org.openapitools.client.api
|
package org.openapitools.client.api
|
||||||
|
|
||||||
import org.openapitools.client.model._
|
import org.openapitools.client.model._
|
||||||
@ -17,30 +17,32 @@ import scala.reflect.ClassTag
|
|||||||
|
|
||||||
object EnumsSerializers {
|
object EnumsSerializers {
|
||||||
|
|
||||||
def all: Seq[Serializer[_]] = Seq[Serializer[_]]() :+
|
def all: Seq[Serializer[_]] =
|
||||||
new EnumNameSerializer(OrderEnums.Status) :+
|
Seq[Serializer[_]]() :+
|
||||||
new EnumNameSerializer(PetEnums.Status)
|
new EnumNameSerializer(OrderEnums.Status) :+
|
||||||
|
new EnumNameSerializer(PetEnums.Status)
|
||||||
|
|
||||||
private class EnumNameSerializer[E <: Enumeration: ClassTag](enum: E)
|
private class EnumNameSerializer[E <: Enumeration: ClassTag](enum: E)
|
||||||
extends Serializer[E#Value] {
|
extends Serializer[E#Value] {
|
||||||
import JsonDSL._
|
import JsonDSL._
|
||||||
|
|
||||||
val EnumerationClass: Class[E#Value] = classOf[E#Value]
|
val EnumerationClass: Class[E#Value] = classOf[E#Value]
|
||||||
|
|
||||||
def deserialize(implicit format: Formats):
|
def deserialize(implicit format: Formats)
|
||||||
PartialFunction[(TypeInfo, JValue), E#Value] = {
|
: PartialFunction[(TypeInfo, JValue), E#Value] = {
|
||||||
case (t @ TypeInfo(EnumerationClass, _), json) if isValid(json) =>
|
case (t @ TypeInfo(EnumerationClass, _), json) if isValid(json) =>
|
||||||
json match {
|
json match {
|
||||||
case JString(value) =>
|
case JString(value) =>
|
||||||
enum.withName(value)
|
enum.withName(value)
|
||||||
case 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 {
|
private[this] def isValid(json: JValue) = json match {
|
||||||
case JString(value) if enum.values.exists(_.toString == value) => true
|
case JString(value) if enum.values.exists(_.toString == value) => true
|
||||||
case _ => false
|
case _ => false
|
||||||
}
|
}
|
||||||
|
|
||||||
def serialize(implicit format: Formats): PartialFunction[Any, JValue] = {
|
def serialize(implicit format: Formats): PartialFunction[Any, JValue] = {
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
/**
|
/**
|
||||||
* OpenAPI Petstore
|
* 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.
|
* 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
|
* OpenAPI spec version: 1.0.0
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
* https://openapi-generator.tech
|
* https://openapi-generator.tech
|
||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
package org.openapitools.client.api
|
package org.openapitools.client.api
|
||||||
|
|
||||||
import org.openapitools.client.model.ApiResponse
|
import org.openapitools.client.model.ApiResponse
|
||||||
@ -21,118 +21,151 @@ import org.openapitools.client.core.ApiKeyLocations._
|
|||||||
object PetApi {
|
object PetApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expected answers:
|
* Expected answers:
|
||||||
* code 405 : (Invalid input)
|
* code 405 : (Invalid input)
|
||||||
*
|
*
|
||||||
* @param pet Pet object that needs to be added to the store
|
* @param pet Pet object that needs to be added to the store
|
||||||
*/
|
*/
|
||||||
def addPet(pet: Pet): ApiRequest[Unit] =
|
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)
|
.withBody(pet)
|
||||||
.withErrorResponse[Unit](405)
|
.withErrorResponse[Unit](405)
|
||||||
/**
|
|
||||||
* Expected answers:
|
/**
|
||||||
* code 400 : (Invalid pet value)
|
* Expected answers:
|
||||||
*
|
* code 400 : (Invalid pet value)
|
||||||
* @param petId Pet id to delete
|
*
|
||||||
* @param apiKey
|
* @param petId Pet id to delete
|
||||||
*/
|
* @param apiKey
|
||||||
|
*/
|
||||||
def deletePet(petId: Long, apiKey: Option[String] = None): ApiRequest[Unit] =
|
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)
|
.withPathParam("petId", petId)
|
||||||
.withHeaderParam("api_key", apiKey)
|
.withHeaderParam("api_key", apiKey)
|
||||||
.withErrorResponse[Unit](400)
|
.withErrorResponse[Unit](400)
|
||||||
/**
|
|
||||||
* Multiple status values can be provided with comma separated strings
|
/**
|
||||||
*
|
* Multiple status values can be provided with comma separated strings
|
||||||
* Expected answers:
|
*
|
||||||
* code 200 : Seq[Pet] (successful operation)
|
* Expected answers:
|
||||||
* code 400 : (Invalid status value)
|
* code 200 : Seq[Pet] (successful operation)
|
||||||
*
|
* code 400 : (Invalid status value)
|
||||||
* @param status Status values that need to be considered for filter
|
*
|
||||||
*/
|
* @param status Status values that need to be considered for filter
|
||||||
|
*/
|
||||||
def findPetsByStatus(status: Seq[String]): ApiRequest[Seq[Pet]] =
|
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))
|
.withQueryParam("status", ArrayValues(status, CSV))
|
||||||
.withSuccessResponse[Seq[Pet]](200)
|
.withSuccessResponse[Seq[Pet]](200)
|
||||||
.withErrorResponse[Unit](400)
|
.withErrorResponse[Unit](400)
|
||||||
/**
|
|
||||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
/**
|
||||||
*
|
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||||
* Expected answers:
|
*
|
||||||
* code 200 : Seq[Pet] (successful operation)
|
* Expected answers:
|
||||||
* code 400 : (Invalid tag value)
|
* code 200 : Seq[Pet] (successful operation)
|
||||||
*
|
* code 400 : (Invalid tag value)
|
||||||
* @param tags Tags to filter by
|
*
|
||||||
*/
|
* @param tags Tags to filter by
|
||||||
|
*/
|
||||||
def findPetsByTags(tags: Seq[String]): ApiRequest[Seq[Pet]] =
|
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))
|
.withQueryParam("tags", ArrayValues(tags, CSV))
|
||||||
.withSuccessResponse[Seq[Pet]](200)
|
.withSuccessResponse[Seq[Pet]](200)
|
||||||
.withErrorResponse[Unit](400)
|
.withErrorResponse[Unit](400)
|
||||||
/**
|
|
||||||
* Returns a single pet
|
/**
|
||||||
*
|
* Returns a single pet
|
||||||
* Expected answers:
|
*
|
||||||
* code 200 : Pet (successful operation)
|
* Expected answers:
|
||||||
* code 400 : (Invalid ID supplied)
|
* code 200 : Pet (successful operation)
|
||||||
* code 404 : (Pet not found)
|
* code 400 : (Invalid ID supplied)
|
||||||
*
|
* code 404 : (Pet not found)
|
||||||
* Available security schemes:
|
*
|
||||||
* api_key (apiKey)
|
* Available security schemes:
|
||||||
*
|
* api_key (apiKey)
|
||||||
* @param petId ID of pet to return
|
*
|
||||||
*/
|
* @param petId ID of pet to return
|
||||||
|
*/
|
||||||
def getPetById(petId: Long)(implicit apiKey: ApiKeyValue): ApiRequest[Unit] =
|
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)
|
.withApiKey(apiKey, "api_key", HEADER)
|
||||||
.withPathParam("petId", petId)
|
.withPathParam("petId", petId)
|
||||||
.withSuccessResponse[Pet](200)
|
.withSuccessResponse[Pet](200)
|
||||||
.withErrorResponse[Unit](400)
|
.withErrorResponse[Unit](400)
|
||||||
.withErrorResponse[Unit](404)
|
.withErrorResponse[Unit](404)
|
||||||
/**
|
|
||||||
* Expected answers:
|
/**
|
||||||
* code 400 : (Invalid ID supplied)
|
* Expected answers:
|
||||||
* code 404 : (Pet not found)
|
* code 400 : (Invalid ID supplied)
|
||||||
* code 405 : (Validation exception)
|
* code 404 : (Pet not found)
|
||||||
*
|
* code 405 : (Validation exception)
|
||||||
* @param pet Pet object that needs to be added to the store
|
*
|
||||||
*/
|
* @param pet Pet object that needs to be added to the store
|
||||||
|
*/
|
||||||
def updatePet(pet: Pet): ApiRequest[Unit] =
|
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)
|
.withBody(pet)
|
||||||
.withErrorResponse[Unit](400)
|
.withErrorResponse[Unit](400)
|
||||||
.withErrorResponse[Unit](404)
|
.withErrorResponse[Unit](404)
|
||||||
.withErrorResponse[Unit](405)
|
.withErrorResponse[Unit](405)
|
||||||
/**
|
|
||||||
* Expected answers:
|
/**
|
||||||
* code 405 : (Invalid input)
|
* Expected answers:
|
||||||
*
|
* code 405 : (Invalid input)
|
||||||
* @param petId ID of pet that needs to be updated
|
*
|
||||||
* @param name Updated name of the pet
|
* @param petId ID of pet that needs to be updated
|
||||||
* @param status Updated status of the pet
|
* @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")
|
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("name", name)
|
||||||
.withFormParam("status", status)
|
.withFormParam("status", status)
|
||||||
.withPathParam("petId", petId)
|
.withPathParam("petId", petId)
|
||||||
.withErrorResponse[Unit](405)
|
.withErrorResponse[Unit](405)
|
||||||
/**
|
|
||||||
* Expected answers:
|
/**
|
||||||
* code 200 : ApiResponse (successful operation)
|
* Expected answers:
|
||||||
*
|
* code 200 : ApiResponse (successful operation)
|
||||||
* @param petId ID of pet to update
|
*
|
||||||
* @param additionalMetadata Additional data to pass to server
|
* @param petId ID of pet to update
|
||||||
* @param file file to upload
|
* @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")
|
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("additionalMetadata", additionalMetadata)
|
||||||
.withFormParam("file", file)
|
.withFormParam("file", file)
|
||||||
.withPathParam("petId", petId)
|
.withPathParam("petId", petId)
|
||||||
.withSuccessResponse[ApiResponse](200)
|
.withSuccessResponse[ApiResponse](200)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
/**
|
/**
|
||||||
* OpenAPI Petstore
|
* 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.
|
* 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
|
* OpenAPI spec version: 1.0.0
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
* https://openapi-generator.tech
|
* https://openapi-generator.tech
|
||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
package org.openapitools.client.api
|
package org.openapitools.client.api
|
||||||
|
|
||||||
import org.openapitools.client.model.Order
|
import org.openapitools.client.model.Order
|
||||||
@ -19,61 +19,75 @@ import org.openapitools.client.core.ApiKeyLocations._
|
|||||||
object StoreApi {
|
object StoreApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||||
*
|
*
|
||||||
* Expected answers:
|
* Expected answers:
|
||||||
* code 400 : (Invalid ID supplied)
|
* code 400 : (Invalid ID supplied)
|
||||||
* code 404 : (Order not found)
|
* code 404 : (Order not found)
|
||||||
*
|
*
|
||||||
* @param orderId ID of the order that needs to be deleted
|
* @param orderId ID of the order that needs to be deleted
|
||||||
*/
|
*/
|
||||||
def deleteOrder(orderId: String): ApiRequest[Unit] =
|
def deleteOrder(orderId: String): ApiRequest[Unit] =
|
||||||
ApiRequest[Unit](ApiMethods.DELETE, "http://petstore.swagger.io/v2", "/store/order/{orderId}", "application/json")
|
ApiRequest[Unit](ApiMethods.DELETE,
|
||||||
|
"http://petstore.swagger.io/v2",
|
||||||
|
"/store/order/{orderId}",
|
||||||
|
"application/json")
|
||||||
.withPathParam("orderId", orderId)
|
.withPathParam("orderId", orderId)
|
||||||
.withErrorResponse[Unit](400)
|
.withErrorResponse[Unit](400)
|
||||||
.withErrorResponse[Unit](404)
|
.withErrorResponse[Unit](404)
|
||||||
/**
|
|
||||||
* Returns a map of status codes to quantities
|
/**
|
||||||
*
|
* Returns a map of status codes to quantities
|
||||||
* Expected answers:
|
*
|
||||||
* code 200 : Map[String, Int] (successful operation)
|
* Expected answers:
|
||||||
*
|
* code 200 : Map[String, Int] (successful operation)
|
||||||
* Available security schemes:
|
*
|
||||||
* api_key (apiKey)
|
* Available security schemes:
|
||||||
*/
|
* api_key (apiKey)
|
||||||
def getInventory()(implicit apiKey: ApiKeyValue): ApiRequest[Map[String, Int]] =
|
*/
|
||||||
ApiRequest[Map[String, Int]](ApiMethods.GET, "http://petstore.swagger.io/v2", "/store/inventory", "application/json")
|
def getInventory()(
|
||||||
|
implicit apiKey: ApiKeyValue): ApiRequest[Map[String, Int]] =
|
||||||
|
ApiRequest[Map[String, Int]](ApiMethods.GET,
|
||||||
|
"http://petstore.swagger.io/v2",
|
||||||
|
"/store/inventory",
|
||||||
|
"application/json")
|
||||||
.withApiKey(apiKey, "api_key", HEADER)
|
.withApiKey(apiKey, "api_key", HEADER)
|
||||||
.withSuccessResponse[Map[String, Int]](200)
|
.withSuccessResponse[Map[String, Int]](200)
|
||||||
/**
|
|
||||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
/**
|
||||||
*
|
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||||
* Expected answers:
|
*
|
||||||
* code 200 : Order (successful operation)
|
* Expected answers:
|
||||||
* code 400 : (Invalid ID supplied)
|
* code 200 : Order (successful operation)
|
||||||
* code 404 : (Order not found)
|
* code 400 : (Invalid ID supplied)
|
||||||
*
|
* code 404 : (Order not found)
|
||||||
* @param orderId ID of pet that needs to be fetched
|
*
|
||||||
*/
|
* @param orderId ID of pet that needs to be fetched
|
||||||
|
*/
|
||||||
def getOrderById(orderId: Long): ApiRequest[Unit] =
|
def getOrderById(orderId: Long): ApiRequest[Unit] =
|
||||||
ApiRequest[Unit](ApiMethods.GET, "http://petstore.swagger.io/v2", "/store/order/{orderId}", "application/json")
|
ApiRequest[Unit](ApiMethods.GET,
|
||||||
|
"http://petstore.swagger.io/v2",
|
||||||
|
"/store/order/{orderId}",
|
||||||
|
"application/json")
|
||||||
.withPathParam("orderId", orderId)
|
.withPathParam("orderId", orderId)
|
||||||
.withSuccessResponse[Order](200)
|
.withSuccessResponse[Order](200)
|
||||||
.withErrorResponse[Unit](400)
|
.withErrorResponse[Unit](400)
|
||||||
.withErrorResponse[Unit](404)
|
.withErrorResponse[Unit](404)
|
||||||
/**
|
|
||||||
* Expected answers:
|
/**
|
||||||
* code 200 : Order (successful operation)
|
* Expected answers:
|
||||||
* code 400 : (Invalid Order)
|
* code 200 : Order (successful operation)
|
||||||
*
|
* code 400 : (Invalid Order)
|
||||||
* @param order order placed for purchasing the pet
|
*
|
||||||
*/
|
* @param order order placed for purchasing the pet
|
||||||
|
*/
|
||||||
def placeOrder(order: Order): ApiRequest[Unit] =
|
def placeOrder(order: Order): ApiRequest[Unit] =
|
||||||
ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/store/order", "application/json")
|
ApiRequest[Unit](ApiMethods.POST,
|
||||||
|
"http://petstore.swagger.io/v2",
|
||||||
|
"/store/order",
|
||||||
|
"application/json")
|
||||||
.withBody(order)
|
.withBody(order)
|
||||||
.withSuccessResponse[Order](200)
|
.withSuccessResponse[Order](200)
|
||||||
.withErrorResponse[Unit](400)
|
.withErrorResponse[Unit](400)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
/**
|
/**
|
||||||
* OpenAPI Petstore
|
* 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.
|
* 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
|
* OpenAPI spec version: 1.0.0
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
* https://openapi-generator.tech
|
* https://openapi-generator.tech
|
||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
package org.openapitools.client.api
|
package org.openapitools.client.api
|
||||||
|
|
||||||
import org.openapitools.client.model.User
|
import org.openapitools.client.model.User
|
||||||
@ -19,111 +19,141 @@ import org.openapitools.client.core.ApiKeyLocations._
|
|||||||
object UserApi {
|
object UserApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This can only be done by the logged in user.
|
* This can only be done by the logged in user.
|
||||||
*
|
*
|
||||||
* Expected answers:
|
* Expected answers:
|
||||||
* code 0 : (successful operation)
|
* code 0 : (successful operation)
|
||||||
*
|
*
|
||||||
* @param user Created user object
|
* @param user Created user object
|
||||||
*/
|
*/
|
||||||
def createUser(user: User): ApiRequest[Unit] =
|
def createUser(user: User): ApiRequest[Unit] =
|
||||||
ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/user", "application/json")
|
ApiRequest[Unit](ApiMethods.POST,
|
||||||
|
"http://petstore.swagger.io/v2",
|
||||||
|
"/user",
|
||||||
|
"application/json")
|
||||||
.withBody(user)
|
.withBody(user)
|
||||||
.withDefaultSuccessResponse[Unit]
|
.withDefaultSuccessResponse[Unit]
|
||||||
/**
|
|
||||||
* Expected answers:
|
/**
|
||||||
* code 0 : (successful operation)
|
* Expected answers:
|
||||||
*
|
* code 0 : (successful operation)
|
||||||
* @param user List of user object
|
*
|
||||||
*/
|
* @param user List of user object
|
||||||
|
*/
|
||||||
def createUsersWithArrayInput(user: Seq[User]): ApiRequest[Unit] =
|
def createUsersWithArrayInput(user: Seq[User]): ApiRequest[Unit] =
|
||||||
ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/user/createWithArray", "application/json")
|
ApiRequest[Unit](ApiMethods.POST,
|
||||||
|
"http://petstore.swagger.io/v2",
|
||||||
|
"/user/createWithArray",
|
||||||
|
"application/json")
|
||||||
.withBody(user)
|
.withBody(user)
|
||||||
.withDefaultSuccessResponse[Unit]
|
.withDefaultSuccessResponse[Unit]
|
||||||
/**
|
|
||||||
* Expected answers:
|
/**
|
||||||
* code 0 : (successful operation)
|
* Expected answers:
|
||||||
*
|
* code 0 : (successful operation)
|
||||||
* @param user List of user object
|
*
|
||||||
*/
|
* @param user List of user object
|
||||||
|
*/
|
||||||
def createUsersWithListInput(user: Seq[User]): ApiRequest[Unit] =
|
def createUsersWithListInput(user: Seq[User]): ApiRequest[Unit] =
|
||||||
ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/user/createWithList", "application/json")
|
ApiRequest[Unit](ApiMethods.POST,
|
||||||
|
"http://petstore.swagger.io/v2",
|
||||||
|
"/user/createWithList",
|
||||||
|
"application/json")
|
||||||
.withBody(user)
|
.withBody(user)
|
||||||
.withDefaultSuccessResponse[Unit]
|
.withDefaultSuccessResponse[Unit]
|
||||||
/**
|
|
||||||
* This can only be done by the logged in user.
|
/**
|
||||||
*
|
* This can only be done by the logged in user.
|
||||||
* Expected answers:
|
*
|
||||||
* code 400 : (Invalid username supplied)
|
* Expected answers:
|
||||||
* code 404 : (User not found)
|
* code 400 : (Invalid username supplied)
|
||||||
*
|
* code 404 : (User not found)
|
||||||
* @param username The name that needs to be deleted
|
*
|
||||||
*/
|
* @param username The name that needs to be deleted
|
||||||
|
*/
|
||||||
def deleteUser(username: String): ApiRequest[Unit] =
|
def deleteUser(username: String): ApiRequest[Unit] =
|
||||||
ApiRequest[Unit](ApiMethods.DELETE, "http://petstore.swagger.io/v2", "/user/{username}", "application/json")
|
ApiRequest[Unit](ApiMethods.DELETE,
|
||||||
|
"http://petstore.swagger.io/v2",
|
||||||
|
"/user/{username}",
|
||||||
|
"application/json")
|
||||||
.withPathParam("username", username)
|
.withPathParam("username", username)
|
||||||
.withErrorResponse[Unit](400)
|
.withErrorResponse[Unit](400)
|
||||||
.withErrorResponse[Unit](404)
|
.withErrorResponse[Unit](404)
|
||||||
/**
|
|
||||||
* Expected answers:
|
/**
|
||||||
* code 200 : User (successful operation)
|
* Expected answers:
|
||||||
* code 400 : (Invalid username supplied)
|
* code 200 : User (successful operation)
|
||||||
* code 404 : (User not found)
|
* code 400 : (Invalid username supplied)
|
||||||
*
|
* code 404 : (User not found)
|
||||||
* @param username The name that needs to be fetched. Use user1 for testing.
|
*
|
||||||
*/
|
* @param username The name that needs to be fetched. Use user1 for testing.
|
||||||
|
*/
|
||||||
def getUserByName(username: String): ApiRequest[Unit] =
|
def getUserByName(username: String): ApiRequest[Unit] =
|
||||||
ApiRequest[Unit](ApiMethods.GET, "http://petstore.swagger.io/v2", "/user/{username}", "application/json")
|
ApiRequest[Unit](ApiMethods.GET,
|
||||||
|
"http://petstore.swagger.io/v2",
|
||||||
|
"/user/{username}",
|
||||||
|
"application/json")
|
||||||
.withPathParam("username", username)
|
.withPathParam("username", username)
|
||||||
.withSuccessResponse[User](200)
|
.withSuccessResponse[User](200)
|
||||||
.withErrorResponse[Unit](400)
|
.withErrorResponse[Unit](400)
|
||||||
.withErrorResponse[Unit](404)
|
.withErrorResponse[Unit](404)
|
||||||
/**
|
|
||||||
* Expected answers:
|
/**
|
||||||
* code 200 : String (successful operation)
|
* Expected answers:
|
||||||
* Headers :
|
* code 200 : String (successful operation)
|
||||||
* X-Rate-Limit - calls per hour allowed by the user
|
* Headers :
|
||||||
* X-Expires-After - date in UTC when toekn expires
|
* X-Rate-Limit - calls per hour allowed by the user
|
||||||
* code 400 : (Invalid username/password supplied)
|
* X-Expires-After - date in UTC when toekn expires
|
||||||
*
|
* code 400 : (Invalid username/password supplied)
|
||||||
* @param username The user name for login
|
*
|
||||||
* @param password The password for login in clear text
|
* @param username The user name for login
|
||||||
*/
|
* @param password The password for login in clear text
|
||||||
|
*/
|
||||||
def loginUser(username: String, password: String): ApiRequest[Unit] =
|
def loginUser(username: String, password: String): ApiRequest[Unit] =
|
||||||
ApiRequest[Unit](ApiMethods.GET, "http://petstore.swagger.io/v2", "/user/login", "application/json")
|
ApiRequest[Unit](ApiMethods.GET,
|
||||||
|
"http://petstore.swagger.io/v2",
|
||||||
|
"/user/login",
|
||||||
|
"application/json")
|
||||||
.withQueryParam("username", username)
|
.withQueryParam("username", username)
|
||||||
.withQueryParam("password", password)
|
.withQueryParam("password", password)
|
||||||
.withSuccessResponse[String](200)
|
.withSuccessResponse[String](200)
|
||||||
.withErrorResponse[Unit](400)
|
.withErrorResponse[Unit](400)
|
||||||
|
|
||||||
object LoginUserHeaders {
|
object LoginUserHeaders {
|
||||||
def xRateLimit(r: ApiReturnWithHeaders) = r.getIntHeader("X-Rate-Limit")
|
def xRateLimit(r: ApiReturnWithHeaders) = r.getIntHeader("X-Rate-Limit")
|
||||||
def xExpiresAfter(r: ApiReturnWithHeaders) = r.getDateTimeHeader("X-Expires-After")
|
def xExpiresAfter(r: ApiReturnWithHeaders) =
|
||||||
|
r.getDateTimeHeader("X-Expires-After")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expected answers:
|
* Expected answers:
|
||||||
* code 0 : (successful operation)
|
* code 0 : (successful operation)
|
||||||
*/
|
*/
|
||||||
def logoutUser(): ApiRequest[Unit] =
|
def logoutUser(): ApiRequest[Unit] =
|
||||||
ApiRequest[Unit](ApiMethods.GET, "http://petstore.swagger.io/v2", "/user/logout", "application/json")
|
ApiRequest[Unit](ApiMethods.GET,
|
||||||
|
"http://petstore.swagger.io/v2",
|
||||||
|
"/user/logout",
|
||||||
|
"application/json")
|
||||||
.withDefaultSuccessResponse[Unit]
|
.withDefaultSuccessResponse[Unit]
|
||||||
/**
|
|
||||||
* This can only be done by the logged in user.
|
/**
|
||||||
*
|
* This can only be done by the logged in user.
|
||||||
* Expected answers:
|
*
|
||||||
* code 400 : (Invalid user supplied)
|
* Expected answers:
|
||||||
* code 404 : (User not found)
|
* code 400 : (Invalid user supplied)
|
||||||
*
|
* code 404 : (User not found)
|
||||||
* @param username name that need to be deleted
|
*
|
||||||
* @param user Updated user object
|
* @param username name that need to be deleted
|
||||||
*/
|
* @param user Updated user object
|
||||||
|
*/
|
||||||
def updateUser(username: String, user: User): ApiRequest[Unit] =
|
def updateUser(username: String, user: User): ApiRequest[Unit] =
|
||||||
ApiRequest[Unit](ApiMethods.PUT, "http://petstore.swagger.io/v2", "/user/{username}", "application/json")
|
ApiRequest[Unit](ApiMethods.PUT,
|
||||||
|
"http://petstore.swagger.io/v2",
|
||||||
|
"/user/{username}",
|
||||||
|
"application/json")
|
||||||
.withBody(user)
|
.withBody(user)
|
||||||
.withPathParam("username", username)
|
.withPathParam("username", username)
|
||||||
.withErrorResponse[Unit](400)
|
.withErrorResponse[Unit](400)
|
||||||
.withErrorResponse[Unit](404)
|
.withErrorResponse[Unit](404)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
/**
|
/**
|
||||||
* OpenAPI Petstore
|
* 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.
|
* 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
|
* OpenAPI spec version: 1.0.0
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
* https://openapi-generator.tech
|
* https://openapi-generator.tech
|
||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
package org.openapitools.client.core
|
package org.openapitools.client.core
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -46,58 +46,82 @@ object ApiInvoker {
|
|||||||
|
|
||||||
def apply()(implicit system: ActorSystem): ApiInvoker =
|
def apply()(implicit system: ActorSystem): ApiInvoker =
|
||||||
apply(DefaultFormats + DateTimeSerializer)
|
apply(DefaultFormats + DateTimeSerializer)
|
||||||
def apply(serializers: Traversable[Serializer[_]])(implicit system: ActorSystem): ApiInvoker =
|
def apply(serializers: Traversable[Serializer[_]])(
|
||||||
|
implicit system: ActorSystem): ApiInvoker =
|
||||||
apply(DefaultFormats + DateTimeSerializer ++ serializers)
|
apply(DefaultFormats + DateTimeSerializer ++ serializers)
|
||||||
def apply(formats: Formats)(implicit system: ActorSystem): ApiInvoker = new ApiInvoker(formats)
|
def apply(formats: Formats)(implicit system: ActorSystem): ApiInvoker =
|
||||||
|
new ApiInvoker(formats)
|
||||||
|
|
||||||
case class CustomStatusCode(value: Int, reason: String = "Application-defined status code", isSuccess: Boolean = true)
|
case class CustomStatusCode(
|
||||||
|
value: Int,
|
||||||
|
reason: String = "Application-defined status code",
|
||||||
|
isSuccess: Boolean = true)
|
||||||
|
|
||||||
def addCustomStatusCode(code: CustomStatusCode): Unit = addCustomStatusCode(code.value, code.reason, code.isSuccess)
|
def addCustomStatusCode(code: CustomStatusCode): Unit =
|
||||||
|
addCustomStatusCode(code.value, code.reason, code.isSuccess)
|
||||||
|
|
||||||
def addCustomStatusCode(code: Int, reason: String = "Application defined code", isSuccess: Boolean = true): Unit = {
|
def addCustomStatusCode(code: Int,
|
||||||
|
reason: String = "Application defined code",
|
||||||
|
isSuccess: Boolean = true): Unit = {
|
||||||
StatusCodes.getForKey(code) foreach { _ =>
|
StatusCodes.getForKey(code) foreach { _ =>
|
||||||
StatusCodes.registerCustom(code, reason, reason, isSuccess, allowsEntity = true)
|
StatusCodes.registerCustom(code,
|
||||||
|
reason,
|
||||||
|
reason,
|
||||||
|
isSuccess,
|
||||||
|
allowsEntity = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows request execution without calling apiInvoker.execute(request)
|
* Allows request execution without calling apiInvoker.execute(request)
|
||||||
* request.response can be used to get a future of the ApiResponse generated.
|
* request.response can be used to get a future of the ApiResponse generated.
|
||||||
* request.result can be used to get a future of the expected ApiResponse content. If content doesn't match, a
|
* request.result can be used to get a future of the expected ApiResponse content. If content doesn't match, a
|
||||||
* Future will failed with a ClassCastException
|
* Future will failed with a ClassCastException
|
||||||
* @param request the apiRequest to be executed
|
* @param request the apiRequest to be executed
|
||||||
*/
|
*/
|
||||||
implicit class ApiRequestImprovements[T](request: ApiRequest[T]) {
|
implicit class ApiRequestImprovements[T](request: ApiRequest[T]) {
|
||||||
|
|
||||||
def response(invoker: ApiInvoker)(implicit ec: ExecutionContext, system: ActorSystem): Future[ApiResponse[T]] =
|
def response(invoker: ApiInvoker)(
|
||||||
|
implicit ec: ExecutionContext,
|
||||||
|
system: ActorSystem): Future[ApiResponse[T]] =
|
||||||
response(ec, system, invoker)
|
response(ec, system, invoker)
|
||||||
|
|
||||||
def response(implicit ec: ExecutionContext, system: ActorSystem, invoker: ApiInvoker): Future[ApiResponse[T]] =
|
def response(implicit ec: ExecutionContext,
|
||||||
|
system: ActorSystem,
|
||||||
|
invoker: ApiInvoker): Future[ApiResponse[T]] =
|
||||||
invoker.execute(request)
|
invoker.execute(request)
|
||||||
|
|
||||||
def result[U <: T](implicit c: ClassTag[U], ec: ExecutionContext, system: ActorSystem, invoker: ApiInvoker): Future[U] =
|
def result[U <: T](implicit c: ClassTag[U],
|
||||||
|
ec: ExecutionContext,
|
||||||
|
system: ActorSystem,
|
||||||
|
invoker: ApiInvoker): Future[U] =
|
||||||
invoker.execute(request).map(_.content).mapTo[U]
|
invoker.execute(request).map(_.content).mapTo[U]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows transformation from ApiMethod to spray HttpMethods
|
* Allows transformation from ApiMethod to spray HttpMethods
|
||||||
* @param method the ApiMethod to be converted
|
* @param method the ApiMethod to be converted
|
||||||
*/
|
*/
|
||||||
implicit class ApiMethodExtensions(val method: ApiMethod) {
|
implicit class ApiMethodExtensions(val method: ApiMethod) {
|
||||||
def toSprayMethod: HttpMethod = HttpMethods.getForKey(method.value).getOrElse(HttpMethods.GET)
|
def toSprayMethod: HttpMethod =
|
||||||
|
HttpMethods.getForKey(method.value).getOrElse(HttpMethods.GET)
|
||||||
}
|
}
|
||||||
|
|
||||||
case object DateTimeSerializer extends CustomSerializer[DateTime](format => ( {
|
case object DateTimeSerializer
|
||||||
case JString(s) =>
|
extends CustomSerializer[DateTime](format =>
|
||||||
ISODateTimeFormat.dateOptionalTimeParser().parseDateTime(s)
|
({
|
||||||
}, {
|
case JString(s) =>
|
||||||
case d: DateTime =>
|
ISODateTimeFormat.dateOptionalTimeParser().parseDateTime(s)
|
||||||
JString(ISODateTimeFormat.dateTime().print(d))
|
}, {
|
||||||
}))
|
case d: DateTime =>
|
||||||
|
JString(ISODateTimeFormat.dateTime().print(d))
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends UntrustedSslContext with CustomContentTypes {
|
class ApiInvoker(formats: Formats)(implicit system: ActorSystem)
|
||||||
|
extends UntrustedSslContext
|
||||||
|
with CustomContentTypes {
|
||||||
|
|
||||||
import org.openapitools.client.core.ApiInvoker._
|
import org.openapitools.client.core.ApiInvoker._
|
||||||
import org.openapitools.client.core.ParametersMap._
|
import org.openapitools.client.core.ParametersMap._
|
||||||
@ -109,23 +133,27 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends Untrust
|
|||||||
|
|
||||||
import spray.http.MessagePredicate._
|
import spray.http.MessagePredicate._
|
||||||
|
|
||||||
val CompressionFilter: MessagePredicate= MessagePredicate({ _ => settings.compressionEnabled}) &&
|
val CompressionFilter: MessagePredicate = MessagePredicate({ _ =>
|
||||||
|
settings.compressionEnabled
|
||||||
|
}) &&
|
||||||
Encoder.DefaultFilter && minEntitySize(settings.compressionSizeThreshold)
|
Encoder.DefaultFilter && minEntitySize(settings.compressionSizeThreshold)
|
||||||
|
|
||||||
settings.customCodes.foreach(addCustomStatusCode)
|
settings.customCodes.foreach(addCustomStatusCode)
|
||||||
|
|
||||||
private def addAuthentication(credentialsSeq: Seq[Credentials]): pipelining.RequestTransformer =
|
private def addAuthentication(
|
||||||
|
credentialsSeq: Seq[Credentials]): pipelining.RequestTransformer =
|
||||||
request =>
|
request =>
|
||||||
credentialsSeq.foldLeft(request) {
|
credentialsSeq.foldLeft(request) {
|
||||||
case (req, BasicCredentials(login, password)) =>
|
case (req, BasicCredentials(login, password)) =>
|
||||||
req ~> addCredentials(BasicHttpCredentials(login, password))
|
req ~> addCredentials(BasicHttpCredentials(login, password))
|
||||||
case (req, ApiKeyCredentials(keyValue, keyName, ApiKeyLocations.HEADER)) =>
|
case (req,
|
||||||
|
ApiKeyCredentials(keyValue, keyName, ApiKeyLocations.HEADER)) =>
|
||||||
req ~> addHeader(RawHeader(keyName, keyValue.value))
|
req ~> addHeader(RawHeader(keyName, keyValue.value))
|
||||||
case (req, _) => req
|
case (req, _) => req
|
||||||
}
|
}
|
||||||
|
|
||||||
private def addHeaders(headers: Map[String, Any]): pipelining.RequestTransformer = { request =>
|
|
||||||
|
|
||||||
|
private def addHeaders(
|
||||||
|
headers: Map[String, Any]): pipelining.RequestTransformer = { request =>
|
||||||
val rawHeaders = for {
|
val rawHeaders = for {
|
||||||
(name, value) <- headers.asFormattedParams
|
(name, value) <- headers.asFormattedParams
|
||||||
header = RawHeader(name, String.valueOf(value))
|
header = RawHeader(name, String.valueOf(value))
|
||||||
@ -155,7 +183,9 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends Untrust
|
|||||||
Some(
|
Some(
|
||||||
normalizedContentType(request.contentType).mediaType match {
|
normalizedContentType(request.contentType).mediaType match {
|
||||||
case MediaTypes.`multipart/form-data` =>
|
case MediaTypes.`multipart/form-data` =>
|
||||||
MultipartFormData(params.map { case (name, value) => (name, bodyPart(name, value))})
|
MultipartFormData(params.map {
|
||||||
|
case (name, value) => (name, bodyPart(name, value))
|
||||||
|
})
|
||||||
case MediaTypes.`application/x-www-form-urlencoded` =>
|
case MediaTypes.`application/x-www-form-urlencoded` =>
|
||||||
FormData(params.mapValues(String.valueOf))
|
FormData(params.mapValues(String.valueOf))
|
||||||
case m: MediaType => // Default : application/x-www-form-urlencoded.
|
case m: MediaType => // Default : application/x-www-form-urlencoded.
|
||||||
@ -180,9 +210,13 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends Untrust
|
|||||||
case Some(c: MultipartFormData) =>
|
case Some(c: MultipartFormData) =>
|
||||||
builder.apply(uri, c)
|
builder.apply(uri, c)
|
||||||
case Some(c: String) =>
|
case Some(c: String) =>
|
||||||
builder.apply(uri, HttpEntity(normalizedContentType(request.contentType), c))
|
builder.apply(
|
||||||
|
uri,
|
||||||
|
HttpEntity(normalizedContentType(request.contentType), c))
|
||||||
case _ =>
|
case _ =>
|
||||||
builder.apply(uri, HttpEntity(normalizedContentType(request.contentType), " "))
|
builder.apply(
|
||||||
|
uri,
|
||||||
|
HttpEntity(normalizedContentType(request.contentType), " "))
|
||||||
}
|
}
|
||||||
case _ => builder.apply(uri)
|
case _ => builder.apply(uri)
|
||||||
}
|
}
|
||||||
@ -194,15 +228,17 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends Untrust
|
|||||||
}
|
}
|
||||||
|
|
||||||
def makeQuery(r: ApiRequest[_]): Query = {
|
def makeQuery(r: ApiRequest[_]): Query = {
|
||||||
r.credentials.foldLeft(r.queryParams) {
|
r.credentials
|
||||||
case (params, ApiKeyCredentials(key, keyName, ApiKeyLocations.QUERY)) =>
|
.foldLeft(r.queryParams) {
|
||||||
params + (keyName -> key.value)
|
case (params, ApiKeyCredentials(key, keyName, ApiKeyLocations.QUERY)) =>
|
||||||
case (params, _) => params
|
params + (keyName -> key.value)
|
||||||
}.asFormattedParams
|
case (params, _) => params
|
||||||
|
}
|
||||||
|
.asFormattedParams
|
||||||
.mapValues(String.valueOf)
|
.mapValues(String.valueOf)
|
||||||
.foldRight[Query](Uri.Query.Empty) {
|
.foldRight[Query](Uri.Query.Empty) {
|
||||||
case ((name, value), acc) => acc.+:(name, value)
|
case ((name, value), acc) => acc.+:(name, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def makeUri(r: ApiRequest[_]): Uri = {
|
def makeUri(r: ApiRequest[_]): Uri = {
|
||||||
@ -210,8 +246,8 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends Untrust
|
|||||||
val opPathWithParams = r.pathParams.asFormattedParams
|
val opPathWithParams = r.pathParams.asFormattedParams
|
||||||
.mapValues(String.valueOf)
|
.mapValues(String.valueOf)
|
||||||
.foldLeft(opPath) {
|
.foldLeft(opPath) {
|
||||||
case (path, (name, value)) => path.replaceAll(s"\\{$name\\}", value)
|
case (path, (name, value)) => path.replaceAll(s"\\{$name\\}", value)
|
||||||
}
|
}
|
||||||
val query = makeQuery(r)
|
val query = makeQuery(r)
|
||||||
|
|
||||||
Uri(r.basePath + opPathWithParams).withQuery(query)
|
Uri(r.basePath + opPathWithParams).withQuery(query)
|
||||||
@ -227,7 +263,9 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends Untrust
|
|||||||
uri.authority.host.toString,
|
uri.authority.host.toString,
|
||||||
uri.effectivePort,
|
uri.effectivePort,
|
||||||
sslEncryption = "https".equals(uri.scheme),
|
sslEncryption = "https".equals(uri.scheme),
|
||||||
defaultHeaders = settings.defaultHeaders ++ List(`Accept-Encoding`(gzip, deflate)))
|
defaultHeaders = settings.defaultHeaders ++ List(
|
||||||
|
`Accept-Encoding`(gzip, deflate))
|
||||||
|
)
|
||||||
|
|
||||||
val request = createRequest(uri, r)
|
val request = createRequest(uri, r)
|
||||||
|
|
||||||
@ -237,46 +275,62 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends Untrust
|
|||||||
} yield {
|
} yield {
|
||||||
response ~> decode(Deflate) ~> decode(Gzip) ~> unmarshallApiResponse(r)
|
response ~> decode(Deflate) ~> decode(Gzip) ~> unmarshallApiResponse(r)
|
||||||
}
|
}
|
||||||
}
|
} catch {
|
||||||
catch {
|
|
||||||
case NonFatal(x) => Future.failed(x)
|
case NonFatal(x) => Future.failed(x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def unmarshallApiResponse[T](request: ApiRequest[T])(response: HttpResponse): ApiResponse[T] = {
|
def unmarshallApiResponse[T](request: ApiRequest[T])(
|
||||||
|
response: HttpResponse): ApiResponse[T] = {
|
||||||
request.responseForCode(response.status.intValue) match {
|
request.responseForCode(response.status.intValue) match {
|
||||||
case Some( (manifest: Manifest[T], state: ResponseState) ) =>
|
case Some((manifest: Manifest[T], state: ResponseState)) =>
|
||||||
entityUnmarshaller(manifest)(response.entity) match {
|
entityUnmarshaller(manifest)(response.entity) match {
|
||||||
case Right(value) ⇒
|
case Right(value) ⇒
|
||||||
state match {
|
state match {
|
||||||
case ResponseState.Success =>
|
case ResponseState.Success =>
|
||||||
ApiResponse(response.status.intValue, value, response.headers.map(header => (header.name, header.value)).toMap)
|
ApiResponse(response.status.intValue,
|
||||||
|
value,
|
||||||
|
response.headers
|
||||||
|
.map(header => (header.name, header.value))
|
||||||
|
.toMap)
|
||||||
case ResponseState.Error =>
|
case ResponseState.Error =>
|
||||||
throw ApiError(response.status.intValue, "Error response received",
|
throw ApiError(response.status.intValue,
|
||||||
Some(value),
|
"Error response received",
|
||||||
headers = response.headers.map(header => (header.name, header.value)).toMap)
|
Some(value),
|
||||||
|
headers = response.headers
|
||||||
|
.map(header => (header.name, header.value))
|
||||||
|
.toMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
case Left(MalformedContent(error, Some(cause))) ⇒
|
case Left(MalformedContent(error, Some(cause))) ⇒
|
||||||
throw ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString), cause)
|
throw ApiError(response.status.intValue,
|
||||||
|
s"Unable to unmarshall content to [$manifest]",
|
||||||
|
Some(response.entity.toString),
|
||||||
|
cause)
|
||||||
|
|
||||||
case Left(MalformedContent(error, None)) ⇒
|
case Left(MalformedContent(error, None)) ⇒
|
||||||
throw ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString))
|
throw ApiError(response.status.intValue,
|
||||||
|
s"Unable to unmarshall content to [$manifest]",
|
||||||
|
Some(response.entity.toString))
|
||||||
|
|
||||||
case Left(ContentExpected) ⇒
|
case Left(ContentExpected) ⇒
|
||||||
throw ApiError(response.status.intValue, s"Unable to unmarshall empty response to [$manifest]", Some(response.entity.toString))
|
throw ApiError(
|
||||||
|
response.status.intValue,
|
||||||
|
s"Unable to unmarshall empty response to [$manifest]",
|
||||||
|
Some(response.entity.toString))
|
||||||
}
|
}
|
||||||
|
|
||||||
case _ => throw ApiError(response.status.intValue, "Unexpected response code", Some(response.entity.toString))
|
case _ =>
|
||||||
|
throw ApiError(response.status.intValue,
|
||||||
|
"Unexpected response code",
|
||||||
|
Some(response.entity.toString))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def entityUnmarshaller[T](implicit mf: Manifest[T]): Unmarshaller[T] =
|
def entityUnmarshaller[T](implicit mf: Manifest[T]): Unmarshaller[T] =
|
||||||
Unmarshaller[T](MediaTypes.`application/json`) {
|
Unmarshaller[T](MediaTypes.`application/json`) {
|
||||||
case x: HttpEntity.NonEmpty ⇒
|
case x: HttpEntity.NonEmpty ⇒
|
||||||
parse(x.asString(defaultCharset = HttpCharsets.`UTF-8`))
|
parse(x.asString(defaultCharset = HttpCharsets.`UTF-8`)).noNulls.camelizeKeys
|
||||||
.noNulls
|
|
||||||
.camelizeKeys
|
|
||||||
.extract[T]
|
.extract[T]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,10 +339,12 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends Untrust
|
|||||||
sealed trait CustomContentTypes {
|
sealed trait CustomContentTypes {
|
||||||
|
|
||||||
def normalizedContentType(original: String): ContentType =
|
def normalizedContentType(original: String): ContentType =
|
||||||
MediaTypes.forExtension(original) map (ContentType(_)) getOrElse parseContentType(original)
|
MediaTypes.forExtension(original) map (ContentType(_)) getOrElse parseContentType(
|
||||||
|
original)
|
||||||
|
|
||||||
def parseContentType(contentType: String): ContentType = {
|
def parseContentType(contentType: String): ContentType = {
|
||||||
val contentTypeAsRawHeader = HttpHeaders.RawHeader("Content-Type", contentType)
|
val contentTypeAsRawHeader =
|
||||||
|
HttpHeaders.RawHeader("Content-Type", contentType)
|
||||||
val parsedContentTypeHeader = HttpParser.parseHeader(contentTypeAsRawHeader)
|
val parsedContentTypeHeader = HttpParser.parseHeader(contentTypeAsRawHeader)
|
||||||
(parsedContentTypeHeader: @unchecked) match {
|
(parsedContentTypeHeader: @unchecked) match {
|
||||||
case Right(ct: HttpHeaders.`Content-Type`) =>
|
case Right(ct: HttpHeaders.`Content-Type`) =>
|
||||||
@ -310,9 +366,11 @@ sealed trait UntrustedSslContext {
|
|||||||
|
|
||||||
case true =>
|
case true =>
|
||||||
class IgnoreX509TrustManager extends X509TrustManager {
|
class IgnoreX509TrustManager extends X509TrustManager {
|
||||||
def checkClientTrusted(chain: Array[X509Certificate], authType: String): Unit = {}
|
def checkClientTrusted(chain: Array[X509Certificate],
|
||||||
|
authType: String): Unit = {}
|
||||||
|
|
||||||
def checkServerTrusted(chain: Array[X509Certificate], authType: String): Unit = {}
|
def checkServerTrusted(chain: Array[X509Certificate],
|
||||||
|
authType: String): Unit = {}
|
||||||
|
|
||||||
def getAcceptedIssuers = null
|
def getAcceptedIssuers = null
|
||||||
}
|
}
|
||||||
@ -324,10 +382,9 @@ sealed trait UntrustedSslContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
implicit val clientSSLEngineProvider =
|
implicit val clientSSLEngineProvider =
|
||||||
ClientSSLEngineProvider {
|
ClientSSLEngineProvider { _ =>
|
||||||
_ =>
|
val engine = trustfulSslContext.createSSLEngine()
|
||||||
val engine = trustfulSslContext.createSSLEngine()
|
engine.setUseClientMode(true)
|
||||||
engine.setUseClientMode(true)
|
engine
|
||||||
engine
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
/**
|
/**
|
||||||
* OpenAPI Petstore
|
* 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.
|
* 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
|
* OpenAPI spec version: 1.0.0
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
* https://openapi-generator.tech
|
* https://openapi-generator.tech
|
||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
package org.openapitools.client.core
|
package org.openapitools.client.core
|
||||||
|
|
||||||
sealed trait ResponseState
|
sealed trait ResponseState
|
||||||
@ -22,44 +22,58 @@ object ResponseState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case class ApiRequest[U](
|
case class ApiRequest[U](
|
||||||
// required fields
|
// required fields
|
||||||
method: ApiMethod,
|
method: ApiMethod,
|
||||||
basePath: String,
|
basePath: String,
|
||||||
operationPath: String,
|
operationPath: String,
|
||||||
contentType: String,
|
contentType: String,
|
||||||
|
// optional fields
|
||||||
|
responses: Map[Int, (Manifest[_], ResponseState)] =
|
||||||
|
Map.empty,
|
||||||
|
bodyParam: Option[Any] = None,
|
||||||
|
formParams: Map[String, Any] = Map.empty,
|
||||||
|
pathParams: Map[String, Any] = Map.empty,
|
||||||
|
queryParams: Map[String, Any] = Map.empty,
|
||||||
|
headerParams: Map[String, Any] = Map.empty,
|
||||||
|
credentials: Seq[Credentials] = List.empty) {
|
||||||
|
|
||||||
// optional fields
|
def withCredentials(cred: Credentials): ApiRequest[U] =
|
||||||
responses: Map[Int, (Manifest[_], ResponseState)] = Map.empty,
|
copy[U](credentials = credentials :+ cred)
|
||||||
bodyParam: Option[Any] = None,
|
|
||||||
formParams: Map[String, Any] = Map.empty,
|
|
||||||
pathParams: Map[String, Any] = Map.empty,
|
|
||||||
queryParams: Map[String, Any] = Map.empty,
|
|
||||||
headerParams: Map[String, Any] = Map.empty,
|
|
||||||
credentials: Seq[Credentials] = List.empty) {
|
|
||||||
|
|
||||||
def withCredentials(cred: Credentials): ApiRequest[U] = copy[U](credentials = credentials :+ cred)
|
def withApiKey(key: ApiKeyValue,
|
||||||
|
keyName: String,
|
||||||
|
location: ApiKeyLocation): ApiRequest[U] =
|
||||||
|
withCredentials(ApiKeyCredentials(key, keyName, location))
|
||||||
|
|
||||||
def withApiKey(key: ApiKeyValue, keyName: String, location: ApiKeyLocation): ApiRequest[U] = withCredentials(ApiKeyCredentials(key, keyName, location))
|
def withSuccessResponse[T](code: Int)(
|
||||||
|
implicit m: Manifest[T]): ApiRequest[U] =
|
||||||
|
copy[U](responses = responses + (code -> (m, ResponseState.Success)))
|
||||||
|
|
||||||
def withSuccessResponse[T](code: Int)(implicit m: Manifest[T]): ApiRequest[U] = copy[U](responses = responses + (code -> (m, ResponseState.Success)))
|
def withErrorResponse[T](code: Int)(implicit m: Manifest[T]): ApiRequest[U] =
|
||||||
|
copy[U](responses = responses + (code -> (m, ResponseState.Error)))
|
||||||
|
|
||||||
def withErrorResponse[T](code: Int)(implicit m: Manifest[T]): ApiRequest[U] = copy[U](responses = responses + (code -> (m, ResponseState.Error)))
|
def withDefaultSuccessResponse[T](implicit m: Manifest[T]): ApiRequest[U] =
|
||||||
|
withSuccessResponse[T](0)
|
||||||
|
|
||||||
def withDefaultSuccessResponse[T](implicit m: Manifest[T]): ApiRequest[U] = withSuccessResponse[T](0)
|
def withDefaultErrorResponse[T](implicit m: Manifest[T]): ApiRequest[U] =
|
||||||
|
withErrorResponse[T](0)
|
||||||
|
|
||||||
def withDefaultErrorResponse[T](implicit m: Manifest[T]): ApiRequest[U] = withErrorResponse[T](0)
|
def responseForCode(statusCode: Int): Option[(Manifest[_], ResponseState)] =
|
||||||
|
responses.get(statusCode) orElse responses.get(0)
|
||||||
def responseForCode(statusCode: Int): Option[(Manifest[_], ResponseState)] = responses.get(statusCode) orElse responses.get(0)
|
|
||||||
|
|
||||||
def withoutBody(): ApiRequest[U] = copy[U](bodyParam = None)
|
def withoutBody(): ApiRequest[U] = copy[U](bodyParam = None)
|
||||||
|
|
||||||
def withBody(body: Any): ApiRequest[U] = copy[U](bodyParam = Some(body))
|
def withBody(body: Any): ApiRequest[U] = copy[U](bodyParam = Some(body))
|
||||||
|
|
||||||
def withFormParam(name: String, value: Any): ApiRequest[U] = copy[U](formParams = formParams + (name -> value))
|
def withFormParam(name: String, value: Any): ApiRequest[U] =
|
||||||
|
copy[U](formParams = formParams + (name -> value))
|
||||||
|
|
||||||
def withPathParam(name: String, value: Any): ApiRequest[U] = copy[U](pathParams = pathParams + (name -> value))
|
def withPathParam(name: String, value: Any): ApiRequest[U] =
|
||||||
|
copy[U](pathParams = pathParams + (name -> value))
|
||||||
|
|
||||||
def withQueryParam(name: String, value: Any): ApiRequest[U] = copy[U](queryParams = queryParams + (name -> value))
|
def withQueryParam(name: String, value: Any): ApiRequest[U] =
|
||||||
|
copy[U](queryParams = queryParams + (name -> value))
|
||||||
|
|
||||||
def withHeaderParam(name: String, value: Any): ApiRequest[U] = copy[U](headerParams = headerParams + (name -> value))
|
def withHeaderParam(name: String, value: Any): ApiRequest[U] =
|
||||||
|
copy[U](headerParams = headerParams + (name -> value))
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
/**
|
/**
|
||||||
* OpenAPI Petstore
|
* 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.
|
* 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
|
* OpenAPI spec version: 1.0.0
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
* https://openapi-generator.tech
|
* https://openapi-generator.tech
|
||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
package org.openapitools.client.core
|
package org.openapitools.client.core
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
@ -27,16 +27,23 @@ class ApiSettings(config: Config) extends Extension {
|
|||||||
private def cfg = config.getConfig("org.openapitools.client.apiRequest")
|
private def cfg = config.getConfig("org.openapitools.client.apiRequest")
|
||||||
|
|
||||||
val alwaysTrustCertificates: Boolean = cfg.getBoolean("trust-certificates")
|
val alwaysTrustCertificates: Boolean = cfg.getBoolean("trust-certificates")
|
||||||
val defaultHeaders: List[RawHeader] = cfg.getConfig("default-headers").entrySet.toList.map(c => RawHeader(c.getKey, c.getValue.render))
|
val defaultHeaders: List[RawHeader] = cfg
|
||||||
val connectionTimeout = FiniteDuration(cfg.getDuration("connection-timeout", TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS)
|
.getConfig("default-headers")
|
||||||
|
.entrySet
|
||||||
|
.toList
|
||||||
|
.map(c => RawHeader(c.getKey, c.getValue.render))
|
||||||
|
val connectionTimeout = FiniteDuration(
|
||||||
|
cfg.getDuration("connection-timeout", TimeUnit.MILLISECONDS),
|
||||||
|
TimeUnit.MILLISECONDS)
|
||||||
val compressionEnabled: Boolean = cfg.getBoolean("compression.enabled")
|
val compressionEnabled: Boolean = cfg.getBoolean("compression.enabled")
|
||||||
val compressionSizeThreshold: Int = cfg.getBytes("compression.size-threshold").toInt
|
val compressionSizeThreshold: Int =
|
||||||
val customCodes: List[CustomStatusCode] = cfg.getConfigList("custom-codes").toList.map { c =>
|
cfg.getBytes("compression.size-threshold").toInt
|
||||||
CustomStatusCode(
|
val customCodes: List[CustomStatusCode] =
|
||||||
c.getInt("code"),
|
cfg.getConfigList("custom-codes").toList.map { c =>
|
||||||
c.getString("reason"),
|
CustomStatusCode(c.getInt("code"),
|
||||||
c.getBoolean("success"))
|
c.getString("reason"),
|
||||||
}
|
c.getBoolean("success"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object ApiSettings extends ExtensionKey[ApiSettings]
|
object ApiSettings extends ExtensionKey[ApiSettings]
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
/**
|
/**
|
||||||
* OpenAPI Petstore
|
* 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.
|
* 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
|
* OpenAPI spec version: 1.0.0
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
* https://openapi-generator.tech
|
* https://openapi-generator.tech
|
||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
package org.openapitools.client.core
|
package org.openapitools.client.core
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -26,28 +26,42 @@ sealed trait ApiReturnWithHeaders {
|
|||||||
// workaround: return date time header in string instead of datetime object
|
// workaround: return date time header in string instead of datetime object
|
||||||
def getDateTimeHeader(name: String): Option[String] = header(name)
|
def getDateTimeHeader(name: String): Option[String] = header(name)
|
||||||
|
|
||||||
def getIntHeader(name: String): Option[Int] = castedHeader(name, java.lang.Integer.parseInt)
|
def getIntHeader(name: String): Option[Int] =
|
||||||
|
castedHeader(name, java.lang.Integer.parseInt)
|
||||||
|
|
||||||
def getLongHeader(name: String): Option[Long] = castedHeader(name, java.lang.Long.parseLong)
|
def getLongHeader(name: String): Option[Long] =
|
||||||
|
castedHeader(name, java.lang.Long.parseLong)
|
||||||
|
|
||||||
def getFloatHeader(name: String): Option[Float] = castedHeader(name, java.lang.Float.parseFloat)
|
def getFloatHeader(name: String): Option[Float] =
|
||||||
|
castedHeader(name, java.lang.Float.parseFloat)
|
||||||
|
|
||||||
def getDoubleHeader(name: String): Option[Double] = castedHeader(name, java.lang.Double.parseDouble)
|
def getDoubleHeader(name: String): Option[Double] =
|
||||||
|
castedHeader(name, java.lang.Double.parseDouble)
|
||||||
|
|
||||||
def getBooleanHeader(name: String): Option[Boolean] = castedHeader(name, java.lang.Boolean.parseBoolean)
|
def getBooleanHeader(name: String): Option[Boolean] =
|
||||||
|
castedHeader(name, java.lang.Boolean.parseBoolean)
|
||||||
|
|
||||||
private def castedHeader[U](name: String, conversion: String => U): Option[U] = {
|
private def castedHeader[U](name: String,
|
||||||
|
conversion: String => U): Option[U] = {
|
||||||
Try {
|
Try {
|
||||||
header(name).map(conversion)
|
header(name).map(conversion)
|
||||||
}.get
|
}.get
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed case class ApiResponse[T](code: Int, content: T, headers: Map[String, String] = Map.empty)
|
sealed case class ApiResponse[T](code: Int,
|
||||||
extends ApiReturnWithHeaders
|
content: T,
|
||||||
|
headers: Map[String, String] = Map.empty)
|
||||||
|
extends ApiReturnWithHeaders
|
||||||
|
|
||||||
sealed case class ApiError[T](code: Int, message: String, responseContent: Option[T], cause: Throwable = null, headers: Map[String, String] = Map.empty)
|
sealed case class ApiError[T](code: Int,
|
||||||
extends Throwable(s"($code) $message.${responseContent.map(s => s" Content : $s").getOrElse("")}", cause)
|
message: String,
|
||||||
|
responseContent: Option[T],
|
||||||
|
cause: Throwable = null,
|
||||||
|
headers: Map[String, String] = Map.empty)
|
||||||
|
extends Throwable(
|
||||||
|
s"($code) $message.${responseContent.map(s => s" Content : $s").getOrElse("")}",
|
||||||
|
cause)
|
||||||
with ApiReturnWithHeaders
|
with ApiReturnWithHeaders
|
||||||
|
|
||||||
sealed case class ApiMethod(value: String)
|
sealed case class ApiMethod(value: String)
|
||||||
@ -65,23 +79,27 @@ object ApiMethods {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This trait needs to be added to any model defined by the api.
|
* This trait needs to be added to any model defined by the api.
|
||||||
*/
|
*/
|
||||||
trait ApiModel
|
trait ApiModel
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Single trait defining a credential that can be transformed to a paramName / paramValue tupple
|
* Single trait defining a credential that can be transformed to a paramName / paramValue tupple
|
||||||
*/
|
*/
|
||||||
sealed trait Credentials {
|
sealed trait Credentials {
|
||||||
def asQueryParam: Option[(String, String)] = None
|
def asQueryParam: Option[(String, String)] = None
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed case class BasicCredentials(user: String, password: String) extends Credentials
|
sealed case class BasicCredentials(user: String, password: String)
|
||||||
|
extends Credentials
|
||||||
|
|
||||||
sealed case class ApiKeyCredentials(key: ApiKeyValue, keyName: String, location: ApiKeyLocation) extends Credentials {
|
sealed case class ApiKeyCredentials(key: ApiKeyValue,
|
||||||
|
keyName: String,
|
||||||
|
location: ApiKeyLocation)
|
||||||
|
extends Credentials {
|
||||||
override def asQueryParam: Option[(String, String)] = location match {
|
override def asQueryParam: Option[(String, String)] = location match {
|
||||||
case ApiKeyLocations.QUERY => Some((keyName, key.value))
|
case ApiKeyLocations.QUERY => Some((keyName, key.value))
|
||||||
case _ => None
|
case _ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,39 +115,40 @@ object ApiKeyLocations {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Case class used to unapply numeric values only in pattern matching
|
* Case class used to unapply numeric values only in pattern matching
|
||||||
*
|
*
|
||||||
* @param value the string representation of the numeric value
|
* @param value the string representation of the numeric value
|
||||||
*/
|
*/
|
||||||
sealed case class NumericValue(value: String) {
|
sealed case class NumericValue(value: String) {
|
||||||
override def toString: String = value
|
override def toString: String = value
|
||||||
}
|
}
|
||||||
|
|
||||||
object NumericValue {
|
object NumericValue {
|
||||||
def unapply(n: Any): Option[NumericValue] = n match {
|
def unapply(n: Any): Option[NumericValue] = n match {
|
||||||
case (_: Int | _: Long | _: Float | _: Double | _: Boolean | _: Byte) => Some(NumericValue(String.valueOf(n)))
|
case (_: Int | _: Long | _: Float | _: Double | _: Boolean | _: Byte) =>
|
||||||
|
Some(NumericValue(String.valueOf(n)))
|
||||||
case _ => None
|
case _ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used for params being arrays
|
* Used for params being arrays
|
||||||
*/
|
*/
|
||||||
sealed case class ArrayValues(values: Seq[Any], format: CollectionFormat = CollectionFormats.CSV)
|
sealed case class ArrayValues(values: Seq[Any],
|
||||||
|
format: CollectionFormat = CollectionFormats.CSV)
|
||||||
|
|
||||||
object ArrayValues {
|
object ArrayValues {
|
||||||
def apply(values: Option[Seq[Any]], format: CollectionFormat): ArrayValues =
|
def apply(values: Option[Seq[Any]], format: CollectionFormat): ArrayValues =
|
||||||
ArrayValues(values.getOrElse(Seq.empty), format)
|
ArrayValues(values.getOrElse(Seq.empty), format)
|
||||||
|
|
||||||
def apply(values: Option[Seq[Any]]): ArrayValues = ArrayValues(values, CollectionFormats.CSV)
|
def apply(values: Option[Seq[Any]]): ArrayValues =
|
||||||
|
ArrayValues(values, CollectionFormats.CSV)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines how arrays should be rendered in query strings.
|
* Defines how arrays should be rendered in query strings.
|
||||||
*/
|
*/
|
||||||
sealed trait CollectionFormat
|
sealed trait CollectionFormat
|
||||||
|
|
||||||
trait MergedArrayFormat extends CollectionFormat {
|
trait MergedArrayFormat extends CollectionFormat {
|
||||||
@ -161,33 +180,39 @@ object CollectionFormats {
|
|||||||
object ParametersMap {
|
object ParametersMap {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pimp parameters maps (Map[String, Any]) in order to transform them in a sequence of String -> Any tupples,
|
* Pimp parameters maps (Map[String, Any]) in order to transform them in a sequence of String -> Any tupples,
|
||||||
* with valid url-encoding, arrays handling, files preservation, ...
|
* with valid url-encoding, arrays handling, files preservation, ...
|
||||||
*/
|
*/
|
||||||
implicit class ParametersMapImprovements(val m: Map[String, Any]) {
|
implicit class ParametersMapImprovements(val m: Map[String, Any]) {
|
||||||
|
|
||||||
def asFormattedParamsList: List[(String, Any)] = m.toList.flatMap(formattedParams)
|
def asFormattedParamsList: List[(String, Any)] =
|
||||||
|
m.toList.flatMap(formattedParams)
|
||||||
|
|
||||||
def asFormattedParams: Map[String, Any] = m.flatMap(formattedParams)
|
def asFormattedParams: Map[String, Any] = m.flatMap(formattedParams)
|
||||||
|
|
||||||
private def urlEncode(v: Any) = URLEncoder.encode(String.valueOf(v), "utf-8").replaceAll("\\+", "%20")
|
private def urlEncode(v: Any) =
|
||||||
|
URLEncoder.encode(String.valueOf(v), "utf-8").replaceAll("\\+", "%20")
|
||||||
|
|
||||||
private def formattedParams(tuple: (String, Any)): Seq[(String, Any)] = formattedParams(tuple._1, tuple._2)
|
private def formattedParams(tuple: (String, Any)): Seq[(String, Any)] =
|
||||||
|
formattedParams(tuple._1, tuple._2)
|
||||||
|
|
||||||
private def formattedParams(name: String, value: Any): Seq[(String, Any)] = value match {
|
private def formattedParams(name: String, value: Any): Seq[(String, Any)] =
|
||||||
case arr: ArrayValues =>
|
value match {
|
||||||
arr.format match {
|
case arr: ArrayValues =>
|
||||||
case CollectionFormats.MULTI => arr.values.flatMap(formattedParams(name, _))
|
arr.format match {
|
||||||
case format: MergedArrayFormat => Seq((name, arr.values.mkString(format.separator)))
|
case CollectionFormats.MULTI =>
|
||||||
}
|
arr.values.flatMap(formattedParams(name, _))
|
||||||
case None => Seq.empty
|
case format: MergedArrayFormat =>
|
||||||
case Some(opt) => formattedParams(name, opt)
|
Seq((name, arr.values.mkString(format.separator)))
|
||||||
case s: Seq[Any] => formattedParams(name, ArrayValues(s))
|
}
|
||||||
case v: String => Seq((name, urlEncode(v)))
|
case None => Seq.empty
|
||||||
case NumericValue(v) => Seq((name, urlEncode(v)))
|
case Some(opt) => formattedParams(name, opt)
|
||||||
case f: File => Seq((name, f))
|
case s: Seq[Any] => formattedParams(name, ArrayValues(s))
|
||||||
case m: ApiModel => Seq((name, m))
|
case v: String => Seq((name, urlEncode(v)))
|
||||||
}
|
case NumericValue(v) => Seq((name, urlEncode(v)))
|
||||||
|
case f: File => Seq((name, f))
|
||||||
|
case m: ApiModel => Seq((name, m))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,22 @@
|
|||||||
/**
|
/**
|
||||||
* OpenAPI Petstore
|
* 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.
|
* 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
|
* OpenAPI spec version: 1.0.0
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
* https://openapi-generator.tech
|
* https://openapi-generator.tech
|
||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
package org.openapitools.client.model
|
package org.openapitools.client.model
|
||||||
|
|
||||||
import org.openapitools.client.core.ApiModel
|
import org.openapitools.client.core.ApiModel
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
case class ApiResponse (
|
case class ApiResponse(
|
||||||
code: Option[Int],
|
code: Option[Int],
|
||||||
`type`: Option[String],
|
`type`: Option[String],
|
||||||
message: Option[String]
|
message: Option[String]
|
||||||
) extends ApiModel
|
) extends ApiModel
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,23 +1,21 @@
|
|||||||
/**
|
/**
|
||||||
* OpenAPI Petstore
|
* 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.
|
* 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
|
* OpenAPI spec version: 1.0.0
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
* https://openapi-generator.tech
|
* https://openapi-generator.tech
|
||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
package org.openapitools.client.model
|
package org.openapitools.client.model
|
||||||
|
|
||||||
import org.openapitools.client.core.ApiModel
|
import org.openapitools.client.core.ApiModel
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
case class Category (
|
case class Category(
|
||||||
id: Option[Long],
|
id: Option[Long],
|
||||||
name: Option[String]
|
name: Option[String]
|
||||||
) extends ApiModel
|
) extends ApiModel
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,28 +1,28 @@
|
|||||||
/**
|
/**
|
||||||
* OpenAPI Petstore
|
* 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.
|
* 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
|
* OpenAPI spec version: 1.0.0
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
* https://openapi-generator.tech
|
* https://openapi-generator.tech
|
||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
package org.openapitools.client.model
|
package org.openapitools.client.model
|
||||||
|
|
||||||
import org.openapitools.client.core.ApiModel
|
import org.openapitools.client.core.ApiModel
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
case class Order (
|
case class Order(
|
||||||
id: Option[Long],
|
id: Option[Long],
|
||||||
petId: Option[Long],
|
petId: Option[Long],
|
||||||
quantity: Option[Int],
|
quantity: Option[Int],
|
||||||
shipDate: Option[DateTime],
|
shipDate: Option[DateTime],
|
||||||
/* Order Status */
|
/* Order Status */
|
||||||
status: Option[OrderEnums.Status],
|
status: Option[OrderEnums.Status],
|
||||||
complete: Option[Boolean]
|
complete: Option[Boolean]
|
||||||
) extends ApiModel
|
) extends ApiModel
|
||||||
|
|
||||||
object OrderEnums {
|
object OrderEnums {
|
||||||
@ -35,4 +35,3 @@ object OrderEnums {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,28 +1,28 @@
|
|||||||
/**
|
/**
|
||||||
* OpenAPI Petstore
|
* 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.
|
* 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
|
* OpenAPI spec version: 1.0.0
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
* https://openapi-generator.tech
|
* https://openapi-generator.tech
|
||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
package org.openapitools.client.model
|
package org.openapitools.client.model
|
||||||
|
|
||||||
import org.openapitools.client.core.ApiModel
|
import org.openapitools.client.core.ApiModel
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
case class Pet (
|
case class Pet(
|
||||||
id: Option[Long],
|
id: Option[Long],
|
||||||
category: Option[Category],
|
category: Option[Category],
|
||||||
name: String,
|
name: String,
|
||||||
photoUrls: Seq[String],
|
photoUrls: Seq[String],
|
||||||
tags: Option[Seq[Tag]],
|
tags: Option[Seq[Tag]],
|
||||||
/* pet status in the store */
|
/* pet status in the store */
|
||||||
status: Option[PetEnums.Status]
|
status: Option[PetEnums.Status]
|
||||||
) extends ApiModel
|
) extends ApiModel
|
||||||
|
|
||||||
object PetEnums {
|
object PetEnums {
|
||||||
@ -35,4 +35,3 @@ object PetEnums {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,23 +1,21 @@
|
|||||||
/**
|
/**
|
||||||
* OpenAPI Petstore
|
* 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.
|
* 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
|
* OpenAPI spec version: 1.0.0
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
* https://openapi-generator.tech
|
* https://openapi-generator.tech
|
||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
package org.openapitools.client.model
|
package org.openapitools.client.model
|
||||||
|
|
||||||
import org.openapitools.client.core.ApiModel
|
import org.openapitools.client.core.ApiModel
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
case class Tag (
|
case class Tag(
|
||||||
id: Option[Long],
|
id: Option[Long],
|
||||||
name: Option[String]
|
name: Option[String]
|
||||||
) extends ApiModel
|
) extends ApiModel
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,30 +1,28 @@
|
|||||||
/**
|
/**
|
||||||
* OpenAPI Petstore
|
* 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.
|
* 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
|
* OpenAPI spec version: 1.0.0
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
* https://openapi-generator.tech
|
* https://openapi-generator.tech
|
||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
package org.openapitools.client.model
|
package org.openapitools.client.model
|
||||||
|
|
||||||
import org.openapitools.client.core.ApiModel
|
import org.openapitools.client.core.ApiModel
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
case class User (
|
case class User(
|
||||||
id: Option[Long],
|
id: Option[Long],
|
||||||
username: Option[String],
|
username: Option[String],
|
||||||
firstName: Option[String],
|
firstName: Option[String],
|
||||||
lastName: Option[String],
|
lastName: Option[String],
|
||||||
email: Option[String],
|
email: Option[String],
|
||||||
password: Option[String],
|
password: Option[String],
|
||||||
phone: Option[String],
|
phone: Option[String],
|
||||||
/* User Status */
|
/* User Status */
|
||||||
userStatus: Option[Int]
|
userStatus: Option[Int]
|
||||||
) extends ApiModel
|
) extends ApiModel
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user