Is it possible to make Storybook.js working with very large auto-generated Typescript files (>200 classes)?

328 Views Asked by At

I'm having an issue with Storybook.js that I'm using with another library called NSwag TypeScriptClientGenerator.

So i'm not sure if it is a bug or if I have a bad configuration but here are the details.

TLDR version:

NSwag generates a huge API client file with hundred of classes. Then Storybook.js crashes when trying to load all those classes

More details:

I'm working on an angular project that consumes a REST API. This API has a lot of endpoints and i'm using NSwag in order to have compilation checks on this API calls.

NSwag read the API description (openAPI/swagger) and then generates a typescript file that describes all API endpoints and all parameters and return types.

This result in a very big typescript file with a lot of interfaces/classes/functions. There are more than 30k generated lines of code and file is 2mo.

Now comes Storybook.js. When I run npm run storybook the tool starts by creating the documentation.json file.

This file contains 1 json entry per class/interface and for each of those entries there is a sourceCode member that contains the file source code.

Problem is that the sourceCode member contains ALL the file code, not just the class or interface code.

As the file contains hundred of classes and interfaces then ALL those classes are described in documentation.json file, and ALL of those entries contains a sourceCode member that contains ALL the 30k lines of codes (in the screenshot, line 601 is 1,599,000 characters -> there are hundred of lines like this on the rest of the file).

Picture showing the sourceCode fill with all the API code

The resulting documentation.json file is more than 700mo. And the result is that storybook crashes while trying to parse that huge file.

Do you have any tips to fix that problem?

Question:

Is it possible to tell Storybook.js to ignore this file? If yes: are there some cons doing that?

Or is it possible to tell Storybook.js to not create this sourceCode entry?

Or maybe is it possible to ask NSwag Typescript Generator to generate one file per class?

0

There are 0 best solutions below