@redocly/openapi-core 1.0.0-beta.106 → 1.0.0-beta.109
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/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
- package/lib/benchmark/benches/resolve-with-no-external.bench.js +1 -1
- package/lib/bundle.d.ts +1 -1
- package/lib/bundle.js +9 -6
- package/lib/config/all.js +5 -3
- package/lib/config/config-resolvers.js +32 -14
- package/lib/config/config.d.ts +3 -5
- package/lib/config/config.js +7 -4
- package/lib/config/load.d.ts +7 -0
- package/lib/config/load.js +14 -6
- package/lib/config/minimal.js +7 -4
- package/lib/config/recommended.js +7 -4
- package/lib/config/rules.d.ts +1 -1
- package/lib/config/rules.js +1 -1
- package/lib/config/types.d.ts +7 -0
- package/lib/config/utils.d.ts +2 -2
- package/lib/config/utils.js +49 -11
- package/lib/decorators/common/registry-dependencies.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.d.ts +1 -1
- package/lib/format/format.js +49 -26
- package/lib/index.d.ts +5 -5
- package/lib/index.js +3 -1
- package/lib/js-yaml/index.js +1 -0
- package/lib/lint.js +2 -2
- 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 +3 -3
- package/lib/redocly/registry-api.js +7 -1
- package/lib/ref-utils.js +2 -1
- package/lib/resolve.d.ts +1 -1
- package/lib/resolve.js +4 -2
- 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/no-ambiguous-paths.js +1 -1
- package/lib/rules/common/no-identical-paths.js +1 -1
- 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-2xx-response.js +1 -1
- package/lib/rules/common/operation-4xx-response.js +1 -1
- package/lib/rules/common/operation-operationId.js +1 -1
- package/lib/rules/common/operation-tag-defined.js +1 -1
- package/lib/rules/common/path-not-include-query.js +1 -1
- package/lib/rules/common/security-defined.d.ts +2 -0
- package/lib/rules/common/{operation-security-defined.js → security-defined.js} +19 -5
- package/lib/rules/common/spec.js +14 -3
- package/lib/rules/common/tags-alphabetical.js +1 -1
- package/lib/rules/oas2/index.d.ts +1 -1
- package/lib/rules/oas2/index.js +2 -2
- package/lib/rules/oas2/remove-unused-components.js +3 -3
- package/lib/rules/oas2/request-mime-type.js +1 -1
- package/lib/rules/oas2/response-mime-type.js +1 -1
- package/lib/rules/oas3/index.js +8 -4
- 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} +5 -5
- package/lib/rules/oas3/no-unused-components.js +2 -2
- 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/remove-unused-components.js +4 -4
- package/lib/rules/oas3/request-mime-type.js +1 -1
- package/lib/rules/oas3/response-mime-type.js +1 -1
- package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
- package/lib/rules/oas3/spec-components-invalid-map-name.js +46 -0
- package/lib/rules/other/stats.d.ts +2 -2
- package/lib/rules/other/stats.js +2 -2
- package/lib/rules/utils.d.ts +3 -2
- package/lib/rules/utils.js +16 -4
- package/lib/types/oas2.js +5 -5
- package/lib/types/oas3.js +27 -20
- package/lib/types/oas3_1.js +3 -3
- package/lib/types/redocly-yaml.js +47 -56
- package/lib/utils.d.ts +6 -1
- package/lib/utils.js +24 -7
- package/lib/visitors.d.ts +12 -12
- package/lib/visitors.js +15 -3
- 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 +3 -3
- package/src/__tests__/fixtures/extension.js +3 -3
- package/src/__tests__/format.test.ts +76 -0
- package/src/__tests__/lint.test.ts +106 -131
- package/src/__tests__/logger-browser.test.ts +53 -0
- package/src/__tests__/logger.test.ts +47 -0
- package/src/__tests__/output-browser.test.ts +18 -0
- package/src/__tests__/output.test.ts +15 -0
- package/src/__tests__/resolve-http.test.ts +1 -1
- package/src/__tests__/resolve.test.ts +9 -9
- package/src/__tests__/utils-browser.test.ts +11 -0
- package/src/__tests__/utils.test.ts +7 -0
- package/src/__tests__/walk.test.ts +78 -10
- package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +0 -1
- package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
- package/src/bundle.ts +10 -7
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +12 -6
- package/src/config/__tests__/config.test.ts +35 -0
- package/src/config/__tests__/fixtures/plugin-config.yaml +2 -3
- package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +11 -12
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +7 -8
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +18 -19
- package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +9 -10
- package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +3 -4
- package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +4 -5
- package/src/config/__tests__/load.test.ts +76 -1
- package/src/config/__tests__/utils.test.ts +64 -4
- package/src/config/all.ts +5 -3
- package/src/config/config-resolvers.ts +45 -19
- package/src/config/config.ts +10 -8
- package/src/config/load.ts +31 -7
- package/src/config/minimal.ts +7 -4
- package/src/config/recommended.ts +7 -4
- package/src/config/rules.ts +2 -2
- package/src/config/types.ts +11 -0
- package/src/config/utils.ts +115 -25
- package/src/decorators/common/registry-dependencies.ts +2 -2
- package/src/env.ts +5 -0
- package/src/format/codeframes.ts +15 -9
- package/src/format/format.ts +59 -34
- package/src/index.ts +6 -4
- package/src/js-yaml/index.ts +1 -0
- package/src/lint.ts +2 -2
- package/src/logger.ts +34 -0
- package/src/output.ts +7 -0
- package/src/redocly/index.ts +7 -4
- package/src/redocly/registry-api-types.ts +27 -29
- package/src/redocly/registry-api.ts +18 -7
- package/src/ref-utils.ts +2 -1
- package/src/resolve.ts +7 -5
- package/src/rules/__tests__/utils.test.ts +39 -1
- package/src/rules/ajv.ts +7 -7
- package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +1 -0
- package/src/rules/common/__tests__/operation-2xx-response.test.ts +1 -1
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +26 -3
- package/src/rules/common/__tests__/security-defined.test.ts +175 -0
- package/src/rules/common/__tests__/spec.test.ts +79 -0
- package/src/rules/common/assertions/__tests__/utils.test.ts +2 -2
- package/src/rules/common/assertions/asserts.ts +4 -4
- package/src/rules/common/assertions/index.ts +1 -1
- package/src/rules/common/no-ambiguous-paths.ts +1 -1
- package/src/rules/common/no-identical-paths.ts +1 -1
- 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-2xx-response.ts +1 -1
- package/src/rules/common/operation-4xx-response.ts +1 -1
- package/src/rules/common/operation-operationId.ts +1 -1
- package/src/rules/common/operation-tag-defined.ts +1 -1
- package/src/rules/common/path-not-include-query.ts +1 -1
- package/src/rules/common/{operation-security-defined.ts → security-defined.ts} +20 -5
- package/src/rules/common/spec.ts +17 -3
- package/src/rules/common/tags-alphabetical.ts +1 -1
- package/src/rules/oas2/index.ts +2 -2
- package/src/rules/oas2/remove-unused-components.ts +3 -3
- package/src/rules/oas2/request-mime-type.ts +1 -1
- package/src/rules/oas2/response-mime-type.ts +1 -1
- package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +5 -5
- package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +145 -0
- package/src/rules/oas3/__tests__/spec/spec.test.ts +10 -0
- package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +217 -0
- package/src/rules/oas3/index.ts +8 -4
- package/src/rules/oas3/no-empty-servers.ts +1 -1
- package/src/rules/oas3/no-invalid-media-type-examples.ts +3 -3
- package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +3 -3
- package/src/rules/oas3/no-unused-components.ts +2 -2
- package/src/rules/oas3/operation-4xx-problem-details-rfc7807.ts +36 -0
- package/src/rules/oas3/remove-unused-components.ts +5 -5
- package/src/rules/oas3/request-mime-type.ts +1 -1
- package/src/rules/oas3/response-mime-type.ts +1 -1
- package/src/rules/oas3/spec-components-invalid-map-name.ts +53 -0
- package/src/rules/other/stats.ts +2 -2
- package/src/rules/utils.ts +17 -3
- package/src/types/index.ts +2 -2
- package/src/types/oas2.ts +5 -5
- package/src/types/oas3.ts +27 -20
- package/src/types/oas3_1.ts +3 -3
- package/src/types/redocly-yaml.ts +53 -41
- package/src/utils.ts +31 -4
- package/src/visitors.ts +34 -18
- package/src/walk.ts +15 -11
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/common/operation-security-defined.d.ts +0 -2
- package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
- package/src/rules/common/__tests__/operation-security-defined.test.ts +0 -69
package/lib/utils.js
CHANGED
|
@@ -9,14 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.
|
|
12
|
+
exports.identity = exports.isTruthy = exports.showErrorForDeprecatedField = exports.showWarningForDeprecatedField = exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.isDefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
|
|
13
13
|
const fs = require("fs");
|
|
14
14
|
const path_1 = require("path");
|
|
15
15
|
const minimatch = require("minimatch");
|
|
16
16
|
const node_fetch_1 = require("node-fetch");
|
|
17
17
|
const pluralize = require("pluralize");
|
|
18
18
|
const js_yaml_1 = require("./js-yaml");
|
|
19
|
-
const
|
|
19
|
+
const env_1 = require("./env");
|
|
20
|
+
const logger_1 = require("./logger");
|
|
20
21
|
var js_yaml_2 = require("./js-yaml");
|
|
21
22
|
Object.defineProperty(exports, "parseYaml", { enumerable: true, get: function () { return js_yaml_2.parseYaml; } });
|
|
22
23
|
Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: function () { return js_yaml_2.stringifyYaml; } });
|
|
@@ -36,10 +37,10 @@ function loadYaml(filename) {
|
|
|
36
37
|
});
|
|
37
38
|
}
|
|
38
39
|
exports.loadYaml = loadYaml;
|
|
39
|
-
function
|
|
40
|
+
function isDefined(x) {
|
|
40
41
|
return x !== undefined;
|
|
41
42
|
}
|
|
42
|
-
exports.
|
|
43
|
+
exports.isDefined = isDefined;
|
|
43
44
|
function isPlainObject(value) {
|
|
44
45
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
45
46
|
}
|
|
@@ -58,7 +59,7 @@ function readFileFromUrl(url, config) {
|
|
|
58
59
|
for (const header of config.headers) {
|
|
59
60
|
if (match(url, header.matches)) {
|
|
60
61
|
headers[header.name] =
|
|
61
|
-
header.envVariable !== undefined ?
|
|
62
|
+
header.envVariable !== undefined ? env_1.env[header.envVariable] || '' : header.value;
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
const req = yield (config.customFetch || node_fetch_1.default)(url, {
|
|
@@ -89,7 +90,7 @@ exports.omitObjectProps = omitObjectProps;
|
|
|
89
90
|
function splitCamelCaseIntoWords(str) {
|
|
90
91
|
const camel = str
|
|
91
92
|
.split(/(?:[-._])|([A-Z][a-z]+)/)
|
|
92
|
-
.filter(
|
|
93
|
+
.filter(isTruthy)
|
|
93
94
|
.map((item) => item.toLocaleLowerCase());
|
|
94
95
|
const caps = str
|
|
95
96
|
.split(/([A-Z]{2,})/)
|
|
@@ -167,7 +168,7 @@ function isNotString(value) {
|
|
|
167
168
|
}
|
|
168
169
|
exports.isNotString = isNotString;
|
|
169
170
|
function assignExisting(target, obj) {
|
|
170
|
-
for (
|
|
171
|
+
for (const k of Object.keys(obj)) {
|
|
171
172
|
if (target.hasOwnProperty(k)) {
|
|
172
173
|
target[k] = obj[k];
|
|
173
174
|
}
|
|
@@ -188,3 +189,19 @@ function doesYamlFileExist(filePath) {
|
|
|
188
189
|
fs.existsSync(filePath));
|
|
189
190
|
}
|
|
190
191
|
exports.doesYamlFileExist = doesYamlFileExist;
|
|
192
|
+
function showWarningForDeprecatedField(deprecatedField, updatedField) {
|
|
193
|
+
logger_1.logger.warn(`The '${logger_1.colorize.red(deprecatedField)}' field is deprecated. ${updatedField ? `Use ${logger_1.colorize.green(updatedField)} instead. ` : ''}Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`);
|
|
194
|
+
}
|
|
195
|
+
exports.showWarningForDeprecatedField = showWarningForDeprecatedField;
|
|
196
|
+
function showErrorForDeprecatedField(deprecatedField, updatedField) {
|
|
197
|
+
throw new Error(`Do not use '${deprecatedField}' field. ${updatedField ? `Use '${updatedField}' instead. ` : ''}\n`);
|
|
198
|
+
}
|
|
199
|
+
exports.showErrorForDeprecatedField = showErrorForDeprecatedField;
|
|
200
|
+
function isTruthy(value) {
|
|
201
|
+
return !!value;
|
|
202
|
+
}
|
|
203
|
+
exports.isTruthy = isTruthy;
|
|
204
|
+
function identity(value) {
|
|
205
|
+
return value;
|
|
206
|
+
}
|
|
207
|
+
exports.identity = identity;
|
package/lib/visitors.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Oas3Definition, Oas3ExternalDocs, Oas3Info, Oas3Contact, Oas3Components, Oas3License, Oas3Schema, Oas3Header, Oas3Parameter, Oas3Operation, Oas3PathItem, Oas3ServerVariable, Oas3Server, Oas3MediaType, Oas3Response, Oas3Example, Oas3RequestBody, Oas3Tag, OasRef, Oas3SecurityScheme, Oas3SecurityRequirement, Oas3Encoding, Oas3Link, Oas3Xml, Oas3Discriminator, Oas3Callback } from './typings/openapi';
|
|
2
|
-
import { Oas2Definition, Oas2Tag, Oas2ExternalDocs, Oas2SecurityRequirement, Oas2Info, Oas2Contact, Oas2License, Oas2PathItem, Oas2Operation, Oas2Header, Oas2Response, Oas2Schema, Oas2Xml, Oas2Parameter, Oas2SecurityScheme } from './typings/swagger';
|
|
3
|
-
import { NormalizedNodeType } from './types';
|
|
4
|
-
import { Stack } from './utils';
|
|
5
|
-
import { UserContext, ResolveResult, ProblemSeverity } from './walk';
|
|
6
|
-
import { Location } from './ref-utils';
|
|
2
|
+
import type { Oas2Definition, Oas2Tag, Oas2ExternalDocs, Oas2SecurityRequirement, Oas2Info, Oas2Contact, Oas2License, Oas2PathItem, Oas2Operation, Oas2Header, Oas2Response, Oas2Schema, Oas2Xml, Oas2Parameter, Oas2SecurityScheme } from './typings/swagger';
|
|
3
|
+
import type { NormalizedNodeType } from './types';
|
|
4
|
+
import type { Stack } from './utils';
|
|
5
|
+
import type { UserContext, ResolveResult, ProblemSeverity } from './walk';
|
|
6
|
+
import type { Location } from './ref-utils';
|
|
7
7
|
export declare type VisitFunction<T> = (node: T, ctx: UserContext & {
|
|
8
8
|
ignoreNextVisitorsOnNode: () => void;
|
|
9
9
|
}, parents?: any, context?: any) => void;
|
|
@@ -16,7 +16,7 @@ declare type VisitObject<T> = {
|
|
|
16
16
|
};
|
|
17
17
|
declare type NestedVisitObject<T, P> = VisitObject<T> & NestedVisitor<P>;
|
|
18
18
|
declare type VisitFunctionOrObject<T> = VisitFunction<T> | VisitObject<T>;
|
|
19
|
-
declare type VisitorNode<T
|
|
19
|
+
declare type VisitorNode<T> = {
|
|
20
20
|
ruleId: string;
|
|
21
21
|
severity: ProblemSeverity;
|
|
22
22
|
context: VisitorLevelContext | VisitorSkippedLevelContext;
|
|
@@ -61,7 +61,7 @@ export declare type BaseVisitor = {
|
|
|
61
61
|
} | VisitRefFunction;
|
|
62
62
|
};
|
|
63
63
|
declare type Oas3FlatVisitor = {
|
|
64
|
-
|
|
64
|
+
Root?: VisitFunctionOrObject<Oas3Definition>;
|
|
65
65
|
Tag?: VisitFunctionOrObject<Oas3Tag>;
|
|
66
66
|
ExternalDocs?: VisitFunctionOrObject<Oas3ExternalDocs>;
|
|
67
67
|
Server?: VisitFunctionOrObject<Oas3Server>;
|
|
@@ -70,13 +70,13 @@ declare type Oas3FlatVisitor = {
|
|
|
70
70
|
Info?: VisitFunctionOrObject<Oas3Info>;
|
|
71
71
|
Contact?: VisitFunctionOrObject<Oas3Contact>;
|
|
72
72
|
License?: VisitFunctionOrObject<Oas3License>;
|
|
73
|
-
|
|
73
|
+
PathsMap?: VisitFunctionOrObject<Record<string, Oas3PathItem>>;
|
|
74
74
|
PathItem?: VisitFunctionOrObject<Oas3PathItem>;
|
|
75
75
|
Callback?: VisitFunctionOrObject<Record<string, Oas3PathItem>>;
|
|
76
76
|
Parameter?: VisitFunctionOrObject<Oas3Parameter>;
|
|
77
77
|
Operation?: VisitFunctionOrObject<Oas3Operation>;
|
|
78
78
|
RequestBody?: VisitFunctionOrObject<Oas3RequestBody>;
|
|
79
|
-
|
|
79
|
+
MediaTypesMap?: VisitFunctionOrObject<Record<string, Oas3MediaType>>;
|
|
80
80
|
MediaType?: VisitFunctionOrObject<Oas3MediaType>;
|
|
81
81
|
Example?: VisitFunctionOrObject<Oas3Example>;
|
|
82
82
|
Encoding?: VisitFunctionOrObject<Oas3Encoding>;
|
|
@@ -107,14 +107,14 @@ declare type Oas3FlatVisitor = {
|
|
|
107
107
|
SecurityScheme?: VisitFunctionOrObject<Oas3SecurityScheme>;
|
|
108
108
|
};
|
|
109
109
|
declare type Oas2FlatVisitor = {
|
|
110
|
-
|
|
110
|
+
Root?: VisitFunctionOrObject<Oas2Definition>;
|
|
111
111
|
Tag?: VisitFunctionOrObject<Oas2Tag>;
|
|
112
112
|
ExternalDocs?: VisitFunctionOrObject<Oas2ExternalDocs>;
|
|
113
113
|
SecurityRequirement?: VisitFunctionOrObject<Oas2SecurityRequirement>;
|
|
114
114
|
Info?: VisitFunctionOrObject<Oas2Info>;
|
|
115
115
|
Contact?: VisitFunctionOrObject<Oas2Contact>;
|
|
116
116
|
License?: VisitFunctionOrObject<Oas2License>;
|
|
117
|
-
|
|
117
|
+
PathsMap?: VisitFunctionOrObject<Record<string, Oas2PathItem>>;
|
|
118
118
|
PathItem?: VisitFunctionOrObject<Oas2PathItem>;
|
|
119
119
|
Parameter?: VisitFunctionOrObject<any>;
|
|
120
120
|
Operation?: VisitFunctionOrObject<Oas2Operation>;
|
|
@@ -140,7 +140,7 @@ export declare type Oas3Visitor = BaseVisitor & Oas3NestedVisitor & Record<strin
|
|
|
140
140
|
export declare type Oas2Visitor = BaseVisitor & Oas2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas2NestedVisitor>>;
|
|
141
141
|
export declare type Oas3TransformVisitor = BaseVisitor & Oas3FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
|
|
142
142
|
export declare type Oas2TransformVisitor = BaseVisitor & Oas2FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
|
|
143
|
-
export declare type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | '
|
|
143
|
+
export declare type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | 'Root'>;
|
|
144
144
|
export declare type NormalizedOasVisitors<T extends BaseVisitor> = {
|
|
145
145
|
[V in keyof T]-?: {
|
|
146
146
|
enter: Array<NormalizeVisitor<T[V]>>;
|
package/lib/visitors.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeVisitors = void 0;
|
|
4
|
+
const legacyTypesMap = {
|
|
5
|
+
Root: 'DefinitionRoot',
|
|
6
|
+
ServerVariablesMap: 'ServerVariableMap',
|
|
7
|
+
PathsMap: 'PathMap',
|
|
8
|
+
CallbacksMap: 'CallbackMap',
|
|
9
|
+
MediaTypesMap: 'MediaTypeMap',
|
|
10
|
+
ExamplesMap: 'ExampleMap',
|
|
11
|
+
EncodingsMap: 'EncodingMap',
|
|
12
|
+
HeadersMap: 'HeaderMap',
|
|
13
|
+
LinksMap: 'LinkMap',
|
|
14
|
+
};
|
|
4
15
|
function normalizeVisitors(visitorsConfig, types) {
|
|
5
16
|
const normalizedVisitors = {};
|
|
6
17
|
normalizedVisitors.any = {
|
|
@@ -30,7 +41,7 @@ function normalizeVisitors(visitorsConfig, types) {
|
|
|
30
41
|
return;
|
|
31
42
|
stack = [...stack, from];
|
|
32
43
|
const possibleChildren = new Set();
|
|
33
|
-
for (
|
|
44
|
+
for (const type of Object.values(from.properties)) {
|
|
34
45
|
if (type === to) {
|
|
35
46
|
addWeakFromStack(ruleConf, stack);
|
|
36
47
|
continue;
|
|
@@ -55,7 +66,7 @@ function normalizeVisitors(visitorsConfig, types) {
|
|
|
55
66
|
possibleChildren.add(from.items);
|
|
56
67
|
}
|
|
57
68
|
}
|
|
58
|
-
for (
|
|
69
|
+
for (const fromType of Array.from(possibleChildren.values())) {
|
|
59
70
|
addWeakNodes(ruleConf, fromType, to, parentContext, stack);
|
|
60
71
|
}
|
|
61
72
|
function addWeakFromStack(ruleConf, stack) {
|
|
@@ -89,7 +100,8 @@ function normalizeVisitors(visitorsConfig, types) {
|
|
|
89
100
|
}
|
|
90
101
|
}
|
|
91
102
|
for (const typeName of visitorKeys) {
|
|
92
|
-
const typeVisitor = visitor[typeName]
|
|
103
|
+
const typeVisitor = (visitor[typeName] ||
|
|
104
|
+
visitor[legacyTypesMap[typeName]]);
|
|
93
105
|
const normalizedTypeVisitor = normalizedVisitors[typeName];
|
|
94
106
|
if (!typeVisitor)
|
|
95
107
|
continue;
|
package/lib/walk.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { NormalizedOasVisitors } from './visitors';
|
|
|
4
4
|
import { ResolvedRefMap, Document, ResolveError, YamlParseError, Source } from './resolve';
|
|
5
5
|
import { OasVersion } from './oas-types';
|
|
6
6
|
import { NormalizedNodeType } from './types';
|
|
7
|
+
import type { RuleSeverity } from './config';
|
|
7
8
|
declare type NonUndefined = string | number | boolean | symbol | bigint | object | Record<string, any>;
|
|
8
9
|
export declare type ResolveResult<T extends NonUndefined> = {
|
|
9
10
|
node: T;
|
|
@@ -49,7 +50,7 @@ export declare type Problem = {
|
|
|
49
50
|
suggest?: string[];
|
|
50
51
|
location?: Partial<LocationObject> | Array<Partial<LocationObject>>;
|
|
51
52
|
from?: LocationObject;
|
|
52
|
-
forceSeverity?:
|
|
53
|
+
forceSeverity?: RuleSeverity;
|
|
53
54
|
ruleId?: string;
|
|
54
55
|
};
|
|
55
56
|
export declare type NormalizedProblem = {
|
package/lib/walk.js
CHANGED
|
@@ -249,9 +249,12 @@ function walkDocument(opts) {
|
|
|
249
249
|
? opts.location
|
|
250
250
|
: [opts.location]
|
|
251
251
|
: [Object.assign(Object.assign({}, currentLocation), { reportOnKey: false })];
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
})
|
|
252
|
+
const ruleSeverity = opts.forceSeverity || severity;
|
|
253
|
+
if (ruleSeverity !== 'off') {
|
|
254
|
+
ctx.problems.push(Object.assign(Object.assign({ ruleId: opts.ruleId || ruleId, severity: ruleSeverity }, opts), { suggest: opts.suggest || [], location: loc.map((loc) => {
|
|
255
|
+
return Object.assign(Object.assign(Object.assign({}, currentLocation), { reportOnKey: false }), loc);
|
|
256
|
+
}) }));
|
|
257
|
+
}
|
|
255
258
|
}
|
|
256
259
|
function getVisitorDataFn(ruleId) {
|
|
257
260
|
ctx.visitorsData[ruleId] = ctx.visitorsData[ruleId] || {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/openapi-core",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.109",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"Andriy Leliv <andriy@redoc.ly> (https://redoc.ly/)"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@redocly/ajv": "^8.6.
|
|
37
|
+
"@redocly/ajv": "^8.6.5",
|
|
38
38
|
"@types/node": "^14.11.8",
|
|
39
39
|
"colorette": "^1.2.0",
|
|
40
40
|
"js-levenshtein": "^1.1.6",
|
|
@@ -47,7 +47,7 @@ rootType:
|
|
|
47
47
|
description:
|
|
48
48
|
type: string
|
|
49
49
|
variables:
|
|
50
|
-
name:
|
|
50
|
+
name: ServerVariablesMap
|
|
51
51
|
properties: {}
|
|
52
52
|
required:
|
|
53
53
|
- url
|
|
@@ -94,7 +94,7 @@ rootType:
|
|
|
94
94
|
name: ExternalDocs
|
|
95
95
|
paths:
|
|
96
96
|
properties: {}
|
|
97
|
-
name:
|
|
97
|
+
name: PathsMap
|
|
98
98
|
components:
|
|
99
99
|
properties:
|
|
100
100
|
parameters:
|
|
@@ -132,7 +132,7 @@ rootType:
|
|
|
132
132
|
- openapi
|
|
133
133
|
- paths
|
|
134
134
|
- info
|
|
135
|
-
name:
|
|
135
|
+
name: Root
|
|
136
136
|
refTypes: {}
|
|
137
137
|
visitorsData:
|
|
138
138
|
registry-dependencies:
|
|
@@ -9,10 +9,10 @@ function oas3_0(types) {
|
|
|
9
9
|
parameters: listOf('Parameter'),
|
|
10
10
|
},
|
|
11
11
|
},
|
|
12
|
-
|
|
13
|
-
...types.
|
|
12
|
+
Root: {
|
|
13
|
+
...types.Root,
|
|
14
14
|
properties: {
|
|
15
|
-
...types.
|
|
15
|
+
...types.Root.properties,
|
|
16
16
|
'x-webhooks': 'XWebHooks',
|
|
17
17
|
},
|
|
18
18
|
},
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { outdent } from 'outdent';
|
|
2
|
+
|
|
3
|
+
import { formatProblems, getTotals } from '../format/format';
|
|
4
|
+
|
|
5
|
+
describe('format', () => {
|
|
6
|
+
function replaceColors(log: string) {
|
|
7
|
+
return log
|
|
8
|
+
.replace(/\x1b\[33m(.*?)\x1b\[39m/g, '<o>$1</o>') // orange
|
|
9
|
+
.replace(/\x1b\[31m(.*?)\x1b\[39m/g, '<r>$1</r>'); // red
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const problems = [
|
|
13
|
+
{
|
|
14
|
+
ruleId: 'spec',
|
|
15
|
+
location: [],
|
|
16
|
+
severity: 'error' as const,
|
|
17
|
+
message: 'message',
|
|
18
|
+
suggest: [],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
ruleId: 'spec',
|
|
22
|
+
location: [],
|
|
23
|
+
severity: 'error' as const,
|
|
24
|
+
message: 'message 2',
|
|
25
|
+
suggest: [],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
ruleId: 'other-rule',
|
|
29
|
+
location: [],
|
|
30
|
+
severity: 'warn' as const,
|
|
31
|
+
message: 'message',
|
|
32
|
+
suggest: [],
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
let output = '';
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
output = '';
|
|
39
|
+
jest.spyOn(process.stderr, 'write').mockImplementation((str: string | Uint8Array) => {
|
|
40
|
+
output += str;
|
|
41
|
+
return true;
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should correctly format summary output', () => {
|
|
46
|
+
formatProblems(problems, {
|
|
47
|
+
format: 'summary',
|
|
48
|
+
version: '1.0.0',
|
|
49
|
+
totals: getTotals(problems),
|
|
50
|
+
color: false,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(output).toMatchInlineSnapshot(`
|
|
54
|
+
"error spec: 2
|
|
55
|
+
warning other-rule: 1
|
|
56
|
+
|
|
57
|
+
"
|
|
58
|
+
`);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should correctly format summary output in color mode', () => {
|
|
62
|
+
formatProblems(problems, {
|
|
63
|
+
format: 'summary',
|
|
64
|
+
version: '1.0.0',
|
|
65
|
+
totals: getTotals(problems),
|
|
66
|
+
color: true,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(replaceColors(output)).toMatchInlineSnapshot(`
|
|
70
|
+
"<r>error </r> spec: 2
|
|
71
|
+
<o>warning</o> other-rule: 1
|
|
72
|
+
|
|
73
|
+
"
|
|
74
|
+
`);
|
|
75
|
+
});
|
|
76
|
+
});
|