@redocly/openapi-core 1.0.0-beta.105 → 1.0.0-beta.108
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 +4 -4
- package/__tests__/utils.ts +5 -5
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
- package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
- package/lib/benchmark/utils.d.ts +2 -2
- package/lib/benchmark/utils.js +2 -2
- package/lib/bundle.d.ts +2 -2
- package/lib/bundle.js +7 -4
- package/lib/config/all.d.ts +2 -2
- package/lib/config/all.js +3 -3
- package/lib/config/builtIn.d.ts +2 -2
- package/lib/config/builtIn.js +2 -2
- package/lib/config/config-resolvers.d.ts +5 -5
- package/lib/config/config-resolvers.js +70 -49
- package/lib/config/config.d.ts +8 -10
- package/lib/config/config.js +10 -7
- package/lib/config/load.d.ts +7 -0
- package/lib/config/load.js +18 -10
- package/lib/config/minimal.d.ts +2 -2
- package/lib/config/minimal.js +5 -4
- package/lib/config/recommended.d.ts +2 -2
- package/lib/config/recommended.js +5 -4
- package/lib/config/rules.d.ts +3 -3
- package/lib/config/rules.js +1 -1
- package/lib/config/types.d.ts +23 -19
- package/lib/config/utils.d.ts +5 -5
- package/lib/config/utils.js +48 -31
- package/lib/decorators/common/registry-dependencies.js +1 -1
- package/lib/decorators/common/remove-x-internal.js +2 -2
- package/lib/env.d.ts +3 -0
- package/lib/env.js +8 -0
- package/lib/format/codeframes.js +16 -10
- package/lib/format/format.js +29 -27
- package/lib/index.d.ts +5 -5
- package/lib/index.js +4 -2
- package/lib/js-yaml/index.js +2 -6
- package/lib/lint.d.ts +2 -2
- package/lib/lint.js +16 -6
- package/lib/logger.d.ts +10 -0
- package/lib/logger.js +31 -0
- package/lib/output.d.ts +3 -0
- package/lib/output.js +9 -0
- package/lib/redocly/index.js +10 -9
- package/lib/redocly/registry-api-types.d.ts +28 -30
- package/lib/redocly/registry-api.d.ts +4 -3
- package/lib/redocly/registry-api.js +9 -4
- package/lib/ref-utils.js +2 -1
- package/lib/resolve.d.ts +1 -1
- package/lib/resolve.js +1 -1
- package/lib/rules/ajv.d.ts +1 -1
- package/lib/rules/ajv.js +7 -7
- package/lib/rules/common/assertions/asserts.js +4 -4
- package/lib/rules/common/assertions/index.js +1 -1
- package/lib/rules/common/info-license-url.d.ts +1 -1
- package/lib/rules/common/info-license-url.js +5 -10
- package/lib/rules/common/info-license.d.ts +2 -0
- package/lib/rules/common/info-license.js +17 -0
- package/lib/rules/common/no-enum-type-mismatch.js +1 -3
- package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
- package/lib/rules/common/no-invalid-schema-examples.js +3 -3
- package/lib/rules/common/operation-operationId.js +1 -1
- package/lib/rules/common/operation-security-defined.js +1 -1
- package/lib/rules/common/path-not-include-query.js +1 -1
- package/lib/rules/common/paths-kebab-case.js +4 -1
- package/lib/rules/common/spec.js +3 -3
- package/lib/rules/oas2/index.js +4 -4
- package/lib/rules/oas2/remove-unused-components.js +5 -5
- package/lib/rules/oas3/index.js +6 -6
- package/lib/rules/oas3/no-empty-servers.js +1 -1
- package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
- package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
- package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +4 -4
- package/lib/rules/oas3/no-unused-components.js +1 -1
- package/lib/rules/oas3/remove-unused-components.js +5 -5
- package/lib/rules/other/stats.js +43 -14
- package/lib/rules/utils.d.ts +3 -2
- package/lib/rules/utils.js +20 -5
- package/lib/types/index.d.ts +2 -2
- package/lib/types/redocly-yaml.js +9 -8
- package/lib/utils.d.ts +5 -0
- package/lib/utils.js +22 -5
- package/lib/visitors.d.ts +1 -1
- package/lib/visitors.js +2 -2
- package/lib/walk.d.ts +2 -1
- package/lib/walk.js +6 -3
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/bundle.test.ts.snap +141 -0
- package/src/__tests__/bundle.test.ts +68 -34
- package/src/__tests__/codeframes.test.ts +13 -14
- package/src/__tests__/js-yaml.test.ts +6 -4
- package/src/__tests__/lint.test.ts +74 -6
- package/src/__tests__/logger-browser.test.ts +53 -0
- package/src/__tests__/logger.test.ts +47 -0
- package/src/__tests__/login.test.ts +2 -2
- package/src/__tests__/normalizeVisitors.test.ts +4 -4
- package/src/__tests__/output-browser.test.ts +18 -0
- package/src/__tests__/output.test.ts +15 -0
- package/src/__tests__/ref-utils.test.ts +13 -13
- package/src/__tests__/resolve-http.test.ts +1 -1
- package/src/__tests__/resolve.test.ts +14 -11
- package/src/__tests__/utils-browser.test.ts +11 -0
- package/src/__tests__/utils.test.ts +7 -0
- package/src/__tests__/walk.test.ts +48 -56
- package/src/benchmark/benches/lint-with-many-rules.bench.ts +1 -1
- package/src/benchmark/benches/lint-with-nested-rule.bench.ts +1 -1
- package/src/benchmark/benches/lint-with-no-rules.bench.ts +1 -1
- package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +1 -2
- package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +1 -1
- package/src/benchmark/benches/recommended-oas3.bench.ts +3 -3
- package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
- package/src/benchmark/benchmark.js +9 -5
- package/src/benchmark/utils.ts +5 -5
- package/src/bundle.ts +24 -20
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +7 -5
- package/src/config/__tests__/config-resolvers.test.ts +123 -121
- package/src/config/__tests__/config.test.ts +111 -76
- package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +4 -2
- package/src/config/__tests__/fixtures/resolve-config/plugin.js +4 -1
- package/src/config/__tests__/load.test.ts +79 -1
- package/src/config/__tests__/resolve-plugins.test.ts +3 -3
- package/src/config/__tests__/utils.test.ts +83 -0
- package/src/config/all.ts +5 -6
- package/src/config/builtIn.ts +5 -5
- package/src/config/config-resolvers.ts +161 -96
- package/src/config/config.ts +15 -13
- package/src/config/load.ts +34 -11
- package/src/config/minimal.ts +7 -6
- package/src/config/recommended.ts +7 -6
- package/src/config/rules.ts +6 -6
- package/src/config/types.ts +28 -19
- package/src/config/utils.ts +78 -57
- package/src/decorators/__tests__/filter-out.test.ts +8 -4
- package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
- package/src/decorators/common/filters/filter-helper.ts +1 -1
- package/src/decorators/common/info-description-override.ts +1 -1
- package/src/decorators/common/operation-description-override.ts +1 -1
- package/src/decorators/common/registry-dependencies.ts +1 -1
- package/src/decorators/common/remove-x-internal.ts +4 -4
- package/src/decorators/common/tag-description-override.ts +1 -1
- package/src/env.ts +5 -0
- package/src/format/codeframes.ts +18 -12
- package/src/format/format.ts +37 -42
- package/src/index.ts +8 -7
- package/src/js-yaml/index.ts +4 -8
- package/src/lint.ts +22 -18
- package/src/logger.ts +34 -0
- package/src/oas-types.ts +1 -6
- package/src/output.ts +7 -0
- package/src/redocly/__tests__/redocly-client.test.ts +25 -19
- package/src/redocly/index.ts +12 -7
- package/src/redocly/registry-api-types.ts +27 -29
- package/src/redocly/registry-api.ts +22 -12
- package/src/ref-utils.ts +4 -3
- package/src/resolve.ts +11 -8
- package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
- package/src/rules/__tests__/utils.test.ts +160 -0
- package/src/rules/ajv.ts +7 -8
- package/src/rules/common/__tests__/info-description.test.ts +3 -3
- package/src/rules/common/__tests__/info-license.test.ts +2 -2
- package/src/rules/common/__tests__/license-url.test.ts +2 -2
- package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
- package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +8 -8
- package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
- package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
- package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
- package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
- package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
- package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
- package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
- package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
- package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
- package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
- package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
- package/src/rules/common/__tests__/paths-kebab-case.test.ts +15 -15
- package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
- package/src/rules/common/__tests__/spec.test.ts +2 -2
- package/src/rules/common/__tests__/tag-description.test.ts +2 -2
- package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
- package/src/rules/common/assertions/__tests__/asserts.test.ts +513 -130
- package/src/rules/common/assertions/asserts.ts +4 -4
- package/src/rules/common/assertions/index.ts +7 -7
- package/src/rules/common/info-license-url.ts +4 -9
- package/src/rules/common/info-license.ts +15 -0
- package/src/rules/common/no-ambiguous-paths.ts +1 -1
- package/src/rules/common/no-enum-type-mismatch.ts +12 -9
- package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
- package/src/rules/common/no-invalid-schema-examples.ts +4 -4
- package/src/rules/common/operation-operationId.ts +1 -1
- package/src/rules/common/operation-parameters-unique.ts +2 -2
- package/src/rules/common/operation-security-defined.ts +1 -1
- package/src/rules/common/path-not-include-query.ts +1 -1
- package/src/rules/common/path-params-defined.ts +1 -1
- package/src/rules/common/paths-kebab-case.ts +4 -1
- package/src/rules/common/scalar-property-missing-example.ts +1 -1
- package/src/rules/common/spec.ts +12 -9
- package/src/rules/no-unresolved-refs.ts +1 -1
- package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
- package/src/rules/oas2/__tests__/spec/info.test.ts +12 -12
- package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
- package/src/rules/oas2/__tests__/spec/paths.test.ts +10 -10
- package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +6 -2
- package/src/rules/oas2/__tests__/spec/utils.ts +6 -6
- package/src/rules/oas2/index.ts +3 -3
- package/src/rules/oas2/remove-unused-components.ts +14 -9
- package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
- package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
- package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +13 -13
- package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
- package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
- package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
- package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
- package/src/rules/oas3/__tests__/spec/info.test.ts +12 -12
- package/src/rules/oas3/__tests__/spec/operation.test.ts +8 -8
- package/src/rules/oas3/__tests__/spec/paths.test.ts +10 -10
- package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +12 -12
- package/src/rules/oas3/__tests__/spec/servers.test.ts +15 -15
- package/src/rules/oas3/__tests__/spec/spec.test.ts +6 -6
- package/src/rules/oas3/__tests__/spec/utils.ts +6 -6
- package/src/rules/oas3/index.ts +5 -5
- package/src/rules/oas3/no-empty-servers.ts +1 -1
- package/src/rules/oas3/no-invalid-media-type-examples.ts +14 -6
- package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +10 -11
- package/src/rules/oas3/no-unused-components.ts +1 -1
- package/src/rules/oas3/remove-unused-components.ts +21 -10
- package/src/rules/other/stats.ts +46 -17
- package/src/rules/utils.ts +20 -4
- package/src/types/index.ts +5 -5
- package/src/types/redocly-yaml.ts +9 -8
- package/src/typings/common.ts +9 -1
- package/src/typings/openapi.ts +1 -1
- package/src/utils.ts +26 -3
- package/src/visitors.ts +9 -9
- package/src/walk.ts +15 -11
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/common/license-url.d.ts +0 -2
- package/lib/rules/common/license-url.js +0 -12
- package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
- package/src/rules/common/license-url.ts +0 -10
package/lib/rules/ajv.js
CHANGED
|
@@ -8,7 +8,7 @@ function releaseAjvInstance() {
|
|
|
8
8
|
ajvInstance = null;
|
|
9
9
|
}
|
|
10
10
|
exports.releaseAjvInstance = releaseAjvInstance;
|
|
11
|
-
function getAjv(resolve,
|
|
11
|
+
function getAjv(resolve, allowAdditionalProperties) {
|
|
12
12
|
if (!ajvInstance) {
|
|
13
13
|
ajvInstance = new ajv_1.default({
|
|
14
14
|
schemaId: '$id',
|
|
@@ -20,7 +20,7 @@ function getAjv(resolve, disallowAdditionalProperties) {
|
|
|
20
20
|
discriminator: true,
|
|
21
21
|
allowUnionTypes: true,
|
|
22
22
|
validateFormats: false,
|
|
23
|
-
defaultAdditionalProperties:
|
|
23
|
+
defaultAdditionalProperties: allowAdditionalProperties,
|
|
24
24
|
loadSchemaSync(base, $ref) {
|
|
25
25
|
const resolvedRef = resolve({ $ref }, base.split('#')[0]);
|
|
26
26
|
if (!resolvedRef || !resolvedRef.location)
|
|
@@ -32,15 +32,15 @@ function getAjv(resolve, disallowAdditionalProperties) {
|
|
|
32
32
|
}
|
|
33
33
|
return ajvInstance;
|
|
34
34
|
}
|
|
35
|
-
function getAjvValidator(schema, loc, resolve,
|
|
36
|
-
const ajv = getAjv(resolve,
|
|
35
|
+
function getAjvValidator(schema, loc, resolve, allowAdditionalProperties) {
|
|
36
|
+
const ajv = getAjv(resolve, allowAdditionalProperties);
|
|
37
37
|
if (!ajv.getSchema(loc.absolutePointer)) {
|
|
38
38
|
ajv.addSchema(Object.assign({ $id: loc.absolutePointer }, schema), loc.absolutePointer);
|
|
39
39
|
}
|
|
40
40
|
return ajv.getSchema(loc.absolutePointer);
|
|
41
41
|
}
|
|
42
|
-
function validateJsonSchema(data, schema, schemaLoc, instancePath, resolve,
|
|
43
|
-
const validate = getAjvValidator(schema, schemaLoc, resolve,
|
|
42
|
+
function validateJsonSchema(data, schema, schemaLoc, instancePath, resolve, allowAdditionalProperties) {
|
|
43
|
+
const validate = getAjvValidator(schema, schemaLoc, resolve, allowAdditionalProperties);
|
|
44
44
|
if (!validate)
|
|
45
45
|
return { valid: true, errors: [] }; // unresolved refs are reported
|
|
46
46
|
const valid = validate(data, {
|
|
@@ -56,7 +56,7 @@ function validateJsonSchema(data, schema, schemaLoc, instancePath, resolve, disa
|
|
|
56
56
|
};
|
|
57
57
|
function beatifyErrorMessage(error) {
|
|
58
58
|
let message = error.message;
|
|
59
|
-
|
|
59
|
+
const suggest = error.keyword === 'enum' ? error.params.allowedValues : undefined;
|
|
60
60
|
if (suggest) {
|
|
61
61
|
message += ` ${suggest.map((e) => `"${e}"`).join(', ')}`;
|
|
62
62
|
}
|
|
@@ -35,7 +35,7 @@ exports.asserts = {
|
|
|
35
35
|
return { isValid: true }; // property doesn't exist, no need to lint it with this assert
|
|
36
36
|
const values = utils_1.isString(value) ? [value] : value;
|
|
37
37
|
const regx = utils_2.regexFromString(condition);
|
|
38
|
-
for (
|
|
38
|
+
for (const _val of values) {
|
|
39
39
|
if (!(regx === null || regx === void 0 ? void 0 : regx.test(_val))) {
|
|
40
40
|
return { isValid: false, location: utils_1.isString(value) ? baseLocation : baseLocation.key() };
|
|
41
41
|
}
|
|
@@ -46,7 +46,7 @@ exports.asserts = {
|
|
|
46
46
|
if (typeof value === 'undefined')
|
|
47
47
|
return { isValid: true }; // property doesn't exist, no need to lint it with this assert
|
|
48
48
|
const values = utils_1.isString(value) ? [value] : value;
|
|
49
|
-
for (
|
|
49
|
+
for (const _val of values) {
|
|
50
50
|
if (!condition.includes(_val)) {
|
|
51
51
|
return {
|
|
52
52
|
isValid: false,
|
|
@@ -72,7 +72,7 @@ exports.asserts = {
|
|
|
72
72
|
if (typeof value === 'undefined')
|
|
73
73
|
return { isValid: true }; // property doesn't exist, no need to lint it with this assert
|
|
74
74
|
const values = utils_1.isString(value) ? [value] : value;
|
|
75
|
-
for (
|
|
75
|
+
for (const _val of values) {
|
|
76
76
|
if (condition.includes(_val)) {
|
|
77
77
|
return {
|
|
78
78
|
isValid: false,
|
|
@@ -104,7 +104,7 @@ exports.asserts = {
|
|
|
104
104
|
if (typeof value === 'undefined')
|
|
105
105
|
return { isValid: true }; // property doesn't exist, no need to lint it with this assert
|
|
106
106
|
const values = utils_1.isString(value) ? [value] : value;
|
|
107
|
-
for (
|
|
107
|
+
for (const _val of values) {
|
|
108
108
|
let matchCase = false;
|
|
109
109
|
switch (condition) {
|
|
110
110
|
case 'camelCase':
|
|
@@ -4,7 +4,7 @@ exports.Assertions = void 0;
|
|
|
4
4
|
const asserts_1 = require("./asserts");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
6
|
const Assertions = (opts) => {
|
|
7
|
-
|
|
7
|
+
const visitors = [];
|
|
8
8
|
// As 'Assertions' has an array of asserts,
|
|
9
9
|
// that array spreads into an 'opts' object on init rules phase here
|
|
10
10
|
// https://github.com/Redocly/redocly-cli/blob/master/packages/core/src/config/config.ts#L311
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const InfoLicenseUrl: Oas3Rule | Oas2Rule;
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.InfoLicenseUrl = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
const
|
|
5
|
+
const InfoLicenseUrl = () => {
|
|
6
6
|
return {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
report({
|
|
10
|
-
message: utils_1.missingRequiredField('Info', 'license'),
|
|
11
|
-
location: { reportOnKey: true }
|
|
12
|
-
});
|
|
13
|
-
}
|
|
7
|
+
License(license, ctx) {
|
|
8
|
+
utils_1.validateDefinedAndNonEmpty('url', license, ctx);
|
|
14
9
|
},
|
|
15
10
|
};
|
|
16
11
|
};
|
|
17
|
-
exports.
|
|
12
|
+
exports.InfoLicenseUrl = InfoLicenseUrl;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InfoLicense = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const InfoLicense = () => {
|
|
6
|
+
return {
|
|
7
|
+
Info(info, { report }) {
|
|
8
|
+
if (!info.license) {
|
|
9
|
+
report({
|
|
10
|
+
message: utils_1.missingRequiredField('Info', 'license'),
|
|
11
|
+
location: { reportOnKey: true },
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.InfoLicense = InfoLicense;
|
|
@@ -28,14 +28,12 @@ const NoEnumTypeMismatch = () => {
|
|
|
28
28
|
if (mismatchedResults[enumValue].length !== schema.type.length)
|
|
29
29
|
delete mismatchedResults[enumValue];
|
|
30
30
|
}
|
|
31
|
-
;
|
|
32
31
|
for (const mismatchedKey of Object.keys(mismatchedResults)) {
|
|
33
32
|
report({
|
|
34
|
-
message: `Enum value \`${mismatchedKey}\` must be of
|
|
33
|
+
message: `Enum value \`${mismatchedKey}\` must be of allowed types: \`${schema.type}\`.`,
|
|
35
34
|
location: location.child(['enum', schema.enum.indexOf(mismatchedKey)]),
|
|
36
35
|
});
|
|
37
36
|
}
|
|
38
|
-
;
|
|
39
37
|
}
|
|
40
38
|
},
|
|
41
39
|
};
|
|
@@ -4,17 +4,17 @@ exports.NoInvalidParameterExamples = void 0;
|
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const NoInvalidParameterExamples = (opts) => {
|
|
6
6
|
var _a;
|
|
7
|
-
const
|
|
7
|
+
const allowAdditionalProperties = (_a = utils_1.getAdditionalPropertiesOption(opts)) !== null && _a !== void 0 ? _a : false;
|
|
8
8
|
return {
|
|
9
9
|
Parameter: {
|
|
10
10
|
leave(parameter, ctx) {
|
|
11
11
|
if (parameter.example) {
|
|
12
|
-
utils_1.validateExample(parameter.example, parameter.schema, ctx.location.child('example'), ctx,
|
|
12
|
+
utils_1.validateExample(parameter.example, parameter.schema, ctx.location.child('example'), ctx, allowAdditionalProperties);
|
|
13
13
|
}
|
|
14
14
|
if (parameter.examples) {
|
|
15
15
|
for (const [key, example] of Object.entries(parameter.examples)) {
|
|
16
16
|
if ('value' in example) {
|
|
17
|
-
utils_1.validateExample(example.value, parameter.schema, ctx.location.child(['examples', key]), ctx,
|
|
17
|
+
utils_1.validateExample(example.value, parameter.schema, ctx.location.child(['examples', key]), ctx, true);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -4,17 +4,17 @@ exports.NoInvalidSchemaExamples = void 0;
|
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const NoInvalidSchemaExamples = (opts) => {
|
|
6
6
|
var _a;
|
|
7
|
-
const
|
|
7
|
+
const allowAdditionalProperties = (_a = utils_1.getAdditionalPropertiesOption(opts)) !== null && _a !== void 0 ? _a : false;
|
|
8
8
|
return {
|
|
9
9
|
Schema: {
|
|
10
10
|
leave(schema, ctx) {
|
|
11
11
|
if (schema.examples) {
|
|
12
12
|
for (const example of schema.examples) {
|
|
13
|
-
utils_1.validateExample(example, schema, ctx.location.child(['examples', schema.examples.indexOf(example)]), ctx,
|
|
13
|
+
utils_1.validateExample(example, schema, ctx.location.child(['examples', schema.examples.indexOf(example)]), ctx, allowAdditionalProperties);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
if (schema.example) {
|
|
17
|
-
utils_1.validateExample(schema.example, schema, ctx.location.child('example'), ctx,
|
|
17
|
+
utils_1.validateExample(schema.example, schema, ctx.location.child('example'), ctx, true);
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OperationSecurityDefined = void 0;
|
|
4
4
|
const OperationSecurityDefined = () => {
|
|
5
|
-
|
|
5
|
+
const referencedSchemes = new Map();
|
|
6
6
|
return {
|
|
7
7
|
DefinitionRoot: {
|
|
8
8
|
leave(_, { report }) {
|
|
@@ -4,7 +4,10 @@ exports.PathsKebabCase = void 0;
|
|
|
4
4
|
const PathsKebabCase = () => {
|
|
5
5
|
return {
|
|
6
6
|
PathItem(_path, { report, key }) {
|
|
7
|
-
const segments = key
|
|
7
|
+
const segments = key
|
|
8
|
+
.substr(1)
|
|
9
|
+
.split('/')
|
|
10
|
+
.filter((s) => s !== ''); // filter out empty segments
|
|
8
11
|
if (!segments.every((segment) => /^{.+}$/.test(segment) || /^[a-z0-9-.]+$/.test(segment))) {
|
|
9
12
|
report({
|
|
10
13
|
message: `\`${key}\` does not use kebab-case.`,
|
package/lib/rules/common/spec.js
CHANGED
|
@@ -27,7 +27,7 @@ const OasSpec = () => {
|
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
const required = typeof type.required === 'function' ? type.required(node, key) : type.required;
|
|
30
|
-
for (
|
|
30
|
+
for (const propName of required || []) {
|
|
31
31
|
if (!node.hasOwnProperty(propName)) {
|
|
32
32
|
report({
|
|
33
33
|
message: `The field \`${propName}\` must be present on this level.`,
|
|
@@ -45,14 +45,14 @@ const OasSpec = () => {
|
|
|
45
45
|
}
|
|
46
46
|
report({
|
|
47
47
|
message: `The field \`${propName}\` is not allowed here.`,
|
|
48
|
-
location: location.child([propName]).key()
|
|
48
|
+
location: location.child([propName]).key(),
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
const requiredOneOf = type.requiredOneOf || null;
|
|
53
53
|
if (requiredOneOf) {
|
|
54
54
|
let hasProperty = false;
|
|
55
|
-
for (
|
|
55
|
+
for (const propName of requiredOneOf || []) {
|
|
56
56
|
if (node.hasOwnProperty(propName)) {
|
|
57
57
|
hasProperty = true;
|
|
58
58
|
}
|
package/lib/rules/oas2/index.js
CHANGED
|
@@ -6,8 +6,8 @@ const no_invalid_schema_examples_1 = require("../common/no-invalid-schema-exampl
|
|
|
6
6
|
const no_invalid_parameter_examples_1 = require("../common/no-invalid-parameter-examples");
|
|
7
7
|
const info_description_1 = require("../common/info-description");
|
|
8
8
|
const info_contact_1 = require("../common/info-contact");
|
|
9
|
+
const info_license_1 = require("../common/info-license");
|
|
9
10
|
const info_license_url_1 = require("../common/info-license-url");
|
|
10
|
-
const license_url_1 = require("../common/license-url");
|
|
11
11
|
const boolean_parameter_prefixes_1 = require("./boolean-parameter-prefixes");
|
|
12
12
|
const tag_description_1 = require("../common/tag-description");
|
|
13
13
|
const tags_alphabetical_1 = require("../common/tags-alphabetical");
|
|
@@ -48,8 +48,8 @@ exports.rules = {
|
|
|
48
48
|
'no-invalid-parameter-examples': no_invalid_parameter_examples_1.NoInvalidParameterExamples,
|
|
49
49
|
'info-description': info_description_1.InfoDescription,
|
|
50
50
|
'info-contact': info_contact_1.InfoContact,
|
|
51
|
-
'info-license':
|
|
52
|
-
'info-license-url':
|
|
51
|
+
'info-license': info_license_1.InfoLicense,
|
|
52
|
+
'info-license-url': info_license_url_1.InfoLicenseUrl,
|
|
53
53
|
'tag-description': tag_description_1.TagDescription,
|
|
54
54
|
'tags-alphabetical': tags_alphabetical_1.TagsAlphabetical,
|
|
55
55
|
'paths-kebab-case': paths_kebab_case_1.PathsKebabCase,
|
|
@@ -58,7 +58,7 @@ exports.rules = {
|
|
|
58
58
|
'no-path-trailing-slash': no_path_trailing_slash_1.NoPathTrailingSlash,
|
|
59
59
|
'operation-2xx-response': operation_2xx_response_1.Operation2xxResponse,
|
|
60
60
|
'operation-4xx-response': operation_4xx_response_1.Operation4xxResponse,
|
|
61
|
-
|
|
61
|
+
assertions: assertions_1.Assertions,
|
|
62
62
|
'operation-operationId-unique': operation_operationId_unique_1.OperationIdUnique,
|
|
63
63
|
'operation-parameters-unique': operation_parameters_unique_1.OperationParametersUnique,
|
|
64
64
|
'path-parameters-defined': path_params_defined_1.PathParamsDefined,
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RemoveUnusedComponents = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const RemoveUnusedComponents = () => {
|
|
6
|
-
|
|
6
|
+
const components = new Map();
|
|
7
7
|
function registerComponent(location, componentType, name) {
|
|
8
8
|
var _a;
|
|
9
9
|
components.set(location.absolutePointer, {
|
|
@@ -24,14 +24,14 @@ const RemoveUnusedComponents = () => {
|
|
|
24
24
|
name: key.toString(),
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
}
|
|
27
|
+
},
|
|
28
28
|
},
|
|
29
29
|
DefinitionRoot: {
|
|
30
30
|
leave(root, ctx) {
|
|
31
31
|
const data = ctx.getVisitorData();
|
|
32
32
|
data.removedCount = 0;
|
|
33
|
-
|
|
34
|
-
components.forEach(usageInfo => {
|
|
33
|
+
const rootComponents = new Set();
|
|
34
|
+
components.forEach((usageInfo) => {
|
|
35
35
|
const { used, name, componentType } = usageInfo;
|
|
36
36
|
if (!used && componentType) {
|
|
37
37
|
rootComponents.add(componentType);
|
|
@@ -67,7 +67,7 @@ const RemoveUnusedComponents = () => {
|
|
|
67
67
|
SecurityScheme(_securityScheme, { location, key }) {
|
|
68
68
|
registerComponent(location, 'securityDefinitions', key.toString());
|
|
69
69
|
},
|
|
70
|
-
}
|
|
70
|
+
},
|
|
71
71
|
};
|
|
72
72
|
};
|
|
73
73
|
exports.RemoveUnusedComponents = RemoveUnusedComponents;
|
package/lib/rules/oas3/index.js
CHANGED
|
@@ -20,13 +20,13 @@ const no_server_trailing_slash_1 = require("./no-server-trailing-slash");
|
|
|
20
20
|
const info_description_1 = require("../common/info-description");
|
|
21
21
|
const tag_description_1 = require("../common/tag-description");
|
|
22
22
|
const info_contact_1 = require("../common/info-contact");
|
|
23
|
+
const info_license_1 = require("../common/info-license");
|
|
23
24
|
const info_license_url_1 = require("../common/info-license-url");
|
|
24
25
|
const operation_description_1 = require("../common/operation-description");
|
|
25
26
|
const no_unused_components_1 = require("./no-unused-components");
|
|
26
27
|
const path_not_include_query_1 = require("../common/path-not-include-query");
|
|
27
28
|
const parameter_description_1 = require("../common/parameter-description");
|
|
28
29
|
const operation_singular_tag_1 = require("../common/operation-singular-tag");
|
|
29
|
-
const license_url_1 = require("../common/license-url");
|
|
30
30
|
const operation_security_defined_1 = require("../common/operation-security-defined");
|
|
31
31
|
const no_unresolved_refs_1 = require("../no-unresolved-refs");
|
|
32
32
|
const boolean_parameter_prefixes_1 = require("./boolean-parameter-prefixes");
|
|
@@ -39,7 +39,7 @@ const no_undefined_server_variable_1 = require("./no-undefined-server-variable")
|
|
|
39
39
|
const operation_operationId_1 = require("../common/operation-operationId");
|
|
40
40
|
const operation_summary_1 = require("../common/operation-summary");
|
|
41
41
|
const no_ambiguous_paths_1 = require("../common/no-ambiguous-paths");
|
|
42
|
-
const
|
|
42
|
+
const no_server_variables_empty_enum_1 = require("./no-server-variables-empty-enum");
|
|
43
43
|
const no_http_verbs_in_paths_1 = require("../common/no-http-verbs-in-paths");
|
|
44
44
|
const request_mime_type_1 = require("./request-mime-type");
|
|
45
45
|
const response_mime_type_1 = require("./response-mime-type");
|
|
@@ -54,11 +54,11 @@ exports.rules = {
|
|
|
54
54
|
spec: spec_1.OasSpec,
|
|
55
55
|
'info-description': info_description_1.InfoDescription,
|
|
56
56
|
'info-contact': info_contact_1.InfoContact,
|
|
57
|
-
'info-license':
|
|
58
|
-
'info-license-url':
|
|
57
|
+
'info-license': info_license_1.InfoLicense,
|
|
58
|
+
'info-license-url': info_license_url_1.InfoLicenseUrl,
|
|
59
59
|
'operation-2xx-response': operation_2xx_response_1.Operation2xxResponse,
|
|
60
60
|
'operation-4xx-response': operation_4xx_response_1.Operation4xxResponse,
|
|
61
|
-
|
|
61
|
+
assertions: assertions_1.Assertions,
|
|
62
62
|
'operation-operationId-unique': operation_operationId_unique_1.OperationIdUnique,
|
|
63
63
|
'operation-parameters-unique': operation_parameters_unique_1.OperationParametersUnique,
|
|
64
64
|
'path-parameters-defined': path_params_defined_1.PathParamsDefined,
|
|
@@ -90,7 +90,7 @@ exports.rules = {
|
|
|
90
90
|
'no-identical-paths': no_identical_paths_1.NoIdenticalPaths,
|
|
91
91
|
'no-ambiguous-paths': no_ambiguous_paths_1.NoAmbiguousPaths,
|
|
92
92
|
'no-undefined-server-variable': no_undefined_server_variable_1.NoUndefinedServerVariable,
|
|
93
|
-
'no-
|
|
93
|
+
'no-server-variables-empty-enum': no_server_variables_empty_enum_1.NoServerVariablesEmptyEnum,
|
|
94
94
|
'no-http-verbs-in-paths': no_http_verbs_in_paths_1.NoHttpVerbsInPaths,
|
|
95
95
|
'path-excludes-patterns': path_excludes_patterns_1.PathExcludesPatterns,
|
|
96
96
|
'request-mime-type': request_mime_type_1.RequestMimeType,
|
|
@@ -5,7 +5,7 @@ const ref_utils_1 = require("../../ref-utils");
|
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const ValidContentExamples = (opts) => {
|
|
7
7
|
var _a;
|
|
8
|
-
const
|
|
8
|
+
const allowAdditionalProperties = (_a = utils_1.getAdditionalPropertiesOption(opts)) !== null && _a !== void 0 ? _a : false;
|
|
9
9
|
return {
|
|
10
10
|
MediaType: {
|
|
11
11
|
leave(mediaType, ctx) {
|
|
@@ -28,7 +28,7 @@ const ValidContentExamples = (opts) => {
|
|
|
28
28
|
location = isMultiple ? resolved.location.child('value') : resolved.location;
|
|
29
29
|
example = resolved.node;
|
|
30
30
|
}
|
|
31
|
-
utils_1.validateExample(isMultiple ? example.value : example, mediaType.schema, location, ctx,
|
|
31
|
+
utils_1.validateExample(isMultiple ? example.value : example, mediaType.schema, location, ctx, allowAdditionalProperties);
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
},
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.NoServerVariablesEmptyEnum = void 0;
|
|
4
4
|
var enumError;
|
|
5
5
|
(function (enumError) {
|
|
6
6
|
enumError["empty"] = "empty";
|
|
7
7
|
enumError["invalidDefaultValue"] = "invalidDefaultValue";
|
|
8
8
|
})(enumError || (enumError = {}));
|
|
9
|
-
const
|
|
9
|
+
const NoServerVariablesEmptyEnum = () => {
|
|
10
10
|
return {
|
|
11
11
|
DefinitionRoot(root, { report, location }) {
|
|
12
12
|
if (!root.servers || root.servers.length === 0)
|
|
@@ -43,13 +43,13 @@ const NoEmptyEnumServers = () => {
|
|
|
43
43
|
},
|
|
44
44
|
};
|
|
45
45
|
};
|
|
46
|
-
exports.
|
|
46
|
+
exports.NoServerVariablesEmptyEnum = NoServerVariablesEmptyEnum;
|
|
47
47
|
function checkEnumVariables(server) {
|
|
48
48
|
var _a;
|
|
49
49
|
if (server.variables && Object.keys(server.variables).length === 0)
|
|
50
50
|
return;
|
|
51
51
|
const errors = [];
|
|
52
|
-
for (
|
|
52
|
+
for (const variable in server.variables) {
|
|
53
53
|
const serverVariable = server.variables[variable];
|
|
54
54
|
if (!serverVariable.enum)
|
|
55
55
|
continue;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NoUnusedComponents = void 0;
|
|
4
4
|
const NoUnusedComponents = () => {
|
|
5
|
-
|
|
5
|
+
const components = new Map();
|
|
6
6
|
function registerComponent(location, name) {
|
|
7
7
|
var _a;
|
|
8
8
|
components.set(location.absolutePointer, {
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RemoveUnusedComponents = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const RemoveUnusedComponents = () => {
|
|
6
|
-
|
|
6
|
+
const components = new Map();
|
|
7
7
|
function registerComponent(location, componentType, name) {
|
|
8
8
|
var _a;
|
|
9
9
|
components.set(location.absolutePointer, {
|
|
@@ -24,16 +24,16 @@ const RemoveUnusedComponents = () => {
|
|
|
24
24
|
name: key.toString(),
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
}
|
|
27
|
+
},
|
|
28
28
|
},
|
|
29
29
|
DefinitionRoot: {
|
|
30
30
|
leave(root, ctx) {
|
|
31
31
|
const data = ctx.getVisitorData();
|
|
32
32
|
data.removedCount = 0;
|
|
33
|
-
components.forEach(usageInfo => {
|
|
33
|
+
components.forEach((usageInfo) => {
|
|
34
34
|
const { used, componentType, name } = usageInfo;
|
|
35
|
-
if (!used && componentType) {
|
|
36
|
-
|
|
35
|
+
if (!used && componentType && root.components) {
|
|
36
|
+
const componentChild = root.components[componentType];
|
|
37
37
|
delete componentChild[name];
|
|
38
38
|
data.removedCount++;
|
|
39
39
|
if (utils_1.isEmptyObject(componentChild)) {
|
package/lib/rules/other/stats.js
CHANGED
|
@@ -3,10 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Stats = void 0;
|
|
4
4
|
const Stats = (statsAccumulator) => {
|
|
5
5
|
return {
|
|
6
|
-
ExternalDocs: {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
ExternalDocs: {
|
|
7
|
+
leave() {
|
|
8
|
+
statsAccumulator.externalDocs.total++;
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
ref: {
|
|
12
|
+
enter(ref) {
|
|
13
|
+
statsAccumulator.refs.items.add(ref['$ref']);
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
Tag: {
|
|
17
|
+
leave(tag) {
|
|
18
|
+
statsAccumulator.tags.items.add(tag.name);
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
Link: {
|
|
22
|
+
leave(link) {
|
|
23
|
+
statsAccumulator.links.items.add(link.operationId);
|
|
24
|
+
},
|
|
25
|
+
},
|
|
10
26
|
DefinitionRoot: {
|
|
11
27
|
leave() {
|
|
12
28
|
statsAccumulator.parameters.total = statsAccumulator.parameters.items.size;
|
|
@@ -18,27 +34,40 @@ const Stats = (statsAccumulator) => {
|
|
|
18
34
|
WebhooksMap: {
|
|
19
35
|
Operation: {
|
|
20
36
|
leave(operation) {
|
|
21
|
-
operation.tags.forEach((tag) => {
|
|
22
|
-
|
|
23
|
-
|
|
37
|
+
operation.tags.forEach((tag) => {
|
|
38
|
+
statsAccumulator.tags.items.add(tag);
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
},
|
|
24
42
|
},
|
|
25
43
|
PathMap: {
|
|
26
44
|
PathItem: {
|
|
27
|
-
leave() {
|
|
45
|
+
leave() {
|
|
46
|
+
statsAccumulator.pathItems.total++;
|
|
47
|
+
},
|
|
28
48
|
Operation: {
|
|
29
49
|
leave(operation) {
|
|
30
50
|
statsAccumulator.operations.total++;
|
|
31
|
-
operation.tags &&
|
|
32
|
-
|
|
51
|
+
operation.tags &&
|
|
52
|
+
operation.tags.forEach((tag) => {
|
|
53
|
+
statsAccumulator.tags.items.add(tag);
|
|
54
|
+
});
|
|
55
|
+
},
|
|
33
56
|
},
|
|
34
|
-
Parameter: {
|
|
57
|
+
Parameter: {
|
|
58
|
+
leave(parameter) {
|
|
35
59
|
statsAccumulator.parameters.items.add(parameter.name);
|
|
36
|
-
}
|
|
60
|
+
},
|
|
61
|
+
},
|
|
37
62
|
},
|
|
38
63
|
},
|
|
39
64
|
NamedSchemas: {
|
|
40
|
-
Schema: {
|
|
41
|
-
|
|
65
|
+
Schema: {
|
|
66
|
+
leave() {
|
|
67
|
+
statsAccumulator.schemas.total++;
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
42
71
|
};
|
|
43
72
|
};
|
|
44
73
|
exports.Stats = Stats;
|
package/lib/rules/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { UserContext } from '../walk';
|
|
2
2
|
import { Location } from '../ref-utils';
|
|
3
3
|
import { Oas3Schema, Referenced } from '../typings/openapi';
|
|
4
|
-
export declare function oasTypeOf(value: unknown): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "
|
|
4
|
+
export declare function oasTypeOf(value: unknown): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "null" | "integer" | "array";
|
|
5
5
|
/**
|
|
6
6
|
* Checks if value matches specified JSON schema type
|
|
7
7
|
*
|
|
@@ -14,4 +14,5 @@ export declare function missingRequiredField(type: string, field: string): strin
|
|
|
14
14
|
export declare function fieldNonEmpty(type: string, field: string): string;
|
|
15
15
|
export declare function validateDefinedAndNonEmpty(fieldName: string, value: any, ctx: UserContext): void;
|
|
16
16
|
export declare function getSuggest(given: string, variants: string[]): string[];
|
|
17
|
-
export declare function validateExample(example: any, schema: Referenced<Oas3Schema>, dataLoc: Location, { resolve, location, report }: UserContext,
|
|
17
|
+
export declare function validateExample(example: any, schema: Referenced<Oas3Schema>, dataLoc: Location, { resolve, location, report }: UserContext, allowAdditionalProperties: boolean): void;
|
|
18
|
+
export declare function getAdditionalPropertiesOption(opts: Record<string, any>): boolean;
|