本文介绍了Swagger 模式中的 oneOf 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想定义 PaymentMethod 如下.swagger.yaml 中是否支持 oneOf?

I want to define PaymentMethod as below. Is oneOf supported in swagger.yaml?

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

ExistPaymentMethod 将只有 id,而 cardNumber 其中 NewPaymentMethod 将没有 id,但所有其他细节,例如cardNumbercardholderNamecardholderAddress

The ExistPaymentMethod will have just id, and cardNumber where NewPaymentMethod will have no id, but all other details, e.g. cardNumber, cardholderName, cardholderAddress etc.

推荐答案

oneOf 在 OpenAPI 版本 3 (openapi: 3.0.0) 中受支持,但在 Swagger 中不支持版本 2 (swagger: '2.0').

oneOf is supported in OpenAPI version 3 (openapi: 3.0.0), but not in Swagger version 2 (swagger: '2.0').

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

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

GitHub issue ref: 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/

For a list of changes in OpenAPI 3.0 compared to 2.0, see: https://blog.readme.io/an-example-filled-guide-to-swagger-3-2/

这篇关于Swagger 模式中的 oneOf 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 18:33