Skip to content

Extract parameters from parameter object #505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 25, 2020

Conversation

zarebski-m
Copy link
Contributor

@zarebski-m zarebski-m commented Mar 23, 2020

Fixes #120, #268, #162, #119

This PR introduces a new Springdoc annotation org.springdoc.api.annotations.ParameterObject. Request parameter annotated with it are not added as a request parameter themselves, but rather each field of the parameter is added as a separate request parameter. This is compatible with Spring MVC request parameters mapping to POJO object.

See test case 102 in springdoc-openapi-webmvc-core.

Consider the following classes:

class QueryParams {
    private String name;
    private String value;
}

@RestController
class TestController {
    @GetMapping("pojo-params")
    public void testMethod(@ParameterObject QueryParams queryParams) {}
}

In generated docs, the /pojo-params endpoint defines two request parameters: name and value, instead of single queryParams one.

This also allows deprecation of the workaround for Pageable with PageableAsQueryParam annotation – we can simply use @ParameterObject Pageable pageable on method parameter.

See test case 7 on springdoc-openapi-data-rest.

Copy link
Collaborator

@bnasslahsen bnasslahsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @zarebski-m,

Thank for sharing your work and your contribution.

Can you please respect the contribution guide and especially formatter provided: Please don't add brackets if there is one instruction, especially on existing instructions:

You can make sure, you change only the lines related to your feature on the follwoing files: AdditionalModelsConverter, AbstractRequestBuilder.

@zarebski-m
Copy link
Contributor Author

Thank you, I've applied https://github.com/spring-projects/spring-boot/blob/master/idea/codeStyleConfig.xml to my IDE and reformatted my code.

@bnasslahsen
Copy link
Collaborator

Thank you @zarebski-m for your contribution.
Its now merged with master.

@prondzyn
Copy link

prondzyn commented Apr 2, 2020

@bnasslahsen when are you planning to release this feature?

@bnasslahsen
Copy link
Collaborator

@prondzyn ,

Should be available, no later than next Monday, 06th April.

@destebanm
Copy link

destebanm commented Apr 13, 2020

HI!!

Thanks for the new annotation @ParameterObject!

Nevertheless, we are facing an issue when using it. Every attribute of the POJO is being set as required. Is there any way to avoid that?
We are using:
<swagger-annotations.version>2.1.2</swagger-annotations.version>
<springdoc-openapi-ui.version>1.3.1</springdoc-openapi-ui.version>

image
image

image

EDIT: using @Nullable fix the problem, so @Parameter i guess is not supported

Thanks!

@bnasslahsen
Copy link
Collaborator

@destebanm,

This is already fixed. #541.
You can just use v1.3.2.

@destebanm
Copy link

WOW, it is working fine with 1.3.2!

Thanks!

@dmittriy13
Copy link

dmittriy13 commented Apr 14, 2020

Hi, thanks for your work, I ran into a problem: inherited fields are not processed.
image

Here is an example of how to handle this case.
I would be very grateful if you correct this in the next version.

@Ichigo85
Copy link

+1
I also need inheritance working for method parameters.

@bnasslahsen
Copy link
Collaborator

@Ichigo85,

Its already released. You can use v1.3.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for object as request parameter container
6 participants