Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !10373

[kotlin-spring] ResponseEntity option

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Administrator requested to merge github/fork/galeries-lafayette/feature/kotlin-spring_responseentity into master Sep 10, 2021
  • Overview 0
  • Commits 2
  • Pipelines 1
  • Changes 46

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

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/galeries-lafayette/feature/kotlin-spring_responseentity