繁体   English   中英

Swagger 模式中的 oneOf 不起作用

[英]oneOf in Swagger schema does not work

我想定义PaymentMethod如下。 swagger.yaml 支持 oneOf 吗?

PaymentMethod:
      oneOf:
        - $ref: '#/definitions/NewPaymentMethod'
        - $ref: '#/definitions/ExistPaymentMethod'

ExistPaymentMethod将只有id和cardNumber其中NewPaymentMethod将没有id ,但所有其他的细节,如cardNumbercardholderNamecardholderAddress等。

oneOf版本 3 ( openapi: 3.0.0 ) 支持 oneOf,但 Swagger 版本 2 ( swagger: '2.0' ) 不支持。

PaymentMethod:
  oneOf:
    - $ref: '#/components/schemas/NewPaymentMethod'
    - $ref: '#/components/schemas/ExistPaymentMethod'

GitHub 问题参考: https : //github.com/OAI/OpenAPI-Specification/issues/333

有关 OpenAPI 3.0 与 2.0 相比的变化列表,请参阅: https ://blog.readme.io/an-example-filled-guide-to-swagger-3-2/

Swagger 使用的只是受到 JSON Schema 的启发。 他们没有过多地偏离 JSON Schema,但是他们省略了一些东西,添加了一些东西,并改变了一些行为。 Swagger 遗漏的一件事是oneOf

更多细节可以在http://swagger.io/specification/#schemaObject找到

OneOf、anyOf 和其他类似指令不受 Swagger 2.0 支持,但在 Open API 3.0 规范中受支持。

您需要将 Swagger 2.0 文件转换为 Open API 3.0 文件。

这是链接 - https://blog.runscope.com/posts/tutorial-upgrading-swagger-2-api-definition-to-openapi-3

这是一个更有用的链接 - https://github.com/swagger-api/swagger-ui/issues/3803

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM