cancel
Showing results for 
Search instead for 
Did you mean: 

Model missing Accept header

SOLVED
Highlighted
Occasional Visitor

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

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.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today

View solution in original post

1 REPLY 1
Highlighted
Moderator

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.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements