springdoc-openapi icon indicating copy to clipboard operation
springdoc-openapi copied to clipboard

@JsonView is not consistent with SpringWeb MVC

Open beatfreaker opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe.

  • I want to apply @JsonView to only ResponseBody and not to RequestBody to achieve this I am annotating @JsonView at the method level in RestController as follows
@PostMapping
@JsonView(UserViews.Internal.class)
public User createUser(@RequestBody CreateUserRequest createUserRequest) {
  return new User("name", "lastName", 10);
}

With this configuration the API is working fine and returning the correct field in response as mentioned in JsonView, but Swagger doc is applying this JsonView to both request and response objects i.e CreateUserRequest as well as User.

Is this a bug ? or is there any way to achieve this?

Check the attached screenshot for reference where the internal schema for both request and response objects was created.

image

beatfreaker avatar Dec 04 '23 13:12 beatfreaker

I've the same problem

a-locatelli avatar Dec 05 '23 08:12 a-locatelli

@beatfreaker,

You should apply different @JsonView in your RequestBody. This is an example how to achieve it:

https://github.com/springdoc/springdoc-openapi/blob/bfc57abd40178e91e24121e5266aee025026788d/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app54/HelloController.java#L56-L61

bnasslahsen avatar Mar 11 '24 17:03 bnasslahsen