forked from loafle/openapi-generator-original
[kotlin-spring] add support for the delegate pattern (#3925)
* #2526 support the delegate pattern for kotlin-spring * fix the diamond * update the doc * fix ci * use Resource? instead of MultipartFile when dealing with files * bump after rebase on master
This commit is contained in:
committed by
William Cheng
parent
8ca1788a75
commit
964260101b
@@ -0,0 +1,19 @@
|
||||
package org.openapitools.api
|
||||
|
||||
import org.springframework.web.context.request.NativeWebRequest
|
||||
|
||||
import javax.servlet.http.HttpServletResponse
|
||||
import java.io.IOException
|
||||
|
||||
object ApiUtil {
|
||||
fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) {
|
||||
try {
|
||||
val res = req.getNativeResponse(HttpServletResponse::class.java)
|
||||
res.setCharacterEncoding("UTF-8")
|
||||
res.addHeader("Content-Type", contentType)
|
||||
res.getWriter().print(example)
|
||||
} catch (e: IOException) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package org.openapitools.api
|
||||
|
||||
import org.openapitools.model.ModelApiResponse
|
||||
import org.openapitools.model.Pet
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
import org.springframework.http.ResponseEntity
|
||||
|
||||
class PetApiTest {
|
||||
|
||||
private val service: PetApiService = PetApiServiceImpl()
|
||||
private val api: PetApiController = PetApiController(service)
|
||||
|
||||
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*
|
||||
*
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun addPetTest() {
|
||||
val pet:Pet? = null
|
||||
val response: ResponseEntity<Unit> = api.addPet(pet!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a pet
|
||||
*
|
||||
*
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun deletePetTest() {
|
||||
val petId:kotlin.Long? = null
|
||||
val apiKey:kotlin.String? = null
|
||||
val response: ResponseEntity<Unit> = api.deletePet(petId!!, apiKey!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds Pets by status
|
||||
*
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun findPetsByStatusTest() {
|
||||
val status:kotlin.collections.List<kotlin.String>? = null
|
||||
val response: ResponseEntity<List<Pet>> = api.findPetsByStatus(status!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds Pets by tags
|
||||
*
|
||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun findPetsByTagsTest() {
|
||||
val tags:kotlin.collections.List<kotlin.String>? = null
|
||||
val response: ResponseEntity<List<Pet>> = api.findPetsByTags(tags!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* Find pet by ID
|
||||
*
|
||||
* Returns a single pet
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun getPetByIdTest() {
|
||||
val petId:kotlin.Long? = null
|
||||
val response: ResponseEntity<Pet> = api.getPetById(petId!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing pet
|
||||
*
|
||||
*
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun updatePetTest() {
|
||||
val pet:Pet? = null
|
||||
val response: ResponseEntity<Unit> = api.updatePet(pet!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a pet in the store with form data
|
||||
*
|
||||
*
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun updatePetWithFormTest() {
|
||||
val petId:kotlin.Long? = null
|
||||
val name:kotlin.String? = null
|
||||
val status:kotlin.String? = null
|
||||
val response: ResponseEntity<Unit> = api.updatePetWithForm(petId!!, name!!, status!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads an image
|
||||
*
|
||||
*
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun uploadFileTest() {
|
||||
val petId:kotlin.Long? = null
|
||||
val additionalMetadata:kotlin.String? = null
|
||||
val file:org.springframework.core.io.Resource? = null
|
||||
val response: ResponseEntity<ModelApiResponse> = api.uploadFile(petId!!, additionalMetadata!!, file!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package org.openapitools.api
|
||||
|
||||
import org.openapitools.model.Order
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
import org.springframework.http.ResponseEntity
|
||||
|
||||
class StoreApiTest {
|
||||
|
||||
private val service: StoreApiService = StoreApiServiceImpl()
|
||||
private val api: StoreApiController = StoreApiController(service)
|
||||
|
||||
|
||||
/**
|
||||
* Delete purchase order by ID
|
||||
*
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun deleteOrderTest() {
|
||||
val orderId:kotlin.String? = null
|
||||
val response: ResponseEntity<Unit> = api.deleteOrder(orderId!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns pet inventories by status
|
||||
*
|
||||
* Returns a map of status codes to quantities
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun getInventoryTest() {
|
||||
val response: ResponseEntity<Map<String, kotlin.Int>> = api.getInventory()
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* Find purchase order by ID
|
||||
*
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun getOrderByIdTest() {
|
||||
val orderId:kotlin.Long? = null
|
||||
val response: ResponseEntity<Order> = api.getOrderById(orderId!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*
|
||||
*
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun placeOrderTest() {
|
||||
val order:Order? = null
|
||||
val response: ResponseEntity<Order> = api.placeOrder(order!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package org.openapitools.api
|
||||
|
||||
import org.openapitools.model.User
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
import org.springframework.http.ResponseEntity
|
||||
|
||||
class UserApiTest {
|
||||
|
||||
private val service: UserApiService = UserApiServiceImpl()
|
||||
private val api: UserApiController = UserApiController(service)
|
||||
|
||||
|
||||
/**
|
||||
* Create user
|
||||
*
|
||||
* This can only be done by the logged in user.
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun createUserTest() {
|
||||
val user:User? = null
|
||||
val response: ResponseEntity<Unit> = api.createUser(user!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
*
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun createUsersWithArrayInputTest() {
|
||||
val user:kotlin.collections.List<User>? = null
|
||||
val response: ResponseEntity<Unit> = api.createUsersWithArrayInput(user!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
*
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun createUsersWithListInputTest() {
|
||||
val user:kotlin.collections.List<User>? = null
|
||||
val response: ResponseEntity<Unit> = api.createUsersWithListInput(user!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user
|
||||
*
|
||||
* This can only be done by the logged in user.
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun deleteUserTest() {
|
||||
val username:kotlin.String? = null
|
||||
val response: ResponseEntity<Unit> = api.deleteUser(username!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user by user name
|
||||
*
|
||||
*
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun getUserByNameTest() {
|
||||
val username:kotlin.String? = null
|
||||
val response: ResponseEntity<User> = api.getUserByName(username!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs user into the system
|
||||
*
|
||||
*
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun loginUserTest() {
|
||||
val username:kotlin.String? = null
|
||||
val password:kotlin.String? = null
|
||||
val response: ResponseEntity<kotlin.String> = api.loginUser(username!!, password!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*
|
||||
*
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun logoutUserTest() {
|
||||
val response: ResponseEntity<Unit> = api.logoutUser()
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
/**
|
||||
* Updated user
|
||||
*
|
||||
* This can only be done by the logged in user.
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun updateUserTest() {
|
||||
val username:kotlin.String? = null
|
||||
val user:User? = null
|
||||
val response: ResponseEntity<Unit> = api.updateUser(username!!, user!!)
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user