Home > database >  How can I mask a password in Swagger using Swashbuckle
How can I mask a password in Swagger using Swashbuckle

Time:05-02

We are using Swashbuckle on our API's, and for one of the metohds we are offering a login. How can the password be masked in Swagger UI?

[HttpGet]
[Produces("text/plain")]
public async Task<string> Login(string userId, string password)

I have seen that appearantly Swagger supports a password fromat. However this is not C# code. I have no idea where to put this

@Parameter(schema = @Schema(type = "string", format = "password")) 

CodePudding user response:

We can try to use DataType attribute with DataType.Password enum that put into we want to mask parameter.

[HttpGet]
[Produces("text/plain")]
public async Task<string> Login(string userId,[DataType(DataType.Password)]
 string password)

Then we can get mask the parameter as below

enter image description here

This Modify might be worked after v2.5.0 version which discusses from Does not use DataType.Password #521

Note: Using attribute and enum from namespace System.ComponentModel.DataAnnotations

  • Related