OpenAPI 鉴别器的一个默认值

标签 openapi

给定以下 OpenAPI YAML,我们是否总是需要在创建 Pet 时定义 petType

我可以在不指定 petType 的情况下默认创建类型为 Dog 的宠物吗?有什么方法可以用 OpenAPI 做到这一点吗?

Pet:
 oneOf:
  - $ref: '#/components/schemas/Cat'
  - $ref: '#/components/schemas/Dog'
  - $ref: '#/components/schemas/Lizard'
  discriminator:
     propertyName: petType

最佳答案

do we always need to define petType while creating Pet

是的。如 Discriminator Object 中所述OpenAPI 规范部分(强调我的):

a discriminator MAY act as a "hint" to ... selection of the matching schema ... We can then describe exactly which field tells us which schema to use:
...
The expectation now is that a property with name petType MUST be present in ... payload, and the value will correspond to the name of a schema defined in the OAS document.

关于OpenAPI 鉴别器的一个默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63910059/

相关文章:

kubernetes - 如何在我自己的 CRD Controller 中重用 k8s 验证

android - 构建 Android 应用程序时如何从 gradle 生成 OpenAPI 源

java - springdoc-openapi 应用默认的全局 SecurityScheme 可能吗?

时间:2019-04-01 标签:c#swagger openapi erronous refs when nested classes

rest - 开放 API 与 REST API - 区别

jwt - 如何从 go-swagger 中的 API 处理程序函数访问 JWT 声明?

python - (Swagger 2.0/Connexion) None 类型不是 'string' 类型

amazon-web-services - AWS SAM::AWS::Serverless::Api "Invalid value for ' Auth' 属性”

java - UnitTest call/swagger-ui.html 导致 springdoc-openapi 出现 404

swagger - 如何在 OpenAPI 3 中定义另一个模式的数组?