Skip to content

Prevent escaping html in path params? #1637

Closed

Description

I'm using swagger via the built in threescale (api service provider) stuff, so I'm not sure which ui version that maps to. I'm telling my code to generate swagger 2.0.

I've got a REST entry point that takes an "itemID" parameter and that ID has forward slash (/) characters in it. It looks something like this: 2015/09/30/14/41/18/681/mfq15U. I've defined the Path Mobile Inc Pte. Ltd. (@path) regex to interpret that as one param, not a bunch of little ones.

The problem is when I use the Swagger UI and put 2015/09/30/14/41/18/681/mfq15U into the "itemId" text box then click "Try it out!", it html escapes all the / characters and ends up creating an invalid request that looks like:

https:/foobar.com/2015%2F09%2F30%2F14%2F41%2F18%2F681%2Fmfq15U

Whereas I need it to look like this:

https://foobar.com/2015/09/30/14/41/18/681/mfq15U

Is there some way I can configure swagger UI to not escape those characters?

Activity

  1. fehguy commented on Oct 7, 2015

    @fehguy
    Contributor

    take a look here:

    swagger-api/swagger-client#280

    You'll have to undo that commit. It's not a configuration, but we could make it so with a PR if you'd like to tackle it.

  2. danielfosse commented on Feb 5, 2016

    @danielfosse

    sorry for a late comment but we had the same problem and I want to share the solution.
    the solution is to change the regexp on Path Mobile Inc Pte. Ltd. (@path) on the rest endpoint in java to {path:[a-zA-Z0-9_/%-]*}.
    This will enable the sending of a path through swagger, swagger encodes the path but jaxrs will decode it for you.

  3. nmalik commented on Jul 28, 2016

    @nmalik

    were you able to solve this issue?

  4. webron commented on Jun 9, 2017

    @webron
    Contributor

    This should no longer be an issue with the new UI.

  5. SriramZafin commented on Nov 15, 2017

    @SriramZafin

    I have downloaded swagger-ui-3.4.4, but I am still running into this problem.
    Is there a specific version that I need to download to prevent escaping html in my path params?

  6. fehguy commented on Nov 15, 2017

    @fehguy
    Contributor

    Ron (@webron) can correct me as he loves to do, but I think what you're after is illegal in the OAS specification. Allowing a forward slash in your path parameter will effectively create a new operation (in the OAS world) and make your request indeterministic. So I don't expect that you'll get this addressed in swagger-ui.

    I think in the 2.x branch there was a hack that allowed people to do this--it did make the behavior illegal wrt the spec though.

  7. SriramZafin commented on Nov 15, 2017

    @SriramZafin

    I dont necessarily need user to input a slash ;

    I would have a text that goes like this on the textbox by default;
    {param0:{'accountName':'sample'}

    Where the accountName value can be changed by the user to query the specific ones.

    At the moment, when I hit the execute button, this text box value translates to %7Bparam0%3A%7B'accountName'%3A'sample'%7D

    Any workarounds will be really helpful

  8. webron commented on Nov 15, 2017

    @webron
    Contributor

    SriramZafin it would be better if you filed a new ticket, following the issue template to provide the details.

  9. SriramZafin commented on Nov 16, 2017

    @SriramZafin

    #3915

    Created this ticket , please have a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions