Skip to content

OpenAPI 3.1.: examples in webhooks are being overwritten by the examples in schema #9937

Closed
@glowcloud

Description

@glowcloud

Q&A (please complete the following information)

  • OS: macOS
  • Browser: chrome
  • Version: 124.0.6367.156
  • Swagger-UI version: 5.17.9
  • Swagger/OpenAPI version: OpenAPI 3.1

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.1.0
info:
  version: 1.0.0
  title: Examples
  description: ''

webhooks:
  test-webhook:
    post:
      operationId: test-webhook
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TestSchema'
            examples:
              TestExample:
                $ref: '#/components/examples/TestExample'
      responses:
        '200':
          description: OK

paths:
  /test-path:
    get:
      operationId: 'test-path'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TestSchema'
              examples:
                TestExample:
                  $ref: '#/components/examples/TestExample'

components:
  schemas:
    TestSchema:
      type: object
      properties:
        userId:
          type: string
          examples: ['userId example from schema']
        orders:
          type: array
          items:
            type: object
            properties:
              orderId:
                type: string
                examples: ['orderId example from schema']

  examples:
    TestExample:
      value:
        userId: 'userId example from examples'
        orders:
          - orderId: 'orderId example from examples'

Describe the bug you're encountering

In webhooks the specified examples are being overwritten by the examples from the schema defined in the same content type, despite the example chosen in the dropdown:

Screenshot 2024-05-14 at 13 44 01

This does not happen for paths - the example values are correctly rendered from the chosen example and not from the schema:

Screenshot 2024-05-14 at 13 45 43

Additionally, if I first expand the webhook, I will see the example from the schema. Expanding the path after that will show the correct example there and also overwrite the example in webhook to the correct one:

Screenshot 2024-05-14 at 13 49 12

This will not happen if I first expand the path and then the webhook:

Screenshot 2024-05-14 at 13 49 57

Also, expanding, collapsing and then expanding the webhook again will show the correct example as well.

To reproduce...

Steps to reproduce the behavior:

  1. Load the attached specification
  2. Expand the webhook
  3. See that the example is the one defined in the schema
  4. Expand the path
  5. See that the example is the one defined in the example selected in the dropdown
  6. Scroll down to the webhook and see that the incorrect example was overwritten by the correct example

Expected behavior

The displayed example should be the one defined in examples / selected in the dropdown.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions