Skip to content

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

@koshaliev

Description

@koshaliev

Is there an existing issue for this?

  • 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

Metadata

Metadata

Assignees

Labels

area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions