Skip to content

Commit

Permalink
fix(swagger-ui-react): call onComplete hook with system instance (#9895)
Browse files Browse the repository at this point in the history
Refs #9876
  • Loading branch information
char0n committed Apr 30, 2024
1 parent 8c90d5d commit 3f67b08
Showing 1 changed file with 38 additions and 40 deletions.
78 changes: 38 additions & 40 deletions flavors/swagger-ui-react/index.jsx
Expand Up @@ -3,7 +3,7 @@
*/
"use client"

import React, { useEffect, useCallback, useState } from "react"
import React, { useEffect, useState } from "react"
import PropTypes from "prop-types"
import SwaggerUIConstructor from "#swagger-ui"

Expand Down Expand Up @@ -41,46 +41,44 @@ const SwaggerUI = ({
const [system, setSystem] = useState(null)
const SwaggerUIComponent = system?.getComponent("App", "root")

const handleComplete = useCallback(() => {
if (typeof onComplete === "function") {
onComplete()
}
}, [onComplete])

useEffect(() => {
setSystem(
SwaggerUIConstructor({
plugins,
spec,
url,
layout,
defaultModelsExpandDepth,
defaultModelRendering,
presets: [SwaggerUIConstructor.presets.apis, ...presets],
requestInterceptor,
responseInterceptor,
onComplete: handleComplete,
docExpansion,
supportedSubmitMethods,
queryConfigEnabled,
defaultModelExpandDepth,
displayOperationId,
tryItOutEnabled,
displayRequestDuration,
requestSnippetsEnabled,
requestSnippets,
showMutatedRequest,
deepLinking,
showExtensions,
showCommonExtensions,
filter,
persistAuthorization,
withCredentials,
...(typeof oauth2RedirectUrl === "string"
? { oauth2RedirectUrl: oauth2RedirectUrl }
: {}),
})
)
const systemInstance = SwaggerUIConstructor({
plugins,
spec,
url,
layout,
defaultModelsExpandDepth,
defaultModelRendering,
presets: [SwaggerUIConstructor.presets.apis, ...presets],
requestInterceptor,
responseInterceptor,
onComplete: () => {
if (typeof onComplete === "function") {
onComplete(systemInstance)
}
},
docExpansion,
supportedSubmitMethods,
queryConfigEnabled,
defaultModelExpandDepth,
displayOperationId,
tryItOutEnabled,
displayRequestDuration,
requestSnippetsEnabled,
requestSnippets,
showMutatedRequest,
deepLinking,
showExtensions,
showCommonExtensions,
filter,
persistAuthorization,
withCredentials,
...(typeof oauth2RedirectUrl === "string"
? { oauth2RedirectUrl: oauth2RedirectUrl }
: {}),
})

setSystem(systemInstance)
}, [])

useEffect(() => {
Expand Down

0 comments on commit 3f67b08

Please sign in to comment.