Skip to content

Bug: Maximum call stack size exceeded when converting openapi 3.0.1 with circular references #350

@zeteref

Description

@zeteref

Current Behavior

When trying to convert openapi 3.0.1 with circular dependencies RangeError is produced. The same exact openapi with only the version changed to openapi: 3.1.0 works correctly.

Exxpected Behavior

openapi 3.0.1 with circular references should convert without errors.

Steps to Reproduce

cat << 'EOF' > /tmp/s18.yaml
openapi: 3.0.1
info:
  title: Test 18 - Minimal 3.0.1
  version: 1.0.0
servers:
  - url: http://localhost

paths:
  /test:
    get:
      responses:
        "200":
          description: Success
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TypeA"

components:
  schemas:
    TypeA:
      type: object
      properties:
        name:
          type: string
        next:
          $ref: "#/components/schemas/TypeB"

    TypeB:
      type: object
      properties:
        value:
          type: integer
        next:
          $ref: "#/components/schemas/TypeC"

    TypeC:
      type: object
      properties:
        description:
          type: string
        next:
          $ref: "#/components/schemas/TypeA"
EOF

adc convert openapi -o /dev/stdout -f /tmp/s18.yaml

[3:48:12 PM] [ADC] › ▶  start     Convert OpenAPI document "/tmp/s18.yaml"
[3:48:12 PM] [ADC] › ✖  error     Convert OpenAPI document "/tmp/s18.yaml"
[3:48:12 PM] [ADC] › ✖  fatal     RangeError: Maximum call stack size exceeded
cat << 'EOF' > /tmp/s19.yaml
openapi: 3.1.0
info:
  title: Test 19 - Minimal 3.1.0
  version: 1.0.0
servers:
  - url: http://localhost

paths:
  /test:
    get:
      responses:
        "200":
          description: Success
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TypeA"

components:
  schemas:
    TypeA:
      type: object
      properties:
        name:
          type: string
        next:
          $ref: "#/components/schemas/TypeB"

    TypeB:
      type: object
      properties:
        value:
          type: integer
        next:
          $ref: "#/components/schemas/TypeC"

    TypeC:
      type: object
      properties:
        description:
          type: string
        next:
          $ref: "#/components/schemas/TypeA"
EOF

adc convert openapi -o /dev/stdout -f /tmp/s19.yaml

[3:48:13 PM] [ADC] › ▶  start     Convert OpenAPI document "/tmp/s19.yaml"
[3:48:13 PM] [ADC] › ✔  success   Convert OpenAPI document "/tmp/s19.yaml"
[3:48:13 PM] [ADC] › ▶  start     Write converted OpenAPI file
services:
  - name: Test 19 - Minimal 3.1.0
    routes:
      - methods:
          - GET
        name: Test-19-Minimal-3.1.0_test_get
        uris:
          - /test
    upstream:
      nodes:
        - host: localhost
          port: 80
          weight: 100
      pass_host: pass
      scheme: http
      timeout:
        connect: 60
        read: 60
        send: 60
[3:48:13 PM] [ADC] › ✔  success   Converted OpenAPI file to "/dev/stdout" successfully
[3:48:13 PM] [ADC] › ★  star      All is well, see you next time!

Environment

  • APISIX version: apache/apisix:3.13.0-ubuntu
  • ADC version (run adc version): 0.21.1
  • Operating system (run uname -a): Linux bluelap 6.8.0-83-generic #83~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Sep 9 18:19:47 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions