我有下面的JSON,它是我自己从代码中生成的。我基本上是在编写代码来为UI生成swagger规范。我正在写一个新的,因为我仍然使用play 1.3,而swagger模块已经有一段时间没有更新了。然而,我从代码生成器中得到了这个JSON,但UI挂在"获取资源列表:http://localhost:9100/resources.json;请稍候。javascript控制台显示错误"Getting"Cannot read property‘parameters’of null"for swagger spec"。我不知道该怎么办,如有任何帮助,将不胜感激。
{
"swagger": "2.0",
"info": null,
"host": null,
"basePath": null,
"tags": [
{
"name": "payments",
"description": null,
"externalDocs": null
}
],
"schemes": null,
"consumes": null,
"produces": null,
"paths": {
"/": {
"get": {
"tags": [
"payments"
],
"summary": "/payment_methods",
"description": "",
"operationId": "paymentMethods",
"schemes": null,
"consumes": null,
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"default": {
"description": "successful operation",
"schema": null,
"examples": null,
"headers": null
}
},
"security": null,
"externalDocs": null,
"deprecated": null
},
"head": null,
"post": {
"tags": [
"payments"
],
"summary": null,
"description": null,
"operationId": "addPaypalAccount",
"schemes": null,
"consumes": null,
"produces": null,
"parameters": [],
"responses": {
"default": {
"description": "successful operation",
"schema": null,
"examples": null,
"headers": null
}
},
"security": null,
"externalDocs": null,
"deprecated": null
},
"put": null,
"delete": {
"tags": [
"payments"
],
"summary": null,
"description": null,
"operationId": "deletePaypalAccount",
"schemes": null,
"consumes": null,
"produces": null,
"parameters": [],
"responses": {
"default": {
"description": "successful operation",
"schema": null,
"examples": null,
"headers": null
}
},
"security": null,
"externalDocs": null,
"deprecated": null
},
"options": null,
"patch": null,
"parameters": null
}
},
"securityDefinitions": null,
"definitions": null,
"parameters": null,
"responses": null,
"externalDocs": null,
"securityRequirement": null
}
问题在于null
值。它们需要被禁用——null不同于"不存在"。也就是说,我认为您需要将映射器配置为不写null。
我遇到了这个问题,结果发现它与我的.NET web api应用程序中的JSON格式化程序有关。我能够通过将这一行添加到BootStrap类Configure方法中来解决它。
config.Formatters.Clear();