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

Generator hangs at a recursive type in methods definition #720

Open
rhysd opened this issue Nov 19, 2024 · 0 comments
Open

Generator hangs at a recursive type in methods definition #720

rhysd opened this issue Nov 19, 2024 · 0 comments

Comments

@rhysd
Copy link

rhysd commented Nov 19, 2024

Describe the bug

I have an API method which returns a tree structure. I created a definition file with describing the recursive type in JSON schema and I tried this code generator. And the generator instantly hung.

To Reproduce
Steps to reproduce the behavior:

  1. Put the following JSON content as openrpc.json in your current directory
  2. npm i @open-rpc/generator
  3. npx open-rpc-generator init
  4. The command hangs at the first question. npx open-rpc-generator generate hangs as well
{
  "openrpc": "1.3.2",
  "info": {
    "version": "0.0.0",
    "title": "My API"
  },
  "methods": [
    {
      "name": "getTree",
      "description": "",
      "params": [],
      "result": {
        "name": "tree",
        "description": "",
        "schema": { "$ref": "#/components/schemas/Node" }
      }
    }
  ],
  "components": {
    "schemas": {
      "Node": {
        "type": "object",
        "properties": {
          "id": { "type": "integer" },
          "children": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Node" }
          }
        }
      }
    }
  }
}

Expected behavior

The npx open-rpc-generator init creates a configuration file for the project.

Screenshots

Instead of screenshot I captured terminal screen outputs:

> npx open-rpc-generator init
? Where is your OpenRPC document? May be a file path or url. (openrpc.json)

The command hung at the first question.

Desktop (please complete the following information):

  • @open-rpc/generator: v1.22.3
  • OS: Windows 10
  • Browser: N/A
  • Version: Node.js v18.20.0

Additional context

When I modified the children field as follows, this issue didn't occur.

"children": {
  "type": "array",
  "items": { "type": "object" }
}

I believe the recursive type made the generator hang. I guess the generator checks $ref recursively without checking the reference is already visit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant