doc-detective-common 1.21.0 → 1.21.1-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/.devcontainer/devcontainer.json +37 -37
  2. package/.github/FUNDING.yml +14 -14
  3. package/.github/workflows/npm-publish.yml +62 -62
  4. package/.github/workflows/npm-test.yml +31 -31
  5. package/LICENSE +21 -21
  6. package/README.md +85 -85
  7. package/dev/dev.js +2 -2
  8. package/package.json +36 -36
  9. package/src/files.js +64 -64
  10. package/src/index.js +11 -11
  11. package/src/resolvePaths.js +167 -167
  12. package/src/schemas/dereferenceSchemas.js +116 -115
  13. package/src/schemas/output_schemas/arazzo_v2.schema.json +40 -0
  14. package/src/schemas/output_schemas/config_v2.schema.json +2651 -2581
  15. package/src/schemas/output_schemas/spec_v2.schema.json +2099 -2034
  16. package/src/schemas/schemas.json +8004 -7829
  17. package/src/schemas/src_schemas/arazzo_v2.schema.json +42 -0
  18. package/src/schemas/src_schemas/checkLink_v2.schema.json +65 -65
  19. package/src/schemas/src_schemas/config_v2.schema.json +957 -929
  20. package/src/schemas/src_schemas/context_v2.schema.json +90 -90
  21. package/src/schemas/src_schemas/find_v2.schema.json +133 -133
  22. package/src/schemas/src_schemas/goTo_v2.schema.json +57 -57
  23. package/src/schemas/src_schemas/httpRequest_v2.schema.json +284 -284
  24. package/src/schemas/src_schemas/openApi_v2.schema.json +64 -64
  25. package/src/schemas/src_schemas/runShell_v2.schema.json +166 -166
  26. package/src/schemas/src_schemas/saveScreenshot_v2.schema.json +129 -129
  27. package/src/schemas/src_schemas/setVariables_v2.schema.json +37 -37
  28. package/src/schemas/src_schemas/spec_v2.schema.json +225 -175
  29. package/src/schemas/src_schemas/startRecording_v2.schema.json +54 -54
  30. package/src/schemas/src_schemas/stopRecording_v2.schema.json +31 -31
  31. package/src/schemas/src_schemas/test_v2.schema.json +199 -199
  32. package/src/schemas/src_schemas/typeKeys_v2.schema.json +63 -63
  33. package/src/validate.js +56 -56
  34. package/test/files.test.js +107 -107
  35. package/test/schema.test.js +31 -31
package/src/files.js CHANGED
@@ -1,64 +1,64 @@
1
- const fs = require("fs");
2
- const YAML = require("yaml");
3
- const axios = require("axios");
4
- const { URL } = require("url");
5
-
6
- /**
7
- * Reads a file from a given URL or local file path and returns its content.
8
- * Supports JSON and YAML file formats.
9
- *
10
- * @param {string} fileURL - The URL or local file path of the file to read.
11
- * @returns {Promise<Object|string|null>} - The parsed content of the file if it's JSON or YAML,
12
- * the raw content if it's another format,
13
- * or null if an error occurs.
14
- */
15
- async function readFile(fileURL) {
16
-
17
- let content;
18
- let isRemote = false;
19
-
20
- try {
21
- const parsedURL = new URL(fileURL);
22
- isRemote = parsedURL.protocol === "http:" || parsedURL.protocol === "https:";
23
- } catch (error) {
24
- // Not a valid URL, assume local file path
25
- }
26
-
27
- if (isRemote) {
28
- try {
29
- const response = await axios.get(fileURL);
30
- content = response.data;
31
- } catch (error) {
32
- console.warn(`Error reading remote file from ${fileURL}: ${error.message}`);
33
- return null;
34
- }
35
- } else {
36
- try {
37
- content = await fs.promises.readFile(fileURL, "utf8");
38
- } catch (error) {
39
- if (error.code === 'ENOENT') {
40
- console.warn(`File not found: ${fileURL}`);
41
- } else {
42
- console.warn(`Error reading file: ${error.message}`);
43
- }
44
- return null;
45
- }
46
- }
47
-
48
- // Parse based on file content, and return either object or string
49
- try {
50
- // Try to parse as JSON
51
- return JSON.parse(content);
52
- } catch (error) {
53
- try {
54
- // Try to parse as YAML
55
- return YAML.parse(content);
56
- } catch (error) {
57
- // Return raw content if not JSON or YAML
58
- return content;
59
- }
60
- }
61
-
62
- }
63
-
64
- module.exports = { readFile };
1
+ const fs = require("fs");
2
+ const YAML = require("yaml");
3
+ const axios = require("axios");
4
+ const { URL } = require("url");
5
+
6
+ /**
7
+ * Reads a file from a given URL or local file path and returns its content.
8
+ * Supports JSON and YAML file formats.
9
+ *
10
+ * @param {string} fileURL - The URL or local file path of the file to read.
11
+ * @returns {Promise<Object|string|null>} - The parsed content of the file if it's JSON or YAML,
12
+ * the raw content if it's another format,
13
+ * or null if an error occurs.
14
+ */
15
+ async function readFile(fileURL) {
16
+
17
+ let content;
18
+ let isRemote = false;
19
+
20
+ try {
21
+ const parsedURL = new URL(fileURL);
22
+ isRemote = parsedURL.protocol === "http:" || parsedURL.protocol === "https:";
23
+ } catch (error) {
24
+ // Not a valid URL, assume local file path
25
+ }
26
+
27
+ if (isRemote) {
28
+ try {
29
+ const response = await axios.get(fileURL);
30
+ content = response.data;
31
+ } catch (error) {
32
+ console.warn(`Error reading remote file from ${fileURL}: ${error.message}`);
33
+ return null;
34
+ }
35
+ } else {
36
+ try {
37
+ content = await fs.promises.readFile(fileURL, "utf8");
38
+ } catch (error) {
39
+ if (error.code === 'ENOENT') {
40
+ console.warn(`File not found: ${fileURL}`);
41
+ } else {
42
+ console.warn(`Error reading file: ${error.message}`);
43
+ }
44
+ return null;
45
+ }
46
+ }
47
+
48
+ // Parse based on file content, and return either object or string
49
+ try {
50
+ // Try to parse as JSON
51
+ return JSON.parse(content);
52
+ } catch (error) {
53
+ try {
54
+ // Try to parse as YAML
55
+ return YAML.parse(content);
56
+ } catch (error) {
57
+ // Return raw content if not JSON or YAML
58
+ return content;
59
+ }
60
+ }
61
+
62
+ }
63
+
64
+ module.exports = { readFile };
package/src/index.js CHANGED
@@ -1,11 +1,11 @@
1
- const { schemas } = require("./schemas");
2
- const { validate } = require("./validate");
3
- const { resolvePaths } = require("./resolvePaths");
4
- const { readFile } = require("./files");
5
-
6
- module.exports = {
7
- schemas,
8
- validate,
9
- resolvePaths,
10
- readFile,
11
- };
1
+ const { schemas } = require("./schemas");
2
+ const { validate } = require("./validate");
3
+ const { resolvePaths } = require("./resolvePaths");
4
+ const { readFile } = require("./files");
5
+
6
+ module.exports = {
7
+ schemas,
8
+ validate,
9
+ resolvePaths,
10
+ readFile,
11
+ };
@@ -1,167 +1,167 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const { validate } = require("./validate");
4
-
5
- exports.resolvePaths = resolvePaths;
6
-
7
- /**
8
- * Resolves paths in config and spec objects based on the provided configuration, object type, object, and source file path.
9
- *
10
- * @param {object} config - The configuration object.
11
- * @param {object} object - The object containing the paths to resolve.
12
- * @param {string} filePath - The path of the file that contains the relative paths.
13
- * @param {boolean} [nested=false] - Whether the object is nested within another object.
14
- * @param {string} [objectType] - The type of object to resolve paths in ("config" or "spec"). Required if the object is nested.
15
- * @returns {object} - The object with resolved paths.
16
- */
17
- async function resolvePaths(
18
- config,
19
- object,
20
- filePath,
21
- nested = false,
22
- objectType
23
- ) {
24
- // Config properties that contain paths
25
- const configPaths = [
26
- "input",
27
- "output",
28
- "envVariables",
29
- "setup",
30
- "cleanup",
31
- "mediaDirectory",
32
- "downloadDirectory",
33
- "descriptionPath",
34
- "path",
35
- ];
36
- // Spec properties that contain paths
37
- const specPaths = [
38
- "file",
39
- "path",
40
- "directory",
41
- "setup",
42
- "cleanup",
43
- "savePath",
44
- "saveDirectory",
45
- "descriptionPath",
46
- "workingDirectory",
47
- ];
48
- // Spec objects that are configurable by the user and shouldn't be resolved
49
- const specNoResolve = [
50
- "requestData",
51
- "responseData",
52
- "requestHeaders",
53
- "responseHeaders",
54
- "requestParams",
55
- "responseParams",
56
- ];
57
-
58
- /**
59
- * Resolves a path based on the provided base type, relative path, and file path.
60
- *
61
- * @param {string} baseType - The base type of the path ("file" or "cwd").
62
- * @param {string} relativePath - The relative path to resolve.
63
- * @param {string} filePath - The file path to use as a reference.
64
- * @returns {string} - The resolved path.
65
- */
66
- function resolve(baseType, relativePath, filePath) {
67
- // If path is already absolute, return it
68
- if (path.isAbsolute(relativePath)) {
69
- return relativePath;
70
- }
71
- // If filePath is a file, use its directory as the base path
72
- filePath = fs.lstatSync(filePath).isFile()
73
- ? path.dirname(filePath)
74
- : filePath;
75
- // Resolve the path based on the base type
76
- return baseType === "file"
77
- ? path.resolve(filePath, relativePath)
78
- : path.resolve(relativePath);
79
- }
80
-
81
- const relativePathBase = config.relativePathBase;
82
-
83
- let pathProperties;
84
- if (!nested && !objectType) {
85
- // Check if object matches the config schema
86
- const validation = validate("config_v2", { ...object });
87
- if (validation.valid) {
88
- pathProperties = configPaths;
89
- objectType = "config";
90
- } else {
91
- // Check if object matches the spec schema
92
- const validation = validate("spec_v2", { ...object });
93
- if (validation.valid) {
94
- pathProperties = specPaths;
95
- objectType = "spec";
96
- } else {
97
- throw new Error("Object isn't a valid config or spec.");
98
- }
99
- }
100
- } else if (nested && !objectType) {
101
- // If the object is nested, the object type is required
102
- throw new Error("Object type is required for nested objects.");
103
- } else if (objectType === "config") {
104
- // If the object type is config, use configPaths
105
- pathProperties = configPaths;
106
- } else if (objectType === "spec") {
107
- // If the object type is spec, use specPaths
108
- pathProperties = specPaths;
109
- }
110
-
111
- for (const property of Object.keys(object)) {
112
- if (
113
- typeof object[property] === "object" &&
114
- ((objectType === "spec" && !specNoResolve.includes(property)) ||
115
- objectType === "config")
116
- ) {
117
- // If the property is an object, recursively call resolvePaths to resolve paths within the object
118
- object[property] = await resolvePaths(
119
- config,
120
- object[property],
121
- filePath,
122
- true,
123
- objectType
124
- );
125
- } else if (typeof object[property] === "string") {
126
- // If the property is a string, check if it matches any of the path properties and resolve it if it does
127
- pathProperties.forEach((pathProperty) => {
128
- if (object[pathProperty]) {
129
- if (pathProperty === "path" && object.directory) {
130
- if (path.isAbsolute(object.directory)) {
131
- object[pathProperty] = resolve(
132
- relativePathBase,
133
- object[pathProperty],
134
- object.directory
135
- );
136
- } else {
137
- object[pathProperty] = path.join(
138
- object.directory,
139
- object[pathProperty]
140
- );
141
- }
142
- } else if (pathProperty === "savePath" && object.saveDirectory) {
143
- if (path.isAbsolute(object.saveDirectory)) {
144
- object[pathProperty] = resolve(
145
- relativePathBase,
146
- object[pathProperty],
147
- object.saveDirectory
148
- );
149
- } else {
150
- object[pathProperty] = path.join(
151
- object.saveDirectory,
152
- object[pathProperty]
153
- );
154
- }
155
- } else {
156
- object[pathProperty] = resolve(
157
- relativePathBase,
158
- object[pathProperty],
159
- filePath
160
- );
161
- }
162
- }
163
- });
164
- }
165
- }
166
- return object;
167
- }
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { validate } = require("./validate");
4
+
5
+ exports.resolvePaths = resolvePaths;
6
+
7
+ /**
8
+ * Resolves paths in config and spec objects based on the provided configuration, object type, object, and source file path.
9
+ *
10
+ * @param {object} config - The configuration object.
11
+ * @param {object} object - The object containing the paths to resolve.
12
+ * @param {string} filePath - The path of the file that contains the relative paths.
13
+ * @param {boolean} [nested=false] - Whether the object is nested within another object.
14
+ * @param {string} [objectType] - The type of object to resolve paths in ("config" or "spec"). Required if the object is nested.
15
+ * @returns {object} - The object with resolved paths.
16
+ */
17
+ async function resolvePaths(
18
+ config,
19
+ object,
20
+ filePath,
21
+ nested = false,
22
+ objectType
23
+ ) {
24
+ // Config properties that contain paths
25
+ const configPaths = [
26
+ "input",
27
+ "output",
28
+ "envVariables",
29
+ "setup",
30
+ "cleanup",
31
+ "mediaDirectory",
32
+ "downloadDirectory",
33
+ "descriptionPath",
34
+ "path",
35
+ ];
36
+ // Spec properties that contain paths
37
+ const specPaths = [
38
+ "file",
39
+ "path",
40
+ "directory",
41
+ "setup",
42
+ "cleanup",
43
+ "savePath",
44
+ "saveDirectory",
45
+ "descriptionPath",
46
+ "workingDirectory",
47
+ ];
48
+ // Spec objects that are configurable by the user and shouldn't be resolved
49
+ const specNoResolve = [
50
+ "requestData",
51
+ "responseData",
52
+ "requestHeaders",
53
+ "responseHeaders",
54
+ "requestParams",
55
+ "responseParams",
56
+ ];
57
+
58
+ /**
59
+ * Resolves a path based on the provided base type, relative path, and file path.
60
+ *
61
+ * @param {string} baseType - The base type of the path ("file" or "cwd").
62
+ * @param {string} relativePath - The relative path to resolve.
63
+ * @param {string} filePath - The file path to use as a reference.
64
+ * @returns {string} - The resolved path.
65
+ */
66
+ function resolve(baseType, relativePath, filePath) {
67
+ // If path is already absolute, return it
68
+ if (path.isAbsolute(relativePath)) {
69
+ return relativePath;
70
+ }
71
+ // If filePath is a file, use its directory as the base path
72
+ filePath = fs.lstatSync(filePath).isFile()
73
+ ? path.dirname(filePath)
74
+ : filePath;
75
+ // Resolve the path based on the base type
76
+ return baseType === "file"
77
+ ? path.resolve(filePath, relativePath)
78
+ : path.resolve(relativePath);
79
+ }
80
+
81
+ const relativePathBase = config.relativePathBase;
82
+
83
+ let pathProperties;
84
+ if (!nested && !objectType) {
85
+ // Check if object matches the config schema
86
+ const validation = validate("config_v2", { ...object });
87
+ if (validation.valid) {
88
+ pathProperties = configPaths;
89
+ objectType = "config";
90
+ } else {
91
+ // Check if object matches the spec schema
92
+ const validation = validate("spec_v2", { ...object });
93
+ if (validation.valid) {
94
+ pathProperties = specPaths;
95
+ objectType = "spec";
96
+ } else {
97
+ throw new Error("Object isn't a valid config or spec.");
98
+ }
99
+ }
100
+ } else if (nested && !objectType) {
101
+ // If the object is nested, the object type is required
102
+ throw new Error("Object type is required for nested objects.");
103
+ } else if (objectType === "config") {
104
+ // If the object type is config, use configPaths
105
+ pathProperties = configPaths;
106
+ } else if (objectType === "spec") {
107
+ // If the object type is spec, use specPaths
108
+ pathProperties = specPaths;
109
+ }
110
+
111
+ for (const property of Object.keys(object)) {
112
+ if (
113
+ typeof object[property] === "object" &&
114
+ ((objectType === "spec" && !specNoResolve.includes(property)) ||
115
+ objectType === "config")
116
+ ) {
117
+ // If the property is an object, recursively call resolvePaths to resolve paths within the object
118
+ object[property] = await resolvePaths(
119
+ config,
120
+ object[property],
121
+ filePath,
122
+ true,
123
+ objectType
124
+ );
125
+ } else if (typeof object[property] === "string") {
126
+ // If the property is a string, check if it matches any of the path properties and resolve it if it does
127
+ pathProperties.forEach((pathProperty) => {
128
+ if (object[pathProperty]) {
129
+ if (pathProperty === "path" && object.directory) {
130
+ if (path.isAbsolute(object.directory)) {
131
+ object[pathProperty] = resolve(
132
+ relativePathBase,
133
+ object[pathProperty],
134
+ object.directory
135
+ );
136
+ } else {
137
+ object[pathProperty] = path.join(
138
+ object.directory,
139
+ object[pathProperty]
140
+ );
141
+ }
142
+ } else if (pathProperty === "savePath" && object.saveDirectory) {
143
+ if (path.isAbsolute(object.saveDirectory)) {
144
+ object[pathProperty] = resolve(
145
+ relativePathBase,
146
+ object[pathProperty],
147
+ object.saveDirectory
148
+ );
149
+ } else {
150
+ object[pathProperty] = path.join(
151
+ object.saveDirectory,
152
+ object[pathProperty]
153
+ );
154
+ }
155
+ } else {
156
+ object[pathProperty] = resolve(
157
+ relativePathBase,
158
+ object[pathProperty],
159
+ filePath
160
+ );
161
+ }
162
+ }
163
+ });
164
+ }
165
+ }
166
+ return object;
167
+ }