'Swagger - How to hide request fiends on API wise, for same input model?
Using Swagger with SpringBoot
implementation "org.springframework.boot:spring-boot-starter-web:2.6.7"
implementation "org.springdoc:springdoc-openapi-ui:1.6.8"
I have tow REST end points, One is as follows -
@PostMapping("/sign-up")
public RESTResponse registerUser(@RequestBody User user) {
....
}
For this, In Swagger UI, Request body
should be like bellow -
{
"userName": "string",
"firstName": "string",
"lastName": "string",
"userToken": "string",
"userType": "EMAIL"
}
Second is as follows -
@PostMapping("/sign-in")
public RESTResponse login(@RequestBody User user) {
..
}
For this, In Swagger UI, Request body
should be like bellow -
{
"userName": "string",
"userToken": "string"
}
Where RequestBody
i.e. User
is same for both API, like bellow -
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class User extends BaseResponse {
@Schema(accessMode = Schema.AccessMode.READ_ONLY)
private Long id;
private String userName;
private String firstName;
private String lastName;
private String userToken;
private UserType userType;
}
How to make it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|