Skip to content

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

@dr4ke616

Description

@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions