[OpenAPI] Trailing slash in servers.url when generating OpenAPI spec
Is there an existing issue for this?
- [x] I have searched the existing issues
Describe the bug
When generating an OpenAPI document in ASP.NET Core, the servers section ends up with a URL that includes a trailing /. This comes from GetOpenApiServers method, which relies on UriHelper.BuildAbsolute(). That helper always appends a trailing slash.
According to the OpenAPI 3.1.0 specification (section 4.8.5.2), the server URLs in the examples is shown without a trailing slash. Because of the current behavior, the generated document doesn’t align with the expected format.
The issue shows up immediately after adding AddOpenApi() with no extra configuration: the generated document contains https://example.com/ instead of https://example.com
Expected Behavior
servers.url should be generated without a trailing slash, matching the example from the specification.
Steps To Reproduce
Steps:
- Create a ASP.NET Core project (minimal api / web api).
- Register OpenAPI using
AddOpenApi(). - Open the generated document.
- The servers section shows a URL ending with /.
Exceptions (if any)
No response
.NET Version
10.0.100
Anything else?
Microsoft.AspNetCore.OpenApi 10 Visual Studio Insiders 2026 11206.111 OpenAPI v3.1.0, ServerObject - https://spec.openapis.org/oas/v3.1.0.html#server-object
@koshaliev thanks for the issue.
You're right the default behavior should not emit trailing slashes for servers (the spec allows a trailing slash) as paths need to start with a / and per specification the path needs to be appended to the server url. Which would result in http://example.com//api/weatherforecast.