@redocly/openapi-core 1.0.2 → 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.
Files changed (80) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/lib/bundle.d.ts +2 -2
  3. package/lib/bundle.js +24 -22
  4. package/lib/config/builtIn.js +4 -0
  5. package/lib/config/config-resolvers.js +19 -6
  6. package/lib/config/config.d.ts +9 -9
  7. package/lib/config/config.js +32 -17
  8. package/lib/config/rules.d.ts +2 -2
  9. package/lib/config/types.d.ts +9 -3
  10. package/lib/format/codeframes.d.ts +1 -1
  11. package/lib/index.d.ts +1 -1
  12. package/lib/index.js +7 -6
  13. package/lib/lint.js +10 -16
  14. package/lib/oas-types.d.ts +16 -10
  15. package/lib/oas-types.js +52 -26
  16. package/lib/rules/async2/channels-kebab-case.d.ts +2 -0
  17. package/lib/rules/async2/channels-kebab-case.js +19 -0
  18. package/lib/rules/async2/index.d.ts +12 -0
  19. package/lib/rules/async2/index.js +22 -0
  20. package/lib/rules/async2/no-channel-trailing-slash.d.ts +2 -0
  21. package/lib/rules/async2/no-channel-trailing-slash.js +16 -0
  22. package/lib/rules/common/no-path-trailing-slash.js +2 -2
  23. package/lib/rules/common/scalar-property-missing-example.js +1 -1
  24. package/lib/rules/common/spec.d.ts +2 -2
  25. package/lib/rules/common/spec.js +3 -3
  26. package/lib/rules/common/tags-alphabetical.js +5 -2
  27. package/lib/rules/oas2/index.js +1 -1
  28. package/lib/rules/oas2/remove-unused-components.js +4 -1
  29. package/lib/rules/oas3/index.js +1 -1
  30. package/lib/rules/oas3/remove-unused-components.js +4 -1
  31. package/lib/rules/utils.d.ts +1 -1
  32. package/lib/types/asyncapi.d.ts +2 -0
  33. package/lib/types/asyncapi.js +1027 -0
  34. package/lib/types/portal-config-schema.d.ts +2533 -0
  35. package/lib/types/portal-config-schema.js +304 -0
  36. package/lib/types/redocly-yaml.js +26 -20
  37. package/lib/types/{config-external-schemas.d.ts → theme-config.d.ts} +140 -575
  38. package/lib/types/{config-external-schemas.js → theme-config.js} +55 -261
  39. package/lib/typings/asyncapi.d.ts +21 -0
  40. package/lib/typings/asyncapi.js +2 -0
  41. package/lib/visitors.d.ts +12 -0
  42. package/lib/walk.d.ts +3 -3
  43. package/package.json +3 -2
  44. package/src/__tests__/lint.test.ts +38 -6
  45. package/src/bundle.ts +27 -28
  46. package/src/config/__tests__/__snapshots__/config.test.ts.snap +24 -0
  47. package/src/config/__tests__/config.test.ts +15 -4
  48. package/src/config/builtIn.ts +4 -0
  49. package/src/config/config-resolvers.ts +25 -6
  50. package/src/config/config.ts +51 -27
  51. package/src/config/rules.ts +2 -2
  52. package/src/config/types.ts +14 -4
  53. package/src/index.ts +7 -1
  54. package/src/lint.ts +13 -22
  55. package/src/oas-types.ts +59 -21
  56. package/src/rules/async2/__tests__/channels-kebab-case.test.ts +141 -0
  57. package/src/rules/async2/__tests__/no-channel-trailing-slash.test.ts +97 -0
  58. package/src/rules/async2/channels-kebab-case.ts +18 -0
  59. package/src/rules/async2/index.ts +22 -0
  60. package/src/rules/async2/no-channel-trailing-slash.ts +15 -0
  61. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +41 -0
  62. package/src/rules/common/__tests__/tags-alphabetical.test.ts +58 -0
  63. package/src/rules/common/no-path-trailing-slash.ts +2 -2
  64. package/src/rules/common/scalar-property-missing-example.ts +2 -2
  65. package/src/rules/common/spec.ts +2 -2
  66. package/src/rules/common/tags-alphabetical.ts +8 -4
  67. package/src/rules/oas2/__tests__/remove-unused-components.test.ts +155 -0
  68. package/src/rules/oas2/index.ts +2 -2
  69. package/src/rules/oas2/remove-unused-components.ts +6 -1
  70. package/src/rules/oas3/__tests__/remove-unused-components.test.ts +171 -0
  71. package/src/rules/oas3/index.ts +2 -2
  72. package/src/rules/oas3/remove-unused-components.ts +6 -1
  73. package/src/types/asyncapi.ts +1136 -0
  74. package/src/types/portal-config-schema.ts +343 -0
  75. package/src/types/redocly-yaml.ts +23 -34
  76. package/src/types/{config-external-schemas.ts → theme-config.ts} +60 -294
  77. package/src/typings/asyncapi.ts +26 -0
  78. package/src/visitors.ts +22 -0
  79. package/src/walk.ts +3 -3
  80. package/tsconfig.tsbuildinfo +1 -1
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 { detectOpenAPI, openAPIMajor, OasMajorVersion } from './oas-types';
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 oasVersion = detectOpenAPI(document.parsed);
97
- const oasMajorVersion = openAPIMajor(oasVersion);
98
- const rules = config.getRulesForOasVersion(oasMajorVersion);
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', oasVersion);
112
- const decorators = initRules(rules as any, config, 'decorators', oasVersion);
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: 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
- oasMajorVersion === OasMajorVersion.Version2
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
- oasMajorVersion,
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: OasMajorVersion) {
181
+ export function mapTypeToComponent(typeName: string, version: SpecMajorVersion) {
192
182
  switch (version) {
193
- case OasMajorVersion.Version3:
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 OasMajorVersion.Version2:
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: OasMajorVersion,
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 === OasMajorVersion.Version3) {
284
+ if (version === SpecMajorVersion.OAS3) {
286
285
  components = root.components = root.components || {};
287
- } else if (version === OasMajorVersion.Version2) {
286
+ } else if (version === SpecMajorVersion.OAS2) {
288
287
  components = root;
289
288
  }
290
289
  },
291
290
  },
292
291
  };
