aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

[OpenAPI] Trailing slash in servers.url when generating OpenAPI spec

Open koshaliev opened this issue 1 month ago • 1 comments

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:

  1. Create a ASP.NET Core project (minimal api / web api).
  2. Register OpenAPI using AddOpenApi().
  3. Open the generated document.
  4. 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 avatar Dec 08 '25 20:12 koshaliev

@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.

desjoerd avatar Dec 08 '25 22:12 desjoerd