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
  • Issues
  • #1106
Closed
Open
Issue created Sep 25, 2018 by Administrator@rootContributor

[KOTLIN][SPRING] Better Handling of Optional/Default Types

Created by: dr4ke616

Description

Few very minor bugs around how default values and required fields are handled in requestBodys and parameters. In particular in correct use of nullable types (?).

  • Request bodies are not respecting the required field when provided. Therefore types are not being correctly set as null-able in controller method signatures.
requestBodies:
  MetaInfoBody:
    required: true  # no matter if set to true or false
    content:
      application/json:
        schema:
          $ref: "#/components/schemas/MetaInfo"

The above definition yields the below code no matter if required is set to true of false.

bodiesPost(@RequestBody metaInfo: MetaInfo)
  • Request parameters that have default values, the types remain null-able. For example, a request parameter such as the following, which has required false but has a default value, still set the types in the RequestParam as null-able.
components:
  parameters:
    Limit:
      name: "limit"
      in: query
      required: false  # required is false, but has a default
      schema:
        type: "integer"
        minimum: 1
        maximum: 50
        default: 10

The above definition would yields:

@RequestParam(value = "limit", required = false, defaultValue = "10") limit: Int?  // <-- still null-able
openapi-generator version

Latest release - org.openapitools:openapi-generator:2.3.2

Assignee
Assign to
Time tracking