Azure / Azure/azure-functions-openapi-extension

Unable to render swagger.json/UI when the HTTP GET function while the route contains only a parameter

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

Description

**Describe the issue**
Unable to render swagger.json/UI when the HTTP GET Azure function while the route contains only a parameter.

**To Reproduce**
Steps to reproduce the behavior:
1. Create a plain new azure function (.NET6 with HTTP trigger)
2. Install Microsoft.Azure.WebJobs.Extensions NuGet (1.4.0)
3. Specify some OpenApi attributes above the newly created function
4. Specify "Route" in the HttpTrigger attribute like so "{somePathParam}"
5. Add a new string parameter of the typed string right below "string somePathParam"
6. Run the function
7. Enter the swagger UI URL into the browser "http://localhost:{your-port}/api/swagger/ui
8. The swagger UI can't be rendered (if you look at "http://localhost:{your-port}/api/swagger.json"), you can see there is just a content that the defined function returns (i.e. the function that should be just documented according to the attributes is being called instead)
9. Try to add something to the Route definition like so "prefix/{somePathParam}", or "{somePathParam}/postfix"
10. Run the function again, visit the swagger UI or swagger,json URL, and voila, everything works as it should.

**Expected behavior**
The swagger.json, or UI should be generated even if there is only path parameter in the Route definition.

**Screenshots**
Does not work like this ...
![2022-11-14 14_34_55-O365LogService (Running) - Microsoft Visual Studio](https://user-images.githubusercontent.com/25385217/201674857-eedacf5f-7258-41c6-928b-1a703d3f65e7.png)
![2022-11-14 14_38_45-OpenAPI Document on Azure Functions - Swagger UI - Brave](https://user-images.githubusercontent.com/25385217/201674869-5b915ba1-c8e2-4c4a-a3c0-221cdee356d2.png)
![2022-11-14 14_39_02-localhost_7086_api_swagger json - Brave](https://user-images.githubusercontent.com/25385217/201674871-ff5dfd9b-472f-4fcd-8506-db0de782bcb3.png)

... but does when it is like this.
![2022-11-14 14_36_53-O365LogService (Running) - Microsoft Visual Studio](https://user-images.githubusercontent.com/25385217/201674862-3cc1ebd9-3917-4fd4-875c-e390184fce4e.png)
![2022-11-14 14_38_18-OpenAPI Document on Azure Functions - Swagger UI - Brave](https://user-images.githubusercontent.com/25385217/201674864-bb6f8ec9-7ef9-4bbd-afed-c4ed14f66dcb.png)

**Environment:**
- OS: Windows 10
- Browser: Chrome/Brave
- Version: 1.4.0
**Additional context**
I am not sure whether this is a bug or intended behavior. I couldn't find any info, so if it is the case, I am sorry.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with a plain .NET 6 Azure HTTP-trigger function using an OpenAPI route containing only a parameter, then request /api/swagger.json and /api/swagger/ui. Trace the HTTP-trigger route handling and OpenAPI generation path; the fix is complete when both endpoints generate the document and UI instead of invoking the function.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp, openapi
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.