Swashbuckle Swagger UI: How to Remove Required Parameters in XML Comment
Think about your setting before proceeding. Is the parameter really needed and is it typing text? Is there a reasonable default and what would be the expected behavior in this case? Depending on your answer, you may prefer one of these two solutions:
Option 1: Optional parameters
If it accessTokenID
has a standard default, you can specify this in the API signature and Swashbuckle will stop identifying the parameter as needed.
For example, id
this example will resolve as an optional parameter in the Swagger interface:
public HttpResponseMessage Get(int id = 0)
If your parameter is really not required, a nullable type might make more sense (for example, if you are listing all values ββon null input):
public HttpResponseMessage Get(int? id = null)
Option 2: SwaggerDefaultValue Attribute
A solution in Swashbuckle GitHub created an IOperationFilter to process SwaggerDefaultValue attributes and apply them to Swagger UI. You can use this solution if you want this setting to require but would like to set the default in Swagger UI.
For example, this would display "0" in the Swagger UI textbox instead of "(required)":
[SwaggerDefaultValue("id", "0")]
public HttpResponseMessage Get(int id)
source to share