You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swagger 2.0定义testPOST出现额外属性错误,求排查方案

问题分析与解决

错误原因

Swagger 2.0对schema定义有严格的结构要求:定义对象类型的schema时,必须显式声明type: object,并且所有属性都要嵌套在properties字段下。你的testPOST定义直接将testRequests作为顶级键,没有遵循这个结构规范,因此被校验器判定为"额外属性"。

修正后的代码

将testPOST的结构调整为符合Swagger规范的格式:

definitions:
  testPOST:
    type: object  # 必须声明为object类型
    properties:   # 所有属性都要放在properties下
      testRequests:
        type: array
        items:
          type: object
          properties:
            sourceUrl:
              type: string
              example: 'http://example.com/test/1202112'
              description: The reference url.
              default: 'null'
            inboundReferenceNumber:
              type: string
              example: '1234567890'
              description: The request identifier.
              default: 'null'

说明

  • 添加type: object:明确告知Swagger这是一个对象类型的schema
  • 把testRequests移入properties:符合Swagger对对象属性的定义规则

这样调整后,校验器就会认可testRequests作为testPOST对象的合法属性,不会再抛出额外属性的错误。

内容的提问来源于stack exchange,提问作者Mr J.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 13:15:38