From e1d04dd8f41785f42293e4db20bb5bbbbd5e4840 Mon Sep 17 00:00:00 2001 From: hawkeyexl Date: Tue, 3 Jun 2025 13:22:15 -0700 Subject: [PATCH 1/4] Update regex for httpRequestFormat to support optional trailing newlines --- src/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.js b/src/config.js index a4d59f0..1921ba4 100644 --- a/src/config.js +++ b/src/config.js @@ -110,7 +110,7 @@ let defaultFileTypes = { { name: "httpRequestFormat", regex: [ - "```(?:http)?\\r?\\n([A-Z]+)\\s+([^\\s]+)(?:\\s+HTTP\\/[\\d.]+)?\\r?\\n((?:[^\\s]+:\\s+[^\\s]+\\r?\\n)*)?(?:\\s+([\\s\\S]*)\\s+)?```", + "```(?:http)?\\r?\\n([A-Z]+)\\s+([^\\s]+)(?:\\s+HTTP\\/[\\d.]+)?\\r?\\n((?:[^\\s]+:\\s+[^\\s]+\\r?\\n)*)?(?:\\s+([\\s\\S]*?)\\r?\\n+)?```", ], actions: [ { From 9276ec51cc7ea02d0de4377b6c2d696b30fc7d2d Mon Sep 17 00:00:00 2001 From: hawkeyexl Date: Tue, 3 Jun 2025 13:22:22 -0700 Subject: [PATCH 2/4] Enhance parseContent function to improve HTTP request handling - 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 --- src/utils.js | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/utils.js b/src/utils.js index c98f522..3585e49 100644 --- a/src/utils.js +++ b/src/utils.js @@ -282,7 +282,8 @@ async function parseContent({ config, content, filePath, fileType }) { return test; } - function replaceNumericVariables(stringOrObject, values) { + function replaceNumericVariables(stringOrObjectSource, values) { + let stringOrObject = JSON.parse(JSON.stringify(stringOrObjectSource)); if ( typeof stringOrObject !== "string" && typeof stringOrObject !== "object" @@ -500,8 +501,42 @@ async function parseContent({ config, content, filePath, fileType }) { // TODO: Make key substitution recursive step = replaceNumericVariables(action, statement); } + + // Normalize step field formats + if (step.httpRequest) { + // Parse headers from line-separated string values + // Example string: "Content-Type: application/json\nAuthorization: Bearer token" + if (typeof step.httpRequest.request.headers === "string") { + try { + const headers = {}; + step.httpRequest.request.headers + .split("\n") + .forEach((header) => { + const [key, value] = header + .split(":") + .map((s) => s.trim()); + if (key && value) { + headers[key] = value; + } + }); + step.httpRequest.request.headers = headers; + } catch (error) {} + } + // Parse JSON-as-string body + if ( + typeof step.httpRequest.request.body === "string" && + step.httpRequest.request.body.trim().startsWith("{") + ) { + try { + step.httpRequest.request.body = JSON.parse( + step.httpRequest.request.body + ); + } catch (error) {} + } + } + // Make sure is valid v3 step schema - valid = validate({ + const valid = validate({ schemaKey: "step_v3", object: step, addDefaults: false, From e025784bda03d98c2fe0d6cc098927caebb3374e Mon Sep 17 00:00:00 2001 From: hawkeyexl Date: Tue, 3 Jun 2025 13:31:19 -0700 Subject: [PATCH 3/4] bump version --- package-lock.json | 33 +++++++++++++++++++++++++-------- package.json | 4 ++-- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index aea87c2..000adeb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "doc-detective-resolver", - "version": "3.0.8", + "version": "3.0.9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "doc-detective-resolver", - "version": "3.0.8", + "version": "3.0.9", "license": "AGPL-3.0-only", "dependencies": { - "@apidevtools/json-schema-ref-parser": "^12.0.2", + "@apidevtools/json-schema-ref-parser": "^13.0.1", "ajv": "^8.17.1", "axios": "^1.9.0", "doc-detective-common": "^3.0.8", @@ -28,12 +28,11 @@ } }, "node_modules/@apidevtools/json-schema-ref-parser": { - "version": "12.0.2", - "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-12.0.2.tgz", - "integrity": "sha512-SoZWqQz4YMKdw4kEMfG5w6QAy+rntjsoAT1FtvZAnVEnCR4uy9YSuDBNoVAFHgzSz0dJbISLLCSrGR2Zd7bcvA==", + "version": "13.0.1", + "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-13.0.1.tgz", + "integrity": "sha512-91uy6MGWqu7CjcV7tLPMuYh/Wj/RNPBXquSdEaCEpj2H/cFy0Yu+t1EdxExSyaryl1ykhDo30plq9tIm/HVZnw==", "license": "MIT", "dependencies": { - "@jsdevtools/ono": "^7.1.3", "@types/json-schema": "^7.0.15", "js-yaml": "^4.1.0" }, @@ -93,7 +92,8 @@ "node_modules/@jsdevtools/ono": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/@jsdevtools/ono/-/ono-7.1.3.tgz", - "integrity": "sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==" + "integrity": "sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==", + "license": "MIT" }, "node_modules/@jsep-plugin/assignment": { "version": "1.3.0", @@ -744,6 +744,23 @@ "yaml": "^2.8.0" } }, + "node_modules/doc-detective-common/node_modules/@apidevtools/json-schema-ref-parser": { + "version": "12.0.2", + "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-12.0.2.tgz", + "integrity": "sha512-SoZWqQz4YMKdw4kEMfG5w6QAy+rntjsoAT1FtvZAnVEnCR4uy9YSuDBNoVAFHgzSz0dJbISLLCSrGR2Zd7bcvA==", + "license": "MIT", + "dependencies": { + "@jsdevtools/ono": "^7.1.3", + "@types/json-schema": "^7.0.15", + "js-yaml": "^4.1.0" + }, + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://github.com/sponsors/philsturgeon" + } + }, "node_modules/dotenv": { "version": "16.5.0", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.5.0.tgz", diff --git a/package.json b/package.json index 94a1a63..aef5010 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "doc-detective-resolver", - "version": "3.0.8", + "version": "3.0.9", "description": "Detect and resolve docs into Doc Detective tests.", "main": "src/index.js", "scripts": { @@ -24,7 +24,7 @@ }, "homepage": "https://github.com/doc-detective/doc-detective-core#readme", "dependencies": { - "@apidevtools/json-schema-ref-parser": "^12.0.2", + "@apidevtools/json-schema-ref-parser": "^13.0.1", "ajv": "^8.17.1", "axios": "^1.9.0", "doc-detective-common": "^3.0.8", From 2c0c265b49c997ef71470e3ba141df1449687a28 Mon Sep 17 00:00:00 2001 From: hawkeyexl Date: Tue, 3 Jun 2025 13:44:28 -0700 Subject: [PATCH 4/4] Improve HTTP request header parsing in parseContent function - Update header parsing to handle cases without a colon - Allow parsing of both JSON and array bodies in HTTP requests --- src/utils.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utils.js b/src/utils.js index 3585e49..7918e14 100644 --- a/src/utils.js +++ b/src/utils.js @@ -512,9 +512,10 @@ async function parseContent({ config, content, filePath, fileType }) { step.httpRequest.request.headers .split("\n") .forEach((header) => { - 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(); if (key && value) { headers[key] = value; } @@ -525,7 +526,8 @@ async function parseContent({ config, content, filePath, fileType }) { // Parse JSON-as-string body if ( typeof step.httpRequest.request.body === "string" && - step.httpRequest.request.body.trim().startsWith("{") + (step.httpRequest.request.body.trim().startsWith("{") || + step.httpRequest.request.body.trim().startsWith("[")) ) { try { step.httpRequest.request.body = JSON.parse(