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

The same RequestMapping with different params #1828

Closed
hybaken opened this issue May 22, 2017 · 5 comments
Closed

The same RequestMapping with different params #1828

hybaken opened this issue May 22, 2017 · 5 comments
Labels
Milestone

Comments

@hybaken
Copy link

hybaken commented May 22, 2017

Hi,

The below user controller contains two GET methods mapped to the same URL. Both got RequestParam.

@RestController
@Api(value = "USER")
@RequestMapping("/users")
public class UserController {

        @RequestMapping(method = RequestMethod.GET, produces="application/json", params={"username"})
    @ResponseStatus(value= HttpStatus.OK)
    public Collection<User> getUsersByName(@RequestParam String username) {
        throw new NotImplementedException();
    }

    @RequestMapping(method = RequestMethod.GET, produces="application/json", params={"status"})
    @ResponseStatus(value= HttpStatus.OK)
    public Collection<User> getUsersByStatus(@RequestParam String status) {
        throw new NotImplementedException();
    }

}

UI will display just one.

Seems its related to this one:
#750

@dilipkrish
Copy link
Member

This is a known problem with open api spec v 2.0. However an incubating feature allows you to work around the problem by enablingUrlTemplating in the docs. However keep in mind that this is not supported by swagger-ui out of the box.

@BetterWork4BetterWorld
Copy link

Hello, can you give more information or a link that explain how to use this feature plz ?

Google doesn't give anything on that...

@dilipkrish
Copy link
Member

See link above @BetterWork4BetterWorld ☝️

Just support for RFC6570 to support url templating. This generates swagger endpoints with templated query parameters and there is a modified swagger-ui that supports having url templates for request parameters as well.

So in your example before the change you'd have only one url

http://host:port/users

after turning enableUrlTemplating on you'll see

http://host:port/users{?username}
http://host:port/users{?status}

@plfgavilan
Copy link

Hi, thanks @dilipkrish but I changed to this dependency springfox-swagger-ui-rfc6570:1.0.0 to support url templating, but I still have only one endpoint intead of two (with the same uri but diferent parameters)

What's still missing?

Thank in advance

@dilipkrish
Copy link
Member

@plfgavilan you're missing configuring your docket with enableUrlTemplating(true)

@dilipkrish dilipkrish added this to the 2.8.0 milestone Dec 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants