Swagger模式中的oneOf不起作用

Swagger模式中的oneOf不起作用

本文介绍了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/Issues/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-11 05:55