Skip to content

Nullable allOfs with default null values fail validation #418

Open
@pranjalv123

Description

@pranjalv123

Hi,

In OpenAPI 3.0 it's a common pattern to represent a reference that can be null as an allOf with nullable: true.

However, if you set the default to null, openapi-spec-validator attempts to validate null against the referenced schema, and returns an error. The default should take into account the nullability of the schema that it's part of, not just the referenced allOf.

{
  "info": {
    "title": "Example",
    "version": "v1",
  },
  "openapi": "3.0.2",
  "components": {
    "schemas": {
      "FooSchema": {
        "title": "FooSchema",
        "type": "object"
      },
      "BarSchema": {
        "allOf": [
          {
            "$ref": "#/components/schemas/FooSchema"
          }
        ],
        "nullable": true,
        "default": null
      }
    }
  },
  "paths": {}
}
Failed validating 'type' in schema['allOf'][0]:
    {'title': 'FooSchema', 'type': 'object'}

On instance:
    None

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