swagger-api / swagger-api/swagger-codegen
"html2" generated documentation fails with Maximum call stack size exceeded
@HugoMario is already working on this.
Since Sep 14, 2019.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When using swagger-codegen-maven-plugin to generate documentation in the "html2" format, responses that contain elements that have recursive definitions (in this case a tree node) do not display. This is not just limited to documentation generated through maven, but seems to be anything that generates "html2" documentation (for example I also tested using SwaggerHub and got the same error). Everything else in the documentation continues to display fine, but the browser console shows the following exception:
Uncaught RangeError: Maximum call stack size exceeded
at Array.toString (native)
at helpers.js:29
at Array.reduce (<anonymous>)
at normal (helpers.js:28)
at JSONSchemaView.template (index.js:244)
at JSONSchemaView.render (index.js:305)
at JSONSchemaView.appendChildren (index.js:345)
at JSONSchemaView.render (index.js:312)
at index.js:352
at Array.forEach (<anonymous>)
The error obviously implies that the code is attempting to recursively create the response structure until it runs out of stack space rather than recognizing the recursive nature and stopping.
Please note the above stacktrace is what appears in the console using Chrome. The same failure occurs in all browsers, though the exact nature of the stacktrace/error message is different in each.
Swagger-codegen version
swagger-codegen-maven-plugin 2.3.1 and 3.0.0-rc1
Swagger declaration file content or url
{
"swagger" : "2.0",
"info" : {
"description" : "HTML2 Generation Bug Sample",
"version" : "v1",
"title" : "HTML2 Generation Bug Sample"
},
"host" : "localhost:8080",
"basePath" : "/rest",
"tags" : [ {
"name" : "test"
} ],
"schemes" : [ "http", "https" ],
"paths" : {
"/test/getRecursiveReponse" : {
"get" : {
"tags" : [ "test" ],
"summary" : "Get a recursively defined response",
"description" : "Get a recursively defined response",
"operationId" : "getRecursiveResponse",
"produces" : [ "application/json" ],
"parameters" : [ {
"name" : "itemID",
"in" : "test",
"description" : "The id of the starting point of the response.",
"required" : true,
"type" : "string"
} ],
"responses" : {
"200" : {
"description" : "successful operation",
"schema" : {
"$ref" : "#/definitions/TreeNode"
}
}
}
}
}
},
"definitions" : {
"TreeNode" : {
"type" : "object",
"required" : [ "id" ],
"properties" : {
"id" : {
"type" : "string",
"description" : "The id of this node"
},
"children" : {
"type" : "array",
"description" : "A list of the children for this node",
"items" : {
"$ref" : "#/definitions/TreeNode"
}
}
}
}
}
}
Command line used for generation
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/webapp/swagger.json</inputSpec>
<language>html2</language>
<output>${project.build.directory}/apidocs</output>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
- Create a maven project with the json listed above in a file called swagger.json in the /src/main/webapp directory.
- Add the given plugin into the pom.xml plugins section.
- Run maven clean install against the project.
- In the output directory, in the apidocs folder, open the index.html file in Google Chrome. The "Schema" section under responses will show as blank. Opening the Developer Tools window and changing to the console pane will show the stacktrace above.
Alternatively:
- Create a file on your desktop called swagger.json with the contents of the JSON section above.
- Go to https://app.swaggerhub.com/home and login.
- In the MyHub section click on the plus sign on the left hand side of the page and choose Import and Document API.
- Use the Browse button in the dialog that appears to find ans select the swagger.json file you just created and click the Upload File, then Import OpenAPI buttons.
- On the following screen choose the Download button toward the upper right side of the screen, and in the submenus that pop up choose Client and then html2. When prompted, save the zipfile to your desktop.
- Extract the contents the zipfile into a folder.
- In the folder, open the index.html file in Google Chrome. The "Schema" section under responses will show as blank. Opening the Developer Tools window and changing to the console pane will show the stacktrace above.
Related issues/PRs
Possibly related to this in the swagger-ui code:
https://github.com/swagger-api/swagger-ui/issues/2923
Suggest a fix/enhancement
A similar problem was fixed in the swagger-js code, the solution in the reference issue above and can probably be inferred from there.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.