Skip to content

Commit

Permalink
Kotlin-Spring template fixes/improvements (OpenAPITools#3007)
Browse files Browse the repository at this point in the history
* Fixed case where invalid comma is added to consumes/produces list in case last element is empty.

* Changed default HttpStatus.OK response to match first response code in definition.
Allowing also other responses 201, 202 ...

* Changed default HttpStatus.OK response to match first response code in definition.
Allowing also other responses 201, 202 ...

* run ./bin/kotlin-springboot-petstore-server.sh
Updated APIs
  • Loading branch information
drejc authored and wing328 committed Jun 3, 2019
1 parent 6ff0512 commit caac76c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class {{classname}}Controller({{#serviceInterface}}@Autowired(required = true) v
value = ["{{#lambda.escapeDoubleQuote}}{{path}}{{/lambda.escapeDoubleQuote}}"],{{#singleContentTypes}}{{#hasProduces}}
produces = "{{{vendorExtensions.x-accepts}}}",{{/hasProduces}}{{#hasConsumes}}
consumes = "{{{vendorExtensions.x-contentType}}}",{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}}
produces = [{{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}}], {{/hasProduces}}{{#hasConsumes}}
consumes = [{{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}],{{/hasConsumes}}{{/singleContentTypes}}
produces = [{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}], {{/hasProduces}}{{#hasConsumes}}
consumes = [{{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}],{{/hasConsumes}}{{/singleContentTypes}}
method = [RequestMethod.{{httpMethod}}])
{{#reactive}}{{^isListContainer}}suspend {{/isListContainer}}{{/reactive}}fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}): ResponseEntity<{{>returnTypes}}> {
return {{>returnValue}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#serviceInterface}}ResponseEntity(service.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}), HttpStatus.OK){{/serviceInterface}}{{^serviceInterface}}ResponseEntity(HttpStatus.NOT_IMPLEMENTED){{/serviceInterface}}
{{#serviceInterface}}ResponseEntity(service.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}), {{#responses}}{{#-first}}HttpStatus.valueOf({{code}}){{/-first}}{{/responses}}){{/serviceInterface}}{{^serviceInterface}}ResponseEntity(HttpStatus.NOT_IMPLEMENTED){{/serviceInterface}}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
method = [RequestMethod.POST])
fun addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody body: Pet
): ResponseEntity<Unit> {
return ResponseEntity(service.addPet(body), HttpStatus.OK)
return ResponseEntity(service.addPet(body), HttpStatus.valueOf(405))
}

@ApiOperation(
Expand All @@ -72,7 +72,7 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
fun deletePet(@ApiParam(value = "Pet id to delete", required=true) @PathVariable("petId") petId: Long
,@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) apiKey: String?
): ResponseEntity<Unit> {
return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.OK)
return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400))
}

@ApiOperation(
Expand All @@ -90,7 +90,7 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
method = [RequestMethod.GET])
fun findPetsByStatus(@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: List<String>
): ResponseEntity<List<Pet>> {
return ResponseEntity(service.findPetsByStatus(status), HttpStatus.OK)
return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200))
}

@ApiOperation(
Expand All @@ -108,7 +108,7 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
method = [RequestMethod.GET])
fun findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: List<String>
): ResponseEntity<List<Pet>> {
return ResponseEntity(service.findPetsByTags(tags), HttpStatus.OK)
return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200))
}

@ApiOperation(
Expand All @@ -125,7 +125,7 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
method = [RequestMethod.GET])
fun getPetById(@ApiParam(value = "ID of pet to return", required=true) @PathVariable("petId") petId: Long
): ResponseEntity<Pet> {
return ResponseEntity(service.getPetById(petId), HttpStatus.OK)
return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200))
}

@ApiOperation(
Expand All @@ -141,7 +141,7 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
method = [RequestMethod.PUT])
fun updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody body: Pet
): ResponseEntity<Unit> {
return ResponseEntity(service.updatePet(body), HttpStatus.OK)
return ResponseEntity(service.updatePet(body), HttpStatus.valueOf(400))
}

@ApiOperation(
Expand All @@ -159,7 +159,7 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
,@ApiParam(value = "Updated name of the pet") @RequestParam(value="name", required=false) name: String?
,@ApiParam(value = "Updated status of the pet") @RequestParam(value="status", required=false) status: String?
): ResponseEntity<Unit> {
return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.OK)
return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405))
}

@ApiOperation(
Expand All @@ -179,6 +179,6 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
,@ApiParam(value = "Additional data to pass to server") @RequestParam(value="additionalMetadata", required=false) additionalMetadata: String?
,@ApiParam(value = "file detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource?
): ResponseEntity<ModelApiResponse> {
return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.OK)
return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic
method = [RequestMethod.DELETE])
fun deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted", required=true) @PathVariable("orderId") orderId: String
): ResponseEntity<Unit> {
return ResponseEntity(service.deleteOrder(orderId), HttpStatus.OK)
return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400))
}

