@scalar/openapi-parser 0.25.4 → 0.25.5

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 (140) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/configuration/index.js +24 -24
  3. package/dist/index.js +24 -45
  4. package/dist/lib/Validator/Validator.js +125 -108
  5. package/dist/plugins/fetch-urls/fetch-urls.js +39 -38
  6. package/dist/plugins/fetch-urls/index.js +1 -6
  7. package/dist/plugins/read-files/index.js +1 -5
  8. package/dist/plugins/read-files/read-files.js +53 -51
  9. package/dist/schemas/v2.0/schema.js +1373 -1377
  10. package/dist/schemas/v3.0/schema.js +1411 -1415
  11. package/dist/schemas/v3.1/schema.js +1196 -1200
  12. package/dist/schemas/v3.2/schema.js +1417 -1421
  13. package/dist/types/index.js +1 -1
  14. package/dist/utils/betterAjvErrors/helpers.js +138 -112
  15. package/dist/utils/betterAjvErrors/index.js +11 -15
  16. package/dist/utils/betterAjvErrors/utils.js +17 -30
  17. package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js +14 -18
  18. package/dist/utils/betterAjvErrors/validation-errors/base.js +20 -21
  19. package/dist/utils/betterAjvErrors/validation-errors/default.js +14 -18
  20. package/dist/utils/betterAjvErrors/validation-errors/enum.js +33 -37
  21. package/dist/utils/betterAjvErrors/validation-errors/index.js +6 -15
  22. package/dist/utils/betterAjvErrors/validation-errors/pattern.js +14 -18
  23. package/dist/utils/betterAjvErrors/validation-errors/required.js +13 -17
  24. package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js +14 -18
  25. package/dist/utils/dereference.js +22 -18
  26. package/dist/utils/details.js +28 -29
  27. package/dist/utils/filter.js +13 -14
  28. package/dist/utils/get-entrypoint.js +5 -6
  29. package/dist/utils/get-list-of-references.js +20 -16
  30. package/dist/utils/get-segments-from-path.js +13 -9
  31. package/dist/utils/is-filesystem.js +8 -6
  32. package/dist/utils/is-json.js +8 -11
  33. package/dist/utils/is-yaml.js +15 -17
  34. package/dist/utils/join/index.js +1 -5
  35. package/dist/utils/join/join.js +267 -153
  36. package/dist/utils/join/merge-objects.js +35 -18
  37. package/dist/utils/load/index.js +1 -5
  38. package/dist/utils/load/load.js +114 -90
  39. package/dist/utils/make-filesystem.js +20 -21
  40. package/dist/utils/normalize.js +32 -29
  41. package/dist/utils/openapi/actions/details.js +9 -10
  42. package/dist/utils/openapi/actions/files.js +7 -8
  43. package/dist/utils/openapi/actions/get.js +9 -10
  44. package/dist/utils/openapi/actions/toJson.js +9 -10
  45. package/dist/utils/openapi/actions/toYaml.js +9 -10
  46. package/dist/utils/openapi/commands/dereferenceCommand.js +25 -26
  47. package/dist/utils/openapi/commands/filterCommand.js +24 -25
  48. package/dist/utils/openapi/commands/loadCommand.js +40 -41
  49. package/dist/utils/openapi/commands/upgradeCommand.js +27 -28
  50. package/dist/utils/openapi/commands/validateCommand.js +31 -32
  51. package/dist/utils/openapi/openapi.js +16 -14
  52. package/dist/utils/openapi/openapi.test-d.js +13 -13
  53. package/dist/utils/openapi/utils/queueTask.js +8 -9
  54. package/dist/utils/openapi/utils/workThroughQueue.js +64 -50
  55. package/dist/utils/resolve-references.js +168 -110
  56. package/dist/utils/to-json.js +1 -5
  57. package/dist/utils/to-yaml.js +2 -6
  58. package/dist/utils/transform/sanitize.js +22 -22
  59. package/dist/utils/transform/utils/addInfoObject.js +9 -14
  60. package/dist/utils/transform/utils/addLatestOpenApiVersion.js +4 -9
  61. package/dist/utils/transform/utils/addMissingTags.js +26 -27
  62. package/dist/utils/transform/utils/normalizeSecuritySchemes.js +39 -37
  63. package/dist/utils/transform/utils/rejectSwaggerDocuments.js +5 -9
  64. package/dist/utils/transform-errors.js +62 -55
  65. package/dist/utils/traverse.js +21 -22
  66. package/dist/utils/unescape-json-pointer.js +8 -6
  67. package/dist/utils/upgrade.js +19 -22
  68. package/dist/utils/validate-path-parameters.js +76 -80
  69. package/dist/utils/validate.js +23 -19
  70. package/package.json +9 -14
  71. package/dist/configuration/index.js.map +0 -7
  72. package/dist/declarations.d.js +0 -1
  73. package/dist/declarations.d.js.map +0 -7
  74. package/dist/index.js.map +0 -7
  75. package/dist/lib/Validator/Validator.js.map +0 -7
  76. package/dist/plugins/fetch-urls/fetch-urls.js.map +0 -7
  77. package/dist/plugins/fetch-urls/index.js.map +0 -7
  78. package/dist/plugins/read-files/index.js.map +0 -7
  79. package/dist/plugins/read-files/read-files.js.map +0 -7
  80. package/dist/schemas/v2.0/schema.js.map +0 -7
  81. package/dist/schemas/v3.0/schema.js.map +0 -7
  82. package/dist/schemas/v3.1/schema.js.map +0 -7
  83. package/dist/schemas/v3.2/schema.js.map +0 -7
  84. package/dist/types/index.js.map +0 -7
  85. package/dist/utils/betterAjvErrors/helpers.js.map +0 -7
  86. package/dist/utils/betterAjvErrors/index.js.map +0 -7
  87. package/dist/utils/betterAjvErrors/utils.js.map +0 -7
  88. package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js.map +0 -7
  89. package/dist/utils/betterAjvErrors/validation-errors/base.js.map +0 -7
  90. package/dist/utils/betterAjvErrors/validation-errors/default.js.map +0 -7
  91. package/dist/utils/betterAjvErrors/validation-errors/enum.js.map +0 -7
  92. package/dist/utils/betterAjvErrors/validation-errors/index.js.map +0 -7
  93. package/dist/utils/betterAjvErrors/validation-errors/pattern.js.map +0 -7
  94. package/dist/utils/betterAjvErrors/validation-errors/required.js.map +0 -7
  95. package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js.map +0 -7
  96. package/dist/utils/dereference.js.map +0 -7
  97. package/dist/utils/details.js.map +0 -7
  98. package/dist/utils/filter.js.map +0 -7
  99. package/dist/utils/get-entrypoint.js.map +0 -7
  100. package/dist/utils/get-list-of-references.js.map +0 -7
  101. package/dist/utils/get-segments-from-path.js.map +0 -7
  102. package/dist/utils/is-filesystem.js.map +0 -7
  103. package/dist/utils/is-json.js.map +0 -7
  104. package/dist/utils/is-yaml.js.map +0 -7
  105. package/dist/utils/join/index.js.map +0 -7
  106. package/dist/utils/join/join.js.map +0 -7
  107. package/dist/utils/join/merge-objects.js.map +0 -7
  108. package/dist/utils/load/index.js.map +0 -7
  109. package/dist/utils/load/load.js.map +0 -7
  110. package/dist/utils/make-filesystem.js.map +0 -7
  111. package/dist/utils/normalize.js.map +0 -7
  112. package/dist/utils/openapi/actions/details.js.map +0 -7
  113. package/dist/utils/openapi/actions/files.js.map +0 -7
  114. package/dist/utils/openapi/actions/get.js.map +0 -7
  115. package/dist/utils/openapi/actions/toJson.js.map +0 -7
  116. package/dist/utils/openapi/actions/toYaml.js.map +0 -7
  117. package/dist/utils/openapi/commands/dereferenceCommand.js.map +0 -7
  118. package/dist/utils/openapi/commands/filterCommand.js.map +0 -7
  119. package/dist/utils/openapi/commands/loadCommand.js.map +0 -7
  120. package/dist/utils/openapi/commands/upgradeCommand.js.map +0 -7
  121. package/dist/utils/openapi/commands/validateCommand.js.map +0 -7
  122. package/dist/utils/openapi/openapi.js.map +0 -7
  123. package/dist/utils/openapi/openapi.test-d.js.map +0 -7
  124. package/dist/utils/openapi/utils/queueTask.js.map +0 -7
  125. package/dist/utils/openapi/utils/workThroughQueue.js.map +0 -7
  126. package/dist/utils/resolve-references.js.map +0 -7
  127. package/dist/utils/to-json.js.map +0 -7
  128. package/dist/utils/to-yaml.js.map +0 -7
  129. package/dist/utils/transform/sanitize.js.map +0 -7
  130. package/dist/utils/transform/utils/addInfoObject.js.map +0 -7
  131. package/dist/utils/transform/utils/addLatestOpenApiVersion.js.map +0 -7
  132. package/dist/utils/transform/utils/addMissingTags.js.map +0 -7
  133. package/dist/utils/transform/utils/normalizeSecuritySchemes.js.map +0 -7
  134. package/dist/utils/transform/utils/rejectSwaggerDocuments.js.map +0 -7
  135. package/dist/utils/transform-errors.js.map +0 -7
  136. package/dist/utils/traverse.js.map +0 -7
  137. package/dist/utils/unescape-json-pointer.js.map +0 -7
  138. package/dist/utils/upgrade.js.map +0 -7
  139. package/dist/utils/validate-path-parameters.js.map +0 -7
  140. package/dist/utils/validate.js.map +0 -7
