我正在尝试使用Loopback的Swagger connector(假设这是此连接器的作用!),从一个庞大的文件(my-api.json
)创建一个api模型。
但是,在运行loopback-cli时,出现以下错误:
? Enter the swagger spec url or file path: my-api.json
Loading my-api.json...
events.js:183
throw er; // Unhandled 'error' event
^
TypeError: Cannot read property '$ref' of null
at C:\Users\Nick\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\generator-loopback\swagger\spec-loader.js:124:13
at baseClone (C:\Users\Nick\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\lodash\lodash.js:2641:27)
at C:\Users\Nick\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\lodash\lodash.js:2711:34
at arrayEach (C:\Users\Nick\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\lodash\lodash.js:516:11)
at baseClone (C:\Users\Nick\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\lodash\lodash.js:2705:7)
at C:\Users\Nick\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\lodash\lodash.js:2711:34
at arrayEach (C:\Users\Nick\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\lodash\lodash.js:516:11)
at baseClone (C:\Users\Nick\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\lodash\lodash.js:2705:7)
at Function.cloneDeepWith (C:\Users\Nick\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\lodash\lodash.js:11120:14)
at parseSpec (C:\Users\Nick\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\generator-loopback\swagger\spec-loader.js:123:19)
at C:\Users\Nick\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\generator-loopback\swagger\spec-loader.js:160:5
at C:\Users\Nick\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\generator-loopback\swagger\spec-loader.js:86:11
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)
这是my-api-json
招摇文件:
{
"swagger": "2.0",
"info": {
"description": "my description",
"version": "0.0.2",
"title": "my title",
"termsOfService": "TBD",
"contact": {
"name": "John Doe",
"url": "http://www.myname.com",
"email": "johndoe@aol.com"
},
"license": {
"name": "TBD",
"url": "http://www.myname.com"
},
"x-classificationRecord": "Classsification of this swagger file - APPROVED"
},
"basePath": "/myPath",
"schemes": [
"http",
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"securityDefinitions": {
"AdminSecurity": {
"type": "apiKey",
"in": "query",
"name": "apikey"
}
},
"paths": {
"/admin/vcap": {
"get": {
"tags": [
"admin"
],
"security": [
{
"AdminSecurity": []
}
],
"x-swagger-router-controller": "misc_info_controller",
"operationId": "getVCAP",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/query/getAllTopicEntity": {
"get": {
"tags": [
"database"
],
"x-swagger-router-controller": "db",
"operationId": "getAllTopicEntity",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/query/getAllTopic": {
"get": {
"tags": [
"database"
],
"x-swagger-router-controller": "db",
"operationId": "getAllTopic",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/query/getAllEntityFacets": {
"get": {
"tags": [
"database"
],
"x-swagger-router-controller": "db",
"operationId": "getAllEntityFacets",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/query/getAllTopicEntityFacets": {
"get": {
"tags": [
"database"
],
"x-swagger-router-controller": "db",
"operationId": "getAllTopicEntityFacets",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/query/getAllTopicEntityRelation": {
"get": {
"tags": [
"database"
],
"x-swagger-router-controller": "db",
"operationId": "getAllTopicEntityRelation",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/query/getAllTopicPropertyFacet": {
"get": {
"tags": [
"database"
],
"x-swagger-router-controller": "db",
"operationId": "getAllTopicPropertyFacet",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/query/getAllTable13": {
"get": {
"tags": [
"database"
],
"x-swagger-router-controller": "db",
"operationId": "getAllTable13",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/query/getAlltblComponentType": {
"get": {
"tags": [
"database"
],
"x-swagger-router-controller": "db",
"operationId": "getAlltblComponentType",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/query/getAlltblElement": {
"get": {
"tags": [
"database"
],
"x-swagger-router-controller": "db",
"operationId": "getAlltblElement",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/query/getAlltblFeature": {
"get": {
"tags": [
"database"
],
"x-swagger-router-controller": "db",
"operationId": "getAlltblFeature",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/query/getAlltblSymbolPlacementInst": {
"get": {
"tags": [
"database"
],
"x-swagger-router-controller": "db",
"operationId": "getAlltblSymbolPlacementInst",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/query/getAlltblSymbolElementLink": {
"get": {
"tags": [
"database"
],
"x-swagger-router-controller": "db",
"operationId": "getAlltblSymbolElementLink",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/query/getAlltblSymol": {
"get": {
"tags": [
"database"
],
"x-swagger-router-controller": "db",
"operationId": "getAlltblSymol",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/query/newQuery": {
"get": {
"tags": [
"database"
],
"x-swagger-router-controller": "db",
"operationId": "newQuery",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Success"
}
}
}
}
},
"definitions": {
"Generic": {
"properties": {
"message": {
"type": "string"
}
}
},
"GenericError": {
"required": [
"status",
"statusCode",
"error"
],
"properties": {
"status": {
"type": "string",
"description": "Status indicating there was an error, should always be error",
"enum": [
"error"
]
},
"statusCode": {
"type": "number",
"description": "HTTP Status Code for the error"
},
"error": {
"type": "string",
"description": "String indicating what the error was"
},
"trace": {
"type": "string",
"description": "Original Error Message providing more detail if available"
}
}
},
"ErrorResponse": {
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "integer"
},
"message": {
"type": "string"
}
}
}
}
}
有关如何修复的任何提示?谢谢。