ardatan / feTS

🗹 TypeScript HTTP Framework focusing on e2e type-safety, easy setup, performance & great developer experience
https://the-guild.dev/openapi/fets
MIT License
629 stars 29 forks source link

Circular Reference Error when using OASModel and OASOutput with Recursive Nested Schemas #1823

Closed akifunal closed 2 months ago

akifunal commented 2 months ago

Describe the bug

I'm encountering a "Type of property 'x' circularly references itself" error when using the OASModel and OASOutput types with recursive schemas. The issue arises when trying to define and work with models that involve a recursive reference (e.g., a tree structure) in the OpenAPI definition.

To Reproduce Steps to reproduce the behavior:

typescriptlang playground

Expected behavior

Recursive schemas should be handled gracefully without triggering circular reference errors.

Environment:

Additional context

I noticed that a similar issue was addressed in #335, but it seems like the fix might only handle one level of recursion or a limited case. In this scenario, deeper or more complex recursive structures still trigger the circular reference error. The issue could likely affect other recursive structures like linked lists or graphs.

We really appreciate the effort you’ve put into this library. We’re using your library in over 10+ projects and it has greatly simplified our development process. Thanks for your ongoing work and dedication!

akifunal commented 2 months ago

Thank you @ardatan :pray: for addressing the previous issue we raised regarding the circular reference error. The fix you implemented worked well for the cases we initially encountered.

However, we’ve come across another situation where the error occurs. This time, the issue is related to handling an array of objects where the object schema itself is recursive. Here’s a brief outline of the structure: typescript playground

We have an array of objects, each representing a recursive entity (e.g., nodes in a tree). The circular reference error appears when the array contains instances of this recursive object.

We’d appreciate your insights on whether this can be resolved similarly to the previous fix or if it requires a different approach.

ardatan commented 2 months ago

You're welcome! Thanks for the reproduction and detailed feedback. Could you create a new issue?