将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
相关产品推荐
相关产品推荐

