Azure / Azure/azure-functions-openapi-extension

Base URL is incorrect when using with proxy

Open
#531 2 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**
After enabling the proxies on V4 and adding the below proxy:
```
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"swagger": {
"matchCondition": {
"methods": [ "GET" ],
"route": "/"
},
"backendUri": "https://localhost/swagger/ui"
}
}
}
```
and opening the function from Visual Studio
`http://localhost:7071/swagger/ui` this works fine
`http://localhost:7071/` shows CORS errors:
![image](https://user-images.githubusercontent.com/1741838/210517448-ba69b4ef-6dc5-4e86-ba31-397a0a29becd.png)

After a quick investigation, I noticed that the URL passed to SwaggerUIBundle is wrong:

Here it is correct:
![image](https://user-images.githubusercontent.com/1741838/210517791-5daf10aa-5c9a-4ea9-b331-8841f04a2359.png)
and when opening the root it is wrong:
![image](https://user-images.githubusercontent.com/1741838/210517933-f6057b3d-2a9a-46a3-86d0-f45114e737d8.png)

Probably calculated here: https://github.com/Azure/azure-functions-openapi-extension/blob/main/src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/SwaggerUI.cs#L61

I'll try to download the source code and debug it locally.

Contributor guide

Open the contributing guide

Research direction

Start at src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/SwaggerUI.cs around line 61 and reproduce the proxy configuration with the root URL and /swagger/ui URL in Visual Studio. Compare the URL passed to SwaggerUIBundle in both cases; done means the root route produces the correct base URL and no CORS errors.

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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.