【发布时间】:2018-12-14 09:11:32
【问题描述】:
我正在尝试在 SwaggerHub 域中定义一些可重用的元素,但不知道如何定义标头。
我尝试了一些方法,但它们都产生错误,例如:
- $refs 不能匹配以下任何一个:“#/definitions”, "#/参数"
- 应该是一个对象
- 需要属性“类型”
- additionalProperty "$ref" 在不允许时存在
此处的完整示例: https://app.swaggerhub.com/domains/batwad/domain-demo/1.0.0
definitions:
error-list:
description: Standard error response
type: object
properties:
errors:
type: array
items:
type: string
readOnly: true
responses:
bad-request:
description: Bad request
headers:
# these don't error, but the UI docs say "Could not render this component"
X-Transaction-ID:
description: Transaction correlation identifier.
type: string
Content-Type:
description: Must be <tt>application/json</tt>
type: string
schema:
$ref: '#/definitions/error-list'
server-error:
description: Unexpected error
headers:
# says "should be an object" and "cannot match any of blablabla"
- $ref: '#/parameters/x-transaction-id'
- $ref: '#/parameters/content-type'
schema:
$ref: '#/definitions/error-list'
service-unavailable:
description: Service temporarily unavailable
schema:
$ref: '#/definitions/error-list'
headers:
# says "requires property 'type'" and "$ref not allowed"
X-Transaction-ID:
$ref: '#/parameters/x-transaction-id'
Content-Type:
$ref: '#/parameters/content-type'
parameters:
x-transaction-id:
name: X-Transaction-ID
in: header
description: Transaction correlation identifier.
required: true
type: string
content-type:
name: Content-Type
in: header
description: Must be <tt>application/json</tt>
required: true
type: string
【问题讨论】:
标签: swagger swagger-2.0 swaggerhub