293
292
 
294
- if (version === OasMajorVersion.Version3) {
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 === OasMajorVersion.Version3) {
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 { OasVersion } from '../../oas-types';
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({}, OasVersion.Version3_0);
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({}, OasVersion.Version2);
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 OasVersion)).toThrowError(
305
+ expect(() => styleguideConfig.extendTypes({}, 'something else' as SpecVersion)).toThrowError(
295
306
  'Not implemented'
296
307
  );
297
308
  });
@@ -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 \`oas2\` rules "${p}.`);
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 (!pluginModule.preprocessors.oas3 && !pluginModule.preprocessors.oas2) {
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 \`oas2\` preprocessors "${p}.`
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 (!pluginModule.decorators.oas3 && !pluginModule.decorators.oas2) {
172
- throw new Error(`Plugin \`decorators\` must have \`oas3\` or \`oas2\` decorators "${p}.`);
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) {
@@ -3,7 +3,13 @@ import * as path from 'path';
3
3
  import { parseYaml, stringifyYaml } from '../js-yaml';
4
4
  import { slash, doesYamlFileExist } from '../utils';
5
5
  import { NormalizedProblem } from '../walk';
6
- import { OasVersion, OasMajorVersion, Oas2RuleSet, Oas3RuleSet } from '../oas-types';
6
+ import {
7
+ SpecVersion,
8
+ SpecMajorVersion,
9
+ Oas2RuleSet,
10
+ Oas3RuleSet,
11
+ Async2RuleSet,
12
+ } from '../oas-types';
7
13
  import { isBrowser, env } from '../env';
8
14
 
9
15
  import type { NodeType } from '../types';
@@ -65,12 +71,12 @@ export class StyleguideConfig {
65
71
  plugins: Plugin[];
66
72
  ignore: Record<string, Record<string, Set<string>>> = {};
67
73
  doNotResolveExamples: boolean;
68
- rules: Record<OasVersion, Record<string, RuleConfig>>;
69
- preprocessors: Record<OasVersion, Record<string, PreprocessorConfig>>;
70
- decorators: Record<OasVersion, Record<string, DecoratorConfig>>;
74
+ rules: Record<SpecVersion, Record<string, RuleConfig>>;
75
+ preprocessors: Record<SpecVersion, Record<string, PreprocessorConfig>>;
76
+ decorators: Record<SpecVersion, Record<string, DecoratorConfig>>;
71
77
 
72
78
  private _usedRules: Set<string> = new Set();
73
- private _usedVersions: Set<OasVersion> = new Set();
79
+ private _usedVersions: Set<SpecVersion> = new Set();
74
80
 
75
81
  recommendedFallback: boolean;
76
82
 
@@ -83,21 +89,24 @@ export class StyleguideConfig {
83
89
  this.recommendedFallback = rawConfig.recommendedFallback || false;
84
90
 
85
91
  this.rules = {
86
- [OasVersion.Version2]: { ...rawConfig.rules, ...rawConfig.oas2Rules },
87
- [OasVersion.Version3_0]: { ...rawConfig.rules, ...rawConfig.oas3_0Rules },
88
- [OasVersion.Version3_1]: { ...rawConfig.rules, ...rawConfig.oas3_1Rules },
92
+ [SpecVersion.OAS2]: { ...rawConfig.rules, ...rawConfig.oas2Rules },
93
+ [SpecVersion.OAS3_0]: { ...rawConfig.rules, ...rawConfig.oas3_0Rules },
94
+ [SpecVersion.OAS3_1]: { ...rawConfig.rules, ...rawConfig.oas3_1Rules },
95
+ [SpecVersion.Async2]: { ...rawConfig.rules, ...rawConfig.async2Rules },
89
96
  };
90
97
 
91
98
  this.preprocessors = {
92
- [OasVersion.Version2]: { ...rawConfig.preprocessors, ...rawConfig.oas2Preprocessors },
93
- [OasVersion.Version3_0]: { ...rawConfig.preprocessors, ...rawConfig.oas3_0Preprocessors },
94
- [OasVersion.Version3_1]: { ...rawConfig.preprocessors, ...rawConfig.oas3_1Preprocessors },
99
+ [SpecVersion.OAS2]: { ...rawConfig.preprocessors, ...rawConfig.oas2Preprocessors },
100
+ [SpecVersion.OAS3_0]: { ...rawConfig.preprocessors, ...rawConfig.oas3_0Preprocessors },
101
+ [SpecVersion.OAS3_1]: { ...rawConfig.preprocessors, ...rawConfig.oas3_1Preprocessors },
102
+ [SpecVersion.Async2]: { ...rawConfig.preprocessors, ...rawConfig.async2Preprocessors },
95
103
  };
96
104
 
97
105
  this.decorators = {
98
- [OasVersion.Version2]: { ...rawConfig.decorators, ...rawConfig.oas2Decorators },
99
- [OasVersion.Version3_0]: { ...rawConfig.decorators, ...rawConfig.oas3_0Decorators },
100
- [OasVersion.Version3_1]: { ...rawConfig.decorators, ...rawConfig.oas3_1Decorators },
106
+ [SpecVersion.OAS2]: { ...rawConfig.decorators, ...rawConfig.oas2Decorators },
107
+ [SpecVersion.OAS3_0]: { ...rawConfig.decorators, ...rawConfig.oas3_0Decorators },
108
+ [SpecVersion.OAS3_1]: { ...rawConfig.decorators, ...rawConfig.oas3_1Decorators },
109
+ [SpecVersion.Async2]: { ...rawConfig.decorators, ...rawConfig.async2Decorators },
101
110
  };
102
111
 
103
112
  this.extendPaths = rawConfig.extendPaths || [];
@@ -173,20 +182,24 @@ export class StyleguideConfig {
173
182
  : problem;
174
183
  }
175
184
 
176
- extendTypes(types: Record<string, NodeType>, version: OasVersion) {
185
+ extendTypes(types: Record<string, NodeType>, version: SpecVersion) {
177
186
  let extendedTypes = types;
178
187
  for (const plugin of this.plugins) {
179
188
  if (plugin.typeExtension !== undefined) {
180
189
  switch (version) {
181
- case OasVersion.Version3_0:
182
- case OasVersion.Version3_1:
190
+ case SpecVersion.OAS3_0:
191
+ case SpecVersion.OAS3_1:
183
192
  if (!plugin.typeExtension.oas3) continue;
184
193
  extendedTypes = plugin.typeExtension.oas3(extendedTypes, version);
185
194
  break;
186
- case OasVersion.Version2:
195
+ case SpecVersion.OAS2:
187
196
  if (!plugin.typeExtension.oas2) continue;
188
197
  extendedTypes = plugin.typeExtension.oas2(extendedTypes, version);
189
198
  break;
199
+ case SpecVersion.Async2:
200
+ if (!plugin.typeExtension.async2) continue;
201
+ extendedTypes = plugin.typeExtension.async2(extendedTypes, version);
202
+ break;
190
203
  default:
191
204
  throw new Error('Not implemented');
192
205
  }
@@ -195,7 +208,7 @@ export class StyleguideConfig {
195
208
  return extendedTypes;
196
209
  }
197
210
 
198
- getRuleSettings(ruleId: string, oasVersion: OasVersion): RuleSettings {
211
+ getRuleSettings(ruleId: string, oasVersion: SpecVersion): RuleSettings {
199
212
  this._usedRules.add(ruleId);
200
213
  this._usedVersions.add(oasVersion);
201
214
  const settings = this.rules[oasVersion][ruleId] || 'off';
@@ -208,7 +221,7 @@ export class StyleguideConfig {
208
221
  }
209
222
  }
210
223
 
211
- getPreprocessorSettings(ruleId: string, oasVersion: OasVersion): RuleSettings {
224
+ getPreprocessorSettings(ruleId: string, oasVersion: SpecVersion): RuleSettings {
212
225
  this._usedRules.add(ruleId);
213
226
  this._usedVersions.add(oasVersion);
214
227
 
@@ -222,7 +235,7 @@ export class StyleguideConfig {
222
235
  }
223
236
  }
224
237
 
225
- getDecoratorSettings(ruleId: string, oasVersion: OasVersion): RuleSettings {
238
+ getDecoratorSettings(ruleId: string, oasVersion: SpecVersion): RuleSettings {
226
239
  this._usedRules.add(ruleId);
227
240
  this._usedVersions.add(oasVersion);
228
241
  const settings = this.decorators[oasVersion][ruleId] || 'off';
@@ -259,28 +272,39 @@ export class StyleguideConfig {
259
272
  };
260
273
  }
261
274
 
262
- getRulesForOasVersion(version: OasMajorVersion) {
275
+ getRulesForOasVersion(version: SpecMajorVersion) {
263
276
  switch (version) {
264
- case OasMajorVersion.Version3:
277
+ case SpecMajorVersion.OAS3:
265
278
  // eslint-disable-next-line no-case-declarations
266
279
  const oas3Rules: Oas3RuleSet[] = []; // default ruleset
267
280
  this.plugins.forEach((p) => p.preprocessors?.oas3 && oas3Rules.push(p.preprocessors.oas3));
268
281
  this.plugins.forEach((p) => p.rules?.oas3 && oas3Rules.push(p.rules.oas3));
269
282
  this.plugins.forEach((p) => p.decorators?.oas3 && oas3Rules.push(p.decorators.oas3));
270
283
  return oas3Rules;
271
- case OasMajorVersion.Version2:
284
+ case SpecMajorVersion.OAS2:
272
285
  // eslint-disable-next-line no-case-declarations
273
286
  const oas2Rules: Oas2RuleSet[] = []; // default ruleset
274
287
  this.plugins.forEach((p) => p.preprocessors?.oas2 && oas2Rules.push(p.preprocessors.oas2));
275
288
  this.plugins.forEach((p) => p.rules?.oas2 && oas2Rules.push(p.rules.oas2));
276
289
  this.plugins.forEach((p) => p.decorators?.oas2 && oas2Rules.push(p.decorators.oas2));
277
290
  return oas2Rules;
291
+ case SpecMajorVersion.Async2:
292
+ // eslint-disable-next-line no-case-declarations
293
+ const asyncApiRules: Async2RuleSet[] = []; // default ruleset
294
+ this.plugins.forEach(
295
+ (p) => p.preprocessors?.async2 && asyncApiRules.push(p.preprocessors.async2)
296
+ );
297
+ this.plugins.forEach((p) => p.rules?.async2 && asyncApiRules.push(p.rules.async2));
298
+ this.plugins.forEach(
299
+ (p) => p.decorators?.async2 && asyncApiRules.push(p.decorators.async2)
300
+ );
301
+ return asyncApiRules;
278
302
  }
279
303
  }
280
304
 
281
305
  skipRules(rules?: string[]) {
282
306
  for (const ruleId of rules || []) {
283
- for (const version of Object.values(OasVersion)) {
307
+ for (const version of Object.values(SpecVersion)) {
284
308
  if (this.rules[version][ruleId]) {
285
309
  this.rules[version][ruleId] = 'off';
286
310
  }
@@ -290,7 +314,7 @@ export class StyleguideConfig {
290
314
 
291
315
  skipPreprocessors(preprocessors?: string[]) {
292
316
  for (const preprocessorId of preprocessors || []) {
293
- for (const version of Object.values(OasVersion)) {
317
+ for (const version of Object.values(SpecVersion)) {
294
318
  if (this.preprocessors[version][preprocessorId]) {
295
319
  this.preprocessors[version][preprocessorId] = 'off';
296
320
  }
@@ -300,7 +324,7 @@ export class StyleguideConfig {
300
324
 
301
325
  skipDecorators(decorators?: string[]) {
302
326
  for (const decoratorId of decorators || []) {
303
- for (const version of Object.values(OasVersion)) {
327
+ for (const version of Object.values(SpecVersion)) {
304
328
  if (this.decorators[version][decoratorId]) {
305
329
  this.decorators[version][decoratorId] = 'off';
306
330
  }
@@ -1,4 +1,4 @@
1
- import { RuleSet, OasVersion } from '../oas-types';
1
+ import { RuleSet, SpecVersion } from '../oas-types';
2
2
  import { StyleguideConfig } from './config';
3
3
  import { isDefined } from '../utils';
4
4
  import type { ProblemSeverity } from '../walk';
@@ -13,7 +13,7 @@ export function initRules<T extends Function, P extends RuleSet<T>>(
13
13
  rules: P[],
14
14
  config: StyleguideConfig,
15
15
  type: 'rules' | 'preprocessors' | 'decorators',
16
- oasVersion: OasVersion
16
+ oasVersion: SpecVersion
17
17
  ): InitializedRule[] {
18
18
  return rules
19
19
  .flatMap((ruleset) =>
@@ -1,14 +1,18 @@
1
1
  import type { ProblemSeverity, UserContext } from '../walk';
2
2
  import type {
3
3
  Oas3PreprocessorsSet,
4
- OasMajorVersion,
4
+ SpecMajorVersion,
5
5
  Oas3DecoratorsSet,
6
6
  Oas2RuleSet,
7
7
  Oas2PreprocessorsSet,
8
8
  Oas2DecoratorsSet,
9
9
  Oas3RuleSet,
10
- OasVersion,
10
+ SpecVersion,
11
+ Async2PreprocessorsSet,
12
+ Async2DecoratorsSet,
13
+ Async2RuleSet,
11
14
  } from '../oas-types';
15
+
12
16
  import type { NodeType } from '../types';
13
17
  import { Location } from '../ref-utils';
14
18
  import type { SkipFunctionContext } from '../visitors';
@@ -43,16 +47,19 @@ export type StyleguideRawConfig = {
43
47
  oas2Rules?: Record<string, RuleConfig>;
44
48
  oas3_0Rules?: Record<string, RuleConfig>;
45
49
  oas3_1Rules?: Record<string, RuleConfig>;
50
+ async2Rules?: Record<string, RuleConfig>;
46
51
 
47
52
  preprocessors?: Record<string, PreprocessorConfig>;
48
53
  oas2Preprocessors?: Record<string, PreprocessorConfig>;
49
54
  oas3_0Preprocessors?: Record<string, PreprocessorConfig>;
50
55
  oas3_1Preprocessors?: Record<string, PreprocessorConfig>;
56
+ async2Preprocessors?: Record<string, PreprocessorConfig>;
51
57
 
52
58
  decorators?: Record<string, DecoratorConfig>;
53
59
  oas2Decorators?: Record<string, DecoratorConfig>;
54
60
  oas3_0Decorators?: Record<string, DecoratorConfig>;
55
61
  oas3_1Decorators?: Record<string, DecoratorConfig>;
62
+ async2Decorators?: Record<string, DecoratorConfig>;
56
63
  };
57
64
 
58
65
  export type ApiStyleguideRawConfig = Omit<StyleguideRawConfig, 'plugins'>;
@@ -68,23 +75,26 @@ export type ResolvedStyleguideConfig = PluginStyleguideConfig & {
68
75
  export type PreprocessorsConfig = {
69
76
  oas3?: Oas3PreprocessorsSet;
70
77
  oas2?: Oas2PreprocessorsSet;
78
+ async2?: Async2PreprocessorsSet;
71
79
  };
72
80
 
73
81
  export type DecoratorsConfig = {
74
82
  oas3?: Oas3DecoratorsSet;
75
83
  oas2?: Oas2DecoratorsSet;
84
+ async2?: Async2DecoratorsSet;
76
85
  };
77
86
 
78
87
  export type TypesExtensionFn = (
79
88
  types: Record<string, NodeType>,
80
- oasVersion: OasVersion
89
+ oasVersion: SpecVersion
81
90
  ) => Record<string, NodeType>;
82
91
 
83
- export type TypeExtensionsConfig = Partial<Record<OasMajorVersion, TypesExtensionFn>>;
92
+ export type TypeExtensionsConfig = Partial<Record<SpecMajorVersion, TypesExtensionFn>>;
84
93
 
85
94
  export type CustomRulesConfig = {
86
95
  oas3?: Oas3RuleSet;
87
96
  oas2?: Oas2RuleSet;
97
+ async2?: Async2RuleSet;
88
98
  };
89
99
 
90
100
  export type AssertionContext = Partial<UserContext> & SkipFunctionContext & { node: any };
package/src/index.ts CHANGED
@@ -52,7 +52,13 @@ export {
52
52
  } from './resolve';
53
53
  export { parseYaml, stringifyYaml } from './js-yaml';
54
54
  export { unescapePointer, isRef, isAbsoluteUrl } from './ref-utils';
55
- export { detectOpenAPI, OasMajorVersion, openAPIMajor, OasVersion } from './oas-types';
55
+ export {
56
+ SpecMajorVersion,
57
+ getMajorSpecVersion,
58
+ SpecVersion,
59
+ detectSpec,
60
+ getTypes,
61
+ } from './oas-types';
56
62
  export { normalizeVisitors } from './visitors';
57
63
 
58
64
  export {