@redocly/openapi-core 1.0.0-beta.105 → 1.0.0-beta.108

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 (240) hide show
  1. package/README.md +4 -4
  2. package/__tests__/utils.ts +5 -5
  3. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
  4. package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
  5. package/lib/benchmark/utils.d.ts +2 -2
  6. package/lib/benchmark/utils.js +2 -2
  7. package/lib/bundle.d.ts +2 -2
  8. package/lib/bundle.js +7 -4
  9. package/lib/config/all.d.ts +2 -2
  10. package/lib/config/all.js +3 -3
  11. package/lib/config/builtIn.d.ts +2 -2
  12. package/lib/config/builtIn.js +2 -2
  13. package/lib/config/config-resolvers.d.ts +5 -5
  14. package/lib/config/config-resolvers.js +70 -49
  15. package/lib/config/config.d.ts +8 -10
  16. package/lib/config/config.js +10 -7
  17. package/lib/config/load.d.ts +7 -0
  18. package/lib/config/load.js +18 -10
  19. package/lib/config/minimal.d.ts +2 -2
  20. package/lib/config/minimal.js +5 -4
  21. package/lib/config/recommended.d.ts +2 -2
  22. package/lib/config/recommended.js +5 -4
  23. package/lib/config/rules.d.ts +3 -3
  24. package/lib/config/rules.js +1 -1
  25. package/lib/config/types.d.ts +23 -19
  26. package/lib/config/utils.d.ts +5 -5
  27. package/lib/config/utils.js +48 -31
  28. package/lib/decorators/common/registry-dependencies.js +1 -1
  29. package/lib/decorators/common/remove-x-internal.js +2 -2
  30. package/lib/env.d.ts +3 -0
  31. package/lib/env.js +8 -0
  32. package/lib/format/codeframes.js +16 -10
  33. package/lib/format/format.js +29 -27
  34. package/lib/index.d.ts +5 -5
  35. package/lib/index.js +4 -2
  36. package/lib/js-yaml/index.js +2 -6
  37. package/lib/lint.d.ts +2 -2
  38. package/lib/lint.js +16 -6
  39. package/lib/logger.d.ts +10 -0
  40. package/lib/logger.js +31 -0
  41. package/lib/output.d.ts +3 -0
  42. package/lib/output.js +9 -0
  43. package/lib/redocly/index.js +10 -9
  44. package/lib/redocly/registry-api-types.d.ts +28 -30
  45. package/lib/redocly/registry-api.d.ts +4 -3
  46. package/lib/redocly/registry-api.js +9 -4
  47. package/lib/ref-utils.js +2 -1
  48. package/lib/resolve.d.ts +1 -1
  49. package/lib/resolve.js +1 -1
  50. package/lib/rules/ajv.d.ts +1 -1
  51. package/lib/rules/ajv.js +7 -7
  52. package/lib/rules/common/assertions/asserts.js +4 -4
  53. package/lib/rules/common/assertions/index.js +1 -1
  54. package/lib/rules/common/info-license-url.d.ts +1 -1
  55. package/lib/rules/common/info-license-url.js +5 -10
  56. package/lib/rules/common/info-license.d.ts +2 -0
  57. package/lib/rules/common/info-license.js +17 -0
  58. package/lib/rules/common/no-enum-type-mismatch.js +1 -3
  59. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  60. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  61. package/lib/rules/common/operation-operationId.js +1 -1
  62. package/lib/rules/common/operation-security-defined.js +1 -1
  63. package/lib/rules/common/path-not-include-query.js +1 -1
  64. package/lib/rules/common/paths-kebab-case.js +4 -1
  65. package/lib/rules/common/spec.js +3 -3
  66. package/lib/rules/oas2/index.js +4 -4
  67. package/lib/rules/oas2/remove-unused-components.js +5 -5
  68. package/lib/rules/oas3/index.js +6 -6
  69. package/lib/rules/oas3/no-empty-servers.js +1 -1
  70. package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
  71. package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
  72. package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +4 -4
  73. package/lib/rules/oas3/no-unused-components.js +1 -1
  74. package/lib/rules/oas3/remove-unused-components.js +5 -5
  75. package/lib/rules/other/stats.js +43 -14
  76. package/lib/rules/utils.d.ts +3 -2
  77. package/lib/rules/utils.js +20 -5
  78. package/lib/types/index.d.ts +2 -2
  79. package/lib/types/redocly-yaml.js +9 -8
  80. package/lib/utils.d.ts +5 -0
  81. package/lib/utils.js +22 -5
  82. package/lib/visitors.d.ts +1 -1
  83. package/lib/visitors.js +2 -2
  84. package/lib/walk.d.ts +2 -1
  85. package/lib/walk.js +6 -3
  86. package/package.json +2 -2
  87. package/src/__tests__/__snapshots__/bundle.test.ts.snap +141 -0
  88. package/src/__tests__/bundle.test.ts +68 -34
  89. package/src/__tests__/codeframes.test.ts +13 -14
  90. package/src/__tests__/js-yaml.test.ts +6 -4
  91. package/src/__tests__/lint.test.ts +74 -6
  92. package/src/__tests__/logger-browser.test.ts +53 -0
  93. package/src/__tests__/logger.test.ts +47 -0
  94. package/src/__tests__/login.test.ts +2 -2
  95. package/src/__tests__/normalizeVisitors.test.ts +4 -4
  96. package/src/__tests__/output-browser.test.ts +18 -0
  97. package/src/__tests__/output.test.ts +15 -0
  98. package/src/__tests__/ref-utils.test.ts +13 -13
  99. package/src/__tests__/resolve-http.test.ts +1 -1
  100. package/src/__tests__/resolve.test.ts +14 -11
  101. package/src/__tests__/utils-browser.test.ts +11 -0
  102. package/src/__tests__/utils.test.ts +7 -0
  103. package/src/__tests__/walk.test.ts +48 -56
  104. package/src/benchmark/benches/lint-with-many-rules.bench.ts +1 -1
  105. package/src/benchmark/benches/lint-with-nested-rule.bench.ts +1 -1
  106. package/src/benchmark/benches/lint-with-no-rules.bench.ts +1 -1
  107. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +1 -2
  108. package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +1 -1
  109. package/src/benchmark/benches/recommended-oas3.bench.ts +3 -3
  110. package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
  111. package/src/benchmark/benchmark.js +9 -5
  112. package/src/benchmark/utils.ts +5 -5
  113. package/src/bundle.ts +24 -20
  114. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +7 -5
  115. package/src/config/__tests__/config-resolvers.test.ts +123 -121
  116. package/src/config/__tests__/config.test.ts +111 -76
  117. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +4 -2
  118. package/src/config/__tests__/fixtures/resolve-config/plugin.js +4 -1
  119. package/src/config/__tests__/load.test.ts +79 -1
  120. package/src/config/__tests__/resolve-plugins.test.ts +3 -3
  121. package/src/config/__tests__/utils.test.ts +83 -0
  122. package/src/config/all.ts +5 -6
  123. package/src/config/builtIn.ts +5 -5
  124. package/src/config/config-resolvers.ts +161 -96
  125. package/src/config/config.ts +15 -13
  126. package/src/config/load.ts +34 -11
  127. package/src/config/minimal.ts +7 -6
  128. package/src/config/recommended.ts +7 -6
  129. package/src/config/rules.ts +6 -6
  130. package/src/config/types.ts +28 -19
  131. package/src/config/utils.ts +78 -57
  132. package/src/decorators/__tests__/filter-out.test.ts +8 -4
  133. package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
  134. package/src/decorators/common/filters/filter-helper.ts +1 -1
  135. package/src/decorators/common/info-description-override.ts +1 -1
  136. package/src/decorators/common/operation-description-override.ts +1 -1
  137. package/src/decorators/common/registry-dependencies.ts +1 -1
  138. package/src/decorators/common/remove-x-internal.ts +4 -4
  139. package/src/decorators/common/tag-description-override.ts +1 -1
  140. package/src/env.ts +5 -0
  141. package/src/format/codeframes.ts +18 -12
  142. package/src/format/format.ts +37 -42
  143. package/src/index.ts +8 -7
  144. package/src/js-yaml/index.ts +4 -8
  145. package/src/lint.ts +22 -18
  146. package/src/logger.ts +34 -0
  147. package/src/oas-types.ts +1 -6
  148. package/src/output.ts +7 -0
  149. package/src/redocly/__tests__/redocly-client.test.ts +25 -19
  150. package/src/redocly/index.ts +12 -7
  151. package/src/redocly/registry-api-types.ts +27 -29
  152. package/src/redocly/registry-api.ts +22 -12
  153. package/src/ref-utils.ts +4 -3
  154. package/src/resolve.ts +11 -8
  155. package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
  156. package/src/rules/__tests__/utils.test.ts +160 -0
  157. package/src/rules/ajv.ts +7 -8
  158. package/src/rules/common/__tests__/info-description.test.ts +3 -3
  159. package/src/rules/common/__tests__/info-license.test.ts +2 -2
  160. package/src/rules/common/__tests__/license-url.test.ts +2 -2
  161. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
  162. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +8 -8
  163. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
  164. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
  165. package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
  166. package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
  167. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
  168. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
  169. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
  170. package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
  171. package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
  172. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
  173. package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
  174. package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
  175. package/src/rules/common/__tests__/paths-kebab-case.test.ts +15 -15
  176. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
  177. package/src/rules/common/__tests__/spec.test.ts +2 -2
  178. package/src/rules/common/__tests__/tag-description.test.ts +2 -2
  179. package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
  180. package/src/rules/common/assertions/__tests__/asserts.test.ts +513 -130
  181. package/src/rules/common/assertions/asserts.ts +4 -4
  182. package/src/rules/common/assertions/index.ts +7 -7
  183. package/src/rules/common/info-license-url.ts +4 -9
  184. package/src/rules/common/info-license.ts +15 -0
  185. package/src/rules/common/no-ambiguous-paths.ts +1 -1
  186. package/src/rules/common/no-enum-type-mismatch.ts +12 -9
  187. package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
  188. package/src/rules/common/no-invalid-schema-examples.ts +4 -4
  189. package/src/rules/common/operation-operationId.ts +1 -1
  190. package/src/rules/common/operation-parameters-unique.ts +2 -2
  191. package/src/rules/common/operation-security-defined.ts +1 -1
  192. package/src/rules/common/path-not-include-query.ts +1 -1
  193. package/src/rules/common/path-params-defined.ts +1 -1
  194. package/src/rules/common/paths-kebab-case.ts +4 -1
  195. package/src/rules/common/scalar-property-missing-example.ts +1 -1
  196. package/src/rules/common/spec.ts +12 -9
  197. package/src/rules/no-unresolved-refs.ts +1 -1
  198. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  199. package/src/rules/oas2/__tests__/spec/info.test.ts +12 -12
  200. package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
  201. package/src/rules/oas2/__tests__/spec/paths.test.ts +10 -10
  202. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +6 -2
  203. package/src/rules/oas2/__tests__/spec/utils.ts +6 -6
  204. package/src/rules/oas2/index.ts +3 -3
  205. package/src/rules/oas2/remove-unused-components.ts +14 -9
  206. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  207. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
  208. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
  209. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +13 -13
  210. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
  211. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  212. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
  213. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
  214. package/src/rules/oas3/__tests__/spec/info.test.ts +12 -12
  215. package/src/rules/oas3/__tests__/spec/operation.test.ts +8 -8
  216. package/src/rules/oas3/__tests__/spec/paths.test.ts +10 -10
  217. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +12 -12
  218. package/src/rules/oas3/__tests__/spec/servers.test.ts +15 -15
  219. package/src/rules/oas3/__tests__/spec/spec.test.ts +6 -6
  220. package/src/rules/oas3/__tests__/spec/utils.ts +6 -6
  221. package/src/rules/oas3/index.ts +5 -5
  222. package/src/rules/oas3/no-empty-servers.ts +1 -1
  223. package/src/rules/oas3/no-invalid-media-type-examples.ts +14 -6
  224. package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +10 -11
  225. package/src/rules/oas3/no-unused-components.ts +1 -1
  226. package/src/rules/oas3/remove-unused-components.ts +21 -10
  227. package/src/rules/other/stats.ts +46 -17
  228. package/src/rules/utils.ts +20 -4
  229. package/src/types/index.ts +5 -5
  230. package/src/types/redocly-yaml.ts +9 -8
  231. package/src/typings/common.ts +9 -1
  232. package/src/typings/openapi.ts +1 -1
  233. package/src/utils.ts +26 -3
  234. package/src/visitors.ts +9 -9
  235. package/src/walk.ts +15 -11
  236. package/tsconfig.tsbuildinfo +1 -1
  237. package/lib/rules/common/license-url.d.ts +0 -2
  238. package/lib/rules/common/license-url.js +0 -12
  239. package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
  240. package/src/rules/common/license-url.ts +0 -10
