question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Circular reference is considered an error

See original GitHub issue

When you have a yaml model that reference itself, the validate function consider it an error, which is not. It is completely supported by tools like swagger-editor and swagger-codegen.

I’m using the latest release on npm (1.0.1).

To reproduce, use the petstore and add this in the definition part:

MenuItemDescription:
  type: string
  description: "List of all menu item descriptions"
  enum:
    - Choice1
    - Choice2
    - Choice3
MenuItem:
  type: object
  description: "Item in a menu"
  required:
    - description
    - childMenuItems
  properties:
    description:
      $ref: "#/definitions/MenuItemDescription"
    childMenuItems:
      type: array
      items:
        $ref: "#/definitions/MenuItem"

The error is as follow:

Swagger schema validation failed.
  Expected type object but found type string at #/definitions/$ref

JSON_OBJECT_VALIDATION_FAILED

Thanks!

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
eugene-rockspooncommented, Jan 5, 2021

It seems there isn’t solution but better error description, at least for swagger-cli bundle -r:

Circular $ref pointer found at /Users/name/go/src/github.com/repo/docs/myModel.yaml#/properties/elements/items

where elements/items:

myModel:
  properties:
    elements:
      items:
        $ref: "./myModel.yaml"
      type: array
      x-go-name: Elements

and swagger-cli validate gives swagger.yaml is valid

0reactions
msandasynteacommented, Dec 14, 2022

Hello, I have found this thread today when I was searching for exactly this problem. I am getting exactly the same results as @eugene-rockspoon metioned. Funny fact I can validate my openApi.yaml spec locally (without error), but we are using it in gitlab CI and it fails. The version of swagger-cli is exactly the same in both enviroments (4.0.4). So this problem is still actual and I think it has to be resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove or allow a circular reference - Microsoft Support
If you can't find the error, click the Formulas tab, click the arrow next to Error Checking, point to Circular References, and then...
Read more >
How to fix a circular reference error - Excel formula - Exceljet
Circular reference errors occur when a formula refers back to its own cell. For example, in the example shown, the formula in F7...
Read more >
How To Find and Remove Circular References in Excel - Indeed
One of the most common reasons a circular reference occurs is by mistake. For instance, consider someone who wants to calculate the sum...
Read more >
What is a circular reference in Excel // PerfectXL ... - PerfectXL
A circular reference refers to a formula, that visits its own or another cell more than once in its chain of calculations, creating...
Read more >
What Is Circular Reference in Excel? Everything You Need to ...
Circular reference is a type of error in Excel that occurs when a formula in a cell tries to calculate itself. Find out...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found