我有以下简单的 swagger.json 文件。这是使用 go-swagger 注释为 golang 服务生成的。我能够让 UI 页面使用 redoc 运行。
我想用 swagger-ui 显示它,但我无法让它工作。它在页面加载时的控制台中显示一个错误,上面写着
Uncaught TypeError: Cannot create property 'definitions' on string 'swagger.json'(…)
window.swaggerUi = new SwaggerUi({
spec: "swagger.json",
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onComplete: function(swaggerApi, swaggerUi){
log("Loaded UI")
},
onFailure: function(data) {
log("Unable to Load SwaggerUI");
},
docExpansion: "none",
jsonEditor: false,
defaultModelRendering: 'schema',
showRequestHeaders: false
});
window.swaggerUi.load();
不知道为什么会这样
这是招摇文件
{
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"schemes": [
"http",
"https"
],
"swagger": "2.0",
"info": {
"description": "the purpose of this service is to do a health check",
"title": "Health Check API.",
"termsOfService": "TOS",
"contact": {
"name": "Backend",
"email": "Backend@company.com"
},
"license": {
"name": "Company Licence"
},
"version": "0.0.1"
},
"host": "host.com",
"basePath": "/",
"paths": {
"/health": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"schemes": [
"http",
"https"
],
"summary": "Health check route.",
"operationId": "health",
"responses": {}
}
}
},
"definitions": {}
}