-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Description
Q&A (please complete the following information)
- OS: macOS
- Browser: chrome
- Version: 138
- Method of installation: dist assets
- Swagger-UI version: 5.26.0
- Swagger/OpenAPI version: OpenAPI 3.0.1
Content & configuration
Note
Although the YAML example here may seem contrived, please note that it was taken from an actual (much larger) real world spec, anonymised, and then reduced to a minimal example that demonstrates the issue.
Example Swagger/OpenAPI definition:
openapi: 3.0.1
info:
title: Example
version: 1.0.0
paths:
/example:
get:
responses:
'200':
description: Empty
components:
schemas:
A:
type: object
properties:
a:
$ref: '#/components/schemas/B'
B:
allOf:
- $ref: '#/components/schemas/C'
- $ref: '#/components/schemas/D'
C:
type: object
properties:
c:
type: string
D:
type: object
properties:
d:
$ref: '#/components/schemas/E'
E:
type: array
items:
$ref: '#/components/schemas/F'
F:
type: object
properties:
f:
$ref: '#/components/schemas/G'
G:
oneOf:
- $ref: '#/components/schemas/H'
- $ref: '#/components/schemas/I'
H:
allOf:
- $ref: '#/components/schemas/J'
- $ref: '#/components/schemas/K'
I:
allOf:
- $ref: '#/components/schemas/B'
- $ref: '#/components/schemas/K'
J:
allOf:
- type: object
properties:
j:
type: string
- $ref: '#/components/schemas/C'
K:
type: object
properties:
k:
type: string
Swagger-UI configuration options:
Reproducible in https://editor.swagger.io/
Important
In the screen recording attached, I am demonstrating the issue using Swagger Editor.
(It was difficult to reliably reproduce it on-demand in Swagger UI, given the intermittent nature).
I can, however, confirm that the issue does intermittently occur in Swagger UI as well.
Describe the bug you're encountering
It will be easiest to describe the issue by referencing specific timestamps in the attached screen recording:
Timestamp | Description |
---|---|
[00:00] | The expanded schema on the right shows the definition G = oneof H or I |
[00:05] | This correctly matches the YAML definition of G on the left |
[00:10] | A edit is made, triggering a re-render |
[00:18] | The rendered definition still correctly shows G = one of H or I |
[00:22] | A second edit is made, triggering another re-render |
[00:29] | The rendered definition now incorrectly shows G = one of H or B |
It is worth noting that the example includes some deeply nested allOf
/ oneOf
definitions; as well as a circular reference (B
-> ... -> G
-> I
, where I
then references back to B
).
Given the intermittent nature of the issue, it is possible that the combination of nested allOf
/ oneOf
, and/or the circular reference causes a race condition where, depending on the order in which references are resolved, the outcome for G
is either correctly "one of H or I", or incorrectly "one of H or B".
To reproduce...
Steps to reproduce the behavior:
- Go to https://editor.swagger.io/
- Paste the above YAML into the editor
- In the Schemas section rendered on the right, expand the
A
schema untilG
is expanded - Note that
G
is correctly rendered as "oneof H or I" (confirm in the definition on the left that this is correct) - Make a trivial edit (e.g. rename the
A.a
->A.x
) - Expand the schema on the right and check the definition of
G
(Note: You may need to repeat steps 5-6 more than once to trigger the issue)
Expected behavior
The rendered definition of G
should always be oneof H or I
.