问题
Is there a way to pass json directly to SwaggerUIBundle instead of pass url? I want to use swagger-ui instead of SwaggerUIBundle, but I am also using react ^16, and wagger-ui doesn't support swagger-ui. So, I change to use SwaggerUIBundle. Please anyone know either how to use swagger-ui in react version 16+ or pass json into SwaggerUIBundle? Thx and appreciated!
回答1:
To pass the spec as JSON, use the spec parameter:
const ui = SwaggerUIBundle({
// BEGIN SPEC
spec: {
swagger: '2.0',
info: {
title: "test",
version: '1.0.0'
},
paths: {
'/foo': {
get: {
responses: {
'200': {
description: 'OK'
}
}
}
}
}
},
// END SPEC
dom_id: '#swagger-ui',
...
Please anyone know either how to use swagger-ui in react version 16+
Use swagger-ui-react.
来源:https://stackoverflow.com/questions/51775766/how-to-pass-json-to-swaggeruibundle