@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
|
@@ -61,6 +61,8 @@ const builtInRulesList = [
|
|
|
61
61
|
'required-string-property-missing-min-length',
|
|
62
62
|
'spec-strict-refs',
|
|
63
63
|
'component-name-unique',
|
|
64
|
+
'channels-kebab-case',
|
|
65
|
+
'no-channel-trailing-slash',
|
|
64
66
|
];
|
|
65
67
|
const nodeTypesList = [
|
|
66
68
|
'any',
|
|
@@ -122,6 +124,7 @@ const nodeTypesList = [
|
|
|
122
124
|
'XCodeSampleList',
|
|
123
125
|
'WebhooksMap',
|
|
124
126
|
'SpecExtension',
|
|
127
|
+
'Message',
|
|
125
128
|
];
|
|
126
129
|
const ConfigStyleguide = {
|
|
127
130
|
properties: {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface Async2Definition {
|
|
2
|
+
asyncapi: string;
|
|
3
|
+
info?: Async2Info;
|
|
4
|
+
}
|
|
5
|
+
export interface Async2Info {
|
|
6
|
+
title: string;
|
|
7
|
+
version: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
termsOfService?: string;
|
|
10
|
+
contact?: Async2Contact;
|
|
11
|
+
license?: Async2License;
|
|
12
|
+
}
|
|
13
|
+
export interface Async2Contact {
|
|
14
|
+
name?: string;
|
|
15
|
+
url?: string;
|
|
16
|
+
email?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface Async2License {
|
|
19
|
+
name: string;
|
|
20
|
+
url?: string;
|
|
21
|
+
}
|
package/lib/visitors.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { NormalizedNodeType } from './types';
|
|
|
4
4
|
import type { Stack } from './utils';
|
|
5
5
|
import type { UserContext, ResolveResult, ProblemSeverity } from './walk';
|
|
6
6
|
import type { Location } from './ref-utils';
|
|
7
|
+
import { Async2Definition } from './typings/asyncapi';
|
|
7
8
|
export declare type SkipFunctionContext = Pick<UserContext, 'location' | 'rawNode' | 'resolve' | 'rawLocation'>;
|
|
8
9
|
export declare type VisitFunction<T> = (node: T, ctx: UserContext & {
|
|
9
10
|
ignoreNextVisitorsOnNode: () => void;
|
|
@@ -134,16 +135,24 @@ declare type Oas2FlatVisitor = {
|
|
|
134
135
|
SecurityScheme?: VisitFunctionOrObject<Oas2SecurityScheme>;
|
|
135
136
|
SpecExtension?: VisitFunctionOrObject<unknown>;
|
|
136
137
|
};
|
|
138
|
+
declare type Async2FlatVisitor = {
|
|
139
|
+
Root?: VisitFunctionOrObject<Async2Definition>;
|
|
140
|
+
};
|
|
137
141
|
declare type Oas3NestedVisitor = {
|
|
138
142
|
[T in keyof Oas3FlatVisitor]: Oas3FlatVisitor[T] extends Function ? Oas3FlatVisitor[T] : Oas3FlatVisitor[T] & NestedVisitor<Oas3NestedVisitor>;
|
|
139
143
|
};
|
|
140
144
|
declare type Oas2NestedVisitor = {
|
|
141
145
|
[T in keyof Oas2FlatVisitor]: Oas2FlatVisitor[T] extends Function ? Oas2FlatVisitor[T] : Oas2FlatVisitor[T] & NestedVisitor<Oas2NestedVisitor>;
|
|
142
146
|
};
|
|
147
|
+
declare type Async2NestedVisitor = {
|
|
148
|
+
[T in keyof Async2FlatVisitor]: Async2FlatVisitor[T] extends Function ? Async2FlatVisitor[T] : Async2FlatVisitor[T] & NestedVisitor<Async2NestedVisitor>;
|
|
149
|
+
};
|
|
143
150
|
export declare type Oas3Visitor = BaseVisitor & Oas3NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas3NestedVisitor>>;
|
|
144
151
|
export declare type Oas2Visitor = BaseVisitor & Oas2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas2NestedVisitor>>;
|
|
152
|
+
export declare type Async2Visitor = BaseVisitor & Async2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Async2NestedVisitor>>;
|
|
145
153
|
export declare type Oas3TransformVisitor = BaseVisitor & Oas3FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
|
|
146
154
|
export declare type Oas2TransformVisitor = BaseVisitor & Oas2FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
|
|
155
|
+
export declare type Async2TransformVisitor = BaseVisitor & Async2FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
|
|
147
156
|
export declare type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | 'Root'>;
|
|
148
157
|
export declare type NormalizedOasVisitors<T extends BaseVisitor> = {
|
|
149
158
|
[V in keyof T]-?: {
|
|
@@ -162,10 +171,13 @@ export declare type NormalizedOasVisitors<T extends BaseVisitor> = {
|
|
|
162
171
|
};
|
|
163
172
|
export declare type Oas3Rule = (options: Record<string, any>) => Oas3Visitor | Oas3Visitor[];
|
|
164
173
|
export declare type Oas2Rule = (options: Record<string, any>) => Oas2Visitor | Oas2Visitor[];
|
|
174
|
+
export declare type Async2Rule = (options: Record<string, any>) => Async2Visitor | Async2Visitor[];
|
|
165
175
|
export declare type Oas3Preprocessor = (options: Record<string, any>) => Oas3TransformVisitor;
|
|
166
176
|
export declare type Oas2Preprocessor = (options: Record<string, any>) => Oas2TransformVisitor;
|
|
177
|
+
export declare type Async2Preprocessor = (options: Record<string, any>) => Async2TransformVisitor;
|
|
167
178
|
export declare type Oas3Decorator = (options: Record<string, any>) => Oas3TransformVisitor;
|
|
168
179
|
export declare type Oas2Decorator = (options: Record<string, any>) => Oas2TransformVisitor;
|
|
180
|
+
export declare type Async2Decorator = (options: Record<string, any>) => Async2TransformVisitor;
|
|
169
181
|
export declare type OasRule = Oas3Rule;
|
|
170
182
|
export declare type OasPreprocessor = Oas3Preprocessor;
|
|
171
183
|
export declare type OasDecorator = Oas3Decorator;
|
package/lib/walk.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { NormalizedNodeType } from './types';
|
|
|
5
5
|
import type { RuleSeverity } from './config';
|
|
6
6
|
import { Location } from './ref-utils';
|
|
7
7
|
import { ResolveError, YamlParseError, Source } from './resolve';
|
|
8
|
-
import {
|
|
8
|
+
import { SpecVersion } from './oas-types';
|
|
9
9
|
declare type NonUndefined = string | number | boolean | symbol | bigint | object | Record<string, any>;
|
|
10
10
|
export declare type ResolveResult<T extends NonUndefined> = {
|
|
11
11
|
node: T;
|
|
@@ -27,7 +27,7 @@ export declare type UserContext = {
|
|
|
27
27
|
type: NormalizedNodeType;
|
|
28
28
|
key: string | number;
|
|
29
29
|
parent: any;
|
|
30
|
-
oasVersion:
|
|
30
|
+
oasVersion: SpecVersion;
|
|
31
31
|
getVisitorData: () => Record<string, unknown>;
|
|
32
32
|
};
|
|
33
33
|
export declare type Loc = {
|
|
@@ -65,7 +65,7 @@ export declare type NormalizedProblem = {
|
|
|
65
65
|
};
|
|
66
66
|
export declare type WalkContext = {
|
|
67
67
|
problems: NormalizedProblem[];
|
|
68
|
-
oasVersion:
|
|
68
|
+
oasVersion: SpecVersion;
|
|
69
69
|
visitorsData: Record<string, Record<string, unknown>>;
|
|
70
70
|
refTypes?: Map<string, NormalizedNodeType>;
|
|
71
71
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/openapi-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"Swagger",
|
|
27
27
|
"OpenAPI linter",
|
|
28
28
|
"Swagger linter",
|
|
29
|
+
"AsyncAPI linter",
|
|
29
30
|
"oas"
|
|
30
31
|
],
|
|
31
32
|
"contributors": [
|
|
@@ -5,7 +5,7 @@ import { lintFromString, lintConfig, lintDocument } from '../lint';
|
|
|
5
5
|
import { BaseResolver } from '../resolve';
|
|
6
6
|
import { loadConfig } from '../config/load';
|
|
7
7
|
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../__tests__/utils';
|
|
8
|
-
import {
|
|
8
|
+
import { detectSpec } from '../oas-types';
|
|
9
9
|
|
|
10
10
|
describe('lint', () => {
|
|
11
11
|
it('lintFromString should work', async () => {
|
|
@@ -61,12 +61,12 @@ describe('lint', () => {
|
|
|
61
61
|
path-http-verbs-order: error
|
|
62
62
|
boolean-parameter-prefixes: off
|
|
63
63
|
rule/operation-summary-length:
|
|
64
|
-
subject:
|
|
64
|
+
subject:
|
|
65
65
|
type: Operation
|
|
66
66
|
property: summary
|
|
67
67
|
message: Operation summary should start with an active verb
|
|
68
68
|
assertions:
|
|
69
|
-
local/checkWordsCount:
|
|
69
|
+
local/checkWordsCount:
|
|
70
70
|
min: 3
|
|
71
71
|
theme:
|
|
72
72
|
openapi:
|
|
@@ -189,8 +189,8 @@ describe('lint', () => {
|
|
|
189
189
|
it('lintConfig should work with legacy fields - referenceDocs', async () => {
|
|
190
190
|
const document = parseYamlToDocument(
|
|
191
191
|
outdent`
|
|
192
|
-
apis:
|
|
193
|
-
entry:
|
|
192
|
+
apis:
|
|
193
|
+
entry:
|
|
194
194
|
root: ./file.yaml
|
|
195
195
|
rules:
|
|
196
196
|
operation-2xx-response: warn
|
|
@@ -304,11 +304,41 @@ describe('lint', () => {
|
|
|
304
304
|
`,
|
|
305
305
|
''
|
|
306
306
|
);
|
|
307
|
-
expect(() =>
|
|
307
|
+
expect(() => detectSpec(testDocument.parsed)).toThrow(
|
|
308
308
|
`Invalid OpenAPI version: should be a string but got "number"`
|
|
309
309
|
);
|
|
310
310
|
});
|
|
311
311
|
|
|
312
|
+
it('detect unsupported OpenAPI version', () => {
|
|
313
|
+
const testDocument = parseYamlToDocument(
|
|
314
|
+
outdent`
|
|
315
|
+
openapi: 1.0.4
|
|
316
|
+
`,
|
|
317
|
+
''
|
|
318
|
+
);
|
|
319
|
+
expect(() => detectSpec(testDocument.parsed)).toThrow(`Unsupported OpenAPI version: 1.0.4`);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it('detect unsupported AsyncAPI version', () => {
|
|
323
|
+
const testDocument = parseYamlToDocument(
|
|
324
|
+
outdent`
|
|
325
|
+
asyncapi: 1.0.4
|
|
326
|
+
`,
|
|
327
|
+
''
|
|
328
|
+
);
|
|
329
|
+
expect(() => detectSpec(testDocument.parsed)).toThrow(`Unsupported AsyncAPI version: 1.0.4`);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it('detect unsupported spec format', () => {
|
|
333
|
+
const testDocument = parseYamlToDocument(
|
|
334
|
+
outdent`
|
|
335
|
+
notapi: 3.1.0
|
|
336
|
+
`,
|
|
337
|
+
''
|
|
338
|
+
);
|
|
339
|
+
expect(() => detectSpec(testDocument.parsed)).toThrow(`Unsupported specification`);
|
|
340
|
+
});
|
|
341
|
+
|
|
312
342
|
it("spec rule shouldn't throw an error for named callback", async () => {
|
|
313
343
|
const document = parseYamlToDocument(
|
|
314
344
|
outdent`
|
package/src/bundle.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import isEqual = require('lodash.isequal');
|
|
2
2
|
import { BaseResolver, resolveDocument, Document, ResolvedRefMap, makeRefId } from './resolve';
|
|
3
3
|
import { Oas3Rule, normalizeVisitors, Oas3Visitor, Oas2Visitor } from './visitors';
|
|
4
|
-
import { Oas3Types } from './types/oas3';
|
|
5
|
-
import { Oas2Types } from './types/oas2';
|
|
6
|
-
import { Oas3_1Types } from './types/oas3_1';
|
|
7
4
|
import { NormalizedNodeType, normalizeTypes, NodeType } from './types';
|
|
8
5
|
import { WalkContext, walkDocument, UserContext, ResolveResult, NormalizedProblem } from './walk';
|
|
9
|
-
import {
|
|
6
|
+
import { detectSpec, getTypes, getMajorSpecVersion, SpecMajorVersion } from './oas-types';
|
|
10
7
|
import { isAbsoluteUrl, isRef, Location, refBaseName } from './ref-utils';
|
|
11
8
|
import { initRules } from './config/rules';
|
|
12
9
|
import { reportUnresolvedRef } from './rules/no-unresolved-refs';
|
|
@@ -93,27 +90,20 @@ export async function bundleDocument(opts: {
|
|
|
93
90
|
removeUnusedComponents = false,
|
|
94
91
|
keepUrlRefs = false,
|
|
95
92
|
} = opts;
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
const rules = config.getRulesForOasVersion(
|
|
93
|
+
const specVersion = detectSpec(document.parsed);
|
|
94
|
+
const specMajorVersion = getMajorSpecVersion(specVersion);
|
|
95
|
+
const rules = config.getRulesForOasVersion(specMajorVersion);
|
|
99
96
|
const types = normalizeTypes(
|
|
100
|
-
config.extendTypes(
|
|
101
|
-
customTypes ?? oasMajorVersion === OasMajorVersion.Version3
|
|
102
|
-
? oasVersion === OasVersion.Version3_1
|
|
103
|
-
? Oas3_1Types
|
|
104
|
-
: Oas3Types
|
|
105
|
-
: Oas2Types,
|
|
106
|
-
oasVersion
|
|
107
|
-
),
|
|
97
|
+
config.extendTypes(customTypes ?? getTypes(specVersion), specVersion),
|
|
108
98
|
config
|
|
109
99
|
);
|
|
110
100
|
|
|
111
|
-
const preprocessors = initRules(rules as any, config, 'preprocessors',
|
|
112
|
-
const decorators = initRules(rules as any, config, 'decorators',
|
|
101
|
+
const preprocessors = initRules(rules as any, config, 'preprocessors', specVersion);
|
|
102
|
+
const decorators = initRules(rules as any, config, 'decorators', specVersion);
|
|
113
103
|
|
|
114
104
|
const ctx: BundleContext = {
|
|
115
105
|
problems: [],
|
|
116
|
-
oasVersion:
|
|
106
|
+
oasVersion: specVersion,
|
|
117
107
|
refTypes: new Map<string, NormalizedNodeType>(),
|
|
118
108
|
visitorsData: {},
|
|
119
109
|
};
|
|
@@ -123,7 +113,7 @@ export async function bundleDocument(opts: {
|
|
|
123
113
|
severity: 'error',
|
|
124
114
|
ruleId: 'remove-unused-components',
|
|
125
115
|
visitor:
|
|
126
|
-
|
|
116
|
+
specMajorVersion === SpecMajorVersion.OAS2
|
|
127
117
|
? RemoveUnusedComponentsOas2({})
|
|
128
118
|
: RemoveUnusedComponentsOas3({}),
|
|
129
119
|
});
|
|
@@ -157,7 +147,7 @@ export async function bundleDocument(opts: {
|
|
|
157
147
|
severity: 'error',
|
|
158
148
|
ruleId: 'bundler',
|
|
159
149
|
visitor: makeBundleVisitor(
|
|
160
|
-
|
|
150
|
+
specMajorVersion,
|
|
161
151
|
dereference,
|
|
162
152
|
skipRedoclyRegistryRefs,
|
|
163
153
|
document,
|
|
@@ -188,9 +178,9 @@ export async function bundleDocument(opts: {
|
|
|
188
178
|
};
|
|
189
179
|
}
|
|
190
180
|
|
|
191
|
-
export function mapTypeToComponent(typeName: string, version:
|
|
181
|
+
export function mapTypeToComponent(typeName: string, version: SpecMajorVersion) {
|
|
192
182
|
switch (version) {
|
|
193
|
-
case
|
|
183
|
+
case SpecMajorVersion.OAS3:
|
|
194
184
|
switch (typeName) {
|
|
195
185
|
case 'Schema':
|
|
196
186
|
return 'schemas';
|
|
@@ -213,7 +203,7 @@ export function mapTypeToComponent(typeName: string, version: OasMajorVersion) {
|
|
|
213
203
|
default:
|
|
214
204
|
return null;
|
|
215
205
|
}
|
|
216
|
-
case
|
|
206
|
+
case SpecMajorVersion.OAS2:
|
|
217
207
|
switch (typeName) {
|
|
218
208
|
case 'Schema':
|
|
219
209
|
return 'definitions';
|
|
@@ -224,13 +214,22 @@ export function mapTypeToComponent(typeName: string, version: OasMajorVersion) {
|
|
|
224
214
|
default:
|
|
225
215
|
return null;
|
|
226
216
|
}
|
|
217
|
+
case SpecMajorVersion.Async2:
|
|
218
|
+
switch (typeName) {
|
|
219
|
+
case 'Schema':
|
|
220
|
+
return 'schemas';
|
|
221
|
+
case 'Parameter':
|
|
222
|
+
return 'parameters';
|
|
223
|
+
default:
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
227
226
|
}
|
|
228
227
|
}
|
|
229
228
|
|
|
230
229
|
// function oas3Move
|
|
231
230
|
|
|
232
231
|
function makeBundleVisitor(
|
|
233
|
-
version:
|
|
232
|
+
version: SpecMajorVersion,
|
|
234
233
|
dereference: boolean,
|
|
235
234
|
skipRedoclyRegistryRefs: boolean,
|
|
236
235
|
rootDocument: Document,
|
|
@@ -282,16 +281,16 @@ function makeBundleVisitor(
|
|
|
282
281
|
Root: {
|
|
283
282
|
enter(root: any, ctx: any) {
|
|
284
283
|
rootLocation = ctx.location;
|
|
285
|
-
if (version ===
|
|
284
|
+
if (version === SpecMajorVersion.OAS3) {
|
|
286
285
|
components = root.components = root.components || {};
|
|
287
|
-
} else if (version ===
|
|
286
|
+
} else if (version === SpecMajorVersion.OAS2) {
|
|
288
287
|
components = root;
|
|
289
288
|
}
|
|
290
289
|
},
|
|
291
290
|
},
|
|
292
291
|
};
|
|
293
292
|
|
|
294
|
-
if (version ===
|
|
293
|
+
if (version === SpecMajorVersion.OAS3) {
|
|
295
294
|
visitor.DiscriminatorMapping = {
|
|
296
295
|
leave(mapping: Record<string, string>, ctx: any) {
|
|
297
296
|
for (const name of Object.keys(mapping)) {
|
|
@@ -345,7 +344,7 @@ function makeBundleVisitor(
|
|
|
345
344
|
components[componentType] = components[componentType] || {};
|
|
346
345
|
const name = getComponentName(target, componentType, ctx);
|
|
347
346
|
components[componentType][name] = target.node;
|
|
348
|
-
if (version ===
|
|
347
|
+
if (version === SpecMajorVersion.OAS3) {
|
|
349
348
|
return `#/components/${componentType}/${name}`;
|
|
350
349
|
} else {
|
|
351
350
|
return `#/${componentType}/${name}`;
|
|
@@ -6,6 +6,11 @@ StyleguideConfig {
|
|
|
6
6
|
"_usedVersions": Set {},
|
|
7
7
|
"configFile": undefined,
|
|
8
8
|
"decorators": Object {
|
|
9
|
+
"async2": Object {
|
|
10
|
+
"oas2": Object {},
|
|
11
|
+
"oas3_0": Object {},
|
|
12
|
+
"oas3_1": Object {},
|
|
13
|
+
},
|
|
9
14
|
"oas2": Object {
|
|
10
15
|
"oas2": Object {},
|
|
11
16
|
"oas3_0": Object {},
|
|
@@ -39,6 +44,11 @@ StyleguideConfig {
|
|
|
39
44
|
"pluginPaths": Array [],
|
|
40
45
|
"plugins": Array [],
|
|
41
46
|
"preprocessors": Object {
|
|
47
|
+
"async2": Object {
|
|
48
|
+
"oas2": Object {},
|
|
49
|
+
"oas3_0": Object {},
|
|
50
|
+
"oas3_1": Object {},
|
|
51
|
+
},
|
|
42
52
|
"oas2": Object {
|
|
43
53
|
"oas2": Object {},
|
|
44
54
|
"oas3_0": Object {},
|
|
@@ -97,6 +107,20 @@ StyleguideConfig {
|
|
|
97
107
|
},
|
|
98
108
|
"recommendedFallback": false,
|
|
99
109
|
"rules": Object {
|
|
110
|
+
"async2": Object {
|
|
111
|
+
"oas2": Object {
|
|
112
|
+
"no-empty-servers": "error",
|
|
113
|
+
"operation-summary": "error",
|
|
114
|
+
},
|
|
115
|
+
"oas3_0": Object {
|
|
116
|
+
"no-empty-servers": "error",
|
|
117
|
+
"operation-summary": "error",
|
|
118
|
+
},
|
|
119
|
+
"oas3_1": Object {
|
|
120
|
+
"no-empty-servers": "error",
|
|
121
|
+
"operation-summary": "error",
|
|
122
|
+
},
|
|
123
|
+
},
|
|
100
124
|
"oas2": Object {
|
|
101
125
|
"oas2": Object {
|
|
102
126
|
"no-empty-servers": "error",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SpecVersion } from '../../oas-types';
|
|
2
2
|
import { Config, StyleguideConfig } from '../config';
|
|
3
3
|
import { getMergedConfig } from '../utils';
|
|
4
4
|
import { doesYamlFileExist } from '../../utils';
|
|
@@ -117,6 +117,7 @@ describe('getMergedConfig', () => {
|
|
|
117
117
|
"_usedVersions": Set {},
|
|
118
118
|
"configFile": "redocly.yaml",
|
|
119
119
|
"decorators": Object {
|
|
120
|
+
"async2": Object {},
|
|
120
121
|
"oas2": Object {},
|
|
121
122
|
"oas3_0": Object {},
|
|
122
123
|
"oas3_1": Object {},
|
|
@@ -127,6 +128,7 @@ describe('getMergedConfig', () => {
|
|
|
127
128
|
"pluginPaths": Array [],
|
|
128
129
|
"plugins": Array [],
|
|
129
130
|
"preprocessors": Object {
|
|
131
|
+
"async2": Object {},
|
|
130
132
|
"oas2": Object {},
|
|
131
133
|
"oas3_0": Object {},
|
|
132
134
|
"oas3_1": Object {},
|
|
@@ -140,6 +142,9 @@ describe('getMergedConfig', () => {
|
|
|
140
142
|
},
|
|
141
143
|
"recommendedFallback": false,
|
|
142
144
|
"rules": Object {
|
|
145
|
+
"async2": Object {
|
|
146
|
+
"operation-summary": "warn",
|
|
147
|
+
},
|
|
143
148
|
"oas2": Object {
|
|
144
149
|
"operation-summary": "warn",
|
|
145
150
|
},
|
|
@@ -217,6 +222,7 @@ describe('getMergedConfig', () => {
|
|
|
217
222
|
"_usedVersions": Set {},
|
|
218
223
|
"configFile": "redocly.yaml",
|
|
219
224
|
"decorators": Object {
|
|
225
|
+
"async2": Object {},
|
|
220
226
|
"oas2": Object {},
|
|
221
227
|
"oas3_0": Object {},
|
|
222
228
|
"oas3_1": Object {},
|
|
@@ -227,6 +233,7 @@ describe('getMergedConfig', () => {
|
|
|
227
233
|
"pluginPaths": Array [],
|
|
228
234
|
"plugins": Array [],
|
|
229
235
|
"preprocessors": Object {
|
|
236
|
+
"async2": Object {},
|
|
230
237
|
"oas2": Object {},
|
|
231
238
|
"oas3_0": Object {},
|
|
232
239
|
"oas3_1": Object {},
|
|
@@ -242,6 +249,10 @@ describe('getMergedConfig', () => {
|
|
|
242
249
|
},
|
|
243
250
|
"recommendedFallback": false,
|
|
244
251
|
"rules": Object {
|
|
252
|
+
"async2": Object {
|
|
253
|
+
"no-empty-servers": "error",
|
|
254
|
+
"operation-summary": "error",
|
|
255
|
+
},
|
|
245
256
|
"oas2": Object {
|
|
246
257
|
"no-empty-servers": "error",
|
|
247
258
|
"operation-summary": "error",
|
|
@@ -279,19 +290,19 @@ describe('StyleguideConfig.extendTypes', () => {
|
|
|
279
290
|
};
|
|
280
291
|
it('should call only oas3 types extension', () => {
|
|
281
292
|
const styleguideConfig = new StyleguideConfig(testRawConfigStyleguide);
|
|
282
|
-
styleguideConfig.extendTypes({},
|
|
293
|
+
styleguideConfig.extendTypes({}, SpecVersion.OAS3_0);
|
|
283
294
|
expect(oas3).toHaveBeenCalledTimes(1);
|
|
284
295
|
expect(oas2).toHaveBeenCalledTimes(0);
|
|
285
296
|
});
|
|
286
297
|
it('should call only oas2 types extension', () => {
|
|
287
298
|
const styleguideConfig = new StyleguideConfig(testRawConfigStyleguide);
|
|
288
|
-
styleguideConfig.extendTypes({},
|
|
299
|
+
styleguideConfig.extendTypes({}, SpecVersion.OAS2);
|
|
289
300
|
expect(oas3).toHaveBeenCalledTimes(0);
|
|
290
301
|
expect(oas2).toHaveBeenCalledTimes(1);
|
|
291
302
|
});
|
|
292
303
|
it('should throw error if for oas version different from 2 and 3', () => {
|
|
293
304
|
const styleguideConfig = new StyleguideConfig(testRawConfigStyleguide);
|
|
294
|
-
expect(() => styleguideConfig.extendTypes({}, 'something else' as
|
|
305
|
+
expect(() => styleguideConfig.extendTypes({}, 'something else' as SpecVersion)).toThrowError(
|
|
295
306
|
'Not implemented'
|
|
296
307
|
);
|
|
297
308
|
});
|
package/src/config/builtIn.ts
CHANGED
|
@@ -3,6 +3,7 @@ import all from './all';
|
|
|
3
3
|
import minimal from './minimal';
|
|
4
4
|
import { rules as oas3Rules } from '../rules/oas3';
|
|
5
5
|
import { rules as oas2Rules } from '../rules/oas2';
|
|
6
|
+
import { rules as async2Rules } from '../rules/async2';
|
|
6
7
|
import { preprocessors as oas3Preprocessors } from '../rules/oas3';
|
|
7
8
|
import { preprocessors as oas2Preprocessors } from '../rules/oas2';
|
|
8
9
|
import { decorators as oas3Decorators } from '../decorators/oas3';
|
|
@@ -24,14 +25,17 @@ export const defaultPlugin: Plugin = {
|
|
|
24
25
|
rules: {
|
|
25
26
|
oas3: oas3Rules,
|
|
26
27
|
oas2: oas2Rules,
|
|
28
|
+
async2: async2Rules,
|
|
27
29
|
} as CustomRulesConfig,
|
|
28
30
|
preprocessors: {
|
|
29
31
|
oas3: oas3Preprocessors,
|
|
30
32
|
oas2: oas2Preprocessors,
|
|
33
|
+
async2: {},
|
|
31
34
|
},
|
|
32
35
|
decorators: {
|
|
33
36
|
oas3: oas3Decorators,
|
|
34
37
|
oas2: oas2Decorators,
|
|
38
|
+
async2: {},
|
|
35
39
|
},
|
|
36
40
|
configs: builtInConfigs,
|
|
37
41
|
};
|
|
@@ -141,8 +141,8 @@ export function resolvePlugins(
|
|
|
141
141
|
};
|
|
142
142
|
|
|
143
143
|
if (pluginModule.rules) {
|
|
144
|
-
if (!pluginModule.rules.oas3 && !pluginModule.rules.oas2) {
|
|
145
|
-
throw new Error(`Plugin rules must have \`oas3\` or \`
|
|
144
|
+
if (!pluginModule.rules.oas3 && !pluginModule.rules.oas2 && !pluginModule.rules.async2) {
|
|
145
|
+
throw new Error(`Plugin rules must have \`oas3\`, \`oas2\` or \`async2\` rules "${p}.`);
|
|
146
146
|
}
|
|
147
147
|
plugin.rules = {};
|
|
148
148
|
if (pluginModule.rules.oas3) {
|
|
@@ -151,11 +151,18 @@ export function resolvePlugins(
|
|
|
151
151
|
if (pluginModule.rules.oas2) {
|
|
152
152
|
plugin.rules.oas2 = prefixRules(pluginModule.rules.oas2, id);
|
|
153
153
|
}
|
|
154
|
+
if (pluginModule.rules.async2) {
|
|
155
|
+
plugin.rules.async2 = prefixRules(pluginModule.rules.async2, id);
|
|
156
|
+
}
|
|
154
157
|
}
|
|
155
158
|
if (pluginModule.preprocessors) {
|
|
156
|
-
if (
|
|
159
|
+
if (
|
|
160
|
+
!pluginModule.preprocessors.oas3 &&
|
|
161
|
+
!pluginModule.preprocessors.oas2 &&
|
|
162
|
+
!pluginModule.preprocessors.async2
|
|
163
|
+
) {
|
|
157
164
|
throw new Error(
|
|
158
|
-
`Plugin \`preprocessors\` must have \`oas3\` or \`
|
|
165
|
+
`Plugin \`preprocessors\` must have \`oas3\`, \`oas2\` or \`async2\` preprocessors "${p}.`
|
|
159
166
|
);
|
|
160
167
|
}
|
|
161
168
|
plugin.preprocessors = {};
|
|
@@ -165,11 +172,20 @@ export function resolvePlugins(
|
|
|
165
172
|
if (pluginModule.preprocessors.oas2) {
|
|
166
173
|
plugin.preprocessors.oas2 = prefixRules(pluginModule.preprocessors.oas2, id);
|
|
167
174
|
}
|
|
175
|
+
if (pluginModule.preprocessors.async2) {
|
|
176
|
+
plugin.preprocessors.async2 = prefixRules(pluginModule.preprocessors.async2, id);
|
|
177
|
+
}
|
|
168
178
|
}
|
|
169
179
|
|
|
170
180
|
if (pluginModule.decorators) {
|
|
171
|
-
if (
|
|
172
|
-
|
|
181
|
+
if (
|
|
182
|
+
!pluginModule.decorators.oas3 &&
|
|
183
|
+
!pluginModule.decorators.oas2 &&
|
|
184
|
+
!pluginModule.decorators.async2
|
|
185
|
+
) {
|
|
186
|
+
throw new Error(
|
|
187
|
+
`Plugin \`decorators\` must have \`oas3\`, \`oas2\` or \`async2\` decorators "${p}.`
|
|
188
|
+
);
|
|
173
189
|
}
|
|
174
190
|
plugin.decorators = {};
|
|
175
191
|
if (pluginModule.decorators.oas3) {
|
|
@@ -178,6 +194,9 @@ export function resolvePlugins(
|
|
|
178
194
|
if (pluginModule.decorators.oas2) {
|
|
179
195
|
plugin.decorators.oas2 = prefixRules(pluginModule.decorators.oas2, id);
|
|
180
196
|
}
|
|
197
|
+
if (pluginModule.decorators.async2) {
|
|
198
|
+
plugin.decorators.async2 = prefixRules(pluginModule.decorators.async2, id);
|
|
199
|
+
}
|
|
181
200
|
}
|
|
182
201
|
|
|
183
202
|
if (pluginModule.assertions) {
|