swagger-api / swagger-api/swagger-codegen
[Spring] Support @ModelAttribute
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Way to generate @ModelAttribute strategy using parameter serialization .
Swagger-codegen version
io.springfox:springfox-swagger2
Swagger declaration file content or url
# description
pageParameter:
in: query
name: pageParameter
schema:
type: object
properties:
page:
type: integer
format: int32
minumum: 1
default: 1
example: 1
size:
type: integer
format: int32
minumum: 10
default: 1000
example: 1000
sort:
type: array
items:
type: string
# paths
get:
operationId: getList
parameters:
- $ref: '#/parameters/pageParameter'
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement
If I generate code using above yml file, it makes object parameter with @RequestParam like following .
default ResponseEntity<XXXX> getList(@ApiParam(value = "") @Valid @RequestParam(value = "pageParameter", required = false) PageParameter pageParameter) {
// ....
}
But I wanna use multiple object parameter like .
get:
operationId: getList
parameters:
- $ref: '#/parameters/pageParameter'
- $ref: '#/parameters/searchParameter'
As you know, if they generate like below,
default ResponseEntity<XXXX> getList(@ApiParam(value = "") @Valid @ModelAttribute PageParameter pageParameter, @ModelAttribute SearchParameter searchParameter) {
// ....
}
I can query http://XXX.com?page=1&size=10&name=XXX&age=10,
and they will be bind theirselves from this query parameter to all of that objects(PageParameter, SearchParameter) automatically. You know, It's feature of @ModelAttribute.
But it seems like that they doesn't suggest this feature.
Is there any way to achieve this?
Thank you.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No implementation files or tests are named. Reproduce the supplied OpenAPI YAML and inspect the Spring server-generation templates and parameter handling; done means multiple object query parameters generate separate Java arguments using @ModelAttribute rather than @RequestParam, with the existing request binding behavior preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100