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

redoc-cli v0.12.1: crash with OpenAPI 3.1 type as array of strings in requestBody #1697

Closed
TheEdward162 opened this issue Jul 15, 2021 · 0 comments · Fixed by #1700
Closed
Assignees

Comments

@TheEdward162
Copy link

Hello, recently I've decided to try out redoc to render my OpenAPI 3.1 spec.

At first I installed a vscode plugin which comes with a bundled preview. That preview uses version 2.0.0-rc.50 of redoc which doesn't even support 3.1. The preview renders like this, which I find acceptable:

tmp

Later I wanted to render a standalone version using redoc-cli:

npx redoc-cli bundle test.openapi.json gives me:

Prerendering docs
TypeError: Cannot read property 'schema' of undefined
    at r.value (/Users/edward/.npm/_npx/088c5868f11c5564/node_modules/redoc-cli/node_modules/redoc/bundles/redoc.lib.js:2:254641)
    at processChild (/Users/edward/.npm/_npx/088c5868f11c5564/node_modules/redoc-cli/node_modules/react-dom/cjs/react-dom-server.node.development.js:3450:18)
    at resolve (/Users/edward/.npm/_npx/088c5868f11c5564/node_modules/redoc-cli/node_modules/react-dom/cjs/react-dom-server.node.development.js:3270:5)
    at ReactDOMServerRenderer.render (/Users/edward/.npm/_npx/088c5868f11c5564/node_modules/redoc-cli/node_modules/react-dom/cjs/react-dom-server.node.development.js:3753:22)
    at ReactDOMServerRenderer.read (/Users/edward/.npm/_npx/088c5868f11c5564/node_modules/redoc-cli/node_modules/react-dom/cjs/react-dom-server.node.development.js:3690:29)
    at Object.renderToString (/Users/edward/.npm/_npx/088c5868f11c5564/node_modules/redoc-cli/node_modules/react-dom/cjs/react-dom-server.node.development.js:4298:27)
    at /Users/edward/.npm/_npx/088c5868f11c5564/node_modules/redoc-cli/index.js:220:29
    at Generator.next (<anonymous>)
    at fulfilled (/Users/edward/.npm/_npx/088c5868f11c5564/node_modules/redoc-cli/index.js:6:58)

While npx redoc-cli serve test.openapi.json runs the webserver and then on the page outputs:

Something went wrong...
e is undefined

Stack trace

value@http://localhost:8080/redoc.standalone.js:2:929600
Ba@http://localhost:8080/redoc.standalone.js:2:484053
Ua@http://localhost:8080/redoc.standalone.js:2:483852
Bs@http://localhost:8080/redoc.standalone.js:2:524451
kl@http://localhost:8080/redoc.standalone.js:2:510832
xl@http://localhost:8080/redoc.standalone.js:2:510760
bl@http://localhost:8080/redoc.standalone.js:2:510621
pl@http://localhost:8080/redoc.standalone.js:2:507696
Wo/<@http://localhost:8080/redoc.standalone.js:2:457404
53/t.unstable_runWithPriority@http://localhost:8080/redoc.standalone.js:2:547935
$o@http://localhost:8080/redoc.standalone.js:2:457181
Wo@http://localhost:8080/redoc.standalone.js:2:457351
Vo@http://localhost:8080/redoc.standalone.js:2:457284
sl@http://localhost:8080/redoc.standalone.js:2:505075
_a@http://localhost:8080/redoc.standalone.js:2:476804
e/<@http://localhost:8080/redoc.standalone.js:2:810133
u@http://localhost:8080/redoc.standalone.js:2:538867
c/i._invoke</<@http://localhost:8080/redoc.standalone.js:2:538656
E/</<@http://localhost:8080/redoc.standalone.js:2:539292
Da@http://localhost:8080/redoc.standalone.js:2:763245
a@http://localhost:8080/redoc.standalone.js:2:763451

ReDoc Version: 2.0.0-rc.54
Commit: bcfae6ac

I reduced the problem down to the following document:

{
	"openapi": "3.1.0",
	"info": {
		"title": "API",
		"version": "1.0.0"
	},
	"paths": {
		"/api": {
			"summary": "Do things",
			"put": {
				"description": "Puts thing",
				"requestBody": {
					"content": {
						"application/json": {
							"schema": {
								"type": ["integer", "string"]
							}
						}
					},
					"required": true
				},
				"responses": {
					"200": {}
				}
			}
		}
	}
}

Specifically to the "type": ["integer", "string"] schema under requestBody. This doesn't happen if such schema appears under a response, only when under requestBody. It also doesn't matter what types are in the array, only that it is an array. An empty array, one-element array and multi-element array produce the same error.

The 2.0.0-rc.50 version also seems to correctly handle one-element arrays as if they were only the contained element (i.e. "type": ["string"] correctly previews to "string" type).

Then, since the 2.0.0-rc.50 version seemed to work I checked out npx [email protected] bundle test.openapi.json and it indeed rendered the docs the same way as the preview in the plugin did. It doesn't even mind the "openapi": "3.1.0" entry as the 2.0.0-rc.53 version does.

Lastly I also checked 2.0.0-rc.55 that is available on the demo page and the same error appears as with 2.0.0-rc.54 so on master this is broken.

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

Successfully merging a pull request may close this issue.

3 participants