Skip to content

Regression since 3.0.2: default: null is now explicitly generated for parameters/schemas without a default value, breaking Swagger UI "Example Value" #3308

Description

@mgierw

Describe the bug

After upgrading from springdoc-openapi-starter-webmvc-ui 3.0.1 to 3.0.2 (and confirmed still present in 3.0.3), every parameter and schema property that does not have an explicit default value now gets an explicit "default": null written into the generated OpenAPI spec (/v3/api-docs), instead of the default field being omitted as before.

This appears to be a side effect of #3198 ("Property resolution for parameter default values"), which was merged into 3.0.2.

The most visible symptom: for endpoints with a request body, Swagger UI's "Example Value" tab now renders a literal null instead of a populated JSON example object.

To Reproduce

Steps to reproduce the behavior:

  • Spring Boot version: 4.1.0
  • springdoc-openapi version: 3.0.3 (bug also present in 3.0.2; confirmed not present in 3.0.1)

Minimal reproduction (adjust to your own header parameter / DTO if you can't share the original):

@Operation(
    parameters = {
        @Parameter(
            name = "X-Request-Signature",
            in = ParameterIn.HEADER,
            required = true,
            style = ParameterStyle.SIMPLE,
            explode = false,
            schema = @Schema(type = "string", format = "hex")
        )
    }
)
@PostMapping("/example")
public ResponseEntity<Void> example(@RequestBody SomeDto body) {
    ...
}

Expected behavior

When no default value is set on a parameter/schema, the default field should be omitted from the generated OpenAPI document (as it was in 3.0.1 and earlier), not written out as default: null.

Actual behavior

Generated /v3/api-docs output, comparing 3.0.1 vs 3.0.2/3.0.3 for the same code, no changes on our side:

3.0.1 (correct):

X-Request-Signature:
  name: X-Request-Signature
  in: header
  required: true
  style: simple
  explode: false
  schema:
    type: string
    format: hex

3.0.2 / 3.0.3 (regression):

X-Request-Signature:
  name: X-Request-Signature
  in: header
  required: true
  style: simple
  explode: false
  schema:
    type: string
    format: hex
    default: null

This default: null is added consistently across the whole generated spec, not just for this one parameter.

Impact

In Swagger UI, for endpoints with a request body, the "Example Value" tab renders null instead of a structured JSON example of the request body schema — presumably because the example-generation logic is affected by the now-present (but meaningless) default: null entries throughout the schema tree. This makes it impossible for API consumers to see a usable example payload in the UI.

Versions

  • springdoc-openapi: 3.0.3 (bug present since 3.0.2; not present in 3.0.1)
  • Spring Boot: 4.1.0
  • Confirmed cause narrowed down via bisection: downgrading only springdoc-openapi-starter-webmvc-ui from 3.0.3 → 3.0.1 (no other changes) resolves both the default: null entries (including for the header parameter shown above) and the Swagger UI "Example Value: null" issue.

Additional context

Suspected root cause: #3198 changed how default values for parameters are resolved (to support property placeholder resolution, e.g. ${some.property}), and appears to have introduced a regression where an unset default is now serialized as an explicit null instead of being omitted.

Happy to provide more of our OpenAPI config or a minimal standalone reproduction project if useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions