I am using springfox version 3.0.0 and using OAS annotations.
I need to produce fragment like this (with schema type array) in Swagger JSON for my method:
"parameters":[
{
"name":"ids",
"in":"query",
"description":"multiple ids",
"required":true,
"schema":{
"uniqueItems":true,
"type":"array",
"items":{
"type":"string"
}
}
},
...
]
Which produces desired parameter component in Swagger UI:

However, I am not able to get this Swagger JSON (and Swagger UI appearance of the parameter) with any of the available Swagger annotations. Currently I have code like this in my controller (btw, this works like a charm with the springdoc library, which we have used before we have migrated to springfox):
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
@Api
@RestController
@RequestMapping("/something")
@RequiredArgsConstructor
public class MyController {
@Operation(summary = "Return list of...")
@ApiResponse(responseCode = "200", description = "Success")
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public List<SomeDTO> getSomethingByIds(@Parameter(description = "List of ids") @RequestParam("ids") Set<String> ids) {
...
}
But I have also experimented with setting schema of the io.swagger.v3.oas.annotations.Parameter annotation manually (like @Parameter(description = "List of ids", content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))) ).
Also tried to experiment with older (non OAS) Swagger annotations - like io.swagger.annotations.ApiImplicitParam or io.swagger.annotations.ApiParam.
Also tried changing of the Set<String> type to List<String> or String[].
No success with neither of these, no matter what I have tried, springfox always produces Swagger JSON fragment like this (with schema type string) and therefore just simple string input in swagger UI:
"parameters":[
{
"name":"ids",
"in":"query",
"description":"List of ids",
"required":true,
"style":"form",
"explode":true,
"schema":{
"type":"string"
}
},
...
]
Anyone had better luck with this?
This works fine for me:
@Parameter(name = "languages", in = QUERY, array = @ArraySchema( schema = @Schema(type = "string")))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With