@@ -1,19 +1,15 @@
1
- import BaseValidationError from "./base.js";
2
- class UnevaluatedPropValidationError extends BaseValidationError {
3
- constructor(...args) {
4
- super(...args);
5
- this.name = "UnevaluatedPropValidationError";
6
- this.options.isIdentifierLocation = true;
7
- }
8
- getError() {
9
- const { params } = this.options;
10
- return {
11
- message: `Property ${params.unevaluatedProperty} is not expected to be here`,
12
- path: this.instancePath
13
- };
14
- }
1
+ import BaseValidationError from './base.js';
2
+ export default class UnevaluatedPropValidationError extends BaseValidationError {
3
+ constructor(...args) {
4
+ super(...args);
5
+ this.name = 'UnevaluatedPropValidationError';
6
+ this.options.isIdentifierLocation = true;
7
+ }
8
+ getError() {
9
+ const { params } = this.options;
10
+ return {
11
+ message: `Property ${params.unevaluatedProperty} is not expected to be here`,
12
+ path: this.instancePath,
13
+ };
14
+ }
15
15
  }
16
- export {
17
- UnevaluatedPropValidationError as default
18
- };
19
- //# sourceMappingURL=unevaluated-prop.js.map
@@ -1,19 +1,23 @@
1
- import { details } from "./details.js";
2
- import { getEntrypoint } from "./get-entrypoint.js";
3
- import { makeFilesystem } from "./make-filesystem.js";
4
- import { resolveReferences } from "./resolve-references.js";
5
- function dereference(value, options) {
6
- const filesystem = makeFilesystem(value);
7
- const entrypoint = getEntrypoint(filesystem);
8
- const result = resolveReferences(filesystem, options);
9
- return {
10
- specification: entrypoint.specification,
11
- errors: result.errors,
12
- schema: result.schema,
13
- ...details(entrypoint.specification)
14
- };
1
+ import { details } from './details.js';
2
+ import { getEntrypoint } from './get-entrypoint.js';
3
+ import { makeFilesystem } from './make-filesystem.js';
4
+ import { resolveReferences } from './resolve-references.js';
5
+ /**
6
+ * Dereferences an API definition or filesystem by resolving all references within the specification.
7
+ *
8
+ * @param value - The API definition or filesystem to dereference.\
9
+ * Can be any supported API definition format or a filesystem object.
10
+ *
11
+ * @param options - Optional options for the dereferencing process.
12
+ */
13
+ export function dereference(value, options) {
14
+ const filesystem = makeFilesystem(value);
15
+ const entrypoint = getEntrypoint(filesystem);
16
+ const result = resolveReferences(filesystem, options);
17
+ return {
18
+ specification: entrypoint.specification,
19
+ errors: result.errors,
20
+ schema: result.schema,
21
+ ...details(entrypoint.specification),
22
+ };
15
23
  }
16
- export {
17
- dereference
18
- };
19
- //# sourceMappingURL=dereference.js.map
@@ -1,33 +1,32 @@
1
- import { isObject } from "@scalar/helpers/object/is-object";
2
- import { OpenApiVersions } from "../configuration/index.js";
3
- function details(specification) {
4
- if (specification === null) {
5
- return {
6
- version: void 0,
7
- specificationType: void 0,
8
- specificationVersion: void 0
9
- };
10
- }
11
- if (isObject(specification)) {
12
- for (const version of new Set(OpenApiVersions)) {
13
- const specificationType = version === "2.0" ? "swagger" : "openapi";
14
- const value = specification[specificationType];
15
- if (typeof value === "string" && value.startsWith(version)) {
1
+ import { isObject } from '@scalar/helpers/object/is-object';
2
+ import { OpenApiVersions } from '../configuration/index.js';
3
+ /**
4
+ * Get versions of the OpenAPI document.
5
+ */
6
+ export function details(specification) {
7
+ if (specification === null) {
16
8
  return {
17
- version,
18
- specificationType,
19
- specificationVersion: value
9
+ version: undefined,
10
+ specificationType: undefined,
11
+ specificationVersion: undefined,
20
12
  };
21
- }
22
13
  }
23
- }
24
- return {
25
- version: void 0,
26
- specificationType: void 0,
27
- specificationVersion: void 0
28
- };
14
+ if (isObject(specification)) {
15
+ for (const version of new Set(OpenApiVersions)) {
16
+ const specificationType = version === '2.0' ? 'swagger' : 'openapi';
17
+ const value = specification[specificationType];
18
+ if (typeof value === 'string' && value.startsWith(version)) {
19
+ return {
20
+ version: version,
21
+ specificationType,
22
+ specificationVersion: value,
23
+ };
24
+ }
25
+ }
26
+ }
27
+ return {
28
+ version: undefined,
29
+ specificationType: undefined,
30
+ specificationVersion: undefined,
31
+ };
29
32
  }
30
- export {
31
- details
32
- };
33
- //# sourceMappingURL=details.js.map
@@ -1,15 +1,14 @@
1
- import { getEntrypoint } from "./get-entrypoint.js";
2
- import { makeFilesystem } from "./make-filesystem.js";
3
- import { traverse } from "./traverse.js";
4
- function filter(specification, callback) {
5
- const filesystem = makeFilesystem(specification);
6
- return {
7
- specification: traverse(getEntrypoint(filesystem).specification, (schema) => {
8
- return callback(schema) ? schema : void 0;
9
- })
10
- };
1
+ import { getEntrypoint } from './get-entrypoint.js';
2
+ import { makeFilesystem } from './make-filesystem.js';
3
+ import { traverse } from './traverse.js';
4
+ /**
5
+ * Filter the specification based on the callback
6
+ */
7
+ export function filter(specification, callback) {
8
+ const filesystem = makeFilesystem(specification);
9
+ return {
10
+ specification: traverse(getEntrypoint(filesystem).specification, (schema) => {
11
+ return callback(schema) ? schema : undefined;
12
+ }),
13
+ };
11
14
  }
12
- export {
13
- filter
14
- };
15
- //# sourceMappingURL=filter.js.map
@@ -1,7 +1,6 @@
1
- function getEntrypoint(filesystem) {
2
- return filesystem?.find((file) => file.isEntrypoint);
1
+ /**
2
+ * Return just the entrypoint of the filesystem.
3
+ */
4
+ export function getEntrypoint(filesystem) {
5
+ return filesystem?.find((file) => file.isEntrypoint);
3
6
  }
4
- export {
5
- getEntrypoint
6
- };
7
- //# sourceMappingURL=get-entrypoint.js.map
@@ -1,18 +1,22 @@
1
- import { traverse } from "./traverse.js";
2
- function getListOfReferences(specification) {
3
- const references = [];
4
- if (!specification || typeof specification !== "object") {
5
- return references;
6
- }
7
- traverse(specification, (value) => {
8
- if (value.$ref && typeof value.$ref === "string" && !value.$ref.startsWith("#")) {
9
- references.push(value.$ref.split("#")[0]);
1
+ import { traverse } from './traverse.js';
2
+ /**
3
+ * Walks through the specification and returns all references as an array.
4
+ *
5
+ * Warning: Doesn't return internal references.
6
+ */
7
+ export function getListOfReferences(specification) {
8
+ const references = [];
9
+ // Make sure we're dealing with an object
10
+ if (!specification || typeof specification !== 'object') {
11
+ return references;
10
12
  }
11
- return value;
12
- });
13
- return [...new Set(references)];
13
+ // Traverse the specification and collect all references
14
+ traverse(specification, (value) => {
15
+ if (value.$ref && typeof value.$ref === 'string' && !value.$ref.startsWith('#')) {
16
+ references.push(value.$ref.split('#')[0]);
17
+ }
18
+ return value;
19
+ });
20
+ // Remove duplicates
21
+ return [...new Set(references)];
14
22
  }
15
- export {
16
- getListOfReferences
17
- };
18
- //# sourceMappingURL=get-list-of-references.js.map
@@ -1,11 +1,15 @@
1
- import { unescapeJsonPointer } from "./unescape-json-pointer.js";
2
- function getSegmentsFromPath(path) {
3
- return (
1
+ import { unescapeJsonPointer } from './unescape-json-pointer.js';
2
+ /**
3
+ * Translate `/paths/~1test` to `['paths', '/test']`
4
+ */
5
+ export function getSegmentsFromPath(path) {
6
+ return (
4
7
  // /paths/~1test
5
- path.split("/").slice(1).map(unescapeJsonPointer)
6
- );
8
+ path
9
+ // ['', 'paths', '~1test']
10
+ .split('/')
11
+ // ['paths', '~test']
12
+ .slice(1)
13
+ // ['paths', '/test']
14
+ .map(unescapeJsonPointer));
7
15
  }
8
- export {
9
- getSegmentsFromPath
10
- };
11
- //# sourceMappingURL=get-segments-from-path.js.map
@@ -1,7 +1,9 @@
1
- function isFilesystem(value) {
2
- return typeof value !== "undefined" && Array.isArray(value) && value.length > 0 && value.some((file) => file.isEntrypoint === true);
1
+ /**
2
+ * Check if the value is a filesystem
3
+ */
4
+ export function isFilesystem(value) {
5
+ return (typeof value !== 'undefined' &&
6
+ Array.isArray(value) &&
7
+ value.length > 0 &&
8
+ value.some((file) => file.isEntrypoint === true));
3
9
  }
4
- export {
5
- isFilesystem
6
- };
7
- //# sourceMappingURL=is-filesystem.js.map
@@ -1,12 +1,9 @@
1
- function isJson(value) {
2
- try {
3
- JSON.parse(value);
4
- return true;
5
- } catch {
6
- return false;
7
- }
1
+ export function isJson(value) {
2
+ try {
3
+ JSON.parse(value);
4
+ return true;
5
+ }
6
+ catch {
7
+ return false;
8
+ }
8
9
  }
9
- export {
10
- isJson
11
- };
12
- //# sourceMappingURL=is-json.js.map
@@ -1,18 +1,16 @@
1
- import { parse } from "yaml";
2
- function isYaml(value) {
3
- if (!value.includes("\n")) {
4
- return false;
5
- }
6
- try {
7
- parse(value, {
8
- maxAliasCount: 1e4
9
- });
10
- return true;
11
- } catch (_error) {
12
- return false;
13
- }
1
+ import { parse } from 'yaml';
2
+ export function isYaml(value) {
3
+ // Line breaks
4
+ if (!value.includes('\n')) {
5
+ return false;
6
+ }
7
+ try {
8
+ parse(value, {
9
+ maxAliasCount: 10000,
10
+ });
11
+ return true;
12
+ }
13
+ catch (_error) {
14
+ return false;
15
+ }
14
16
  }
15
- export {
16
- isYaml
17
- };
18
- //# sourceMappingURL=is-yaml.js.map
@@ -1,5 +1 @@
1
- import { join } from "./join.js";
2
- export {
3
- join
4
- };
5
- //# sourceMappingURL=index.js.map
1
+ export { join } from './join.js';