@scalar/openapi-parser 0.8.6 → 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 (74) hide show
  1. package/CHANGELOG.md +6 -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.js +26 -1
  64. package/dist/utils/unescapeJsonPointer.js +11 -1
  65. package/dist/utils/upgrade.js +20 -1
  66. package/dist/utils/upgradeFromThreeToThreeOne.js +122 -1
  67. package/dist/utils/upgradeFromTwoToThree.js +174 -1
  68. package/dist/utils/validate.js +18 -1
  69. package/package.json +15 -13
  70. package/dist/utils/load/plugins/fetchUrls.d.ts.map +0 -1
  71. package/dist/utils/load/plugins/fetchUrls.js +0 -1
  72. package/dist/utils/load/plugins/readFiles.d.ts +0 -3
  73. package/dist/utils/load/plugins/readFiles.d.ts.map +0 -1
  74. package/dist/utils/load/plugins/readFiles.js +0 -1
@@ -1 +1,108 @@
1
- import{getErrors as r,isRequiredError as e,isAnyOfError as t,isEnumError as n,getSiblings as o,notUndefined as a,concatAll as i,getChildren as c}from"./utils.js";import s from"./validation-errors/additional-prop.js";import d from"./validation-errors/default.js";import l from"./validation-errors/enum.js";import u from"./validation-errors/pattern.js";import h from"./validation-errors/required.js";import m from"./validation-errors/unevaluated-prop.js";const p=/\/[\w_-]+(\/\d+)?/g;function f(r=[]){const e={children:{}};return r.forEach((r=>{const t=void 0!==r.instancePath?r.instancePath:r.dataPath,n=""===t?[""]:t.match(p);n&&n.reduce(((e,t,o)=>(e.children[t]=e.children[t]||{children:{},errors:[]},o===n.length-1&&e.children[t].errors.push(r),e.children[t])),e)})),e}function w(i,c,s){r(i).forEach((r=>{e(r)&&(i.errors=[r],i.children={})})),r(i).some(t)&&Object.keys(i.children).length>0&&delete i.errors,i.errors?.length&&r(i).every(n)&&o(c)(i).filter(a).some(r)&&delete c.children[s],Object.entries(i.children).forEach((([r,e])=>w(e,i,r)))}function v(e,t){const o=r(e);if(o.length&&o.every(n)){const r=[...new Set(i([])(o.map((r=>r.params.allowedValues))))],e=o[0];return[new l({...e,params:{allowedValues:r}},t)]}return i(o.reduce(((r,e)=>{switch(e.keyword){case"additionalProperties":return r.concat(new s(e,t));case"pattern":return r.concat(new u(e,t));case"required":return r.concat(new h(e,t));case"unevaluatedProperties":return r.concat(new m(e,t));default:return r.concat(new d(e,t))}}),[]))(c(e).map((r=>v(r,t))))}function j(r,e){const t=f(r||[]);return w(t),v(t,e)}export{v as createErrorInstances,j as default,w as filterRedundantErrors,f as makeTree};
1
+ import { getErrors, isRequiredError, isAnyOfError, isEnumError, getSiblings, notUndefined, concatAll, getChildren } from './utils.js';
2
+ import EnumValidationError from './validation-errors/enum.js';
3
+ import DefaultValidationError from './validation-errors/default.js';
4
+ import UnevaluatedPropValidationError from './validation-errors/unevaluated-prop.js';
5
+ import RequiredValidationError from './validation-errors/required.js';
6
+ import PatternValidationError from './validation-errors/pattern.js';
7
+ import AdditionalPropValidationError from './validation-errors/additional-prop.js';
8
+
9
+ /* eslint-disable no-param-reassign */
10
+ const JSON_POINTERS_REGEX = /\/[\w_-]+(\/\d+)?/g;
11
+ // Make a tree of errors from ajv errors array
12
+ function makeTree(ajvErrors = []) {
13
+ const root = { children: {} };
14
+ ajvErrors.forEach((ajvError) => {
15
+ const instancePath = typeof ajvError.instancePath !== 'undefined'
16
+ ? ajvError.instancePath
17
+ : ajvError.dataPath;
18
+ // `dataPath === ''` is root
19
+ const paths = instancePath === '' ? [''] : instancePath.match(JSON_POINTERS_REGEX);
20
+ if (paths) {
21
+ paths.reduce((obj, path, i) => {
22
+ obj.children[path] = obj.children[path] || { children: {}, errors: [] };
23
+ if (i === paths.length - 1) {
24
+ obj.children[path].errors.push(ajvError);
25
+ }
26
+ return obj.children[path];
27
+ }, root);
28
+ }
29
+ });
30
+ return root;
31
+ }
32
+ function filterRedundantErrors(root, parent, key) {
33
+ /**
34
+ * If there is a `required` error then we can just skip everythig else.
35
+ * And, also `required` should have more priority than `anyOf`. @see #8
36
+ */
37
+ getErrors(root).forEach((error) => {
38
+ if (isRequiredError(error)) {
39
+ root.errors = [error];
40
+ root.children = {};
41
+ }
42
+ });
43
+ /**
44
+ * If there is an `anyOf` error that means we have more meaningful errors
45
+ * inside children. So we will just remove all errors from this level.
46
+ *
47
+ * If there are no children, then we don't delete the errors since we should
48
+ * have at least one error to report.
49
+ */
50
+ if (getErrors(root).some(isAnyOfError)) {
51
+ if (Object.keys(root.children).length > 0) {
52
+ delete root.errors;
53
+ }
54
+ }
55
+ /**
56
+ * If all errors are `enum` and siblings have any error then we can safely
57
+ * ignore the node.
58
+ *
59
+ * **CAUTION**
60
+ * Need explicit `root.errors` check because `[].every(fn) === true`
61
+ * https://en.wikipedia.org/wiki/Vacuous_truth#Vacuous_truths_in_mathematics
62
+ */
63
+ if (root.errors?.length && getErrors(root).every(isEnumError)) {
64
+ if (getSiblings(parent)(root)
65
+ // Remove any reference which becomes `undefined` later
66
+ .filter(notUndefined)
67
+ .some(getErrors)) {
68
+ delete parent.children[key];
69
+ }
70
+ }
71
+ Object.entries(root.children).forEach(([k, child]) => filterRedundantErrors(child, root, k));
72
+ }
73
+ function createErrorInstances(root, options) {
74
+ const errors = getErrors(root);
75
+ if (errors.length && errors.every(isEnumError)) {
76
+ const uniqueValues = new Set(concatAll([])(errors.map((e) => e.params.allowedValues)));
77
+ const allowedValues = [...uniqueValues];
78
+ const error = errors[0];
79
+ return [
80
+ new EnumValidationError({
81
+ ...error,
82
+ params: { allowedValues },
83
+ }, options),
84
+ ];
85
+ }
86
+ return concatAll(errors.reduce((ret, error) => {
87
+ switch (error.keyword) {
88
+ case 'additionalProperties':
89
+ return ret.concat(new AdditionalPropValidationError(error, options));
90
+ case 'pattern':
91
+ return ret.concat(new PatternValidationError(error, options));
92
+ case 'required':
93
+ return ret.concat(new RequiredValidationError(error, options));
94
+ case 'unevaluatedProperties':
95
+ return ret.concat(new UnevaluatedPropValidationError(error, options));
96
+ default:
97
+ return ret.concat(new DefaultValidationError(error, options));
98
+ }
99
+ }, []))(getChildren(root).map((child) => createErrorInstances(child, options)));
100
+ }
101
+ function prettify(ajvErrors, options) {
102
+ const tree = makeTree(ajvErrors || []);
103
+ // @ts-expect-error TODO
104
+ filterRedundantErrors(tree);
105
+ return createErrorInstances(tree, options);
106
+ }
107
+
108
+ export { createErrorInstances, prettify as default, filterRedundantErrors, makeTree };
@@ -1 +1,15 @@
1
- import n from"./helpers.js";function r(r,t,o,e={}){const{indent:l=null,json:s=null}=e,a=s||JSON.stringify(t,null,l);return n(o,{data:t,schema:r,jsonRaw:a}).map((n=>n.getError()))}export{r as betterAjvErrors};
1
+ import prettify from './helpers.js';
2
+
3
+ function betterAjvErrors(schema, data, errors, options = {}) {
4
+ const { indent = null, json = null } = options;
5
+ const jsonRaw = json || JSON.stringify(data, null, indent);
6
+ const customErrorToStructure = (error) => error.getError();
7
+ const customErrors = prettify(errors, {
8
+ data,
9
+ schema,
10
+ jsonRaw,
11
+ });
12
+ return customErrors.map(customErrorToStructure);
13
+ }
14
+
15
+ export { betterAjvErrors };
@@ -1 +1,31 @@
1
- const r=r=>void 0!==r,e=r=>e=>e.keyword===r,n=e("required"),t=e("anyOf"),c=e("enum"),o=r=>r&&r.errors||[],u=r=>{return r&&(e=r.children,Object.values(e))||[];var e},a=r=>e=>{return u(r).filter((t=e,n=r=>t===r,r=>!n(r)));var n,t},d=r=>e=>e.reduce(((r,e)=>r.concat(e)),r);export{d as concatAll,u as getChildren,o as getErrors,a as getSiblings,t as isAnyOfError,c as isEnumError,n as isRequiredError,r as notUndefined};
1
+ // Basic
2
+ const eq = (x) => (y) => x === y;
3
+ const not = (fn) => (x) => !fn(x);
4
+
5
+ const getValues = (o) => Object.values(o);
6
+
7
+ const notUndefined = (x) => x !== undefined;
8
+
9
+ // Error
10
+ const isXError = (x) => (error) => error.keyword === x;
11
+ const isRequiredError = isXError('required');
12
+ const isAnyOfError = isXError('anyOf');
13
+ const isEnumError = isXError('enum');
14
+ const getErrors = (node) => (node && node.errors) || [];
15
+
16
+ // Node
17
+ const getChildren = (node) => (node && getValues(node.children)) || [];
18
+
19
+ const getSiblings =
20
+ (parent /*: Node */) => (node /*: Node */) /*: $ReadOnlyArray<Node> */ =>
21
+ getChildren(parent).filter(not(eq(node)));
22
+
23
+ const concatAll =
24
+ /* ::<T> */
25
+
26
+
27
+ (xs /*: $ReadOnlyArray<T> */) =>
28
+ (ys /* : $ReadOnlyArray<T> */) /* : $ReadOnlyArray<T> */ =>
29
+ ys.reduce((zs, z) => zs.concat(z), xs);
30
+
31
+ export { concatAll, getChildren, getErrors, getSiblings, isAnyOfError, isEnumError, isRequiredError, notUndefined };
@@ -1 +1,20 @@
1
- import t from"./base.js";class e extends t{constructor(...t){super(...t),this.name="AdditionalPropValidationError",this.options.isIdentifierLocation=!0}getError(){const{params:t}=this.options;return{message:`Property ${t.additionalProperty} is not expected to be here`,path:this.instancePath}}}export{e as default};
1
+ import BaseValidationError from './base.js';
2
+
3
+ class AdditionalPropValidationError extends BaseValidationError {
4
+ constructor(...args) {
5
+ super(...args);
6
+ this.name = 'AdditionalPropValidationError';
7
+ this.options.isIdentifierLocation = true;
8
+ }
9
+
10
+ getError() {
11
+ const { params } = this.options;
12
+
13
+ return {
14
+ message: `Property ${params.additionalProperty} is not expected to be here`,
15
+ path: this.instancePath,
16
+ }
17
+ }
18
+ }
19
+
20
+ export { AdditionalPropValidationError as default };
@@ -1 +1,34 @@
1
- class t{constructor(t={isIdentifierLocation:!1},{data:s,schema:o,jsonAst:i,jsonRaw:n}){this.options=t,this.data=s,this.schema=o,this.jsonAst=i,this.jsonRaw=n}get instancePath(){return void 0!==this.options.instancePath?this.options.instancePath:this.options.dataPath}getError(){throw new Error(`Implement the 'getError' method inside ${this.constructor.name}!`)}}export{t as default};
1
+ // import { codeFrameColumns } from '@babel/code-frame';
2
+ // import chalk from 'chalk';
3
+ // import { getMetaFromPath } from '../json/index'
4
+
5
+ class BaseValidationError {
6
+ // eslint-disable-next-line default-param-last
7
+ constructor(
8
+ options = { isIdentifierLocation: false },
9
+ { data, schema, jsonAst, jsonRaw },
10
+ ) {
11
+ this.options = options;
12
+ this.data = data;
13
+ this.schema = schema;
14
+ this.jsonAst = jsonAst;
15
+ this.jsonRaw = jsonRaw;
16
+ }
17
+
18
+ /**
19
+ * @return {string}
20
+ */
21
+ get instancePath() {
22
+ return typeof this.options.instancePath !== 'undefined'
23
+ ? this.options.instancePath
24
+ : this.options.dataPath
25
+ }
26
+
27
+ getError() {
28
+ throw new Error(
29
+ `Implement the 'getError' method inside ${this.constructor.name}!`,
30
+ )
31
+ }
32
+ }
33
+
34
+ export { BaseValidationError as default };
@@ -1 +1,20 @@
1
- import s from"./base.js";class t extends s{constructor(...s){super(...s),this.name="DefaultValidationError",this.options.isSkipEndLocation=!0}getError(){const{keyword:s,message:t}=this.options;return{message:`${s} ${t}`,path:this.instancePath}}}export{t as default};
1
+ import BaseValidationError from './base.js';
2
+
3
+ class DefaultValidationError extends BaseValidationError {
4
+ constructor(...args) {
5
+ super(...args);
6
+ this.name = 'DefaultValidationError';
7
+ this.options.isSkipEndLocation = true;
8
+ }
9
+
10
+ getError() {
11
+ const { keyword, message } = this.options;
12
+
13
+ return {
14
+ message: `${keyword} ${message}`,
15
+ path: this.instancePath,
16
+ }
17
+ }
18
+ }
19
+
20
+ export { DefaultValidationError as default };
@@ -1 +1,58 @@
1
- import t from"jsonpointer";import e from"leven";import s from"./base.js";class a extends s{constructor(...t){super(...t),this.name="EnumValidationError"}getError(){const{message:t,params:e}=this.options,s=this.findBestMatch(),a={message:`${t}: ${e.allowedValues.join(", ")}`,path:this.instancePath};return null!==s&&(a.suggestion=`Did you mean ${s}?`),a}findBestMatch(){const{params:{allowedValues:s}}=this.options,a=""===this.instancePath?this.data:t.get(this.data,this.instancePath);if(!a)return null;const i=s.map((t=>({value:t,weight:e(t,a.toString())}))).sort(((t,e)=>t.weight>e.weight?1:t.weight<e.weight?-1:0))[0];return 1===s.length||i.weight<i.value.length?i.value:null}}export{a as default};
1
+ import pointer from 'jsonpointer';
2
+ import leven from 'leven';
3
+ import BaseValidationError from './base.js';
4
+
5
+ class EnumValidationError extends BaseValidationError {
6
+ constructor(...args) {
7
+ super(...args);
8
+ this.name = 'EnumValidationError';
9
+ }
10
+
11
+ getError() {
12
+ const { message, params } = this.options;
13
+ const bestMatch = this.findBestMatch();
14
+ const allowedValues = params.allowedValues.join(', ');
15
+
16
+ const output = {
17
+ message: `${message}: ${allowedValues}`,
18
+ path: this.instancePath,
19
+ };
20
+
21
+ if (bestMatch !== null) {
22
+ output.suggestion = `Did you mean ${bestMatch}?`;
23
+ }
24
+
25
+ return output
26
+ }
27
+
28
+ findBestMatch() {
29
+ const {
30
+ params: { allowedValues },
31
+ } = this.options;
32
+
33
+ const currentValue =
34
+ this.instancePath === ''
35
+ ? this.data
36
+ : pointer.get(this.data, this.instancePath);
37
+
38
+ if (!currentValue) {
39
+ return null
40
+ }
41
+
42
+ const bestMatch = allowedValues
43
+ .map((value) => ({
44
+ value,
45
+ weight: leven(value, currentValue.toString()),
46
+ }))
47
+ .sort((x, y) =>
48
+ x.weight > y.weight ? 1 : x.weight < y.weight ? -1 : 0,
49
+ )[0];
50
+
51
+ return allowedValues.length === 1 ||
52
+ bestMatch.weight < bestMatch.value.length
53
+ ? bestMatch.value
54
+ : null
55
+ }
56
+ }
57
+
58
+ export { EnumValidationError as default };
@@ -1 +1,20 @@
1
- import t from"./base.js";class r extends t{constructor(...t){super(...t),this.name="PatternValidationError",this.options.isIdentifierLocation=!0}getError(){const{params:t,propertyName:r}=this.options;return{message:`Property "${r}" must match pattern ${t.pattern}`,path:this.instancePath}}}export{r as default};
1
+ import BaseValidationError from './base.js';
2
+
3
+ class PatternValidationError extends BaseValidationError {
4
+ constructor(...args) {
5
+ super(...args);
6
+ this.name = 'PatternValidationError';
7
+ this.options.isIdentifierLocation = true;
8
+ }
9
+
10
+ getError() {
11
+ const { params, propertyName } = this.options;
12
+
13
+ return {
14
+ message: `Property "${propertyName}" must match pattern ${params.pattern}`,
15
+ path: this.instancePath,
16
+ }
17
+ }
18
+ }
19
+
20
+ export { PatternValidationError as default };
@@ -1 +1,19 @@
1
- import s from"./base.js";class t extends s{constructor(...s){super(...s),this.name="RequiredValidationError"}getError(){const{message:s}=this.options;return{message:`${s}`,path:this.instancePath}}}export{t as default};
1
+ import BaseValidationError from './base.js';
2
+
3
+ class RequiredValidationError extends BaseValidationError {
4
+ constructor(...args) {
5
+ super(...args);
6
+ this.name = 'RequiredValidationError';
7
+ }
8
+
9
+ getError() {
10
+ const { message } = this.options;
11
+
12
+ return {
13
+ message: `${message}`,
14
+ path: this.instancePath,
15
+ }
16
+ }
17
+ }
18
+
19
+ export { RequiredValidationError as default };
@@ -1 +1,20 @@
1
- import t from"./base.js";class e extends t{constructor(...t){super(...t),this.name="UnevaluatedPropValidationError",this.options.isIdentifierLocation=!0}getError(){const{params:t}=this.options;return{message:`Property ${t.unevaluatedProperty} is not expected to be here`,path:this.instancePath}}}export{e as default};
1
+ import BaseValidationError from './base.js';
2
+
3
+ class UnevaluatedPropValidationError extends BaseValidationError {
4
+ constructor(...args) {
5
+ super(...args);
6
+ this.name = 'UnevaluatedPropValidationError';
7
+ this.options.isIdentifierLocation = true;
8
+ }
9
+
10
+ getError() {
11
+ const { params } = this.options;
12
+
13
+ return {
14
+ message: `Property ${params.unevaluatedProperty} is not expected to be here`,
15
+ path: this.instancePath,
16
+ }
17
+ }
18
+ }
19
+
20
+ export { UnevaluatedPropValidationError as default };
@@ -1 +1,21 @@
1
- import{details as e}from"./details.js";import{getEntrypoint as r}from"./getEntrypoint.js";import{makeFilesystem as o}from"./makeFilesystem.js";import{resolveReferences as s}from"./resolveReferences.js";async function i(i,t){const c=o(i),m=r(c),n=s(c,t);return{specification:m.specification,errors:n.errors,schema:n.schema,...e(m.specification)}}export{i as dereference};
1
+ import { details } from './details.js';
2
+ import { getEntrypoint } from './getEntrypoint.js';
3
+ import { makeFilesystem } from './makeFilesystem.js';
4
+ import { resolveReferences } from './resolveReferences.js';
5
+
6
+ /**
7
+ * Validates an OpenAPI schema and resolves all references.
8
+ */
9
+ async function dereference(value, options) {
10
+ const filesystem = makeFilesystem(value);
11
+ const entrypoint = getEntrypoint(filesystem);
12
+ const result = resolveReferences(filesystem, options);
13
+ return {
14
+ specification: entrypoint.specification,
15
+ errors: result.errors,
16
+ schema: result.schema,
17
+ ...details(entrypoint.specification),
18
+ };
19
+ }
20
+
21
+ export { dereference };
@@ -1 +1,25 @@
1
- import{OpenApiVersions as i}from"../configuration/index.js";function o(o){for(const n of new Set(i)){const i="2.0"===n?"swagger":"openapi",e=o[i];if("string"==typeof e&&e.startsWith(n))return{version:n,specificationType:i,specificationVersion:e}}return{version:void 0,specificationType:void 0,specificationVersion:void 0}}export{o as details};
1
+ import { OpenApiVersions } from '../configuration/index.js';
2
+
3
+ /**
4
+ * Get versions of the OpenAPI specification.
5
+ */
6
+ function details(specification) {
7
+ for (const version of new Set(OpenApiVersions)) {
8
+ const specificationType = version === '2.0' ? 'swagger' : 'openapi';
9
+ const value = specification[specificationType];
10
+ if (typeof value === 'string' && value.startsWith(version)) {
11
+ return {
12
+ version: version,
13
+ specificationType,
14
+ specificationVersion: value,
15
+ };
16
+ }
17
+ }
18
+ return {
19
+ version: undefined,
20
+ specificationType: undefined,
21
+ specificationVersion: undefined,
22
+ };
23
+ }
24
+
25
+ export { details };
@@ -1 +1,10 @@
1
- function e(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}export{e as escapeJsonPointer};
1
+ /**
2
+ * Escapes a JSON pointer string.
3
+ *
4
+ * Example: `/foo/bar~baz` -> `/foo~1bar~0baz`
5
+ */
6
+ function escapeJsonPointer(str) {
7
+ return str.replace(/~/g, '~0').replace(/\//g, '~1');
8
+ }
9
+
10
+ export { escapeJsonPointer };
@@ -1 +1,17 @@
1
- import{getEntrypoint as t}from"./getEntrypoint.js";import{makeFilesystem as i}from"./makeFilesystem.js";import{traverse as o}from"./traverse.js";function r(r,e){const s=i(r);return{specification:o(t(s).specification,(t=>e(t)?t:void 0))}}export{r as filter};
1
+ import { getEntrypoint } from './getEntrypoint.js';
2
+ import { makeFilesystem } from './makeFilesystem.js';
3
+ import { traverse } from './traverse.js';
4
+
5
+ /**
6
+ * Filter the specification based on the callback
7
+ */
8
+ function filter(specification, callback) {
9
+ const filesystem = makeFilesystem(specification);
10
+ return {
11
+ specification: traverse(getEntrypoint(filesystem).specification, (schema) => {
12
+ return callback(schema) ? schema : undefined;
13
+ }),
14
+ };
15
+ }
16
+
17
+ export { filter };
@@ -1 +1,8 @@
1
- function n(n){return n?.find((n=>n.isEntrypoint))}export{n as getEntrypoint};
1
+ /**
2
+ * Return just the entrypoint of the filesystem.
3
+ */
4
+ function getEntrypoint(filesystem) {
5
+ return filesystem?.find((file) => file.isEntrypoint);
6
+ }
7
+
8
+ export { getEntrypoint };
@@ -1 +1,27 @@
1
- import{traverse as t}from"./traverse.js";function e(e){const r=[];return e&&"object"==typeof e?(t(e,(t=>(t.$ref&&"string"==typeof t.$ref&&!t.$ref.startsWith("#")&&r.push(t.$ref.split("#")[0]),t))),[...new Set(r)]):r}export{e as getListOfReferences};
1
+ import { traverse } from './traverse.js';
2
+
3
+ /**
4
+ * Walks through the specification and returns all references as an array.
5
+ *
6
+ * Warning: Doesn’t return internal references.
7
+ */
8
+ function getListOfReferences(specification) {
9
+ const references = [];
10
+ // Make sure we’re dealing with an object
11
+ if (!specification || typeof specification !== 'object') {
12
+ return references;
13
+ }
14
+ // Traverse the specification and collect all references
15
+ traverse(specification, (value) => {
16
+ if (value.$ref &&
17
+ typeof value.$ref === 'string' &&
18
+ !value.$ref.startsWith('#')) {
19
+ references.push(value.$ref.split('#')[0]);
20
+ }
21
+ return value;
22
+ });
23
+ // Remove duplicates
24
+ return [...new Set(references)];
25
+ }
26
+
27
+ export { getListOfReferences };
@@ -1 +1,18 @@
1
- import{unescapeJsonPointer as e}from"./unescapeJsonPointer.js";function n(n){return n.split("/").slice(1).map(e)}export{n as getSegmentsFromPath};
1
+ import { unescapeJsonPointer } from './unescapeJsonPointer.js';
2
+
3
+ /**
4
+ * Translate `/paths/~1test` to `['paths', '/test']`
5
+ */
6
+ function getSegmentsFromPath(path) {
7
+ return (
8
+ // /paths/~1test
9
+ path
10
+ // ['', 'paths', '~1test']
11
+ .split('/')
12
+ // ['paths', '~test']
13
+ .slice(1)
14
+ // ['paths', '/test']
15
+ .map(unescapeJsonPointer));
16
+ }
17
+
18
+ export { getSegmentsFromPath };
@@ -1 +1,11 @@
1
- function r(r){return void 0!==r&&Array.isArray(r)&&r.length>0&&r.some((r=>!0===r.isEntrypoint))}export{r as isFilesystem};
1
+ /**
2
+ * Check if the value is a filesystem
3
+ */
4
+ function isFilesystem(value) {
5
+ return (typeof value !== 'undefined' &&
6
+ Array.isArray(value) &&
7
+ value.length > 0 &&
8
+ value.some((file) => file.isEntrypoint === true));
9
+ }
10
+
11
+ export { isFilesystem };
@@ -1 +1,11 @@
1
- function r(r){try{return JSON.parse(r),!0}catch{return!1}}export{r as isJson};
1
+ function isJson(value) {
2
+ try {
3
+ JSON.parse(value);
4
+ return true;
5
+ }
6
+ catch {
7
+ return false;
8
+ }
9
+ }
10
+
11
+ export { isJson };
@@ -1 +1,6 @@
1
- const r=r=>"object"==typeof r&&!Array.isArray(r)&&null!==r;export{r as isObject};
1
+ /**
2
+ * Check if the given value is an object
3
+ */
4
+ const isObject = (obj) => typeof obj === 'object' && !Array.isArray(obj) && obj !== null;
5
+
6
+ export { isObject };
@@ -1 +1,19 @@
1
- import{parse as r}from"yaml";function t(t){if(!t.includes("\n"))return!1;try{return r(t,{maxAliasCount:1e4}),!0}catch(r){return!1}}export{t as isYaml};
1
+ import { parse } from 'yaml';
2
+
3
+ function isYaml(value) {
4
+ // Line breaks
5
+ if (!value.includes('\n')) {
6
+ return false;
7
+ }
8
+ try {
9
+ parse(value, {
10
+ maxAliasCount: 10000,
11
+ });
12
+ return true;
13
+ }
14
+ catch (error) {
15
+ return false;
16
+ }
17
+ }
18
+
19
+ export { isYaml };