Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger UI generates wrong request #335

Closed
zivfri opened this issue Oct 23, 2013 · 4 comments
Closed

Swagger UI generates wrong request #335

zivfri opened this issue Oct 23, 2013 · 4 comments

Comments

@zivfri
Copy link

zivfri commented Oct 23, 2013

Also posted in the Swagger Google group.
In Swagger UI, I'm trying the interactive "try it" on a GET resource by ID. I insert an ID - an integer, and when I press on the "try it" button I see that
the generated request is wrong, instead of inserting the id I from the input field and build the request with the ID part of the URL, the request renders the path parameter as the regex string I have in the @path annotation:

for example:
I have the code:
@get
@path("/applications/{id:[0-9]+}")
@produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
ApplicationDTO getApplicationById(ApiParam(name = "Application ID", value = "The ID of the application", required = true) @PathParam("id") long applicationId){...}

in the input field I'm inserting ID = 1, so I expect the following request:
http://localhost/applications/1

instead, the "try it" button generates:

http://localhost/applications/%7Bid:%5B0-9%5D+%7D
which is the encoded URL of:
http://localhost/applications/{id:[0-9]+}

it's worth mentioning that for a @QueryParam the request generates fine:

if the code is like
@get
@path("/applications/")
@produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
ApplicationListDTO getApplications(ApiParam(name = "Application name", value = "name of the application or part of name of application") @QueryParam("name") String name){...}

and in the input field I'm inserting name = "app", the "try it" button generates the expected URL: http://localhost/applications?name=app

Any help getting the path parameters in the request ? Does Swagger supports that ?

@fehguy
Copy link
Contributor

fehguy commented Oct 23, 2013

Hi, the path parameters (in your case, {id:[0-9]+}) are not currently supported. There are two challenges:

  1. The path replacement logic won't match on it (that's fairly easy)

  2. While programmatic via regex, it's fairly difficult for consumers (i.e. clients) to know how it will be invoked.

That said, it's discouraged to do this in the path param with swagger, and the tooling currently doesn't support it.

@fehguy fehguy closed this as completed Oct 23, 2013
@zivfri
Copy link
Author

zivfri commented Oct 23, 2013

I have the same issue with any path parameter, it's not the regex.
I tried to use just {id} as path parameter like in the pet store sample, and still the generated request
will be:
http://localhost/applications/{id}
what then could be the problem ?

@fehguy
Copy link
Contributor

fehguy commented Oct 23, 2013

This can really only be caused by a mismatch between the path segment {id} and the path parameter name. Can you confirm they match?

@zivfri
Copy link
Author

zivfri commented Oct 23, 2013

the path parameter in the @path matches to the one in the @PathParam if that's what you meant:
@get
@path("/applications/{id}")
@produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
ApplicationDTO getApplicationById(ApiParam(name = "Application ID", value = "The ID of the application", required = true) @PathParam("id") long applicationId){...}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants