Open
requested to merge github/fork/galeries-lafayette/feature/kotlin-spring_responseentity into master
Created by: frecco75
This PR adds ResponseEntity
option (inspired by the spring generator).
By default the generator (before this PR) generates code with 200 return code.
Given this schema
openapi: "3.0.1"
info:
version: 1.0.0
title: Users
paths:
/users/{userId}:
get:
parameters:
- in: path
name: userId
required: true
schema:
type: string
responses:
200:
description: user found
content:
application/json:
schema:
$ref: '#/components/schemas/User'
404:
description: user not found
components:
schemas:
User:
type: object
required:
- name
properties:
name:
type: string
It generates by default this code
fun usersUserIdGet(@ApiParam(value = "", required=true) @PathVariable("userId") userId: kotlin.String
): ResponseEntity<User> {
return ResponseEntity(service.usersUserIdGet(userId), HttpStatus.valueOf(200))
}
which doesn't respect the schema response code when user isn't found.
Providing the option responseEntity=true
it generates
fun usersUserIdGet(@ApiParam(value = "", required=true) @PathVariable("userId") userId: kotlin.String
): ResponseEntity<User> {
return service.usersUserIdGet(userId)
}
and for the service
interface UsersApiService {
fun usersUserIdGet(userId: kotlin.String): ResponseEntity<User>
}
so the developer can provide custom behaviour and provide status code, headers etc.. in the response