@redocly/openapi-core 1.0.0-beta.104 → 1.0.0-beta.107

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 (203) hide show
  1. package/README.md +4 -4
  2. package/__tests__/utils.ts +8 -6
  3. package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
  4. package/lib/benchmark/utils.d.ts +2 -2
  5. package/lib/benchmark/utils.js +2 -2
  6. package/lib/bundle.d.ts +2 -2
  7. package/lib/bundle.js +2 -2
  8. package/lib/config/all.d.ts +2 -2
  9. package/lib/config/all.js +1 -1
  10. package/lib/config/builtIn.d.ts +2 -2
  11. package/lib/config/builtIn.js +2 -2
  12. package/lib/config/config-resolvers.d.ts +5 -5
  13. package/lib/config/config-resolvers.js +39 -36
  14. package/lib/config/config.d.ts +6 -5
  15. package/lib/config/config.js +27 -20
  16. package/lib/config/load.js +6 -7
  17. package/lib/config/minimal.d.ts +2 -2
  18. package/lib/config/minimal.js +3 -2
  19. package/lib/config/recommended.d.ts +2 -2
  20. package/lib/config/recommended.js +3 -2
  21. package/lib/config/rules.d.ts +2 -2
  22. package/lib/config/rules.js +1 -1
  23. package/lib/config/types.d.ts +23 -19
  24. package/lib/config/utils.d.ts +5 -5
  25. package/lib/config/utils.js +43 -26
  26. package/lib/decorators/common/remove-x-internal.js +2 -2
  27. package/lib/format/format.js +1 -1
  28. package/lib/index.d.ts +2 -2
  29. package/lib/index.js +3 -2
  30. package/lib/js-yaml/index.js +1 -6
  31. package/lib/lint.d.ts +2 -2
  32. package/lib/lint.js +16 -6
  33. package/lib/redocly/registry-api.d.ts +1 -1
  34. package/lib/redocly/registry-api.js +2 -2
  35. package/lib/rules/ajv.d.ts +1 -1
  36. package/lib/rules/ajv.js +6 -6
  37. package/lib/rules/common/info-license-url.d.ts +1 -1
  38. package/lib/rules/common/info-license-url.js +5 -10
  39. package/lib/rules/common/info-license.d.ts +2 -0
  40. package/lib/rules/common/info-license.js +17 -0
  41. package/lib/rules/common/no-enum-type-mismatch.js +1 -3
  42. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  43. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  44. package/lib/rules/common/operation-operationId.js +1 -1
  45. package/lib/rules/common/path-not-include-query.js +1 -1
  46. package/lib/rules/common/paths-kebab-case.js +4 -1
  47. package/lib/rules/common/spec.js +1 -1
  48. package/lib/rules/oas2/index.js +4 -4
  49. package/lib/rules/oas2/remove-unused-components.js +3 -3
  50. package/lib/rules/oas3/index.js +4 -4
  51. package/lib/rules/oas3/no-empty-servers.js +1 -1
  52. package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
  53. package/lib/rules/oas3/remove-unused-components.js +2 -2
  54. package/lib/rules/other/stats.js +43 -14
  55. package/lib/rules/utils.d.ts +3 -2
  56. package/lib/rules/utils.js +19 -4
  57. package/lib/types/index.d.ts +2 -2
  58. package/lib/types/redocly-yaml.js +8 -7
  59. package/lib/utils.d.ts +5 -2
  60. package/lib/utils.js +20 -2
  61. package/lib/walk.d.ts +2 -1
  62. package/lib/walk.js +6 -3
  63. package/package.json +2 -2
  64. package/src/__tests__/__snapshots__/bundle.test.ts.snap +141 -0
  65. package/src/__tests__/bundle.test.ts +68 -34
  66. package/src/__tests__/codeframes.test.ts +13 -14
  67. package/src/__tests__/fixtures/.redocly.lint-ignore.yaml +5 -0
  68. package/src/__tests__/js-yaml.test.ts +6 -4
  69. package/src/__tests__/lint.test.ts +127 -12
  70. package/src/__tests__/login.test.ts +2 -2
  71. package/src/__tests__/normalizeVisitors.test.ts +4 -4
  72. package/src/__tests__/ref-utils.test.ts +13 -13
  73. package/src/__tests__/resolve-http.test.ts +1 -1
  74. package/src/__tests__/resolve.test.ts +14 -11
  75. package/src/__tests__/utils.test.ts +42 -1
  76. package/src/__tests__/walk.test.ts +48 -56
  77. package/src/benchmark/benches/lint-with-many-rules.bench.ts +1 -1
  78. package/src/benchmark/benches/lint-with-nested-rule.bench.ts +1 -1
  79. package/src/benchmark/benches/lint-with-no-rules.bench.ts +1 -1
  80. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +1 -1
  81. package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +1 -1
  82. package/src/benchmark/benches/recommended-oas3.bench.ts +3 -3
  83. package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
  84. package/src/benchmark/benchmark.js +9 -5
  85. package/src/benchmark/utils.ts +5 -5
  86. package/src/bundle.ts +18 -17
  87. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +3 -1
  88. package/src/config/__tests__/config-resolvers.test.ts +123 -121
  89. package/src/config/__tests__/config.test.ts +76 -76
  90. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +4 -2
  91. package/src/config/__tests__/fixtures/resolve-config/plugin.js +4 -1
  92. package/src/config/__tests__/load.test.ts +2 -2
  93. package/src/config/__tests__/resolve-plugins.test.ts +3 -3
  94. package/src/config/__tests__/utils.test.ts +83 -0
  95. package/src/config/all.ts +3 -4
  96. package/src/config/builtIn.ts +5 -5
  97. package/src/config/config-resolvers.ts +122 -83
  98. package/src/config/config.ts +36 -32
  99. package/src/config/load.ts +13 -16
  100. package/src/config/minimal.ts +5 -4
  101. package/src/config/recommended.ts +5 -4
  102. package/src/config/rules.ts +6 -6
  103. package/src/config/types.ts +28 -19
  104. package/src/config/utils.ts +74 -54
  105. package/src/decorators/__tests__/filter-out.test.ts +8 -4
  106. package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
  107. package/src/decorators/common/filters/filter-helper.ts +1 -1
  108. package/src/decorators/common/info-description-override.ts +1 -1
  109. package/src/decorators/common/operation-description-override.ts +1 -1
  110. package/src/decorators/common/remove-x-internal.ts +4 -4
  111. package/src/decorators/common/tag-description-override.ts +1 -1
  112. package/src/format/codeframes.ts +4 -4
  113. package/src/format/format.ts +10 -10
  114. package/src/index.ts +3 -4
  115. package/src/js-yaml/index.ts +3 -8
  116. package/src/lint.ts +22 -18
  117. package/src/oas-types.ts +1 -6
  118. package/src/redocly/__tests__/redocly-client.test.ts +25 -19
  119. package/src/redocly/index.ts +6 -4
  120. package/src/redocly/registry-api.ts +6 -6
  121. package/src/ref-utils.ts +2 -2
  122. package/src/resolve.ts +7 -4
  123. package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
  124. package/src/rules/__tests__/utils.test.ts +160 -0
  125. package/src/rules/ajv.ts +7 -8
  126. package/src/rules/common/__tests__/info-description.test.ts +3 -3
  127. package/src/rules/common/__tests__/info-license.test.ts +2 -2
  128. package/src/rules/common/__tests__/license-url.test.ts +2 -2
  129. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
  130. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +8 -8
  131. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
  132. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
  133. package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
  134. package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
  135. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
  136. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
  137. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
  138. package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
  139. package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
  140. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
  141. package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
  142. package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
  143. package/src/rules/common/__tests__/paths-kebab-case.test.ts +15 -15
  144. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
  145. package/src/rules/common/__tests__/spec.test.ts +2 -2
  146. package/src/rules/common/__tests__/tag-description.test.ts +2 -2
  147. package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
  148. package/src/rules/common/assertions/__tests__/asserts.test.ts +513 -130
  149. package/src/rules/common/assertions/index.ts +6 -6
  150. package/src/rules/common/info-license-url.ts +4 -9
  151. package/src/rules/common/info-license.ts +15 -0
  152. package/src/rules/common/no-ambiguous-paths.ts +1 -1
  153. package/src/rules/common/no-enum-type-mismatch.ts +12 -9
  154. package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
  155. package/src/rules/common/no-invalid-schema-examples.ts +4 -4
  156. package/src/rules/common/operation-operationId.ts +1 -1
  157. package/src/rules/common/operation-parameters-unique.ts +2 -2
  158. package/src/rules/common/path-not-include-query.ts +1 -1
  159. package/src/rules/common/path-params-defined.ts +1 -1
  160. package/src/rules/common/paths-kebab-case.ts +4 -1
  161. package/src/rules/common/scalar-property-missing-example.ts +1 -1
  162. package/src/rules/common/spec.ts +10 -7
  163. package/src/rules/no-unresolved-refs.ts +1 -1
  164. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  165. package/src/rules/oas2/__tests__/spec/info.test.ts +12 -12
  166. package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
  167. package/src/rules/oas2/__tests__/spec/paths.test.ts +10 -10
  168. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +6 -2
  169. package/src/rules/oas2/__tests__/spec/utils.ts +6 -6
  170. package/src/rules/oas2/index.ts +3 -3
  171. package/src/rules/oas2/remove-unused-components.ts +13 -8
  172. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  173. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
  174. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +13 -13
  175. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
  176. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  177. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
  178. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
  179. package/src/rules/oas3/__tests__/spec/info.test.ts +12 -12
  180. package/src/rules/oas3/__tests__/spec/operation.test.ts +8 -8
  181. package/src/rules/oas3/__tests__/spec/paths.test.ts +10 -10
  182. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +12 -12
  183. package/src/rules/oas3/__tests__/spec/servers.test.ts +15 -15
  184. package/src/rules/oas3/__tests__/spec/spec.test.ts +6 -6
  185. package/src/rules/oas3/__tests__/spec/utils.ts +6 -6
  186. package/src/rules/oas3/index.ts +3 -3
  187. package/src/rules/oas3/no-empty-servers.ts +1 -1
  188. package/src/rules/oas3/no-invalid-media-type-examples.ts +14 -6
  189. package/src/rules/oas3/no-servers-empty-enum.ts +9 -10
  190. package/src/rules/oas3/remove-unused-components.ts +18 -7
  191. package/src/rules/other/stats.ts +46 -17
  192. package/src/rules/utils.ts +19 -3
  193. package/src/types/index.ts +5 -5
  194. package/src/types/redocly-yaml.ts +8 -7
  195. package/src/typings/common.ts +9 -1
  196. package/src/typings/openapi.ts +1 -1
  197. package/src/utils.ts +31 -8
  198. package/src/visitors.ts +4 -4
  199. package/src/walk.ts +15 -11
  200. package/tsconfig.tsbuildinfo +1 -1
  201. package/lib/rules/common/license-url.d.ts +0 -2
  202. package/lib/rules/common/license-url.js +0 -12
  203. package/src/rules/common/license-url.ts +0 -10
@@ -1,4 +1,4 @@
1
- import { Config } from '../config';
1
+ import { Config, StyleguideConfig } from '../config';
2
2
  import { getMergedConfig } from '../utils';
3
3
 
4
4
  const testConfig: Config = {
@@ -6,11 +6,11 @@ const testConfig: Config = {
6
6
  apis: {
7
7
  'test@v1': {
8
8
  root: 'resources/pets.yaml',
9
- lint: { rules: { 'operation-summary': 'warn' } },
9
+ styleguide: { rules: { 'operation-summary': 'warn' } },
10
10
  },
11
11
  },
12
12
  organization: 'redocly-test',
13
- lint: {
13
+ styleguide: {
14
14
  rules: { 'operation-summary': 'error', 'no-empty-servers': 'error' },
15
15
  plugins: [],
16
16
  },
@@ -19,11 +19,11 @@ const testConfig: Config = {
19
19
  apis: {
20
20
  'test@v1': {
21
21
  root: 'resources/pets.yaml',
22
- lint: { rules: { 'operation-summary': 'warn' } },
22
+ styleguide: { rules: { 'operation-summary': 'warn' } },
23
23
  },
24
24
  },
25
- // @ts-ignore
26
- lint: {
25
+
26
+ styleguide: {
27
27
  rawConfig: {
28
28
  rules: { 'operation-summary': 'error', 'no-empty-servers': 'error' },
29
29
  plugins: [],
@@ -42,7 +42,7 @@ const testConfig: Config = {
42
42
  },
43
43
  preprocessors: { oas2: {}, oas3_0: {}, oas3_1: {} },
44
44
  decorators: { oas2: {}, oas3_0: {}, oas3_1: {} },
45
- },
45
+ } as unknown as StyleguideConfig,
46
46
  'features.openapi': {},
47
47
  'features.mockServer': {},
48
48
  resolve: { http: { headers: [] } },
@@ -50,23 +50,53 @@ const testConfig: Config = {
50
50
  };
51
51
 
52
52
  describe('getMergedConfig', () => {
53
- it('should get lint defined in "apis" section', () => {
53
+ it('should get styleguide defined in "apis" section', () => {
54
54
  expect(getMergedConfig(testConfig, 'test@v1')).toMatchInlineSnapshot(`
55
55
  Config {
56
56
  "apis": Object {
57
57
  "test@v1": Object {
58
- "lint": Object {
58
+ "root": "resources/pets.yaml",
59
+ "styleguide": Object {
59
60
  "rules": Object {
60
61
  "operation-summary": "warn",
61
62
  },
62
63
  },
63
- "root": "resources/pets.yaml",
64
64
  },
65
65
  },
66
66
  "configFile": "redocly.yaml",
67
67
  "features.mockServer": Object {},
68
68
  "features.openapi": Object {},
69
- "lint": LintConfig {
69
+ "organization": "redocly-test",
70
+ "rawConfig": Object {
71
+ "apis": Object {
72
+ "test@v1": Object {
73
+ "root": "resources/pets.yaml",
74
+ "styleguide": Object {
75
+ "rules": Object {
76
+ "operation-summary": "warn",
77
+ },
78
+ },
79
+ },
80
+ },
81
+ "features.mockServer": Object {},
82
+ "features.openapi": Object {},
83
+ "organization": "redocly-test",
84
+ "styleguide": Object {
85
+ "extendPaths": Array [],
86
+ "pluginPaths": Array [],
87
+ "rules": Object {
88
+ "operation-summary": "warn",
89
+ },
90
+ },
91
+ },
92
+ "region": undefined,
93
+ "resolve": Object {
94
+ "http": Object {
95
+ "customFetch": undefined,
96
+ "headers": Array [],
97
+ },
98
+ },
99
+ "styleguide": StyleguideConfig {
70
100
  "_usedRules": Set {},
71
101
  "_usedVersions": Set {},
72
102
  "configFile": "redocly.yaml",
@@ -105,28 +135,57 @@ describe('getMergedConfig', () => {
105
135
  },
106
136
  },
107
137
  },
138
+ }
139
+ `);
140
+ });
141
+ it('should take into account a config file', () => {
142
+ const result = getMergedConfig(testConfig, 'test@v1');
143
+ expect(result.configFile).toEqual('redocly.yaml');
144
+ expect(result.styleguide.configFile).toEqual('redocly.yaml');
145
+ });
146
+ it('should return the same config when there is no alias provided', () => {
147
+ expect(getMergedConfig(testConfig)).toEqual(testConfig);
148
+ });
149
+ it('should handle wrong alias - return the same styleguide, empty features', () => {
150
+ expect(getMergedConfig(testConfig, 'wrong-alias')).toMatchInlineSnapshot(`
151
+ Config {
152
+ "apis": Object {
153
+ "test@v1": Object {
154
+ "root": "resources/pets.yaml",
155
+ "styleguide": Object {
156
+ "rules": Object {
157
+ "operation-summary": "warn",
158
+ },
159
+ },
160
+ },
161
+ },
162
+ "configFile": "redocly.yaml",
163
+ "features.mockServer": Object {},
164
+ "features.openapi": Object {},
108
165
  "organization": "redocly-test",
109
166
  "rawConfig": Object {
110
167
  "apis": Object {
111
168
  "test@v1": Object {
112
- "lint": Object {
169
+ "root": "resources/pets.yaml",
170
+ "styleguide": Object {
113
171
  "rules": Object {
114
172
  "operation-summary": "warn",
115
173
  },
116
174
  },
117
- "root": "resources/pets.yaml",
118
175
  },
119
176
  },
120
177
  "features.mockServer": Object {},
121
178
  "features.openapi": Object {},
122
- "lint": Object {
179
+ "organization": "redocly-test",
180
+ "styleguide": Object {
123
181
  "extendPaths": Array [],
124
182
  "pluginPaths": Array [],
183
+ "plugins": Array [],
125
184
  "rules": Object {
126
- "operation-summary": "warn",
185
+ "no-empty-servers": "error",
186
+ "operation-summary": "error",
127
187
  },
128
188
  },
129
- "organization": "redocly-test",
130
189
  },
131
190
  "region": undefined,
132
191
  "resolve": Object {
@@ -135,34 +194,7 @@ describe('getMergedConfig', () => {
135
194
  "headers": Array [],
136
195
  },
137
196
  },
138
- }
139
- `);
140
- });
141
- it('should take into account a config file', () => {
142
- const result = getMergedConfig(testConfig, 'test@v1');
143
- expect(result.configFile).toEqual('redocly.yaml');
144
- expect(result.lint.configFile).toEqual('redocly.yaml');
145
- });
146
- it('should return the same config when there is no alias provided', () => {
147
- expect(getMergedConfig(testConfig)).toEqual(testConfig);
148
- });
149
- it('should handle wrong alias - return the same lint, empty features', () => {
150
- expect(getMergedConfig(testConfig, 'wrong-alias')).toMatchInlineSnapshot(`
151
- Config {
152
- "apis": Object {
153
- "test@v1": Object {
154
- "lint": Object {
155
- "rules": Object {
156
- "operation-summary": "warn",
157
- },
158
- },
159
- "root": "resources/pets.yaml",
160
- },
161
- },
162
- "configFile": "redocly.yaml",
163
- "features.mockServer": Object {},
164
- "features.openapi": Object {},
165
- "lint": LintConfig {
197
+ "styleguide": StyleguideConfig {
166
198
  "_usedRules": Set {},
167
199
  "_usedVersions": Set {},
168
200
  "configFile": "redocly.yaml",
@@ -206,38 +238,6 @@ describe('getMergedConfig', () => {
206
238
  },
207
239
  },
208
240
  },
209
- "organization": "redocly-test",
210
- "rawConfig": Object {
211
- "apis": Object {
212
- "test@v1": Object {
213
- "lint": Object {
214
- "rules": Object {
215
- "operation-summary": "warn",
216
- },
217
- },
218
- "root": "resources/pets.yaml",
219
- },
220
- },
221
- "features.mockServer": Object {},
222
- "features.openapi": Object {},
223
- "lint": Object {
224
- "extendPaths": Array [],
225
- "pluginPaths": Array [],
226
- "plugins": Array [],
227
- "rules": Object {
228
- "no-empty-servers": "error",
229
- "operation-summary": "error",
230
- },
231
- },
232
- "organization": "redocly-test",
233
- },
234
- "region": undefined,
235
- "resolve": Object {
236
- "http": Object {
237
- "customFetch": undefined,
238
- "headers": Array [],
239
- },
240
- },
241
241
  }
242
242
  `);
243
243
  });
@@ -21,7 +21,10 @@ const rules = {
21
21
  return {
22
22
  SecurityScheme(scheme, { location, report }) {
23
23
  if (scheme.type === 'openIdConnect') {
24
- if (scheme.openIdConnectUrl && !scheme.openIdConnectUrl.endsWith('/.well-known/openid-configuration')) {
24
+ if (
25
+ scheme.openIdConnectUrl &&
26
+ !scheme.openIdConnectUrl.endsWith('/.well-known/openid-configuration')
27
+ ) {
25
28
  report({
26
29
  message:
27
30
  'openIdConnectUrl must be a URL that ends with /.well-known/openid-configuration',
@@ -57,7 +60,6 @@ const configs = {
57
60
  },
58
61
  };
59
62
 
60
-
61
63
  module.exports = {
62
64
  id,
63
65
  preprocessors,
@@ -21,7 +21,10 @@ const rules = {
21
21
  return {
22
22
  SecurityScheme(scheme, { location, report }) {
23
23
  if (scheme.type === 'openIdConnect') {
24
- if (scheme.openIdConnectUrl && !scheme.openIdConnectUrl.endsWith('/.well-known/openid-configuration')) {
24
+ if (
25
+ scheme.openIdConnectUrl &&
26
+ !scheme.openIdConnectUrl.endsWith('/.well-known/openid-configuration')
27
+ ) {
25
28
  report({
26
29
  message:
27
30
  'openIdConnectUrl must be a URL that ends with /.well-known/openid-configuration',
@@ -9,7 +9,7 @@ describe('loadConfig', () => {
9
9
  jest
10
10
  .spyOn(RedoclyClient.prototype, 'getTokens')
11
11
  .mockImplementation(() =>
12
- Promise.resolve([{ region: 'us', token: 'accessToken', valid: true }]),
12
+ Promise.resolve([{ region: 'us', token: 'accessToken', valid: true }])
13
13
  );
14
14
  const config = await loadConfig();
15
15
  expect(config.resolve.http.headers).toStrictEqual([
@@ -32,7 +32,7 @@ describe('loadConfig', () => {
32
32
  jest
33
33
  .spyOn(RedoclyClient.prototype, 'getTokens')
34
34
  .mockImplementation(() =>
35
- Promise.resolve([{ region: 'eu', token: 'accessToken', valid: true }]),
35
+ Promise.resolve([{ region: 'eu', token: 'accessToken', valid: true }])
36
36
  );
37
37
  const config = await loadConfig();
38
38
  expect(config.resolve.http.headers).toStrictEqual([
@@ -6,21 +6,21 @@ describe('resolving a plugin', () => {
6
6
 
7
7
  it('should prefix rule names with the plugin id', async () => {
8
8
  const config = await loadConfig(configPath);
9
- const plugin = config.lint.plugins[0];
9
+ const plugin = config.styleguide.plugins[0];
10
10
 
11
11
  expect(plugin.rules?.oas3).toHaveProperty('test-plugin/openid-connect-url-well-known');
12
12
  });
13
13
 
14
14
  it('should prefix preprocessor names with the plugin id', async () => {
15
15
  const config = await loadConfig(configPath);
16
- const plugin = config.lint.plugins[0];
16
+ const plugin = config.styleguide.plugins[0];
17
17
 
18
18
  expect(plugin.preprocessors?.oas2).toHaveProperty('test-plugin/description-preprocessor');
19
19
  });
20
20
 
21
21
  it('should prefix decorator names with the plugin id', async () => {
22
22
  const config = await loadConfig(configPath);
23
- const plugin = config.lint.plugins[0];
23
+ const plugin = config.styleguide.plugins[0];
24
24
 
25
25
  expect(plugin.decorators?.oas3).toHaveProperty('test-plugin/inject-x-stats');
26
26
  });
@@ -0,0 +1,83 @@
1
+ import { DeprecatedInRawConfig, RawConfig } from '../types';
2
+ import * as utils from '../utils';
3
+
4
+ const makeTestRawConfig = (
5
+ apiStyleguideName: string,
6
+ rootStyleguideName: string
7
+ ): RawConfig & DeprecatedInRawConfig => ({
8
+ apis: {
9
+ 'test@v1': {
10
+ root: 'root.yaml',
11
+ [apiStyleguideName]: {
12
+ rules: {
13
+ 'operation-2xx-response': 'error',
14
+ },
15
+ },
16
+ },
17
+ },
18
+ [rootStyleguideName]: {
19
+ rules: {
20
+ 'operation-4xx-response': 'warn',
21
+ },
22
+ },
23
+ });
24
+
25
+ describe('transformConfig', () => {
26
+ it('should work for new syntax', () => {
27
+ const transformedRawConfig: RawConfig = utils.transformConfig(
28
+ makeTestRawConfig('styleguide', 'styleguide')
29
+ );
30
+ expect(transformedRawConfig).toMatchInlineSnapshot(`
31
+ Object {
32
+ "apis": Object {
33
+ "test@v1": Object {
34
+ "root": "root.yaml",
35
+ "styleguide": Object {
36
+ "rules": Object {
37
+ "operation-2xx-response": "error",
38
+ },
39
+ },
40
+ },
41
+ },
42
+ "features.openapi": undefined,
43
+ "styleguide": Object {
44
+ "rules": Object {
45
+ "operation-4xx-response": "warn",
46
+ },
47
+ },
48
+ }
49
+ `);
50
+ });
51
+ it('should be equal for both `lint` and `styleguide` names', () => {
52
+ expect(utils.transformConfig(makeTestRawConfig('lint', 'styleguide'))).toEqual(
53
+ utils.transformConfig(makeTestRawConfig('styleguide', 'lint'))
54
+ );
55
+ });
56
+ it('should work for `apiDefinitions`', () => {
57
+ const testRawConfig = makeTestRawConfig('styleguide', 'lint');
58
+ testRawConfig.apis = undefined;
59
+ testRawConfig.apiDefinitions = { legacyApiDefinition: 'file.yaml' };
60
+ expect(utils.transformConfig(testRawConfig)).toMatchInlineSnapshot(`
61
+ Object {
62
+ "apis": Object {
63
+ "legacyApiDefinition": Object {
64
+ "root": "file.yaml",
65
+ },
66
+ },
67
+ "features.openapi": undefined,
68
+ "styleguide": Object {
69
+ "rules": Object {
70
+ "operation-4xx-response": "warn",
71
+ },
72
+ },
73
+ }
74
+ `);
75
+ });
76
+ it('should throw an error if both new and old syntax used together', () => {
77
+ const testRawConfig = makeTestRawConfig('styleguide', 'lint');
78
+ testRawConfig.apiDefinitions = { legacyApiDefinition: 'file.yaml' };
79
+ expect(() => utils.transformConfig(testRawConfig)).toThrowError(
80
+ `Do not use 'apiDefinitions' field. Use 'apis' instead.`
81
+ );
82
+ });
83
+ });
package/src/config/all.ts CHANGED
@@ -1,5 +1,4 @@
1
- import type { PluginLintConfig } from "./types";
2
-
1
+ import type { PluginStyleguideConfig } from './types';
3
2
 
4
3
  export default {
5
4
  rules: {
@@ -20,7 +19,7 @@ export default {
20
19
  'operation-description': 'error',
21
20
  'operation-2xx-response': 'error',
22
21
  'operation-4xx-response': 'error',
23
- 'assertions': 'error',
22
+ assertions: 'error',
24
23
  'operation-operationId': 'error',
25
24
  'operation-summary': 'error',
26
25
  'operation-operationId-unique': 'error',
@@ -63,4 +62,4 @@ export default {
63
62
  'no-undefined-server-variable': 'error',
64
63
  'no-servers-empty-enum': 'error',
65
64
  },
66
- } as PluginLintConfig;
65
+ } as PluginStyleguideConfig;
@@ -8,15 +8,15 @@ import { preprocessors as oas2Preprocessors } from '../rules/oas2';
8
8
  import { decorators as oas3Decorators } from '../decorators/oas3';
9
9
  import { decorators as oas2Decorators } from '../decorators/oas2';
10
10
 
11
- import type { CustomRulesConfig, LintRawConfig, Plugin } from './types';
11
+ import type { CustomRulesConfig, StyleguideRawConfig, Plugin } from './types';
12
12
 
13
- export const builtInConfigs: Record<string, LintRawConfig> = {
13
+ export const builtInConfigs: Record<string, StyleguideRawConfig> = {
14
14
  recommended,
15
15
  minimal,
16
16
  all,
17
17
  'redocly-registry': {
18
- decorators: { 'registry-dependencies': 'on' }
19
- }
18
+ decorators: { 'registry-dependencies': 'on' },
19
+ },
20
20
  };
21
21
 
22
22
  export const defaultPlugin: Plugin = {
@@ -34,4 +34,4 @@ export const defaultPlugin: Plugin = {
34
34
  oas2: oas2Decorators,
35
35
  },
36
36
  configs: builtInConfigs,
37
- }
37
+ };