Update HTTP request handling and version bump#13
Conversation
- Rename parameter in replaceNumericVariables for clarity - Normalize step field formats for HTTP requests - Parse headers from line-separated string values - Parse JSON-as-string body for HTTP requests
WalkthroughThis change updates the package version and a dependency, refines the regex for parsing HTTP request code blocks in markdown, and introduces normalization logic for HTTP request steps in the parsing utility. The normalization includes parsing headers into objects and attempting to parse JSON bodies, with error handling for both operations. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant MarkdownParser
participant Utils
participant SchemaValidator
User->>MarkdownParser: Provide markdown with HTTP request code block
MarkdownParser->>Utils: parseContent(markdown)
Utils->>Utils: Detect httpRequest markup using new regex
Utils->>Utils: Normalize headers (string to object)
Utils->>Utils: Attempt to parse body as JSON
Utils->>SchemaValidator: Validate step against step_v3 schema
SchemaValidator-->>Utils: Validation result
Utils-->>MarkdownParser: Normalized and validated step
MarkdownParser-->>User: Parsed and normalized steps
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/utils.js (2)
504-537: Review the HTTP request normalization logic for edge cases.The normalization logic is well-implemented with proper error handling. However, consider these potential edge cases:
Header parsing: Headers containing colons in their values (e.g.,
"Date: Mon, 01 Jan 2024 12:00:00 GMT") will be incorrectly split. Consider usingsplit(':')with a limit of 2.JSON body parsing: Only parsing bodies that start with
"{"excludes valid JSON arrays or other JSON types.Consider this improvement for header parsing:
- const [key, value] = header - .split(":") - .map((s) => s.trim()); + const colonIndex = header.indexOf(':'); + if (colonIndex === -1) return; + const key = header.substring(0, colonIndex).trim(); + const value = header.substring(colonIndex + 1).trim();For JSON body parsing, consider supporting all JSON types:
- step.httpRequest.request.body.trim().startsWith("{") + (step.httpRequest.request.body.trim().startsWith("{") || + step.httpRequest.request.body.trim().startsWith("["))
523-523: Consider logging parsing errors for better debugging.The silent error handling in try-catch blocks might make debugging difficult when header or body parsing fails. Consider adding debug-level logging to help troubleshoot parsing issues.
- } catch (error) {} + } catch (error) { + // Silently ignore header parsing errors + if (config.logLevel === "debug") { + log(config, "debug", `Failed to parse headers: ${error.message}`); + } + }Also applies to: 534-534
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (3)
package.json(2 hunks)src/config.js(1 hunks)src/utils.js(2 hunks)
🔇 Additional comments (4)
src/config.js (1)
113-113: LGTM! Regex pattern improvement enhances precision.The updated regex pattern correctly uses non-greedy matching (
*?) for the HTTP request body and explicitly handles optional trailing whitespace/newlines before the closing backticks. This improvement enhances the precision of HTTP request body capture from fenced code blocks.src/utils.js (1)
285-286: Good practice: Preventing input mutation with deep copy.Creating a deep copy of the input parameter prevents unintended mutations of the original object, which is a good defensive programming practice.
package.json (2)
3-3: LGTM! Version bump follows semantic versioning.The patch version increment appropriately reflects the HTTP request handling improvements and normalization features added in this PR.
27-27:Details
❓ Verification inconclusive
Verify compatibility with the major version update.
The dependency update from
^12.0.2to^13.0.1represents a major version change that could introduce breaking changes. Ensure that the update is compatible with the current codebase.
🏁 Script executed:
#!/bin/bash # Description: Check for breaking changes in @apidevtools/json-schema-ref-parser v13 # Expected: Documentation showing compatibility or migration guide # Check for changelog or breaking changes documentation gh api repos/APIDevTools/json-schema-ref-parser/releases | jq -r '.[0:5] | .[] | select(.tag_name | startswith("v13")) | {tag_name, name, body}' # Search for any usage of the library in the codebase rg -A 3 -B 3 "@apidevtools/json-schema-ref-parser|json-schema-ref-parser"Length of output: 5785
Verify error-handling compatibility with json-schema-ref-parser v13 upgrade
I reviewed the v13 changelog and found that the only breaking change in 13.0.0 is the removal of the
onodependency, which alters the shape/stack of errors thrown by the parser. If your code doesn’t rely on anyOnoError-specific behavior, this upgrade should be safe. Otherwise, please:
- Validate error-handling in
src/openapi.js(where@apidevtools/json-schema-ref-parseris required) to ensure parser failures still surface correctly.- Run the full test suite—including any failure/integration tests around schema parsing—to catch regressions.
- Note that
doc-detective-commonstill brings in v12.0.2 of this package as a nested dependency; confirm there are no conflicting behaviors at runtime.Files to check:
- package.json (line 27:
"@apidevtools/json-schema-ref-parser": "^13.0.1")- src/openapi.js (parser usage)
- Update header parsing to handle cases without a colon - Allow parsing of both JSON and array bodies in HTTP requests
Enhance the handling of HTTP requests by improving regex support, normalizing step field formats, and parsing headers and JSON bodies. Update the package version to reflect these changes.
Summary by CodeRabbit
Bug Fixes
New Features
Chores