@redocly/openapi-core 0.0.0-snapshot.1737554067
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/README.md +268 -0
- package/lib/benchmark/benches/lint-with-many-rules.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-many-rules.bench.js +38 -0
- package/lib/benchmark/benches/lint-with-nested-rule.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-nested-rule.bench.js +44 -0
- package/lib/benchmark/benches/lint-with-no-rules.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-no-rules.bench.js +25 -0
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +37 -0
- package/lib/benchmark/benches/lint-with-top-level-rule.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-top-level-rule.bench.js +36 -0
- package/lib/benchmark/benches/recommended-oas3.bench.d.ts +3 -0
- package/lib/benchmark/benches/recommended-oas3.bench.js +21 -0
- package/lib/benchmark/benches/resolve-with-no-external.bench.d.ts +3 -0
- package/lib/benchmark/benches/resolve-with-no-external.bench.js +22 -0
- package/lib/benchmark/utils.d.ts +6 -0
- package/lib/benchmark/utils.js +34 -0
- package/lib/bundle.d.ts +50 -0
- package/lib/bundle.js +385 -0
- package/lib/config/all.d.ts +3 -0
- package/lib/config/all.js +227 -0
- package/lib/config/builtIn.d.ts +3 -0
- package/lib/config/builtIn.js +53 -0
- package/lib/config/config-resolvers.d.ts +30 -0
- package/lib/config/config-resolvers.js +447 -0
- package/lib/config/config.d.ts +53 -0
- package/lib/config/config.js +320 -0
- package/lib/config/index.d.ts +7 -0
- package/lib/config/index.js +23 -0
- package/lib/config/load.d.ts +38 -0
- package/lib/config/load.js +140 -0
- package/lib/config/minimal.d.ts +3 -0
- package/lib/config/minimal.js +203 -0
- package/lib/config/recommended-strict.d.ts +3 -0
- package/lib/config/recommended-strict.js +203 -0
- package/lib/config/recommended.d.ts +3 -0
- package/lib/config/recommended.js +203 -0
- package/lib/config/rules.d.ts +10 -0
- package/lib/config/rules.js +37 -0
- package/lib/config/spec.d.ts +3 -0
- package/lib/config/spec.js +29 -0
- package/lib/config/types.d.ts +189 -0
- package/lib/config/types.js +2 -0
- package/lib/config/utils.d.ts +19 -0
- package/lib/config/utils.js +308 -0
- package/lib/decorators/arazzo/index.d.ts +1 -0
- package/lib/decorators/arazzo/index.js +4 -0
- package/lib/decorators/async2/index.d.ts +1 -0
- package/lib/decorators/async2/index.js +4 -0
- package/lib/decorators/async3/index.d.ts +1 -0
- package/lib/decorators/async3/index.js +4 -0
- package/lib/decorators/common/filters/filter-helper.d.ts +3 -0
- package/lib/decorators/common/filters/filter-helper.js +66 -0
- package/lib/decorators/common/filters/filter-in.d.ts +2 -0
- package/lib/decorators/common/filters/filter-in.js +17 -0
- package/lib/decorators/common/filters/filter-out.d.ts +2 -0
- package/lib/decorators/common/filters/filter-out.js +17 -0
- package/lib/decorators/common/info-description-override.d.ts +2 -0
- package/lib/decorators/common/info-description-override.js +24 -0
- package/lib/decorators/common/info-override.d.ts +2 -0
- package/lib/decorators/common/info-override.js +17 -0
- package/lib/decorators/common/media-type-examples-override.d.ts +2 -0
- package/lib/decorators/common/media-type-examples-override.js +59 -0
- package/lib/decorators/common/operation-description-override.d.ts +2 -0
- package/lib/decorators/common/operation-description-override.js +29 -0
- package/lib/decorators/common/registry-dependencies.d.ts +2 -0
- package/lib/decorators/common/registry-dependencies.js +24 -0
- package/lib/decorators/common/remove-x-internal.d.ts +2 -0
- package/lib/decorators/common/remove-x-internal.js +69 -0
- package/lib/decorators/common/tag-description-override.d.ts +2 -0
- package/lib/decorators/common/tag-description-override.js +25 -0
- package/lib/decorators/oas2/index.d.ts +11 -0
- package/lib/decorators/oas2/index.js +21 -0
- package/lib/decorators/oas2/remove-unused-components.d.ts +2 -0
- package/lib/decorators/oas2/remove-unused-components.js +89 -0
- package/lib/decorators/oas3/index.d.ts +12 -0
- package/lib/decorators/oas3/index.js +23 -0
- package/lib/decorators/oas3/remove-unused-components.d.ts +2 -0
- package/lib/decorators/oas3/remove-unused-components.js +100 -0
- package/lib/env.d.ts +2 -0
- package/lib/env.js +7 -0
- package/lib/format/codeframes.d.ts +22 -0
- package/lib/format/codeframes.js +185 -0
- package/lib/format/format.d.ts +20 -0
- package/lib/format/format.js +365 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.js +98 -0
- package/lib/js-yaml/index.d.ts +3 -0
- package/lib/js-yaml/index.js +15 -0
- package/lib/lint.d.ts +32 -0
- package/lib/lint.js +118 -0
- package/lib/logger.d.ts +10 -0
- package/lib/logger.js +31 -0
- package/lib/oas-types.d.ts +36 -0
- package/lib/oas-types.js +92 -0
- package/lib/output.d.ts +3 -0
- package/lib/output.js +9 -0
- package/lib/redocly/domains.d.ts +14 -0
- package/lib/redocly/domains.js +41 -0
- package/lib/redocly/index.d.ts +30 -0
- package/lib/redocly/index.js +131 -0
- package/lib/redocly/redocly-client-types.d.ts +8 -0
- package/lib/redocly/redocly-client-types.js +2 -0
- package/lib/redocly/registry-api-types.d.ts +29 -0
- package/lib/redocly/registry-api-types.js +2 -0
- package/lib/redocly/registry-api.d.ts +17 -0
- package/lib/redocly/registry-api.js +96 -0
- package/lib/ref-utils.d.ts +27 -0
- package/lib/ref-utils.js +85 -0
- package/lib/resolve.d.ts +66 -0
- package/lib/resolve.js +342 -0
- package/lib/rules/ajv.d.ts +10 -0
- package/lib/rules/ajv.js +82 -0
- package/lib/rules/arazzo/criteria-unique.d.ts +2 -0
- package/lib/rules/arazzo/criteria-unique.js +71 -0
- package/lib/rules/arazzo/index.d.ts +3 -0
- package/lib/rules/arazzo/index.js +36 -0
- package/lib/rules/arazzo/parameters-unique.d.ts +2 -0
- package/lib/rules/arazzo/parameters-unique.js +32 -0
- package/lib/rules/arazzo/requestBody-replacements-unique.d.ts +2 -0
- package/lib/rules/arazzo/requestBody-replacements-unique.js +28 -0
- package/lib/rules/arazzo/sourceDescription-type.d.ts +2 -0
- package/lib/rules/arazzo/sourceDescription-type.js +22 -0
- package/lib/rules/arazzo/sourceDescriptions-name-unique.d.ts +2 -0
- package/lib/rules/arazzo/sourceDescriptions-name-unique.js +24 -0
- package/lib/rules/arazzo/sourceDescriptions-not-empty.d.ts +2 -0
- package/lib/rules/arazzo/sourceDescriptions-not-empty.js +18 -0
- package/lib/rules/arazzo/step-onFailure-unique.d.ts +2 -0
- package/lib/rules/arazzo/step-onFailure-unique.js +32 -0
- package/lib/rules/arazzo/step-onSuccess-unique.d.ts +2 -0
- package/lib/rules/arazzo/step-onSuccess-unique.js +32 -0
- package/lib/rules/arazzo/stepId-unique.d.ts +2 -0
- package/lib/rules/arazzo/stepId-unique.js +26 -0
- package/lib/rules/arazzo/workflow-dependsOn.d.ts +2 -0
- package/lib/rules/arazzo/workflow-dependsOn.js +56 -0
- package/lib/rules/arazzo/workflowId-unique.d.ts +2 -0
- package/lib/rules/arazzo/workflowId-unique.js +22 -0
- package/lib/rules/async2/channels-kebab-case.d.ts +2 -0
- package/lib/rules/async2/channels-kebab-case.js +19 -0
- package/lib/rules/async2/index.d.ts +3 -0
- package/lib/rules/async2/index.js +27 -0
- package/lib/rules/async2/no-channel-trailing-slash.d.ts +2 -0
- package/lib/rules/async2/no-channel-trailing-slash.js +16 -0
- package/lib/rules/async3/channels-kebab-case.d.ts +2 -0
- package/lib/rules/async3/channels-kebab-case.js +19 -0
- package/lib/rules/async3/index.d.ts +3 -0
- package/lib/rules/async3/index.js +27 -0
- package/lib/rules/async3/no-channel-trailing-slash.d.ts +2 -0
- package/lib/rules/async3/no-channel-trailing-slash.js +16 -0
- package/lib/rules/common/assertions/asserts.d.ts +30 -0
- package/lib/rules/common/assertions/asserts.js +281 -0
- package/lib/rules/common/assertions/index.d.ts +27 -0
- package/lib/rules/common/assertions/index.js +24 -0
- package/lib/rules/common/assertions/utils.d.ts +28 -0
- package/lib/rules/common/assertions/utils.js +226 -0
- package/lib/rules/common/info-contact.d.ts +2 -0
- package/lib/rules/common/info-contact.js +17 -0
- package/lib/rules/common/info-license-strict.d.ts +2 -0
- package/lib/rules/common/info-license-strict.js +26 -0
- package/lib/rules/common/info-license-url.d.ts +2 -0
- package/lib/rules/common/info-license-url.js +12 -0
- package/lib/rules/common/info-license.d.ts +2 -0
- package/lib/rules/common/info-license.js +17 -0
- package/lib/rules/common/no-ambiguous-paths.d.ts +2 -0
- package/lib/rules/common/no-ambiguous-paths.js +45 -0
- package/lib/rules/common/no-enum-type-mismatch.d.ts +2 -0
- package/lib/rules/common/no-enum-type-mismatch.js +41 -0
- package/lib/rules/common/no-http-verbs-in-paths.d.ts +2 -0
- package/lib/rules/common/no-http-verbs-in-paths.js +33 -0
- package/lib/rules/common/no-identical-paths.d.ts +2 -0
- package/lib/rules/common/no-identical-paths.js +24 -0
- package/lib/rules/common/no-invalid-parameter-examples.d.ts +1 -0
- package/lib/rules/common/no-invalid-parameter-examples.js +24 -0
- package/lib/rules/common/no-invalid-schema-examples.d.ts +1 -0
- package/lib/rules/common/no-invalid-schema-examples.js +22 -0
- package/lib/rules/common/no-path-trailing-slash.d.ts +2 -0
- package/lib/rules/common/no-path-trailing-slash.js +16 -0
- package/lib/rules/common/no-required-schema-properties-undefined.d.ts +2 -0
- package/lib/rules/common/no-required-schema-properties-undefined.js +36 -0
- package/lib/rules/common/operation-2xx-response.d.ts +2 -0
- package/lib/rules/common/operation-2xx-response.js +23 -0
- package/lib/rules/common/operation-4xx-response.d.ts +2 -0
- package/lib/rules/common/operation-4xx-response.js +23 -0
- package/lib/rules/common/operation-description.d.ts +2 -0
- package/lib/rules/common/operation-description.js +12 -0
- package/lib/rules/common/operation-operationId-unique.d.ts +2 -0
- package/lib/rules/common/operation-operationId-unique.js +20 -0
- package/lib/rules/common/operation-operationId-url-safe.d.ts +2 -0
- package/lib/rules/common/operation-operationId-url-safe.js +18 -0
- package/lib/rules/common/operation-operationId.d.ts +2 -0
- package/lib/rules/common/operation-operationId.js +16 -0
- package/lib/rules/common/operation-parameters-unique.d.ts +2 -0
- package/lib/rules/common/operation-parameters-unique.js +40 -0
- package/lib/rules/common/operation-singular-tag.d.ts +2 -0
- package/lib/rules/common/operation-singular-tag.js +16 -0
- package/lib/rules/common/operation-summary.d.ts +2 -0
- package/lib/rules/common/operation-summary.js +12 -0
- package/lib/rules/common/operation-tag-defined.d.ts +2 -0
- package/lib/rules/common/operation-tag-defined.js +24 -0
- package/lib/rules/common/parameter-description.d.ts +2 -0
- package/lib/rules/common/parameter-description.js +22 -0
- package/lib/rules/common/path-declaration-must-exist.d.ts +2 -0
- package/lib/rules/common/path-declaration-must-exist.js +16 -0
- package/lib/rules/common/path-excludes-patterns.d.ts +2 -0
- package/lib/rules/common/path-excludes-patterns.js +22 -0
- package/lib/rules/common/path-http-verbs-order.d.ts +2 -0
- package/lib/rules/common/path-http-verbs-order.js +26 -0
- package/lib/rules/common/path-not-include-query.d.ts +2 -0
- package/lib/rules/common/path-not-include-query.js +18 -0
- package/lib/rules/common/path-params-defined.d.ts +2 -0
- package/lib/rules/common/path-params-defined.js +58 -0
- package/lib/rules/common/path-segment-plural.d.ts +2 -0
- package/lib/rules/common/path-segment-plural.js +33 -0
- package/lib/rules/common/paths-kebab-case.d.ts +2 -0
- package/lib/rules/common/paths-kebab-case.js +20 -0
- package/lib/rules/common/required-string-property-missing-min-length.d.ts +2 -0
- package/lib/rules/common/required-string-property-missing-min-length.js +37 -0
- package/lib/rules/common/response-contains-header.d.ts +2 -0
- package/lib/rules/common/response-contains-header.js +29 -0
- package/lib/rules/common/scalar-property-missing-example.d.ts +2 -0
- package/lib/rules/common/scalar-property-missing-example.js +42 -0
- package/lib/rules/common/security-defined.d.ts +2 -0
- package/lib/rules/common/security-defined.js +65 -0
- package/lib/rules/common/spec-strict-refs.d.ts +2 -0
- package/lib/rules/common/spec-strict-refs.js +30 -0
- package/lib/rules/common/struct.d.ts +2 -0
- package/lib/rules/common/struct.js +158 -0
- package/lib/rules/common/tag-description.d.ts +2 -0
- package/lib/rules/common/tag-description.js +12 -0
- package/lib/rules/common/tags-alphabetical.d.ts +2 -0
- package/lib/rules/common/tags-alphabetical.js +23 -0
- package/lib/rules/no-unresolved-refs.d.ts +5 -0
- package/lib/rules/no-unresolved-refs.js +46 -0
- package/lib/rules/oas2/boolean-parameter-prefixes.d.ts +5 -0
- package/lib/rules/oas2/boolean-parameter-prefixes.js +22 -0
- package/lib/rules/oas2/index.d.ts +3 -0
- package/lib/rules/oas2/index.js +98 -0
- package/lib/rules/oas2/request-mime-type.d.ts +2 -0
- package/lib/rules/oas2/request-mime-type.js +17 -0
- package/lib/rules/oas2/response-contains-property.d.ts +2 -0
- package/lib/rules/oas2/response-contains-property.js +37 -0
- package/lib/rules/oas2/response-mime-type.d.ts +2 -0
- package/lib/rules/oas2/response-mime-type.js +17 -0
- package/lib/rules/oas3/array-parameter-serialization.d.ts +5 -0
- package/lib/rules/oas3/array-parameter-serialization.js +29 -0
- package/lib/rules/oas3/boolean-parameter-prefixes.d.ts +5 -0
- package/lib/rules/oas3/boolean-parameter-prefixes.js +24 -0
- package/lib/rules/oas3/component-name-unique.d.ts +2 -0
- package/lib/rules/oas3/component-name-unique.js +133 -0
- package/lib/rules/oas3/index.d.ts +3 -0
- package/lib/rules/oas3/index.js +122 -0
- package/lib/rules/oas3/no-empty-servers.d.ts +2 -0
- package/lib/rules/oas3/no-empty-servers.js +23 -0
- package/lib/rules/oas3/no-example-value-and-externalValue.d.ts +2 -0
- package/lib/rules/oas3/no-example-value-and-externalValue.js +16 -0
- package/lib/rules/oas3/no-invalid-media-type-examples.d.ts +2 -0
- package/lib/rules/oas3/no-invalid-media-type-examples.js +39 -0
- package/lib/rules/oas3/no-server-example.com.d.ts +2 -0
- package/lib/rules/oas3/no-server-example.com.js +18 -0
- package/lib/rules/oas3/no-server-trailing-slash.d.ts +2 -0
- package/lib/rules/oas3/no-server-trailing-slash.js +18 -0
- package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
- package/lib/rules/oas3/no-server-variables-empty-enum.js +66 -0
- package/lib/rules/oas3/no-undefined-server-variable.d.ts +2 -0
- package/lib/rules/oas3/no-undefined-server-variable.js +31 -0
- package/lib/rules/oas3/no-unused-components.d.ts +2 -0
- package/lib/rules/oas3/no-unused-components.js +73 -0
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +5 -0
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +36 -0
- package/lib/rules/oas3/request-mime-type.d.ts +2 -0
- package/lib/rules/oas3/request-mime-type.js +31 -0
- package/lib/rules/oas3/response-contains-property.d.ts +2 -0
- package/lib/rules/oas3/response-contains-property.js +39 -0
- package/lib/rules/oas3/response-mime-type.d.ts +2 -0
- package/lib/rules/oas3/response-mime-type.js +31 -0
- package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
- package/lib/rules/oas3/spec-components-invalid-map-name.js +62 -0
- package/lib/rules/other/stats.d.ts +41 -0
- package/lib/rules/other/stats.js +75 -0
- package/lib/rules/spot/no-criteria-xpath.d.ts +2 -0
- package/lib/rules/spot/no-criteria-xpath.js +21 -0
- package/lib/rules/spot/spot-supported-versions.d.ts +2 -0
- package/lib/rules/spot/spot-supported-versions.js +21 -0
- package/lib/rules/utils.d.ts +22 -0
- package/lib/rules/utils.js +183 -0
- package/lib/types/arazzo.d.ts +2 -0
- package/lib/types/arazzo.js +311 -0
- package/lib/types/asyncapi2.d.ts +17 -0
- package/lib/types/asyncapi2.js +1008 -0
- package/lib/types/asyncapi3.d.ts +2 -0
- package/lib/types/asyncapi3.js +347 -0
- package/lib/types/index.d.ts +57 -0
- package/lib/types/index.js +94 -0
- package/lib/types/json-schema-adapter.d.ts +3 -0
- package/lib/types/json-schema-adapter.js +159 -0
- package/lib/types/oas2.d.ts +3 -0
- package/lib/types/oas2.js +456 -0
- package/lib/types/oas3.d.ts +7 -0
- package/lib/types/oas3.js +554 -0
- package/lib/types/oas3_1.d.ts +6 -0
- package/lib/types/oas3_1.js +285 -0
- package/lib/types/redocly-yaml.d.ts +26 -0
- package/lib/types/redocly-yaml.js +1126 -0
- package/lib/typings/arazzo.d.ts +131 -0
- package/lib/typings/arazzo.js +5 -0
- package/lib/typings/asyncapi.d.ts +21 -0
- package/lib/typings/asyncapi.js +2 -0
- package/lib/typings/asyncapi3.d.ts +53 -0
- package/lib/typings/asyncapi3.js +2 -0
- package/lib/typings/common.d.ts +8 -0
- package/lib/typings/common.js +2 -0
- package/lib/typings/openapi.d.ts +355 -0
- package/lib/typings/openapi.js +2 -0
- package/lib/typings/swagger.d.ts +217 -0
- package/lib/typings/swagger.js +2 -0
- package/lib/utils.d.ts +70 -0
- package/lib/utils.js +301 -0
- package/lib/visitors.d.ts +229 -0
- package/lib/visitors.js +176 -0
- package/lib/walk.d.ts +78 -0
- package/lib/walk.js +290 -0
- package/package.json +59 -0
package/lib/resolve.js
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseResolver = exports.YamlParseError = exports.ResolveError = exports.Source = void 0;
|
|
4
|
+
exports.makeRefId = makeRefId;
|
|
5
|
+
exports.makeDocumentFromString = makeDocumentFromString;
|
|
6
|
+
exports.resolveDocument = resolveDocument;
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const ref_utils_1 = require("./ref-utils");
|
|
10
|
+
const types_1 = require("./types");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
class Source {
|
|
13
|
+
constructor(absoluteRef, body, mimeType) {
|
|
14
|
+
this.absoluteRef = absoluteRef;
|
|
15
|
+
this.body = body;
|
|
16
|
+
this.mimeType = mimeType;
|
|
17
|
+
}
|
|
18
|
+
// pass safeLoad as argument to separate it from browser bundle
|
|
19
|
+
getAst(safeLoad) {
|
|
20
|
+
if (this._ast === undefined) {
|
|
21
|
+
this._ast = safeLoad(this.body, { filename: this.absoluteRef }) ?? undefined;
|
|
22
|
+
// fix ast representation of file with newlines only
|
|
23
|
+
if (this._ast &&
|
|
24
|
+
this._ast.kind === 0 && // KIND.scalar = 0
|
|
25
|
+
this._ast.value === '' &&
|
|
26
|
+
this._ast.startPosition !== 1) {
|
|
27
|
+
this._ast.startPosition = 1;
|
|
28
|
+
this._ast.endPosition = 1;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return this._ast;
|
|
32
|
+
}
|
|
33
|
+
getLines() {
|
|
34
|
+
if (this._lines === undefined) {
|
|
35
|
+
this._lines = this.body.split(/\r\n|[\n\r]/g);
|
|
36
|
+
}
|
|
37
|
+
return this._lines;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.Source = Source;
|
|
41
|
+
class ResolveError extends Error {
|
|
42
|
+
constructor(originalError) {
|
|
43
|
+
super(originalError.message);
|
|
44
|
+
this.originalError = originalError;
|
|
45
|
+
// Set the prototype explicitly.
|
|
46
|
+
Object.setPrototypeOf(this, ResolveError.prototype);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.ResolveError = ResolveError;
|
|
50
|
+
const jsYamlErrorLineColRegexp = /\((\d+):(\d+)\)$/;
|
|
51
|
+
class YamlParseError extends Error {
|
|
52
|
+
constructor(originalError, source) {
|
|
53
|
+
super(originalError.message.split('\n')[0]);
|
|
54
|
+
this.originalError = originalError;
|
|
55
|
+
this.source = source;
|
|
56
|
+
// Set the prototype explicitly.
|
|
57
|
+
Object.setPrototypeOf(this, YamlParseError.prototype);
|
|
58
|
+
const [, line, col] = this.message.match(jsYamlErrorLineColRegexp) || [];
|
|
59
|
+
this.line = parseInt(line, 10);
|
|
60
|
+
this.col = parseInt(col, 10);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.YamlParseError = YamlParseError;
|
|
64
|
+
function makeRefId(absoluteRef, pointer) {
|
|
65
|
+
return absoluteRef + '::' + pointer;
|
|
66
|
+
}
|
|
67
|
+
function makeDocumentFromString(sourceString, absoluteRef) {
|
|
68
|
+
const source = new Source(absoluteRef, sourceString);
|
|
69
|
+
try {
|
|
70
|
+
return {
|
|
71
|
+
source,
|
|
72
|
+
parsed: (0, utils_1.parseYaml)(sourceString, { filename: absoluteRef }),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
throw new YamlParseError(e, source);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
class BaseResolver {
|
|
80
|
+
constructor(config = { http: { headers: [] } }) {
|
|
81
|
+
this.config = config;
|
|
82
|
+
this.cache = new Map();
|
|
83
|
+
}
|
|
84
|
+
getFiles() {
|
|
85
|
+
return new Set(Array.from(this.cache.keys()));
|
|
86
|
+
}
|
|
87
|
+
resolveExternalRef(base, ref) {
|
|
88
|
+
if ((0, ref_utils_1.isAbsoluteUrl)(ref)) {
|
|
89
|
+
return ref;
|
|
90
|
+
}
|
|
91
|
+
if (base && (0, ref_utils_1.isAbsoluteUrl)(base)) {
|
|
92
|
+
return new URL(ref, base).href;
|
|
93
|
+
}
|
|
94
|
+
return path.resolve(base ? path.dirname(base) : process.cwd(), ref);
|
|
95
|
+
}
|
|
96
|
+
async loadExternalRef(absoluteRef) {
|
|
97
|
+
try {
|
|
98
|
+
if ((0, ref_utils_1.isAbsoluteUrl)(absoluteRef)) {
|
|
99
|
+
const { body, mimeType } = await (0, utils_1.readFileFromUrl)(absoluteRef, this.config.http);
|
|
100
|
+
return new Source(absoluteRef, body, mimeType);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
if (fs.lstatSync(absoluteRef).isDirectory()) {
|
|
104
|
+
throw new Error(`Expected a file but received a folder at ${absoluteRef}.`);
|
|
105
|
+
}
|
|
106
|
+
const content = await fs.promises.readFile(absoluteRef, 'utf-8');
|
|
107
|
+
// In some cases file have \r\n line delimeters like on windows, we should skip it.
|
|
108
|
+
return new Source(absoluteRef, content.replace(/\r\n/g, '\n'));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
error.message = error.message.replace(', lstat', '');
|
|
113
|
+
throw new ResolveError(error);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
parseDocument(source, isRoot = false) {
|
|
117
|
+
const ext = source.absoluteRef.substr(source.absoluteRef.lastIndexOf('.'));
|
|
118
|
+
if (!['.json', '.json', '.yml', '.yaml'].includes(ext) &&
|
|
119
|
+
!source.mimeType?.match(/(json|yaml|openapi)/) &&
|
|
120
|
+
!isRoot // always parse root
|
|
121
|
+
) {
|
|
122
|
+
return { source, parsed: source.body };
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
return {
|
|
126
|
+
source,
|
|
127
|
+
parsed: (0, utils_1.parseYaml)(source.body, { filename: source.absoluteRef }),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
throw new YamlParseError(e, source);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async resolveDocument(base, ref, isRoot = false) {
|
|
135
|
+
const absoluteRef = this.resolveExternalRef(base, ref);
|
|
136
|
+
const cachedDocument = this.cache.get(absoluteRef);
|
|
137
|
+
if (cachedDocument) {
|
|
138
|
+
return cachedDocument;
|
|
139
|
+
}
|
|
140
|
+
const doc = this.loadExternalRef(absoluteRef).then((source) => {
|
|
141
|
+
return this.parseDocument(source, isRoot);
|
|
142
|
+
});
|
|
143
|
+
this.cache.set(absoluteRef, doc);
|
|
144
|
+
return doc;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.BaseResolver = BaseResolver;
|
|
148
|
+
function pushRef(head, node) {
|
|
149
|
+
return {
|
|
150
|
+
prev: head,
|
|
151
|
+
node,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function hasRef(head, node) {
|
|
155
|
+
while (head) {
|
|
156
|
+
if (head.node === node) {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
head = head.prev;
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
const unknownType = { name: 'unknown', properties: {} };
|
|
164
|
+
const resolvableScalarType = { name: 'scalar', properties: {} };
|
|
165
|
+
async function resolveDocument(opts) {
|
|
166
|
+
const { rootDocument, externalRefResolver, rootType } = opts;
|
|
167
|
+
const resolvedRefMap = new Map();
|
|
168
|
+
const seenNodes = new Set(); // format "${type}::${absoluteRef}${pointer}"
|
|
169
|
+
const resolvePromises = [];
|
|
170
|
+
resolveRefsInParallel(rootDocument.parsed, rootDocument, '#/', rootType);
|
|
171
|
+
let resolved;
|
|
172
|
+
do {
|
|
173
|
+
resolved = await Promise.all(resolvePromises);
|
|
174
|
+
} while (resolvePromises.length !== resolved.length);
|
|
175
|
+
return resolvedRefMap;
|
|
176
|
+
function resolveRefsInParallel(rootNode, rootNodeDocument, rootNodePointer, type) {
|
|
177
|
+
const rootNodeDocAbsoluteRef = rootNodeDocument.source.absoluteRef;
|
|
178
|
+
const anchorRefsMap = new Map();
|
|
179
|
+
walk(rootNode, type, rootNodeDocAbsoluteRef + rootNodePointer);
|
|
180
|
+
function walk(node, type, nodeAbsoluteRef) {
|
|
181
|
+
if (typeof node !== 'object' || node === null) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const nodeId = `${type.name}::${nodeAbsoluteRef}`;
|
|
185
|
+
if (seenNodes.has(nodeId)) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
seenNodes.add(nodeId);
|
|
189
|
+
const [_, anchor] = Object.entries(node).find(([key]) => key === '$anchor') || [];
|
|
190
|
+
if (anchor) {
|
|
191
|
+
anchorRefsMap.set(`#${anchor}`, node);
|
|
192
|
+
}
|
|
193
|
+
if (Array.isArray(node)) {
|
|
194
|
+
const itemsType = type.items;
|
|
195
|
+
// we continue resolving unknown types, but stop early on known scalars
|
|
196
|
+
if (itemsType === undefined && type !== unknownType && type !== types_1.SpecExtension) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const isTypeAFunction = typeof itemsType === 'function';
|
|
200
|
+
for (let i = 0; i < node.length; i++) {
|
|
201
|
+
const itemType = isTypeAFunction
|
|
202
|
+
? itemsType(node[i], (0, ref_utils_1.joinPointer)(nodeAbsoluteRef, i))
|
|
203
|
+
: itemsType;
|
|
204
|
+
// we continue resolving unknown types, but stop early on known scalars
|
|
205
|
+
if (itemType === undefined && type !== unknownType && type !== types_1.SpecExtension) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
walk(node[i], (0, types_1.isNamedType)(itemType) ? itemType : unknownType, (0, ref_utils_1.joinPointer)(nodeAbsoluteRef, i));
|
|
209
|
+
}
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
for (const propName of Object.keys(node)) {
|
|
213
|
+
let propValue = node[propName];
|
|
214
|
+
let propType = type.properties[propName];
|
|
215
|
+
if (propType === undefined)
|
|
216
|
+
propType = type.additionalProperties;
|
|
217
|
+
if (typeof propType === 'function')
|
|
218
|
+
propType = propType(propValue, propName);
|
|
219
|
+
if (propType === undefined)
|
|
220
|
+
propType = unknownType;
|
|
221
|
+
if (type.extensionsPrefix &&
|
|
222
|
+
propName.startsWith(type.extensionsPrefix) &&
|
|
223
|
+
propType === unknownType) {
|
|
224
|
+
propType = types_1.SpecExtension;
|
|
225
|
+
}
|
|
226
|
+
if (!(0, types_1.isNamedType)(propType) && propType?.directResolveAs) {
|
|
227
|
+
propType = propType.directResolveAs;
|
|
228
|
+
propValue = { $ref: propValue };
|
|
229
|
+
}
|
|
230
|
+
if (propType && propType.name === undefined && propType.resolvable !== false) {
|
|
231
|
+
propType = resolvableScalarType;
|
|
232
|
+
}
|
|
233
|
+
if (!(0, types_1.isNamedType)(propType) || typeof propValue !== 'object') {
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
walk(propValue, propType, (0, ref_utils_1.joinPointer)(nodeAbsoluteRef, (0, ref_utils_1.escapePointer)(propName)));
|
|
237
|
+
}
|
|
238
|
+
if ((0, ref_utils_1.isRef)(node)) {
|
|
239
|
+
const promise = followRef(rootNodeDocument, node, {
|
|
240
|
+
prev: null,
|
|
241
|
+
node,
|
|
242
|
+
}).then((resolvedRef) => {
|
|
243
|
+
if (resolvedRef.resolved) {
|
|
244
|
+
resolveRefsInParallel(resolvedRef.node, resolvedRef.document, resolvedRef.nodePointer, type);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
resolvePromises.push(promise);
|
|
248
|
+
}
|
|
249
|
+
// handle example.externalValue as reference
|
|
250
|
+
if ((0, ref_utils_1.isExternalValue)(node)) {
|
|
251
|
+
const promise = followRef(rootNodeDocument, { $ref: node.externalValue }, {
|
|
252
|
+
prev: null,
|
|
253
|
+
node,
|
|
254
|
+
}).then((resolvedRef) => {
|
|
255
|
+
if (resolvedRef.resolved) {
|
|
256
|
+
resolveRefsInParallel(resolvedRef.node, resolvedRef.document, resolvedRef.nodePointer, type);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
resolvePromises.push(promise);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
async function followRef(document, ref, refStack) {
|
|
263
|
+
if (hasRef(refStack.prev, ref)) {
|
|
264
|
+
throw new Error('Self-referencing circular pointer');
|
|
265
|
+
}
|
|
266
|
+
if ((0, ref_utils_1.isAnchor)(ref.$ref)) {
|
|
267
|
+
// Wait for all anchors in the document to be collected firstly.
|
|
268
|
+
await (0, utils_1.nextTick)();
|
|
269
|
+
const resolvedRef = {
|
|
270
|
+
resolved: true,
|
|
271
|
+
isRemote: false,
|
|
272
|
+
node: anchorRefsMap.get(ref.$ref),
|
|
273
|
+
document,
|
|
274
|
+
nodePointer: ref.$ref,
|
|
275
|
+
};
|
|
276
|
+
const refId = makeRefId(document.source.absoluteRef, ref.$ref);
|
|
277
|
+
resolvedRefMap.set(refId, resolvedRef);
|
|
278
|
+
return resolvedRef;
|
|
279
|
+
}
|
|
280
|
+
const { uri, pointer } = (0, ref_utils_1.parseRef)(ref.$ref);
|
|
281
|
+
const isRemote = uri !== null;
|
|
282
|
+
let targetDoc;
|
|
283
|
+
try {
|
|
284
|
+
targetDoc = isRemote
|
|
285
|
+
? (await externalRefResolver.resolveDocument(document.source.absoluteRef, uri))
|
|
286
|
+
: document;
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
const resolvedRef = {
|
|
290
|
+
resolved: false,
|
|
291
|
+
isRemote,
|
|
292
|
+
document: undefined,
|
|
293
|
+
error: error,
|
|
294
|
+
};
|
|
295
|
+
const refId = makeRefId(document.source.absoluteRef, ref.$ref);
|
|
296
|
+
resolvedRefMap.set(refId, resolvedRef);
|
|
297
|
+
return resolvedRef;
|
|
298
|
+
}
|
|
299
|
+
let resolvedRef = {
|
|
300
|
+
resolved: true,
|
|
301
|
+
document: targetDoc,
|
|
302
|
+
isRemote,
|
|
303
|
+
node: document.parsed,
|
|
304
|
+
nodePointer: '#/',
|
|
305
|
+
};
|
|
306
|
+
let target = targetDoc.parsed;
|
|
307
|
+
const segments = pointer;
|
|
308
|
+
for (const segment of segments) {
|
|
309
|
+
if (typeof target !== 'object') {
|
|
310
|
+
target = undefined;
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
else if (target[segment] !== undefined) {
|
|
314
|
+
target = target[segment];
|
|
315
|
+
resolvedRef.nodePointer = (0, ref_utils_1.joinPointer)(resolvedRef.nodePointer, (0, ref_utils_1.escapePointer)(segment));
|
|
316
|
+
}
|
|
317
|
+
else if ((0, ref_utils_1.isRef)(target)) {
|
|
318
|
+
resolvedRef = await followRef(targetDoc, target, pushRef(refStack, target));
|
|
319
|
+
targetDoc = resolvedRef.document || targetDoc;
|
|
320
|
+
if (typeof resolvedRef.node !== 'object') {
|
|
321
|
+
target = undefined;
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
target = resolvedRef.node[segment];
|
|
325
|
+
resolvedRef.nodePointer = (0, ref_utils_1.joinPointer)(resolvedRef.nodePointer, (0, ref_utils_1.escapePointer)(segment));
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
target = undefined;
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
resolvedRef.node = target;
|
|
333
|
+
resolvedRef.document = targetDoc;
|
|
334
|
+
const refId = makeRefId(document.source.absoluteRef, ref.$ref);
|
|
335
|
+
if (resolvedRef.document && (0, ref_utils_1.isRef)(target)) {
|
|
336
|
+
resolvedRef = await followRef(resolvedRef.document, target, pushRef(refStack, target));
|
|
337
|
+
}
|
|
338
|
+
resolvedRefMap.set(refId, resolvedRef);
|
|
339
|
+
return { ...resolvedRef };
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Location } from '../ref-utils';
|
|
2
|
+
import type { ErrorObject } from '@redocly/ajv/dist/2020';
|
|
3
|
+
import type { ResolveFn } from '../walk';
|
|
4
|
+
export declare function releaseAjvInstance(): void;
|
|
5
|
+
export declare function validateJsonSchema(data: any, schema: any, schemaLoc: Location, instancePath: string, resolve: ResolveFn, allowAdditionalProperties: boolean): {
|
|
6
|
+
valid: boolean;
|
|
7
|
+
errors: (ErrorObject & {
|
|
8
|
+
suggest?: string[];
|
|
9
|
+
})[];
|
|
10
|
+
};
|
package/lib/rules/ajv.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.releaseAjvInstance = releaseAjvInstance;
|
|
4
|
+
exports.validateJsonSchema = validateJsonSchema;
|
|
5
|
+
const _2020_1 = require("@redocly/ajv/dist/2020");
|
|
6
|
+
const ref_utils_1 = require("../ref-utils");
|
|
7
|
+
let ajvInstance = null;
|
|
8
|
+
function releaseAjvInstance() {
|
|
9
|
+
ajvInstance = null;
|
|
10
|
+
}
|
|
11
|
+
function getAjv(resolve, allowAdditionalProperties) {
|
|
12
|
+
if (!ajvInstance) {
|
|
13
|
+
ajvInstance = new _2020_1.default({
|
|
14
|
+
schemaId: '$id',
|
|
15
|
+
meta: true,
|
|
16
|
+
allErrors: true,
|
|
17
|
+
strictSchema: false,
|
|
18
|
+
inlineRefs: false,
|
|
19
|
+
validateSchema: false,
|
|
20
|
+
discriminator: true,
|
|
21
|
+
allowUnionTypes: true,
|
|
22
|
+
validateFormats: false, // TODO: fix it
|
|
23
|
+
defaultUnevaluatedProperties: allowAdditionalProperties,
|
|
24
|
+
loadSchemaSync(base, $ref, $id) {
|
|
25
|
+
const resolvedRef = resolve({ $ref }, base.split('#')[0]);
|
|
26
|
+
if (!resolvedRef || !resolvedRef.location)
|
|
27
|
+
return false;
|
|
28
|
+
return { $id: resolvedRef.location.source.absoluteRef + '#' + $id, ...resolvedRef.node };
|
|
29
|
+
},
|
|
30
|
+
logger: false,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return ajvInstance;
|
|
34
|
+
}
|
|
35
|
+
function getAjvValidator(schema, loc, resolve, allowAdditionalProperties) {
|
|
36
|
+
const ajv = getAjv(resolve, allowAdditionalProperties);
|
|
37
|
+
if (!ajv.getSchema(loc.absolutePointer)) {
|
|
38
|
+
ajv.addSchema({ $id: loc.absolutePointer, ...schema }, loc.absolutePointer);
|
|
39
|
+
}
|
|
40
|
+
return ajv.getSchema(loc.absolutePointer);
|
|
41
|
+
}
|
|
42
|
+
function validateJsonSchema(data, schema, schemaLoc, instancePath, resolve, allowAdditionalProperties) {
|
|
43
|
+
const validate = getAjvValidator(schema, schemaLoc, resolve, allowAdditionalProperties);
|
|
44
|
+
if (!validate)
|
|
45
|
+
return { valid: true, errors: [] }; // unresolved refs are reported
|
|
46
|
+
const valid = validate(data, {
|
|
47
|
+
instancePath,
|
|
48
|
+
parentData: { fake: {} },
|
|
49
|
+
parentDataProperty: 'fake',
|
|
50
|
+
rootData: {},
|
|
51
|
+
dynamicAnchors: {},
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
valid: !!valid,
|
|
55
|
+
errors: (validate.errors || []).map(beatifyErrorMessage),
|
|
56
|
+
};
|
|
57
|
+
function beatifyErrorMessage(error) {
|
|
58
|
+
let message = error.message;
|
|
59
|
+
const suggest = error.keyword === 'enum' ? error.params.allowedValues : undefined;
|
|
60
|
+
if (suggest) {
|
|
61
|
+
message += ` ${suggest.map((e) => `"${e}"`).join(', ')}`;
|
|
62
|
+
}
|
|
63
|
+
if (error.keyword === 'type') {
|
|
64
|
+
message = `type ${message}`;
|
|
65
|
+
}
|
|
66
|
+
const relativePath = error.instancePath.substring(instancePath.length + 1);
|
|
67
|
+
const propName = relativePath.substring(relativePath.lastIndexOf('/') + 1);
|
|
68
|
+
if (propName) {
|
|
69
|
+
message = `\`${propName}\` property ${message}`;
|
|
70
|
+
}
|
|
71
|
+
if (error.keyword === 'additionalProperties' || error.keyword === 'unevaluatedProperties') {
|
|
72
|
+
const property = error.params.additionalProperty || error.params.unevaluatedProperty;
|
|
73
|
+
message = `${message} \`${property}\``;
|
|
74
|
+
error.instancePath += '/' + (0, ref_utils_1.escapePointer)(property);
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
...error,
|
|
78
|
+
message,
|
|
79
|
+
suggest,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CriteriaUnique = void 0;
|
|
4
|
+
const CriteriaUnique = () => {
|
|
5
|
+
return {
|
|
6
|
+
FailureActionObject: {
|
|
7
|
+
enter(action, { report, location }) {
|
|
8
|
+
const criterias = action?.criteria;
|
|
9
|
+
if (!Array.isArray(criterias)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const seen = new Set();
|
|
13
|
+
for (const criteria of criterias) {
|
|
14
|
+
const key = JSON.stringify(criteria);
|
|
15
|
+
if (seen.has(key)) {
|
|
16
|
+
report({
|
|
17
|
+
message: 'The FailureAction criteria items must be unique.',
|
|
18
|
+
location: location.child(['criteria', criterias.indexOf(criteria)]),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
seen.add(key);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
SuccessActionObject: {
|
|
28
|
+
enter(action, { report, location }) {
|
|
29
|
+
const criterias = action?.criteria;
|
|
30
|
+
if (!Array.isArray(criterias)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const seen = new Set();
|
|
34
|
+
for (const criteria of criterias) {
|
|
35
|
+
const key = JSON.stringify(criteria);
|
|
36
|
+
if (seen.has(key)) {
|
|
37
|
+
report({
|
|
38
|
+
message: 'The SuccessAction criteria items must be unique.',
|
|
39
|
+
location: location.child(['criteria', criterias.indexOf(criteria)]),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
seen.add(key);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
Step: {
|
|
49
|
+
enter(step, { report, location }) {
|
|
50
|
+
const successCriterias = step?.successCriteria;
|
|
51
|
+
if (!Array.isArray(successCriterias)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const seen = new Set();
|
|
55
|
+
for (const criteria of successCriterias) {
|
|
56
|
+
const key = JSON.stringify(criteria);
|
|
57
|
+
if (seen.has(key)) {
|
|
58
|
+
report({
|
|
59
|
+
message: 'The Step SuccessCriteria items must be unique.',
|
|
60
|
+
location: location.child(['successCriteria', successCriterias.indexOf(criteria)]),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
seen.add(key);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
exports.CriteriaUnique = CriteriaUnique;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.preprocessors = exports.rules = void 0;
|
|
4
|
+
const struct_1 = require("../common/struct");
|
|
5
|
+
const assertions_1 = require("../common/assertions");
|
|
6
|
+
const sourceDescription_type_1 = require("../arazzo/sourceDescription-type");
|
|
7
|
+
const sourceDescriptions_not_empty_1 = require("./sourceDescriptions-not-empty");
|
|
8
|
+
const spot_supported_versions_1 = require("../spot/spot-supported-versions");
|
|
9
|
+
const workflowId_unique_1 = require("./workflowId-unique");
|
|
10
|
+
const stepId_unique_1 = require("./stepId-unique");
|
|
11
|
+
const sourceDescriptions_name_unique_1 = require("./sourceDescriptions-name-unique");
|
|
12
|
+
const workflow_dependsOn_1 = require("./workflow-dependsOn");
|
|
13
|
+
const parameters_unique_1 = require("./parameters-unique");
|
|
14
|
+
const step_onSuccess_unique_1 = require("./step-onSuccess-unique");
|
|
15
|
+
const step_onFailure_unique_1 = require("./step-onFailure-unique");
|
|
16
|
+
const requestBody_replacements_unique_1 = require("./requestBody-replacements-unique");
|
|
17
|
+
const no_criteria_xpath_1 = require("../spot/no-criteria-xpath");
|
|
18
|
+
const criteria_unique_1 = require("./criteria-unique");
|
|
19
|
+
exports.rules = {
|
|
20
|
+
struct: struct_1.Struct,
|
|
21
|
+
assertions: assertions_1.Assertions,
|
|
22
|
+
'sourceDescription-type': sourceDescription_type_1.SourceDescriptionType,
|
|
23
|
+
'spot-supported-versions': spot_supported_versions_1.SpotSupportedVersions,
|
|
24
|
+
'workflowId-unique': workflowId_unique_1.WorkflowIdUnique,
|
|
25
|
+
'stepId-unique': stepId_unique_1.StepIdUnique,
|
|
26
|
+
'sourceDescription-name-unique': sourceDescriptions_name_unique_1.SourceDescriptionsNameUnique,
|
|
27
|
+
'sourceDescriptions-not-empty': sourceDescriptions_not_empty_1.SourceDescriptionsNotEmpty,
|
|
28
|
+
'workflow-dependsOn': workflow_dependsOn_1.WorkflowDependsOn,
|
|
29
|
+
'parameters-unique': parameters_unique_1.ParametersUnique,
|
|
30
|
+
'step-onSuccess-unique': step_onSuccess_unique_1.StepOnSuccessUnique,
|
|
31
|
+
'step-onFailure-unique': step_onFailure_unique_1.StepOnFailureUnique,
|
|
32
|
+
'requestBody-replacements-unique': requestBody_replacements_unique_1.RequestBodyReplacementsUnique,
|
|
33
|
+
'no-criteria-xpath': no_criteria_xpath_1.NoCriteriaXpath,
|
|
34
|
+
'criteria-unique': criteria_unique_1.CriteriaUnique,
|
|
35
|
+
};
|
|
36
|
+
exports.preprocessors = {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParametersUnique = void 0;
|
|
4
|
+
const ParametersUnique = () => {
|
|
5
|
+
return {
|
|
6
|
+
Parameters: {
|
|
7
|
+
enter(parameters, { report, location }) {
|
|
8
|
+
if (!parameters)
|
|
9
|
+
return;
|
|
10
|
+
const seenParameters = new Set();
|
|
11
|
+
for (const parameter of parameters) {
|
|
12
|
+
if (seenParameters.has(parameter?.name)) {
|
|
13
|
+
report({
|
|
14
|
+
message: 'The parameter `name` must be unique amongst listed parameters.',
|
|
15
|
+
location: location.child([parameters.indexOf(parameter)]),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
if (seenParameters.has(parameter?.reference)) {
|
|
19
|
+
report({
|
|
20
|
+
message: 'The parameter `reference` must be unique amongst listed parameters.',
|
|
21
|
+
location: location.child([parameters.indexOf(parameter)]),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
parameter?.name
|
|
25
|
+
? seenParameters.add(parameter.name)
|
|
26
|
+
: seenParameters.add(parameter.reference);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
exports.ParametersUnique = ParametersUnique;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestBodyReplacementsUnique = void 0;
|
|
4
|
+
const RequestBodyReplacementsUnique = () => {
|
|
5
|
+
const seenReplacements = new Set();
|
|
6
|
+
return {
|
|
7
|
+
RequestBody: {
|
|
8
|
+
enter(requestBody, { report, location }) {
|
|
9
|
+
if (!requestBody.replacements)
|
|
10
|
+
return;
|
|
11
|
+
for (const replacement of requestBody.replacements) {
|
|
12
|
+
if (seenReplacements.has(replacement.target)) {
|
|
13
|
+
report({
|
|
14
|
+
message: 'Every `replacement` in `requestBody` must be unique.',
|
|
15
|
+
location: location.child([
|
|
16
|
+
'replacements',
|
|
17
|
+
requestBody.replacements.indexOf(replacement),
|
|
18
|
+
`target`,
|
|
19
|
+
]),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
seenReplacements.add(replacement.target);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
exports.RequestBodyReplacementsUnique = RequestBodyReplacementsUnique;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SourceDescriptionType = void 0;
|
|
4
|
+
const SourceDescriptionType = () => {
|
|
5
|
+
return {
|
|
6
|
+
SourceDescriptions: {
|
|
7
|
+
enter(sourceDescriptions, { report, location }) {
|
|
8
|
+
if (!sourceDescriptions.length)
|
|
9
|
+
return;
|
|
10
|
+
for (const sourceDescription of sourceDescriptions) {
|
|
11
|
+
if (!['openapi', 'arazzo'].includes(sourceDescription?.type)) {
|
|
12
|
+
report({
|
|
13
|
+
message: 'The `type` property of the `sourceDescription` object must be either `openapi` or `arazzo`.',
|
|
14
|
+
location: location.child([sourceDescriptions.indexOf(sourceDescription)]),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.SourceDescriptionType = SourceDescriptionType;
|