Skip to content

Cannot read property '0' of undefined -- only with dereferenced file #5705

Open
@lorthirk

Description

@lorthirk

Q&A (please complete the following information)

  • OS: macOS
  • Browser: Chrome
  • Version: 10.15.1
  • Method of installation: Docker
  • Swagger-UI version: 3.24.2
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Example Swagger/OpenAPI definition:

Dereferenced version: https://keybase.pub/lorthirk/openapi-bundle-dereference.yaml
Non-dereferenced version: https://keybase.pub/lorthirk/openapi-bundle.yaml

Swagger-UI configuration options:

SwaggerUI({
        url: "./openapi.yaml",
        "dom_id": "#swagger-ui",
        deepLinking: true,
        presets: [
          SwaggerUIBundle.presets.apis,
          SwaggerUIStandalonePreset
        ],
        plugins: [
          SwaggerUIBundle.plugins.DownloadUrl
        ],
        layout: "StandaloneLayout",
        docExpansion: "none",
})

Describe the bug you're encountering

With the Dereferenced file I have errors in my console when expanding an API method:

index.js:2247 TypeError: Cannot read property '0' of undefined
    at l (core.js:244)
    at Object.p [as applyPatch] (core.js:277)
    at Object.applyPatch (index.js:940)
    at e.value (index.js:2258)
    at index.js:2242
    at Array.forEach (<anonymous>)
    at e.value (index.js:2214)
    at a (index.js:2412)
    at index.js:2390
    at e.value (index.js:2380)

Such errors are not present with the non-dereferenced file

To reproduce...

Steps to reproduce the behavior:

  1. Expand a Tag
  2. Expand an API method
  3. Check the console
  4. See error

Expected behavior

No errors

Additional context or thoughts

In my schemas I make an extensive use of allOf to compose schemas via $ref, and mix them with inline defined properties. If I change the following schema:

kapuaUpdatableEntity:
      allOf:
        - $ref: '#/components/schemas/kapuaEntity'
      description: An Entity that also supports edits and versioning
      type: object
      properties:
        modifiedOn:
          description: The date and time when this entity was modified
          type: string
          format: 'date-time'
          readOnly: true
        modifiedBy:
          allOf:
            - $ref: '#/components/schemas/kapuaId'
          description: The ID of the Entity who modified this Entity
          readOnly: true
        optlock:
          description: |
            The optlock field is used to detect that this entity has not been modified by someone else. When updating an entity, first do a find to get the latest version of the entity and note the value of the optlock. Then in the update operation, set the optlock value to match the value that you found. If someone else has updated the entity between your find and update operations, the update will fail and the db/server will return an error.\
            See this [StackOverflow question](http://stackoverflow.com/questions/129329/optimistic-vs-pessimistic-locking) for more information on optimistic locking
          type: integer

to

kapuaUpdatableEntity:
      allOf:
        - $ref: '#/components/schemas/kapuaEntity'
        - description: An Entity that also supports edits and versioning
          type: object
          properties:
            modifiedOn:
              description: The date and time when this entity was modified
              type: string
              format: 'date-time'
              readOnly: true
            modifiedBy:
              allOf:
                - $ref: '#/components/schemas/kapuaId'
              description: The ID of the Entity who modified this Entity
              readOnly: true
            optlock:
              description: |
                The optlock field is used to detect that this entity has not been modified by someone else. When updating an entity, first do a find to get the latest version of the entity and note the value of the optlock. Then in the update operation, set the optlock value to match the value that you found. If someone else has updated the entity between your find and update operations, the update will fail and the db/server will return an error.\
                See this [StackOverflow question](http://stackoverflow.com/questions/129329/optimistic-vs-pessimistic-locking) for more information on optimistic locking
              type: integer

The error seem to go away in both the dereferenced and non-dereferenced version

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions