Repository: dotnet/aspnetcore
File: src/OpenApi/src/Extensions/ApiDescriptionExtensions.cs (C#)

Code before:
using System.Linq;
using System.Net.Http;
using System.Text;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Routing.Patterns;

internal static class ApiDescriptionExtensions
{
    /// <summary>
    /// Maps the HTTP method of the ApiDescription to the HttpMethod.
    /// </summary>
    /// <param name="apiDescription">The ApiDescription to resolve an HttpMethod from.</param>
    /// <returns>The <see cref="HttpMethod"/> associated with the given <paramref name="apiDescription"/>, if known.</returns>
    public static HttpMethod? GetHttpMethod(this ApiDescription apiDescription) =>
        apiDescription.HttpMethod?.ToUpperInvariant() switch
        {
            "GET" => HttpMethod.Get,
            "POST" => HttpMethod.Post,
            "PUT" => HttpMethod.Put,
            "DELETE" => HttpMethod.Delete,
            "PATCH" => HttpMethod.Patch,
            "HEAD" => HttpMethod.Head,
            "OPTIONS" => HttpMethod.Options,
            "TRACE" => HttpMethod.Trace,
            "QUERY" => null, // OpenAPI as of 3.1 does not yet support HTTP QUERY
            _ => null,
        };

    /// <summary>
    /// Maps the relative path included in the ApiDescription to the path
    /// that should be included in the OpenApiDocument. This typically
    /// consists of removing any constraints from route parameter parts
    /// and retaining only the literals.
    /// </summary>
    /// <param name="apiDescription">The ApiDescription to resolve an item path from.</param>
    /// <returns>The resolved item path for the given <paramref name="apiDescription"/>.</returns>
    public static string MapRelativePathToItemPath(this ApiDescription apiDescription)
    {
        Debug.Assert(apiDescription.RelativePath != null, "Relative path cannot be null.");
        // "" -> "/"
        if (string.IsNullOrEmpty(apiDescription.RelativePath))
        {
            return "/";
        }
        var strippedRoute = new StringBuilder();
        var routePattern = RoutePatternFactory.Parse(apiDescription.RelativePath);
        for (var i = 0; i < routePattern.PathSegments.Count; i++)
        {
            strippedRoute.Append('/');
            var segment = routePattern.PathSegments[i];

Review comment (suggestion):
```suggestion
```

Maybe we can just link to the spec here? https://spec.openapis.org/oas/v3.1.1.html#path-item-object

Code after:
using System.Linq;
using System.Net.Http;
using System.Text;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Routing.Patterns;

internal static class ApiDescriptionExtensions
{
    /// <summary>
    /// Maps the HTTP method of the ApiDescription to the HttpMethod.
    /// </summary>
    /// <param name="apiDescription">The ApiDescription to resolve an HttpMethod from.</param>
    /// <returns>The <see cref="HttpMethod"/> associated with the given <paramref name="apiDescription"/>, if known.</returns>
    public static HttpMethod? GetHttpMethod(this ApiDescription apiDescription) =>
        apiDescription.HttpMethod?.ToUpperInvariant() switch
        {
            // Only add methods documented in the OpenAPI spec: https://spec.openapis.org/oas/v3.1.1.html#path-item-object
            "GET" => HttpMethod.Get,
            "POST" => HttpMethod.Post,
            "PUT" => HttpMethod.Put,
            "DELETE" => HttpMethod.Delete,
            "PATCH" => HttpMethod.Patch,
            "HEAD" => HttpMethod.Head,
            "OPTIONS" => HttpMethod.Options,
            "TRACE" => HttpMethod.Trace,
            _ => null,
        };

    /// <summary>
    /// Maps the relative path included in the ApiDescription to the path
    /// that should be included in the OpenApiDocument. This typically
    /// consists of removing any constraints from route parameter parts
    /// and retaining only the literals.
    /// </summary>
    /// <param name="apiDescription">The ApiDescription to resolve an item path from.</param>
    /// <returns>The resolved item path for the given <paramref name="apiDescription"/>.</returns>
    public static string MapRelativePathToItemPath(this ApiDescription apiDescription)
    {
        Debug.Assert(apiDescription.RelativePath != null, "Relative path cannot be null.");
        // "" -> "/"
        if (string.IsNullOrEmpty(apiDescription.RelativePath))
        {
            return "/";
        }
        var strippedRoute = new StringBuilder();
        var routePattern = RoutePatternFactory.Parse(apiDescription.RelativePath);
        for (var i = 0; i < routePattern.PathSegments.Count; i++)
        {
            strippedRoute.Append('/');
            var segment = routePattern.PathSegments[i];