Skip to content

OpenAPI 3.1 self-referential array items renders as array<any> and shows only raw $ref URL #10584

@atsuoishimoto

Description

@atsuoishimoto

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.

Image

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).

Image

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions