Closed abccbaandy closed 3 months ago
Not sure I can help with Swagger. The parameter is not required when using @Filter
.
@torshid You are right, but I guess @Filter
use some special way to generate the Specification right?
And it make swagger doc looks weird. For ex: It accept null value, but it's required in swagger.
Are you using version 3.x?
Yes, I also test with 2.x, the same issue.
Btw I use springdoc to generate the swagger doc. https://springdoc.org/
Hi @torshid
Seems springdoc team already know this issue, and it's followed the spring way (ask user to add @RequestParam(required = false)
).
ref: https://github.com/springdoc/springdoc-openapi/issues/252#issuecomment-564777773
Any other way?
Not sure of the source of the problem, but you can try using a String parameter and then parse it later:
@Autowired
private FilterParser filterParser;
@Autowired
private FilterSpecificationConverter filterSpecificationConverter;
@GetMapping
public List<Entity> search(@RequestParam String filter) {
FilterNode node = filterParser.parse(filter);
FilterSpecification<Entity> spec = filterSpecificationConverter.convert(node);
return repository.findAll(spec);
}
Thanks @torshid , it work in 3.x, but it seems filterSpecificationConverter
not exist in 2.x ?
Also it looks like a workaround, with many extra code.
Hope we can have a fix about this issue.
There should be similar classes to achieve the same goal in 2.x. It's a workaround yes but I don't see any other way to do it currently since it's a problem with springdoc, using String gives you more flexibility. You can also write your own interceptors.
In this issue https://github.com/turkraft/springfilter/issues/177
We can use
@Parameter
to show correct format in swagger, but even withrequire = false
, it still be required in swagger.I try with
@RequestParam
with require false, but it will make the whole filter not work(the filter will be always null).