@redocly/openapi-core 1.17.1 → 1.18.1

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 (72) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/lib/bundle.d.ts +1 -1
  3. package/lib/bundle.js +16 -2
  4. package/lib/config/all.js +6 -0
  5. package/lib/config/builtIn.js +10 -2
  6. package/lib/config/config-resolvers.js +15 -4
  7. package/lib/config/config.d.ts +2 -2
  8. package/lib/config/config.js +15 -0
  9. package/lib/config/load.d.ts +1 -2
  10. package/lib/config/minimal.js +8 -0
  11. package/lib/config/recommended-strict.js +8 -0
  12. package/lib/config/recommended.js +8 -0
  13. package/lib/config/types.d.ts +10 -4
  14. package/lib/config/utils.js +13 -1
  15. package/lib/decorators/arazzo/index.d.ts +1 -0
  16. package/lib/decorators/arazzo/index.js +4 -0
  17. package/lib/decorators/async2/index.d.ts +1 -0
  18. package/lib/decorators/async2/index.js +4 -0
  19. package/lib/index.d.ts +1 -0
  20. package/lib/index.js +4 -2
  21. package/lib/oas-types.d.ts +13 -8
  22. package/lib/oas-types.js +10 -0
  23. package/lib/rules/arazzo/index.d.ts +3 -0
  24. package/lib/rules/arazzo/index.js +10 -0
  25. package/lib/rules/common/path-segment-plural.js +2 -1
  26. package/lib/rules/common/spec.d.ts +2 -2
  27. package/lib/types/arazzo.d.ts +2276 -0
  28. package/lib/types/arazzo.js +386 -0
  29. package/lib/types/asyncapi.js +17 -43
  30. package/lib/types/oas3.js +0 -8
  31. package/lib/types/oas3_1.js +2 -2
  32. package/lib/types/redocly-yaml.d.ts +4 -4
  33. package/lib/types/redocly-yaml.js +15 -5
  34. package/lib/typings/arazzo.d.ts +30 -0
  35. package/lib/typings/arazzo.js +2 -0
  36. package/lib/utils.d.ts +8 -4
  37. package/lib/utils.js +38 -7
  38. package/lib/visitors.d.ts +11 -0
  39. package/package.json +3 -2
  40. package/src/__tests__/lint.test.ts +0 -50
  41. package/src/bundle.ts +15 -3
  42. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +20 -0
  43. package/src/config/__tests__/__snapshots__/config.test.ts.snap +3 -0
  44. package/src/config/__tests__/config.test.ts +6 -0
  45. package/src/config/all.ts +6 -0
  46. package/src/config/builtIn.ts +10 -2
  47. package/src/config/config-resolvers.ts +17 -3
  48. package/src/config/config.ts +17 -0
  49. package/src/config/load.ts +1 -2
  50. package/src/config/minimal.ts +8 -0
  51. package/src/config/recommended-strict.ts +8 -0
  52. package/src/config/recommended.ts +8 -0
  53. package/src/config/types.ts +15 -2
  54. package/src/config/utils.ts +15 -0
  55. package/src/decorators/arazzo/index.ts +1 -0
  56. package/src/decorators/async2/index.ts +1 -0
  57. package/src/index.ts +1 -0
  58. package/src/oas-types.ts +25 -4
  59. package/src/rules/arazzo/index.ts +11 -0
  60. package/src/rules/common/__tests__/spec.test.ts +47 -0
  61. package/src/rules/common/no-invalid-schema-examples.ts +3 -2
  62. package/src/rules/common/path-segment-plural.ts +3 -2
  63. package/src/rules/common/spec.ts +2 -2
  64. package/src/types/arazzo.ts +391 -0
  65. package/src/types/asyncapi.ts +22 -43
  66. package/src/types/oas3.ts +0 -7
  67. package/src/types/oas3_1.ts +2 -2
  68. package/src/types/redocly-yaml.ts +18 -8
  69. package/src/typings/arazzo.ts +44 -0
  70. package/src/utils.ts +41 -8
  71. package/src/visitors.ts +18 -0
  72. package/tsconfig.tsbuildinfo +1 -1
@@ -11,6 +11,9 @@ import type {
11
11
  Async2PreprocessorsSet,
12
12
  Async2DecoratorsSet,
13
13
  Async2RuleSet,
14
+ ArazzoRuleSet,
15
+ ArazzoPreprocessorsSet,
16
+ ArazzoDecoratorsSet,
14
17
  RuleMap,
15
18
  } from '../oas-types';
16
19
 
@@ -20,9 +23,9 @@ import type { SkipFunctionContext } from '../visitors';
20
23
  import {
21
24
  BuiltInAsync2RuleId,
22
25
  BuiltInCommonOASRuleId,
23
- BuiltInCommonRuleId,
24
26
  BuiltInOAS2RuleId,
25
27
  BuiltInOAS3RuleId,
28
+ BuiltInArazzoRuleId,
26
29
  } from '../types/redocly-yaml';
27
30
 
28
31
  export type RuleSeverity = ProblemSeverity | 'off';
@@ -51,23 +54,26 @@ export type StyleguideRawConfig<T = undefined> = {
51
54
  doNotResolveExamples?: boolean;
52
55
  recommendedFallback?: boolean;
53
56
 
54
- rules?: RuleMap<BuiltInCommonRuleId | BuiltInCommonOASRuleId, RuleConfig, T>;
57
+ rules?: RuleMap<BuiltInCommonOASRuleId, RuleConfig, T>;
55
58
  oas2Rules?: RuleMap<BuiltInOAS2RuleId, RuleConfig, T>;
56
59
  oas3_0Rules?: RuleMap<BuiltInOAS3RuleId, RuleConfig, T>;
57
60
  oas3_1Rules?: RuleMap<BuiltInOAS3RuleId, RuleConfig, T>;
58
61
  async2Rules?: RuleMap<BuiltInAsync2RuleId, RuleConfig, T>;
62
+ arazzoRules?: RuleMap<BuiltInArazzoRuleId, RuleConfig, T>;
59
63
 
60
64
  preprocessors?: Record<string, PreprocessorConfig>;
61
65
  oas2Preprocessors?: Record<string, PreprocessorConfig>;
62
66
  oas3_0Preprocessors?: Record<string, PreprocessorConfig>;
63
67
  oas3_1Preprocessors?: Record<string, PreprocessorConfig>;
64
68
  async2Preprocessors?: Record<string, PreprocessorConfig>;
69
+ arazzoPreprocessors?: Record<string, PreprocessorConfig>;
65
70
 
66
71
  decorators?: Record<string, DecoratorConfig>;
67
72
  oas2Decorators?: Record<string, DecoratorConfig>;
68
73
  oas3_0Decorators?: Record<string, DecoratorConfig>;
69
74
  oas3_1Decorators?: Record<string, DecoratorConfig>;
70
75
  async2Decorators?: Record<string, DecoratorConfig>;
76
+ arazzoDecorators?: Record<string, DecoratorConfig>;
71
77
  };
72
78
 
73
79
  export type ApiStyleguideRawConfig = Omit<StyleguideRawConfig, 'plugins'>;
@@ -84,12 +90,14 @@ export type PreprocessorsConfig = {
84
90
  oas3?: Oas3PreprocessorsSet;
85
91
  oas2?: Oas2PreprocessorsSet;
86
92
  async2?: Async2PreprocessorsSet;
93
+ arazzo?: ArazzoPreprocessorsSet;
87
94
  };
88
95
 
89
96
  export type DecoratorsConfig = {
90
97
  oas3?: Oas3DecoratorsSet;
91
98
  oas2?: Oas2DecoratorsSet;
92
99
  async2?: Async2DecoratorsSet;
100
+ arazzo?: ArazzoDecoratorsSet;
93
101
  };
94
102
 
