APIDevTools / json-schema-ref-parser

Parse, Resolve, and Dereference JSON Schema $ref pointers in Node and browsers
https://apitools.dev/json-schema-ref-parser
MIT License
942 stars 226 forks source link

How to get rid of the circular reference error #344

Closed RagaviMuthukrishnan closed 4 months ago

RagaviMuthukrishnan commented 4 months ago

I am getting the below error message if i try to wrap it using JSON.stringify()


    --> starting at object with constructor 'Object'
    |     property 'properties' -> object with constructor 'Object'
    --- property 'parent_folder_workspace_item' closes the circle
    at JSON.stringify (<anonymous>)
    at resolveSchema (/Users/ragavimuthukrishnan/Apromore-playwright-tests/tests/api/schemas/sample.test.js:15:24)
Error: No tests found.
Make sure that arguments are regular expressions matching test files.
You may need to escape symbols like "$" or "*" and quote the arguments.```

Can you please guide me how to get rid of that in order to extract the actual object contents instead of [Object] ?

_Originally posted by @RagaviMuthukrishnan in https://github.com/APIDevTools/json-schema-ref-parser/issues/343#issuecomment-2069036385_
jonluca commented 4 months ago

That is because you cant stringify an object with circular references. You need to look at the circular options.

https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#dereferenceschema-options-callback

You can use bundle before stringifying.

RagaviMuthukrishnan commented 4 months ago

That is because you cant stringify an object with circular references. You need to look at the circular options.

https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#dereferenceschema-options-callback

You can use bundle before stringifying.

Thank you so much and it worked like a charm !!!!