Skip to content

[Bug]: Issues using @Nullable annotations in OpenAPI 3.1 schemata #5077

@pmerschmann

Description

@pmerschmann

Description of the problem/issue

The created OpenApiSpec for nullable objects is not correct.

The nullable annotations do not work proper on objects using OpenApi 3.1 schemata, but only on simple attributes (e.g. strings). With the support for nullable and @Nullable annotations within #5001 and #4555 this issue should have been solved, but wasn't.

Affected Version

2.2.44

Earliest version the bug appears in (if known):
2.2.44

Steps to Reproduce

Code to reproduce can be found here:

Simply start the application and check the api under http://localhost:9090/v3/api-docs (for json formatted) or under http://localhost:9090/swagger-ui/index.html for visual appearance via swagger.

Actual Behavior

For simple objects (like Strings) everything seems to work out just fine:

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

For lists it can be argued that it is correct as well, as the list itself can be null and any of the contained items as well in my example. Was unexpected for me at first honestly, but can be accepted. Yet the question come to my mind: can we somehow manage that the type can be array or null, but the items themselves are non-nullable?

"listOfString": {
            "type": ["array", "null"],
            "items": {
              "type": ["string", "null"]
            }
          }

For custom classes things break, as the type is not recognized as object, but as null and only as null.

"foo": {
  "$ref": "#/components/schemas/Foo"
},

"Foo": {
        "type": "null",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
}

Logs / Stack Traces

Additional Context

Checklist

  • I have searched the existing issues and this is not a duplicate.
  • I have provided sufficient information for maintainers to reproduce the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    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