JJ Yong
JJ Yong

Reputation: 73

Specify options available on API endpoint for a path variable with Swagger in Spring Boot

I have the following controller method

@ApiOperation(value = "Send a signin request with a provider")
@GetMapping("/{provider}/signin")
public void signIn(@PathVariable String provider, HttpServletResponse response) {
    service.signIn(provider, response);
}

And what I want to know is if there is way to specify the possible values, that can be passed in the provider path variable. On the Swagger docs I see something about enums, but I don't know how to use this on my Spring Boot app. And on the SpringFox docs I couldn't find the word enum. Thanks in advance

Upvotes: 3

Views: 1960

Answers (1)

MSR SHAHEEN
MSR SHAHEEN

Reputation: 167

Here is sample code for generating available options. This example shows how to multi-select available options. Just use String instead of List for single select

@GetMapping(value = "/request/......", produces = {"application/xml"})
public ResponseEntity<?> createMandate(@NotNull @ApiParam(value = "Test 
Case", required = true, allowableValues = "happy-path, dirty-path, wrong-
path") @RequestParam(value = "TestCase", required = true) List<String> 
testCases,
                                                           @NotNull 
@ApiParam(value = "Another Text Field input") @RequestParam(value = 
"CustomerMSISDN", required = true) String customerMsisdn) {
    return ??
}

Upvotes: 5

Related Questions