Forum Discussion

Peter_XXX's avatar
Peter_XXX
Occasional Visitor
4 years ago
Solved

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. 

 

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?

  • 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

1 Reply

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    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