Reputation: 6527
I want to send a object in a post but with a api key.
How can I describe this in OpenAPI-Specification 2.0?
I tried this (a subset in 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
But at
- in: header
name: api_key
I get the following error:
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
Upvotes: 0
Views: 587
Reputation: 97677
The error occurs because the header parameter is missing type
.
However, API keys are related to authentication/authorization, so they should be described using the securityDefinitions
and security
keywords instead of a header parameter:
securityDefinitions:
apiKey:
type: apiKey
in: header
name: api_key
security:
- apiKey: []
More info: API Keys
Upvotes: 1