@scalar/openapi-parser 0.25.4 → 0.25.6

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 +12 -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 +79 -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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @scalar/openapi-parser
2
2
 
3
+ ## 0.25.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#8520](https://github.com/scalar/scalar/pull/8520): Normalize trailing `+` in path template parameter names during path-parameter validation so `{name+}` matches a declared `name` path parameter.
8
+
9
+ ## 0.25.5
10
+
11
+ ### Patch Changes
12
+
13
+ - [#8466](https://github.com/scalar/scalar/pull/8466): chore: new build pipeline
14
+
3
15
  ## 0.25.4
4
16
 
5
17
  ### Patch Changes
@@ -1,26 +1,26 @@
1
- import Swagger20 from "../schemas/v2.0/schema.js";
2
- import OpenApi30 from "../schemas/v3.0/schema.js";
3
- import OpenApi31 from "../schemas/v3.1/schema.js";
4
- import OpenApi32 from "../schemas/v3.2/schema.js";
5
- const OpenApiSpecifications = {
6
- "2.0": Swagger20,
7
- "3.0": OpenApi30,
8
- "3.1": OpenApi31,
9
- "3.2": OpenApi32
1
+ import Swagger20 from '../schemas/v2.0/schema.js';
2
+ import OpenApi30 from '../schemas/v3.0/schema.js';
3
+ import OpenApi31 from '../schemas/v3.1/schema.js';
4
+ import OpenApi32 from '../schemas/v3.2/schema.js';
5
+ /**
6
+ * A list of the supported OpenAPI specifications
7
+ */
8
+ export const OpenApiSpecifications = {
9
+ '2.0': Swagger20,
10
+ '3.0': OpenApi30,
11
+ '3.1': OpenApi31,
12
+ '3.2': OpenApi32,
10
13
  };
11
- const OpenApiVersions = Object.keys(OpenApiSpecifications);
12
- const ERRORS = {
13
- EMPTY_OR_INVALID: "Can't find JSON, YAML or filename in data.",
14
- OPENAPI_VERSION_NOT_SUPPORTED: "Can't find supported Swagger/OpenAPI version in the provided document, version must be a string.",
15
- INVALID_REFERENCE: "Can't resolve reference: %s",
16
- EXTERNAL_REFERENCE_NOT_FOUND: "Can't resolve external reference: %s",
17
- SELF_REFERENCE: "Can't resolve reference to itself: %s",
18
- FILE_DOES_NOT_EXIST: "File does not exist: %s",
19
- NO_CONTENT: "No content found"
14
+ export const OpenApiVersions = Object.keys(OpenApiSpecifications);
15
+ /**
16
+ * List of error messages used in the Validator
17
+ */
18
+ export const ERRORS = {
19
+ EMPTY_OR_INVALID: "Can't find JSON, YAML or filename in data.",
20
+ OPENAPI_VERSION_NOT_SUPPORTED: "Can't find supported Swagger/OpenAPI version in the provided document, version must be a string.",
21
+ INVALID_REFERENCE: "Can't resolve reference: %s",
22
+ EXTERNAL_REFERENCE_NOT_FOUND: "Can't resolve external reference: %s",
23
+ SELF_REFERENCE: "Can't resolve reference to itself: %s",
24
+ FILE_DOES_NOT_EXIST: 'File does not exist: %s',
25
+ NO_CONTENT: 'No content found',
20
26
  };
21
- export {
22
- ERRORS,
23
- OpenApiSpecifications,
24
- OpenApiVersions
25
- };
26
- //# sourceMappingURL=index.js.map
package/dist/index.js CHANGED
@@ -1,45 +1,24 @@
1
- import {
2
- escapeJsonPointer
3
- } from "@scalar/json-magic/helpers/escape-json-pointer";
4
- import {
5
- upgradeFromTwoToThree
6
- } from "@scalar/openapi-upgrader/2.0-to-3.0";
7
- import {
8
- upgradeFromThreeToThreeOne
9
- } from "@scalar/openapi-upgrader/3.0-to-3.1";
10
- import { dereference } from "./utils/dereference.js";
11
- import { filter } from "./utils/filter.js";
12
- import { isJson } from "./utils/is-json.js";
13
- import { isYaml } from "./utils/is-yaml.js";
14
- import { join } from "./utils/join/index.js";
15
- import { load } from "./utils/load/index.js";
16
- import { normalize } from "./utils/normalize.js";
17
- import { openapi } from "./utils/openapi/openapi.js";
18
- import { toJson } from "./utils/to-json.js";
19
- import { toYaml } from "./utils/to-yaml.js";
20
- import { sanitize } from "./utils/transform/sanitize.js";
21
- import { traverse } from "./utils/traverse.js";
22
- import { unescapeJsonPointer } from "./utils/unescape-json-pointer.js";
23
- import { upgrade } from "./utils/upgrade.js";
24
- import { validate } from "./utils/validate.js";
25
- export {
26
- dereference,
27
- escapeJsonPointer,
28
- filter,
29
- isJson,
30
- isYaml,
31
- join,
32
- load,
33
- normalize,
34
- openapi,
35
- sanitize,
36
- toJson,
37
- toYaml,
38
- traverse,
39
- unescapeJsonPointer,
40
- upgrade,
41
- upgradeFromThreeToThreeOne,
42
- upgradeFromTwoToThree,
43
- validate
44
- };
45
- //# sourceMappingURL=index.js.map
1
+ export {
2
+ /** @deprecated Please import from @scalar/json-magic/helpers/escape-json-pointer instead */
3
+ escapeJsonPointer, } from '@scalar/json-magic/helpers/escape-json-pointer';
4
+ export {
5
+ /** @deprecated Please import from @scalar/openapi-upgrader/2.0-to-3.0 instead */
6
+ upgradeFromTwoToThree, } from '@scalar/openapi-upgrader/2.0-to-3.0';
7
+ export {
8
+ /** @deprecated Please import from @scalar/openapi-upgrader/3.0-to-3.1 instead */
9
+ upgradeFromThreeToThreeOne, } from '@scalar/openapi-upgrader/3.0-to-3.1';
10
+ export { dereference } from './utils/dereference.js';
11
+ export { filter } from './utils/filter.js';
12
+ export { isJson } from './utils/is-json.js';
13
+ export { isYaml } from './utils/is-yaml.js';
14
+ export { join } from './utils/join/index.js';
15
+ export { load } from './utils/load/index.js';
16
+ export { normalize } from './utils/normalize.js';
17
+ export { openapi } from './utils/openapi/openapi.js';
18
+ export { toJson } from './utils/to-json.js';
19
+ export { toYaml } from './utils/to-yaml.js';
20
+ export { sanitize } from './utils/transform/sanitize.js';
21
+ export { traverse } from './utils/traverse.js';
22
+ export { unescapeJsonPointer } from './utils/unescape-json-pointer.js';
23
+ export { upgrade } from './utils/upgrade.js';
24
+ export { validate } from './utils/validate.js';
@@ -1,116 +1,133 @@
1
- import Ajv, {} from "ajv";
2
- import Ajv2020 from "ajv/dist/2020.js";
3
- import Ajv04 from "ajv-draft-04";
4
- import addFormats from "ajv-formats";
5
- import { ERRORS, OpenApiSpecifications, OpenApiVersions } from "../../configuration/index.js";
6
- import { details as getOpenApiVersion } from "../../utils/details.js";
7
- import { resolveReferences } from "../../utils/resolve-references.js";
8
- import { transformErrors } from "../../utils/transform-errors.js";
9
- import { validatePathParameters } from "../../utils/validate-path-parameters.js";
1
+ import Ajv, {} from 'ajv';
2
+ import Ajv2020 from 'ajv/dist/2020.js';
3
+ import Ajv04 from 'ajv-draft-04';
4
+ import addFormats from 'ajv-formats';
5
+ import { ERRORS, OpenApiSpecifications, OpenApiVersions } from '../../configuration/index.js';
6
+ import { details as getOpenApiVersion } from '../../utils/details.js';
7
+ import { resolveReferences } from '../../utils/resolve-references.js';
8
+ import { transformErrors } from '../../utils/transform-errors.js';
9
+ import { validatePathParameters } from '../../utils/validate-path-parameters.js';
10
+ /**
11
+ * Configure available JSON Schema versions
12
+ */
10
13
  const jsonSchemaVersions = {
11
- "http://json-schema.org/draft-04/schema#": Ajv04,
12
- "http://json-schema.org/draft-07/schema#": Ajv,
13
- "https://json-schema.org/draft/2020-12/schema": Ajv2020
14
+ 'http://json-schema.org/draft-04/schema#': Ajv04,
15
+ 'http://json-schema.org/draft-07/schema#': Ajv,
16
+ 'https://json-schema.org/draft/2020-12/schema': Ajv2020,
14
17
  };
15
- class Validator {
16
- version;
17
- static supportedVersions = OpenApiVersions;
18
- // Object with function *or* object { errors: string }
19
- ajvValidators = {};
20
- errors;
21
- specificationVersion;
22
- specificationType;
23
- specification;
24
- /**
25
- * Checks whether a specification is valid and all references can be resolved.
26
- */
27
- validate(filesystem, options) {
28
- const entrypoint = filesystem.find((file) => file.isEntrypoint);
29
- const specification = entrypoint?.specification;
30
- this.specification = specification;
31
- if (this.specification?.info && !this.specification.info.version) {
32
- this.specification.info.version = "0.0.1";
33
- }
34
- try {
35
- if (specification === void 0 || specification === null) {
36
- if (options?.throwOnError) {
37
- throw new Error(ERRORS.EMPTY_OR_INVALID);
18
+ export class Validator {
19
+ version;
20
+ static supportedVersions = OpenApiVersions;
21
+ // Object with function *or* object { errors: string }
22
+ ajvValidators = {};
23
+ errors;
24
+ specificationVersion;
25
+ specificationType;
26
+ specification;
27
+ /**
28
+ * Checks whether a specification is valid and all references can be resolved.
29
+ */
30
+ validate(filesystem, options) {
31
+ const entrypoint = filesystem.find((file) => file.isEntrypoint);
32
+ const specification = entrypoint?.specification;
33
+ // TODO: How does this work with a filesystem?
34
+ this.specification = specification;
35
+ // TODO: defaulting info.version to keep parser compatible with the previous one
36
+ // we should bubble this error up and not throw on it
37
+ if (this.specification?.info && !this.specification.info.version) {
38
+ this.specification.info.version = '0.0.1';
38
39
  }
39
- return {
40
- valid: false,
41
- errors: transformErrors(specification, ERRORS.EMPTY_OR_INVALID)
42
- };
43
- }
44
- const { version, specificationType, specificationVersion } = getOpenApiVersion(specification);
45
- this.version = version;
46
- this.specificationVersion = specificationVersion;
47
- this.specificationType = specificationType;
48
- if (!version) {
49
- if (options?.throwOnError) {
50
- throw new Error(ERRORS.OPENAPI_VERSION_NOT_SUPPORTED);
40
+ try {
41
+ // AnyObject is empty or invalid
42
+ if (specification === undefined || specification === null) {
43
+ if (options?.throwOnError) {
44
+ throw new Error(ERRORS.EMPTY_OR_INVALID);
45
+ }
46
+ return {
47
+ valid: false,
48
+ errors: transformErrors(specification, ERRORS.EMPTY_OR_INVALID),
49
+ };
50
+ }
51
+ // Meta data about the specification
52
+ const { version, specificationType, specificationVersion } = getOpenApiVersion(specification);
53
+ this.version = version;
54
+ this.specificationVersion = specificationVersion;
55
+ this.specificationType = specificationType;
56
+ // AnyObject is not supported
57
+ if (!version) {
58
+ if (options?.throwOnError) {
59
+ throw new Error(ERRORS.OPENAPI_VERSION_NOT_SUPPORTED);
60
+ }
61
+ return {
62
+ valid: false,
63
+ errors: transformErrors(specification, ERRORS.OPENAPI_VERSION_NOT_SUPPORTED),
64
+ };
65
+ }
66
+ // Get the correct OpenAPI validator
67
+ const validateSchema = this.getAjvValidator(version);
68
+ const schemaResult = validateSchema(specification);
69
+ // Error handling
70
+ if (validateSchema.errors) {
71
+ if (validateSchema.errors.length > 0) {
72
+ if (options?.throwOnError) {
73
+ throw new Error(validateSchema.errors[0].message);
74
+ }
75
+ return {
76
+ valid: false,
77
+ errors: transformErrors(specification, validateSchema.errors),
78
+ };
79
+ }
80
+ }
81
+ // Check if the references are valid
82
+ const resolvedReferences = resolveReferences(filesystem, options);
83
+ const semanticErrors = validatePathParameters(resolvedReferences.schema);
84
+ const errors = [...resolvedReferences.errors, ...semanticErrors];
85
+ return {
86
+ valid: schemaResult && resolvedReferences.valid && semanticErrors.length === 0,
87
+ errors,
88
+ schema: resolvedReferences.schema,
89
+ };
51
90
  }
52
- return {
53
- valid: false,
54
- errors: transformErrors(specification, ERRORS.OPENAPI_VERSION_NOT_SUPPORTED)
55
- };
56
- }
57
- const validateSchema = this.getAjvValidator(version);
58
- const schemaResult = validateSchema(specification);
59
- if (validateSchema.errors) {
60
- if (validateSchema.errors.length > 0) {
61
- if (options?.throwOnError) {
62
- throw new Error(validateSchema.errors[0].message);
63
- }
64
- return {
65
- valid: false,
66
- errors: transformErrors(specification, validateSchema.errors)
67
- };
91
+ catch (error) {
92
+ // Something went horribly wrong!
93
+ if (options?.throwOnError) {
94
+ throw error;
95
+ }
96
+ return {
97
+ valid: false,
98
+ errors: transformErrors(specification, error.message ?? error),
99
+ };
68
100
  }
69
- }
70
- const resolvedReferences = resolveReferences(filesystem, options);
71
- const semanticErrors = validatePathParameters(resolvedReferences.schema);
72
- const errors = [...resolvedReferences.errors, ...semanticErrors];
73
- return {
74
- valid: schemaResult && resolvedReferences.valid && semanticErrors.length === 0,
75
- errors,
76
- schema: resolvedReferences.schema
77
- };
78
- } catch (error) {
79
- if (options?.throwOnError) {
80
- throw error;
81
- }
82
- return {
83
- valid: false,
84
- errors: transformErrors(specification, error.message ?? error)
85
- };
86
- }
87
- }
88
- /**
89
- * Ajv JSON schema validator
90
- */
91
- getAjvValidator(version) {
92
- if (this.ajvValidators[version]) {
93
- return this.ajvValidators[version];
94
101
  }
95
- const schema = OpenApiSpecifications[version];
96
- const AjvClass = jsonSchemaVersions[schema.$schema];
97
- const ajv = new AjvClass({
98
- // Ajv is a bit too strict in its strict validation of OpenAPI schemas.
99
- // Switch strict mode off.
100
- strict: false,
101
- // Enable discriminator support for better oneOf error messages
102
- discriminator: true,
103
- // Show all errors, not just the first one
104
- allErrors: true
105
- });
106
- addFormats(ajv);
107
- if (version === "3.1" || version === "3.2") {
108
- ajv.addFormat("media-range", true);
102
+ /**
103
+ * Ajv JSON schema validator
104
+ */
105
+ getAjvValidator(version) {
106
+ // Schema loaded already
107
+ if (this.ajvValidators[version]) {
108
+ return this.ajvValidators[version];
109
+ }
110
+ // Load OpenAPI Schema
111
+ const schema = OpenApiSpecifications[version];
112
+ // Load JSON Schema
113
+ const AjvClass = jsonSchemaVersions[schema.$schema];
114
+ // Get the correct Ajv validator
115
+ const ajv = new AjvClass({
116
+ // Ajv is a bit too strict in its strict validation of OpenAPI schemas.
117
+ // Switch strict mode off.
118
+ strict: false,
119
+ // Enable discriminator support for better oneOf error messages
120
+ discriminator: true,
121
+ // Show all errors, not just the first one
122
+ allErrors: true,
123
+ });
124
+ // Register formats
125
+ // https://ajv.js.org/packages/ajv-formats.html#formats
126
+ addFormats(ajv);
127
+ // OpenAPI 3.1 and 3.2 uses media-range format
128
+ if (version === '3.1' || version === '3.2') {
129
+ ajv.addFormat('media-range', true);
130
+ }
131
+ return (this.ajvValidators[version] = ajv.compile(schema));
109
132
  }
110
- return this.ajvValidators[version] = ajv.compile(schema);
111
- }
112
133
  }
113
- export {
114
- Validator
115
- };
116
- //# sourceMappingURL=Validator.js.map
@@ -1,40 +1,41 @@
1
- const fetchUrlsDefaultConfiguration = {
2
- limit: 20
1
+ export const fetchUrlsDefaultConfiguration = {
2
+ limit: 20,
3
3
  };
4
- const fetchUrls = (customConfiguration) => {
5
- let numberOfRequests = 0;
6
- const configuration = {
7
- ...fetchUrlsDefaultConfiguration,
8
- ...customConfiguration
9
- };
10
- return {
11
- check(value) {
12
- if (typeof value !== "string") {
13
- return false;
14
- }
15
- if (!value.startsWith("http://") && !value.startsWith("https://")) {
16
- return false;
17
- }
18
- return true;
19
- },
20
- async get(value) {
21
- if (configuration?.limit !== false && numberOfRequests >= configuration?.limit) {
22
- console.warn(`[fetchUrls] Maximum number of requests reeached (${configuration?.limit}), skipping request`);
23
- return void 0;
24
- }
25
- try {
26
- numberOfRequests++;
27
- const response = await (configuration?.fetch ? configuration.fetch(value) : fetch(value));
28
- return await response.text();
29
- } catch (error) {
30
- console.error("[fetchUrls]", error.message, `(${value})`);
31
- return void 0;
32
- }
33
- }
34
- };
4
+ export const fetchUrls = (customConfiguration) => {
5
+ // State
6
+ let numberOfRequests = 0;
7
+ // Configuration
8
+ const configuration = {
9
+ ...fetchUrlsDefaultConfiguration,
10
+ ...customConfiguration,
11
+ };
12
+ return {
13
+ check(value) {
14
+ // Not a string
15
+ if (typeof value !== 'string') {
16
+ return false;
17
+ }
18
+ // Not http/https
19
+ if (!value.startsWith('http://') && !value.startsWith('https://')) {
20
+ return false;
21
+ }
22
+ return true;
23
+ },
24
+ async get(value) {
25
+ // Limit ht enumber of requests
26
+ if (configuration?.limit !== false && numberOfRequests >= configuration?.limit) {
27
+ console.warn(`[fetchUrls] Maximum number of requests reeached (${configuration?.limit}), skipping request`);
28
+ return undefined;
29
+ }
30
+ try {
31
+ numberOfRequests++;
32
+ const response = await (configuration?.fetch ? configuration.fetch(value) : fetch(value));
33
+ return await response.text();
34
+ }
35
+ catch (error) {
36
+ console.error('[fetchUrls]', error.message, `(${value})`);
37
+ return undefined;
38
+ }
39
+ },
40
+ };
35
41
  };
36
- export {
37
- fetchUrls,
38
- fetchUrlsDefaultConfiguration
39
- };
40
- //# sourceMappingURL=fetch-urls.js.map
@@ -1,6 +1 @@
1
- import { fetchUrls, fetchUrlsDefaultConfiguration } from "./fetch-urls.js";
2
- export {
3
- fetchUrls,
4
- fetchUrlsDefaultConfiguration
5
- };
6
- //# sourceMappingURL=index.js.map
1
+ export { fetchUrls, fetchUrlsDefaultConfiguration } from './fetch-urls.js';
@@ -1,5 +1 @@
1
- import { readFiles } from "./read-files.js";
2
- export {
3
- readFiles
4
- };
5
- //# sourceMappingURL=index.js.map
1
+ export { readFiles } from './read-files.js';
@@ -1,52 +1,54 @@
1
- import fs from "node:fs";
2
- import { dirname, join } from "node:path";
3
- import { ERRORS } from "../../configuration/index.js";
4
- import { isJson } from "../../utils/is-json.js";
5
- import { isYaml } from "../../utils/is-yaml.js";
6
- const readFiles = () => {
7
- return {
8
- check(value) {
9
- if (typeof value !== "string") {
10
- return false;
11
- }
12
- if (value.startsWith("http://") || value.startsWith("https://")) {
13
- return false;
14
- }
15
- if (value.includes("\n")) {
16
- return false;
17
- }
18
- if (isJson(value)) {
19
- return false;
20
- }
21
- if (isYaml(value)) {
22
- return false;
23
- }
24
- return true;
25
- },
26
- get(value) {
27
- if (!fs.existsSync(value)) {
28
- throw new Error(ERRORS.FILE_DOES_NOT_EXIST.replace("%s", value));
29
- }
30
- try {
31
- return fs.readFileSync(value, "utf-8");
32
- } catch (error) {
33
- console.error("[readFiles]", error);
34
- return false;
35
- }
36
- },
37
- resolvePath(value, reference) {
38
- const dir = dirname(value);
39
- return join(dir, reference);
40
- },
41
- getDir(value) {
42
- return dirname(value);
43
- },
44
- getFilename(value) {
45
- return value.split("/").pop();
46
- }
47
- };
1
+ import fs from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { ERRORS } from '../../configuration/index.js';
4
+ import { isJson } from '../../utils/is-json.js';
5
+ import { isYaml } from '../../utils/is-yaml.js';
6
+ export const readFiles = () => {
7
+ return {
8
+ check(value) {
9
+ // Not a string
10
+ if (typeof value !== 'string') {
11
+ return false;
12
+ }
13
+ // URL
14
+ if (value.startsWith('http://') || value.startsWith('https://')) {
15
+ return false;
16
+ }
17
+ // Line breaks
18
+ if (value.includes('\n')) {
19
+ return false;
20
+ }
21
+ // JSON
22
+ if (isJson(value)) {
23
+ return false;
24
+ }
25
+ // YAML (run through YAML.parse)
26
+ if (isYaml(value)) {
27
+ return false;
28
+ }
29
+ return true;
30
+ },
31
+ get(value) {
32
+ if (!fs.existsSync(value)) {
33
+ throw new Error(ERRORS.FILE_DOES_NOT_EXIST.replace('%s', value));
34
+ }
35
+ try {
36
+ return fs.readFileSync(value, 'utf-8');
37
+ }
38
+ catch (error) {
39
+ console.error('[readFiles]', error);
40
+ return false;
41
+ }
42
+ },
43
+ resolvePath(value, reference) {
44
+ const dir = dirname(value);
45
+ return join(dir, reference);
46
+ },
47
+ getDir(value) {
48
+ return dirname(value);
49
+ },
50
+ getFilename(value) {
51
+ return value.split('/').pop();
52
+ },
53
+ };
48
54
  };
49
- export {
50
- readFiles
51
- };
52
- //# sourceMappingURL=read-files.js.map