@scalar/openapi-parser 0.25.3 → 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.
- package/CHANGELOG.md +12 -0
- package/dist/configuration/index.js +24 -24
- package/dist/index.js +24 -45
- package/dist/lib/Validator/Validator.d.ts.map +1 -1
- package/dist/lib/Validator/Validator.js +125 -105
- package/dist/plugins/fetch-urls/fetch-urls.js +39 -38
- package/dist/plugins/fetch-urls/index.js +1 -6
- package/dist/plugins/read-files/index.js +1 -5
- package/dist/plugins/read-files/read-files.js +53 -51
- package/dist/schemas/v2.0/schema.js +1373 -1377
- package/dist/schemas/v3.0/schema.js +1411 -1415
- package/dist/schemas/v3.1/schema.js +1196 -1200
- package/dist/schemas/v3.2/schema.js +1417 -1421
- package/dist/types/index.js +1 -1
- package/dist/utils/betterAjvErrors/helpers.js +138 -112
- package/dist/utils/betterAjvErrors/index.js +11 -15
- package/dist/utils/betterAjvErrors/utils.js +17 -30
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js +14 -18
- package/dist/utils/betterAjvErrors/validation-errors/base.js +20 -21
- package/dist/utils/betterAjvErrors/validation-errors/default.js +14 -18
- package/dist/utils/betterAjvErrors/validation-errors/enum.js +33 -37
- package/dist/utils/betterAjvErrors/validation-errors/index.js +6 -15
- package/dist/utils/betterAjvErrors/validation-errors/pattern.js +14 -18
- package/dist/utils/betterAjvErrors/validation-errors/required.js +13 -17
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js +14 -18
- package/dist/utils/dereference.js +22 -18
- package/dist/utils/details.js +28 -29
- package/dist/utils/filter.js +13 -14
- package/dist/utils/get-entrypoint.js +5 -6
- package/dist/utils/get-list-of-references.js +20 -16
- package/dist/utils/get-segments-from-path.js +13 -9
- package/dist/utils/is-filesystem.js +8 -6
- package/dist/utils/is-json.js +8 -11
- package/dist/utils/is-yaml.js +15 -17
- package/dist/utils/join/index.js +1 -5
- package/dist/utils/join/join.js +267 -153
- package/dist/utils/join/merge-objects.js +35 -18
- package/dist/utils/load/index.js +1 -5
- package/dist/utils/load/load.js +114 -90
- package/dist/utils/make-filesystem.js +20 -21
- package/dist/utils/normalize.js +32 -29
- package/dist/utils/openapi/actions/details.js +9 -10
- package/dist/utils/openapi/actions/files.js +7 -8
- package/dist/utils/openapi/actions/get.js +9 -10
- package/dist/utils/openapi/actions/toJson.js +9 -10
- package/dist/utils/openapi/actions/toYaml.js +9 -10
- package/dist/utils/openapi/commands/dereferenceCommand.js +25 -26
- package/dist/utils/openapi/commands/filterCommand.js +24 -25
- package/dist/utils/openapi/commands/loadCommand.js +40 -41
- package/dist/utils/openapi/commands/upgradeCommand.js +27 -28
- package/dist/utils/openapi/commands/validateCommand.js +31 -32
- package/dist/utils/openapi/openapi.js +16 -14
- package/dist/utils/openapi/openapi.test-d.js +13 -13
- package/dist/utils/openapi/utils/queueTask.js +8 -9
- package/dist/utils/openapi/utils/workThroughQueue.js +64 -50
- package/dist/utils/resolve-references.js +168 -110
- package/dist/utils/to-json.js +1 -5
- package/dist/utils/to-yaml.js +2 -6
- package/dist/utils/transform/sanitize.js +22 -22
- package/dist/utils/transform/utils/addInfoObject.js +9 -14
- package/dist/utils/transform/utils/addLatestOpenApiVersion.js +4 -9
- package/dist/utils/transform/utils/addMissingTags.js +26 -27
- package/dist/utils/transform/utils/normalizeSecuritySchemes.js +39 -37
- package/dist/utils/transform/utils/rejectSwaggerDocuments.js +5 -9
- package/dist/utils/transform-errors.js +62 -55
- package/dist/utils/traverse.js +21 -22
- package/dist/utils/unescape-json-pointer.js +8 -6
- package/dist/utils/upgrade.js +19 -22
- package/dist/utils/validate-path-parameters.d.ts +6 -0
- package/dist/utils/validate-path-parameters.d.ts.map +1 -0
- package/dist/utils/validate-path-parameters.js +91 -0
- package/dist/utils/validate.js +23 -19
- package/package.json +9 -14
- package/dist/configuration/index.js.map +0 -7
- package/dist/declarations.d.js +0 -1
- package/dist/declarations.d.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/lib/Validator/Validator.js.map +0 -7
- package/dist/plugins/fetch-urls/fetch-urls.js.map +0 -7
- package/dist/plugins/fetch-urls/index.js.map +0 -7
- package/dist/plugins/read-files/index.js.map +0 -7
- package/dist/plugins/read-files/read-files.js.map +0 -7
- package/dist/schemas/v2.0/schema.js.map +0 -7
- package/dist/schemas/v3.0/schema.js.map +0 -7
- package/dist/schemas/v3.1/schema.js.map +0 -7
- package/dist/schemas/v3.2/schema.js.map +0 -7
- package/dist/types/index.js.map +0 -7
- package/dist/utils/betterAjvErrors/helpers.js.map +0 -7
- package/dist/utils/betterAjvErrors/index.js.map +0 -7
- package/dist/utils/betterAjvErrors/utils.js.map +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js.map +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/base.js.map +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/default.js.map +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/enum.js.map +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/index.js.map +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/pattern.js.map +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/required.js.map +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js.map +0 -7
- package/dist/utils/dereference.js.map +0 -7
- package/dist/utils/details.js.map +0 -7
- package/dist/utils/filter.js.map +0 -7
- package/dist/utils/get-entrypoint.js.map +0 -7
- package/dist/utils/get-list-of-references.js.map +0 -7
- package/dist/utils/get-segments-from-path.js.map +0 -7
- package/dist/utils/is-filesystem.js.map +0 -7
- package/dist/utils/is-json.js.map +0 -7
- package/dist/utils/is-yaml.js.map +0 -7
- package/dist/utils/join/index.js.map +0 -7
- package/dist/utils/join/join.js.map +0 -7
- package/dist/utils/join/merge-objects.js.map +0 -7
- package/dist/utils/load/index.js.map +0 -7
- package/dist/utils/load/load.js.map +0 -7
- package/dist/utils/make-filesystem.js.map +0 -7
- package/dist/utils/normalize.js.map +0 -7
- package/dist/utils/openapi/actions/details.js.map +0 -7
- package/dist/utils/openapi/actions/files.js.map +0 -7
- package/dist/utils/openapi/actions/get.js.map +0 -7
- package/dist/utils/openapi/actions/toJson.js.map +0 -7
- package/dist/utils/openapi/actions/toYaml.js.map +0 -7
- package/dist/utils/openapi/commands/dereferenceCommand.js.map +0 -7
- package/dist/utils/openapi/commands/filterCommand.js.map +0 -7
- package/dist/utils/openapi/commands/loadCommand.js.map +0 -7
- package/dist/utils/openapi/commands/upgradeCommand.js.map +0 -7
- package/dist/utils/openapi/commands/validateCommand.js.map +0 -7
- package/dist/utils/openapi/openapi.js.map +0 -7
- package/dist/utils/openapi/openapi.test-d.js.map +0 -7
- package/dist/utils/openapi/utils/queueTask.js.map +0 -7
- package/dist/utils/openapi/utils/workThroughQueue.js.map +0 -7
- package/dist/utils/resolve-references.js.map +0 -7
- package/dist/utils/to-json.js.map +0 -7
- package/dist/utils/to-yaml.js.map +0 -7
- package/dist/utils/transform/sanitize.js.map +0 -7
- package/dist/utils/transform/utils/addInfoObject.js.map +0 -7
- package/dist/utils/transform/utils/addLatestOpenApiVersion.js.map +0 -7
- package/dist/utils/transform/utils/addMissingTags.js.map +0 -7
- package/dist/utils/transform/utils/normalizeSecuritySchemes.js.map +0 -7
- package/dist/utils/transform/utils/rejectSwaggerDocuments.js.map +0 -7
- package/dist/utils/transform-errors.js.map +0 -7
- package/dist/utils/traverse.js.map +0 -7
- package/dist/utils/unescape-json-pointer.js.map +0 -7
- package/dist/utils/upgrade.js.map +0 -7
- 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.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#8466](https://github.com/scalar/scalar/pull/8466): chore: new build pipeline
|
|
8
|
+
|
|
9
|
+
## 0.25.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#8448](https://github.com/scalar/scalar/pull/8448): fix parser validation for unused path parameters
|
|
14
|
+
|
|
3
15
|
## 0.25.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import Swagger20 from
|
|
2
|
-
import OpenApi30 from
|
|
3
|
-
import OpenApi31 from
|
|
4
|
-
import OpenApi32 from
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Validator.d.ts","sourceRoot":"","sources":["../../../src/lib/Validator/Validator.ts"],"names":[],"mappings":"AAAA,OAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAKhD,OAAO,EAAiC,KAAK,cAAc,EAAmB,MAAM,iBAAiB,CAAA;AACrG,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"Validator.d.ts","sourceRoot":"","sources":["../../../src/lib/Validator/Validator.ts"],"names":[],"mappings":"AAAA,OAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAKhD,OAAO,EAAiC,KAAK,cAAc,EAAmB,MAAM,iBAAiB,CAAA;AACrG,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAe9F,qBAAa,SAAS;IACb,OAAO,EAAE,cAAc,CAAA;IAE9B,OAAc,iBAAiB,oCAAkB;IAGjD,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAK;IAE9D,SAAS,CAAC,MAAM,EAAE,MAAM,CAAA;IAExB,SAAS,CAAC,oBAAoB,EAAE,MAAM,CAAA;IAEtC,SAAS,CAAC,iBAAiB,EAAE,MAAM,CAAA;IAE5B,aAAa,EAAE,SAAS,CAAA;IAE/B;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,cAAc;IAsF9E;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,gBAAgB;CAkC3D"}
|
|
@@ -1,113 +1,133 @@
|
|
|
1
|
-
import Ajv, {} from
|
|
2
|
-
import Ajv2020 from
|
|
3
|
-
import Ajv04 from
|
|
4
|
-
import addFormats from
|
|
5
|
-
import { ERRORS, OpenApiSpecifications, OpenApiVersions } from
|
|
6
|
-
import { details as getOpenApiVersion } from
|
|
7
|
-
import { resolveReferences } from
|
|
8
|
-
import { transformErrors } from
|
|
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
|
+
*/
|
|
9
13
|
const jsonSchemaVersions = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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,
|
|
13
17
|
};
|
|
14
|
-
class Validator {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (options?.throwOnError) {
|
|
36
|
-
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';
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
+
};
|
|
50
90
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (options?.throwOnError) {
|
|
61
|
-
throw new Error(validateSchema.errors[0].message);
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
valid: false,
|
|
65
|
-
errors: transformErrors(specification, validateSchema.errors)
|
|
66
|
-
};
|
|
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
|
+
};
|
|
67
100
|
}
|
|
68
|
-
}
|
|
69
|
-
const resolvedReferences = resolveReferences(filesystem, options);
|
|
70
|
-
return {
|
|
71
|
-
valid: schemaResult && resolvedReferences.valid,
|
|
72
|
-
errors: [...resolvedReferences.errors],
|
|
73
|
-
schema: resolvedReferences.schema
|
|
74
|
-
};
|
|
75
|
-
} catch (error) {
|
|
76
|
-
if (options?.throwOnError) {
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
valid: false,
|
|
81
|
-
errors: transformErrors(specification, error.message ?? error)
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Ajv JSON schema validator
|
|
87
|
-
*/
|
|
88
|
-
getAjvValidator(version) {
|
|
89
|
-
if (this.ajvValidators[version]) {
|
|
90
|
-
return this.ajvValidators[version];
|
|
91
101
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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));
|
|
106
132
|
}
|
|
107
|
-
return this.ajvValidators[version] = ajv.compile(schema);
|
|
108
|
-
}
|
|
109
133
|
}
|
|
110
|
-
export {
|
|
111
|
-
Validator
|
|
112
|
-
};
|
|
113
|
-
//# sourceMappingURL=Validator.js.map
|
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
const fetchUrlsDefaultConfiguration = {
|
|
2
|
-
|
|
1
|
+
export const fetchUrlsDefaultConfiguration = {
|
|
2
|
+
limit: 20,
|
|
3
3
|
};
|
|
4
|
-
const fetchUrls = (customConfiguration) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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,52 +1,54 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import { dirname, join } from
|
|
3
|
-
import { ERRORS } from
|
|
4
|
-
import { isJson } from
|
|
5
|
-
import { isYaml } from
|
|
6
|
-
const readFiles = () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|