swagger-ui: Cannot read property '1' of undefined (Swagger Hub)

Q&A (please complete the following information)

  • OS: Windows 10
  • Browser: chrome
  • Version: Swagger Hub
  • Method of installation: Swagger Hub
  • Swagger-UI version: Swagger Hub
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

I am encountering an error in swagger hub that is particularly annoying and seems to occur haphazardly. This issue seemed to be resolved in the past however it is appearing for me in SwaggerHub. The error Cannot Read Property ‘1’ of undefined explodes and makes swagger hub unusable until refreshed.

Example Swagger/OpenAPI definition:

openapi: 3.0.0
components:
  schemas:  
    QuestionBase:
      type: object
      properties:
        question:
          type: string
        type:
          type: string
        options:
          type: object
    
    QuestionInputBase:
      allOf:
        - $ref: '#/components/schemas/QuestionBase'
        - type: object
          required:
            - type
    QuestionInputById:
      allOf:
        - $ref: '#/components/schemas/QuestionInputBase'
        - type: object
          required:
            - id
          properties:
            id:
              type: integer

    QuestionInputWithOrder:
      allOf:
        - $ref: '#/components/schemas/QuestionInputBase'
        - type: object
          required:
            - order
            - type
          properties:
            order:
              type: integer
              minimum: 1
    
    QuestionInputWithOrderById:
      allOf:
        - $ref: '#/components/schemas/QuestionInputWithOrder'
        - type: object
          required:
            - id
          properties:
            id:
              type: integer
              minimum: 1
        
    
    QuestionInputWithNested:
      allOf:
        - $ref: '#/components/schemas/QuestionInputBase'
        - type: object
          required:
            - type
          properties:
            type:
              type: string
              example: "ranking"
            subQuestions:
              type: array
              items:
                oneOf:
                  - $ref: '#/components/schemas/QuestionInputById'
                  - $ref: '#/components/schemas/QuestionInputWithOrder'
                  - $ref: '#/components/schemas/QuestionInputWithOrderById'

Describe the bug you’re encountering

Cannot read property ‘1’ of undefined occurring whenever QuestionInputWithNested is expanded in the UI.

To reproduce…

Steps to reproduce the behavior:

  1. Go to Swagger Editor
  2. Copy and paste the YAML
  3. Scroll down to QuestionInputWithNested in the UI.
  4. Expand
  5. Watch the explosion of Cannot read property 1 of undefined errors

Screenshots

Additional context or thoughts

These seems to happen because QuestionInputWithOrderById is referencing QuestionInputById as part of an allOf. When QuestionInputWithOrderById is removed from the oneOf list of the subQuestions property on the QuestionInputWithNested the issue seems to be fixed. This is strange to me because I am using the same pattern elsewhere and it doesn’t cause the same error. I will get around this for now by removing the inheritance which for some reason or another is causing these circular import errors 😦

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 20 (5 by maintainers)

Most upvoted comments

Hi,

is there any update on this issue? I have an API definition in openapi v3 and face the same issue. I checked with the example from @Moro-Code above and I get the same error with the react component.

Hmmmm, yeah I see this too.

Good timing @Moro-Code, I’m looking at a similar internal report today, might be related.

I recently encountered this issue, I ensured my braces were properly closed and aligned. It works fine now!

@Moro-Code I spent a while trying to figure out why I wasn’t seeing the problem in the online swagger editor, and the answer is that the currently deployed version per the changelog (0.30.x) does not seem to render resolver errors.