docusaurus-openapi-docs icon indicating copy to clipboard operation
docusaurus-openapi-docs copied to clipboard

DiscriminatorNode access on undefined property

Open pmarschik opened this issue 1 year ago • 3 comments

Describe the bug

With version 4.2.0 OAS discriminator was changed and now results in "This page crashed": TypeError: undefined is not an object (evaluating 'subProperties[discriminator.propertyName]') errors.

Rolling back to 4.1.0 fixes the issue but shows "circular(InnerClassTypeA)".

Your Environment

  • Version used: 4.2.0

Context

The relevant part of redacted OAS looks like this:

# ...
components:
  schemas:
    OuterClass:
      type: object
      properties:
        _TYPE:
          type: string
          enum:
            - type1
            - type2
        sharedProperty:
          type: string
     discriminator:
       propertyName: _TYPE
       mapping:
         type1: "#components/schemas/OuterClassType1"
         type2: "#components/schemas/OuterClassType2"
    OuterClassType1:
      allOf:
        - $ref: "#components/schemas/OuterClass"
        - type: object
          properties:
            # property named the same but different concrete schema per discriminated property
            innerClass:
              $ref: "#components/schemas/InnerClassTypeA"
    OuterClassType2:
      allOf:
        - $ref: "#components/schemas/OuterClass"
        - type: object
          properties:
            # property named the same but different concrete schema per discriminated property
            innerClass:
              $ref: "#components/schemas/InnerClassTypeB"
    # never used directly but only "inherited" from with allOf
    InnerClass:
      type: object
      properties:
        _TYPE:
          type: string
          enum:
            - typeA
            - typeB
        sharedProperty:
          type: string
     discriminator:
       propertyName: _TYPE
       mapping:
         type1: "#components/schemas/InnerClassTypeA"
         type2: "#components/schemas/InnerClassTypeB"
    InnerClassTypeA:
      allOf:
        - $ref: "#components/schemas/InnerClass"
        - type: object
          properties:
            specificFieldA:
              type: string
    InnerClassTypeB:
      allOf:
        - $ref: "#components/schemas/InnerClass"
        - type: object
          properties:
            specificFieldB:
              type: string

pmarschik avatar Nov 21 '24 10:11 pmarschik