swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.32k stars 8.91k forks source link

curl commands containing spaces won't execute in Linux terminals #4263

Open dotasek opened 6 years ago

dotasek commented 6 years ago
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.

webron commented 6 years ago

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

heldersepu commented 6 years ago

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?

dotasek commented 6 years ago

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

heldersepu commented 6 years ago

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

vikramvi commented 5 years ago

@dotasek can you please clarify

Replacing the spaces with %20 fixes the issue:

what's %20 mean ?

ghost commented 5 years ago

Can someone please guide on https://stackoverflow.com/questions/53379440/swagger-not-working-while-doing-crud-operation-through-ui-also-curl-commands-do

jzakrzewski commented 5 years ago

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.