Azure / Azure/azure-functions-openapi-extension

Invalid OpenAPI file generated when path parameters are included.

Open
#668 0 comments 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 I include path parameters, the file generated does not meet OpenApi spec because the "required: true" is omitted. It looks like the "Required" is being ignored entirely for this parameter, as it also doesn't have a required annotation in the Swagger UI.

**To Reproduce**
Steps to reproduce the behavior:
```
[OpenApiOperation(
operationId: "ListUnread",
tags: new[] { "notification" },
Summary = "Lists unread notifications",
Description = "Lists all unread notifications assigned to the calling user."
)]
[OpenApiParameter("tenantId", Description = "The tenant ID of the current customer.", Type = typeof(Guid), Required = true, In = ParameterLocation.Path)]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(IEnumerable), Summary = "Unread notifications", Description = "This returns a list of notifications.")]
[Function("ListUnread")]
public IActionResult ListUnread(
[HttpTrigger(AuthorizationLevel.User, "get", Route = "{tenantId:guid}/notification/unread")] HttpRequest req, Guid tenantId,
ILogger log)
{
```

Generate a v3.yaml (or any other output) file:

```
paths:
'/{tenantId}/notification/unread':
get:
tags:
- notification
summary: Lists unread notifications
description: Lists all unread notifications assigned to the calling user.
operationId: ListUnread
parameters:
- name: tenantId
in: path
description: The tenant ID of the current customer.
schema:
type: string
format: uuid
responses:
'200':
description: This returns a list of notifications.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/notificationTableEntity'
x-ms-summary: Unread notifications
```

**Expected behavior**
The "parameters" section should have "required: true" under the parameter.

**Environment (please complete the following information, if applicable):**
- OS: happens on local Windows build and building on ubuntu-latest
- Version v1.5.1, v2.0.0-preview2

Contributor guide

Open the contributing guide

Research direction

Start with the OpenApiParameter attribute and the generated v3.yaml for the provided Azure Function path parameter. Reproduce the output using the ListUnread example, then verify that the tenantId path parameter includes required: true and is marked required in Swagger UI.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.