httpgenerator icon indicating copy to clipboard operation
httpgenerator copied to clipboard

Fix string handling edge cases and case-insensitive URL/file detection

Open Copilot opened this issue 1 month ago • 2 comments

Description:

Fixes several bugs discovered during codebase analysis:

String handling edge cases (StringExtensions.cs)

  • CapitalizeFirstCharacter() threw ArgumentOutOfRangeException on empty strings
  • Added null/empty guard and single-character handling

Case-insensitive URL/file detection (OpenApiDocumentFactory.cs, OpenApiValidator.cs)

  • IsHttp() failed for uppercase URLs like HTTP:// or HTTPS://
  • IsYaml() matched filenames like notayaml instead of only .yaml/.yml extensions
  • GetStream() used case-sensitive HTTP check

Unnecessary FileInfo allocation (OpenApiValidator.cs)

  • ParseOpenApi() created FileInfo for HTTP URLs; refactored to only allocate when processing file paths

Example fix for CapitalizeFirstCharacter:

// Before: throws on empty string
return str.Substring(0, 1).ToUpperInvariant() + str.Substring(1, str.Length - 1);

// After: handles edge cases
if (string.IsNullOrEmpty(str))
    return str;
if (str.Length == 1)
    return str.ToUpperInvariant();
return str.Substring(0, 1).ToUpperInvariant() + str.Substring(1, str.Length - 1);

Example fix for IsYaml:

// Before: matches "notayaml"
return path.EndsWith("yaml") || path.EndsWith("yml");

// After: requires dot prefix, case-insensitive
return path.EndsWith(".yaml", StringComparison.OrdinalIgnoreCase) || 
       path.EndsWith(".yml", StringComparison.OrdinalIgnoreCase);

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • demo.netbox.dev
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/HttpGenerator.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/HttpGenerator.Tests.deps.json /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/testhost.dll --port 44509 --endpoint 127.0.0.1:044509 --role client --parentprocessid 3654 --telemetryoptedin false (dns block)
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/HttpGenerator.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/HttpGenerator.Tests.deps.json /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/testhost.dll --port 36815 --endpoint 127.0.0.1:036815 --role client --parentprocessid 4630 --telemetryoptedin false (dns block)
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/HttpGenerator.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/HttpGenerator.Tests.deps.json /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/testhost.dll --port 39719 --endpoint 127.0.0.1:039719 --role client --parentprocessid 5588 --telemetryoptedin false (dns block)
  • developers.intellihr.io
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/HttpGenerator.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/HttpGenerator.Tests.deps.json /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/testhost.dll --port 44509 --endpoint 127.0.0.1:044509 --role client --parentprocessid 3654 --telemetryoptedin false (dns block)
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/HttpGenerator.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/HttpGenerator.Tests.deps.json /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/testhost.dll --port 36815 --endpoint 127.0.0.1:036815 --role client --parentprocessid 4630 --telemetryoptedin false (dns block)
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/HttpGenerator.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/HttpGenerator.Tests.deps.json /home/REDACTED/work/httpgenerator/httpgenerator/src/HttpGenerator.Tests/bin/Release/net8.0/testhost.dll --port 39719 --endpoint 127.0.0.1:039719 --role client --parentprocessid 5588 --telemetryoptedin false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Find and resolve bugs and issue in the current code base. Be as thorough as possible


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Nov 28 '25 13:11 Copilot

[!IMPORTANT]

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Nov 28 '25 13:11 coderabbitai[bot]

Codecov Report

:x: Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 85.12%. Comparing base (3d6a413) to head (4d55b0a). :warning: Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/HttpGenerator.Core/OpenApiDocumentFactory.cs 50.00% 2 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #290      +/-   ##
==========================================
+ Coverage   84.93%   85.12%   +0.18%     
==========================================
  Files          12       12              
  Lines         551      558       +7     
  Branches       76       78       +2     
==========================================
+ Hits          468      475       +7     
  Misses         70       70              
  Partials       13       13              
Flag Coverage Δ
unittests 85.12% <85.71%> (+0.18%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Dec 08 '25 12:12 codecov[bot]