95
103
  export type TypesExtensionFn = (
@@ -103,6 +111,7 @@ export type CustomRulesConfig = {
103
111
  oas3?: Oas3RuleSet;
104
112
  oas2?: Oas2RuleSet;
105
113
  async2?: Async2RuleSet;
114
+ arazzo?: ArazzoRuleSet;
106
115
  };
107
116
 
108
117
  export type AssertionContext = Partial<UserContext> & SkipFunctionContext & { node: any };
@@ -227,19 +236,23 @@ export type ThemeRawConfig = {
227
236
  mockServer?: Record<string, any>;
228
237
  };
229
238
 
239
+ // TODO: sync types
230
240
  export type RulesFields =
231
241
  | 'rules'
232
242
  | 'oas2Rules'
233
243
  | 'oas3_0Rules'
234
244
  | 'oas3_1Rules'
235
245
  | 'async2Rules'
246
+ | 'arazzoRules'
236
247
  | 'preprocessors'
237
248
  | 'oas2Preprocessors'
238
249
  | 'oas3_0Preprocessors'
239
250
  | 'oas3_1Preprocessors'
240
251
  | 'async2Preprocessors'
252
+ | 'arazzoPreprocessors'
241
253
  | 'decorators'
242
254
  | 'oas2Decorators'
243
255
  | 'oas3_0Decorators'
244
256
  | 'oas3_1Decorators'
257
+ | 'arazzoDecorators'
245
258
  | 'async2Decorators';
@@ -56,18 +56,21 @@ function extractFlatConfig<
56
56
  oas3_0Rules,
57
57
  oas3_1Rules,
58
58
  async2Rules,
59
+ arazzoRules,
59
60
 
60
61
  preprocessors,
61
62
  oas2Preprocessors,
62
63
  oas3_0Preprocessors,
63
64
  oas3_1Preprocessors,
64
65
  async2Preprocessors,
66
+ arazzoPreprocessors,
65
67
 
66
68
  decorators,
67
69
  oas2Decorators,
68
70
  oas3_0Decorators,
69
71
  oas3_1Decorators,
70
72
  async2Decorators,
73
+ arazzoDecorators,
71
74
 
72
75
  ...rawConfigRest
73
76
  }: T): {
@@ -83,18 +86,21 @@ function extractFlatConfig<
83
86
  oas3_0Rules,
84
87
  oas3_1Rules,
85
88
  async2Rules,
89
+ arazzoRules,
86
90
 
87
91
  preprocessors,
88
92
  oas2Preprocessors,
89
93
  oas3_0Preprocessors,
90
94
  oas3_1Preprocessors,
91
95
  async2Preprocessors,
96
+ arazzoPreprocessors,
92
97
 
93
98
  decorators,
94
99
  oas2Decorators,
95
100
  oas3_0Decorators,
96
101
  oas3_1Decorators,
97
102
  async2Decorators,
103
+ arazzoDecorators,
98
104
 
99
105
  doNotResolveExamples: rawConfigRest.resolve?.doNotResolveExamples,
100
106
  };
