Azure / Azure/azure-functions-openapi-extension

Parameters Not functioning correctly

Open
#672 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
388
Forks
202
PR merge metrics
No merged PRs in 30d

Description

**Describe the issue**
When a parameter is included for a "get", the parameter either does not pass the correct value (parameter is a string) or it causes an error (parameter is an integer)

**To Reproduce**
[Function("Get1")]
[OpenApiOperation(operationId: "Get1")]
[OpenApiParameter(name: "id", In = ParameterLocation.Query, Required = true, Type = typeof(int), Description = "User Id")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(string), Description = "The OK response message containing a JSON result.")]
public IActionResult Get1([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Get1/{id}")] HttpRequest req, int id)
{
string parameter = id.ToString();
string response = $"You passed in {parameter}.";
return new OkObjectResult(response);
}

[Function("Get2")]
[OpenApiOperation(operationId: "Get2")]
[OpenApiParameter(name: "id", In = ParameterLocation.Query, Required = true, Type = typeof(string), Description = "User Id")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(string), Description = "The OK response message containing a JSON result.")]
public IActionResult Get2([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Get2/{id}")] HttpRequest req, string id)
{
string response = $"You passed in {id}.";
return new OkObjectResult(response);
}

**Expected behavior**
Get1 should successfully pass in the number one when called with "Get1/1". Instead, it throws the following error : Cannot convert input parameter 'id' to type 'System.Int32' from type 'System.String')
Get2 should successfully pass in the string 'abc' when called with "Get2/abc". The parameter id has the value of "{id}"

**Screenshots**
![Image](https://github.com/user-attachments/assets/50ea10b5-cb7f-4d50-a256-364e443b6348)
![Image](https://github.com/user-attachments/assets/82c12f4d-d9f3-4fc6-adda-5c8a42e1e406)
![Image](https://github.com/user-attachments/assets/b77ec115-c295-4558-8015-c35367ebe6a4)
![Image](https://github.com/user-attachments/assets/e5c9a67c-d12e-429b-827e-2dfe44d71902)

**Environment (please complete the following information, if applicable):**
- OS: Windows 10 Enterprise
- Browser Chrome
- Version 129.0.6668.101

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Get1 and Get2 entry points from the issue in an Azure Functions app, using the shown routes and parameter types. Trace how the route values are bound to the int and string parameters and how the OpenAPI parameter declarations are used. Done means Get1/1 binds to integer 1 and Get2/abc provides the string abc without an error.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp, openapi
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.