dotnet / dotnet/docfx

Swagger API docs generation: Error: Max. depth level of JSON reached at position

Open
#10,393 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4.4k
Forks
890
Avg merge
2h 11m
Merged PRs (30d)
10

Description

**Describe the issue**
I am facing an issue that when having a **really** large swagger.json (15+ thousand lines, size was 7.538 MB), the json stringify or parse function will fail with the error message `Error: Max. depth level of JSON reached at position xxx`.

**To Reproduce**
Steps to reproduce the behavior:
1. Have a really large swagger.json
2. Let docfx parse it
3. See the error message output

**Expected behavior**
docfx is able to parse the swagger.json without issues.

**Context (please complete the following information):**
- OS: Windows 11 (Build 22631.4460)
- Docfx version: 2.77.0

**Additional context**
A swagger.json with around 10k lines doesn't fail. The issue seems to be caused by an underlying JS library that has the limit, but I am not a specialist there to be able to tell what exactly is going on. I am not able to share the swagger.json due to NDA. Full stacktrace:

```
: error ApplyTemplatePreprocessorError: Error transforming model "" generated from "" using "RestApi.html.primary.js". Error running Transform function inside template preprocessor: Error: Max. depth level of JSON reached at position 889036
at parse RestApi.common.js:297:22
at addDefinition (definition, definitions) RestApi.common.js:297:22
at addComplexTypeMetadata (child, definitions) RestApi.common.js:339:9
at forEach RestApi.common.js:88:72
at forEach RestApi.common.js:88:17
at forEach RestApi.common.js:87:13
at RestApi.common.js:86:9
DocumentException: Error transforming model "" generated from "" using "RestApi.html.primary.js". Error running Transform function inside template preprocessor: Error: Max. depth level of
JSON reached at position 889036
at parse RestApi.common.js:297:22
at addDefinition (definition, definitions) RestApi.common.js:297:22
at addComplexTypeMetadata (child, definitions) RestApi.common.js:339:9
at forEach RestApi.common.js:88:72
at forEach RestApi.common.js:88:17
at forEach RestApi.common.js:87:13
at RestApi.common.js:86:9
DocumentException: Error transforming model "" generated from "" using "RestApi.html.primary.js". Error running Transform function inside template preprocessor: Error: Max. depth
level of JSON reached at position 889036
at parse RestApi.common.js:297:22
at addDefinition (definition, definitions) RestApi.common.js:297:22
at addComplexTypeMetadata (child, definitions) RestApi.common.js:339:9
at forEach RestApi.common.js:88:72
at forEach RestApi.common.js:88:17
at forEach RestApi.common.js:87:13
at RestApi.common.js:86:9
InvalidPreprocessorException: Error running Transform function inside template preprocessor: Error: Max. depth level of JSON reached at position 889036
at parse RestApi.common.js:297:22
at addDefinition (definition, definitions) RestApi.common.js:297:22
at addComplexTypeMetadata (child, definitions) RestApi.common.js:339:9
at forEach RestApi.common.js:88:72
at forEach RestApi.common.js:88:17
at forEach RestApi.common.js:87:13
at RestApi.common.js:86:9
at object TransformModel(object model) in PreprocessorWithResourcePool.cs:81
at object TransformModel(object model) in Template.cs:95
at ManifestItem Transform(InternalManifestItem item) in TemplateModelTransformer.cs:98
at ManifestItem Transform(InternalManifestItem item) in TemplateModelTransformer.cs:115
at void b__0(InternalManifestItem item) in TemplateProcessor.cs:194
at void b__0(TElement s) in DocumentExceptionExtensions.cs:80
at void RunAll(IEnumerable elements, Action action, int parallelism) in DocumentExceptionExtensions.cs:89
at void RunAll(IReadOnlyList elements, Action action, int parallelism) in DocumentExceptionExtensions.cs:60
at List ProcessCore(List items, ApplyTemplateSettings settings, IDictionary globals) in TemplateProcessor.cs:189
at List Process(List manifest, ApplyTemplateSettings settings, IDictionary globals) in TemplateProcessor.cs:88
at List ProcessTemplate() in ManifestProcessor.cs:182
at void Process() in ManifestProcessor.cs:53
at void Handle(List hostServices, int maxParallelism) in LinkPhaseHandler.cs:32
at Manifest Build(DocumentBuildParameters parameters, IMarkdownService markdownService) in SingleDocumentBuilder.cs:67
at void Build(IList parameters, string outputDirectory) in DocumentBuilder.cs:122
at void BuildDocument(BuildJsonConfig config, BuildOptions options, TemplateManager templateManager, string baseDirectory, string outputDirectory, string templateDirectory) in DocumentBuilderWrapper.cs:42
at string Exec(BuildJsonConfig config, BuildOptions options, string configDirectory, string outputDirectory) in RunBuild.cs:39
at void b__0() in DefaultCommand.cs:51
at int Run(LogOptions options, Action run) in CommandHelper.cs:48
at int Execute(CommandContext context, Options options) in DefaultCommand.cs:31
at Task Execute(CommandContext context, CommandSettings settings) in CommandOfT.cs:40
at async Task Execute(CommandTree leaf, CommandTree tree, CommandContext context, ITypeResolver resolver, IConfiguration configuration) in CommandExecutor.cs:166
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.