Skip to content

Downcast oneOf null to nullable with OpenAPI 3.0 #2629

@desjoerd

Description

@desjoerd

ASP.NET Core 10 OpenApi generates "oneOf" schemas for nullable references for OpenApi 3.1 which is structurely different than what would be idiomatic in OpenAPI 3.0

OpenAPI 3.1

"contact": 
{
  "oneOf": 
  [
    {
      "type": "null"
    },
    {
      "$ref": "#/components/schemas/Person"
    }
  ]
}

When downcasting this to OpenAPI 3.0 we get

"contact": 
{
  "oneOf": 
  [
    {
      "nullable": true
    },
    {
      "$ref": "#/components/schemas/Person"
    }
  ]
}

This is incorrect as { "nullable": true } does not refer to a base schema.

The pattern of "oneOf" with OpenAPI 3.1 should be downcasted to the following:

"contact":
{
  "allOf":
  {
    "$ref": "#/components/schemas/Person"
  },
  "nullable": true
}

Remarks:

  • Probably a pattern of "anyOf" with a { "type": "null" } should also be recognized.
  • OpenAPI 3.1 "oneOf" with multiple schemas AND a null schema would be required to be downcasted to a "oneOf" without the { "type": "null" } and the nullable: true

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions