Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape the percent sign in URL in OpenAPI?

I have an API with parameters. In my OpenAPI documentation I used the allowReserved: true property to escape special characters, but unfortunately one parameter contains the % sign which is not in the list.

Is there any possibility to escape the % sign?

      - name: sig
        in: query
        required: true
        schema:
          type: string
        allowReserved: true      

This is from the Swagger documentation:

Additionally, the allowReserved keyword specifies whether the reserved characters :/?#[]@!$&'()*+,;= in parameter values are allowed to be sent as they are, or should be percent-encoded. By default, allowReserved is false, and reserved characters are percent-encoded. For example, / is encoded as %2F (or %2f), so that the parameter value quotes/h2g2.txt will be sent as quotes%2Fh2g2.txt

like image 839
zanza67 Avatar asked Oct 30 '25 17:10

zanza67


1 Answers

Because the percent character % has a special meaning in query strings (it's an indicator of percent-encoded octets), clients are supposed to always encode % as %25 when this character is used literally in the query string. Servers, in their turn, decode %25 back to % when processing requests.

This is the default behavior and does not require any special attributes in the OpenAPI document.

A screenshot of Swagger Editor that shows a request with a query parameter. The parameter value contains the % character, which is automatically encoded as %25 in the "try it out" request.

like image 72
Helen Avatar answered Nov 03 '25 05:11

Helen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!