ScaCap / spring-auto-restdocs

Spring Auto REST Docs is an extension to Spring REST Docs
https://scacap.github.io/spring-auto-restdocs/
Apache License 2.0
310 stars 86 forks source link

RequestParam with complex data structure is not flattened #454

Closed mustaphazorgati closed 9 months ago

mustaphazorgati commented 2 years ago

Hey @jmisur,

today we've used the PropertyEditorSupport in order to pass a complex data structure as a query parameter.

Unfortunately the documentation did not behave as we expected.

Controller method signature:

@GetMapping(path = RestEndpoints.URL_MONITOR_WORKBASKET_PRIORITY_REPORT)
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<ReportRepresentationModel> computePriorityWorkbasketReport(
    @RequestParam(name = "columnHeader", required = false)
        PriorityColumnHeaderRepresentationModel[] columnHeaders) {
  /* content not not important */
}

spring-rest-auto-docs will generate the following documentation for that method signature:

|===
|Parameter|Type|Optional|Description

|columnHeader
|Array[Object]
|true
|The column headers for the report.

|===

Since the PriorityColumnHeaderRepresentationModel is a complex data structure we expected that the documentation will flatten the PriorityColumnHeaderRepresentationModel, like it's done for e.g. a RequestBody.

In this context we expected this:

|===
|Parameter|Type|Optional|Description

|columnHeader
|Array[Object]
|true
|The column headers for the report.

|columnHeader[].lowerBound
|Integer
|true
|Determine the lower priority for this column header. This value is inclusive.

|columnHeader[].upperBound
|Integer
|true
|Determine the upper priority for this column header. This value is inclusive.

|===

I am willing to extend the RequestParametersSnippet to flatten complex data structures which are passed as @RequestParam. Before I do that I'd love to get your opinion on this modification to that snippet.

Furthermore I think that the CI has to be fixed before I get started, so that we can integrate this soon ;)

jmisur commented 2 years ago

Hi @mustaphazorgati, you are really stretching the APIs to the limits :)) Surely, if that works in spring then we should support it. I wonder how spring does the deserialisation of the complex request param into a POJO. This is probably something defferent than request body handling, where the jackson kicks in with it's super complex logic. If you could investigate and provide some clues, or even a PR, that would be awesome.

mustaphazorgati commented 2 years ago

Hi @jmisur,

Hi @mustaphazorgati, you are really stretching the APIs to the limits :)) I'll take that as a compliment. Thank you :)

I will have a look over the weekend. Maybe I can already create a PR.

Talk to you soon mate!