Skip to content

[OpenAPI 3.1] Example value is not generated for nested objects that are referenced via allOf #9941

Closed
@hkosova

Description

@hkosova

Q&A (please complete the following information)

  • OS: macOS 13.6.7
  • Browser: Chrome latest
  • Method of installation: standalone Swagger UI (5.17.9), also https://editor-next.swagger.io (UI v. 5.17.3)
  • Swagger-UI version: 5.17.9, 5.17.3
  • Swagger/OpenAPI version: OpenAPI 3.1 only

Ref swagger-api/swagger-js#3520

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.1.0
info:
  title: Example generation test
  version: 1.0.0
paths:
  /foo:
    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Foo'

components:
  schemas:
    Foo:
      type: object
      properties:
        bar:
          allOf:
            - $ref: '#/components/schemas/Bar'
    
    Bar:
      type: object
      properties:
        a:
          type: integer
          example: 123
        b:
          type: string
          example: hello

Describe the bug you're encountering

The issue may (or may not) be related to #8374.

On the "Example Value" tab, the bar value appears empty object "bar": {} instead of an actual object generated from its schema "bar": {"a": 123, "b": "hello"}. This happens for properties that reference their schema using allOf+$ref instead of just $ref.

The property schema on the "Schema" tab appears correctly though, and shows all fields defined in the referenced schema.

The issue exists for OpenAPI 3.1 definitions and does NOT exist for OpenAPI 3.0 and 2.0.

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor-next.swagger.io
  2. Paste the definition provided above.
  3. Expand the GET /foo operation and examine the "Example Value".

Actual result:

{
  "bar": {}
}

Expected result:

{
  "bar": {
    "a": 123,
    "b": "hello"
  }
}
  1. Replace openapi: 3.1.0 with openapi: 3.0.0.
  2. Example "Example Value" again.

=> Now the example value is correct and includes the nested fields.

Screenshots

Additional context or thoughts

Looks like the correctness of the Example Value depends on whether the user expands the operation or schema first? If I first fully expand the schema under "Schemas" at the bottom, then the Example Value inside the operation is generated correctly.

weird

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions