Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger - spring fox - hide password

Swagger - spring fox - hide password.

In one of our API I need to return alphanumeric code after verifying user id and password.

We are using springfox-swagger-ui-2.3.1.I have a field "password" where I do not want to show password (instead i want to show "XXXX") when user types in swagger ui.

password is defined as @RequestParam(value = "password") String password.

any suggestion is highly appreciated.

like image 925
Ashish S Avatar asked Sep 14 '17 22:09

Ashish S


People also ask

How do I hide parameters in Swagger?

6. Using @ApiParam. @ApiParam is also a Swagger annotation that we can use to specify metadata related to request parameters. We can set the hidden property to true in order to hide any property.

How do you hide entity in Swagger?

To hide the "Models" section, add defaultModelsExpandDepth: -1 to the Swagger UI configuration code in your index.

What is Springfox Swagger2?

Swagger2 is an open source project used to generate the REST API documents for RESTful web services. It provides a user interface to access our RESTful web services via the web browser. To enable the Swagger2 in Spring Boot application, you need to add the following dependencies in our build configurations file.


2 Answers

Unfortunately springfox does not provide support for swagger-core's password format.

It was introduced in swagger-core 1.5.11 #469

Issue #2366 is still open in springfox.

like image 122
imTachu Avatar answered Oct 22 '22 14:10

imTachu


To use password as a parameter type, you can simply override the format like this:

@ApiParam(value = "your password", type = "string", format = "password") 
@QueryParam(/* normal stuff */)

hidden password for APiParam

like image 1
Pawan Maurya Avatar answered Oct 22 '22 13:10

Pawan Maurya