Skip to content

Update HTTP request handling and version bump#13

Merged
hawkeyexl merged 4 commits intomainfrom
helper-parsing
Jun 3, 2025
Merged

Update HTTP request handling and version bump#13
hawkeyexl merged 4 commits intomainfrom
helper-parsing

Conversation

@hawkeyexl
Copy link
Contributor

@hawkeyexl hawkeyexl commented Jun 3, 2025

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

    • Improved the precision of HTTP request body detection in markdown code blocks, reducing the chance of capturing unwanted trailing whitespace or newlines.
  • New Features

    • HTTP headers in request steps are now automatically parsed from a string into key-value pairs.
    • HTTP request bodies that are valid JSON are now automatically parsed for easier handling.
  • Chores

    • Updated a dependency to the latest version for improved stability.

hawkeyexl added 3 commits June 3, 2025 13:22
- 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
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 3, 2025

Walkthrough

This 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

File(s) Change Summary
package.json Bumped version from 3.0.8 to 3.0.9; updated "@apidevtools/json-schema-ref-parser" from ^12.0.2 to ^13.0.1.
src/config.js Modified the regex for "httpRequestFormat" to use non-greedy body capture and allow optional trailing newlines.
src/utils.js Updated to deep copy input in replaceNumericVariables; added normalization for HTTP headers and body in steps with httpRequest.

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
Loading

Possibly related PRs

Poem

A regex refined, with care and delight,
Now HTTP blocks are captured just right.
Headers parsed, bodies decoded anew,
JSON or not, we’ll know what to do!
With a hop and a skip, this bunny’s quite proud—
Version bumped up, we’re hopping aloud!
🐇✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e025784 and 2c0c265.

📒 Files selected for processing (1)
  • src/utils.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/utils.js
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Header parsing: Headers containing colons in their values (e.g., "Date: Mon, 01 Jan 2024 12:00:00 GMT") will be incorrectly split. Consider using split(':') with a limit of 2.

  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

📥 Commits

Reviewing files that changed from the base of the PR and between 489c98b and e025784.

⛔ Files ignored due to path filters (1)
  • package-lock.json is 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.2 to ^13.0.1 represents 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 ono dependency, which alters the shape/stack of errors thrown by the parser. If your code doesn’t rely on any OnoError-specific behavior, this upgrade should be safe. Otherwise, please:

  • Validate error-handling in src/openapi.js (where @apidevtools/json-schema-ref-parser is 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-common still 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
@hawkeyexl hawkeyexl merged commit f965e95 into main Jun 3, 2025
15 checks passed
@hawkeyexl hawkeyexl deleted the helper-parsing branch June 3, 2025 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant