Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
41 changes: 39 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -500,8 +501,44 @@ 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 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;
}
});
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("{") ||
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,
Expand Down