openapi-generators / openapi-generators/openapi-python-client

`default` property sibling to a `$ref` is ignored

Open
#1,432 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2k
Forks
293
Avg merge
34m
Merged PRs (30d)
1

Description

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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the OpenAPI 3.1 specification in the report and inspect the generated _get_kwargs output. Trace how schema defaults are handled for direct $ref siblings, referenced schemas, and allOf wrappers. Done means all four defaults, including component_default, are preserved in the generated client.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.