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

Issue with Nested Schemas in OpenAPI generator #642

Closed
0sssama opened this issue Jul 26, 2024 · 1 comment
Closed

Issue with Nested Schemas in OpenAPI generator #642

0sssama opened this issue Jul 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@0sssama
Copy link
Contributor

0sssama commented Jul 26, 2024

To Reproduce

  1. Create a test.yaml with the following content
openapi: 3.0.3
info:
  title: Test API
  version: 0.0.1
paths:
  /v1/get-folder:
    get:
      tags: []
      summary: Get Folder
      operationId: GetFolder
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Folder'
  /v1/get-relation:
    get:
      tags: []
      summary: Get Relation Definition
      operationId: GetRelationDefinition
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RelationDefinition'
components:
  schemas:
    RelationDefinition:
      type: object
      properties:
        name:
          type: string
          description: Name of the relation definition
        definition:
          $ref: '#/components/schemas/Folder'
    Folder:
      type: object
      properties:
        file:
          type: string
        folders:
          type: array
          items:
            $ref: '#/components/schemas/Folder'
  1. Load the file to FumaDocs' generateFiles OpenAPI generator in a scripts/generate-docs.mjs file
import { generateFiles } from 'fumadocs-openapi';

void generateFiles({
  input: ['openapi/test.yaml'],
  output: '/content/api',
  per: 'operation',
})
  1. run the script, you should get the following error:
/Users/some-project/node_modules/lodash/lodash.js:10612
      var memoized = function() {
                             ^

RangeError: Maximum call stack size exceeded
    at memoized (/Users/some-project/node_modules/lodash/lodash.js:10612:30)
    at /Users/some-project/node_modules/json-schema-to-typescript/dist/src/generator.js:256:104
    at Array.map (<anonymous>)
    at generateInterface (/Users/some-project/node_modules/json-schema-to-typescript/dist/src/generator.js:256:14)
    at generateRawType (/Users/some-project/node_modules/json-schema-to-typescript/dist/src/generator.js:151:20)
    at generateTypeUnmemoized (/Users/some-project/node_modules/json-schema-to-typescript/dist/src/generator.js:128:18)
    at memoized (/Users/some-project/node_modules/lodash/lodash.js:10620:27)
    at /Users/some-project/node_modules/json-schema-to-typescript/dist/src/generator.js:145:55
    at generateRawType (/Users/some-project/node_modules/json-schema-to-typescript/dist/src/generator.js:147:15)
    at generateTypeUnmemoized (/Users/some-project/node_modules/json-schema-to-typescript/dist/src/generator.js:128:18)

Node.js v18.18.0

Current vs. Expected behavior

Current behavior: Error!

Expected behavior: generation of a docs page from the OpenAPI file

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.5.0: Wed May  1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 18.18.0
  npm: 9.8.1
  Yarn: 1.22.22
  pnpm: 8.12.0
Relevant Packages:
  next: 14.2.5 // Latest available version is detected (14.2.5).
  eslint-config-next: 14.2.5
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.5.4
Next.js Config:
  output: N/A

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

UI

Additional context

No response

@0sssama 0sssama added the bug Something isn't working label Jul 26, 2024
@0sssama 0sssama changed the title Issue with Nested Schemas Issue with Nested Schemas in OpenAPI generator Jul 26, 2024
@fuma-nama
Copy link
Owner

Looks like an upstream problem from bcherny/json-schema-to-typescript#482

I'll add an option to disable it as a temporarily fix

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