Skip to content

default property sibling to a $ref is ignored #1432

@gcq-swish

Description

@gcq-swish

Describe the bug
default property sibling to a $ref is ignored. OAS 3.1.X relies on JSON Schema 2020-12 which does not include the requirement that sibling properties to $ref should be ignored.

OpenAPI Spec File

{
  "openapi": "3.1.0",
  "info": {
    "title": "title",
    "summary": "summary",
    "description": "description",
    "version": "0.0.1"
  },
  "paths": {
    "/": {
      "get": {
        "parameters": [
          {
            "name": "default_lost1",
            "required": false,
            "schema": {
              "$ref": "#/components/schemas/String",
              "default": "lost"
            }
          },
          {
            "name": "default_lost2",
            "required": false,
            "schema": {
              "$ref": "#/components/schemas/DefaultString"
            }
          },
          {
            "name": "default_lost3",
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/DefaultString"
                }
              ]
            }
          }, 
          {
            "name": "default_kept",
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/String"
                }
              ],
              "default": "kept"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {}
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "String": {
        "type": "string"
      },
      "DefaultString": {
        "type": "string",
        "default": "component_default"
      }
    }
  }
}

Desktop (please complete the following information):

  • OS: macOS 26.4.1
  • Python Version: 3.11.13
  • openapi-python-client version: 0.28.3

Additional context
The previous schema generates code like this:

def _get_kwargs(
    *,
    body: Object,
    default_lost1: str | Unset = UNSET,
    default_lost2: str | Unset = UNSET,
    default_lost3: str | Unset = UNSET,
    default_kept: str | Unset = 'kept',

) -> dict[str, Any]:

I would expect all defaults to be kept.

If anything else is needed I will be more than happy to provide it. Thank you for your time!

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