An optional string parameter is not passed correctly by swagger ui
An Azure function (V3) is declared with an optional string parameter. it is sent incorrectly to the function from the swagger UI regardless if the parameter is specified or left empty.
[OpenApiOperation(operationId: "Function1", tags: new[] { "Function" }, Summary = "Show ",Visibility = OpenApiVisibilityType.Important)]
[OpenApiParameter("filter", Type = typeof(string), In = ParameterLocation.Path, Visibility = OpenApiVisibilityType.Important, Description = "Optional string", Required =false )]
[Function("Function1")]
public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "MyRoute/{filter?}")] HttpRequestData req,
FunctionContext executionContext, string filter)
{
var logger = executionContext.GetLogger("Function1");
logger.LogInformation("C# HTTP trigger function processed a request.");
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
response.WriteString($"The filter value is {(filter==null?"null":filter)}");
return response;
}
}
when tested from the address bar of a browser, the response is as expected: http://localhost:7071/api/myroute/XYZ returns: The filter value is XYZ http://localhost:7071/api/myroute returns: The filter value is null
but going through the Swagger UI, the response is: The filter value is {filter
I have created a repository at https://github.com/GilShalit/SwaggerBug to demonstrate.
@GilShalit Thanks for the issue! I'll take a look.
Hi, This is still happening in OpenAPI 1.0.0 on .Net 6 :-\
Thank you for your work!
Still the case in v1.1.0 Code by TS is the way to reproduce
I checked the OpenAPI spec (v3.0.1) about this: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.1.md#paths-object
Unfortunately, the spec doesn't support the wildcard characters in the path template. In other words, if you declare path template, the path part MUST be required value, not optional - it MUST NOT be nullable.