[Repo Assist] refactor: extract fetchUrlContent helper to eliminate HTTP fetch duplication in Utils.fs#406
Conversation
…nate duplication The HTTPS and HTTP branches of readSchemaPath shared ~50 lines of identical code for building headers, creating the HttpRequestMessage, creating the HttpClient, sending the request, and handling errors. Extract a private fetchUrlContent helper that: - Parses custom headers from the pipe-separated header string - Creates and sends the GET request with UseDefaultCredentials=false - Validates the response Content-Type - Handles all three error cases uniformly (OpenApiException, WebException, other) The HTTP branch now also handles OpenApiException (previously it would bubble up unhandled), which is a minor bug fix alongside the cleanup. readSchemaPath is reduced by ~60 lines with identical behaviour preserved. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Refactors SchemaReader.readSchemaPath to remove duplicated HTTP fetch logic by extracting a shared private helper, keeping the SSRF-guarded URL scheme branching intact while centralizing request/response handling.
Changes:
- Added a private
fetchUrlContenthelper to consolidate GET + headers + content-type validation + error handling. - Replaced duplicated
"https"and"http"fetch implementations with calls to the shared helper. - Standardized exception handling behavior across both schemes (notably
Swagger.OpenApiExceptionvsWebExceptionhandling paths).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot fix inline comments and check that there is no breaking changes. |
Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/afc4c3b8-fa37-45a7-9b26-ebaf1e5c5c64 Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
…xpression Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/afc4c3b8-fa37-45a7-9b26-ebaf1e5c5c64 Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
Fixed all inline comments in commits f43d9c8 and e0959ae:
All 327 unit tests pass and Fantomas format check passes. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot fix build and formatting |
Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/129f72d4-4d34-42d1-b945-80161589697c Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
Fixed in commit |
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Extracts a private
fetchUrlContenthelper fromreadSchemaPathinUtils.fs, eliminating ~60 lines of code duplication between the"https"and"http"URL scheme branches.Before
Both branches independently built the same header dictionary, created the same
HttpRequestMessage/HttpClient, sent the request, and handled errors — ~50 lines duplicated verbatim.After
A single
fetchUrlContenthelper handles the shared logic. Each scheme branch is reduced to its unique part:Minor fix included
The original HTTP branch did not handle
Swagger.OpenApiException(it would bubble up unhandled). The shared helper now handles it consistently for both HTTP and HTTPS, matching the original HTTPS behaviour.Test Status
✅ All 327 unit tests pass (same as baseline, no regressions).
✅ Fantomas format check passes (
dotnet fantomas --check src/SwaggerProvider.DesignTime/Utils.fs).