@redocly/openapi-core 1.0.0-beta.127 → 1.0.0-beta.128
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/bundle.js +16 -2
- package/lib/config/all.js +1 -0
- package/lib/config/config-resolvers.js +8 -2
- package/lib/config/minimal.js +1 -0
- package/lib/config/recommended.js +1 -0
- package/lib/config/types.d.ts +1 -1
- package/lib/config/utils.js +15 -1
- package/lib/lint.js +17 -2
- package/lib/rules/common/spec-strict-refs.d.ts +2 -0
- package/lib/rules/common/spec-strict-refs.js +30 -0
- package/lib/rules/oas2/index.d.ts +1 -0
- package/lib/rules/oas2/index.js +2 -0
- package/lib/rules/oas3/index.js +2 -0
- package/lib/rules/oas3/spec-components-invalid-map-name.js +0 -5
- package/lib/types/redocly-yaml.js +6 -1
- package/lib/walk.js +3 -4
- package/package.json +1 -1
package/lib/bundle.js
CHANGED
|
@@ -74,13 +74,27 @@ function bundleDocument(opts) {
|
|
|
74
74
|
: remove_unused_components_2.RemoveUnusedComponents({}),
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
let resolvedRefMap = yield resolve_1.resolveDocument({
|
|
78
78
|
rootDocument: document,
|
|
79
79
|
rootType: types.Root,
|
|
80
80
|
externalRefResolver,
|
|
81
81
|
});
|
|
82
|
+
if (preprocessors.length > 0) {
|
|
83
|
+
// Make additional pass to resolve refs defined in preprocessors.
|
|
84
|
+
walk_1.walkDocument({
|
|
85
|
+
document,
|
|
86
|
+
rootType: types.Root,
|
|
87
|
+
normalizedVisitors: visitors_1.normalizeVisitors(preprocessors, types),
|
|
88
|
+
resolvedRefMap,
|
|
89
|
+
ctx,
|
|
90
|
+
});
|
|
91
|
+
resolvedRefMap = yield resolve_1.resolveDocument({
|
|
92
|
+
rootDocument: document,
|
|
93
|
+
rootType: types.Root,
|
|
94
|
+
externalRefResolver,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
82
97
|
const bundleVisitor = visitors_1.normalizeVisitors([
|
|
83
|
-
...preprocessors,
|
|
84
98
|
{
|
|
85
99
|
severity: 'error',
|
|
86
100
|
ruleId: 'bundler',
|
package/lib/config/all.js
CHANGED
|
@@ -75,6 +75,9 @@ function resolvePlugins(plugins, configPath = '') {
|
|
|
75
75
|
: require(absoltePluginPath);
|
|
76
76
|
}
|
|
77
77
|
catch (e) {
|
|
78
|
+
if (e instanceof SyntaxError) {
|
|
79
|
+
throw e;
|
|
80
|
+
}
|
|
78
81
|
throw new Error(`Failed to load plugin "${plugin}". Please provide a valid path`);
|
|
79
82
|
}
|
|
80
83
|
}
|
|
@@ -253,7 +256,10 @@ function groupStyleguideAssertionRules({ rules, plugins, }) {
|
|
|
253
256
|
// Collect assertion rules
|
|
254
257
|
const assertions = [];
|
|
255
258
|
for (const [ruleKey, rule] of Object.entries(rules)) {
|
|
256
|
-
|
|
259
|
+
// keep the old assert/ syntax as an alias
|
|
260
|
+
if ((ruleKey.startsWith('rule/') || ruleKey.startsWith('assert/')) &&
|
|
261
|
+
typeof rule === 'object' &&
|
|
262
|
+
rule !== null) {
|
|
257
263
|
const assertion = rule;
|
|
258
264
|
if (plugins) {
|
|
259
265
|
registerCustomAssertions(plugins, assertion);
|
|
@@ -262,7 +268,7 @@ function groupStyleguideAssertionRules({ rules, plugins, }) {
|
|
|
262
268
|
registerCustomAssertions(plugins, context);
|
|
263
269
|
}
|
|
264
270
|
}
|
|
265
|
-
assertions.push(Object.assign(Object.assign({}, assertion), { assertionId: ruleKey.replace(
|
|
271
|
+
assertions.push(Object.assign(Object.assign({}, assertion), { assertionId: ruleKey.replace(/rule\/|assert\//, '') }));
|
|
266
272
|
}
|
|
267
273
|
else {
|
|
268
274
|
// If it's not an assertion, keep it as is
|
package/lib/config/minimal.js
CHANGED
package/lib/config/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ProblemSeverity, UserContext } from '../walk';
|
|
|
2
2
|
import type { Oas3PreprocessorsSet, OasMajorVersion, Oas3DecoratorsSet, Oas2RuleSet, Oas2PreprocessorsSet, Oas2DecoratorsSet, Oas3RuleSet, OasVersion } from '../oas-types';
|
|
3
3
|
import type { NodeType } from '../types';
|
|
4
4
|
import { Location } from '../ref-utils';
|
|
5
|
-
import { SkipFunctionContext } from '../visitors';
|
|
5
|
+
import type { SkipFunctionContext } from '../visitors';
|
|
6
6
|
export declare type RuleSeverity = ProblemSeverity | 'off';
|
|
7
7
|
export declare type RuleSettings = {
|
|
8
8
|
severity: RuleSeverity;
|
package/lib/config/utils.js
CHANGED
|
@@ -191,12 +191,26 @@ function transformConfig(rawConfig) {
|
|
|
191
191
|
}
|
|
192
192
|
const { apis, apiDefinitions, referenceDocs, lint } = rawConfig, rest = __rest(rawConfig, ["apis", "apiDefinitions", "referenceDocs", "lint"]);
|
|
193
193
|
const { styleguideConfig, rawConfigRest } = extractFlatConfig(rest);
|
|
194
|
-
|
|
194
|
+
const transformedConfig = Object.assign({ theme: {
|
|
195
195
|
openapi: Object.assign(Object.assign(Object.assign({}, referenceDocs), rawConfig['features.openapi']), (_a = rawConfig.theme) === null || _a === void 0 ? void 0 : _a.openapi),
|
|
196
196
|
mockServer: Object.assign(Object.assign({}, rawConfig['features.mockServer']), (_b = rawConfig.theme) === null || _b === void 0 ? void 0 : _b.mockServer),
|
|
197
197
|
}, apis: transformApis(apis) || transformApiDefinitionsToApis(apiDefinitions), styleguide: styleguideConfig || lint }, rawConfigRest);
|
|
198
|
+
showDeprecationMessages(transformedConfig);
|
|
199
|
+
return transformedConfig;
|
|
198
200
|
}
|
|
199
201
|
exports.transformConfig = transformConfig;
|
|
202
|
+
function showDeprecationMessages(config) {
|
|
203
|
+
var _a, _b;
|
|
204
|
+
let allRules = Object.assign({}, (_a = config.styleguide) === null || _a === void 0 ? void 0 : _a.rules);
|
|
205
|
+
for (const api of Object.values(config.apis || {})) {
|
|
206
|
+
allRules = Object.assign(Object.assign({}, allRules), (_b = api === null || api === void 0 ? void 0 : api.styleguide) === null || _b === void 0 ? void 0 : _b.rules);
|
|
207
|
+
}
|
|
208
|
+
for (const ruleKey of Object.keys(allRules)) {
|
|
209
|
+
if (ruleKey.startsWith('assert/')) {
|
|
210
|
+
logger_1.logger.warn(`\nThe 'assert/' syntax in ${ruleKey} is deprecated. Update your configuration to use 'rule/' instead. Examples and more information: https://redocly.com/docs/cli/rules/configurable-rules/\n`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
200
214
|
function getResolveConfig(resolve) {
|
|
201
215
|
var _a, _b;
|
|
202
216
|
return {
|
package/lib/lint.js
CHANGED
|
@@ -57,12 +57,27 @@ function lintDocument(opts) {
|
|
|
57
57
|
};
|
|
58
58
|
const preprocessors = config_1.initRules(rules, config, 'preprocessors', oasVersion);
|
|
59
59
|
const regularRules = config_1.initRules(rules, config, 'rules', oasVersion);
|
|
60
|
-
|
|
61
|
-
const resolvedRefMap = yield resolve_1.resolveDocument({
|
|
60
|
+
let resolvedRefMap = yield resolve_1.resolveDocument({
|
|
62
61
|
rootDocument: document,
|
|
63
62
|
rootType: types.Root,
|
|
64
63
|
externalRefResolver,
|
|
65
64
|
});
|
|
65
|
+
if (preprocessors.length > 0) {
|
|
66
|
+
// Make additional pass to resolve refs defined in preprocessors.
|
|
67
|
+
walk_1.walkDocument({
|
|
68
|
+
document,
|
|
69
|
+
rootType: types.Root,
|
|
70
|
+
normalizedVisitors: visitors_1.normalizeVisitors(preprocessors, types),
|
|
71
|
+
resolvedRefMap,
|
|
72
|
+
ctx,
|
|
73
|
+
});
|
|
74
|
+
resolvedRefMap = yield resolve_1.resolveDocument({
|
|
75
|
+
rootDocument: document,
|
|
76
|
+
rootType: types.Root,
|
|
77
|
+
externalRefResolver,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const normalizedVisitors = visitors_1.normalizeVisitors(regularRules, types);
|
|
66
81
|
walk_1.walkDocument({
|
|
67
82
|
document,
|
|
68
83
|
rootType: types.Root,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SpecStrictRefs = void 0;
|
|
4
|
+
const ref_utils_1 = require("../../ref-utils");
|
|
5
|
+
const SpecStrictRefs = () => {
|
|
6
|
+
const nodesToSkip = [
|
|
7
|
+
'Schema',
|
|
8
|
+
'Response',
|
|
9
|
+
'Parameter',
|
|
10
|
+
'RequestBody',
|
|
11
|
+
'Example',
|
|
12
|
+
'Header',
|
|
13
|
+
'SecurityScheme',
|
|
14
|
+
'Link',
|
|
15
|
+
'Callback',
|
|
16
|
+
'PathItem',
|
|
17
|
+
];
|
|
18
|
+
return {
|
|
19
|
+
any(_node, { report, rawNode, rawLocation, type }) {
|
|
20
|
+
const shouldCheck = !nodesToSkip.includes(type.name);
|
|
21
|
+
if (shouldCheck && ref_utils_1.isRef(rawNode)) {
|
|
22
|
+
report({
|
|
23
|
+
message: 'Field $ref is not expected here.',
|
|
24
|
+
location: rawLocation.child('$ref').key(),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
exports.SpecStrictRefs = SpecStrictRefs;
|
|
@@ -42,5 +42,6 @@ export declare const rules: {
|
|
|
42
42
|
'response-contains-property': Oas2Rule;
|
|
43
43
|
'scalar-property-missing-example': import("../../visitors").Oas3Rule | Oas2Rule;
|
|
44
44
|
'required-string-property-missing-min-length': import("../../visitors").Oas3Rule;
|
|
45
|
+
'spec-strict-refs': import("../../visitors").Oas3Rule | Oas2Rule;
|
|
45
46
|
};
|
|
46
47
|
export declare const preprocessors: {};
|
package/lib/rules/oas2/index.js
CHANGED
|
@@ -42,6 +42,7 @@ const response_contains_header_1 = require("../common/response-contains-header")
|
|
|
42
42
|
const response_contains_property_1 = require("./response-contains-property");
|
|
43
43
|
const scalar_property_missing_example_1 = require("../common/scalar-property-missing-example");
|
|
44
44
|
const required_string_property_missing_min_length_1 = require("../common/required-string-property-missing-min-length");
|
|
45
|
+
const spec_strict_refs_1 = require("../common/spec-strict-refs");
|
|
45
46
|
exports.rules = {
|
|
46
47
|
spec: spec_1.OasSpec,
|
|
47
48
|
'no-invalid-schema-examples': no_invalid_schema_examples_1.NoInvalidSchemaExamples,
|
|
@@ -85,5 +86,6 @@ exports.rules = {
|
|
|
85
86
|
'response-contains-property': response_contains_property_1.ResponseContainsProperty,
|
|
86
87
|
'scalar-property-missing-example': scalar_property_missing_example_1.ScalarPropertyMissingExample,
|
|
87
88
|
'required-string-property-missing-min-length': required_string_property_missing_min_length_1.RequiredStringPropertyMissingMinLength,
|
|
89
|
+
'spec-strict-refs': spec_strict_refs_1.SpecStrictRefs,
|
|
88
90
|
};
|
|
89
91
|
exports.preprocessors = {};
|
package/lib/rules/oas3/index.js
CHANGED
|
@@ -52,6 +52,7 @@ const scalar_property_missing_example_1 = require("../common/scalar-property-mis
|
|
|
52
52
|
const spec_components_invalid_map_name_1 = require("./spec-components-invalid-map-name");
|
|
53
53
|
const operation_4xx_problem_details_rfc7807_1 = require("./operation-4xx-problem-details-rfc7807");
|
|
54
54
|
const required_string_property_missing_min_length_1 = require("../common/required-string-property-missing-min-length");
|
|
55
|
+
const spec_strict_refs_1 = require("../common/spec-strict-refs");
|
|
55
56
|
exports.rules = {
|
|
56
57
|
spec: spec_1.OasSpec,
|
|
57
58
|
'info-contact': info_contact_1.InfoContact,
|
|
@@ -105,5 +106,6 @@ exports.rules = {
|
|
|
105
106
|
'scalar-property-missing-example': scalar_property_missing_example_1.ScalarPropertyMissingExample,
|
|
106
107
|
'spec-components-invalid-map-name': spec_components_invalid_map_name_1.SpecComponentsInvalidMapName,
|
|
107
108
|
'required-string-property-missing-min-length': required_string_property_missing_min_length_1.RequiredStringPropertyMissingMinLength,
|
|
109
|
+
'spec-strict-refs': spec_strict_refs_1.SpecStrictRefs,
|
|
108
110
|
};
|
|
109
111
|
exports.preprocessors = {};
|
|
@@ -57,11 +57,6 @@ const SpecComponentsInvalidMapName = () => {
|
|
|
57
57
|
validateKey(key, report, location, 'callbacks');
|
|
58
58
|
},
|
|
59
59
|
},
|
|
60
|
-
ExampleMap: {
|
|
61
|
-
Example(_node, { key, report, location }) {
|
|
62
|
-
validateKey(key, report, location, 'examples');
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
60
|
};
|
|
66
61
|
};
|
|
67
62
|
exports.SpecComponentsInvalidMapName = SpecComponentsInvalidMapName;
|
|
@@ -56,6 +56,7 @@ const builtInRulesList = [
|
|
|
56
56
|
'scalar-property-missing-example',
|
|
57
57
|
'spec-components-invalid-map-name',
|
|
58
58
|
'required-string-property-missing-min-length',
|
|
59
|
+
'spec-strict-refs',
|
|
59
60
|
];
|
|
60
61
|
const nodeTypesList = [
|
|
61
62
|
'any',
|
|
@@ -196,7 +197,11 @@ const ConfigRootTheme = {
|
|
|
196
197
|
const Rules = {
|
|
197
198
|
properties: {},
|
|
198
199
|
additionalProperties: (value, key) => {
|
|
199
|
-
if (key.startsWith('
|
|
200
|
+
if (key.startsWith('rule/')) {
|
|
201
|
+
return 'Assert';
|
|
202
|
+
}
|
|
203
|
+
else if (key.startsWith('assert/')) {
|
|
204
|
+
// keep the old assert/ prefix as an alias
|
|
200
205
|
return 'Assert';
|
|
201
206
|
}
|
|
202
207
|
else if (builtInRulesList.includes(key) || utils_1.isCustomRuleId(key)) {
|
package/lib/walk.js
CHANGED
|
@@ -254,16 +254,15 @@ function walkDocument(opts) {
|
|
|
254
254
|
}, collectParents(context), context);
|
|
255
255
|
}
|
|
256
256
|
function reportFn(ruleId, severity, opts) {
|
|
257
|
-
const
|
|
257
|
+
const normalizedLocation = opts.location
|
|
258
258
|
? Array.isArray(opts.location)
|
|
259
259
|
? opts.location
|
|
260
260
|
: [opts.location]
|
|
261
261
|
: [Object.assign(Object.assign({}, currentLocation), { reportOnKey: false })];
|
|
262
|
+
const location = normalizedLocation.map((l) => (Object.assign(Object.assign(Object.assign({}, currentLocation), { reportOnKey: false }), l)));
|
|
262
263
|
const ruleSeverity = opts.forceSeverity || severity;
|
|
263
264
|
if (ruleSeverity !== 'off') {
|
|
264
|
-
ctx.problems.push(Object.assign(Object.assign({ ruleId: opts.ruleId || ruleId, severity: ruleSeverity }, opts), { suggest: opts.suggest || [], location
|
|
265
|
-
return Object.assign(Object.assign(Object.assign({}, currentLocation), { reportOnKey: false }), loc);
|
|
266
|
-
}) }));
|
|
265
|
+
ctx.problems.push(Object.assign(Object.assign({ ruleId: opts.ruleId || ruleId, severity: ruleSeverity }, opts), { suggest: opts.suggest || [], location }));
|
|
267
266
|
}
|
|
268
267
|
}
|
|
269
268
|
function getVisitorDataFn(ruleId) {
|