我想在帖子中发送一个对象但是带有api密钥。
我如何在OpenAPI-Specification 2.0?
中对此进行描述我试过这个(yaml中的一个子集):
paths:
/eau:
post:
tags:
- Pets
summary: Send a pet
description: 'Send a pet'
operationId: sendapet
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: pet
description: Send a pet
required: true
schema:
$ref: '#/definitions/pet'
- in: header
name: api_key
但是
- in: header
name: api_key
我收到以下错误:
Schema error at paths['/pet'].post.parameters[1].in
should be equal to one of the allowed values
allowedValues: body
Jump to line 36
Schema error at paths['/pet'].post.parameters[1]
should match exactly one schema in oneOf
Jump to line 36
Schema error at paths['/pet'].post.parameters[1]
should NOT have additional properties
additionalProperty: in, name
Jump to line 36
答案 0 :(得分:1)
发生错误是因为缺少标头参数type
。
但是,API密钥与身份验证/授权相关,因此应使用securityDefinitions
和security
关键字而不是标头参数来描述它们:
securityDefinitions:
apiKey:
type: apiKey
in: header
name: api_key
security:
- apiKey: []
更多信息:API Keys