@redocly/openapi-core 1.2.1 → 1.4.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 (192) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/lib/benchmark/benches/lint-with-many-rules.bench.js +4 -4
  3. package/lib/benchmark/benches/lint-with-nested-rule.bench.js +4 -4
  4. package/lib/benchmark/benches/lint-with-no-rules.bench.js +4 -4
  5. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +4 -4
  6. package/lib/benchmark/benches/lint-with-top-level-rule.bench.js +4 -4
  7. package/lib/benchmark/benches/recommended-oas3.bench.js +4 -4
  8. package/lib/benchmark/benches/resolve-with-no-external.bench.js +3 -3
  9. package/lib/benchmark/utils.js +3 -3
  10. package/lib/bundle.d.ts +4 -4
  11. package/lib/bundle.js +23 -23
  12. package/lib/config/all.d.ts +2 -2
  13. package/lib/config/all.js +44 -8
  14. package/lib/config/builtIn.js +2 -0
  15. package/lib/config/config-resolvers.js +25 -25
  16. package/lib/config/config.js +9 -9
  17. package/lib/config/index.js +5 -1
  18. package/lib/config/load.d.ts +1 -1
  19. package/lib/config/load.js +9 -6
  20. package/lib/config/minimal.d.ts +2 -2
  21. package/lib/config/minimal.js +34 -3
  22. package/lib/config/recommended-strict.d.ts +3 -0
  23. package/lib/config/recommended-strict.js +92 -0
  24. package/lib/config/recommended.d.ts +2 -2
  25. package/lib/config/recommended.js +34 -3
  26. package/lib/config/rules.d.ts +1 -1
  27. package/lib/config/types.d.ts +47 -46
  28. package/lib/config/types.js +2 -2
  29. package/lib/config/utils.d.ts +2 -0
  30. package/lib/config/utils.js +30 -15
  31. package/lib/decorators/common/filters/filter-helper.js +4 -4
  32. package/lib/decorators/common/filters/filter-in.js +2 -2
  33. package/lib/decorators/common/filters/filter-out.js +2 -2
  34. package/lib/decorators/common/info-description-override.js +1 -1
  35. package/lib/decorators/common/media-type-examples-override.js +3 -3
  36. package/lib/decorators/common/operation-description-override.js +1 -1
  37. package/lib/decorators/common/registry-dependencies.js +1 -1
  38. package/lib/decorators/common/remove-x-internal.js +4 -4
  39. package/lib/decorators/common/tag-description-override.js +1 -1
  40. package/lib/format/codeframes.d.ts +6 -6
  41. package/lib/format/format.d.ts +2 -2
  42. package/lib/format/format.js +12 -12
  43. package/lib/js-yaml/index.d.ts +2 -2
  44. package/lib/js-yaml/index.js +2 -2
  45. package/lib/lint.js +18 -18
  46. package/lib/oas-types.d.ts +12 -10
  47. package/lib/oas-types.js +2 -2
  48. package/lib/redocly/index.js +10 -10
  49. package/lib/redocly/registry-api.js +2 -2
  50. package/lib/resolve.d.ts +4 -4
  51. package/lib/resolve.js +18 -18
  52. package/lib/rules/ajv.js +1 -1
  53. package/lib/rules/async2/index.d.ts +2 -11
  54. package/lib/rules/common/assertions/asserts.d.ts +3 -3
  55. package/lib/rules/common/assertions/asserts.js +21 -21
  56. package/lib/rules/common/assertions/index.d.ts +4 -4
  57. package/lib/rules/common/assertions/index.js +3 -3
  58. package/lib/rules/common/assertions/utils.d.ts +4 -4
  59. package/lib/rules/common/assertions/utils.js +3 -3
  60. package/lib/rules/common/info-contact.js +1 -1
  61. package/lib/rules/common/info-license-url.js +1 -1
  62. package/lib/rules/common/info-license.js +1 -1
  63. package/lib/rules/common/no-enum-type-mismatch.js +3 -3
  64. package/lib/rules/common/no-http-verbs-in-paths.js +2 -2
  65. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  66. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  67. package/lib/rules/common/operation-2xx-response.js +2 -2
  68. package/lib/rules/common/operation-4xx-response.js +2 -2
  69. package/lib/rules/common/operation-description.js +1 -1
  70. package/lib/rules/common/operation-operationId.js +1 -1
  71. package/lib/rules/common/operation-summary.js +1 -1
  72. package/lib/rules/common/path-segment-plural.js +1 -1
  73. package/lib/rules/common/response-contains-header.js +2 -2
  74. package/lib/rules/common/spec-strict-refs.js +1 -1
  75. package/lib/rules/common/spec.js +11 -11
  76. package/lib/rules/common/tag-description.js +1 -1
  77. package/lib/rules/oas2/boolean-parameter-prefixes.d.ts +1 -1
  78. package/lib/rules/oas2/index.d.ts +2 -46
  79. package/lib/rules/oas2/remove-unused-components.js +1 -1
  80. package/lib/rules/oas2/request-mime-type.js +2 -2
  81. package/lib/rules/oas2/response-contains-property.js +2 -2
  82. package/lib/rules/oas2/response-mime-type.js +2 -2
  83. package/lib/rules/oas3/boolean-parameter-prefixes.d.ts +1 -1
  84. package/lib/rules/oas3/index.d.ts +1 -1
  85. package/lib/rules/oas3/index.js +1 -1
  86. package/lib/rules/oas3/no-invalid-media-type-examples.js +3 -3
  87. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +3 -3
  88. package/lib/rules/oas3/remove-unused-components.js +2 -2
  89. package/lib/rules/oas3/request-mime-type.js +3 -3
  90. package/lib/rules/oas3/response-contains-property.js +2 -2
  91. package/lib/rules/oas3/response-mime-type.js +3 -3
  92. package/lib/rules/utils.js +3 -3
  93. package/lib/types/asyncapi.js +21 -21
  94. package/lib/types/index.d.ts +8 -8
  95. package/lib/types/oas2.js +14 -14
  96. package/lib/types/oas3.js +27 -27
  97. package/lib/types/oas3_1.js +6 -6
  98. package/lib/types/redocly-yaml.d.ts +11 -0
  99. package/lib/types/redocly-yaml.js +71 -53
  100. package/lib/types/theme-config.js +1 -1
  101. package/lib/typings/common.d.ts +2 -2
  102. package/lib/typings/openapi.d.ts +6 -6
  103. package/lib/typings/swagger.d.ts +3 -3
  104. package/lib/utils.d.ts +5 -5
  105. package/lib/utils.js +3 -3
  106. package/lib/visitors.d.ts +40 -40
  107. package/lib/walk.d.ts +14 -15
  108. package/lib/walk.js +11 -11
  109. package/package.json +2 -2
  110. package/src/__tests__/lint.test.ts +40 -40
  111. package/src/__tests__/normalizeVisitors.test.ts +23 -5
  112. package/src/__tests__/ref-utils.test.ts +7 -7
  113. package/src/__tests__/resolve-http.test.ts +10 -10
  114. package/src/__tests__/resolve.test.ts +39 -39
  115. package/src/__tests__/walk.test.ts +48 -48
  116. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +95 -32
  117. package/src/config/__tests__/__snapshots__/config.test.ts.snap +81 -81
  118. package/src/config/__tests__/config-resolvers.test.ts +30 -1
  119. package/src/config/__tests__/config.test.ts +88 -88
  120. package/src/config/__tests__/load.test.ts +12 -8
  121. package/src/config/__tests__/utils.test.ts +18 -18
  122. package/src/config/all.ts +46 -9
  123. package/src/config/builtIn.ts +2 -0
  124. package/src/config/load.ts +4 -1
  125. package/src/config/minimal.ts +36 -4
  126. package/src/config/recommended-strict.ts +93 -0
  127. package/src/config/recommended.ts +36 -4
  128. package/src/config/types.ts +22 -8
  129. package/src/config/utils.ts +17 -0
  130. package/src/decorators/common/media-type-examples-override.ts +2 -2
  131. package/src/lint.ts +3 -3
  132. package/src/oas-types.ts +26 -3
  133. package/src/rules/__tests__/no-unresolved-refs.test.ts +26 -26
  134. package/src/rules/async2/__tests__/channels-kebab-case.test.ts +12 -12
  135. package/src/rules/async2/__tests__/no-channel-trailing-slash.test.ts +7 -7
  136. package/src/rules/async2/index.ts +2 -1
  137. package/src/rules/common/__tests__/info-license.test.ts +6 -6
  138. package/src/rules/common/__tests__/license-url.test.ts +6 -6
  139. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +13 -13
  140. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +18 -18
  141. package/src/rules/common/__tests__/no-identical-paths.test.ts +5 -5
  142. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +12 -12
  143. package/src/rules/common/__tests__/operation-2xx-response.test.ts +18 -18
  144. package/src/rules/common/__tests__/operation-4xx-response.test.ts +23 -23
  145. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +6 -6
  146. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +5 -5
  147. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +16 -16
  148. package/src/rules/common/__tests__/operation-singular-tag.test.ts +6 -6
  149. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +10 -10
  150. package/src/rules/common/__tests__/path-not-include-query.test.ts +6 -6
  151. package/src/rules/common/__tests__/path-params-defined.test.ts +21 -21
  152. package/src/rules/common/__tests__/paths-kebab-case.test.ts +11 -11
  153. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +18 -18
  154. package/src/rules/common/__tests__/security-defined.test.ts +21 -21
  155. package/src/rules/common/__tests__/spec-strict-refs.test.ts +9 -9
  156. package/src/rules/common/__tests__/spec.test.ts +102 -102
  157. package/src/rules/common/__tests__/tag-description.test.ts +6 -6
  158. package/src/rules/common/__tests__/tags-alphabetical.test.ts +12 -12
  159. package/src/rules/common/assertions/__tests__/index.test.ts +15 -15
  160. package/src/rules/common/assertions/__tests__/utils.test.ts +9 -9
  161. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +7 -7
  162. package/src/rules/oas2/__tests__/response-contains-header.test.ts +13 -13
  163. package/src/rules/oas2/__tests__/response-contains-property.test.ts +8 -8
  164. package/src/rules/oas2/__tests__/spec/info.test.ts +21 -21
  165. package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
  166. package/src/rules/oas2/__tests__/spec/paths.test.ts +12 -12
  167. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +1 -1
  168. package/src/rules/oas2/index.ts +3 -1
  169. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +7 -7
  170. package/src/rules/oas3/__tests__/component-name-unique.test.ts +186 -186
  171. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +18 -18
  172. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +6 -6
  173. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +36 -36
  174. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +11 -11
  175. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +7 -7
  176. package/src/rules/oas3/__tests__/no-unused-components.test.ts +31 -31
  177. package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +15 -15
  178. package/src/rules/oas3/__tests__/response-contains-header.test.ts +26 -26
  179. package/src/rules/oas3/__tests__/response-contains-property.test.ts +27 -27
  180. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
  181. package/src/rules/oas3/__tests__/spec/info.test.ts +21 -21
  182. package/src/rules/oas3/__tests__/spec/operation.test.ts +10 -10
  183. package/src/rules/oas3/__tests__/spec/paths.test.ts +13 -13
  184. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +2 -2
  185. package/src/rules/oas3/__tests__/spec/servers.test.ts +25 -25
  186. package/src/rules/oas3/__tests__/spec/spec.test.ts +56 -56
  187. package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +28 -28
  188. package/src/rules/oas3/index.ts +3 -3
  189. package/src/types/redocly-yaml.ts +75 -40
  190. package/src/visitors.ts +3 -3
  191. package/src/walk.ts +23 -10
  192. package/tsconfig.tsbuildinfo +1 -1
package/src/config/all.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { PluginStyleguideConfig } from './types';
2
2
 
3
- export default {
3
+ const all: PluginStyleguideConfig<'built-in'> = {
4
4
  rules: {
5
5
  'info-contact': 'error',
6
6
  'info-license': 'error',
@@ -28,13 +28,24 @@ export default {
28
28
  'operation-singular-tag': 'error',
29
29
  'no-unresolved-refs': 'error',
30
30
  'no-enum-type-mismatch': 'error',
31
- 'boolean-parameter-prefixes': 'error',
32
31
  'paths-kebab-case': 'error',
33
32
  'no-http-verbs-in-paths': 'error',
34
33
  'path-excludes-patterns': {
35
34
  severity: 'error',
36
35
  patterns: [],
37
36
  },
37
+ spec: 'error',
38
+ 'no-invalid-schema-examples': 'error',
39
+ 'no-invalid-parameter-examples': 'error',
40
+ 'scalar-property-missing-example': 'error',
41
+ 'spec-strict-refs': 'error',
42
+ 'path-http-verbs-order': 'error',
43
+ 'path-params-defined': 'error',
44
+ 'required-string-property-missing-min-length': 'error',
45
+ 'response-contains-header': 'error',
46
+ },
47
+ oas2Rules: {
48
+ 'boolean-parameter-prefixes': 'error',
38
49
  'request-mime-type': {
39
50
  severity: 'error',
40
51
  allowedValues: ['application/json'],
@@ -43,12 +54,7 @@ export default {
43
54
  severity: 'error',
44
55
  allowedValues: ['application/json'],
45
56
  },
46
- spec: 'error',
47
- 'no-invalid-schema-examples': 'error',
48
- 'no-invalid-parameter-examples': 'error',
49
- 'scalar-property-missing-example': 'error',
50
- 'spec-strict-refs': 'error',
51
- 'component-name-unique': 'error',
57
+ 'response-contains-property': 'error',
52
58
  },
53
59
  oas3_0Rules: {
54
60
  'no-invalid-media-type-examples': 'error',
@@ -60,8 +66,21 @@ export default {
60
66
  'no-undefined-server-variable': 'error',
61
67
  'no-server-variables-empty-enum': 'error',
62
68
  'operation-4xx-problem-details-rfc7807': 'error',
69
+ 'boolean-parameter-prefixes': 'error',
70
+ 'request-mime-type': {
71
+ severity: 'error',
72
+ allowedValues: ['application/json'],
73
+ },
74
+ 'response-mime-type': {
75
+ severity: 'error',
76
+ allowedValues: ['application/json'],
77
+ },
78
+ 'component-name-unique': 'error',
79
+ 'response-contains-property': 'error',
80
+ 'spec-components-invalid-map-name': 'error',
63
81
  },
64
82
  oas3_1Rules: {
83
+ 'no-invalid-media-type-examples': 'error',
65
84
  'no-server-example.com': 'error',
66
85
  'no-server-trailing-slash': 'error',
67
86
  'no-empty-servers': 'error',
@@ -70,5 +89,23 @@ export default {
70
89
  'no-undefined-server-variable': 'error',
71
90
  'no-server-variables-empty-enum': 'error',
72
91
  'operation-4xx-problem-details-rfc7807': 'error',
92
+ 'boolean-parameter-prefixes': 'error',
93
+ 'request-mime-type': {
94
+ severity: 'error',
95
+ allowedValues: ['application/json'],
96
+ },
97
+ 'response-mime-type': {
98
+ severity: 'error',
99
+ allowedValues: ['application/json'],
100
+ },
101
+ 'component-name-unique': 'error',
102
+ 'response-contains-property': 'error',
103
+ 'spec-components-invalid-map-name': 'error',
73
104
  },
74
- } as PluginStyleguideConfig;
105
+ async2Rules: {
106
+ 'channels-kebab-case': 'error',
107
+ 'no-channel-trailing-slash': 'error',
108
+ },
109
+ };
110
+
111
+ export default all;
@@ -1,4 +1,5 @@
1
1
  import recommended from './recommended';
2
+ import recommendedStrict from './recommended-strict';
2
3
  import all from './all';
3
4
  import minimal from './minimal';
4
5
  import { rules as oas3Rules } from '../rules/oas3';
@@ -13,6 +14,7 @@ import type { CustomRulesConfig, StyleguideRawConfig, Plugin } from './types';
13
14
 
14
15
  export const builtInConfigs: Record<string, StyleguideRawConfig> = {
15
16
  recommended,
17
+ 'recommended-strict': recommendedStrict,
16
18
  minimal,
17
19
  all,
18
20
  'redocly-registry': {
@@ -4,7 +4,7 @@ import { RedoclyClient } from '../redocly';
4
4
  import { isEmptyObject, loadYaml, doesYamlFileExist } from '../utils';
5
5
  import { parseYaml } from '../js-yaml';
6
6
  import { Config, DOMAINS } from './config';
7
- import { transformConfig } from './utils';
7
+ import { ConfigValidationError, transformConfig } from './utils';
8
8
  import { resolveConfig } from './config-resolvers';
9
9
 
10
10
  import type {
@@ -128,6 +128,9 @@ export async function getConfig(
128
128
  }
129
129
  return transformConfig(rawConfig);
130
130
  } catch (e) {
131
+ if (e instanceof ConfigValidationError) {
132
+ throw e;
133
+ }
131
134
  throw new Error(`Error parsing config file at '${configPath}': ${e.message}`);
132
135
  }
133
136
  }
@@ -1,6 +1,6 @@
1
1
  import type { PluginStyleguideConfig } from './types';
2
2
 
3
- export default {
3
+ const minimal: PluginStyleguideConfig<'built-in'> = {
4
4
  rules: {
5
5
  'info-contact': 'off',
6
6
  'info-license': 'off',
@@ -27,11 +27,25 @@ export default {
27
27
  'operation-singular-tag': 'off',
28
28
  'no-unresolved-refs': 'error',
29
29
  'no-enum-type-mismatch': 'warn',
30
- 'boolean-parameter-prefixes': 'off',
31
30
  'paths-kebab-case': 'off',
32
31
  spec: 'error',
33
32
  'spec-strict-refs': 'off',
34
- 'component-name-unique': 'off',
33
+ 'no-http-verbs-in-paths': 'off',
34
+ 'no-invalid-parameter-examples': 'off',
35
+ 'no-invalid-schema-examples': 'off',
36
+ 'path-excludes-patterns': 'off',
37
+ 'path-http-verbs-order': 'off',
38
+ 'path-params-defined': 'off',
39
+ 'required-string-property-missing-min-length': 'off',
40
+ 'response-contains-header': 'off',
41
+ 'path-segment-plural': 'off',
42
+ 'scalar-property-missing-example': 'off',
43
+ },
44
+ oas2Rules: {
45
+ 'boolean-parameter-prefixes': 'off',
46
+ 'request-mime-type': 'off',
47
+ 'response-contains-property': 'off',
48
+ 'response-mime-type': 'off',
35
49
  },
36
50
  oas3_0Rules: {
37
51
  'no-invalid-media-type-examples': {
@@ -46,6 +60,12 @@ export default {
46
60
  'no-undefined-server-variable': 'warn',
47
61
  'no-server-variables-empty-enum': 'error',
48
62
  'spec-components-invalid-map-name': 'warn',
63
+ 'boolean-parameter-prefixes': 'off',
64
+ 'component-name-unique': 'off',
65
+ 'operation-4xx-problem-details-rfc7807': 'off',
66
+ 'request-mime-type': 'off',
67
+ 'response-contains-property': 'off',
68
+ 'response-mime-type': 'off',
49
69
  },
50
70
  oas3_1Rules: {
51
71
  'no-invalid-media-type-examples': 'warn',
@@ -57,5 +77,17 @@ export default {
57
77
  'no-undefined-server-variable': 'warn',
58
78
  'no-server-variables-empty-enum': 'error',
59
79
  'spec-components-invalid-map-name': 'warn',
80
+ 'boolean-parameter-prefixes': 'off',
81
+ 'component-name-unique': 'off',
82
+ 'operation-4xx-problem-details-rfc7807': 'off',
83
+ 'request-mime-type': 'off',
84
+ 'response-contains-property': 'off',
85
+ 'response-mime-type': 'off',
60
86
  },
61
- } as PluginStyleguideConfig;
87
+ async2Rules: {
88
+ 'channels-kebab-case': 'off',
89
+ 'no-channel-trailing-slash': 'off',
90
+ },
91
+ };
92
+
93
+ export default minimal;
@@ -0,0 +1,93 @@
1
+ import type { PluginStyleguideConfig } from './types';
2
+
3
+ const recommendedStrict: PluginStyleguideConfig<'built-in'> = {
4
+ rules: {
5
+ 'info-contact': 'off',
6
+ 'info-license': 'error',
7
+ 'info-license-url': 'error',
8
+ 'tag-description': 'error',
9
+ 'tags-alphabetical': 'off',
10
+ 'parameter-description': 'off',
11
+ 'no-path-trailing-slash': 'error',
12
+ 'no-identical-paths': 'error',
13
+ 'no-ambiguous-paths': 'error',
14
+ 'path-declaration-must-exist': 'error',
15
+ 'path-not-include-query': 'error',
16
+ 'path-parameters-defined': 'error',
17
+ 'operation-description': 'off',
18
+ 'operation-2xx-response': 'error',
19
+ 'operation-4xx-response': 'error',
20
+ 'operation-operationId': 'error',
21
+ 'operation-summary': 'error',
22
+ 'operation-operationId-unique': 'error',
23
+ 'operation-operationId-url-safe': 'error',
24
+ 'operation-parameters-unique': 'error',
25
+ 'operation-tag-defined': 'off',
26
+ 'security-defined': 'error',
27
+ 'operation-singular-tag': 'off',
28
+ 'no-unresolved-refs': 'error',
29
+ 'no-enum-type-mismatch': 'error',
30
+ 'paths-kebab-case': 'off',
31
+ spec: 'error',
32
+ 'spec-strict-refs': 'off',
33
+ 'no-http-verbs-in-paths': 'off',
34
+ 'no-invalid-parameter-examples': 'off',
35
+ 'no-invalid-schema-examples': 'off',
36
+ 'path-excludes-patterns': 'off',
37
+ 'path-http-verbs-order': 'off',
38
+ 'path-params-defined': 'off',
39
+ 'path-segment-plural': 'off',
40
+ 'required-string-property-missing-min-length': 'off',
41
+ 'response-contains-header': 'off',
42
+ 'scalar-property-missing-example': 'off',
43
+ },
44
+ oas2Rules: {
45
+ 'boolean-parameter-prefixes': 'off',
46
+ 'request-mime-type': 'off',
47
+ 'response-contains-property': 'off',
48
+ 'response-mime-type': 'off',
49
+ },
50
+ oas3_0Rules: {
51
+ 'no-invalid-media-type-examples': {
52
+ severity: 'error',
53
+ allowAdditionalProperties: false,
54
+ },
55
+ 'no-server-example.com': 'error',
56
+ 'no-server-trailing-slash': 'error',
57
+ 'no-empty-servers': 'error',
58
+ 'no-example-value-and-externalValue': 'error',
59
+ 'no-unused-components': 'error',
60
+ 'no-undefined-server-variable': 'error',
61
+ 'no-server-variables-empty-enum': 'error',
62
+ 'spec-components-invalid-map-name': 'error',
63
+ 'boolean-parameter-prefixes': 'off',
64
+ 'component-name-unique': 'off',
65
+ 'operation-4xx-problem-details-rfc7807': 'off',
66
+ 'request-mime-type': 'off',
67
+ 'response-contains-property': 'off',
68
+ 'response-mime-type': 'off',
69
+ },
70
+ oas3_1Rules: {
71
+ 'no-invalid-media-type-examples': 'error',
72
+ 'no-server-example.com': 'error',
73
+ 'no-server-trailing-slash': 'error',
74
+ 'no-empty-servers': 'error',
75
+ 'no-example-value-and-externalValue': 'error',
76
+ 'no-unused-components': 'error',
77
+ 'no-undefined-server-variable': 'error',
78
+ 'no-server-variables-empty-enum': 'error',
79
+ 'spec-components-invalid-map-name': 'error',
80
+ 'boolean-parameter-prefixes': 'off',
81
+ 'component-name-unique': 'off',
82
+ 'operation-4xx-problem-details-rfc7807': 'off',
83
+ 'request-mime-type': 'off',
84
+ 'response-contains-property': 'off',
85
+ 'response-mime-type': 'off',
86
+ },
87
+ async2Rules: {
88
+ 'channels-kebab-case': 'off',
89
+ 'no-channel-trailing-slash': 'off',
90
+ },
91
+ };
92
+
93
+ export default recommendedStrict;
@@ -1,6 +1,6 @@
1
1
  import type { PluginStyleguideConfig } from './types';
2
2
 
3
- export default {
3
+ const recommended: PluginStyleguideConfig<'built-in'> = {
4
4
  rules: {
5
5
  'info-contact': 'off',
6
6
  'info-license': 'warn',
@@ -27,11 +27,25 @@ export default {
27
27
  'operation-singular-tag': 'off',
28
28
  'no-unresolved-refs': 'error',
29
29
  'no-enum-type-mismatch': 'error',
30
- 'boolean-parameter-prefixes': 'off',
31
30
  'paths-kebab-case': 'off',
32
31
  spec: 'error',
33
32
  'spec-strict-refs': 'off',
34
- 'component-name-unique': 'off',
33
+ 'no-http-verbs-in-paths': 'off',
34
+ 'no-invalid-parameter-examples': 'off',
35
+ 'no-invalid-schema-examples': 'off',
36
+ 'path-excludes-patterns': 'off',
37
+ 'path-http-verbs-order': 'off',
38
+ 'path-params-defined': 'off',
39
+ 'path-segment-plural': 'off',
40
+ 'required-string-property-missing-min-length': 'off',
41
+ 'response-contains-header': 'off',
42
+ 'scalar-property-missing-example': 'off',
43
+ },
44
+ oas2Rules: {
45
+ 'boolean-parameter-prefixes': 'off',
46
+ 'request-mime-type': 'off',
47
+ 'response-contains-property': 'off',
48
+ 'response-mime-type': 'off',
35
49
  },
36
50
  oas3_0Rules: {
37
51
  'no-invalid-media-type-examples': {
@@ -46,6 +60,12 @@ export default {
46
60
  'no-undefined-server-variable': 'error',
47
61
  'no-server-variables-empty-enum': 'error',
48
62
  'spec-components-invalid-map-name': 'error',
63
+ 'boolean-parameter-prefixes': 'off',
64
+ 'component-name-unique': 'off',
65
+ 'operation-4xx-problem-details-rfc7807': 'off',
66
+ 'request-mime-type': 'off',
67
+ 'response-contains-property': 'off',
68
+ 'response-mime-type': 'off',
49
69
  },
50
70
  oas3_1Rules: {
51
71
  'no-invalid-media-type-examples': 'warn',
@@ -57,5 +77,17 @@ export default {
57
77
  'no-undefined-server-variable': 'error',
58
78
  'no-server-variables-empty-enum': 'error',
59
79
  'spec-components-invalid-map-name': 'error',
80
+ 'boolean-parameter-prefixes': 'off',
81
+ 'component-name-unique': 'off',
82
+ 'operation-4xx-problem-details-rfc7807': 'off',
83
+ 'request-mime-type': 'off',
84
+ 'response-contains-property': 'off',
85
+ 'response-mime-type': 'off',
60
86
  },
61
- } as PluginStyleguideConfig;
87
+ async2Rules: {
88
+ 'channels-kebab-case': 'off',
89
+ 'no-channel-trailing-slash': 'off',
90
+ },
91
+ };
92
+
93
+ export default recommended;
@@ -11,11 +11,19 @@ import type {
11
11
  Async2PreprocessorsSet,
12
12
  Async2DecoratorsSet,
13
13
  Async2RuleSet,
14
+ RuleMap,
14
15
  } from '../oas-types';
15
16
 
16
17
  import type { NodeType } from '../types';
17
18
  import { Location } from '../ref-utils';
18
19
  import type { SkipFunctionContext } from '../visitors';
20
+ import {
21
+ BuiltInAsync2RuleId,
22
+ BuiltInCommonOASRuleId,
23
+ BuiltInCommonRuleId,
24
+ BuiltInOAS2RuleId,
25
+ BuiltInOAS3RuleId,
26
+ } from '../types/redocly-yaml';
19
27
 
20
28
  export type RuleSeverity = ProblemSeverity | 'off';
21
29
 
@@ -37,17 +45,17 @@ export type PreprocessorConfig =
37
45
 
38
46
  export type DecoratorConfig = PreprocessorConfig;
39
47
 
40
- export type StyleguideRawConfig = {
48
+ export type StyleguideRawConfig<T = undefined> = {
41
49
  plugins?: (string | Plugin)[];
42
50
  extends?: string[];
43
51
  doNotResolveExamples?: boolean;
44
52
  recommendedFallback?: boolean;
45
53
 
46
- rules?: Record<string, RuleConfig>;
47
- oas2Rules?: Record<string, RuleConfig>;
48
- oas3_0Rules?: Record<string, RuleConfig>;
49
- oas3_1Rules?: Record<string, RuleConfig>;
50
- async2Rules?: Record<string, RuleConfig>;
54
+ rules?: RuleMap<BuiltInCommonRuleId | BuiltInCommonOASRuleId, RuleConfig, T>;
55
+ oas2Rules?: RuleMap<BuiltInOAS2RuleId, RuleConfig, T>;
56
+ oas3_0Rules?: RuleMap<BuiltInOAS3RuleId, RuleConfig, T>;
57
+ oas3_1Rules?: RuleMap<BuiltInOAS3RuleId, RuleConfig, T>;
58
+ async2Rules?: RuleMap<BuiltInAsync2RuleId, RuleConfig, T>;
51
59
 
52
60
  preprocessors?: Record<string, PreprocessorConfig>;
53
61
  oas2Preprocessors?: Record<string, PreprocessorConfig>;
@@ -118,7 +126,10 @@ export type Plugin = {
118
126
  assertions?: AssertionsConfig;
119
127
  };
120
128
 
121
- export type PluginStyleguideConfig = Omit<StyleguideRawConfig, 'plugins' | 'extends'>;
129
+ export type PluginStyleguideConfig<T = undefined> = Omit<
130
+ StyleguideRawConfig<T>,
131
+ 'plugins' | 'extends'
132
+ >;
122
133
 
123
134
  export type ResolveHeader =
124
135
  | {
@@ -221,14 +232,17 @@ export type RulesFields =
221
232
  | 'oas2Rules'
222
233
  | 'oas3_0Rules'
223
234
  | 'oas3_1Rules'
235
+ | 'async2Rules'
224
236
  | 'preprocessors'
225
237
  | 'oas2Preprocessors'
226
238
  | 'oas3_0Preprocessors'
227
239
  | 'oas3_1Preprocessors'
240
+ | 'async2Preprocessors'
228
241
  | 'decorators'
229
242
  | 'oas2Decorators'
230
243
  | 'oas3_0Decorators'
231
- | 'oas3_1Decorators';
244
+ | 'oas3_1Decorators'
245
+ | 'async2Decorators';
232
246
 
233
247
  export enum AuthProviderType {
234
248
  OIDC = 'OIDC',
@@ -55,16 +55,19 @@ function extractFlatConfig<
55
55
  oas2Rules,
56
56
  oas3_0Rules,
57
57
  oas3_1Rules,
58
+ async2Rules,
58
59
 
59
60
  preprocessors,
60
61
  oas2Preprocessors,
61
62
  oas3_0Preprocessors,
62
63
  oas3_1Preprocessors,
64
+ async2Preprocessors,
63
65
 
64
66
  decorators,
65
67
  oas2Decorators,
66
68
  oas3_0Decorators,
67
69
  oas3_1Decorators,
70
+ async2Decorators,
68
71
 
69
72
  ...rawConfigRest
70
73
  }: T): {
@@ -79,16 +82,19 @@ function extractFlatConfig<
79
82
  oas2Rules,
80
83
  oas3_0Rules,
81
84
  oas3_1Rules,
85
+ async2Rules,
82
86
 
83
87
  preprocessors,
84
88
  oas2Preprocessors,
85
89
  oas3_0Preprocessors,
86
90
  oas3_1Preprocessors,
91
+ async2Preprocessors,
87
92
 
88
93
  decorators,
89
94
  oas2Decorators,
90
95
  oas3_0Decorators,
91
96
  oas3_1Decorators,
97
+ async2Decorators,
92
98
 
93
99
  doNotResolveExamples: rawConfigRest.resolve?.doNotResolveExamples,
94
100
  };
@@ -145,16 +151,19 @@ export function mergeExtends(rulesConfList: ResolvedStyleguideConfig[]) {
145
151
  oas2Rules: {},
146
152
  oas3_0Rules: {},
147
153
  oas3_1Rules: {},
154
+ async2Rules: {},
148
155
 
149
156
  preprocessors: {},
150
157
  oas2Preprocessors: {},
151
158
  oas3_0Preprocessors: {},
152
159
  oas3_1Preprocessors: {},
160
+ async2Preprocessors: {},
153
161
 
154
162
  decorators: {},
155
163
  oas2Decorators: {},
156
164
  oas3_0Decorators: {},
157
165
  oas3_1Decorators: {},
166
+ async2Decorators: {},
158
167
 
159
168
  plugins: [],
160
169
  pluginPaths: [],
@@ -175,6 +184,8 @@ export function mergeExtends(rulesConfList: ResolvedStyleguideConfig[]) {
175
184
  assignExisting(result.oas3_0Rules, rulesConf.rules || {});
176
185
  Object.assign(result.oas3_1Rules, rulesConf.oas3_1Rules);
177
186
  assignExisting(result.oas3_1Rules, rulesConf.rules || {});
187
+ Object.assign(result.async2Rules, rulesConf.async2Rules);
188
+ assignExisting(result.async2Rules, rulesConf.rules || {});
178
189
 
179
190
  Object.assign(result.preprocessors, rulesConf.preprocessors);
180
191
  Object.assign(result.oas2Preprocessors, rulesConf.oas2Preprocessors);
@@ -183,6 +194,8 @@ export function mergeExtends(rulesConfList: ResolvedStyleguideConfig[]) {
183
194
  assignExisting(result.oas3_0Preprocessors, rulesConf.preprocessors || {});
184
195
  Object.assign(result.oas3_1Preprocessors, rulesConf.oas3_1Preprocessors);
185
196
  assignExisting(result.oas3_1Preprocessors, rulesConf.preprocessors || {});
197
+ Object.assign(result.async2Preprocessors, rulesConf.async2Preprocessors);
198
+ assignExisting(result.async2Preprocessors, rulesConf.preprocessors || {});
186
199
 
187
200
  Object.assign(result.decorators, rulesConf.decorators);
188
201
  Object.assign(result.oas2Decorators, rulesConf.oas2Decorators);
@@ -191,6 +204,8 @@ export function mergeExtends(rulesConfList: ResolvedStyleguideConfig[]) {
191
204
  assignExisting(result.oas3_0Decorators, rulesConf.decorators || {});
192
205
  Object.assign(result.oas3_1Decorators, rulesConf.oas3_1Decorators);
193
206
  assignExisting(result.oas3_1Decorators, rulesConf.decorators || {});
207
+ Object.assign(result.async2Decorators, rulesConf.async2Decorators);
208
+ assignExisting(result.async2Decorators, rulesConf.decorators || {});
194
209
 
195
210
  result.plugins!.push(...(rulesConf.plugins || []));
196
211
  result.pluginPaths!.push(...(rulesConf.pluginPaths || []));
@@ -347,3 +362,5 @@ export function getUniquePlugins(plugins: Plugin[]): Plugin[] {
347
362
  }
348
363
  return results;
349
364
  }
365
+
366
+ export class ConfigValidationError extends Error {}
@@ -2,7 +2,7 @@ import { Oas3Decorator } from '../../visitors';
2
2
  import { Oas3Operation, Oas3RequestBody, Oas3Response } from '../../typings/openapi';
3
3
  import { yamlAndJsonSyncReader } from '../../utils';
4
4
  import { isRef } from '../../ref-utils';
5
- import { ResolveFn, UserContext } from '../../walk';
5
+ import { NonUndefined, ResolveFn, UserContext } from '../../walk';
6
6
 
7
7
  export const MediaTypeExamplesOverride: Oas3Decorator = ({ operationIds }) => {
8
8
  return {
@@ -69,7 +69,7 @@ export const MediaTypeExamplesOverride: Oas3Decorator = ({ operationIds }) => {
69
69
  };
70
70
  };
71
71
 
72
- function checkAndResolveRef<T>(node: any, resolver: ResolveFn): T | undefined {
72
+ function checkAndResolveRef<T extends NonUndefined>(node: any, resolver: ResolveFn): T | undefined {
73
73
  if (!isRef(node)) {
74
74
  return node;
75
75
  }
package/src/lint.ts CHANGED
@@ -5,7 +5,7 @@ import { ProblemSeverity, WalkContext, walkDocument } from './walk';
5
5
  import { StyleguideConfig, Config, initRules, defaultPlugin, resolvePlugins } from './config';
6
6
  import { normalizeTypes } from './types';
7
7
  import { releaseAjvInstance } from './rules/ajv';
8
- import { Oas3RuleSet, SpecVersion, getMajorSpecVersion, detectSpec, getTypes } from './oas-types';
8
+ import { SpecVersion, getMajorSpecVersion, detectSpec, getTypes } from './oas-types';
9
9
  import { ConfigTypes } from './types/redocly-yaml';
10
10
  import { Spec } from './rules/common/spec';
11
11
 
@@ -65,8 +65,8 @@ export async function lintDocument(opts: {
65
65
  visitorsData: {},
66
66
  };
67
67
 
68
- const preprocessors = initRules(rules as any, config, 'preprocessors', specVersion);
69
- const regularRules = initRules(rules as Oas3RuleSet[], config, 'rules', specVersion);
68
+ const preprocessors = initRules(rules, config, 'preprocessors', specVersion);
69
+ const regularRules = initRules(rules, config, 'rules', specVersion);
70
70
 
71
71
  let resolvedRefMap = await resolveDocument({
72
72
  rootDocument: document,
package/src/oas-types.ts CHANGED
@@ -10,6 +10,13 @@ import { Oas2Types } from './types/oas2';
10
10
  import { Oas3Types } from './types/oas3';
11
11
  import { Oas3_1Types } from './types/oas3_1';
12
12
  import { AsyncApi2Types } from './types/asyncapi';
13
+ import {
14
+ BuiltInAsync2RuleId,
15
+ BuiltInCommonOASRuleId,
16
+ BuiltInCommonRuleId,
17
+ BuiltInOAS2RuleId,
18
+ BuiltInOAS3RuleId,
19
+ } from './types/redocly-yaml';
13
20
 
14
21
  export type RuleSet<T> = Record<string, T>;
15
22
 
@@ -33,9 +40,25 @@ const typesMap = {
33
40
  [SpecVersion.Async2]: AsyncApi2Types,
34
41
  };
35
42
 
36
- export type Oas3RuleSet = Record<string, Oas3Rule>;
37
- export type Oas2RuleSet = Record<string, Oas2Rule>;
38
- export type Async2RuleSet = Record<string, Async2Rule>;
43
+ export type RuleMap<Key extends string, RuleConfig, T> = Record<
44
+ T extends 'built-in' ? Key : string,
45
+ RuleConfig
46
+ >;
47
+ export type Oas3RuleSet<T = undefined> = RuleMap<
48
+ BuiltInCommonRuleId | BuiltInCommonOASRuleId | BuiltInOAS3RuleId | 'assertions',
49
+ Oas3Rule,
50
+ T
51
+ >;
52
+ export type Oas2RuleSet<T = undefined> = RuleMap<
53
+ BuiltInCommonRuleId | BuiltInCommonOASRuleId | BuiltInOAS2RuleId | 'assertions',
54
+ Oas2Rule,
55
+ T
56
+ >;
57
+ export type Async2RuleSet<T = undefined> = RuleMap<
58
+ BuiltInCommonRuleId | BuiltInAsync2RuleId | 'assertions',
59
+ Async2Rule,
60
+ T
61
+ >;
39
62
  export type Oas3PreprocessorsSet = Record<string, Oas3Preprocessor>;
40
63
  export type Oas2PreprocessorsSet = Record<string, Oas2Preprocessor>;
41
64
  export type Async2PreprocessorsSet = Record<string, Async2Preprocessor>;