@@ -152,18 +158,21 @@ export function mergeExtends(rulesConfList: ResolvedStyleguideConfig[]) {
152
158
  oas3_0Rules: {},
153
159
  oas3_1Rules: {},
154
160
  async2Rules: {},
161
+ arazzoRules: {},
155
162
 
156
163
  preprocessors: {},
157
164
  oas2Preprocessors: {},
158
165
  oas3_0Preprocessors: {},
159
166
  oas3_1Preprocessors: {},
160
167
  async2Preprocessors: {},
168
+ arazzoPreprocessors: {},
161
169
 
162
170
  decorators: {},
163
171
  oas2Decorators: {},
164
172
  oas3_0Decorators: {},
165
173
  oas3_1Decorators: {},
166
174
  async2Decorators: {},
175
+ arazzoDecorators: {},
167
176
 
168
177
  plugins: [],
169
178
  pluginPaths: [],
@@ -186,6 +195,8 @@ export function mergeExtends(rulesConfList: ResolvedStyleguideConfig[]) {
186
195
  assignExisting(result.oas3_1Rules, rulesConf.rules || {});
187
196
  Object.assign(result.async2Rules, rulesConf.async2Rules);
188
197
  assignExisting(result.async2Rules, rulesConf.rules || {});
198
+ Object.assign(result.arazzoRules, rulesConf.arazzoRules);
199
+ assignExisting(result.arazzoRules, rulesConf.rules || {});
189
200
 
190
201
  Object.assign(result.preprocessors, rulesConf.preprocessors);
191
202
  Object.assign(result.oas2Preprocessors, rulesConf.oas2Preprocessors);
@@ -196,6 +207,8 @@ export function mergeExtends(rulesConfList: ResolvedStyleguideConfig[]) {
196
207
  assignExisting(result.oas3_1Preprocessors, rulesConf.preprocessors || {});
197
208
  Object.assign(result.async2Preprocessors, rulesConf.async2Preprocessors);
198
209
  assignExisting(result.async2Preprocessors, rulesConf.preprocessors || {});
210
+ Object.assign(result.arazzoPreprocessors, rulesConf.arazzoPreprocessors);
211
+ assignExisting(result.arazzoPreprocessors, rulesConf.preprocessors || {});
199
212
 
200
213
  Object.assign(result.decorators, rulesConf.decorators);
201
214
  Object.assign(result.oas2Decorators, rulesConf.oas2Decorators);
@@ -206,6 +219,8 @@ export function mergeExtends(rulesConfList: ResolvedStyleguideConfig[]) {
206
219
  assignExisting(result.oas3_1Decorators, rulesConf.decorators || {});
207
220
  Object.assign(result.async2Decorators, rulesConf.async2Decorators);
208
221
  assignExisting(result.async2Decorators, rulesConf.decorators || {});
222
+ Object.assign(result.arazzoDecorators, rulesConf.arazzoDecorators);
223
+ assignExisting(result.arazzoDecorators, rulesConf.decorators || {});
209
224
 
210
225
  result.plugins!.push(...(rulesConf.plugins || []));
211
226
  result.pluginPaths!.push(...(rulesConf.pluginPaths || []));
@@ -0,0 +1 @@
1
+ export const decorators = {};
@@ -0,0 +1 @@
1
+ export const decorators = {};
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ export {
8
8
  pause,
9
9
  } from './utils';
10
10
  export { Oas3_1Types } from './types/oas3_1';
11
+ export { ArazzoTypes } from './types/arazzo';
11
12
  export { Oas3Types } from './types/oas3';
12
13
  export { Oas2Types } from './types/oas2';
13
14
  export { AsyncApi2Types } from './types/asyncapi';
package/src/oas-types.ts CHANGED
@@ -5,15 +5,18 @@ import {
5
5
  Oas2Preprocessor,
6
6
  Async2Preprocessor,
7
7
  Async2Rule,
8
+ ArazzoPreprocessor,
9
+ ArazzoRule,
8
10
  } from './visitors';
9
11
  import { Oas2Types } from './types/oas2';
10
12
  import { Oas3Types } from './types/oas3';
11
13
  import { Oas3_1Types } from './types/oas3_1';
12
14
  import { AsyncApi2Types } from './types/asyncapi';
15
+ import { ArazzoTypes } from './types/arazzo';
13
16
  import {
14
17
  BuiltInAsync2RuleId,
15
18
  BuiltInCommonOASRuleId,
16
- BuiltInCommonRuleId,
19
+ BuiltInArazzoRuleId,
17
20
  BuiltInOAS2RuleId,
18
21
  BuiltInOAS3RuleId,
19
22
  } from './types/redocly-yaml';
@@ -25,12 +28,14 @@ export enum SpecVersion {
25
28
  OAS3_0 = 'oas3_0',
26
29
  OAS3_1 = 'oas3_1',
27
30
  Async2 = 'async2', // todo split into 2.x maybe?
31
+ Arazzo = 'arazzo',
28
32
  }
29
33
 
30
34
  export enum SpecMajorVersion {
31
35
  OAS2 = 'oas2',
32
36
  OAS3 = 'oas3',
33
37
  Async2 = 'async2',
38
+ Arazzo = 'arazzo',
34
39
  }
35
40
 
36
41
  const typesMap = {
@@ -38,6 +43,7 @@ const typesMap = {
38
43
  [SpecVersion.OAS3_0]: Oas3Types,
39
44
  [SpecVersion.OAS3_1]: Oas3_1Types,
40
45
  [SpecVersion.Async2]: AsyncApi2Types,
46
+ [SpecVersion.Arazzo]: ArazzoTypes,
41
47
  };
42
48
 
43
49
  export type RuleMap<Key extends string, RuleConfig, T> = Record<
@@ -45,26 +51,35 @@ export type RuleMap<Key extends string, RuleConfig, T> = Record<
45
51
  RuleConfig
46
52
  >;
47
53
  export type Oas3RuleSet<T = undefined> = RuleMap<
48
- BuiltInCommonRuleId | BuiltInCommonOASRuleId | BuiltInOAS3RuleId | 'assertions',
54
+ BuiltInCommonOASRuleId | BuiltInOAS3RuleId | 'assertions',
49
55
  Oas3Rule,
50
56
  T
51
57
  >;
52
58
  export type Oas2RuleSet<T = undefined> = RuleMap<
53
- BuiltInCommonRuleId | BuiltInCommonOASRuleId | BuiltInOAS2RuleId | 'assertions',
59
+ BuiltInCommonOASRuleId | BuiltInOAS2RuleId | 'assertions',
54
60
  Oas2Rule,
55
61
  T
56
62
  >;
57
63
  export type Async2RuleSet<T = undefined> = RuleMap<
58
- BuiltInCommonRuleId | BuiltInAsync2RuleId | 'assertions',
64
+ BuiltInAsync2RuleId | 'assertions',
59
65
  Async2Rule,
60
66
  T
61
67
  >;
68
+ export type ArazzoRuleSet<T = undefined> = RuleMap<
69
+ BuiltInArazzoRuleId | 'assertions',
70
+ ArazzoRule,
71
+ T
72
+ >;
73
+
62
74
  export type Oas3PreprocessorsSet = Record<string, Oas3Preprocessor>;
63
75
  export type Oas2PreprocessorsSet = Record<string, Oas2Preprocessor>;
64
76
  export type Async2PreprocessorsSet = Record<string, Async2Preprocessor>;
77
+ export type ArazzoPreprocessorsSet = Record<string, ArazzoPreprocessor>;
78
+
65
79
  export type Oas3DecoratorsSet = Record<string, Oas3Preprocessor>;
66
80
  export type Oas2DecoratorsSet = Record<string, Oas2Preprocessor>;
67
81
  export type Async2DecoratorsSet = Record<string, Async2Preprocessor>;
82
+ export type ArazzoDecoratorsSet = Record<string, ArazzoPreprocessor>;
68
83
 
69
84
  export function detectSpec(root: any): SpecVersion {
70
85
  if (typeof root !== 'object') {
@@ -100,6 +115,10 @@ export function detectSpec(root: any): SpecVersion {
100
115
  throw new Error(`Unsupported AsyncAPI version: ${root.asyncapi}`);
101
116
  }
102
117
 
118
+ if (root.arazzo && root.arazzo.startsWith('1.')) {
119
+ return SpecVersion.Arazzo;
120
+ }
121
+
103
122
  throw new Error(`Unsupported specification`);
104
123
  }
105
124
 
@@ -108,6 +127,8 @@ export function getMajorSpecVersion(version: SpecVersion): SpecMajorVersion {
108
127
  return SpecMajorVersion.OAS2;
109
128
  } else if (version === SpecVersion.Async2) {
110
129
  return SpecMajorVersion.Async2;
130
+ } else if (version === SpecVersion.Arazzo) {
131
+ return SpecMajorVersion.Arazzo;
111
132
  } else {
112
133
  return SpecMajorVersion.OAS3;
113
134
  }
@@ -0,0 +1,11 @@
1
+ import { ArazzoRule } from '../../visitors';
2
+ import { Spec } from '../common/spec';
3
+ import type { ArazzoRuleSet } from '../../oas-types';
4
+ import { Assertions } from '../common/assertions';
5
+
6
+ export const rules: ArazzoRuleSet<'built-in'> = {
7
+ spec: Spec as ArazzoRule,
8
+ assertions: Assertions,
9
+ };
10
+
11
+ export const preprocessors = {};
@@ -607,4 +607,51 @@ describe('Oas3.1 spec', () => {
607
607
  ]
608
608
  `);
609
609
  });
610
+
611
+ it('should flag invalid dependentSchemas', async () => {
612
+ const document = parseYamlToDocument(
613
+ outdent`
614
+ openapi: 3.1.0
615
+ info:
616
+ version: 1.0.0
617
+ title: Example.com
618
+ description: info,
619
+ license:
620
+ name: Apache 2.0
621
+ url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
622
+ components:
623
+ schemas:
624
+ withInvalidDependentSchemas:
625
+ dependentSchemas:
626
+ - invalid1
627
+ - invalid2
628
+ `,
629
+ 'foobar.yaml'
630
+ );
631
+
632
+ const results = await lintDocument({
633
+ externalRefResolver: new BaseResolver(),
634
+ document,
635
+ config: await makeConfig({ spec: 'error' }),
636
+ });
637
+
638
+ expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
639
+ [
640
+ {
641
+ "from": undefined,
642
+ "location": [
643
+ {
644
+ "pointer": "#/components/schemas/withInvalidDependentSchemas/dependentSchemas",
645
+ "reportOnKey": false,
646
+ "source": "foobar.yaml",
647
+ },
648
+ ],
649
+ "message": "Expected type \`SchemaMap\` (object) but got \`array\`",
650
+ "ruleId": "spec",
651
+ "severity": "error",
652
+ "suggest": [],
653
+ },
654
+ ]
655
+ `);
656
+ });
610
657
  });
@@ -1,7 +1,8 @@
1
- import { UserContext } from '../../walk';
2
- import { Oas3_1Schema } from '../../typings/openapi';
3
1
  import { getAdditionalPropertiesOption, validateExample } from '../utils';
4
2
 
3
+ import type { UserContext } from '../../walk';
4
+ import type { Oas3_1Schema } from '../../typings/openapi';
5
+
5
6
  export const NoInvalidSchemaExamples: any = (opts: any) => {
6
7
  const allowAdditionalProperties = getAdditionalPropertiesOption(opts) ?? false;
7
8
  return {
@@ -1,6 +1,7 @@
1
+ import * as pluralize from 'pluralize';
1
2
  import { Oas3Rule, Oas2Rule } from '../../visitors';
2
3
  import { UserContext } from '../../walk';
3
- import { isPathParameter, isSingular } from '../../utils';
4
+ import { isPathParameter } from '../../utils';
4
5
 
5
6
  export const PathSegmentPlural: Oas3Rule | Oas2Rule = (opts) => {
6
7
  const { ignoreLastPathSegment, exceptions } = opts;
@@ -17,7 +18,7 @@ export const PathSegmentPlural: Oas3Rule | Oas2Rule = (opts) => {
17
18
 
18
19
  for (const pathSegment of pathSegments) {
19
20
  if (exceptions && exceptions.includes(pathSegment)) continue;
20
- if (!isPathParameter(pathSegment) && isSingular(pathSegment)) {
21
+ if (!isPathParameter(pathSegment) && pluralize.isSingular(pathSegment)) {
21
22
  report({
22
23
  message: `path segment \`${pathSegment}\` should be plural.`,
23
24
  location: location.key(),
@@ -1,11 +1,11 @@
1
- import type { Oas3Rule, Oas2Rule, Async2Rule } from '../../visitors';
1
+ import type { Oas3Rule, Oas2Rule, Async2Rule, ArazzoRule } from '../../visitors';
2
2
  import { isNamedType, SpecExtension } from '../../types';
3
3
  import { oasTypeOf, matchesJsonSchemaType, getSuggest, validateSchemaEnumType } from '../utils';
4
4
  import { isRef } from '../../ref-utils';
5
5
  import { isPlainObject } from '../../utils';
6
6
  import { UserContext } from '../../walk';
7
7
 
8
- export const Spec: Oas3Rule | Oas2Rule | Async2Rule = () => {
8
+ export const Spec: Oas3Rule | Oas2Rule | Async2Rule | ArazzoRule = () => {
9
9
  return {
10
10
  any(
11
11
  node: any,