swagger-api / swagger-api/swagger-ui
OpenAPI 3.1 self-referential array items renders as array<any> and shows only raw $ref URL
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
Content & configuration
Example Swagger/OpenAPI definition:
openapi: 3.1.0
info:
title: test
description: test
version: 1.0.0
servers:
- url: http://localhost:5000
description: test
paths:
/api/user:
get:
summary: get user
responses:
'200':
description: ok
content:
application/json:
schema:
$ref: '#/components/schemas/User'
components:
schemas:
User:
type: object
properties:
id:
type: integer
name:
type: string
friends:
type: array
items:
type: object
$ref: '#/components/schemas/User'
required:
- id
Swagger-UI configuration options:
SwaggerUI({
url: "/schema.yaml",
dom_id: '#swagger-ui'
})
Is your feature request related to a problem?
Expanding the attached OpenAPI 3.1.0 User schema in Swagger UI results in the friends property (an array that self-references User) being displayed as array, and the UI shows only a raw $ref-like string such as:
$ref=http://localhost:5000/schema.yaml#/components/schemas/User
The property definition is not expanded.
Figure 1. The self-referential property is rendered as the $ref schema name.
Describe the solution you'd like
The friends array should render as an array of User objects with the schema expanded (e.g., array<User>).
Additional context
With OpenAPI 3.0.0, a similar schema defined using allOf expands correctly in Swagger UI (see below). Under OpenAPI 3.1.0, the allOf-based definition is not usable because it triggers an error in Swagger UI 5.28.0 (#10583).
openapi: 3.0.0
info:
title: test
description: test
version: 1.0.0
servers:
- url: http://localhost:5000
description: test
paths:
/api/user:
get:
summary: get user
responses:
'200':
description: ok
content:
application/json:
schema:
$ref: '#/components/schemas/User'
components:
schemas:
User:
type: object
properties:
id:
type: integer
name:
type: string
friends:
type: array
items:
type: object
allOf:
- $ref: '#/components/schemas/User'
- type: object
required:
- id
Figure 2. The self-referential property defined with allOf is correctly expanded(OpenAPI 3.0).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue in Swagger UI 5.28.0 using the provided OpenAPI 3.1 YAML, then compare it with the OpenAPI 3.0 allOf example. Trace how the self-referential array schema and its $ref are rendered; done means the friends property displays as an array of User objects instead of array with a raw $ref URL.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, openapi
- Domain
- api, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100