@@ -1,4 +1,5 @@
1
- import { Config } from '../config';
1
+ import { OasVersion } from '../../oas-types';
2
+ import { Config, StyleguideConfig } from '../config';
2
3
  import { getMergedConfig } from '../utils';
3
4
 
4
5
  const testConfig: Config = {
@@ -6,11 +7,11 @@ const testConfig: Config = {
6
7
  apis: {
7
8
  'test@v1': {
8
9
  root: 'resources/pets.yaml',
9
- lint: { rules: { 'operation-summary': 'warn' } },
10
+ styleguide: { rules: { 'operation-summary': 'warn' } },
10
11
  },
11
12
  },
12
13
  organization: 'redocly-test',
13
- lint: {
14
+ styleguide: {
14
15
  rules: { 'operation-summary': 'error', 'no-empty-servers': 'error' },
15
16
  plugins: [],
16
17
  },
@@ -19,11 +20,11 @@ const testConfig: Config = {
19
20
  apis: {
20
21
  'test@v1': {
21
22
  root: 'resources/pets.yaml',
22
- lint: { rules: { 'operation-summary': 'warn' } },
23
+ styleguide: { rules: { 'operation-summary': 'warn' } },
23
24
  },
24
25
  },
25
- // @ts-ignore
26
- lint: {
26
+
27
+ styleguide: {
27
28
  rawConfig: {
28
29
  rules: { 'operation-summary': 'error', 'no-empty-servers': 'error' },
29
30
  plugins: [],
@@ -42,7 +43,7 @@ const testConfig: Config = {
42
43
  },
43
44
  preprocessors: { oas2: {}, oas3_0: {}, oas3_1: {} },
44
45
  decorators: { oas2: {}, oas3_0: {}, oas3_1: {} },
45
- },
46
+ } as unknown as StyleguideConfig,
46
47
  'features.openapi': {},
47
48
  'features.mockServer': {},
48
49
  resolve: { http: { headers: [] } },
@@ -50,23 +51,53 @@ const testConfig: Config = {
50
51
  };
51
52
 
52
53
  describe('getMergedConfig', () => {
53
- it('should get lint defined in "apis" section', () => {
54
+ it('should get styleguide defined in "apis" section', () => {
54
55
  expect(getMergedConfig(testConfig, 'test@v1')).toMatchInlineSnapshot(`
55
56
  Config {
56
57
  "apis": Object {
57
58
  "test@v1": Object {
58
- "lint": Object {
59
+ "root": "resources/pets.yaml",
60
+ "styleguide": Object {
59
61
  "rules": Object {
60
62
  "operation-summary": "warn",
61
63
  },
62
64
  },
63
- "root": "resources/pets.yaml",
64
65
  },
65
66
  },
66
67
  "configFile": "redocly.yaml",
67
68
  "features.mockServer": Object {},
68
69
  "features.openapi": Object {},
69
- "lint": LintConfig {
70
+ "organization": "redocly-test",
71
+ "rawConfig": Object {
72
+ "apis": Object {
73
+ "test@v1": Object {
74
+ "root": "resources/pets.yaml",
75
+ "styleguide": Object {
76
+ "rules": Object {
77
+ "operation-summary": "warn",
78
+ },
79
+ },
80
+ },
81
+ },
82
+ "features.mockServer": Object {},
83
+ "features.openapi": Object {},
84
+ "organization": "redocly-test",
85
+ "styleguide": Object {
86
+ "extendPaths": Array [],
87
+ "pluginPaths": Array [],
88
+ "rules": Object {
89
+ "operation-summary": "warn",
90
+ },
91
+ },
92
+ },
93
+ "region": undefined,
94
+ "resolve": Object {
95
+ "http": Object {
96
+ "customFetch": undefined,
97
+ "headers": Array [],
98
+ },
99
+ },
100
+ "styleguide": StyleguideConfig {
70
101
  "_usedRules": Set {},
71
102
  "_usedVersions": Set {},
72
103
  "configFile": "redocly.yaml",
@@ -105,28 +136,57 @@ describe('getMergedConfig', () => {
105
136
  },
106
137
  },
107
138
  },
139
+ }
140
+ `);
141
+ });
142
+ it('should take into account a config file', () => {
143
+ const result = getMergedConfig(testConfig, 'test@v1');
144
+ expect(result.configFile).toEqual('redocly.yaml');
145
+ expect(result.styleguide.configFile).toEqual('redocly.yaml');
146
+ });
147
+ it('should return the same config when there is no alias provided', () => {
148
+ expect(getMergedConfig(testConfig)).toEqual(testConfig);
149
+ });
150
+ it('should handle wrong alias - return the same styleguide, empty features', () => {
151
+ expect(getMergedConfig(testConfig, 'wrong-alias')).toMatchInlineSnapshot(`
152
+ Config {
153
+ "apis": Object {
154
+ "test@v1": Object {
155
+ "root": "resources/pets.yaml",
156
+ "styleguide": Object {
157
+ "rules": Object {
158
+ "operation-summary": "warn",
159
+ },
160
+ },
161
+ },
162
+ },
163
+ "configFile": "redocly.yaml",
164
+ "features.mockServer": Object {},
165
+ "features.openapi": Object {},
108
166
  "organization": "redocly-test",
109
167
  "rawConfig": Object {
110
168
  "apis": Object {
111
169
  "test@v1": Object {
112
- "lint": Object {
170
+ "root": "resources/pets.yaml",
171
+ "styleguide": Object {
113
172
  "rules": Object {
114
173
  "operation-summary": "warn",
115
174
  },
116
175
  },
117
- "root": "resources/pets.yaml",
118
176
  },
119
177
  },
120
178
  "features.mockServer": Object {},
121
179
  "features.openapi": Object {},
122
- "lint": Object {
180
+ "organization": "redocly-test",
181
+ "styleguide": Object {
123
182
  "extendPaths": Array [],
124
183
  "pluginPaths": Array [],
184
+ "plugins": Array [],
125
185
  "rules": Object {
126
- "operation-summary": "warn",
186
+ "no-empty-servers": "error",
187
+ "operation-summary": "error",
127
188
  },
128
189
  },
129
- "organization": "redocly-test",
130
190
  },
131
191
  "region": undefined,
132
192
  "resolve": Object {
@@ -135,34 +195,7 @@ describe('getMergedConfig', () => {
135
195
  "headers": Array [],
136
196
  },
137
197
  },
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 {
198
+ "styleguide": StyleguideConfig {
166
199
  "_usedRules": Set {},
167
200
  "_usedVersions": Set {},
168
201
  "configFile": "redocly.yaml",
@@ -206,39 +239,41 @@ describe('getMergedConfig', () => {
206
239
  },
207
240
  },
208
241
  },
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
242
  }
242
243
  `);
243
244
  });
244
245
  });
246
+
247
+ describe('StyleguideConfig.extendTypes', () => {
248
+ let oas3 = jest.fn();
249
+ let oas2 = jest.fn();
250
+ let testRawConfigStyleguide = {
251
+ plugins: [
252
+ {
253
+ id: 'test-types-plugin',
254
+ typeExtension: {
255
+ oas3,
256
+ oas2,
257
+ },
258
+ },
259
+ ],
260
+ };
261
+ it('should call only oas3 types extension', () => {
262
+ const styleguideConfig = new StyleguideConfig(testRawConfigStyleguide);
263
+ styleguideConfig.extendTypes({}, OasVersion.Version3_0);
264
+ expect(oas3).toHaveBeenCalledTimes(1);
265
+ expect(oas2).toHaveBeenCalledTimes(0);
266
+ });
267
+ it('should call only oas2 types extension', () => {
268
+ const styleguideConfig = new StyleguideConfig(testRawConfigStyleguide);
269
+ styleguideConfig.extendTypes({}, OasVersion.Version2);
270
+ expect(oas3).toHaveBeenCalledTimes(0);
271
+ expect(oas2).toHaveBeenCalledTimes(1);
272
+ });
273
+ it('should throw error if for oas version different from 2 and 3', () => {
274
+ const styleguideConfig = new StyleguideConfig(testRawConfigStyleguide);
275
+ expect(() => styleguideConfig.extendTypes({}, 'something else' as OasVersion)).toThrowError(
276
+ 'Not implemented'
277
+ );
278
+ });
279
+ });
@@ -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',
@@ -1,5 +1,7 @@
1
- import { loadConfig, findConfig, getConfig } from '../load';
1
+ import { loadConfig, findConfig, getConfig, createConfig } from '../load';
2
2
  import { RedoclyClient } from '../../redocly';
3
+ import { RuleConfig, RawConfig } from './../types';
4
+ import { Config } from '../config';
3
5
 
4
6
  const fs = require('fs');
5
7
  const path = require('path');
@@ -87,3 +89,79 @@ describe('getConfig', () => {
87
89
  expect(getConfig()).toEqual(Promise.resolve({}));
88
90
  });
89
91
  });
92
+
93
+ describe('createConfig', () => {
94
+ it('should create config from string', async () => {
95
+ const config = await createConfig(`
96
+ styleguide:
97
+ extends:
98
+ - recommended
99
+ rules:
100
+ info-license: off
101
+ `);
102
+
103
+ verifyExtendedConfig(config, {
104
+ extendsRuleSet: 'recommended',
105
+ overridesRules: { 'info-license': 'off' },
106
+ });
107
+ });
108
+
109
+ it('should create config from object', async () => {
110
+ const rawConfig: RawConfig = {
111
+ styleguide: {
112
+ extends: ['minimal'],
113
+ rules: {
114
+ 'info-license': 'off',
115
+ 'tag-description': 'off',
116
+ 'operation-2xx-response': 'off',
117
+ },
118
+ },
119
+ };
120
+ const config = await createConfig(rawConfig);
121
+
122
+ verifyExtendedConfig(config, {
123
+ extendsRuleSet: 'minimal',
124
+ overridesRules: rawConfig.styleguide!.rules as Record<string, RuleConfig>,
125
+ });
126
+ });
127
+ });
128
+
129
+ function verifyExtendedConfig(
130
+ config: Config,
131
+ {
132
+ extendsRuleSet,
133
+ overridesRules,
134
+ }: { extendsRuleSet: string; overridesRules: Record<string, RuleConfig> }
135
+ ) {
136
+ const defaultPlugin = config.styleguide.plugins.find((plugin) => plugin.id === '');
137
+ expect(defaultPlugin).toBeDefined();
138
+
139
+ const recommendedRules = defaultPlugin?.configs?.[extendsRuleSet];
140
+ expect(recommendedRules).toBeDefined();
141
+
142
+ verifyOasRules(config.styleguide.rules.oas2, overridesRules, recommendedRules?.rules || {});
143
+ verifyOasRules(
144
+ config.styleguide.rules.oas3_0,
145
+ overridesRules,
146
+ Object.assign({}, recommendedRules?.rules, recommendedRules?.oas3_0Rules)
147
+ );
148
+ verifyOasRules(
149
+ config.styleguide.rules.oas3_1,
150
+ overridesRules,
151
+ Object.assign({}, recommendedRules?.rules, recommendedRules?.oas3_1Rules)
152
+ );
153
+ }
154
+
155
+ function verifyOasRules(
156
+ finalRuleset: Record<string, RuleConfig>,
157
+ overridesRules: Record<string, RuleConfig>,
158
+ defaultRuleset: Record<string, RuleConfig>
159
+ ) {
160
+ Object.entries(finalRuleset).forEach(([ruleName, ruleValue]) => {
161
+ if (ruleName in overridesRules) {
162
+ expect(ruleValue).toBe(overridesRules[ruleName]);
163
+ } else {
164
+ expect(ruleValue).toBe(defaultRuleset[ruleName]);
165
+ }
166
+ });
167
+ }
@@ -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',
@@ -52,7 +51,7 @@ export default {
52
51
  'no-example-value-and-externalValue': 'error',
53
52
  'no-unused-components': 'error',
54
53
  'no-undefined-server-variable': 'error',
55
- 'no-servers-empty-enum': 'error',
54
+ 'no-server-variables-empty-enum': 'error',
56
55
  },
57
56
  oas3_1Rules: {
58
57
  'no-server-example.com': 'error',
@@ -61,6 +60,6 @@ export default {
61
60
  'no-example-value-and-externalValue': 'error',
62
61
  'no-unused-components': 'error',
63
62
  'no-undefined-server-variable': 'error',
64
- 'no-servers-empty-enum': 'error',
63
+ 'no-server-variables-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
+ };