OpenAPI-Specification 2.0 a post with body AND header
OpenAPI-Specification 2.0 a post with body AND header
我想在 post 中发送一个对象,但使用 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
错误发生是因为 header 参数丢失 type
.
但是,API 键与 authentication/authorization 相关,因此应使用 securityDefinitions
和 security
关键字而不是 header 参数来描述它们:
securityDefinitions:
apiKey:
type: apiKey
in: header
name: api_key
security:
- apiKey: []
更多信息:API Keys
我想在 post 中发送一个对象,但使用 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
错误发生是因为 header 参数丢失 type
.
但是,API 键与 authentication/authorization 相关,因此应使用 securityDefinitions
和 security
关键字而不是 header 参数来描述它们:
securityDefinitions:
apiKey:
type: apiKey
in: header
name: api_key
security:
- apiKey: []
更多信息:API Keys