swagger-api / swagger-api/swagger-ui

OpenAPI 3.1.0 self-referential array items with allOf triggers “Elements in allOf must be objects”

Open
#10,583 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P2 pull-request-welcome type: bug
Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
  • OS: Windows 11
  • Browser: Chrome
  • Version: 140.0.7339.208
  • Method of installation: dist assets
  • Swagger-UI version: 5.28.0
  • Swagger/OpenAPI version: OpenAPI 3.1
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
            allOf:
              - $ref: '#/components/schemas/User'
              - type: object
                required:
                  - id

security:
  - {}

Swagger-UI configuration options:

SwaggerUI({
  url: "/schema.yaml",
 dom_id: '#swagger-ui'
Describe the bug you're encountering

Expanding the attached User schema in Swagger UI shows the following error:

Errors
Resolver error at properties.friends.items.allOf
Elements in allOf must be objects

This schema works without error under OpenAPI 3.0.0. Under 3.1.0, the error appears when an object schema has an array property whose items definition combines a self-referential $ref and an allOf that adds constraints.

To reproduce...
  1. Load the OpenAPI 3.1.0 document above in Swagger UI.
  2. Expand components > schemas > User.
Expected behavior

The schema resolves and renders without errors, matching OpenAPI 3.0.0 behavior.

Screenshots
Image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by loading the supplied OpenAPI 3.1.0 document in Swagger UI 5.28.0 and expanding User, then compare the same schema under OpenAPI 3.0.0. Trace the resolver behavior for the self-referential array items and nested allOf; done means the 3.1.0 schema renders without the reported resolver error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, openapi
Domain
api, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.