question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request parameters, lead to an incorrecty generated cURL request

See original GitHub issue

Version: 2.9.2 (latest) Kind: Bug report

Hey, I think I’ve found a bug in the generation of the curl request, when clicking on ‘Try it out’.

I’ve got following endpoint:

@RequestMapping(method = RequestMethod.GET, path = "/ranking/country", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Returns a ranking of the top countries with the most sensors")
public List<RankingItemCountry> getRankingByCountry(
        @RequestParam(defaultValue = "10") int items
) throws RankingDataException {
    if(items < 1) throw new RankingDataException(ErrorCodeUtils.INVALID_ITEMS_NUMBER);
    return sensorRepository.getRankingByCountry(items);
}

On the UI page it looks like this: Capture

Look at the generated curl request. It is wrong isn’t it? The expected request should look like this: https://<api-url>.com/ranking/city?items=2

This results in a 404 response code. I would appreciate, if it can be fixed. Thanks for your awesome implementation!

Marc

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
MaksimOrlovcommented, Apr 10, 2020

If you have two @RequestMappings with same url but different @RequestParam, with enabled urlTempkating SpringFox will generate two endpoints. Otherwise only one,the second mapping will be lost. But unfortunately, Swagger-UI doesn’t support that feature. So, it won’t be able to generate correct curl request.

More about feature https://tools.ietf.org/html/rfc6570

0reactions
studeyangcommented, Jul 16, 2021

add @ApiImplicitParam may solve your problem, like this:

@RequestMapping(method = RequestMethod.GET, path = "/ranking/country", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiImplicitParam(name = "items", value = "items", dataType = "int", paramType = "param")
@ApiOperation(value = "Returns a ranking of the top countries with the most sensors")
public List<RankingItemCountry> getRankingByCountry(
        @RequestParam(defaultValue = "10") int items
) throws RankingDataException {
    if(items < 1) throw new RankingDataException(ErrorCodeUtils.INVALID_ITEMS_NUMBER);
    return sensorRepository.getRankingByCountry(items);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

CURL Command Line URL Parameters - Stack Overflow
I tried using some GUI application and when I pass the url as: http://localhost:5000/locations?id=3 , it works. I really would rather use CURL...
Read more >
Solved: Adding request params through curl is throwing jav...
I tried the same curl command generated by the REST Explorer. I'd noticed that If I haven't add query parameters ( --data )...
Read more >
Copy as curl
Paste that in a shell to get a curl command line that makes the transfer. This feature is available by default in all...
Read more >
HTTP Requests and Responses
Can be caused by an incorrect curl command, for example including a path parameter that isn't allowed, like using orgs/org_id for an endpoint...
Read more >
curl_exec - Manual - PHP
$params['host']; ?> CURL automatically creates the host parameter (since it is required for HTTP/1.1 requests), so you don't need to set it. But...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found