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

将Swagger 2.0转换为OpenAPI 3.0时遭遇结构错误的解决方法

解决Swagger 2.0转OpenAPI 3.0时的totalDigits结构错误

我在将Swagger 2.0文件转换为OpenAPI 3.0时遇到结构错误,涉及代码片段如下:

insuranceCompanyNbr:
    type: integer
    totalDigits: 6
  invoiceTypeInfo:
    $ref: '#/definitions/invoiceTypeInfo'
  submitterTypeId:
    type: string

收到的错误提示:

Error: Structural error at definitions.InvoiceType.properties.insuranceCompanyNbr.
should NOT have additional properties.
additionalProperty: totalDigits

解决办法

  • OpenAPI 3.0已废弃totalDigits属性,要限制整数位数,需通过minimum和maximum定义数值范围。6位整数的有效范围是100000至999999,直接用这两个属性替换totalDigits即可。
  • 另外注意OpenAPI 3.0的组件定义路径是components/schemas,而非Swagger 2.0的definitions,所以invoiceTypeInfo的引用路径也需要同步调整。

修改后的代码片段:

insuranceCompanyNbr:
    type: integer
    minimum: 100000
    maximum: 999999
  invoiceTypeInfo:
    $ref: '#/components/schemas/invoiceTypeInfo'
  submitterTypeId:
    type: string

内容的提问来源于stack exchange,提问作者Kiran

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 01:15:31