elements icon indicating copy to clipboard operation
elements copied to clipboard

Default value ignored on referenced objects

Open spous-ovl opened this issue 6 months ago • 1 comments

When an object as a default value overridden, it doesn't show in the doc.

Here a small snippet to show the problem:

Page is defined inline (Ok: default is shown in doc) Quality1 is defined as a reference and the object has the default value inline (Ok: default is shown in doc) Quality2 is defined as a reference and the object HAS NO default value, but the default value is documented in the referring object (NOT OK: default value NOT shown in doc)

description: A test Object
type: object
properties:
    page:
        type: integer
        default: 0
    quality1:
        $ref: '#/components/schemas/quality1'
    quality2:
        $ref: '#/components/schemas/quality2'
        default: "static"

Current Behavior

The default value doesn't appear in the stoplight even if the openapi.json with version 3.1 has the default value in the property of the object "quality": openapi.json "quality":{"$ref":"#/components/schemas/Quality","default":"static"}

Image

Expected Behavior

The default should appear as "static" Image

spous-ovl avatar Jul 16 '25 10:07 spous-ovl

Here's another minimal example to illustrate the issue.

  • Expected: If a parameter has a schema.default this is used as the default.
  • Perhaps expected: If a parameter has a schema.$ref that points to a component with a default, this is used as the default.
  • Perhaps expected: If a parameter has both a schema.default and a schema.$ref that points to a component with a default, the component's default overrides the parameter's default.
  • NOT expected: If a parameter has both a schema.default and a schema.$ref that points to a component WITHOUT a default, the parameter's default is disregarded, and no default is shown.
{
    "openapi": "3.1.0",
    "paths": {
        "/repro": {
            "get": {
                "parameters": [
                    {
                        "name": "field1",
                        "in": "query",
                        "required": false,
                        "schema": {
                            "default": "1.0"
                        }
                    },
                    {
                        "name": "field2",
                        "in": "query",
                        "required": false,
                        "schema": {
                            "$ref": "#/components/schemas/Type2"
                        }
                    },
                    {
                        "name": "field3",
                        "in": "query",
                        "required": false,
                        "schema": {
                            "$ref": "#/components/schemas/Type3",
                            "default": "3.0"
                        }
                    },
                    {
                        "name": "field4",
                        "in": "query",
                        "required": false,
                        "schema": {
                            "$ref": "#/components/schemas/Type4",
                            "default": "4.0"
                        }
                    }
                ]
            }
        }
    },
    "components": {
        "schemas": {
            "Type2": {
                "default": "2.1"
            },
            "Type3": {
                "default": "3.1"
            },
            "Type4": {
            }
        }
    }
}

NOTE: I have not verified the above is a completely valid schema. But Elements does parse it, and it does demonstrate the isssue.

Elements output:

field1  any
  Default:  1.0
field2  any
  Default:  2.1
field3  any
  Default:  3.1
field4  any

css-optivoy avatar Aug 20 '25 11:08 css-optivoy