@redocly/openapi-core 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/lib/bundle.d.ts +2 -2
- package/lib/bundle.js +24 -22
- package/lib/config/builtIn.js +4 -0
- package/lib/config/config-resolvers.js +19 -6
- package/lib/config/config.d.ts +9 -9
- package/lib/config/config.js +32 -17
- package/lib/config/rules.d.ts +2 -2
- package/lib/config/types.d.ts +9 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +7 -6
- package/lib/lint.js +10 -16
- package/lib/oas-types.d.ts +16 -10
- package/lib/oas-types.js +52 -26
- 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 +12 -0
- package/lib/rules/async2/index.js +22 -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/common/scalar-property-missing-example.js +1 -1
- package/lib/rules/common/spec.d.ts +2 -2
- package/lib/rules/common/spec.js +3 -3
- package/lib/rules/oas2/index.js +1 -1
- package/lib/rules/oas3/index.js +1 -1
- package/lib/types/asyncapi.d.ts +2 -0
- package/lib/types/asyncapi.js +1027 -0
- package/lib/types/redocly-yaml.js +3 -0
- package/lib/typings/asyncapi.d.ts +21 -0
- package/lib/typings/asyncapi.js +2 -0
- package/lib/visitors.d.ts +12 -0
- package/lib/walk.d.ts +3 -3
- package/package.json +2 -1
- package/src/__tests__/lint.test.ts +36 -6
- package/src/bundle.ts +27 -28
- package/src/config/__tests__/__snapshots__/config.test.ts.snap +24 -0
- package/src/config/__tests__/config.test.ts +15 -4
- package/src/config/builtIn.ts +4 -0
- package/src/config/config-resolvers.ts +25 -6
- package/src/config/config.ts +51 -27
- package/src/config/rules.ts +2 -2
- package/src/config/types.ts +14 -4
- package/src/index.ts +7 -1
- package/src/lint.ts +13 -22
- package/src/oas-types.ts +59 -21
- package/src/rules/async2/__tests__/channels-kebab-case.test.ts +141 -0
- package/src/rules/async2/__tests__/no-channel-trailing-slash.test.ts +97 -0
- package/src/rules/async2/channels-kebab-case.ts +18 -0
- package/src/rules/async2/index.ts +22 -0
- package/src/rules/async2/no-channel-trailing-slash.ts +15 -0
- package/src/rules/common/scalar-property-missing-example.ts +2 -2
- package/src/rules/common/spec.ts +2 -2
- package/src/rules/oas2/index.ts +2 -2
- package/src/rules/oas3/index.ts +2 -2
- package/src/types/asyncapi.ts +1136 -0
- package/src/types/redocly-yaml.ts +3 -0
- package/src/typings/asyncapi.ts +26 -0
- package/src/visitors.ts +22 -0
- package/src/walk.ts +3 -3
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @redocly/openapi-core
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added support for linting AsyncAPI v2 files, so that a wider range of API descriptions can use the Redocly linting workflow.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Renamed API definition to API description for consistency.
|
|
12
|
+
|
|
3
13
|
## 1.1.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/lib/bundle.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { BaseResolver, Document } from './resolve';
|
|
|
2
2
|
import { Oas3Rule } from './visitors';
|
|
3
3
|
import { NormalizedNodeType, NodeType } from './types';
|
|
4
4
|
import { NormalizedProblem } from './walk';
|
|
5
|
-
import {
|
|
5
|
+
import { SpecMajorVersion } from './oas-types';
|
|
6
6
|
import type { Config, StyleguideConfig } from './config';
|
|
7
7
|
export declare type Oas3RuleSet = Record<string, Oas3Rule>;
|
|
8
8
|
export declare enum OasVersion {
|
|
@@ -39,4 +39,4 @@ export declare function bundleDocument(opts: {
|
|
|
39
39
|
removeUnusedComponents?: boolean;
|
|
40
40
|
keepUrlRefs?: boolean;
|
|
41
41
|
}): Promise<BundleResult>;
|
|
42
|
-
export declare function mapTypeToComponent(typeName: string, version:
|
|
42
|
+
export declare function mapTypeToComponent(typeName: string, version: SpecMajorVersion): "responses" | "parameters" | "examples" | "headers" | "schemas" | "requestBodies" | "securitySchemes" | "links" | "callbacks" | "definitions" | null;
|
package/lib/bundle.js
CHANGED
|
@@ -13,9 +13,6 @@ exports.mapTypeToComponent = exports.bundleDocument = exports.bundle = exports.O
|
|
|
13
13
|
const isEqual = require("lodash.isequal");
|
|
14
14
|
const resolve_1 = require("./resolve");
|
|
15
15
|
const visitors_1 = require("./visitors");
|
|
16
|
-
const oas3_1 = require("./types/oas3");
|
|
17
|
-
const oas2_1 = require("./types/oas2");
|
|
18
|
-
const oas3_1_1 = require("./types/oas3_1");
|
|
19
16
|
const types_1 = require("./types");
|
|
20
17
|
const walk_1 = require("./walk");
|
|
21
18
|
const oas_types_1 = require("./oas-types");
|
|
@@ -49,19 +46,15 @@ exports.bundle = bundle;
|
|
|
49
46
|
function bundleDocument(opts) {
|
|
50
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
48
|
const { document, config, customTypes, externalRefResolver, dereference = false, skipRedoclyRegistryRefs = false, removeUnusedComponents = false, keepUrlRefs = false, } = opts;
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const rules = config.getRulesForOasVersion(
|
|
55
|
-
const types = types_1.normalizeTypes(config.extendTypes(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
: oas3_1.Oas3Types
|
|
59
|
-
: oas2_1.Oas2Types, oasVersion), config);
|
|
60
|
-
const preprocessors = rules_1.initRules(rules, config, 'preprocessors', oasVersion);
|
|
61
|
-
const decorators = rules_1.initRules(rules, config, 'decorators', oasVersion);
|
|
49
|
+
const specVersion = oas_types_1.detectSpec(document.parsed);
|
|
50
|
+
const specMajorVersion = oas_types_1.getMajorSpecVersion(specVersion);
|
|
51
|
+
const rules = config.getRulesForOasVersion(specMajorVersion);
|
|
52
|
+
const types = types_1.normalizeTypes(config.extendTypes(customTypes !== null && customTypes !== void 0 ? customTypes : oas_types_1.getTypes(specVersion), specVersion), config);
|
|
53
|
+
const preprocessors = rules_1.initRules(rules, config, 'preprocessors', specVersion);
|
|
54
|
+
const decorators = rules_1.initRules(rules, config, 'decorators', specVersion);
|
|
62
55
|
const ctx = {
|
|
63
56
|
problems: [],
|
|
64
|
-
oasVersion:
|
|
57
|
+
oasVersion: specVersion,
|
|
65
58
|
refTypes: new Map(),
|
|
66
59
|
visitorsData: {},
|
|
67
60
|
};
|
|
@@ -69,7 +62,7 @@ function bundleDocument(opts) {
|
|
|
69
62
|
decorators.push({
|
|
70
63
|
severity: 'error',
|
|
71
64
|
ruleId: 'remove-unused-components',
|
|
72
|
-
visitor:
|
|
65
|
+
visitor: specMajorVersion === oas_types_1.SpecMajorVersion.OAS2
|
|
73
66
|
? remove_unused_components_1.RemoveUnusedComponents({})
|
|
74
67
|
: remove_unused_components_2.RemoveUnusedComponents({}),
|
|
75
68
|
});
|
|
@@ -98,7 +91,7 @@ function bundleDocument(opts) {
|
|
|
98
91
|
{
|
|
99
92
|
severity: 'error',
|
|
100
93
|
ruleId: 'bundler',
|
|
101
|
-
visitor: makeBundleVisitor(
|
|
94
|
+
visitor: makeBundleVisitor(specMajorVersion, dereference, skipRedoclyRegistryRefs, document, resolvedRefMap, keepUrlRefs),
|
|
102
95
|
},
|
|
103
96
|
...decorators,
|
|
104
97
|
], types);
|
|
@@ -122,7 +115,7 @@ function bundleDocument(opts) {
|
|
|
122
115
|
exports.bundleDocument = bundleDocument;
|
|
123
116
|
function mapTypeToComponent(typeName, version) {
|
|
124
117
|
switch (version) {
|
|
125
|
-
case oas_types_1.
|
|
118
|
+
case oas_types_1.SpecMajorVersion.OAS3:
|
|
126
119
|
switch (typeName) {
|
|
127
120
|
case 'Schema':
|
|
128
121
|
return 'schemas';
|
|
@@ -145,7 +138,7 @@ function mapTypeToComponent(typeName, version) {
|
|
|
145
138
|
default:
|
|
146
139
|
return null;
|
|
147
140
|
}
|
|
148
|
-
case oas_types_1.
|
|
141
|
+
case oas_types_1.SpecMajorVersion.OAS2:
|
|
149
142
|
switch (typeName) {
|
|
150
143
|
case 'Schema':
|
|
151
144
|
return 'definitions';
|
|
@@ -156,6 +149,15 @@ function mapTypeToComponent(typeName, version) {
|
|
|
156
149
|
default:
|
|
157
150
|
return null;
|
|
158
151
|
}
|
|
152
|
+
case oas_types_1.SpecMajorVersion.Async2:
|
|
153
|
+
switch (typeName) {
|
|
154
|
+
case 'Schema':
|
|
155
|
+
return 'schemas';
|
|
156
|
+
case 'Parameter':
|
|
157
|
+
return 'parameters';
|
|
158
|
+
default:
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
159
161
|
}
|
|
160
162
|
}
|
|
161
163
|
exports.mapTypeToComponent = mapTypeToComponent;
|
|
@@ -202,16 +204,16 @@ function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDo
|
|
|
202
204
|
Root: {
|
|
203
205
|
enter(root, ctx) {
|
|
204
206
|
rootLocation = ctx.location;
|
|
205
|
-
if (version === oas_types_1.
|
|
207
|
+
if (version === oas_types_1.SpecMajorVersion.OAS3) {
|
|
206
208
|
components = root.components = root.components || {};
|
|
207
209
|
}
|
|
208
|
-
else if (version === oas_types_1.
|
|
210
|
+
else if (version === oas_types_1.SpecMajorVersion.OAS2) {
|
|
209
211
|
components = root;
|
|
210
212
|
}
|
|
211
213
|
},
|
|
212
214
|
},
|
|
213
215
|
};
|
|
214
|
-
if (version === oas_types_1.
|
|
216
|
+
if (version === oas_types_1.SpecMajorVersion.OAS3) {
|
|
215
217
|
visitor.DiscriminatorMapping = {
|
|
216
218
|
leave(mapping, ctx) {
|
|
217
219
|
for (const name of Object.keys(mapping)) {
|
|
@@ -259,7 +261,7 @@ function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDo
|
|
|
259
261
|
components[componentType] = components[componentType] || {};
|
|
260
262
|
const name = getComponentName(target, componentType, ctx);
|
|
261
263
|
components[componentType][name] = target.node;
|
|
262
|
-
if (version === oas_types_1.
|
|
264
|
+
if (version === oas_types_1.SpecMajorVersion.OAS3) {
|
|
263
265
|
return `#/components/${componentType}/${name}`;
|
|
264
266
|
}
|
|
265
267
|
else {
|
package/lib/config/builtIn.js
CHANGED
|
@@ -6,6 +6,7 @@ const all_1 = require("./all");
|
|
|
6
6
|
const minimal_1 = require("./minimal");
|
|
7
7
|
const oas3_1 = require("../rules/oas3");
|
|
8
8
|
const oas2_1 = require("../rules/oas2");
|
|
9
|
+
const async2_1 = require("../rules/async2");
|
|
9
10
|
const oas3_2 = require("../rules/oas3");
|
|
10
11
|
const oas2_2 = require("../rules/oas2");
|
|
11
12
|
const oas3_3 = require("../decorators/oas3");
|
|
@@ -23,14 +24,17 @@ exports.defaultPlugin = {
|
|
|
23
24
|
rules: {
|
|
24
25
|
oas3: oas3_1.rules,
|
|
25
26
|
oas2: oas2_1.rules,
|
|
27
|
+
async2: async2_1.rules,
|
|
26
28
|
},
|
|
27
29
|
preprocessors: {
|
|
28
30
|
oas3: oas3_2.preprocessors,
|
|
29
31
|
oas2: oas2_2.preprocessors,
|
|
32
|
+
async2: {},
|
|
30
33
|
},
|
|
31
34
|
decorators: {
|
|
32
35
|
oas3: oas3_3.decorators,
|
|
33
36
|
oas2: oas2_3.decorators,
|
|
37
|
+
async2: {},
|
|
34
38
|
},
|
|
35
39
|
configs: exports.builtInConfigs,
|
|
36
40
|
};
|
|
@@ -105,8 +105,8 @@ function resolvePlugins(plugins, configPath = '') {
|
|
|
105
105
|
seenPluginIds.set(id, p.toString());
|
|
106
106
|
const plugin = Object.assign(Object.assign({ id }, (pluginModule.configs ? { configs: pluginModule.configs } : {})), (pluginModule.typeExtension ? { typeExtension: pluginModule.typeExtension } : {}));
|
|
107
107
|
if (pluginModule.rules) {
|
|
108
|
-
if (!pluginModule.rules.oas3 && !pluginModule.rules.oas2) {
|
|
109
|
-
throw new Error(`Plugin rules must have \`oas3\` or \`
|
|
108
|
+
if (!pluginModule.rules.oas3 && !pluginModule.rules.oas2 && !pluginModule.rules.async2) {
|
|
109
|
+
throw new Error(`Plugin rules must have \`oas3\`, \`oas2\` or \`async2\` rules "${p}.`);
|
|
110
110
|
}
|
|
111
111
|
plugin.rules = {};
|
|
112
112
|
if (pluginModule.rules.oas3) {
|
|
@@ -115,10 +115,15 @@ function resolvePlugins(plugins, configPath = '') {
|
|
|
115
115
|
if (pluginModule.rules.oas2) {
|
|
116
116
|
plugin.rules.oas2 = utils_2.prefixRules(pluginModule.rules.oas2, id);
|
|
117
117
|
}
|
|
118
|
+
if (pluginModule.rules.async2) {
|
|
119
|
+
plugin.rules.async2 = utils_2.prefixRules(pluginModule.rules.async2, id);
|
|
120
|
+
}
|
|
118
121
|
}
|
|
119
122
|
if (pluginModule.preprocessors) {
|
|
120
|
-
if (!pluginModule.preprocessors.oas3 &&
|
|
121
|
-
|
|
123
|
+
if (!pluginModule.preprocessors.oas3 &&
|
|
124
|
+
!pluginModule.preprocessors.oas2 &&
|
|
125
|
+
!pluginModule.preprocessors.async2) {
|
|
126
|
+
throw new Error(`Plugin \`preprocessors\` must have \`oas3\`, \`oas2\` or \`async2\` preprocessors "${p}.`);
|
|
122
127
|
}
|
|
123
128
|
plugin.preprocessors = {};
|
|
124
129
|
if (pluginModule.preprocessors.oas3) {
|
|
@@ -127,10 +132,15 @@ function resolvePlugins(plugins, configPath = '') {
|
|
|
127
132
|
if (pluginModule.preprocessors.oas2) {
|
|
128
133
|
plugin.preprocessors.oas2 = utils_2.prefixRules(pluginModule.preprocessors.oas2, id);
|
|
129
134
|
}
|
|
135
|
+
if (pluginModule.preprocessors.async2) {
|
|
136
|
+
plugin.preprocessors.async2 = utils_2.prefixRules(pluginModule.preprocessors.async2, id);
|
|
137
|
+
}
|
|
130
138
|
}
|
|
131
139
|
if (pluginModule.decorators) {
|
|
132
|
-
if (!pluginModule.decorators.oas3 &&
|
|
133
|
-
|
|
140
|
+
if (!pluginModule.decorators.oas3 &&
|
|
141
|
+
!pluginModule.decorators.oas2 &&
|
|
142
|
+
!pluginModule.decorators.async2) {
|
|
143
|
+
throw new Error(`Plugin \`decorators\` must have \`oas3\`, \`oas2\` or \`async2\` decorators "${p}.`);
|
|
134
144
|
}
|
|
135
145
|
plugin.decorators = {};
|
|
136
146
|
if (pluginModule.decorators.oas3) {
|
|
@@ -139,6 +149,9 @@ function resolvePlugins(plugins, configPath = '') {
|
|
|
139
149
|
if (pluginModule.decorators.oas2) {
|
|
140
150
|
plugin.decorators.oas2 = utils_2.prefixRules(pluginModule.decorators.oas2, id);
|
|
141
151
|
}
|
|
152
|
+
if (pluginModule.decorators.async2) {
|
|
153
|
+
plugin.decorators.async2 = utils_2.prefixRules(pluginModule.decorators.async2, id);
|
|
154
|
+
}
|
|
142
155
|
}
|
|
143
156
|
if (pluginModule.assertions) {
|
|
144
157
|
plugin.assertions = pluginModule.assertions;
|
package/lib/config/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NormalizedProblem } from '../walk';
|
|
2
|
-
import {
|
|
2
|
+
import { SpecVersion, SpecMajorVersion, Oas2RuleSet, Oas3RuleSet, Async2RuleSet } from '../oas-types';
|
|
3
3
|
import type { NodeType } from '../types';
|
|
4
4
|
import type { DecoratorConfig, Plugin, PreprocessorConfig, Region, ResolveConfig, ResolvedApi, ResolvedConfig, ResolvedStyleguideConfig, RuleConfig, RuleSettings, Telemetry, ThemeRawConfig } from './types';
|
|
5
5
|
export declare const IGNORE_FILE = ".redocly.lint-ignore.yaml";
|
|
@@ -15,9 +15,9 @@ export declare class StyleguideConfig {
|
|
|
15
15
|
plugins: Plugin[];
|
|
16
16
|
ignore: Record<string, Record<string, Set<string>>>;
|
|
17
17
|
doNotResolveExamples: boolean;
|
|
18
|
-
rules: Record<
|
|
19
|
-
preprocessors: Record<
|
|
20
|
-
decorators: Record<
|
|
18
|
+
rules: Record<SpecVersion, Record<string, RuleConfig>>;
|
|
19
|
+
preprocessors: Record<SpecVersion, Record<string, PreprocessorConfig>>;
|
|
20
|
+
decorators: Record<SpecVersion, Record<string, DecoratorConfig>>;
|
|
21
21
|
private _usedRules;
|
|
22
22
|
private _usedVersions;
|
|
23
23
|
recommendedFallback: boolean;
|
|
@@ -28,16 +28,16 @@ export declare class StyleguideConfig {
|
|
|
28
28
|
saveIgnore(): void;
|
|
29
29
|
addIgnore(problem: NormalizedProblem): void;
|
|
30
30
|
addProblemToIgnore(problem: NormalizedProblem): NormalizedProblem;
|
|
31
|
-
extendTypes(types: Record<string, NodeType>, version:
|
|
32
|
-
getRuleSettings(ruleId: string, oasVersion:
|
|
33
|
-
getPreprocessorSettings(ruleId: string, oasVersion:
|
|
34
|
-
getDecoratorSettings(ruleId: string, oasVersion:
|
|
31
|
+
extendTypes(types: Record<string, NodeType>, version: SpecVersion): Record<string, NodeType>;
|
|
32
|
+
getRuleSettings(ruleId: string, oasVersion: SpecVersion): RuleSettings;
|
|
33
|
+
getPreprocessorSettings(ruleId: string, oasVersion: SpecVersion): RuleSettings;
|
|
34
|
+
getDecoratorSettings(ruleId: string, oasVersion: SpecVersion): RuleSettings;
|
|
35
35
|
getUnusedRules(): {
|
|
36
36
|
rules: string[];
|
|
37
37
|
preprocessors: string[];
|
|
38
38
|
decorators: string[];
|
|
39
39
|
};
|
|
40
|
-
getRulesForOasVersion(version:
|
|
40
|
+
getRulesForOasVersion(version: SpecMajorVersion): Oas3RuleSet[] | Oas2RuleSet[] | Async2RuleSet[];
|
|
41
41
|
skipRules(rules?: string[]): void;
|
|
42
42
|
skipPreprocessors(preprocessors?: string[]): void;
|
|
43
43
|
skipDecorators(decorators?: string[]): void;
|
package/lib/config/config.js
CHANGED
|
@@ -51,19 +51,22 @@ class StyleguideConfig {
|
|
|
51
51
|
this.doNotResolveExamples = !!rawConfig.doNotResolveExamples;
|
|
52
52
|
this.recommendedFallback = rawConfig.recommendedFallback || false;
|
|
53
53
|
this.rules = {
|
|
54
|
-
[oas_types_1.
|
|
55
|
-
[oas_types_1.
|
|
56
|
-
[oas_types_1.
|
|
54
|
+
[oas_types_1.SpecVersion.OAS2]: Object.assign(Object.assign({}, rawConfig.rules), rawConfig.oas2Rules),
|
|
55
|
+
[oas_types_1.SpecVersion.OAS3_0]: Object.assign(Object.assign({}, rawConfig.rules), rawConfig.oas3_0Rules),
|
|
56
|
+
[oas_types_1.SpecVersion.OAS3_1]: Object.assign(Object.assign({}, rawConfig.rules), rawConfig.oas3_1Rules),
|
|
57
|
+
[oas_types_1.SpecVersion.Async2]: Object.assign(Object.assign({}, rawConfig.rules), rawConfig.async2Rules),
|
|
57
58
|
};
|
|
58
59
|
this.preprocessors = {
|
|
59
|
-
[oas_types_1.
|
|
60
|
-
[oas_types_1.
|
|
61
|
-
[oas_types_1.
|
|
60
|
+
[oas_types_1.SpecVersion.OAS2]: Object.assign(Object.assign({}, rawConfig.preprocessors), rawConfig.oas2Preprocessors),
|
|
61
|
+
[oas_types_1.SpecVersion.OAS3_0]: Object.assign(Object.assign({}, rawConfig.preprocessors), rawConfig.oas3_0Preprocessors),
|
|
62
|
+
[oas_types_1.SpecVersion.OAS3_1]: Object.assign(Object.assign({}, rawConfig.preprocessors), rawConfig.oas3_1Preprocessors),
|
|
63
|
+
[oas_types_1.SpecVersion.Async2]: Object.assign(Object.assign({}, rawConfig.preprocessors), rawConfig.async2Preprocessors),
|
|
62
64
|
};
|
|
63
65
|
this.decorators = {
|
|
64
|
-
[oas_types_1.
|
|
65
|
-
[oas_types_1.
|
|
66
|
-
[oas_types_1.
|
|
66
|
+
[oas_types_1.SpecVersion.OAS2]: Object.assign(Object.assign({}, rawConfig.decorators), rawConfig.oas2Decorators),
|
|
67
|
+
[oas_types_1.SpecVersion.OAS3_0]: Object.assign(Object.assign({}, rawConfig.decorators), rawConfig.oas3_0Decorators),
|
|
68
|
+
[oas_types_1.SpecVersion.OAS3_1]: Object.assign(Object.assign({}, rawConfig.decorators), rawConfig.oas3_1Decorators),
|
|
69
|
+
[oas_types_1.SpecVersion.Async2]: Object.assign(Object.assign({}, rawConfig.decorators), rawConfig.async2Decorators),
|
|
67
70
|
};
|
|
68
71
|
this.extendPaths = rawConfig.extendPaths || [];
|
|
69
72
|
this.pluginPaths = rawConfig.pluginPaths || [];
|
|
@@ -124,17 +127,22 @@ class StyleguideConfig {
|
|
|
124
127
|
for (const plugin of this.plugins) {
|
|
125
128
|
if (plugin.typeExtension !== undefined) {
|
|
126
129
|
switch (version) {
|
|
127
|
-
case oas_types_1.
|
|
128
|
-
case oas_types_1.
|
|
130
|
+
case oas_types_1.SpecVersion.OAS3_0:
|
|
131
|
+
case oas_types_1.SpecVersion.OAS3_1:
|
|
129
132
|
if (!plugin.typeExtension.oas3)
|
|
130
133
|
continue;
|
|
131
134
|
extendedTypes = plugin.typeExtension.oas3(extendedTypes, version);
|
|
132
135
|
break;
|
|
133
|
-
case oas_types_1.
|
|
136
|
+
case oas_types_1.SpecVersion.OAS2:
|
|
134
137
|
if (!plugin.typeExtension.oas2)
|
|
135
138
|
continue;
|
|
136
139
|
extendedTypes = plugin.typeExtension.oas2(extendedTypes, version);
|
|
137
140
|
break;
|
|
141
|
+
case oas_types_1.SpecVersion.Async2:
|
|
142
|
+
if (!plugin.typeExtension.async2)
|
|
143
|
+
continue;
|
|
144
|
+
extendedTypes = plugin.typeExtension.async2(extendedTypes, version);
|
|
145
|
+
break;
|
|
138
146
|
default:
|
|
139
147
|
throw new Error('Not implemented');
|
|
140
148
|
}
|
|
@@ -198,25 +206,32 @@ class StyleguideConfig {
|
|
|
198
206
|
}
|
|
199
207
|
getRulesForOasVersion(version) {
|
|
200
208
|
switch (version) {
|
|
201
|
-
case oas_types_1.
|
|
209
|
+
case oas_types_1.SpecMajorVersion.OAS3:
|
|
202
210
|
// eslint-disable-next-line no-case-declarations
|
|
203
211
|
const oas3Rules = []; // default ruleset
|
|
204
212
|
this.plugins.forEach((p) => { var _a; return ((_a = p.preprocessors) === null || _a === void 0 ? void 0 : _a.oas3) && oas3Rules.push(p.preprocessors.oas3); });
|
|
205
213
|
this.plugins.forEach((p) => { var _a; return ((_a = p.rules) === null || _a === void 0 ? void 0 : _a.oas3) && oas3Rules.push(p.rules.oas3); });
|
|
206
214
|
this.plugins.forEach((p) => { var _a; return ((_a = p.decorators) === null || _a === void 0 ? void 0 : _a.oas3) && oas3Rules.push(p.decorators.oas3); });
|
|
207
215
|
return oas3Rules;
|
|
208
|
-
case oas_types_1.
|
|
216
|
+
case oas_types_1.SpecMajorVersion.OAS2:
|
|
209
217
|
// eslint-disable-next-line no-case-declarations
|
|
210
218
|
const oas2Rules = []; // default ruleset
|
|
211
219
|
this.plugins.forEach((p) => { var _a; return ((_a = p.preprocessors) === null || _a === void 0 ? void 0 : _a.oas2) && oas2Rules.push(p.preprocessors.oas2); });
|
|
212
220
|
this.plugins.forEach((p) => { var _a; return ((_a = p.rules) === null || _a === void 0 ? void 0 : _a.oas2) && oas2Rules.push(p.rules.oas2); });
|
|
213
221
|
this.plugins.forEach((p) => { var _a; return ((_a = p.decorators) === null || _a === void 0 ? void 0 : _a.oas2) && oas2Rules.push(p.decorators.oas2); });
|
|
214
222
|
return oas2Rules;
|
|
223
|
+
case oas_types_1.SpecMajorVersion.Async2:
|
|
224
|
+
// eslint-disable-next-line no-case-declarations
|
|
225
|
+
const asyncApiRules = []; // default ruleset
|
|
226
|
+
this.plugins.forEach((p) => { var _a; return ((_a = p.preprocessors) === null || _a === void 0 ? void 0 : _a.async2) && asyncApiRules.push(p.preprocessors.async2); });
|
|
227
|
+
this.plugins.forEach((p) => { var _a; return ((_a = p.rules) === null || _a === void 0 ? void 0 : _a.async2) && asyncApiRules.push(p.rules.async2); });
|
|
228
|
+
this.plugins.forEach((p) => { var _a; return ((_a = p.decorators) === null || _a === void 0 ? void 0 : _a.async2) && asyncApiRules.push(p.decorators.async2); });
|
|
229
|
+
return asyncApiRules;
|
|
215
230
|
}
|
|
216
231
|
}
|
|
217
232
|
skipRules(rules) {
|
|
218
233
|
for (const ruleId of rules || []) {
|
|
219
|
-
for (const version of Object.values(oas_types_1.
|
|
234
|
+
for (const version of Object.values(oas_types_1.SpecVersion)) {
|
|
220
235
|
if (this.rules[version][ruleId]) {
|
|
221
236
|
this.rules[version][ruleId] = 'off';
|
|
222
237
|
}
|
|
@@ -225,7 +240,7 @@ class StyleguideConfig {
|
|
|
225
240
|
}
|
|
226
241
|
skipPreprocessors(preprocessors) {
|
|
227
242
|
for (const preprocessorId of preprocessors || []) {
|
|
228
|
-
for (const version of Object.values(oas_types_1.
|
|
243
|
+
for (const version of Object.values(oas_types_1.SpecVersion)) {
|
|
229
244
|
if (this.preprocessors[version][preprocessorId]) {
|
|
230
245
|
this.preprocessors[version][preprocessorId] = 'off';
|
|
231
246
|
}
|
|
@@ -234,7 +249,7 @@ class StyleguideConfig {
|
|
|
234
249
|
}
|
|
235
250
|
skipDecorators(decorators) {
|
|
236
251
|
for (const decoratorId of decorators || []) {
|
|
237
|
-
for (const version of Object.values(oas_types_1.
|
|
252
|
+
for (const version of Object.values(oas_types_1.SpecVersion)) {
|
|
238
253
|
if (this.decorators[version][decoratorId]) {
|
|
239
254
|
this.decorators[version][decoratorId] = 'off';
|
|
240
255
|
}
|
package/lib/config/rules.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RuleSet,
|
|
1
|
+
import { RuleSet, SpecVersion } from '../oas-types';
|
|
2
2
|
import { StyleguideConfig } from './config';
|
|
3
3
|
import type { ProblemSeverity } from '../walk';
|
|
4
4
|
declare type InitializedRule = {
|
|
@@ -6,5 +6,5 @@ declare type InitializedRule = {
|
|
|
6
6
|
ruleId: string;
|
|
7
7
|
visitor: any;
|
|
8
8
|
};
|
|
9
|
-
export declare function initRules<T extends Function, P extends RuleSet<T>>(rules: P[], config: StyleguideConfig, type: 'rules' | 'preprocessors' | 'decorators', oasVersion:
|
|
9
|
+
export declare function initRules<T extends Function, P extends RuleSet<T>>(rules: P[], config: StyleguideConfig, type: 'rules' | 'preprocessors' | 'decorators', oasVersion: SpecVersion): InitializedRule[];
|
|
10
10
|
export {};
|
package/lib/config/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ProblemSeverity, UserContext } from '../walk';
|
|
2
|
-
import type { Oas3PreprocessorsSet,
|
|
2
|
+
import type { Oas3PreprocessorsSet, SpecMajorVersion, Oas3DecoratorsSet, Oas2RuleSet, Oas2PreprocessorsSet, Oas2DecoratorsSet, Oas3RuleSet, SpecVersion, Async2PreprocessorsSet, Async2DecoratorsSet, Async2RuleSet } from '../oas-types';
|
|
3
3
|
import type { NodeType } from '../types';
|
|
4
4
|
import { Location } from '../ref-utils';
|
|
5
5
|
import type { SkipFunctionContext } from '../visitors';
|
|
@@ -24,14 +24,17 @@ export declare type StyleguideRawConfig = {
|
|
|
24
24
|
oas2Rules?: Record<string, RuleConfig>;
|
|
25
25
|
oas3_0Rules?: Record<string, RuleConfig>;
|
|
26
26
|
oas3_1Rules?: Record<string, RuleConfig>;
|
|
27
|
+
async2Rules?: Record<string, RuleConfig>;
|
|
27
28
|
preprocessors?: Record<string, PreprocessorConfig>;
|
|
28
29
|
oas2Preprocessors?: Record<string, PreprocessorConfig>;
|
|
29
30
|
oas3_0Preprocessors?: Record<string, PreprocessorConfig>;
|
|
30
31
|
oas3_1Preprocessors?: Record<string, PreprocessorConfig>;
|
|
32
|
+
async2Preprocessors?: Record<string, PreprocessorConfig>;
|
|
31
33
|
decorators?: Record<string, DecoratorConfig>;
|
|
32
34
|
oas2Decorators?: Record<string, DecoratorConfig>;
|
|
33
35
|
oas3_0Decorators?: Record<string, DecoratorConfig>;
|
|
34
36
|
oas3_1Decorators?: Record<string, DecoratorConfig>;
|
|
37
|
+
async2Decorators?: Record<string, DecoratorConfig>;
|
|
35
38
|
};
|
|
36
39
|
export declare type ApiStyleguideRawConfig = Omit<StyleguideRawConfig, 'plugins'>;
|
|
37
40
|
export declare type ResolvedStyleguideConfig = PluginStyleguideConfig & {
|
|
@@ -44,16 +47,19 @@ export declare type ResolvedStyleguideConfig = PluginStyleguideConfig & {
|
|
|
44
47
|
export declare type PreprocessorsConfig = {
|
|
45
48
|
oas3?: Oas3PreprocessorsSet;
|
|
46
49
|
oas2?: Oas2PreprocessorsSet;
|
|
50
|
+
async2?: Async2PreprocessorsSet;
|
|
47
51
|
};
|
|
48
52
|
export declare type DecoratorsConfig = {
|
|
49
53
|
oas3?: Oas3DecoratorsSet;
|
|
50
54
|
oas2?: Oas2DecoratorsSet;
|
|
55
|
+
async2?: Async2DecoratorsSet;
|
|
51
56
|
};
|
|
52
|
-
export declare type TypesExtensionFn = (types: Record<string, NodeType>, oasVersion:
|
|
53
|
-
export declare type TypeExtensionsConfig = Partial<Record<
|
|
57
|
+
export declare type TypesExtensionFn = (types: Record<string, NodeType>, oasVersion: SpecVersion) => Record<string, NodeType>;
|
|
58
|
+
export declare type TypeExtensionsConfig = Partial<Record<SpecMajorVersion, TypesExtensionFn>>;
|
|
54
59
|
export declare type CustomRulesConfig = {
|
|
55
60
|
oas3?: Oas3RuleSet;
|
|
56
61
|
oas2?: Oas2RuleSet;
|
|
62
|
+
async2?: Async2RuleSet;
|
|
57
63
|
};
|
|
58
64
|
export declare type AssertionContext = Partial<UserContext> & SkipFunctionContext & {
|
|
59
65
|
node: any;
|
package/lib/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { RedoclyClient, isRedoclyRegistryURL } from './redocly';
|
|
|
13
13
|
export { Source, BaseResolver, Document, resolveDocument, ResolveError, YamlParseError, makeDocumentFromString, } from './resolve';
|
|
14
14
|
export { parseYaml, stringifyYaml } from './js-yaml';
|
|
15
15
|
export { unescapePointer, isRef, isAbsoluteUrl } from './ref-utils';
|
|
16
|
-
export {
|
|
16
|
+
export { SpecMajorVersion, getMajorSpecVersion, SpecVersion, detectSpec, getTypes, } from './oas-types';
|
|
17
17
|
export { normalizeVisitors } from './visitors';
|
|
18
18
|
export { WalkContext, walkDocument, NormalizedProblem, ProblemSeverity, LineColLocationObject, LocationObject, Loc, } from './walk';
|
|
19
19
|
export { getAstNodeByPointer, getLineColLocation } from './format/codeframes';
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.mapTypeToComponent = void 0;
|
|
3
|
+
exports.bundle = exports.lintConfig = exports.lintFromString = exports.lintDocument = exports.validate = exports.lint = exports.getTotals = exports.formatProblems = exports.getLineColLocation = exports.getAstNodeByPointer = exports.walkDocument = exports.normalizeVisitors = exports.getTypes = exports.detectSpec = exports.SpecVersion = exports.getMajorSpecVersion = exports.SpecMajorVersion = exports.isAbsoluteUrl = exports.isRef = exports.unescapePointer = exports.stringifyYaml = exports.parseYaml = exports.makeDocumentFromString = exports.YamlParseError = exports.ResolveError = exports.resolveDocument = exports.BaseResolver = exports.Source = exports.isRedoclyRegistryURL = exports.RedoclyClient = exports.createConfig = exports.CONFIG_FILE_NAMES = exports.findConfig = exports.getConfig = exports.loadConfig = exports.transformConfig = exports.getMergedConfig = exports.IGNORE_FILE = exports.StyleguideConfig = exports.Config = exports.Stats = exports.normalizeTypes = exports.ConfigTypes = exports.Oas2Types = exports.Oas3Types = exports.Oas3_1Types = exports.isTruthy = exports.doesYamlFileExist = exports.slash = exports.readFileFromUrl = void 0;
|
|
4
|
+
exports.mapTypeToComponent = exports.bundleDocument = void 0;
|
|
5
5
|
var utils_1 = require("./utils");
|
|
6
6
|
Object.defineProperty(exports, "readFileFromUrl", { enumerable: true, get: function () { return utils_1.readFileFromUrl; } });
|
|
7
7
|
Object.defineProperty(exports, "slash", { enumerable: true, get: function () { return utils_1.slash; } });
|
|
@@ -48,10 +48,11 @@ Object.defineProperty(exports, "unescapePointer", { enumerable: true, get: funct
|
|
|
48
48
|
Object.defineProperty(exports, "isRef", { enumerable: true, get: function () { return ref_utils_1.isRef; } });
|
|
49
49
|
Object.defineProperty(exports, "isAbsoluteUrl", { enumerable: true, get: function () { return ref_utils_1.isAbsoluteUrl; } });
|
|
50
50
|
var oas_types_1 = require("./oas-types");
|
|
51
|
-
Object.defineProperty(exports, "
|
|
52
|
-
Object.defineProperty(exports, "
|
|
53
|
-
Object.defineProperty(exports, "
|
|
54
|
-
Object.defineProperty(exports, "
|
|
51
|
+
Object.defineProperty(exports, "SpecMajorVersion", { enumerable: true, get: function () { return oas_types_1.SpecMajorVersion; } });
|
|
52
|
+
Object.defineProperty(exports, "getMajorSpecVersion", { enumerable: true, get: function () { return oas_types_1.getMajorSpecVersion; } });
|
|
53
|
+
Object.defineProperty(exports, "SpecVersion", { enumerable: true, get: function () { return oas_types_1.SpecVersion; } });
|
|
54
|
+
Object.defineProperty(exports, "detectSpec", { enumerable: true, get: function () { return oas_types_1.detectSpec; } });
|
|
55
|
+
Object.defineProperty(exports, "getTypes", { enumerable: true, get: function () { return oas_types_1.getTypes; } });
|
|
55
56
|
var visitors_1 = require("./visitors");
|
|
56
57
|
Object.defineProperty(exports, "normalizeVisitors", { enumerable: true, get: function () { return visitors_1.normalizeVisitors; } });
|
|
57
58
|
var walk_1 = require("./walk");
|
package/lib/lint.js
CHANGED
|
@@ -12,9 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.lintConfig = exports.lintDocument = exports.lintFromString = exports.lint = void 0;
|
|
13
13
|
const resolve_1 = require("./resolve");
|
|
14
14
|
const visitors_1 = require("./visitors");
|
|
15
|
-
const oas3_1_1 = require("./types/oas3_1");
|
|
16
|
-
const oas3_1 = require("./types/oas3");
|
|
17
|
-
const oas2_1 = require("./types/oas2");
|
|
18
15
|
const walk_1 = require("./walk");
|
|
19
16
|
const config_1 = require("./config");
|
|
20
17
|
const types_1 = require("./types");
|
|
@@ -42,21 +39,17 @@ function lintDocument(opts) {
|
|
|
42
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
40
|
ajv_1.releaseAjvInstance(); // FIXME: preprocessors can modify nodes which are then cached to ajv-instance by absolute path
|
|
44
41
|
const { document, customTypes, externalRefResolver, config } = opts;
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const rules = config.getRulesForOasVersion(
|
|
48
|
-
const types = types_1.normalizeTypes(config.extendTypes(
|
|
49
|
-
? oasVersion === oas_types_1.OasVersion.Version3_1
|
|
50
|
-
? oas3_1_1.Oas3_1Types
|
|
51
|
-
: oas3_1.Oas3Types
|
|
52
|
-
: oas2_1.Oas2Types, oasVersion), config);
|
|
42
|
+
const specVersion = oas_types_1.detectSpec(document.parsed);
|
|
43
|
+
const specMajorVersion = oas_types_1.getMajorSpecVersion(specVersion);
|
|
44
|
+
const rules = config.getRulesForOasVersion(specMajorVersion);
|
|
45
|
+
const types = types_1.normalizeTypes(config.extendTypes(customTypes !== null && customTypes !== void 0 ? customTypes : oas_types_1.getTypes(specVersion), specVersion), config);
|
|
53
46
|
const ctx = {
|
|
54
47
|
problems: [],
|
|
55
|
-
oasVersion:
|
|
48
|
+
oasVersion: specVersion,
|
|
56
49
|
visitorsData: {},
|
|
57
50
|
};
|
|
58
|
-
const preprocessors = config_1.initRules(rules, config, 'preprocessors',
|
|
59
|
-
const regularRules = config_1.initRules(rules, config, 'rules',
|
|
51
|
+
const preprocessors = config_1.initRules(rules, config, 'preprocessors', specVersion);
|
|
52
|
+
const regularRules = config_1.initRules(rules, config, 'rules', specVersion);
|
|
60
53
|
let resolvedRefMap = yield resolve_1.resolveDocument({
|
|
61
54
|
rootDocument: document,
|
|
62
55
|
rootType: types.Root,
|
|
@@ -94,7 +87,7 @@ function lintConfig(opts) {
|
|
|
94
87
|
const { document, severity } = opts;
|
|
95
88
|
const ctx = {
|
|
96
89
|
problems: [],
|
|
97
|
-
oasVersion: oas_types_1.
|
|
90
|
+
oasVersion: oas_types_1.SpecVersion.OAS3_0,
|
|
98
91
|
visitorsData: {},
|
|
99
92
|
};
|
|
100
93
|
const plugins = config_1.resolvePlugins([config_1.defaultPlugin]);
|
|
@@ -107,9 +100,10 @@ function lintConfig(opts) {
|
|
|
107
100
|
{
|
|
108
101
|
severity: severity || 'error',
|
|
109
102
|
ruleId: 'configuration spec',
|
|
110
|
-
visitor: spec_1.
|
|
103
|
+
visitor: spec_1.Spec({ severity: 'error' }),
|
|
111
104
|
},
|
|
112
105
|
];
|
|
106
|
+
// TODO: check why any is needed
|
|
113
107
|
const normalizedVisitors = visitors_1.normalizeVisitors(rules, types);
|
|
114
108
|
walk_1.walkDocument({
|
|
115
109
|
document,
|
package/lib/oas-types.d.ts
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
import { Oas3Rule, Oas3Preprocessor, Oas2Rule, Oas2Preprocessor } from './visitors';
|
|
1
|
+
import { Oas3Rule, Oas3Preprocessor, Oas2Rule, Oas2Preprocessor, Async2Preprocessor, Async2Rule } from './visitors';
|
|
2
2
|
export declare type RuleSet<T> = Record<string, T>;
|
|
3
|
-
export declare enum
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export declare enum SpecVersion {
|
|
4
|
+
OAS2 = "oas2",
|
|
5
|
+
OAS3_0 = "oas3_0",
|
|
6
|
+
OAS3_1 = "oas3_1",
|
|
7
|
+
Async2 = "async2"
|
|
7
8
|
}
|
|
8
|
-
export declare enum
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
export declare enum SpecMajorVersion {
|
|
10
|
+
OAS2 = "oas2",
|
|
11
|
+
OAS3 = "oas3",
|
|
12
|
+
Async2 = "async2"
|
|
11
13
|
}
|
|
12
14
|
export declare type Oas3RuleSet = Record<string, Oas3Rule>;
|
|
13
15
|
export declare type Oas2RuleSet = Record<string, Oas2Rule>;
|
|
16
|
+
export declare type Async2RuleSet = Record<string, Async2Rule>;
|
|
14
17
|
export declare type Oas3PreprocessorsSet = Record<string, Oas3Preprocessor>;
|
|
15
18
|
export declare type Oas2PreprocessorsSet = Record<string, Oas2Preprocessor>;
|
|
19
|
+
export declare type Async2PreprocessorsSet = Record<string, Async2Preprocessor>;
|
|
16
20
|
export declare type Oas3DecoratorsSet = Record<string, Oas3Preprocessor>;
|
|
17
21
|
export declare type Oas2DecoratorsSet = Record<string, Oas2Preprocessor>;
|
|
18
|
-
export declare
|
|
19
|
-
export declare function
|
|
22
|
+
export declare type Async2DecoratorsSet = Record<string, Async2Preprocessor>;
|
|
23
|
+
export declare function detectSpec(root: any): SpecVersion;
|
|
24
|
+
export declare function getMajorSpecVersion(version: SpecVersion): SpecMajorVersion;
|
|
25
|
+
export declare function getTypes(spec: SpecVersion): Record<string, import("./types").NodeType>;
|