swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

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

Open atsuoishimoto opened this issue 3 months ago • 3 comments

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

atsuoishimoto avatar Oct 01 '25 06:10 atsuoishimoto

Hey I would like to work on this issue can you assign it to me under hacktoberfest. Thank you

karthikeyan-v-max avatar Oct 04 '25 08:10 karthikeyan-v-max

I have an approach for the issue, we pre-process the $refs in our schema before passing it to the validator and in that way the validator will not throw an error, can you assign this issue to me? Thank you.

satyanvm avatar Oct 04 '25 20:10 satyanvm

Hi all,

Thanks for your interest in this issue! We also have it reported in Swagger Client, which is where it needs to be addressed. The error most likely comes from AllOfVisitor. It needs to be verified whether it also occurs elsewhere for OpenAPI 3.1.

Please note that this issue might also affect dereferencing in ApiDOM, for both OpenAPI 3.0 and 3.1, but it should be addressed separately, if that is the case.

If you’d like to work on this, please feel free to address it in Swagger Client.

glowcloud avatar Oct 08 '25 06:10 glowcloud