Open evantahler opened 4 years ago
Try swagger-ui-react
instead of swagger-ui
.
swagger-ui-react
suffers from the same SSR rendering issues (relies on window
) and fails on server-side import. I chose "regular" swagger-ui
because it seems like it was able to be mounted dynamically more reliably
Also, even when using suspense to load swagger-ui-react
, the routes aren't displayed. Clicking on any produe the error:
swagger-ui.js:8 Uncaught TypeError: Cannot read property 'indexOf' of undefined
at value (swagger-ui.js:8)
at swagger-ui.js:1
at Connect.configureFinalMapState (connect.js:155)
at Connect.computeStateProps (connect.js:142)
at Connect.updateStatePropsIfNeeded (connect.js:204)
at Connect.render (connect.js:340)
at finishClassComponent (react-dom.development.js:17160)
at updateClassComponent (react-dom.development.js:17110)
at beginWork (react-dom.development.js:18620)
at HTMLUnknownElement.callCallback (react-dom.development.js:188)
at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
at invokeGuardedCallback (react-dom.development.js:292)
at beginWork$1 (react-dom.development.js:23203)
at performUnitOfWork (react-dom.development.js:22154)
at workLoopSync (react-dom.development.js:22130)
at performSyncWorkOnRoot (react-dom.development.js:21756)
This is my suspense loader to avoid the window
load errors
import { Suspense, lazy } from "react";
import Loader from "./../components/loader";
const SwaggerUI = lazy(() => import("swagger-ui-react"));
export default function ({ apiVersion }) {
return (
<div>
<Suspense fallback={<Loader />}>
<SwaggerUI
url={`https://petstore.swagger.io/v2/swagger.json`}
/>
</Suspense>
</div>
);
}
You can use the https://petstore.swagger.io/v2/swagger.json API endpoint to reproduce the error
Q&A (please complete the following information)
Content & configuration
Example Swagger/OpenAPI definition:
Swagger-UI configuration options:
Describe the bug you're encountering
When rendering
swagger-ui
with Next.js, none of the inputs forms' data is actually sent to the server in the API request. This manifests in a few ways:Required params look like they are never filled out
The defaults are always used, no matter what
To reproduce...
Steps to reproduce the behavior:
Expected behavior
Data the user types into the swagger ui should be sent to the server
Additional context or thoughts
The same swagger doc used on https://editor.swagger.io seems work fine. So I think the problem is isolated to the
swagger-ui
component. Also, something in Swagger might be conflicting with Next?