Azure / Azure/azure-functions-openapi-extension

"Failed to fetch http://localhost:57773/api/swagger.json" when running from Azure Functions with Aspire

Open
#692 3 comments 0 reactions 0 assignees View on GitHub
feature: api-description Needs: Triage (Functions) potential-bug
Dominant language
C#
Stars
388
Forks
202
PR merge metrics
No merged PRs in 30d

Description

### Description

I've created a new Azure Functions project with new Aspire in Visual Studio 2022 using net9.0. Then, I've added NuGet depencency `Microsoft.Azure.Functions.Worker.Extensions.OpenApi` in version 1.5.1. When starting this, the default `Function1` and Swagger UI is listed in console output of the App as expected:

```
Functions:

Function1: [GET,POST] http://localhost:7227/api/Function1

RenderOAuth2Redirect: [GET] http://localhost:7227/api/oauth2-redirect.html

RenderOpenApiDocument: [GET] http://localhost:7227/api/openapi/{version}.{extension}

RenderSwaggerDocument: [GET] http://localhost:7227/api/swagger.{extension}

RenderSwaggerUI: [GET] http://localhost:7227/api/swagger/ui
```

When I now open http://localhost:7227/api/swagger/ui, I get an error `Failed to load API definition.` and `Fetch error,
Failed to fetch http://localhost:57773/api/swagger.json`. It looks like the Aspire port 7227 is not picked up by Swagger UI so it tries to load definitions from a wrong address.

Image

### Steps to reproduce

See description.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.