获取"无法读取属性'参数' of null"对于swagger规范

时间:2015-12-21 19:34:53

标签: swagger swagger-ui swagger-2.0 swagger-editor

我有自己从代码生成的以下JSON。我基本上编写代码来为UI生成swagger规范。我正在写一个新的,因为我仍然使用play 1.3,并且swagger模块暂时没有更新。但是,我从我的代码生成器中获取了这个JSON,但是UI挂起了"获取资源列表:http://localhost:9100/resources.json;请稍候。" javascript控制台显示错误"获取"无法读取属性'参数' of null"对于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
}

2 个答案:

答案 0 :(得分:2)

问题是null值。需要禁用它们 - null与“not present”不同。也就是说,我相信您需要配置您的映射器以不写空值。

答案 1 :(得分:1)

我遇到了这个问题,事实证明它与.NET Web API应用程序中的JSON格式化程序有关。通过将此行添加到BootStrap类的Configure方法中,可以解决该问题。

config.Formatters.Clear();