gpt4 book ai didi

yaml - Swagger 文档错误 `Should be object`

转载 作者:行者123 更新时间:2023-12-05 06:17:33 28 4
gpt4 key购买 nike

我正在手动编写 swagger 文档。但是我遇到了一些错误 Should be object

我不知道为什么我在下面的代码中遇到错误。

events:
$ref: "#/def/Events"

Events:
type: "object"
properties:
oneOf:
- $ref: '#/def/ClassRef'
- $ref: '#/def/TypeRef'
- $ref: '#/def/EventRef'
- $ref: '#/def/MarketRef'
- $ref: '#/def/OutcomeRef'

ClassRef: # <--- I get the "should be object" error here
type: "object"
properties:
classRef:
type: "string"

TypeRef:
type: "object"
properties:
typeRef:
type: "string"

EventRef:
type: "object"
properties:
eventRef:
type: "string"

MarketRef:
type: "object"
properties:
marketRef:
type: "string"

OutcomeRef:
type: "object"
properties:
outcomeRef:
type: "string"

我在 ClassRef 行中收到此错误。有人可以帮帮我吗

最佳答案

OpenAPI 2.0 (swagger: '2.0') 不支持oneOf,需要OpenAPI 3.0 (openapi: 3.0.0)使用 oneOf

假设您使用 OpenAPI 3.0,并且所有模式都位于 components/schemas 部分,请按如下方式更改 Events 模式:

Events:
oneOf:
- $ref: '#/components/schemas/ClassRef'
- $ref: '#/components/schemas/TypeRef'
- $ref: '#/components/schemas/EventRef'
- $ref: '#/components/schemas/MarketRef'
- $ref: '#/components/schemas/OutcomeRef'

关于yaml - Swagger 文档错误 `Should be object`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61616027/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com