Swagger-ui: curl commands containing spaces won't execute in Linux terminals

Created on 27 Feb 2018  路  7Comments  路  Source: swagger-api/swagger-ui

| Q | A
| ------------------------------- | -------
| Bug or feature request? | Bug
| Which Swagger/OpenAPI version? | 2.0
| Which Swagger-UI version? | 3.11.0
| How did you install Swagger-UI? | Used dist directory for own version, verified on SwaggerUI demo
| Which browser & version? | 64.0.3282.167
| Which operating system? | Ubuntu 16.04 LTS

Expected Behavior

The generated curl available in the UI should be immediately executable when it's copied to a terminal, even if the address contains spaces.

Current Behavior

On operations that contain spaces, the generated curl cannot be executed within a linux console.

For example, this operation: POST /v1/commands/apps/list disabled results in a 400 error if you try to execute the resulting curl:

curl -X POST "http://localhost:1234/v1/commands/apps/list disabled" -H "accept: application/json"

Possible Solution

Replacing the spaces with %20 fixes the issue:

curl -X POST "http://localhost:1234/v1/commands/apps/list%20disabled" -H "accept: application/json"

Context

We are representing some underlying API that unfortunately allows spaces in its naming convention. Developers attempting to quickly script REST communications were held up.

try-it-out bug

Most helpful comment

Here is a definition reproducing the issue:
petstore.swagger.io/?...url=http://heldersepu.github.io/hs-scripts/swagger/4263_swagger.yaml

I thing the Possible solution will be on:
https://github.com/swagger-api/swagger-ui/blob/master/src/core/curlify.js#L9
But is replacing spaces with %20 all we need? or are there other problematic characters?

All 7 comments

Thanks for the report, but it would really help having an API definition that reproduces the problem.

Here is a definition reproducing the issue:
petstore.swagger.io/?...url=http://heldersepu.github.io/hs-scripts/swagger/4263_swagger.yaml

I thing the Possible solution will be on:
https://github.com/swagger-api/swagger-ui/blob/master/src/core/curlify.js#L9
But is replacing spaces with %20 all we need? or are there other problematic characters?

Thank you Helder, that's the situation I was describing.

I was looking at other chars that could be causing problems the # is a problem too...
http://swagger-net-test.azurewebsites.net/swagger/ui/index?filter=ArrayTest#/ArrayTest/ArrayTest_Put
And that one is causing bigger problems in the UI

@dotasek can you please clarify

Replacing the spaces with %20 fixes the issue:

what's %20 mean ?

curl expects that the URL is properly URL-encoded. The https://tools.ietf.org/html/rfc3986#section-2 explains what has to be encoded.
@vikramvi "%20" is simply an ASCII code for space written in hexadecimal.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

grosch picture grosch  路  75Comments

chanurahemal picture chanurahemal  路  87Comments

azamatsulaiman picture azamatsulaiman  路  34Comments

SzymonKlimuk picture SzymonKlimuk  路  32Comments

lmprice picture lmprice  路  104Comments