我想将PaymentMethod
定义如下。swagger.yaml是否支持oneOf?
PaymentMethod:
oneOf:
- $ref: '#/definitions/NewPaymentMethod'
- $ref: '#/definitions/ExistPaymentMethod'
ExistPaymentMethod
将只有id和cardNumber
,其中NewPaymentMethod
没有id
,但有所有其他详细信息,例如cardNumber
、cardholderName
、cardholderAddress
等。
发布于 2017-06-14 11:02:07
在OpenAPI版本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/
发布于 2016-05-01 10:24:02
Swagger所使用的仅受JSON Schema的启发。它们并没有太多偏离JSON Schema,但是它们省略了一些东西,添加了一些东西,并改变了一些行为。Swagger遗漏的一件事是oneOf
。
欲了解更多详情,请访问http://swagger.io/specification/#schemaObject。
发布于 2019-03-19 16:27:09
OneOf、anyOf和其他类似指令不受swagger 2.0支持,但在Open API3.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
https://stackoverflow.com/questions/36872277
复制相似问题