Model missing Accept header
Hey there, I am modeling an API that does different things depending on the value, and presence, of an Accept header. I have it modeled as follows in the Swagger YAML, and it should be correct for as much as I can understand:
'/my-api/endpoint':
get:
summary: My summary.
description: >-
Blah blah blah.
operationId: myOperationId
parameters:
- name: firstParam
in: query
description: Value to use.
required: false
schema:
type: string
responses:
'200':
description: Successful operation.
content:
application/vnd.my.format.one+json:
schema:
$ref: '#/components/schemas/MyFormatOneEntity'
application/vnd.my.format.two+json:
schema:
$ref: '#/components/schemas/MyFormatTwoEntity'
application/json:
schema:
$ref: '#/components/schemas/MyFormatOneEntity'
"":
schema:
$ref: '#/components/schemas/LegacyFormatEntity'
'*/*':
schema:
$ref: '#/components/schemas/MyFormatTwoEntity'
The issue is, when I select the empty Accept header in SwaggerHub, the response preview is not taken from LegacyFormatEntity but from MyFormatTwoEntity. Looks like a bug to me, but maybe I am not modeling the case "there is no Accept header in the request" case. Anyone has ideas on how to actually do this, or how to send a bug report?
Thanks in advance!
An empty string "" is not a valid media type, so it's not allowed in response definitions.
According to RFC 7231 section 5.3.2, no Accept header is equivalent to Accept: */*, so you can use the */* value to test this use case. If you specifically need to omit the Accept header entirely, you'll need to use cURL or Swagger Inspector to test such requests.