|
| 1 | +/** |
| 2 | + * OpenAPI Petstore |
| 3 | + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. |
| 4 | + * |
| 5 | + * The version of the OpenAPI document: 1.0.0 |
| 6 | + * |
| 7 | + * |
| 8 | + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). |
| 9 | + * https://openapi-generator.tech |
| 10 | + * Do not edit the class manually. |
| 11 | + */ |
| 12 | +package org.openapitools.client.api |
| 13 | + |
| 14 | +import org.openapitools.client.model.ApiResponse |
| 15 | +import java.io.File |
| 16 | +import org.openapitools.client.model.Pet |
| 17 | +import org.openapitools.client.core.JsonSupport._ |
| 18 | +import sttp.client4._ |
| 19 | +import sttp.model.Method |
| 20 | + |
| 21 | +object PetApi { |
| 22 | + def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new PetApi(baseUrl) |
| 23 | +} |
| 24 | + |
| 25 | +class PetApi(baseUrl: String) { |
| 26 | + |
| 27 | + /** |
| 28 | + * |
| 29 | + * |
| 30 | + * Expected answers: |
| 31 | + * code 200 : Pet (successful operation) |
| 32 | + * code 405 : (Invalid input) |
| 33 | + * |
| 34 | + * @param pet Pet object that needs to be added to the store |
| 35 | + */ |
| 36 | + def addPet(pet: Pet): Request[Either[ResponseException[String], Pet]] = |
| 37 | + basicRequest |
| 38 | + .method(Method.POST, uri"$baseUrl/pet") |
| 39 | + .contentType("application/json") |
| 40 | + .body(asJson(pet)) |
| 41 | + .response(asJson[Pet]) |
| 42 | + |
| 43 | + /** |
| 44 | + * |
| 45 | + * |
| 46 | + * Expected answers: |
| 47 | + * code 400 : (Invalid pet value) |
| 48 | + * |
| 49 | + * @param petId Pet id to delete |
| 50 | + * @param apiKey |
| 51 | + */ |
| 52 | + def deletePet(petId: Long, apiKey: Option[String] = None): Request[Either[ResponseException[String], Unit]] = |
| 53 | + basicRequest |
| 54 | + .method(Method.DELETE, uri"$baseUrl/pet/${petId}") |
| 55 | + .contentType("application/json") |
| 56 | + .header("api_key", apiKey) |
| 57 | + .response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(())))) |
| 58 | + |
| 59 | + /** |
| 60 | + * Multiple status values can be provided with comma separated strings |
| 61 | + * |
| 62 | + * Expected answers: |
| 63 | + * code 200 : Seq[Pet] (successful operation) |
| 64 | + * code 400 : (Invalid status value) |
| 65 | + * |
| 66 | + * @param status Status values that need to be considered for filter |
| 67 | + */ |
| 68 | + def findPetsByStatus(status: Seq[String] = Seq.empty): Request[Either[ResponseException[String], Seq[Pet]]] = |
| 69 | + basicRequest |
| 70 | + .method(Method.GET, uri"$baseUrl/pet/findByStatus?status=${ status }") |
| 71 | + .contentType("application/json") |
| 72 | + .response(asJson[Seq[Pet]]) |
| 73 | + |
| 74 | + /** |
| 75 | + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. |
| 76 | + * |
| 77 | + * Expected answers: |
| 78 | + * code 200 : Seq[Pet] (successful operation) |
| 79 | + * code 400 : (Invalid tag value) |
| 80 | + * |
| 81 | + * @param tags Tags to filter by |
| 82 | + */ |
| 83 | + def findPetsByTags(tags: Seq[String] = Seq.empty): Request[Either[ResponseException[String], Seq[Pet]]] = |
| 84 | + basicRequest |
| 85 | + .method(Method.GET, uri"$baseUrl/pet/findByTags?tags=${ tags }") |
| 86 | + .contentType("application/json") |
| 87 | + .response(asJson[Seq[Pet]]) |
| 88 | + |
| 89 | + /** |
| 90 | + * Returns a single pet |
| 91 | + * |
| 92 | + * Expected answers: |
| 93 | + * code 200 : Pet (successful operation) |
| 94 | + * code 400 : (Invalid ID supplied) |
| 95 | + * code 404 : (Pet not found) |
| 96 | + * |
| 97 | + * Available security schemes: |
| 98 | + * api_key (apiKey) |
| 99 | + * |
| 100 | + * @param petId ID of pet to return |
| 101 | + */ |
| 102 | + def getPetById(apiKeyHeader: String)(petId: Long): Request[Either[ResponseException[String], Pet]] = |
| 103 | + basicRequest |
| 104 | + .method(Method.GET, uri"$baseUrl/pet/${petId}") |
| 105 | + .contentType("application/json") |
| 106 | + .header("api_key", apiKeyHeader) |
| 107 | + .response(asJson[Pet]) |
| 108 | + |
| 109 | + /** |
| 110 | + * |
| 111 | + * |
| 112 | + * Expected answers: |
| 113 | + * code 200 : Pet (successful operation) |
| 114 | + * code 400 : (Invalid ID supplied) |
| 115 | + * code 404 : (Pet not found) |
| 116 | + * code 405 : (Validation exception) |
| 117 | + * |
| 118 | + * @param pet Pet object that needs to be added to the store |
| 119 | + */ |
| 120 | + def updatePet(pet: Pet): Request[Either[ResponseException[String], Pet]] = |
| 121 | + basicRequest |
| 122 | + .method(Method.PUT, uri"$baseUrl/pet") |
| 123 | + .contentType("application/json") |
| 124 | + .body(asJson(pet)) |
| 125 | + .response(asJson[Pet]) |
| 126 | + |
| 127 | + /** |
| 128 | + * |
| 129 | + * |
| 130 | + * Expected answers: |
| 131 | + * code 405 : (Invalid input) |
| 132 | + * |
| 133 | + * @param petId ID of pet that needs to be updated |
| 134 | + * @param name Updated name of the pet |
| 135 | + * @param status Updated status of the pet |
| 136 | + */ |
| 137 | + def updatePetWithForm(petId: Long, name: Option[String] = None, status: Option[String] = None): Request[Either[ResponseException[String], Unit]] = |
| 138 | + basicRequest |
| 139 | + .method(Method.POST, uri"$baseUrl/pet/${petId}") |
| 140 | + .contentType("application/x-www-form-urlencoded") |
| 141 | + .body(Map( |
| 142 | + "name" -> name, |
| 143 | + "status" -> status |
| 144 | + )) |
| 145 | + .response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(())))) |
| 146 | + |
| 147 | + /** |
| 148 | + * |
| 149 | + * |
| 150 | + * Expected answers: |
| 151 | + * code 200 : ApiResponse (successful operation) |
| 152 | + * |
| 153 | + * @param petId ID of pet to update |
| 154 | + * @param additionalMetadata Additional data to pass to server |
| 155 | + * @param file file to upload |
| 156 | + */ |
| 157 | + def uploadFile(petId: Long, additionalMetadata: Option[String] = None, file: Option[File] = None): Request[Either[ResponseException[String], ApiResponse]] = |
| 158 | + basicRequest |
| 159 | + .method(Method.POST, uri"$baseUrl/pet/${petId}/uploadImage") |
| 160 | + .contentType("multipart/form-data") |
| 161 | + .multipartBody(Seq( |
| 162 | + additionalMetadata.map(multipart("additionalMetadata", _)) |
| 163 | +, |
| 164 | + file.map(multipartFile("file", _)) |
| 165 | + |
| 166 | + ).flatten) |
| 167 | + .response(asJson[ApiResponse]) |
| 168 | + |
| 169 | +} |
0 commit comments