问题描述
我想如下定义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
,但是所有其他详细信息,例如cardNumber
,cardholderName
,cardholderAddress
等
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不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!