JSON响应中的嵌套对象

时间:2018-12-04 16:02:12

标签: json swagger

我正在如下定义我的swagger文件:

{
  "swagger": "2.0",
  "info": {
    "title": "PSD2 Account  API Specification",
    "description": "PSD2 Account Swagger API Specification",
    "version": "1.0.0"
  },
  "schemes": [
    "https"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "securityDefinitions": {
    "basicAuth": {
      "type": "basic"
    }
  },
  "security": [
    {
      "basicAuth": []
    }
  ],
  "paths": {
    "/accounts/{id}/transactionhistory": {
      "get": {
        "tags": [
          "Accounts"
        ],
        "summary": "Get transaction history",
        "operationId": "GetTransactionHistory",
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "fromDate",
            "in": "query",
            "required": false,
            "type": "string"
          },
          {
            "name": "toDate",
            "in": "query",
            "required": false,
            "type": "string",
            "format": "date"
          },
          {
            "name": "sumOrDetail",
            "in": "query",
            "required": false,
            "type": "string"
          },
          {
            "name": "noOfEntries",
            "in": "query",
            "required": false,
            "type": "string"
          },
          {
            "name": "toTime",
            "in": "query",
            "required": false,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/definitions/200TransactionHistory"
          }
        }
      }
    }
  },
  "definitions": {
    "200TransactionHistory": {
      "type": "object",
      "properties": {
        "amount": {
          "type": "string",
          "maxLength": 25
        },
        "txnCodeDesc": {
          "type": "string"
        },
        "accountDesc": {
          "type": "string"
        },
        "txnCurrency": {
          "type": "string",
          "maxLength": 3
        },
        "accountIBAN": {
          "type": "string"
        },
        "valueDate": {
          "type": "string",
          "format": "date"
        },
        "transactionCode": {
          "type": "object",
          "properties": {
            "code": {
              "type": "string",
              "maxLength": 3
            },
            "subcode": {
              "type": "string",
              "maxLength": 3
            }
          }
        },
        "executionEndTime": {
          "type": "string"
        },
        "stmtEntryId": {
          "type": "string",
          "maxLength": 90
        },
        "accountId": {
          "type": "string"
        },
        "transReference": {
          "type": "string",
          "maxLength": 60
        },
        "exchangeRate": {
          "type": "string",
          "maxLength": 11
        },
        "remittanceInformation": {
          "type": "string",
          "maxLength": 65
        },
        "payeeCustomer": {
          "type": "string"
        },
        "closeBalance": {
          "type": "string"
        },
        "bookingDate": {
          "type": "string",
          "format": "date"
        },
        "currency": {
          "type": "string",
          "maxLength": 3
        },
        "id": {
          "type": "string"
        },
        "txnCurrencyAmount": {
          "type": "string",
          "maxLength": 25
        },
        "payeeAccount": {
          "type": "string"
        },
        "openBalance": {
          "type": "string"
        }
      }
    }
  }
}

有一个简单的GET请求,我希望响应中具有以下格式:

"transactionCode": {
          "code": "thisIsTheCode",
          "SubsubCode": "thisIsTheSubCode"
        }

如您在响应定义中看到的,这就是我嵌套对象的方式:

"transactionCode": {
  "type": "object",
  "properties": {
    "code": {
      "type": "string",
      "maxLength": 3
    },
    "subcode": {
      "type": "string",
      "maxLength": 3
    }
  }
}

当我测试来自邮递员的请求时,我收到以下错误消息:

com.fasterxml.jackson.core.JsonParseException: Unexpected character ('}' (code 125)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: {"header":{"audit":{"T24_time":107,"parse_time":0},"page_start":0,"page_token":"5fc34084-2496-41f0-a968-084b3b519c88","total_size":0,"page_size":50},"body":}; line: 1, column: 158]

谁能告诉我我在做什么错?我在响应中嵌套对象的方式有问题吗?

0 个答案:

没有答案