Skip to content

OpenAPI: Minimal API unused Path parameters are not emitted in the OpenAPI #63883

@desjoerd

Description

@desjoerd

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The following unit test fails because the parameters are null.

    [Fact]
    public async Task SupportsUnusedRouteParametersFromMinimalApis()
    {
        var source = """
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;

var builder = WebApplication.CreateBuilder();

builder.Services.AddOpenApi();

var app = builder.Build();

app.MapGet("/{userId}", RouteHandlerExtensionMethods.Get);

app.Run();

public static class RouteHandlerExtensionMethods
{
    /// <param name="userId">The id of the user.</param>
    public static string Get()
    {
        return "Hello, World!";
    }
}
""";

        var generator = new XmlCommentGenerator();
        await SnapshotTestHelper.Verify(source, generator, out var compilation);
        await SnapshotTestHelper.VerifyOpenApi(compilation, document =>
        {
            var path = document.Paths["/{userId}"].Operations[HttpMethod.Get];
            Assert.NotEmpty(path.Parameters);
            Assert.Equal("The id of the user.", path.Parameters[0].Description);
        });
    }

Expected Behavior

The unused path parameter {userId} should be emitted on the operation or on the path as a parameter (that is document.Paths["/{userId}"].Parameters).

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

10.0.100-rc.1.25420.111

Anything else?

Found while fixing #63757

Metadata

Metadata

Assignees

No one assigned

    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