cancel
Showing results for 
Search instead for 
Did you mean: 

is it possible to define multiple charset in the content type of a REST call in Swagger?

SOLVED
Highlighted
Occasional Visitor

is it possible to define multiple charset in the content type of a REST call in Swagger?

I'm trying to describe a call like this. 

Peter_XXX_0-1601368818112.png

 

The issue I run into is that the charset that is returned is the charset of the DB. 

And we have some DB that for historical reasons are not on the UTF-8 encoding yet. 

 

Is it possible to describe this in a way that both the headers Content-type: application/Json; charset=UTF-8 and Content-type: application/Json; charset= iso-8859-1 are considered valid answers?

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: is it possible to define multiple charset in the content type of a REST call in Swagger?

Hi Peter,

You'll need to define those different encodings as separate media types:

      requestBody:
        required: true
        content:
          application/json; charset=UTF-8:
            schema:
              $ref: '#/components/schemas/Something'
          application/json; charset=iso-8859-1:
            schema:
              $ref: '#/components/schemas/Something'

 

There's an existing enhancement request to improve the syntax so that parameterized media types can be defined using a single Media Type Object:

Parameters for Media Types


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

1 REPLY 1
Highlighted
Moderator

Re: is it possible to define multiple charset in the content type of a REST call in Swagger?

Hi Peter,

You'll need to define those different encodings as separate media types:

      requestBody:
        required: true
        content:
          application/json; charset=UTF-8:
            schema:
              $ref: '#/components/schemas/Something'
          application/json; charset=iso-8859-1:
            schema:
              $ref: '#/components/schemas/Something'

 

There's an existing enhancement request to improve the syntax so that parameterized media types can be defined using a single Media Type Object:

Parameters for Media Types


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

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