pb33f/doctor

Doctor Will Hang Indefinitely on Poorly Formatted Self References

Closed this issue · 4 comments

As per our discord chat, opened this for tracking on your end since I saw that you prefer issues be on Github.

a root.yaml

paths:
  /v3/test:
    get:
      summary: test
      operationId: test
      responses:
        "200":
          description: Success
          content:
            application/json:
              schema:
                $ref: "schemas.yaml#/TestAccountV3"

referencing a schemas.yaml

TestAccountV3:
  type: object
  properties:
    parentAccount:
      $ref: "schemas.yaml#/TestAccountV3"
    liveAccount:
      $ref: "schemas.yaml#/TestAccountV3"
    provisionedForAccount:
      $ref: "schemas.yaml#/TestAccountV3"

Like so, will hang indefinitely. The reason that occurs is because of the following line:

https://github.com/pb33f/doctor/blob/main/model/high/base/schema_proxy.go#L61

	for _, ref := range circularRefs {
		if ref.LoopPoint.Definition == sp.Value.GetReference() {
			return true
		}
	}

Which never finds a match. The variable values are as follows:

ref.LoopPoint.Definition

is #/TestAccountV3, but

sp.Value.GetReference()

is schemas.yaml#/TestAccountV3.

This occurs because the schemas.yaml has a self reference that uses a file reference (adding in the schemas.yaml# to refer to a definition to itself).

As per your recommendation, this is most likely invalid or at least non standard but in that case should either error or be fixed to pass. My preference is for it to pass, but lint it in vacuum.

The doctor should be able to handle this design, so I will dig into this asap.

I cannot re-create this anymore with the latest version of the doctor.

Can you try again?

Sure! let me see

I can confirm that the latest version works perfectly!! Thank you @daveshanley