[OpenAPI 3.1] Example value is not generated for nested objects that are referenced via allOf
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 https://github.com/swagger-api/swagger-js/issues/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:
- Go to https://editor-next.swagger.io
- Paste the definition provided above.
- Expand the
GET /foooperation and examine the "Example Value".
Actual result:
{
"bar": {}
}
Expected result:
{
"bar": {
"a": 123,
"b": "hello"
}
}
- Replace
openapi: 3.1.0withopenapi: 3.0.0. - 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.
Hi @hkosova,
Nice to see you here again ;]
We're looking into the issue. Thanks for the report.
I can confirm this is a regression in Swagger Client.
This works properly in Swagger UI version 5.15.2 and stops working in 5.16.0. We updated the Swagger Client version from 3.26.8 to 3.27.0 and there were changes to dereferencing: https://github.com/swagger-api/swagger-js/pull/3472, so it looks like the regression was caused by that.
@glowcloud can you constructor minimal reproducibe fixture with expected result and current result?
Looks like it can be reproduced without the reference inside of allOf:
openapi: 3.1.0
info:
title: Example generation test
version: 1.0.0
paths:
/foo:
get:
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/Foo'
components:
schemas:
Foo:
type: object
properties:
bar:
allOf:
- type: object
properties:
a:
type: integer
Here's the schema inside of response with the allOf keyword:
and under schemas:
Associated upstream swagger-js issue has been created in https://github.com/swagger-api/swagger-js/issues/3520
We're encountering the same issue with our documentation. This is a high priority matter as a significant portion of our documentation is affected.
We already have an upstream regression remediation in https://github.com/swagger-api/swagger-js/pull/3521
ETA in SwaggerUI during today.
Upstream fix released in [email protected]
Addressed for SwaggerUI in https://github.com/swagger-api/swagger-ui/pull/9950
Released as https://github.com/swagger-api/swagger-ui/releases/tag/v5.17.12
Thanks for the quick fix @char0n, @glowcloud!