Skip to content

OpenAPI schema object null type #3709

@Korbeil

Description

@Korbeil

API Platform version(s) affected: v2.5.4

Description
When we generate an OpenAPI schema from our API, if we have a nullable field, it does add it as an array as following:

{
  "Object": {
    "properties": {
      "foo": {"type": ["string", "null"]}
    }
  }
}

Actually, this is totaly wrong. According to the OpenApi v3.0.3 (last OpenApi version):

type - Value MUST be a string. Multiple types via an array are not supported.

(see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#schemaObject for more details)

To handle nullable fields we should use the nullable field which is a boolean.

I don't know what introduced this bug, but this was working fine before, something added this behavior recently.
Since we have some OpenAPI parser behind our schema, I can't export my API anymore since this update.

How to reproduce
Having a resource with a property that is nullable.

Possible Solution
Replace adding a "null" to the field by setting the nullable field to true.

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions