@redocly/openapi-core 1.3.0 → 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 (190) hide show
  1. package/CHANGELOG.md +6 -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 +6 -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.js +26 -14
  30. package/lib/decorators/common/filters/filter-helper.js +4 -4
  31. package/lib/decorators/common/filters/filter-in.js +2 -2
  32. package/lib/decorators/common/filters/filter-out.js +2 -2
  33. package/lib/decorators/common/info-description-override.js +1 -1
  34. package/lib/decorators/common/media-type-examples-override.js +3 -3
  35. package/lib/decorators/common/operation-description-override.js +1 -1
  36. package/lib/decorators/common/registry-dependencies.js +1 -1
  37. package/lib/decorators/common/remove-x-internal.js +4 -4
  38. package/lib/decorators/common/tag-description-override.js +1 -1
  39. package/lib/format/codeframes.d.ts +6 -6
  40. package/lib/format/format.d.ts +2 -2
  41. package/lib/format/format.js +12 -12
  42. package/lib/js-yaml/index.d.ts +2 -2
  43. package/lib/js-yaml/index.js +2 -2
  44. package/lib/lint.js +18 -18
  45. package/lib/oas-types.d.ts +12 -10
  46. package/lib/oas-types.js +2 -2
  47. package/lib/redocly/index.js +10 -10
  48. package/lib/redocly/registry-api.js +2 -2
  49. package/lib/resolve.d.ts +4 -4
  50. package/lib/resolve.js +18 -18
  51. package/lib/rules/ajv.js +1 -1
  52. package/lib/rules/async2/index.d.ts +2 -11
  53. package/lib/rules/common/assertions/asserts.d.ts +3 -3
  54. package/lib/rules/common/assertions/asserts.js +21 -21
  55. package/lib/rules/common/assertions/index.d.ts +4 -4
  56. package/lib/rules/common/assertions/index.js +3 -3
  57. package/lib/rules/common/assertions/utils.d.ts +4 -4
  58. package/lib/rules/common/assertions/utils.js +3 -3
  59. package/lib/rules/common/info-contact.js +1 -1
  60. package/lib/rules/common/info-license-url.js +1 -1
  61. package/lib/rules/common/info-license.js +1 -1
  62. package/lib/rules/common/no-enum-type-mismatch.js +3 -3
  63. package/lib/rules/common/no-http-verbs-in-paths.js +2 -2
  64. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  65. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  66. package/lib/rules/common/operation-2xx-response.js +2 -2
  67. package/lib/rules/common/operation-4xx-response.js +2 -2
  68. package/lib/rules/common/operation-description.js +1 -1
  69. package/lib/rules/common/operation-operationId.js +1 -1
  70. package/lib/rules/common/operation-summary.js +1 -1
  71. package/lib/rules/common/path-segment-plural.js +1 -1
  72. package/lib/rules/common/response-contains-header.js +2 -2
  73. package/lib/rules/common/spec-strict-refs.js +1 -1
  74. package/lib/rules/common/spec.js +11 -11
  75. package/lib/rules/common/tag-description.js +1 -1
  76. package/lib/rules/oas2/boolean-parameter-prefixes.d.ts +1 -1
  77. package/lib/rules/oas2/index.d.ts +2 -46
  78. package/lib/rules/oas2/remove-unused-components.js +1 -1
  79. package/lib/rules/oas2/request-mime-type.js +2 -2
  80. package/lib/rules/oas2/response-contains-property.js +2 -2
  81. package/lib/rules/oas2/response-mime-type.js +2 -2
  82. package/lib/rules/oas3/boolean-parameter-prefixes.d.ts +1 -1
  83. package/lib/rules/oas3/index.d.ts +1 -1
  84. package/lib/rules/oas3/index.js +1 -1
  85. package/lib/rules/oas3/no-invalid-media-type-examples.js +3 -3
  86. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +3 -3
  87. package/lib/rules/oas3/remove-unused-components.js +2 -2
  88. package/lib/rules/oas3/request-mime-type.js +3 -3
  89. package/lib/rules/oas3/response-contains-property.js +2 -2
  90. package/lib/rules/oas3/response-mime-type.js +3 -3
  91. package/lib/rules/utils.js +3 -3
  92. package/lib/types/asyncapi.js +21 -21
  93. package/lib/types/index.d.ts +8 -8
  94. package/lib/types/oas2.js +14 -14
  95. package/lib/types/oas3.js +27 -27
  96. package/lib/types/oas3_1.js +6 -6
  97. package/lib/types/redocly-yaml.d.ts +11 -0
  98. package/lib/types/redocly-yaml.js +71 -53
  99. package/lib/types/theme-config.js +1 -1
  100. package/lib/typings/common.d.ts +2 -2
  101. package/lib/typings/openapi.d.ts +6 -6
  102. package/lib/typings/swagger.d.ts +3 -3
  103. package/lib/utils.d.ts +5 -5
  104. package/lib/utils.js +3 -3
  105. package/lib/visitors.d.ts +40 -40
  106. package/lib/walk.d.ts +14 -15
  107. package/lib/walk.js +11 -11
  108. package/package.json +2 -2
  109. package/src/__tests__/lint.test.ts +40 -40
  110. package/src/__tests__/normalizeVisitors.test.ts +23 -5
  111. package/src/__tests__/ref-utils.test.ts +7 -7
  112. package/src/__tests__/resolve-http.test.ts +10 -10
  113. package/src/__tests__/resolve.test.ts +39 -39
  114. package/src/__tests__/walk.test.ts +48 -48
  115. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +95 -32
  116. package/src/config/__tests__/__snapshots__/config.test.ts.snap +81 -81
  117. package/src/config/__tests__/config-resolvers.test.ts +30 -1
  118. package/src/config/__tests__/config.test.ts +88 -88
  119. package/src/config/__tests__/load.test.ts +12 -8
  120. package/src/config/__tests__/utils.test.ts +18 -18
  121. package/src/config/all.ts +46 -9
  122. package/src/config/builtIn.ts +2 -0
  123. package/src/config/minimal.ts +36 -4
  124. package/src/config/recommended-strict.ts +93 -0
  125. package/src/config/recommended.ts +36 -4
  126. package/src/config/types.ts +22 -8
  127. package/src/config/utils.ts +15 -0
  128. package/src/decorators/common/media-type-examples-override.ts +2 -2
  129. package/src/lint.ts +3 -3
  130. package/src/oas-types.ts +26 -3
  131. package/src/rules/__tests__/no-unresolved-refs.test.ts +26 -26
  132. package/src/rules/async2/__tests__/channels-kebab-case.test.ts +12 -12
  133. package/src/rules/async2/__tests__/no-channel-trailing-slash.test.ts +7 -7
  134. package/src/rules/async2/index.ts +2 -1
  135. package/src/rules/common/__tests__/info-license.test.ts +6 -6
  136. package/src/rules/common/__tests__/license-url.test.ts +6 -6
  137. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +13 -13
  138. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +18 -18
  139. package/src/rules/common/__tests__/no-identical-paths.test.ts +5 -5
  140. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +12 -12
  141. package/src/rules/common/__tests__/operation-2xx-response.test.ts +18 -18
  142. package/src/rules/common/__tests__/operation-4xx-response.test.ts +23 -23
  143. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +6 -6
  144. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +5 -5
  145. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +16 -16
  146. package/src/rules/common/__tests__/operation-singular-tag.test.ts +6 -6
  147. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +10 -10
  148. package/src/rules/common/__tests__/path-not-include-query.test.ts +6 -6
  149. package/src/rules/common/__tests__/path-params-defined.test.ts +21 -21
  150. package/src/rules/common/__tests__/paths-kebab-case.test.ts +11 -11
  151. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +18 -18
  152. package/src/rules/common/__tests__/security-defined.test.ts +21 -21
  153. package/src/rules/common/__tests__/spec-strict-refs.test.ts +9 -9
  154. package/src/rules/common/__tests__/spec.test.ts +102 -102
  155. package/src/rules/common/__tests__/tag-description.test.ts +6 -6
  156. package/src/rules/common/__tests__/tags-alphabetical.test.ts +12 -12
  157. package/src/rules/common/assertions/__tests__/index.test.ts +15 -15
  158. package/src/rules/common/assertions/__tests__/utils.test.ts +9 -9
  159. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +7 -7
  160. package/src/rules/oas2/__tests__/response-contains-header.test.ts +13 -13
  161. package/src/rules/oas2/__tests__/response-contains-property.test.ts +8 -8
  162. package/src/rules/oas2/__tests__/spec/info.test.ts +21 -21
  163. package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
  164. package/src/rules/oas2/__tests__/spec/paths.test.ts +12 -12
  165. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +1 -1
  166. package/src/rules/oas2/index.ts +3 -1
  167. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +7 -7
  168. package/src/rules/oas3/__tests__/component-name-unique.test.ts +186 -186
  169. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +18 -18
  170. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +6 -6
  171. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +36 -36
  172. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +11 -11
  173. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +7 -7
  174. package/src/rules/oas3/__tests__/no-unused-components.test.ts +31 -31
  175. package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +15 -15
  176. package/src/rules/oas3/__tests__/response-contains-header.test.ts +26 -26
  177. package/src/rules/oas3/__tests__/response-contains-property.test.ts +27 -27
  178. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
  179. package/src/rules/oas3/__tests__/spec/info.test.ts +21 -21
  180. package/src/rules/oas3/__tests__/spec/operation.test.ts +10 -10
  181. package/src/rules/oas3/__tests__/spec/paths.test.ts +13 -13
  182. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +2 -2
  183. package/src/rules/oas3/__tests__/spec/servers.test.ts +25 -25
  184. package/src/rules/oas3/__tests__/spec/spec.test.ts +56 -56
  185. package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +28 -28
  186. package/src/rules/oas3/index.ts +3 -3
  187. package/src/types/redocly-yaml.ts +75 -40
  188. package/src/visitors.ts +3 -3
  189. package/src/walk.ts +23 -10
  190. package/tsconfig.tsbuildinfo +1 -1
@@ -45,11 +45,11 @@ describe('Oas3 Structural visitor basic', () => {
45
45
  });
46
46
 
47
47
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
48
- Array [
49
- Object {
48
+ [
49
+ {
50
50
  "from": undefined,
51
- "location": Array [
52
- Object {
51
+ "location": [
52
+ {
53
53
  "pointer": "#/info/contact/url",
54
54
  "reportOnKey": false,
55
55
  "source": "foobar.yaml",
@@ -58,12 +58,12 @@ describe('Oas3 Structural visitor basic', () => {
58
58
  "message": "Expected type \`string\` but got \`array\`.",
59
59
  "ruleId": "spec",
60
60
  "severity": "error",
61
- "suggest": Array [],
61
+ "suggest": [],
62
62
  },
63
- Object {
63
+ {
64
64
  "from": undefined,
65
- "location": Array [
66
- Object {
65
+ "location": [
66
+ {
67
67
  "pointer": "#/info/contact/email",
68
68
  "reportOnKey": false,
69
69
  "source": "foobar.yaml",
@@ -72,12 +72,12 @@ describe('Oas3 Structural visitor basic', () => {
72
72
  "message": "Expected type \`string\` but got \`boolean\`.",
73
73
  "ruleId": "spec",
74
74
  "severity": "error",
75
- "suggest": Array [],
75
+ "suggest": [],
76
76
  },
77
- Object {
77
+ {
78
78
  "from": undefined,
79
- "location": Array [
80
- Object {
79
+ "location": [
80
+ {
81
81
  "pointer": "#/info/license",
82
82
  "reportOnKey": false,
83
83
  "source": "foobar.yaml",
@@ -86,15 +86,15 @@ describe('Oas3 Structural visitor basic', () => {
86
86
  "message": "Expected type \`License\` (object) but got \`string\`",
87
87
  "ruleId": "spec",
88
88
  "severity": "error",
89
- "suggest": Array [],
89
+ "suggest": [],
90
90
  },
91
- Object {
92
- "from": Object {
91
+ {
92
+ "from": {
93
93
  "pointer": "#/servers/0/url",
94
94
  "source": "foobar.yaml",
95
95
  },
96
- "location": Array [
97
- Object {
96
+ "location": [
97
+ {
98
98
  "pointer": "#/servers/0/variables/a",
99
99
  "reportOnKey": true,
100
100
  "source": "foobar.yaml",
@@ -103,12 +103,12 @@ describe('Oas3 Structural visitor basic', () => {
103
103
  "message": "The \`a\` variable is not used in the server's \`url\` field.",
104
104
  "ruleId": "no-undefined-server-variable",
105
105
  "severity": "error",
106
- "suggest": Array [],
106
+ "suggest": [],
107
107
  },
108
- Object {
108
+ {
109
109
  "from": undefined,
110
- "location": Array [
111
- Object {
110
+ "location": [
111
+ {
112
112
  "pointer": "#/servers/0/variables/a/enum/0",
113
113
  "reportOnKey": false,
114
114
  "source": "foobar.yaml",
@@ -117,12 +117,12 @@ describe('Oas3 Structural visitor basic', () => {
117
117
  "message": "Expected type \`string\` but got \`integer\`.",
118
118
  "ruleId": "spec",
119
119
  "severity": "error",
120
- "suggest": Array [],
120
+ "suggest": [],
121
121
  },
122
- Object {
122
+ {
123
123
  "from": undefined,
124
- "location": Array [
125
- Object {
124
+ "location": [
125
+ {
126
126
  "pointer": "#/tags/0",
127
127
  "reportOnKey": false,
128
128
  "source": "foobar.yaml",
@@ -131,12 +131,12 @@ describe('Oas3 Structural visitor basic', () => {
131
131
  "message": "Expected type \`Tag\` (object) but got \`number\`",
132
132
  "ruleId": "spec",
133
133
  "severity": "error",
134
- "suggest": Array [],
134
+ "suggest": [],
135
135
  },
136
- Object {
136
+ {
137
137
  "from": undefined,
138
- "location": Array [
139
- Object {
138
+ "location": [
139
+ {
140
140
  "pointer": "#/tags/1",
141
141
  "reportOnKey": false,
142
142
  "source": "foobar.yaml",
@@ -145,7 +145,7 @@ describe('Oas3 Structural visitor basic', () => {
145
145
  "message": "Expected type \`Tag\` (object) but got \`string\`",
146
146
  "ruleId": "spec",
147
147
  "severity": "error",
148
- "suggest": Array [],
148
+ "suggest": [],
149
149
  },
150
150
  ]
151
151
  `);
@@ -179,11 +179,11 @@ describe('Oas3 Structural visitor basic', () => {
179
179
  });
180
180
 
181
181
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
182
- Array [
183
- Object {
182
+ [
183
+ {
184
184
  "from": undefined,
185
- "location": Array [
186
- Object {
185
+ "location": [
186
+ {
187
187
  "pointer": "#/components1",
188
188
  "reportOnKey": true,
189
189
  "source": "foobar.yaml",
@@ -192,13 +192,13 @@ describe('Oas3 Structural visitor basic', () => {
192
192
  "message": "Property \`components1\` is not expected here.",
193
193
  "ruleId": "spec",
194
194
  "severity": "error",
195
- "suggest": Array [
195
+ "suggest": [
196
196
  "components",
197
197
  ],
198
198
  },
199
- Object {
200
- "location": Array [
201
- Object {
199
+ {
200
+ "location": [
201
+ {
202
202
  "pointer": "#/openapi",
203
203
  "reportOnKey": true,
204
204
  "source": "foobar.yaml",
@@ -207,12 +207,12 @@ describe('Oas3 Structural visitor basic', () => {
207
207
  "message": "Servers must be present.",
208
208
  "ruleId": "no-empty-servers",
209
209
  "severity": "error",
210
- "suggest": Array [],
210
+ "suggest": [],
211
211
  },
212
- Object {
212
+ {
213
213
  "from": undefined,
214
- "location": Array [
215
- Object {
214
+ "location": [
215
+ {
216
216
  "pointer": "#/info/contact/test",
217
217
  "reportOnKey": true,
218
218
  "source": "foobar.yaml",
@@ -221,7 +221,7 @@ describe('Oas3 Structural visitor basic', () => {
221
221
  "message": "Property \`test\` is not expected here.",
222
222
  "ruleId": "spec",
223
223
  "severity": "error",
224
- "suggest": Array [],
224
+ "suggest": [],
225
225
  },
226
226
  ]
227
227
  `);
@@ -250,11 +250,11 @@ describe('Oas3 Structural visitor basic', () => {
250
250
  });
251
251
 
252
252
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
253
- Array [
254
- Object {
253
+ [
254
+ {
255
255
  "from": undefined,
256
- "location": Array [
257
- Object {
256
+ "location": [
257
+ {
258
258
  "pointer": "#/",
259
259
  "reportOnKey": true,
260
260
  "source": "foobar.yaml",
@@ -263,11 +263,11 @@ describe('Oas3 Structural visitor basic', () => {
263
263
  "message": "The field \`paths\` must be present on this level.",
264
264
  "ruleId": "spec",
265
265
  "severity": "error",
266
- "suggest": Array [],
266
+ "suggest": [],
267
267
  },
268
- Object {
269
- "location": Array [
270
- Object {
268
+ {
269
+ "location": [
270
+ {
271
271
  "pointer": "#/openapi",
272
272
  "reportOnKey": true,
273
273
  "source": "foobar.yaml",
@@ -276,12 +276,12 @@ describe('Oas3 Structural visitor basic', () => {
276
276
  "message": "Servers must be present.",
277
277
  "ruleId": "no-empty-servers",
278
278
  "severity": "error",
279
- "suggest": Array [],
279
+ "suggest": [],
280
280
  },
281
- Object {
281
+ {
282
282
  "from": undefined,
283
- "location": Array [
284
- Object {
283
+ "location": [
284
+ {
285
285
  "pointer": "#/info",
286
286
  "reportOnKey": true,
287
287
  "source": "foobar.yaml",
@@ -290,7 +290,7 @@ describe('Oas3 Structural visitor basic', () => {
290
290
  "message": "The field \`title\` must be present on this level.",
291
291
  "ruleId": "spec",
292
292
  "severity": "error",
293
- "suggest": Array [],
293
+ "suggest": [],
294
294
  },
295
295
  ]
296
296
  `);
@@ -36,10 +36,10 @@ describe('Oas3 spec-components-invalid-map-name', () => {
36
36
  });
37
37
 
38
38
  expect(results).toMatchInlineSnapshot(`
39
- Array [
40
- Object {
41
- "location": Array [
42
- Object {
39
+ [
40
+ {
41
+ "location": [
42
+ {
43
43
  "pointer": "#/components/parameters/my Param",
44
44
  "reportOnKey": true,
45
45
  "source": Source {
@@ -68,14 +68,14 @@ describe('Oas3 spec-components-invalid-map-name', () => {
68
68
  },
69
69
  },
70
70
  ],
71
- "message": "The map key in parameters \\"my Param\\" does not match the regular expression \\"^[a-zA-Z0-9\\\\.\\\\-_]+$\\"",
71
+ "message": "The map key in parameters "my Param" does not match the regular expression "^[a-zA-Z0-9\\.\\-_]+$"",
72
72
  "ruleId": "spec-components-invalid-map-name",
73
73
  "severity": "error",
74
- "suggest": Array [],
74
+ "suggest": [],
75
75
  },
76
- Object {
77
- "location": Array [
78
- Object {
76
+ {
77
+ "location": [
78
+ {
79
79
  "pointer": "#/components/schemas/first schema",
80
80
  "reportOnKey": true,
81
81
  "source": Source {
@@ -104,14 +104,14 @@ describe('Oas3 spec-components-invalid-map-name', () => {
104
104
  },
105
105
  },
106
106
  ],
107
- "message": "The map key in schemas \\"first schema\\" does not match the regular expression \\"^[a-zA-Z0-9\\\\.\\\\-_]+$\\"",
107
+ "message": "The map key in schemas "first schema" does not match the regular expression "^[a-zA-Z0-9\\.\\-_]+$"",
108
108
  "ruleId": "spec-components-invalid-map-name",
109
109
  "severity": "error",
110
- "suggest": Array [],
110
+ "suggest": [],
111
111
  },
112
- Object {
113
- "location": Array [
114
- Object {
112
+ {
113
+ "location": [
114
+ {
115
115
  "pointer": "#/components/responses/400 status",
116
116
  "reportOnKey": true,
117
117
  "source": Source {
@@ -140,14 +140,14 @@ describe('Oas3 spec-components-invalid-map-name', () => {
140
140
  },
141
141
  },
142
142
  ],
143
- "message": "The map key in responses \\"400 status\\" does not match the regular expression \\"^[a-zA-Z0-9\\\\.\\\\-_]+$\\"",
143
+ "message": "The map key in responses "400 status" does not match the regular expression "^[a-zA-Z0-9\\.\\-_]+$"",
144
144
  "ruleId": "spec-components-invalid-map-name",
145
145
  "severity": "error",
146
- "suggest": Array [],
146
+ "suggest": [],
147
147
  },
148
- Object {
149
- "location": Array [
150
- Object {
148
+ {
149
+ "location": [
150
+ {
151
151
  "pointer": "#/components/examples/invalid identifier",
152
152
  "reportOnKey": true,
153
153
  "source": Source {
@@ -176,10 +176,10 @@ describe('Oas3 spec-components-invalid-map-name', () => {
176
176
  },
177
177
  },
178
178
  ],
179
- "message": "The map key in examples \\"invalid identifier\\" does not match the regular expression \\"^[a-zA-Z0-9\\\\.\\\\-_]+$\\"",
179
+ "message": "The map key in examples "invalid identifier" does not match the regular expression "^[a-zA-Z0-9\\.\\-_]+$"",
180
180
  "ruleId": "spec-components-invalid-map-name",
181
181
  "severity": "error",
182
- "suggest": Array [],
182
+ "suggest": [],
183
183
  },
184
184
  ]
185
185
  `);
@@ -212,7 +212,7 @@ describe('Oas3 spec-components-invalid-map-name', () => {
212
212
  }),
213
213
  });
214
214
 
215
- expect(results).toMatchInlineSnapshot(`Array []`);
215
+ expect(results).toMatchInlineSnapshot(`[]`);
216
216
  });
217
217
 
218
218
  it('should not report invalid keys inside nested examples', async () => {
@@ -240,10 +240,10 @@ describe('Oas3 spec-components-invalid-map-name', () => {
240
240
  });
241
241
 
242
242
  expect(results).toMatchInlineSnapshot(`
243
- Array [
244
- Object {
245
- "location": Array [
246
- Object {
243
+ [
244
+ {
245
+ "location": [
246
+ {
247
247
  "pointer": "#/components/parameters/my Param",
248
248
  "reportOnKey": true,
249
249
  "source": Source {
@@ -265,10 +265,10 @@ describe('Oas3 spec-components-invalid-map-name', () => {
265
265
  },
266
266
  },
267
267
  ],
268
- "message": "The map key in parameters \\"my Param\\" does not match the regular expression \\"^[a-zA-Z0-9\\\\.\\\\-_]+$\\"",
268
+ "message": "The map key in parameters "my Param" does not match the regular expression "^[a-zA-Z0-9\\.\\-_]+$"",
269
269
  "ruleId": "spec-components-invalid-map-name",
270
270
  "severity": "error",
271
- "suggest": Array [],
271
+ "suggest": [],
272
272
  },
273
273
  ]
274
274
  `);
@@ -53,7 +53,7 @@ import { RequiredStringPropertyMissingMinLength } from '../common/required-strin
53
53
  import { SpecStrictRefs } from '../common/spec-strict-refs';
54
54
  import { ComponentNameUnique } from './component-name-unique';
55
55
 
56
- export const rules = {
56
+ export const rules: Oas3RuleSet<'built-in'> = {
57
57
  spec: Spec,
58
58
  'info-contact': InfoContact,
59
59
  'info-license': InfoLicense,
@@ -64,7 +64,6 @@ export const rules = {
64
64
  assertions: Assertions,
65
65
  'operation-operationId-unique': OperationIdUnique,
66
66
  'operation-parameters-unique': OperationParametersUnique,
67
- 'path-parameters-defined': PathParamsDefined,
68
67
  'operation-tag-defined': OperationTagDefined,
69
68
  'no-example-value-and-externalValue': NoExampleValueAndExternalValue,
70
69
  'no-enum-type-mismatch': NoEnumTypeMismatch,
@@ -81,6 +80,7 @@ export const rules = {
81
80
  'operation-description': OperationDescription,
82
81
  'no-unused-components': NoUnusedComponents,
83
82
  'path-not-include-query': PathNotIncludeQuery,
83
+ 'path-parameters-defined': PathParamsDefined,
84
84
  'path-params-defined': PathParamsDefined,
85
85
  'parameter-description': ParameterDescription,
86
86
  'operation-singular-tag': OperationSingularTag,
@@ -108,6 +108,6 @@ export const rules = {
108
108
  'required-string-property-missing-min-length': RequiredStringPropertyMissingMinLength,
109
109
  'spec-strict-refs': SpecStrictRefs,
110
110
  'component-name-unique': ComponentNameUnique,
111
- } as Oas3RuleSet;
111
+ };
112
112
 
113
113
  export const preprocessors = {};
@@ -4,64 +4,96 @@ import { NodeType, listOf } from '.';
4
4
  import { Oas3_1Types } from './oas3_1';
5
5
  import { omitObjectProps, pickObjectProps, isCustomRuleId } from '../utils';
6
6
 
7
- const builtInRulesList = [
7
+ const builtInCommonRules = [
8
8
  'spec',
9
9
  'info-contact',
10
- 'info-license',
10
+ 'operation-operationId',
11
+ 'tag-description',
12
+ 'tags-alphabetical',
13
+ ] as const;
14
+
15
+ export type BuiltInCommonRuleId = typeof builtInCommonRules[number];
16
+
17
+ const builtInCommonOASRules = [
11
18
  'info-license-url',
19
+ 'info-license',
20
+ 'no-ambiguous-paths',
21
+ 'no-enum-type-mismatch',
22
+ 'no-http-verbs-in-paths',
23
+ 'no-identical-paths',
24
+ 'no-invalid-parameter-examples',
25
+ 'no-invalid-schema-examples',
26
+ 'no-path-trailing-slash',
12
27
  'operation-2xx-response',
13
28
  'operation-4xx-response',
14
- 'operation-4xx-problem-details-rfc7807',
15
- 'assertions',
29
+ 'operation-description',
16
30
  'operation-operationId-unique',
31
+ 'operation-operationId-url-safe',
17
32
  'operation-parameters-unique',
18
- 'path-parameters-defined',
33
+ 'operation-singular-tag',
34
+ 'operation-summary',
19
35
  'operation-tag-defined',
20
- 'no-example-value-and-externalValue',
21
- 'no-enum-type-mismatch',
22
- 'no-path-trailing-slash',
23
- 'no-empty-servers',
36
+ 'parameter-description',
24
37
  'path-declaration-must-exist',
25
- 'operation-operationId-url-safe',
26
- 'operation-operationId',
27
- 'operation-summary',
28
- 'tags-alphabetical',
29
- 'no-server-example.com',
30
- 'no-server-trailing-slash',
31
- 'tag-description',
32
- 'operation-description',
33
- 'no-unused-components',
38
+ 'path-excludes-patterns',
39
+ 'path-http-verbs-order',
34
40
  'path-not-include-query',
35
41
  'path-params-defined',
36
- 'parameter-description',
37
- 'operation-singular-tag',
42
+ 'path-parameters-defined',
43
+ 'path-segment-plural',
44
+ 'paths-kebab-case',
45
+ 'required-string-property-missing-min-length',
46
+ 'response-contains-header',
47
+ 'scalar-property-missing-example',
38
48
  'security-defined',
49
+ 'spec-strict-refs',
39
50
  'no-unresolved-refs',
40
- 'paths-kebab-case',
51
+ ] as const;
52
+
53
+ export type BuiltInCommonOASRuleId = typeof builtInCommonOASRules[number];
54
+
55
+ const builtInOAS2Rules = [
41
56
  'boolean-parameter-prefixes',
42
- 'path-http-verbs-order',
57
+ 'request-mime-type',
58
+ 'response-contains-property',
59
+ 'response-mime-type',
60
+ ] as const;
61
+
62
+ export type BuiltInOAS2RuleId = typeof builtInOAS2Rules[number];
63
+
64
+ const builtInOAS3Rules = [
65
+ 'boolean-parameter-prefixes',
66
+ 'component-name-unique',
67
+ 'no-empty-servers',
68
+ 'no-example-value-and-externalValue',
43
69
  'no-invalid-media-type-examples',
44
- 'no-identical-paths',
45
- 'no-ambiguous-paths',
46
- 'no-undefined-server-variable',
70
+ 'no-server-example.com',
71
+ 'no-server-trailing-slash',
47
72
  'no-server-variables-empty-enum',
48
- 'no-http-verbs-in-paths',
49
- 'path-excludes-patterns',
73
+ 'no-undefined-server-variable',
74
+ 'no-unused-components',
75
+ 'operation-4xx-problem-details-rfc7807',
50
76
  'request-mime-type',
51
- 'response-mime-type',
52
- 'path-segment-plural',
53
- 'no-invalid-schema-examples',
54
- 'no-invalid-parameter-examples',
55
- 'response-contains-header',
56
77
  'response-contains-property',
57
- 'scalar-property-missing-example',
78
+ 'response-mime-type',
58
79
  'spec-components-invalid-map-name',
59
- 'required-string-property-missing-min-length',
60
- 'spec-strict-refs',
61
- 'component-name-unique',
62
- 'channels-kebab-case',
63
- 'no-channel-trailing-slash',
64
- ];
80
+ ] as const;
81
+
82
+ export type BuiltInOAS3RuleId = typeof builtInOAS3Rules[number];
83
+
84
+ const builtInAsync2Rules = ['channels-kebab-case', 'no-channel-trailing-slash'] as const;
85
+
86
+ export type BuiltInAsync2RuleId = typeof builtInAsync2Rules[number];
87
+
88
+ const builtInRules = [
89
+ ...builtInCommonRules,
90
+ ...builtInCommonOASRules,
91
+ ...builtInOAS2Rules,
92
+ ...builtInOAS3Rules,
93
+ ...builtInAsync2Rules,
94
+ ] as const;
95
+
96
+ type BuiltInRuleId = typeof builtInRules[number];
65
97
 
66
98
  const nodeTypesList = [
67
99
  'any',
@@ -138,14 +170,17 @@ const ConfigStyleguide: NodeType = {
138
170
  oas2Rules: 'Rules',
139
171
  oas3_0Rules: 'Rules',
140
172
  oas3_1Rules: 'Rules',
173
+ async2Rules: 'Rules',
141
174
  preprocessors: { type: 'object' },
142
175
  oas2Preprocessors: { type: 'object' },
143
176
  oas3_0Preprocessors: { type: 'object' },
144
177
  oas3_1Preprocessors: { type: 'object' },
178
+ async2Preprocessors: { type: 'object' },
145
179
  decorators: { type: 'object' },
146
180
  oas2Decorators: { type: 'object' },
147
181
  oas3_0Decorators: { type: 'object' },
148
182
  oas3_1Decorators: { type: 'object' },
183
+ async2Decorators: { type: 'object' },
149
184
  },
150
185
  };
151
186
 
@@ -243,7 +278,7 @@ const Rules: NodeType = {
243
278
  } else if (key.startsWith('assert/')) {
244
279
  // keep the old assert/ prefix as an alias
245
280
  return 'Assert';
246
- } else if (builtInRulesList.includes(key) || isCustomRuleId(key)) {
281
+ } else if (builtInRules.includes(key as BuiltInRuleId) || isCustomRuleId(key)) {
247
282
  if (typeof value === 'string') {
248
283
  return { enum: ['error', 'warn', 'off'] };
249
284
  } else {
package/src/visitors.ts CHANGED
@@ -73,11 +73,11 @@ type VisitObject<T> = {
73
73
  skip?: SkipFunction<T>;
74
74
  };
75
75
 
76
- type NestedVisitObject<T, P> = VisitObject<T> & NestedVisitor<P>;
76
+ export type NestedVisitObject<T, P> = VisitObject<T> & NestedVisitor<P>;
77
77
 
78
78
  type VisitFunctionOrObject<T> = VisitFunction<T> | VisitObject<T>;
79
79
 
80
- type VisitorNode<T> = {
80
+ export type VisitorNode<T> = {
81
81
  ruleId: string;
82
82
  severity: ProblemSeverity;
83
83
  context: VisitorLevelContext | VisitorSkippedLevelContext;
@@ -113,7 +113,7 @@ export type VisitorSkippedLevelContext = {
113
113
  seen: Set<any>;
114
114
  };
115
115
 
116
- type NormalizeVisitor<Fn> = Fn extends VisitFunction<infer T> ? VisitorNode<T> : never;
116
+ export type NormalizeVisitor<Fn> = Fn extends VisitFunction<infer T> ? VisitorNode<T> : never;
117
117
 
118
118
  export type BaseVisitor = {
119
119
  any?:
package/src/walk.ts CHANGED
@@ -4,6 +4,9 @@ import type {
4
4
  NormalizedOasVisitors,
5
5
  VisitorSkippedLevelContext,
6
6
  VisitFunction,
7
+ BaseVisitor,
8
+ NormalizeVisitor,
9
+ VisitorNode,
7
10
  } from './visitors';
8
11
  import type { ResolvedRefMap, Document } from './resolve';
9
12
  import type { NormalizedNodeType } from './types';
@@ -15,13 +18,23 @@ import { ResolveError, YamlParseError, Source, makeRefId } from './resolve';
15
18
  import { SpecVersion } from './oas-types';
16
19
  import { isNamedType, SpecExtension } from './types';
17
20
 
18
- type NonUndefined = string | number | boolean | symbol | bigint | object | Record<string, any>;
21
+ export type NonUndefined =
22
+ | string
23
+ | number
24
+ | boolean
25
+ | symbol
26
+ | bigint
27
+ | object
28
+ | Record<string, any>;
19
29
 
20
30
  export type ResolveResult<T extends NonUndefined> =
21
31
  | { node: T; location: Location; error?: ResolveError | YamlParseError }
22
32
  | { node: undefined; location: undefined; error?: ResolveError | YamlParseError };
23
33
 
24
- export type ResolveFn = <T>(node: Referenced<T>, from?: string) => ResolveResult<T>;
34
+ export type ResolveFn = <T extends NonUndefined>(
35
+ node: Referenced<T>,
36
+ from?: string
37
+ ) => ResolveResult<T>;
25
38
 
26
39
  export type UserContext = {
27
40
  report(problem: Problem): void;
@@ -85,7 +98,7 @@ export type WalkContext = {
85
98
  };
86
99
 
87
100
  function collectParents(ctx: VisitorLevelContext) {
88
- const parents: Record<string, any> = {};
101
+ const parents: Record<string, unknown> = {};
89
102
  while (ctx.parent) {
90
103
  parents[ctx.parent.type.name] = ctx.parent.activatedOn?.value.node;
91
104
  ctx = ctx.parent;
@@ -104,7 +117,7 @@ function collectParentsLocations(ctx: VisitorLevelContext) {
104
117
  return locations;
105
118
  }
106
119
 
107
- export function walkDocument<T>(opts: {
120
+ export function walkDocument<T extends BaseVisitor>(opts: {
108
121
  document: Document;
109
122
  rootType: NormalizedNodeType;
110
123
  normalizedVisitors: NormalizedOasVisitors<T>;
@@ -112,7 +125,7 @@ export function walkDocument<T>(opts: {
112
125
  ctx: WalkContext;
113
126
  }) {
114
127
  const { document, rootType, normalizedVisitors, resolvedRefMap, ctx } = opts;
115
- const seenNodesPerType: Record<string, Set<any>> = {};
128
+ const seenNodesPerType: Record<string, Set<unknown>> = {};
116
129
  const ignoredNodes = new Set<string>();
117
130
 
118
131
  walkNode(document.parsed, rootType, new Location(document.source, '#/'), undefined, '');
@@ -185,7 +198,7 @@ export function walkDocument<T>(opts: {
185
198
 
186
199
  const anyEnterVisitors = normalizedVisitors.any.enter;
187
200
  const currentEnterVisitors = anyEnterVisitors.concat(
188
- normalizedVisitors[type.name]?.enter || []
201
+ (normalizedVisitors[type.name]?.enter as NormalizeVisitor<VisitorNode<unknown>[]>) || []
189
202
  );
190
203
 
191
204
  const activatedContexts: Array<VisitorSkippedLevelContext | VisitorLevelContext> = [];
@@ -328,7 +341,7 @@ export function walkDocument<T>(opts: {
328
341
  if (context.isSkippedLevel) {
329
342
  context.seen.delete(resolvedNode);
330
343
  } else {
331
- context.activatedOn = popStack(context.activatedOn) as any;
344
+ context.activatedOn = popStack(context.activatedOn);
332
345
  if (context.parent) {
333
346
  let ctx: VisitorLevelContext | null = context.parent;
334
347
  while (ctx) {
@@ -378,9 +391,9 @@ export function walkDocument<T>(opts: {
378
391
 
379
392
  // returns true ignores all the next visitors on the specific node
380
393
  function visitWithContext(
381
- visit: VisitFunction<any>,
382
- resolvedNode: any,
383
- node: any,
394
+ visit: VisitFunction<unknown>,
395
+ resolvedNode: unknown,
396
+ node: unknown,
384
397
  context: VisitorLevelContext,
385
398
  ruleId: string,
386
399
  severity: ProblemSeverity