-
Notifications
You must be signed in to change notification settings - Fork 205
Description
Description
When accessing SwaggerUI at /api/v1/swagger, the browser automatically requests favicon files using relative paths, which results in requests to /api/v1/favicon-16x16.png and similar endpoints.
These requests are then forwarded to the application router, causing 500 errors.
Environment
- OpenApiSpex version: 3.21.5
- Phoenix version: 1.8.0-rc.4
- Elixir version: 1.18.4
- Browser: Chrome 138.0.0.0
Steps to Reproduce
- Set up a Phoenix application with OpenApiSpex SwaggerUI:
scope "/api/v1" do
pipe_through [:api]
forward "/swagger", OpenApiSpex.Plug.SwaggerUI,
path: "/api/v1/open_api",
default_model_expand_depth: 4,
operations_sorter: "alpha",
tags_sorter: "alpha"
forward "/", MyApp.ApiRouter
end
- Navigate to /api/v1/swagger in a browser
- Check the browser's network tab and server logs
Expected Behavior
SwaggerUI should either:
- Use absolute paths for favicon requests (e.g., /favicon-16x16.png instead of favicon-16x16.png)
- Not request favicon files at all
- Include its own favicon handling
Actual Behavior
The browser requests:
- /api/v1/favicon-16x16.png
- /api/v1/favicon-32x32.png
- /api/v1/favicon.ico
These requests are forwarded to the application's API router, causing errors like:
[error] ** (UndefinedFunctionError) function MyApp.Domain.json_api_match_route/2 is undefined or private
Error Log
2025-07-30 10:17:57.849 request_id=GFbinxHb7U2mY28AABkB remote_ip=127.0.0.1 user_agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0
Safari/537.36 [error] ** (UndefinedFunctionError) function MyApp.Accounts.json_api_match_route/2 is undefined or private
(my_app 0.1.0) MyApp.Accounts.json_api_match_route("GET", ["favicon-16x16.png"])
...