How to pass query parameters with spaces in Open API 3

84 Views Asked by At

I have query parameter http://localhost:8080/test?username=User Name . Below is the spec used

  /test:
    get:
      description: Pass name
      parameters:
        - name: username
          in: query
          required: true
          schema:
            type: string
          allowReserved: true

the spec validation is failing with "bad request" error when the query parameter contains spaces. how to pass spaces in query paramer in Open API 3

1

There are 1 best solutions below

4
On

Escape the space!

http://localhost:8080/test?username=User%20Name

you can use encodeURIComponent to do that:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent