【发布时间】:2020-03-14 05:06:20
【问题描述】:
我正在尝试使用 AWS API Gateway 实现在 Swagger 或 OpenAPI 3.0 中定义的 API。
此 API 中的一个端点采用抽象基础模型(我们称其为 Pet 以与陈旧的 Swagger 示例保持一致),但实际上需要一个派生自 Pet 的具体模型... @987654326 @例如。
具体模型可以通过Pet 上的type 属性确定。
具体模型可以添加额外的字段。
当然,这是discriminator 的工作:
definitions:
Pet:
discriminator: petType
required:
- name
- petType # required for inheritance to work
properties:
name:
type: string
petType:
type: string
Cat:
allOf:
- $ref: '#/definitions/Pet' # Cat has all properties of a Pet
- properties: # extra properties only for cats
huntingSkill:
type: string
default: lazy
enum:
- lazy
- aggressive
Dog:
allOf:
- $ref: '#/definitions/Pet' # Dog has all properties of a Pet
- properties: # extra properties only for dogs
packSize:
description: The size of the pack the dog is from
type: integer
(取自here)
但是,AWS API Gateway 不支持discriminator (ref)。
好的,烦人,但也许一种解决方法是使用 OpenAPI 3.0 定义 API,并在架构中使用 oneOf:
paths:
/pets:
patch:
requestBody:
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
但是(再次),AWS API Gateway 也不支持oneOf (ref)。
有谁知道如何使用 AWS API Gateway 实现这种性质的模型架构,特别是利用继承模式的主体验证 (Pet <- Dog)?或者确实是一种解决方法,而不必为每种具体类型提供方法?
【问题讨论】:
-
有什么解决办法吗?
-
@TolgaEvcimen - 我不知道。我们已经不再使用 AWS API Gateway,因为这种不一致和问题太多了。
标签: amazon-web-services swagger aws-api-gateway openapi