Skip to content

support for nullable fields for OpenAPI31 #3138

@zdary

Description

@zdary

Is your feature request related to a problem? Please describe.
the generated openapi doesn't include nullable and required fields properly when annotated for OpenAPI31.

  • terminology

nullable: Controls whether a field's value can be null (i.e., the JSON value can be null) DataRestDelegatingMethodParameterCustomizer.java:323-325

requiredMode = NOT_REQUIRED: Controls whether the field must be present in the request/response (i.e., whether the field key must exist in the JSON) SchemaUtils.java:134-136

  • A clear and concise description of what the problem is. Ex. I'm always frustrated
    example DTO
@Nullable
  @Schema(
    nullable = true, 
    requiredMode = RequiredMode.NOT_REQUIRED
  )
  private String field;

The library does not currently set nullable = true or use type arrays like type: ["string", "null"] for nullable fields in OpenAPI 3.1, even when you explicitly use @Schema(nullable = true) or @Nullable.
The OpenAPI 3.1 specification supports type arrays for nullable fields (e.g., type: ["string", "null"]), but springdoc-openapi doesn't currently generate them automatically. The library only explicitly sets nullable = false for non-nullable fields when validation annotations are present, and doesn't add any nullable indicators for fields that can be null.

requiredMode doesn't do anything either.

Describe the solution you'd like

generate the nullable section
OpenAPI 3.0 approach:

{  
  "type": "string",  
  "nullable": true  
}

OpenAPI 3.1.0 approach:

{  
  "type": ["string", "null"]  
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions