@scalar/openapi-parser 0.8.5 → 0.8.7

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 (79) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +1 -1
  3. package/dist/configuration/index.js +27 -1
  4. package/dist/index.js +26 -1
  5. package/dist/lib/Validator/Validator.js +127 -1
  6. package/dist/{utils/load/plugins → plugins/fetch-urls}/fetchUrls.d.ts +1 -1
  7. package/dist/plugins/fetch-urls/fetchUrls.d.ts.map +1 -0
  8. package/dist/plugins/fetch-urls/fetchUrls.js +45 -0
  9. package/dist/plugins/fetch-urls/index.d.ts +2 -0
  10. package/dist/plugins/fetch-urls/index.d.ts.map +1 -0
  11. package/dist/plugins/fetch-urls/index.js +1 -0
  12. package/dist/plugins/read-files/index.d.ts +2 -0
  13. package/dist/plugins/read-files/index.d.ts.map +1 -0
  14. package/dist/plugins/read-files/index.js +1 -0
  15. package/dist/plugins/read-files/readFiles.d.ts +3 -0
  16. package/dist/plugins/read-files/readFiles.d.ts.map +1 -0
  17. package/dist/plugins/read-files/readFiles.js +56 -0
  18. package/dist/polyfills/path.js +120 -1
  19. package/dist/schemas/v2.0/schema.json.js +1623 -1
  20. package/dist/schemas/v3.0/schema.json.js +1673 -1
  21. package/dist/schemas/v3.1/schema.json.js +1451 -1
  22. package/dist/utils/betterAjvErrors/helpers.js +108 -1
  23. package/dist/utils/betterAjvErrors/index.js +15 -1
  24. package/dist/utils/betterAjvErrors/utils.js +31 -1
  25. package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js +20 -1
  26. package/dist/utils/betterAjvErrors/validation-errors/base.js +34 -1
  27. package/dist/utils/betterAjvErrors/validation-errors/default.js +20 -1
  28. package/dist/utils/betterAjvErrors/validation-errors/enum.js +58 -1
  29. package/dist/utils/betterAjvErrors/validation-errors/pattern.js +20 -1
  30. package/dist/utils/betterAjvErrors/validation-errors/required.js +19 -1
  31. package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js +20 -1
  32. package/dist/utils/dereference.js +21 -1
  33. package/dist/utils/details.js +25 -1
  34. package/dist/utils/escapeJsonPointer.js +10 -1
  35. package/dist/utils/filter.js +17 -1
  36. package/dist/utils/getEntrypoint.js +8 -1
  37. package/dist/utils/getListOfReferences.js +27 -1
  38. package/dist/utils/getSegmentsFromPath.js +18 -1
  39. package/dist/utils/isFilesystem.js +11 -1
  40. package/dist/utils/isJson.js +11 -1
  41. package/dist/utils/isObject.js +6 -1
  42. package/dist/utils/isYaml.js +19 -1
  43. package/dist/utils/load/load.js +121 -1
  44. package/dist/utils/makeFilesystem.js +25 -1
  45. package/dist/utils/normalize.js +25 -1
  46. package/dist/utils/openapi/actions/details.js +13 -1
  47. package/dist/utils/openapi/actions/files.js +11 -1
  48. package/dist/utils/openapi/actions/get.js +13 -1
  49. package/dist/utils/openapi/actions/toJson.js +13 -1
  50. package/dist/utils/openapi/actions/toYaml.js +13 -1
  51. package/dist/utils/openapi/commands/dereferenceCommand.js +29 -1
  52. package/dist/utils/openapi/commands/filterCommand.js +28 -1
  53. package/dist/utils/openapi/commands/loadCommand.js +44 -1
  54. package/dist/utils/openapi/commands/upgradeCommand.js +31 -1
  55. package/dist/utils/openapi/commands/validateCommand.js +35 -1
  56. package/dist/utils/openapi/openapi.js +18 -1
  57. package/dist/utils/openapi/utils/queueTask.js +11 -1
  58. package/dist/utils/openapi/utils/workThroughQueue.js +67 -1
  59. package/dist/utils/resolveReferences.js +153 -1
  60. package/dist/utils/toJson.js +3 -1
  61. package/dist/utils/toYaml.js +5 -1
  62. package/dist/utils/transformErrors.js +23 -1
  63. package/dist/utils/traverse.d.ts +1 -1
  64. package/dist/utils/traverse.d.ts.map +1 -1
  65. package/dist/utils/traverse.js +26 -1
  66. package/dist/utils/unescapeJsonPointer.js +11 -1
  67. package/dist/utils/upgrade.js +20 -1
  68. package/dist/utils/upgradeFromThreeToThreeOne.d.ts +3 -1
  69. package/dist/utils/upgradeFromThreeToThreeOne.d.ts.map +1 -1
  70. package/dist/utils/upgradeFromThreeToThreeOne.js +122 -1
  71. package/dist/utils/upgradeFromTwoToThree.d.ts.map +1 -1
  72. package/dist/utils/upgradeFromTwoToThree.js +174 -1
  73. package/dist/utils/validate.js +18 -1
  74. package/package.json +15 -13
  75. package/dist/utils/load/plugins/fetchUrls.d.ts.map +0 -1
  76. package/dist/utils/load/plugins/fetchUrls.js +0 -1
  77. package/dist/utils/load/plugins/readFiles.d.ts +0 -3
  78. package/dist/utils/load/plugins/readFiles.d.ts.map +0 -1
  79. package/dist/utils/load/plugins/readFiles.js +0 -1
@@ -1 +1,121 @@
1
- import{ERRORS as e}from"../../configuration/index.js";import{getEntrypoint as i}from"../getEntrypoint.js";import{getListOfReferences as r}from"../getListOfReferences.js";import{makeFilesystem as s}from"../makeFilesystem.js";import{normalize as t}from"../normalize.js";async function n(o,f){const c=[];if(f?.filesystem?.find((e=>e.filename===o)))return{specification:i(f.filesystem)?.specification,filesystem:f.filesystem,errors:c};const l=f?.plugins?.find((e=>e.check(o)));let a;if(l)try{a=t(await l.get(o))}catch(i){if(f?.throwOnError)throw new Error(e.EXTERNAL_REFERENCE_NOT_FOUND.replace("%s",o));return c.push({code:"EXTERNAL_REFERENCE_NOT_FOUND",message:e.EXTERNAL_REFERENCE_NOT_FOUND.replace("%s",o)}),{specification:null,filesystem:[],errors:c}}else a=t(o);if(void 0===a){if(f?.throwOnError)throw new Error("No content to load");return c.push({code:"NO_CONTENT",message:e.NO_CONTENT}),{specification:null,filesystem:[],errors:c}}let m=s(a,{filename:f?.filename??null});const E=(f?.filename?m.find((e=>e.filename===f?.filename)):i(m)).references??r(a);if(0===E.length)return{specification:i(m)?.specification,filesystem:m,errors:c};for(const e of E){const i=f?.plugins?.find((i=>i.check(e)));if(!i)continue;const r=i.check(e)&&i.resolvePath?i.resolvePath(o,e):e;if(m.find((i=>i.filename===e)))continue;const{filesystem:s,errors:t}=await n(r,{...f,filename:e});c.push(...t),m=[...m,...s.map((e=>({...e,isEntrypoint:!1})))]}return{specification:i(m)?.specification,filesystem:m,errors:c}}export{n as load};
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 as e}from"./getListOfReferences.js";import{isFilesystem as r}from"./isFilesystem.js";import{normalize as i}from"./normalize.js";function t(t,n={}){if(r(t))return t;const o=i(t);return[{isEntrypoint:!0,specification:o,filename:null,dir:"./",references:e(o),...n}]}export{t as makeFilesystem};
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 };
@@ -1 +1,25 @@
1
- import{parse as r}from"yaml";import{isFilesystem as t}from"./isFilesystem.js";function e(e){if(t(e))return e;if("string"==typeof e)try{return JSON.parse(e)}catch(t){return r(e,{maxAliasCount:1e4})}return e}export{e as normalize};
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 t}from"../../details.js";import{getEntrypoint as i}from"../../getEntrypoint.js";import{workThroughQueue as o}from"../utils/workThroughQueue.js";async function r(r){const{filesystem:s}=await o(r);return t(i(s).specification)}export{r as details};
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 as t}from"../utils/workThroughQueue.js";async function o(o){const{filesystem:r}=await t(o);return r}export{o as files};
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 as r}from"../utils/workThroughQueue.js";async function t(t){return{filesystem:[],...await r(t)}}export{t as get};
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 as o}from"../../getEntrypoint.js";import{toJson as t}from"../../toJson.js";import{workThroughQueue as r}from"../utils/workThroughQueue.js";async function s(s){const{filesystem:i}=await r(s);return t(o(i).specification)}export{s as toJson};
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 as t}from"../../getEntrypoint.js";import{toYaml as o}from"../../toYaml.js";import{workThroughQueue as r}from"../utils/workThroughQueue.js";async function i(i){const{filesystem:s}=await r(i);return o(t(s).specification)}export{i as toYaml};
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{details as o}from"../actions/details.js";import{files as t}from"../actions/files.js";import{get as r}from"../actions/get.js";import{toJson as s}from"../actions/toJson.js";import{toYaml as i}from"../actions/toYaml.js";import{queueTask as n}from"../utils/queueTask.js";function e(e,m){const a={name:"dereference",options:{throwOnError:e.options?.throwOnError,...m??{}}},f=n(e,a);return{details:()=>o(f),files:()=>t(f),get:()=>r(f),toJson:()=>s(f),toYaml:()=>i(f)}}export{e as dereferenceCommand};
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{details as o}from"../actions/details.js";import{files as t}from"../actions/files.js";import{get as e}from"../actions/get.js";import{toJson as r}from"../actions/toJson.js";import{toYaml as s}from"../actions/toYaml.js";import{queueTask as i}from"../utils/queueTask.js";import{dereferenceCommand as m}from"./dereferenceCommand.js";function n(n,f){const a=i(n,{name:"filter",options:f});return{dereference:o=>m(a,o),details:()=>o(a),files:()=>t(a),get:()=>e(a),toJson:()=>r(a),toYaml:()=>s(a)}}export{n as filterCommand};
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{details as o}from"../actions/details.js";import{files as r}from"../actions/files.js";import{get as t}from"../actions/get.js";import{toJson as m}from"../actions/toJson.js";import{toYaml as i}from"../actions/toYaml.js";import{queueTask as e}from"../utils/queueTask.js";import{dereferenceCommand as s}from"./dereferenceCommand.js";import{filterCommand as n}from"./filterCommand.js";import{upgradeCommand as a}from"./upgradeCommand.js";import{validateCommand as f}from"./validateCommand.js";function p(p,d,l){const j={name:"load",options:{throwOnError:p.options?.throwOnError,...l}},c={...e(p,j),input:d};return{dereference:o=>s(c,o),details:()=>o(c),files:()=>r(c),filter:o=>n(c,o),get:()=>t(c),upgrade:()=>a(c),toJson:()=>m(c),toYaml:()=>i(c),validate:o=>f(c,o)}}export{p as loadCommand};
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{details as o}from"../actions/details.js";import{files as t}from"../actions/files.js";import{get as r}from"../actions/get.js";import{toJson as m}from"../actions/toJson.js";import{toYaml as e}from"../actions/toYaml.js";import{queueTask as i}from"../utils/queueTask.js";import{dereferenceCommand as s}from"./dereferenceCommand.js";import{filterCommand as a}from"./filterCommand.js";import{validateCommand as n}from"./validateCommand.js";function f(f){const l=i(f,{name:"upgrade"});return{dereference:o=>s(l,o),details:()=>o(l),files:()=>t(l),filter:o=>a(l,o),get:()=>r(l),toJson:()=>m(l),toYaml:()=>e(l),validate:o=>n(l,o)}}export{f as upgradeCommand};
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{details as o}from"../actions/details.js";import{files as r}from"../actions/files.js";import{get as t}from"../actions/get.js";import{toJson as m}from"../actions/toJson.js";import{toYaml as e}from"../actions/toYaml.js";import{queueTask as i}from"../utils/queueTask.js";import{dereferenceCommand as s}from"./dereferenceCommand.js";import{filterCommand as n}from"./filterCommand.js";import{upgradeCommand as a}from"./upgradeCommand.js";function f(f,p){const d={name:"validate",options:{throwOnError:f.options?.throwOnError,...p??{}}},l=i(f,d);return{dereference:o=>s(l,o),details:()=>o(l),files:()=>r(l),filter:o=>n(l,o),get:()=>t(l),toJson:()=>m(l),toYaml:()=>e(l),upgrade:()=>a(l)}}export{f as validateCommand};
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 as o}from"./commands/loadCommand.js";function n(n){const t={input:null,options:n,tasks:[]};return{load:(n,m)=>o(t,n,m)}}export{n as openapi};
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,11 @@
1
- function t(t,s){return{...t,tasks:[...t.tasks,s]}}export{t as queueTask};
1
+ /**
2
+ * Add a new task to the existing queue
3
+ */
4
+ function queueTask(queue, task) {
5
+ return {
6
+ ...queue,
7
+ tasks: [...queue.tasks, task],
8
+ };
9
+ }
10
+
11
+ export { queueTask };
@@ -1 +1,67 @@
1
- import{dereference as o}from"../../dereference.js";import{filter as t}from"../../filter.js";import{load as e}from"../../load/load.js";import{upgrade as i}from"../../upgrade.js";import{validate as r}from"../../validate.js";async function a(a){const{input:n}={...a};let s={};for(const f of a.tasks){const a=f.name,p="options"in f?f.options:void 0,c=s.specification?s.specification:"object"==typeof n?structuredClone(n):n;"load"===a?s={...s,...await e(n,p)}:"filter"===a?s={...s,...t(c,p)}:"dereference"===a?s={...s,...await o(c,p)}:"upgrade"===a?s={...s,...i(c)}:"validate"===a&&(s={...s,...await r(c,p)})}return s}export{a as workThroughQueue};
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 };