【发布时间】:2017-09-12 04:33:57
【问题描述】:
我正在使用 OpenAPI 2.0 在 SwaggerHub 中定义 API 规范。 /contacts 请求返回一个联系人数组。定义如下:
/contacts:
get:
tags:
- contacts
summary: Get all the contacts
description: This displays all the contacts present for the user.
operationId: getContact
produces:
- application/json
- application/xml
responses:
200:
description: successful operation
schema:
$ref: '#/definitions/AllContacts'
400:
description: Invalid id supplied
404:
description: Contact not found
500:
description: Server error
definitions:
AllContacts:
type: array
items:
- $ref: '#/definitions/ContactModel1'
- $ref: '#/definitions/ContactModel2'
ContactModel1:
type: object
properties:
id:
type: integer
example: 1
firstName:
type: string
example: 'someValue'
lastName:
type: string
example: 'someValue'
ContactModel2:
type: object
properties:
id:
type: integer
example: 2
firstName:
type: string
example: 'someValue1'
lastName:
type: string
example: 'someValue1'
由于某种原因,它只返回第二个对象而不是整个对象数组。
我使用的是 OpenAPI 2.0,并且怀疑该版本不支持数组。
【问题讨论】:
-
所有
ContactModel对象是否具有相同的字段名称(名称,而不是值)?还是他们有一些不同的领域? -
@Helen 他们都有相同的字段名称,分别是:id、firstName 和 lastName。
标签: swagger openapi swagger-2.0