swagger-editor 中的继承抛出错误
Inheritance in swagger-editor throwing an error
使用 swagger 编辑器并在我尝试从包含数组的模型继承时收到验证错误。我假设我的定义搞砸了,因为我是新手。但我知道要在编辑器中支持 swagger 2.0,还有很多工作要做。不想指出编辑器中的错误或不足,只是想知道我的架构是否有效。
这在编辑器中有效(来自简单的宠物店示例):
definitions:
pet:
properties:
name:
type: string
newPet:
allOf:
- $ref: '#/definitions/pet'
但是我想将 pet 定义为数组:
definitions:
pet:
type: array
items:
type: string
newPet:
allOf:
- $ref: '#/definitions/pet'
从技术上讲,这不是继承,而是组合。 newPet
和pet
之间没有层级关系。对于继承,定义必须都是对象,并且必须有一个 discriminator
定义。
就组合而言,这看起来像是一个有效的定义。
这里有一个例子:https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/yaml/petstore-expanded.yaml
所以看起来像这样:
definitions:
Pet:
allOf:
- $ref: '#/definitions/NewPet'
required:
- id
properties:
id:
type: integer
format: int64
NewPet:
required:
- name
properties:
name:
type: string
tag:
type: string
使用 swagger 编辑器并在我尝试从包含数组的模型继承时收到验证错误。我假设我的定义搞砸了,因为我是新手。但我知道要在编辑器中支持 swagger 2.0,还有很多工作要做。不想指出编辑器中的错误或不足,只是想知道我的架构是否有效。
这在编辑器中有效(来自简单的宠物店示例):
definitions:
pet:
properties:
name:
type: string
newPet:
allOf:
- $ref: '#/definitions/pet'
但是我想将 pet 定义为数组:
definitions:
pet:
type: array
items:
type: string
newPet:
allOf:
- $ref: '#/definitions/pet'
从技术上讲,这不是继承,而是组合。 newPet
和pet
之间没有层级关系。对于继承,定义必须都是对象,并且必须有一个 discriminator
定义。
就组合而言,这看起来像是一个有效的定义。
这里有一个例子:https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/yaml/petstore-expanded.yaml
所以看起来像这样:
definitions:
Pet:
allOf:
- $ref: '#/definitions/NewPet'
required:
- id
properties:
id:
type: integer
format: int64
NewPet:
required:
- name
properties:
name:
type: string
tag:
type: string