Repository: dotnet/aspnetcore
File: src/OpenApi/src/Services/OpenApiDocumentService.cs (C#)

Code before:
        var bindingMetadata = description.ActionDescriptor.EndpointMetadata
            .OfType<IParameterBindingMetadata>()
            .SingleOrDefault(metadata => metadata.Name == parameter.Name);
        var parameterType = parameter.Type is not null
            ? Nullable.GetUnderlyingType(parameter.Type) ?? parameter.Type
            : parameter.Type;

        // parameter.Type = typeof(string)
        // parameter.ModelMetadata.Type = typeof(TEnum)
        var requiresModelMetadataFallbackForEnum = parameterType == typeof(string)
            && parameter.ModelMetadata.ModelType != parameter.Type
            && parameter.ModelMetadata.ModelType.IsEnum;
        // Enums are exempt because we want to set the IOpenApiSchema.Enum field when feasible.
        // parameter.Type = typeof(TEnum), typeof(TypeWithTryParse)
        // parameter.ModelMetadata.Type = typeof(string)
        var hasTryParse = bindingMetadata?.HasTryParse == true && parameterType is not null && !parameterType.IsEnum;
        var targetType = requiresModelMetadataFallbackForEnum || hasTryParse
            ? parameter.ModelMetadata.ModelType
            : parameter.Type;
        targetType ??= typeof(string);
        return targetType;
    }

    /// <inheritdoc />
    public Task<OpenApiDocument> GetOpenApiDocumentAsync(CancellationToken cancellationToken = default)
        => GetOpenApiDocumentAsync(serviceProvider, null, cancellationToken);
}


Review comment (suggestion):
```suggestion
        => GetOpenApiDocumentAsync(serviceProvider, httpRequest: null, cancellationToken);
```

Code after:
        var bindingMetadata = description.ActionDescriptor.EndpointMetadata
            .OfType<IParameterBindingMetadata>()
            .SingleOrDefault(metadata => metadata.Name == parameter.Name);
        var parameterType = parameter.Type is not null
            ? Nullable.GetUnderlyingType(parameter.Type) ?? parameter.Type
            : parameter.Type;

        // parameter.Type = typeof(string)
        // parameter.ModelMetadata.Type = typeof(TEnum)
        var requiresModelMetadataFallbackForEnum = parameterType == typeof(string)
            && parameter.ModelMetadata.ModelType != parameter.Type
            && parameter.ModelMetadata.ModelType.IsEnum;
        // Enums are exempt because we want to set the IOpenApiSchema.Enum field when feasible.
        // parameter.Type = typeof(TEnum), typeof(TypeWithTryParse)
        // parameter.ModelMetadata.Type = typeof(string)
        var hasTryParse = bindingMetadata?.HasTryParse == true && parameterType is not null && !parameterType.IsEnum;
        var targetType = requiresModelMetadataFallbackForEnum || hasTryParse
            ? parameter.ModelMetadata.ModelType
            : parameter.Type;
        targetType ??= typeof(string);
        return targetType;
    }

    /// <inheritdoc />
    public Task<OpenApiDocument> GetOpenApiDocumentAsync(CancellationToken cancellationToken = default)
    {
        cancellationToken.ThrowIfCancellationRequested();
        return GetOpenApiDocumentAsync(serviceProvider, httpRequest: null, cancellationToken);
    }
}