Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@fumari/json-schema-to-typescript cyclic reference bug #1100

Open
ndom91 opened this issue Nov 23, 2024 · 2 comments
Open

@fumari/json-schema-to-typescript cyclic reference bug #1100

ndom91 opened this issue Nov 23, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@ndom91
Copy link
Contributor

ndom91 commented Nov 23, 2024

To Reproduce

Since issues are disabled on fuma-nama/json-schema-to-typescript, I'll post this here.

I'm having a similar issues to here with [email protected].

The resulting OpenAPI JSON fails to be parsed and results in a maximum call stack size exceeded error when there are cyclic references like the one below:

"Butler_API_Entities_Project": {
  "type": "object",
  "properties": {
    "slug": {
      "type": "string"
    },
    "owner": {
      "type": "string"
    },
    "parent_project": {
      "$ref": "#/components/schemas/Butler_API_Entities_Project"
    },
    "name": {
      "type": "string",
      "description": "Project Name"
    },
  },
}

As you can see the parent_project property doesn't have any other fields, but the cyclic reference still rbeaks the build with the "max call stack size exceeded" error 🤔

I'm using:

"fumadocs-core": "14.4.0",
"fumadocs-mdx": "11.1.1",
"fumadocs-openapi": "^5.5.10",
"fumadocs-twoslash": "^2.0.1",
"fumadocs-ui": "14.4.0",

There is a simliar issue in the parent repository to your fork that yuo might be aware of here.

Current vs. Expected behavior

Parse openapi spec JSON successfully

Provide environment information

Node.js v22.10.0

Operating System:
  Platform: linux
  Arch: x64
  Version: #1-NixOS SMP PREEMPT_DYNAMIC Fri Nov  1 01:02:44 UTC 2024
  Available memory (MB): 32026
  Available CPU cores: 12
Binaries:
  Node: 22.10.0
  npm: 10.9.0
  Yarn: N/A
  pnpm: 9.3.0
Relevant Packages:
  next: 15.0.3 // Latest available version is detected (15.0.3).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: N/A
Next.js Config:
  output: N/A

I've worked around it so far by just dropping self-referencing properties in the effected entities before passing the json file to fumadocs-openapi's generateFiles as input.

delete swaggerContent.components.schemas.Butler_API_Entities_Project.properties.parentProject

Which area(s) are affected? (Select all that apply)

Integrations (e.g OpenAPI, Typescript DocsGen)

Additional context

No response

@fuma-nama
Copy link
Owner

Didn't have much time to work on the fork, I will look into that later.

@fuma-nama
Copy link
Owner

Also if you don't mind, you can disable it as a temporary fix:

export const openapi = createOpenAPI({
  generateTypeScriptSchema: false,
});

As the linked issue said

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants