@scalar/openapi-parser 0.8.6 → 0.8.8
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.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/configuration/index.js +27 -1
- package/dist/index.js +26 -1
- package/dist/lib/Validator/Validator.js +127 -1
- package/dist/{utils/load/plugins → plugins/fetch-urls}/fetchUrls.d.ts +1 -1
- package/dist/plugins/fetch-urls/fetchUrls.d.ts.map +1 -0
- package/dist/plugins/fetch-urls/fetchUrls.js +45 -0
- package/dist/plugins/fetch-urls/index.d.ts +2 -0
- package/dist/plugins/fetch-urls/index.d.ts.map +1 -0
- package/dist/plugins/fetch-urls/index.js +1 -0
- package/dist/plugins/read-files/index.d.ts +2 -0
- package/dist/plugins/read-files/index.d.ts.map +1 -0
- package/dist/plugins/read-files/index.js +1 -0
- package/dist/plugins/read-files/readFiles.d.ts +3 -0
- package/dist/plugins/read-files/readFiles.d.ts.map +1 -0
- package/dist/plugins/read-files/readFiles.js +56 -0
- package/dist/polyfills/path.js +120 -1
- package/dist/schemas/v2.0/schema.json.js +1623 -1
- package/dist/schemas/v3.0/schema.json.js +1673 -1
- package/dist/schemas/v3.1/schema.json.js +1451 -1
- package/dist/utils/betterAjvErrors/helpers.js +108 -1
- package/dist/utils/betterAjvErrors/index.js +15 -1
- package/dist/utils/betterAjvErrors/utils.js +31 -1
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js +20 -1
- package/dist/utils/betterAjvErrors/validation-errors/base.js +34 -1
- package/dist/utils/betterAjvErrors/validation-errors/default.js +20 -1
- package/dist/utils/betterAjvErrors/validation-errors/enum.js +58 -1
- package/dist/utils/betterAjvErrors/validation-errors/pattern.js +20 -1
- package/dist/utils/betterAjvErrors/validation-errors/required.js +19 -1
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js +20 -1
- package/dist/utils/dereference.js +21 -1
- package/dist/utils/details.js +25 -1
- package/dist/utils/escapeJsonPointer.js +10 -1
- package/dist/utils/filter.js +17 -1
- package/dist/utils/getEntrypoint.js +8 -1
- package/dist/utils/getListOfReferences.js +27 -1
- package/dist/utils/getSegmentsFromPath.js +18 -1
- package/dist/utils/isFilesystem.js +11 -1
- package/dist/utils/isJson.js +11 -1
- package/dist/utils/isObject.js +6 -1
- package/dist/utils/isYaml.js +19 -1
- package/dist/utils/load/load.js +121 -1
- package/dist/utils/makeFilesystem.js +25 -1
- package/dist/utils/normalize.js +25 -1
- package/dist/utils/openapi/actions/details.js +13 -1
- package/dist/utils/openapi/actions/files.js +11 -1
- package/dist/utils/openapi/actions/get.js +13 -1
- package/dist/utils/openapi/actions/toJson.js +13 -1
- package/dist/utils/openapi/actions/toYaml.js +13 -1
- package/dist/utils/openapi/commands/dereferenceCommand.js +29 -1
- package/dist/utils/openapi/commands/filterCommand.js +28 -1
- package/dist/utils/openapi/commands/loadCommand.js +44 -1
- package/dist/utils/openapi/commands/upgradeCommand.js +31 -1
- package/dist/utils/openapi/commands/validateCommand.js +35 -1
- package/dist/utils/openapi/openapi.js +18 -1
- package/dist/utils/openapi/utils/queueTask.js +11 -1
- package/dist/utils/openapi/utils/workThroughQueue.js +67 -1
- package/dist/utils/resolveReferences.js +153 -1
- package/dist/utils/toJson.js +3 -1
- package/dist/utils/toYaml.js +5 -1
- package/dist/utils/transformErrors.js +23 -1
- package/dist/utils/traverse.js +26 -1
- package/dist/utils/unescapeJsonPointer.js +11 -1
- package/dist/utils/upgrade.js +20 -1
- package/dist/utils/upgradeFromThreeToThreeOne.js +122 -1
- package/dist/utils/upgradeFromTwoToThree.js +174 -1
- package/dist/utils/validate.js +18 -1
- package/package.json +15 -13
- package/dist/utils/load/plugins/fetchUrls.d.ts.map +0 -1
- package/dist/utils/load/plugins/fetchUrls.js +0 -1
- package/dist/utils/load/plugins/readFiles.d.ts +0 -3
- package/dist/utils/load/plugins/readFiles.d.ts.map +0 -1
- package/dist/utils/load/plugins/readFiles.js +0 -1
package/dist/utils/load/load.js
CHANGED
|
@@ -1 +1,121 @@
|
|
|
1
|
-
import{ERRORS
|
|
1
|
+
import { ERRORS } from '../../configuration/index.js';
|
|
2
|
+
import { getEntrypoint } from '../getEntrypoint.js';
|
|
3
|
+
import { getListOfReferences } from '../getListOfReferences.js';
|
|
4
|
+
import { makeFilesystem } from '../makeFilesystem.js';
|
|
5
|
+
import { normalize } from '../normalize.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Loads an OpenAPI document, including any external references.
|
|
9
|
+
*
|
|
10
|
+
* This function handles loading content from various sources, normalizes the content,
|
|
11
|
+
* and recursively loads any external references found within the definition.
|
|
12
|
+
*
|
|
13
|
+
* It builds a filesystem representation of all loaded content and collects any errors
|
|
14
|
+
* encountered during the process.
|
|
15
|
+
*/
|
|
16
|
+
async function load(value, options) {
|
|
17
|
+
const errors = [];
|
|
18
|
+
// Don’t load a reference twice, check the filesystem before fetching something
|
|
19
|
+
if (options?.filesystem?.find((entry) => entry.filename === value)) {
|
|
20
|
+
return {
|
|
21
|
+
specification: getEntrypoint(options.filesystem)?.specification,
|
|
22
|
+
filesystem: options.filesystem,
|
|
23
|
+
errors,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
// Check whether the value is an URL or file path
|
|
27
|
+
const plugin = options?.plugins?.find((thisPlugin) => thisPlugin.check(value));
|
|
28
|
+
let content;
|
|
29
|
+
if (plugin) {
|
|
30
|
+
try {
|
|
31
|
+
content = normalize(await plugin.get(value));
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (options?.throwOnError) {
|
|
35
|
+
throw new Error(ERRORS.EXTERNAL_REFERENCE_NOT_FOUND.replace('%s', value));
|
|
36
|
+
}
|
|
37
|
+
errors.push({
|
|
38
|
+
code: 'EXTERNAL_REFERENCE_NOT_FOUND',
|
|
39
|
+
message: ERRORS.EXTERNAL_REFERENCE_NOT_FOUND.replace('%s', value),
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
specification: null,
|
|
43
|
+
filesystem: [],
|
|
44
|
+
errors,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
content = normalize(value);
|
|
50
|
+
}
|
|
51
|
+
// No content
|
|
52
|
+
if (content === undefined) {
|
|
53
|
+
if (options?.throwOnError) {
|
|
54
|
+
throw new Error('No content to load');
|
|
55
|
+
}
|
|
56
|
+
errors.push({
|
|
57
|
+
code: 'NO_CONTENT',
|
|
58
|
+
message: ERRORS.NO_CONTENT,
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
specification: null,
|
|
62
|
+
filesystem: [],
|
|
63
|
+
errors,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
let filesystem = makeFilesystem(content, {
|
|
67
|
+
filename: options?.filename ?? null,
|
|
68
|
+
});
|
|
69
|
+
// Get references from file system entry, or from the content
|
|
70
|
+
const newEntry = options?.filename
|
|
71
|
+
? filesystem.find((entry) => entry.filename === options?.filename)
|
|
72
|
+
: getEntrypoint(filesystem);
|
|
73
|
+
const listOfReferences = newEntry.references ?? getListOfReferences(content);
|
|
74
|
+
// No other references
|
|
75
|
+
if (listOfReferences.length === 0) {
|
|
76
|
+
return {
|
|
77
|
+
specification: getEntrypoint(filesystem)?.specification,
|
|
78
|
+
filesystem,
|
|
79
|
+
errors,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
// Load other external references
|
|
83
|
+
for (const reference of listOfReferences) {
|
|
84
|
+
// Find a matching plugin
|
|
85
|
+
const otherPlugin = options?.plugins?.find((thisPlugin) => thisPlugin.check(reference));
|
|
86
|
+
// Skip if no plugin is found (internal references don’t need a plugin for example)
|
|
87
|
+
if (!otherPlugin) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const target = otherPlugin.check(reference) && otherPlugin.resolvePath
|
|
91
|
+
? otherPlugin.resolvePath(value, reference)
|
|
92
|
+
: reference;
|
|
93
|
+
// Don’t load a reference twice, check the filesystem before fetching something
|
|
94
|
+
if (filesystem.find((entry) => entry.filename === reference)) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const { filesystem: referencedFiles, errors: newErrors } = await load(target, {
|
|
98
|
+
...options,
|
|
99
|
+
// Make the filename the exact same value as the $ref
|
|
100
|
+
// TODO: This leads to problems, if there are multiple references with the same file name but in different folders
|
|
101
|
+
filename: reference,
|
|
102
|
+
});
|
|
103
|
+
errors.push(...newErrors);
|
|
104
|
+
filesystem = [
|
|
105
|
+
...filesystem,
|
|
106
|
+
...referencedFiles.map((file) => {
|
|
107
|
+
return {
|
|
108
|
+
...file,
|
|
109
|
+
isEntrypoint: false,
|
|
110
|
+
};
|
|
111
|
+
}),
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
specification: getEntrypoint(filesystem)?.specification,
|
|
116
|
+
filesystem,
|
|
117
|
+
errors,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { load };
|
|
@@ -1 +1,25 @@
|
|
|
1
|
-
import{getListOfReferences
|
|
1
|
+
import { getListOfReferences } from './getListOfReferences.js';
|
|
2
|
+
import { isFilesystem } from './isFilesystem.js';
|
|
3
|
+
import { normalize } from './normalize.js';
|
|
4
|
+
|
|
5
|
+
function makeFilesystem(value, overwrites = {}) {
|
|
6
|
+
// Keep as is
|
|
7
|
+
if (isFilesystem(value)) {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
// Make an object
|
|
11
|
+
const specification = normalize(value);
|
|
12
|
+
// Create fake filesystem
|
|
13
|
+
return [
|
|
14
|
+
{
|
|
15
|
+
isEntrypoint: true,
|
|
16
|
+
specification,
|
|
17
|
+
filename: null,
|
|
18
|
+
dir: './',
|
|
19
|
+
references: getListOfReferences(specification),
|
|
20
|
+
...overwrites,
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { makeFilesystem };
|
package/dist/utils/normalize.js
CHANGED
|
@@ -1 +1,25 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { parse } from 'yaml';
|
|
2
|
+
import { isFilesystem } from './isFilesystem.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Normalize the OpenAPI specification to a JavaScript object.
|
|
6
|
+
* Don’t touch the object if it’s a `Filesystem` (multiple files).
|
|
7
|
+
*/
|
|
8
|
+
function normalize(specification) {
|
|
9
|
+
if (isFilesystem(specification)) {
|
|
10
|
+
return specification;
|
|
11
|
+
}
|
|
12
|
+
if (typeof specification === 'string') {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(specification);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
return parse(specification, {
|
|
18
|
+
maxAliasCount: 10000,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return specification;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { normalize };
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
import{details as
|
|
1
|
+
import { details as details$1 } from '../../details.js';
|
|
2
|
+
import { getEntrypoint } from '../../getEntrypoint.js';
|
|
3
|
+
import { workThroughQueue } from '../utils/workThroughQueue.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Run the chained tasks and return just some basic information about the OpenAPI document
|
|
7
|
+
*/
|
|
8
|
+
async function details(queue) {
|
|
9
|
+
const { filesystem } = await workThroughQueue(queue);
|
|
10
|
+
return details$1(getEntrypoint(filesystem).specification);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { details };
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
import{workThroughQueue
|
|
1
|
+
import { workThroughQueue } from '../utils/workThroughQueue.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Run the chained tasks and return just the filesystem
|
|
5
|
+
*/
|
|
6
|
+
async function files(queue) {
|
|
7
|
+
const { filesystem } = await workThroughQueue(queue);
|
|
8
|
+
return filesystem;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { files };
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
import{workThroughQueue
|
|
1
|
+
import { workThroughQueue } from '../utils/workThroughQueue.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Run the chained tasks and return the results
|
|
5
|
+
*/
|
|
6
|
+
async function get(queue) {
|
|
7
|
+
return {
|
|
8
|
+
filesystem: [],
|
|
9
|
+
...(await workThroughQueue(queue)),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { get };
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
import{getEntrypoint
|
|
1
|
+
import { getEntrypoint } from '../../getEntrypoint.js';
|
|
2
|
+
import { toJson as toJson$1 } from '../../toJson.js';
|
|
3
|
+
import { workThroughQueue } from '../utils/workThroughQueue.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Run the chained tasks and return the results
|
|
7
|
+
*/
|
|
8
|
+
async function toJson(queue) {
|
|
9
|
+
const { filesystem } = await workThroughQueue(queue);
|
|
10
|
+
return toJson$1(getEntrypoint(filesystem).specification);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { toJson };
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
import{getEntrypoint
|
|
1
|
+
import { getEntrypoint } from '../../getEntrypoint.js';
|
|
2
|
+
import { toYaml as toYaml$1 } from '../../toYaml.js';
|
|
3
|
+
import { workThroughQueue } from '../utils/workThroughQueue.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Run the chained tasks and return the results
|
|
7
|
+
*/
|
|
8
|
+
async function toYaml(queue) {
|
|
9
|
+
const { filesystem } = await workThroughQueue(queue);
|
|
10
|
+
return toYaml$1(getEntrypoint(filesystem).specification);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { toYaml };
|
|
@@ -1 +1,29 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { details } from '../actions/details.js';
|
|
2
|
+
import { files } from '../actions/files.js';
|
|
3
|
+
import { get } from '../actions/get.js';
|
|
4
|
+
import { toJson } from '../actions/toJson.js';
|
|
5
|
+
import { toYaml } from '../actions/toYaml.js';
|
|
6
|
+
import { queueTask } from '../utils/queueTask.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Dereference the given OpenAPI document
|
|
10
|
+
*/
|
|
11
|
+
function dereferenceCommand(previousQueue, options) {
|
|
12
|
+
const task = {
|
|
13
|
+
name: 'dereference',
|
|
14
|
+
options: {
|
|
15
|
+
throwOnError: previousQueue.options?.throwOnError,
|
|
16
|
+
...(options ?? {}),
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
const queue = queueTask(previousQueue, task);
|
|
20
|
+
return {
|
|
21
|
+
details: () => details(queue),
|
|
22
|
+
files: () => files(queue),
|
|
23
|
+
get: () => get(queue),
|
|
24
|
+
toJson: () => toJson(queue),
|
|
25
|
+
toYaml: () => toYaml(queue),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { dereferenceCommand };
|
|
@@ -1 +1,28 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { details } from '../actions/details.js';
|
|
2
|
+
import { files } from '../actions/files.js';
|
|
3
|
+
import { get } from '../actions/get.js';
|
|
4
|
+
import { toJson } from '../actions/toJson.js';
|
|
5
|
+
import { toYaml } from '../actions/toYaml.js';
|
|
6
|
+
import { queueTask } from '../utils/queueTask.js';
|
|
7
|
+
import { dereferenceCommand } from './dereferenceCommand.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Filter the given OpenAPI document
|
|
11
|
+
*/
|
|
12
|
+
function filterCommand(previousQueue, options) {
|
|
13
|
+
const task = {
|
|
14
|
+
name: 'filter',
|
|
15
|
+
options,
|
|
16
|
+
};
|
|
17
|
+
const queue = queueTask(previousQueue, task);
|
|
18
|
+
return {
|
|
19
|
+
dereference: (dereferenceOptions) => dereferenceCommand(queue, dereferenceOptions),
|
|
20
|
+
details: () => details(queue),
|
|
21
|
+
files: () => files(queue),
|
|
22
|
+
get: () => get(queue),
|
|
23
|
+
toJson: () => toJson(queue),
|
|
24
|
+
toYaml: () => toYaml(queue),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { filterCommand };
|
|
@@ -1 +1,44 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { details } from '../actions/details.js';
|
|
2
|
+
import { files } from '../actions/files.js';
|
|
3
|
+
import { get } from '../actions/get.js';
|
|
4
|
+
import { toJson } from '../actions/toJson.js';
|
|
5
|
+
import { toYaml } from '../actions/toYaml.js';
|
|
6
|
+
import { queueTask } from '../utils/queueTask.js';
|
|
7
|
+
import { dereferenceCommand } from './dereferenceCommand.js';
|
|
8
|
+
import { filterCommand } from './filterCommand.js';
|
|
9
|
+
import { upgradeCommand } from './upgradeCommand.js';
|
|
10
|
+
import { validateCommand } from './validateCommand.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Pass any OpenAPI document
|
|
14
|
+
*/
|
|
15
|
+
function loadCommand(previousQueue, input, options) {
|
|
16
|
+
const task = {
|
|
17
|
+
name: 'load',
|
|
18
|
+
options: {
|
|
19
|
+
// global
|
|
20
|
+
throwOnError: previousQueue.options?.throwOnError,
|
|
21
|
+
// local
|
|
22
|
+
...options,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const queue = {
|
|
26
|
+
// Add the load task
|
|
27
|
+
...queueTask(previousQueue, task),
|
|
28
|
+
// Add input to the queue
|
|
29
|
+
input,
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
dereference: (dereferenceOptions) => dereferenceCommand(queue, dereferenceOptions),
|
|
33
|
+
details: () => details(queue),
|
|
34
|
+
files: () => files(queue),
|
|
35
|
+
filter: (callback) => filterCommand(queue, callback),
|
|
36
|
+
get: () => get(queue),
|
|
37
|
+
upgrade: () => upgradeCommand(queue),
|
|
38
|
+
toJson: () => toJson(queue),
|
|
39
|
+
toYaml: () => toYaml(queue),
|
|
40
|
+
validate: (validateOptions) => validateCommand(queue, validateOptions),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { loadCommand };
|
|
@@ -1 +1,31 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { details } from '../actions/details.js';
|
|
2
|
+
import { files } from '../actions/files.js';
|
|
3
|
+
import { get } from '../actions/get.js';
|
|
4
|
+
import { toJson } from '../actions/toJson.js';
|
|
5
|
+
import { toYaml } from '../actions/toYaml.js';
|
|
6
|
+
import { queueTask } from '../utils/queueTask.js';
|
|
7
|
+
import { dereferenceCommand } from './dereferenceCommand.js';
|
|
8
|
+
import { filterCommand } from './filterCommand.js';
|
|
9
|
+
import { validateCommand } from './validateCommand.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Upgrade the given OpenAPI document
|
|
13
|
+
*/
|
|
14
|
+
function upgradeCommand(previousQueue) {
|
|
15
|
+
const task = {
|
|
16
|
+
name: 'upgrade',
|
|
17
|
+
};
|
|
18
|
+
const queue = queueTask(previousQueue, task);
|
|
19
|
+
return {
|
|
20
|
+
dereference: (dereferenceOptions) => dereferenceCommand(queue, dereferenceOptions),
|
|
21
|
+
details: () => details(queue),
|
|
22
|
+
files: () => files(queue),
|
|
23
|
+
filter: (callback) => filterCommand(queue, callback),
|
|
24
|
+
get: () => get(queue),
|
|
25
|
+
toJson: () => toJson(queue),
|
|
26
|
+
toYaml: () => toYaml(queue),
|
|
27
|
+
validate: (validateOptions) => validateCommand(queue, validateOptions),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { upgradeCommand };
|
|
@@ -1 +1,35 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { details } from '../actions/details.js';
|
|
2
|
+
import { files } from '../actions/files.js';
|
|
3
|
+
import { get } from '../actions/get.js';
|
|
4
|
+
import { toJson } from '../actions/toJson.js';
|
|
5
|
+
import { toYaml } from '../actions/toYaml.js';
|
|
6
|
+
import { queueTask } from '../utils/queueTask.js';
|
|
7
|
+
import { dereferenceCommand } from './dereferenceCommand.js';
|
|
8
|
+
import { filterCommand } from './filterCommand.js';
|
|
9
|
+
import { upgradeCommand } from './upgradeCommand.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Validate the given OpenAPI document
|
|
13
|
+
*/
|
|
14
|
+
function validateCommand(previousQueue, options) {
|
|
15
|
+
const task = {
|
|
16
|
+
name: 'validate',
|
|
17
|
+
options: {
|
|
18
|
+
throwOnError: previousQueue.options?.throwOnError,
|
|
19
|
+
...(options ?? {}),
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
const queue = queueTask(previousQueue, task);
|
|
23
|
+
return {
|
|
24
|
+
dereference: (dereferenceOptions) => dereferenceCommand(queue, dereferenceOptions),
|
|
25
|
+
details: () => details(queue),
|
|
26
|
+
files: () => files(queue),
|
|
27
|
+
filter: (callback) => filterCommand(queue, callback),
|
|
28
|
+
get: () => get(queue),
|
|
29
|
+
toJson: () => toJson(queue),
|
|
30
|
+
toYaml: () => toYaml(queue),
|
|
31
|
+
upgrade: () => upgradeCommand(queue),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { validateCommand };
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
import{loadCommand
|
|
1
|
+
import { loadCommand } from './commands/loadCommand.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a fluent OpenAPI pipeline
|
|
5
|
+
*/
|
|
6
|
+
function openapi(globalOptions) {
|
|
7
|
+
// Create a new queue
|
|
8
|
+
const queue = {
|
|
9
|
+
input: null,
|
|
10
|
+
options: globalOptions,
|
|
11
|
+
tasks: [],
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
load: (input, options) => loadCommand(queue, input, options),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { openapi };
|
|
@@ -1 +1,67 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { dereference } from '../../dereference.js';
|
|
2
|
+
import { filter } from '../../filter.js';
|
|
3
|
+
import { upgrade } from '../../upgrade.js';
|
|
4
|
+
import { validate } from '../../validate.js';
|
|
5
|
+
import { load } from '../../load/load.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Takes a queue of tasks and works through them
|
|
9
|
+
*/
|
|
10
|
+
async function workThroughQueue(queue) {
|
|
11
|
+
const { input } = {
|
|
12
|
+
...queue,
|
|
13
|
+
};
|
|
14
|
+
let result = {};
|
|
15
|
+
// Work through the whole queue
|
|
16
|
+
for (const task of queue.tasks) {
|
|
17
|
+
const name = task.name;
|
|
18
|
+
const options = 'options' in task ? task.options : undefined;
|
|
19
|
+
// Use the result of the previous task, or fall back to the original input
|
|
20
|
+
const currentSpecification = result.specification
|
|
21
|
+
? result.specification
|
|
22
|
+
: typeof input === 'object'
|
|
23
|
+
? // Detach from the original object
|
|
24
|
+
structuredClone(input)
|
|
25
|
+
: input;
|
|
26
|
+
// load
|
|
27
|
+
if (name === 'load') {
|
|
28
|
+
result = {
|
|
29
|
+
...result,
|
|
30
|
+
...(await load(input, options)),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// validate
|
|
34
|
+
else if (name === 'filter') {
|
|
35
|
+
result = {
|
|
36
|
+
...result,
|
|
37
|
+
...filter(currentSpecification, options),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// dereference
|
|
41
|
+
else if (name === 'dereference') {
|
|
42
|
+
result = {
|
|
43
|
+
...result,
|
|
44
|
+
...(await dereference(currentSpecification, options)),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// upgrade
|
|
48
|
+
else if (name === 'upgrade') {
|
|
49
|
+
result = {
|
|
50
|
+
...result,
|
|
51
|
+
...upgrade(currentSpecification),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// validate
|
|
55
|
+
else if (name === 'validate') {
|
|
56
|
+
result = {
|
|
57
|
+
...result,
|
|
58
|
+
...(await validate(currentSpecification, options)),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// Make TS complain when we forgot to handle a command.
|
|
62
|
+
else ;
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { workThroughQueue };
|