@ApiOperation(
Expand All @@ -70,7 +70,7 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic
produces = ["application/json"],
method = [RequestMethod.GET])
fun getInventory(): ResponseEntity<Map<String, Int>> {
return ResponseEntity(service.getInventory(), HttpStatus.OK)
return ResponseEntity(service.getInventory(), HttpStatus.valueOf(200))
}

@ApiOperation(
Expand All @@ -86,7 +86,7 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic
method = [RequestMethod.GET])
fun getOrderById(@Min(1L) @Max(5L) @ApiParam(value = "ID of pet that needs to be fetched", required=true) @PathVariable("orderId") orderId: Long
): ResponseEntity<Order> {
return ResponseEntity(service.getOrderById(orderId), HttpStatus.OK)
return ResponseEntity(service.getOrderById(orderId), HttpStatus.valueOf(200))
}

@ApiOperation(
Expand All @@ -102,6 +102,6 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic
method = [RequestMethod.POST])
fun placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody body: Order
): ResponseEntity<Order> {
return ResponseEntity(service.placeOrder(body), HttpStatus.OK)
return ResponseEntity(service.placeOrder(body), HttpStatus.valueOf(200))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
method = [RequestMethod.POST])
fun createUser(@ApiParam(value = "Created user object" ,required=true ) @Valid @RequestBody body: User
): ResponseEntity<Unit> {
return ResponseEntity(service.createUser(body), HttpStatus.OK)
return ResponseEntity(service.createUser(body), HttpStatus.valueOf(200))
}

@ApiOperation(
Expand All @@ -67,7 +67,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
method = [RequestMethod.POST])
fun createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody body: List<User>
): ResponseEntity<Unit> {
return ResponseEntity(service.createUsersWithArrayInput(body), HttpStatus.OK)
return ResponseEntity(service.createUsersWithArrayInput(body), HttpStatus.valueOf(200))
}

@ApiOperation(
Expand All @@ -81,7 +81,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
method = [RequestMethod.POST])
fun createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody body: List<User>
): ResponseEntity<Unit> {
return ResponseEntity(service.createUsersWithListInput(body), HttpStatus.OK)
return ResponseEntity(service.createUsersWithListInput(body), HttpStatus.valueOf(200))
}

@ApiOperation(
Expand All @@ -95,7 +95,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
method = [RequestMethod.DELETE])
fun deleteUser(@ApiParam(value = "The name that needs to be deleted", required=true) @PathVariable("username") username: String
): ResponseEntity<Unit> {
return ResponseEntity(service.deleteUser(username), HttpStatus.OK)
return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400))
}

@ApiOperation(
Expand All @@ -111,7 +111,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
method = [RequestMethod.GET])
fun getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing.", required=true) @PathVariable("username") username: String
): ResponseEntity<User> {
return ResponseEntity(service.getUserByName(username), HttpStatus.OK)
return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200))
}

@ApiOperation(
Expand All @@ -128,7 +128,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
fun loginUser(@NotNull @ApiParam(value = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: String
,@NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: String
): ResponseEntity<String> {
return ResponseEntity(service.loginUser(username, password), HttpStatus.OK)
return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200))
}

@ApiOperation(
Expand All @@ -141,7 +141,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
value = ["/user/logout"],
method = [RequestMethod.GET])
fun logoutUser(): ResponseEntity<Unit> {
return ResponseEntity(service.logoutUser(), HttpStatus.OK)
return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200))
}

@ApiOperation(
Expand All @@ -156,6 +156,6 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
fun updateUser(@ApiParam(value = "name that need to be deleted", required=true) @PathVariable("username") username: String
,@ApiParam(value = "Updated user object" ,required=true ) @Valid @RequestBody body: User
): ResponseEntity<Unit> {
return ResponseEntity(service.updateUser(username, body), HttpStatus.OK)
return ResponseEntity(service.updateUser(username, body), HttpStatus.valueOf(400))
}
}

0 comments on commit caac76c

Please sign in to comment.