fix(swagger-ui-react): call onComplete hook with system instance (#9895)
Refs #9876
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import React, { useEffect, useCallback, useState } from "react"
|
import React, { useEffect, useState } from "react"
|
||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import SwaggerUIConstructor from "#swagger-ui"
|
import SwaggerUIConstructor from "#swagger-ui"
|
||||||
|
|
||||||
@@ -41,46 +41,44 @@ const SwaggerUI = ({
|
|||||||
const [system, setSystem] = useState(null)
|
const [system, setSystem] = useState(null)
|
||||||
const SwaggerUIComponent = system?.getComponent("App", "root")
|
const SwaggerUIComponent = system?.getComponent("App", "root")
|
||||||
|
|
||||||
const handleComplete = useCallback(() => {
|
|
||||||
if (typeof onComplete === "function") {
|
|
||||||
onComplete()
|
|
||||||
}
|
|
||||||
}, [onComplete])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSystem(
|
const systemInstance = SwaggerUIConstructor({
|
||||||
SwaggerUIConstructor({
|
plugins,
|
||||||
plugins,
|
spec,
|
||||||
spec,
|
url,
|
||||||
url,
|
layout,
|
||||||
layout,
|
defaultModelsExpandDepth,
|
||||||
defaultModelsExpandDepth,
|
defaultModelRendering,
|
||||||
defaultModelRendering,
|
presets: [SwaggerUIConstructor.presets.apis, ...presets],
|
||||||
presets: [SwaggerUIConstructor.presets.apis, ...presets],
|
requestInterceptor,
|
||||||
requestInterceptor,
|
responseInterceptor,
|
||||||
responseInterceptor,
|
onComplete: () => {
|
||||||
onComplete: handleComplete,
|
if (typeof onComplete === "function") {
|
||||||
docExpansion,
|
onComplete(systemInstance)
|
||||||
supportedSubmitMethods,
|
}
|
||||||
queryConfigEnabled,
|
},
|
||||||
defaultModelExpandDepth,
|
docExpansion,
|
||||||
displayOperationId,
|
supportedSubmitMethods,
|
||||||
tryItOutEnabled,
|
queryConfigEnabled,
|
||||||
displayRequestDuration,
|
defaultModelExpandDepth,
|
||||||
requestSnippetsEnabled,
|
displayOperationId,
|
||||||
requestSnippets,
|
tryItOutEnabled,
|
||||||
showMutatedRequest,
|
displayRequestDuration,
|
||||||
deepLinking,
|
requestSnippetsEnabled,
|
||||||
showExtensions,
|
requestSnippets,
|
||||||
showCommonExtensions,
|
showMutatedRequest,
|
||||||
filter,
|
deepLinking,
|
||||||
persistAuthorization,
|
showExtensions,
|
||||||
withCredentials,
|
showCommonExtensions,
|
||||||
...(typeof oauth2RedirectUrl === "string"
|
filter,
|
||||||
? { oauth2RedirectUrl: oauth2RedirectUrl }
|
persistAuthorization,
|
||||||
: {}),
|
withCredentials,
|
||||||
})
|
...(typeof oauth2RedirectUrl === "string"
|
||||||
)
|
? { oauth2RedirectUrl: oauth2RedirectUrl }
|
||||||
|
: {}),
|
||||||
|
})
|
||||||
|
|
||||||
|
setSystem(systemInstance)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user