@redocly/openapi-core 0.0.0-snapshot.1737554067

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 (322) hide show
  1. package/README.md +268 -0
  2. package/lib/benchmark/benches/lint-with-many-rules.bench.d.ts +4 -0
  3. package/lib/benchmark/benches/lint-with-many-rules.bench.js +38 -0
  4. package/lib/benchmark/benches/lint-with-nested-rule.bench.d.ts +4 -0
  5. package/lib/benchmark/benches/lint-with-nested-rule.bench.js +44 -0
  6. package/lib/benchmark/benches/lint-with-no-rules.bench.d.ts +4 -0
  7. package/lib/benchmark/benches/lint-with-no-rules.bench.js +25 -0
  8. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.d.ts +4 -0
  9. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +37 -0
  10. package/lib/benchmark/benches/lint-with-top-level-rule.bench.d.ts +4 -0
  11. package/lib/benchmark/benches/lint-with-top-level-rule.bench.js +36 -0
  12. package/lib/benchmark/benches/recommended-oas3.bench.d.ts +3 -0
  13. package/lib/benchmark/benches/recommended-oas3.bench.js +21 -0
  14. package/lib/benchmark/benches/resolve-with-no-external.bench.d.ts +3 -0
  15. package/lib/benchmark/benches/resolve-with-no-external.bench.js +22 -0
  16. package/lib/benchmark/utils.d.ts +6 -0
  17. package/lib/benchmark/utils.js +34 -0
  18. package/lib/bundle.d.ts +50 -0
  19. package/lib/bundle.js +385 -0
  20. package/lib/config/all.d.ts +3 -0
  21. package/lib/config/all.js +227 -0
  22. package/lib/config/builtIn.d.ts +3 -0
  23. package/lib/config/builtIn.js +53 -0
  24. package/lib/config/config-resolvers.d.ts +30 -0
  25. package/lib/config/config-resolvers.js +447 -0
  26. package/lib/config/config.d.ts +53 -0
  27. package/lib/config/config.js +320 -0
  28. package/lib/config/index.d.ts +7 -0
  29. package/lib/config/index.js +23 -0
  30. package/lib/config/load.d.ts +38 -0
  31. package/lib/config/load.js +140 -0
  32. package/lib/config/minimal.d.ts +3 -0
  33. package/lib/config/minimal.js +203 -0
  34. package/lib/config/recommended-strict.d.ts +3 -0
  35. package/lib/config/recommended-strict.js +203 -0
  36. package/lib/config/recommended.d.ts +3 -0
  37. package/lib/config/recommended.js +203 -0
  38. package/lib/config/rules.d.ts +10 -0
  39. package/lib/config/rules.js +37 -0
  40. package/lib/config/spec.d.ts +3 -0
  41. package/lib/config/spec.js +29 -0
  42. package/lib/config/types.d.ts +189 -0
  43. package/lib/config/types.js +2 -0
  44. package/lib/config/utils.d.ts +19 -0
  45. package/lib/config/utils.js +308 -0
  46. package/lib/decorators/arazzo/index.d.ts +1 -0
  47. package/lib/decorators/arazzo/index.js +4 -0
  48. package/lib/decorators/async2/index.d.ts +1 -0
  49. package/lib/decorators/async2/index.js +4 -0
  50. package/lib/decorators/async3/index.d.ts +1 -0
  51. package/lib/decorators/async3/index.js +4 -0
  52. package/lib/decorators/common/filters/filter-helper.d.ts +3 -0
  53. package/lib/decorators/common/filters/filter-helper.js +66 -0
  54. package/lib/decorators/common/filters/filter-in.d.ts +2 -0
  55. package/lib/decorators/common/filters/filter-in.js +17 -0
  56. package/lib/decorators/common/filters/filter-out.d.ts +2 -0
  57. package/lib/decorators/common/filters/filter-out.js +17 -0
  58. package/lib/decorators/common/info-description-override.d.ts +2 -0
  59. package/lib/decorators/common/info-description-override.js +24 -0
  60. package/lib/decorators/common/info-override.d.ts +2 -0
  61. package/lib/decorators/common/info-override.js +17 -0
  62. package/lib/decorators/common/media-type-examples-override.d.ts +2 -0
  63. package/lib/decorators/common/media-type-examples-override.js +59 -0
  64. package/lib/decorators/common/operation-description-override.d.ts +2 -0
  65. package/lib/decorators/common/operation-description-override.js +29 -0
  66. package/lib/decorators/common/registry-dependencies.d.ts +2 -0
  67. package/lib/decorators/common/registry-dependencies.js +24 -0
  68. package/lib/decorators/common/remove-x-internal.d.ts +2 -0
  69. package/lib/decorators/common/remove-x-internal.js +69 -0
  70. package/lib/decorators/common/tag-description-override.d.ts +2 -0
  71. package/lib/decorators/common/tag-description-override.js +25 -0
  72. package/lib/decorators/oas2/index.d.ts +11 -0
  73. package/lib/decorators/oas2/index.js +21 -0
  74. package/lib/decorators/oas2/remove-unused-components.d.ts +2 -0
  75. package/lib/decorators/oas2/remove-unused-components.js +89 -0
  76. package/lib/decorators/oas3/index.d.ts +12 -0
  77. package/lib/decorators/oas3/index.js +23 -0
  78. package/lib/decorators/oas3/remove-unused-components.d.ts +2 -0
  79. package/lib/decorators/oas3/remove-unused-components.js +100 -0
  80. package/lib/env.d.ts +2 -0
  81. package/lib/env.js +7 -0
  82. package/lib/format/codeframes.d.ts +22 -0
  83. package/lib/format/codeframes.js +185 -0
  84. package/lib/format/format.d.ts +20 -0
  85. package/lib/format/format.js +365 -0
  86. package/lib/index.d.ts +26 -0
  87. package/lib/index.js +98 -0
  88. package/lib/js-yaml/index.d.ts +3 -0
  89. package/lib/js-yaml/index.js +15 -0
  90. package/lib/lint.d.ts +32 -0
  91. package/lib/lint.js +118 -0
  92. package/lib/logger.d.ts +10 -0
  93. package/lib/logger.js +31 -0
  94. package/lib/oas-types.d.ts +36 -0
  95. package/lib/oas-types.js +92 -0
  96. package/lib/output.d.ts +3 -0
  97. package/lib/output.js +9 -0
  98. package/lib/redocly/domains.d.ts +14 -0
  99. package/lib/redocly/domains.js +41 -0
  100. package/lib/redocly/index.d.ts +30 -0
  101. package/lib/redocly/index.js +131 -0
  102. package/lib/redocly/redocly-client-types.d.ts +8 -0
  103. package/lib/redocly/redocly-client-types.js +2 -0
  104. package/lib/redocly/registry-api-types.d.ts +29 -0
  105. package/lib/redocly/registry-api-types.js +2 -0
  106. package/lib/redocly/registry-api.d.ts +17 -0
  107. package/lib/redocly/registry-api.js +96 -0
  108. package/lib/ref-utils.d.ts +27 -0
  109. package/lib/ref-utils.js +85 -0
  110. package/lib/resolve.d.ts +66 -0
  111. package/lib/resolve.js +342 -0
  112. package/lib/rules/ajv.d.ts +10 -0
  113. package/lib/rules/ajv.js +82 -0
  114. package/lib/rules/arazzo/criteria-unique.d.ts +2 -0
  115. package/lib/rules/arazzo/criteria-unique.js +71 -0
  116. package/lib/rules/arazzo/index.d.ts +3 -0
  117. package/lib/rules/arazzo/index.js +36 -0
  118. package/lib/rules/arazzo/parameters-unique.d.ts +2 -0
  119. package/lib/rules/arazzo/parameters-unique.js +32 -0
  120. package/lib/rules/arazzo/requestBody-replacements-unique.d.ts +2 -0
  121. package/lib/rules/arazzo/requestBody-replacements-unique.js +28 -0
  122. package/lib/rules/arazzo/sourceDescription-type.d.ts +2 -0
  123. package/lib/rules/arazzo/sourceDescription-type.js +22 -0
  124. package/lib/rules/arazzo/sourceDescriptions-name-unique.d.ts +2 -0
  125. package/lib/rules/arazzo/sourceDescriptions-name-unique.js +24 -0
  126. package/lib/rules/arazzo/sourceDescriptions-not-empty.d.ts +2 -0
  127. package/lib/rules/arazzo/sourceDescriptions-not-empty.js +18 -0
  128. package/lib/rules/arazzo/step-onFailure-unique.d.ts +2 -0
  129. package/lib/rules/arazzo/step-onFailure-unique.js +32 -0
  130. package/lib/rules/arazzo/step-onSuccess-unique.d.ts +2 -0
  131. package/lib/rules/arazzo/step-onSuccess-unique.js +32 -0
  132. package/lib/rules/arazzo/stepId-unique.d.ts +2 -0
  133. package/lib/rules/arazzo/stepId-unique.js +26 -0
  134. package/lib/rules/arazzo/workflow-dependsOn.d.ts +2 -0
  135. package/lib/rules/arazzo/workflow-dependsOn.js +56 -0
  136. package/lib/rules/arazzo/workflowId-unique.d.ts +2 -0
  137. package/lib/rules/arazzo/workflowId-unique.js +22 -0
  138. package/lib/rules/async2/channels-kebab-case.d.ts +2 -0
  139. package/lib/rules/async2/channels-kebab-case.js +19 -0
  140. package/lib/rules/async2/index.d.ts +3 -0
  141. package/lib/rules/async2/index.js +27 -0
  142. package/lib/rules/async2/no-channel-trailing-slash.d.ts +2 -0
  143. package/lib/rules/async2/no-channel-trailing-slash.js +16 -0
  144. package/lib/rules/async3/channels-kebab-case.d.ts +2 -0
  145. package/lib/rules/async3/channels-kebab-case.js +19 -0
  146. package/lib/rules/async3/index.d.ts +3 -0
  147. package/lib/rules/async3/index.js +27 -0
  148. package/lib/rules/async3/no-channel-trailing-slash.d.ts +2 -0
  149. package/lib/rules/async3/no-channel-trailing-slash.js +16 -0
  150. package/lib/rules/common/assertions/asserts.d.ts +30 -0
  151. package/lib/rules/common/assertions/asserts.js +281 -0
  152. package/lib/rules/common/assertions/index.d.ts +27 -0
  153. package/lib/rules/common/assertions/index.js +24 -0
  154. package/lib/rules/common/assertions/utils.d.ts +28 -0
  155. package/lib/rules/common/assertions/utils.js +226 -0
  156. package/lib/rules/common/info-contact.d.ts +2 -0
  157. package/lib/rules/common/info-contact.js +17 -0
  158. package/lib/rules/common/info-license-strict.d.ts +2 -0
  159. package/lib/rules/common/info-license-strict.js +26 -0
  160. package/lib/rules/common/info-license-url.d.ts +2 -0
  161. package/lib/rules/common/info-license-url.js +12 -0
  162. package/lib/rules/common/info-license.d.ts +2 -0
  163. package/lib/rules/common/info-license.js +17 -0
  164. package/lib/rules/common/no-ambiguous-paths.d.ts +2 -0
  165. package/lib/rules/common/no-ambiguous-paths.js +45 -0
  166. package/lib/rules/common/no-enum-type-mismatch.d.ts +2 -0
  167. package/lib/rules/common/no-enum-type-mismatch.js +41 -0
  168. package/lib/rules/common/no-http-verbs-in-paths.d.ts +2 -0
  169. package/lib/rules/common/no-http-verbs-in-paths.js +33 -0
  170. package/lib/rules/common/no-identical-paths.d.ts +2 -0
  171. package/lib/rules/common/no-identical-paths.js +24 -0
  172. package/lib/rules/common/no-invalid-parameter-examples.d.ts +1 -0
  173. package/lib/rules/common/no-invalid-parameter-examples.js +24 -0
  174. package/lib/rules/common/no-invalid-schema-examples.d.ts +1 -0
  175. package/lib/rules/common/no-invalid-schema-examples.js +22 -0
  176. package/lib/rules/common/no-path-trailing-slash.d.ts +2 -0
  177. package/lib/rules/common/no-path-trailing-slash.js +16 -0
  178. package/lib/rules/common/no-required-schema-properties-undefined.d.ts +2 -0
  179. package/lib/rules/common/no-required-schema-properties-undefined.js +36 -0
  180. package/lib/rules/common/operation-2xx-response.d.ts +2 -0
  181. package/lib/rules/common/operation-2xx-response.js +23 -0
  182. package/lib/rules/common/operation-4xx-response.d.ts +2 -0
  183. package/lib/rules/common/operation-4xx-response.js +23 -0
  184. package/lib/rules/common/operation-description.d.ts +2 -0
  185. package/lib/rules/common/operation-description.js +12 -0
  186. package/lib/rules/common/operation-operationId-unique.d.ts +2 -0
  187. package/lib/rules/common/operation-operationId-unique.js +20 -0
  188. package/lib/rules/common/operation-operationId-url-safe.d.ts +2 -0
  189. package/lib/rules/common/operation-operationId-url-safe.js +18 -0
  190. package/lib/rules/common/operation-operationId.d.ts +2 -0
  191. package/lib/rules/common/operation-operationId.js +16 -0
  192. package/lib/rules/common/operation-parameters-unique.d.ts +2 -0
  193. package/lib/rules/common/operation-parameters-unique.js +40 -0
  194. package/lib/rules/common/operation-singular-tag.d.ts +2 -0
  195. package/lib/rules/common/operation-singular-tag.js +16 -0
  196. package/lib/rules/common/operation-summary.d.ts +2 -0
  197. package/lib/rules/common/operation-summary.js +12 -0
  198. package/lib/rules/common/operation-tag-defined.d.ts +2 -0
  199. package/lib/rules/common/operation-tag-defined.js +24 -0
  200. package/lib/rules/common/parameter-description.d.ts +2 -0
  201. package/lib/rules/common/parameter-description.js +22 -0
  202. package/lib/rules/common/path-declaration-must-exist.d.ts +2 -0
  203. package/lib/rules/common/path-declaration-must-exist.js +16 -0
  204. package/lib/rules/common/path-excludes-patterns.d.ts +2 -0
  205. package/lib/rules/common/path-excludes-patterns.js +22 -0
  206. package/lib/rules/common/path-http-verbs-order.d.ts +2 -0
  207. package/lib/rules/common/path-http-verbs-order.js +26 -0
  208. package/lib/rules/common/path-not-include-query.d.ts +2 -0
  209. package/lib/rules/common/path-not-include-query.js +18 -0
  210. package/lib/rules/common/path-params-defined.d.ts +2 -0
  211. package/lib/rules/common/path-params-defined.js +58 -0
  212. package/lib/rules/common/path-segment-plural.d.ts +2 -0
  213. package/lib/rules/common/path-segment-plural.js +33 -0
  214. package/lib/rules/common/paths-kebab-case.d.ts +2 -0
  215. package/lib/rules/common/paths-kebab-case.js +20 -0
  216. package/lib/rules/common/required-string-property-missing-min-length.d.ts +2 -0
  217. package/lib/rules/common/required-string-property-missing-min-length.js +37 -0
  218. package/lib/rules/common/response-contains-header.d.ts +2 -0
  219. package/lib/rules/common/response-contains-header.js +29 -0
  220. package/lib/rules/common/scalar-property-missing-example.d.ts +2 -0
  221. package/lib/rules/common/scalar-property-missing-example.js +42 -0
  222. package/lib/rules/common/security-defined.d.ts +2 -0
  223. package/lib/rules/common/security-defined.js +65 -0
  224. package/lib/rules/common/spec-strict-refs.d.ts +2 -0
  225. package/lib/rules/common/spec-strict-refs.js +30 -0
  226. package/lib/rules/common/struct.d.ts +2 -0
  227. package/lib/rules/common/struct.js +158 -0
  228. package/lib/rules/common/tag-description.d.ts +2 -0
  229. package/lib/rules/common/tag-description.js +12 -0
  230. package/lib/rules/common/tags-alphabetical.d.ts +2 -0
  231. package/lib/rules/common/tags-alphabetical.js +23 -0
  232. package/lib/rules/no-unresolved-refs.d.ts +5 -0
  233. package/lib/rules/no-unresolved-refs.js +46 -0
  234. package/lib/rules/oas2/boolean-parameter-prefixes.d.ts +5 -0
  235. package/lib/rules/oas2/boolean-parameter-prefixes.js +22 -0
  236. package/lib/rules/oas2/index.d.ts +3 -0
  237. package/lib/rules/oas2/index.js +98 -0
  238. package/lib/rules/oas2/request-mime-type.d.ts +2 -0
  239. package/lib/rules/oas2/request-mime-type.js +17 -0
  240. package/lib/rules/oas2/response-contains-property.d.ts +2 -0
  241. package/lib/rules/oas2/response-contains-property.js +37 -0
  242. package/lib/rules/oas2/response-mime-type.d.ts +2 -0
  243. package/lib/rules/oas2/response-mime-type.js +17 -0
  244. package/lib/rules/oas3/array-parameter-serialization.d.ts +5 -0
  245. package/lib/rules/oas3/array-parameter-serialization.js +29 -0
  246. package/lib/rules/oas3/boolean-parameter-prefixes.d.ts +5 -0
  247. package/lib/rules/oas3/boolean-parameter-prefixes.js +24 -0
  248. package/lib/rules/oas3/component-name-unique.d.ts +2 -0
  249. package/lib/rules/oas3/component-name-unique.js +133 -0
  250. package/lib/rules/oas3/index.d.ts +3 -0
  251. package/lib/rules/oas3/index.js +122 -0
  252. package/lib/rules/oas3/no-empty-servers.d.ts +2 -0
  253. package/lib/rules/oas3/no-empty-servers.js +23 -0
  254. package/lib/rules/oas3/no-example-value-and-externalValue.d.ts +2 -0
  255. package/lib/rules/oas3/no-example-value-and-externalValue.js +16 -0
  256. package/lib/rules/oas3/no-invalid-media-type-examples.d.ts +2 -0
  257. package/lib/rules/oas3/no-invalid-media-type-examples.js +39 -0
  258. package/lib/rules/oas3/no-server-example.com.d.ts +2 -0
  259. package/lib/rules/oas3/no-server-example.com.js +18 -0
  260. package/lib/rules/oas3/no-server-trailing-slash.d.ts +2 -0
  261. package/lib/rules/oas3/no-server-trailing-slash.js +18 -0
  262. package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
  263. package/lib/rules/oas3/no-server-variables-empty-enum.js +66 -0
  264. package/lib/rules/oas3/no-undefined-server-variable.d.ts +2 -0
  265. package/lib/rules/oas3/no-undefined-server-variable.js +31 -0
  266. package/lib/rules/oas3/no-unused-components.d.ts +2 -0
  267. package/lib/rules/oas3/no-unused-components.js +73 -0
  268. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +5 -0
  269. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +36 -0
  270. package/lib/rules/oas3/request-mime-type.d.ts +2 -0
  271. package/lib/rules/oas3/request-mime-type.js +31 -0
  272. package/lib/rules/oas3/response-contains-property.d.ts +2 -0
  273. package/lib/rules/oas3/response-contains-property.js +39 -0
  274. package/lib/rules/oas3/response-mime-type.d.ts +2 -0
  275. package/lib/rules/oas3/response-mime-type.js +31 -0
  276. package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
  277. package/lib/rules/oas3/spec-components-invalid-map-name.js +62 -0
  278. package/lib/rules/other/stats.d.ts +41 -0
  279. package/lib/rules/other/stats.js +75 -0
  280. package/lib/rules/spot/no-criteria-xpath.d.ts +2 -0
  281. package/lib/rules/spot/no-criteria-xpath.js +21 -0
  282. package/lib/rules/spot/spot-supported-versions.d.ts +2 -0
  283. package/lib/rules/spot/spot-supported-versions.js +21 -0
  284. package/lib/rules/utils.d.ts +22 -0
  285. package/lib/rules/utils.js +183 -0
  286. package/lib/types/arazzo.d.ts +2 -0
  287. package/lib/types/arazzo.js +311 -0
  288. package/lib/types/asyncapi2.d.ts +17 -0
  289. package/lib/types/asyncapi2.js +1008 -0
  290. package/lib/types/asyncapi3.d.ts +2 -0
  291. package/lib/types/asyncapi3.js +347 -0
  292. package/lib/types/index.d.ts +57 -0
  293. package/lib/types/index.js +94 -0
  294. package/lib/types/json-schema-adapter.d.ts +3 -0
  295. package/lib/types/json-schema-adapter.js +159 -0
  296. package/lib/types/oas2.d.ts +3 -0
  297. package/lib/types/oas2.js +456 -0
  298. package/lib/types/oas3.d.ts +7 -0
  299. package/lib/types/oas3.js +554 -0
  300. package/lib/types/oas3_1.d.ts +6 -0
  301. package/lib/types/oas3_1.js +285 -0
  302. package/lib/types/redocly-yaml.d.ts +26 -0
  303. package/lib/types/redocly-yaml.js +1126 -0
  304. package/lib/typings/arazzo.d.ts +131 -0
  305. package/lib/typings/arazzo.js +5 -0
  306. package/lib/typings/asyncapi.d.ts +21 -0
  307. package/lib/typings/asyncapi.js +2 -0
  308. package/lib/typings/asyncapi3.d.ts +53 -0
  309. package/lib/typings/asyncapi3.js +2 -0
  310. package/lib/typings/common.d.ts +8 -0
  311. package/lib/typings/common.js +2 -0
  312. package/lib/typings/openapi.d.ts +355 -0
  313. package/lib/typings/openapi.js +2 -0
  314. package/lib/typings/swagger.d.ts +217 -0
  315. package/lib/typings/swagger.js +2 -0
  316. package/lib/utils.d.ts +70 -0
  317. package/lib/utils.js +301 -0
  318. package/lib/visitors.d.ts +229 -0
  319. package/lib/visitors.js +176 -0
  320. package/lib/walk.d.ts +78 -0
  321. package/lib/walk.js +290 -0
  322. package/package.json +59 -0
@@ -0,0 +1,217 @@
1
+ import type { Schema } from 'js-yaml';
2
+ import type { Referenced } from './openapi';
3
+ export interface Oas2Definition {
4
+ swagger: '2.0';
5
+ info?: Oas2Info;
6
+ paths?: Oas2Paths;
7
+ basePath?: string;
8
+ schemes?: string[];
9
+ consumes?: string[];
10
+ produces?: string[];
11
+ definitions?: Record<string, Oas2Schema>;
12
+ responses?: Record<string, Oas2Response>;
13
+ parameters?: Record<string, Oas2Parameter>;
14
+ securityDefinitions?: Record<string, Oas2SecurityScheme>;
15
+ security?: Oas2SecurityRequirement[];
16
+ tags?: Oas2Tag[];
17
+ externalDocs?: Oas2ExternalDocs;
18
+ }
19
+ export interface Oas2Components {
20
+ definitions?: {
21
+ [name: string]: Record<string, Oas2Schema>;
22
+ };
23
+ securityDefinitions?: {
24
+ [name: string]: Record<string, Oas2SecurityScheme>;
25
+ };
26
+ responses?: {
27
+ [name: string]: Record<string, Oas2Response>;
28
+ };
29
+ parameters?: {
30
+ [name: string]: Record<string, Oas2Parameter>;
31
+ };
32
+ }
33
+ export interface Oas2Info {
34
+ title: string;
35
+ version: string;
36
+ description?: string;
37
+ termsOfService?: string;
38
+ contact?: Oas2Contact;
39
+ license?: Oas2License;
40
+ }
41
+ export interface Oas2Paths {
42
+ [path: string]: Oas2PathItem;
43
+ }
44
+ export interface Oas2PathItem {
45
+ get?: Oas2Operation;
46
+ put?: Oas2Operation;
47
+ post?: Oas2Operation;
48
+ delete?: Oas2Operation;
49
+ options?: Oas2Operation;
50
+ head?: Oas2Operation;
51
+ patch?: Oas2Operation;
52
+ parameters?: Array<Referenced<Oas2Parameter>>;
53
+ }
54
+ export interface Oas2XCodeSample {
55
+ lang: string;
56
+ label?: string;
57
+ source: string;
58
+ }
59
+ export interface Oas2Operation {
60
+ tags?: string[];
61
+ consumes?: string[];
62
+ produces?: string[];
63
+ schemes?: string[];
64
+ summary?: string;
65
+ description?: string;
66
+ externalDocs?: Oas2ExternalDocs;
67
+ operationId?: string;
68
+ parameters?: Array<Referenced<Oas2Parameter>>;
69
+ responses: Oas2Responses;
70
+ deprecated?: boolean;
71
+ security?: Oas2SecurityRequirement[];
72
+ 'x-codeSamples'?: Oas2XCodeSample[];
73
+ 'x-code-samples'?: Oas2XCodeSample[];
74
+ 'x-hideTryItPanel'?: boolean;
75
+ }
76
+ export type Oas2Parameter = Oas2BodyParameter | Oas2SimpleParameter;
77
+ export interface Oas2BodyParameter {
78
+ name: string;
79
+ in: 'body';
80
+ schema: Oas2Schema;
81
+ description?: string;
82
+ required?: boolean;
83
+ }
84
+ export interface Oas2SimpleParameter {
85
+ name: string;
86
+ in: Oas2ParameterLocation;
87
+ description?: string;
88
+ required?: boolean;
89
+ type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'file';
90
+ format?: string;
91
+ allowEmptyValue?: boolean;
92
+ items?: Oas2Items;
93
+ collectionFormat?: 'csv' | 'ssv' | 'tsv' | 'pipes' | 'multi';
94
+ default?: any;
95
+ maximum?: number;
96
+ exclusiveMaximum?: boolean;
97
+ minimum?: number;
98
+ exclusiveMinimum?: boolean;
99
+ maxLength?: number;
100
+ minLength?: number;
101
+ pattern?: string;
102
+ maxItems?: number;
103
+ minItems?: number;
104
+ uniqueItems?: boolean;
105
+ enum?: any[];
106
+ multipleOf?: number;
107
+ }
108
+ export interface Oas2Items {
109
+ type: 'string' | 'number' | 'integer' | 'boolean' | 'array';
110
+ format?: string;
111
+ allowEmptyValue?: boolean;
112
+ items?: Oas2Items;
113
+ collectionFormat?: 'csv' | 'ssv' | 'tsv' | 'pipes' | 'multi';
114
+ default?: any;
115
+ maximum?: number;
116
+ exclusiveMaximum?: boolean;
117
+ minimum?: number;
118
+ exclusiveMinimum?: boolean;
119
+ maxLength?: number;
120
+ minLength?: number;
121
+ pattern?: string;
122
+ maxItems?: number;
123
+ minItems?: number;
124
+ uniqueItems?: boolean;
125
+ enum?: any[];
126
+ multipleOf?: number;
127
+ }
128
+ export interface Oas2Xml {
129
+ name?: string;
130
+ namespace?: string;
131
+ prefix?: string;
132
+ attribute?: string;
133
+ wrapped?: string;
134
+ }
135
+ export interface Oas2Schema {
136
+ $ref?: string;
137
+ type?: string;
138
+ properties?: {
139
+ [name: string]: Oas2Schema;
140
+ };
141
+ additionalProperties?: boolean | Oas2Schema;
142
+ description?: string;
143
+ default?: any;
144
+ items?: Oas2Schema;
145
+ required?: string[];
146
+ readOnly?: boolean;
147
+ deprecated?: boolean;
148
+ format?: string;
149
+ externalDocs?: Oas2ExternalDocs;
150
+ discriminator?: string;
151
+ nullable?: boolean;
152
+ allOf?: Oas2Schema[];
153
+ title?: string;
154
+ multipleOf?: number;
155
+ maximum?: number;
156
+ exclusiveMaximum?: boolean;
157
+ minimum?: number;
158
+ exclusiveMinimum?: boolean;
159
+ maxLength?: number;
160
+ minLength?: number;
161
+ pattern?: string;
162
+ maxItems?: number;
163
+ minItems?: number;
164
+ uniqueItems?: boolean;
165
+ maxProperties?: number;
166
+ minProperties?: number;
167
+ enum?: any[];
168
+ example?: any;
169
+ xml?: Oas2Xml;
170
+ 'x-tags'?: string[];
171
+ }
172
+ export type Oas2ParameterLocation = 'query' | 'header' | 'path' | 'formData';
173
+ export interface Oas2Responses {
174
+ [code: string]: Oas2Response;
175
+ }
176
+ export type Oas2Header = Oas2Items & {
177
+ description?: 'string';
178
+ };
179
+ export interface Oas2Response {
180
+ description?: string;
181
+ schema: Referenced<Schema>;
182
+ examples?: Record<string, any>;
183
+ headers?: Record<string, Oas2Header>;
184
+ }
185
+ export interface Oas2SecurityRequirement {
186
+ [name: string]: string[];
187
+ }
188
+ export interface Oas2SecurityScheme {
189
+ type: 'basic' | 'apiKey' | 'oauth2';
190
+ description?: string;
191
+ name?: string;
192
+ in?: 'query' | 'header' | 'cookie';
193
+ scheme?: string;
194
+ flow: 'implicit' | 'password' | 'application' | 'accessCode';
195
+ authorizationUrl?: string;
196
+ tokenUrl?: string;
197
+ scopes?: Record<string, string>;
198
+ }
199
+ export interface Oas2Tag {
200
+ name: string;
201
+ description?: string;
202
+ externalDocs?: Oas2ExternalDocs;
203
+ 'x-displayName'?: string;
204
+ }
205
+ export interface Oas2ExternalDocs {
206
+ description?: string;
207
+ url: string;
208
+ }
209
+ export interface Oas2Contact {
210
+ name?: string;
211
+ url?: string;
212
+ email?: string;
213
+ }
214
+ export interface Oas2License {
215
+ name: string;
216
+ url?: string;
217
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/lib/utils.d.ts ADDED
@@ -0,0 +1,70 @@
1
+ import { HttpsProxyAgent } from 'https-proxy-agent';
2
+ import type { HttpResolveConfig } from './config';
3
+ import type { UserContext } from './walk';
4
+ export { parseYaml, stringifyYaml } from './js-yaml';
5
+ export type StackFrame<T> = {
6
+ prev: StackFrame<T> | null;
7
+ value: T;
8
+ };
9
+ export type Stack<T> = StackFrame<T> | null;
10
+ export type StackNonEmpty<T> = StackFrame<T>;
11
+ export declare function pushStack<T, P extends Stack<T> = Stack<T>>(head: P, value: T): {
12
+ prev: P;
13
+ value: T;
14
+ };
15
+ export declare function pluralize(sentence: string, count?: number, inclusive?: boolean): string;
16
+ export declare function popStack<T, P extends Stack<T>>(head: P): StackFrame<T> | null;
17
+ export type BundleOutputFormat = 'json' | 'yml' | 'yaml';
18
+ export declare function loadYaml<T>(filename: string): Promise<T>;
19
+ export declare function isDefined<T>(x: T | undefined): x is T;
20
+ export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
21
+ export declare function isEmptyObject(value: unknown): value is Record<string, unknown>;
22
+ export declare function isNotEmptyObject(obj: unknown): boolean;
23
+ export declare function isEmptyArray(value: unknown): boolean;
24
+ export declare function isNotEmptyArray<T>(args?: T[]): boolean;
25
+ export declare function readFileFromUrl(url: string, config: HttpResolveConfig): Promise<{
26
+ body: any;
27
+ mimeType: any;
28
+ }>;
29
+ export declare function pickObjectProps<T extends Record<string, unknown>>(object: T, keys: Array<string>): T;
30
+ export declare function omitObjectProps<T extends Record<string, unknown>>(object: T, keys: Array<string>): T;
31
+ export declare function splitCamelCaseIntoWords(str: string): Set<string>;
32
+ export declare function validateMimeType({ type, value }: any, { report, location }: UserContext, allowedValues: string[]): void;
33
+ export declare function validateMimeTypeOAS3({ type, value }: any, { report, location }: UserContext, allowedValues: string[]): void;
34
+ export declare function readFileAsStringSync(filePath: string): string;
35
+ export declare function yamlAndJsonSyncReader<T>(filePath: string): T;
36
+ export declare function isPathParameter(pathSegment: string): boolean;
37
+ /**
38
+ * Convert Windows backslash paths to slash paths: foo\\bar ➔ foo/bar
39
+ */
40
+ export declare function slash(path: string): string;
41
+ export declare function isString(value: unknown): value is string;
42
+ export declare function isNotString<T>(value: string | T): value is T;
43
+ export declare const assignConfig: <T extends string | {
44
+ severity?: string;
45
+ }>(target: Record<string, T>, obj?: Record<string, T>) => void;
46
+ export declare function assignOnlyExistingConfig<T extends string | {
47
+ severity?: string;
48
+ }>(target: Record<string, T>, obj?: Record<string, T>): void;
49
+ export declare function getMatchingStatusCodeRange(code: number | string): string;
50
+ export declare function isCustomRuleId(id: string): boolean;
51
+ export declare function doesYamlFileExist(filePath: string): boolean;
52
+ export declare function showWarningForDeprecatedField(deprecatedField: string, updatedField?: string, updatedObject?: string, link?: string): void;
53
+ export declare function showErrorForDeprecatedField(deprecatedField: string, updatedField?: string, updatedObject?: string): void;
54
+ export type Falsy = undefined | null | false | '' | 0;
55
+ export declare function isTruthy<Truthy>(value: Truthy | Falsy): value is Truthy;
56
+ export declare function identity<T>(value: T): T;
57
+ export declare function keysOf<T>(obj: T): (keyof T)[];
58
+ export declare function pickDefined<T extends Record<string, unknown>>(obj?: T): Record<string, unknown> | undefined;
59
+ export declare function nextTick(): Promise<unknown>;
60
+ export declare function pause(ms: number): Promise<void>;
61
+ export declare function getProxyAgent(): HttpsProxyAgent<string> | undefined;
62
+ /**
63
+ * Checks if two objects are deeply equal.
64
+ * Borrowed the source code from https://github.com/lukeed/dequal.
65
+ */
66
+ export declare function dequal(foo: any, bar: any): boolean;
67
+ export type CollectFn = (value: unknown) => void;
68
+ export type StrictObject<T extends object> = T & {
69
+ [key: string]: undefined;
70
+ };
package/lib/utils.js ADDED
@@ -0,0 +1,301 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assignConfig = exports.stringifyYaml = exports.parseYaml = void 0;
4
+ exports.pushStack = pushStack;
5
+ exports.pluralize = pluralize;
6
+ exports.popStack = popStack;
7
+ exports.loadYaml = loadYaml;
8
+ exports.isDefined = isDefined;
9
+ exports.isPlainObject = isPlainObject;
10
+ exports.isEmptyObject = isEmptyObject;
11
+ exports.isNotEmptyObject = isNotEmptyObject;
12
+ exports.isEmptyArray = isEmptyArray;
13
+ exports.isNotEmptyArray = isNotEmptyArray;
14
+ exports.readFileFromUrl = readFileFromUrl;
15
+ exports.pickObjectProps = pickObjectProps;
16
+ exports.omitObjectProps = omitObjectProps;
17
+ exports.splitCamelCaseIntoWords = splitCamelCaseIntoWords;
18
+ exports.validateMimeType = validateMimeType;
19
+ exports.validateMimeTypeOAS3 = validateMimeTypeOAS3;
20
+ exports.readFileAsStringSync = readFileAsStringSync;
21
+ exports.yamlAndJsonSyncReader = yamlAndJsonSyncReader;
22
+ exports.isPathParameter = isPathParameter;
23
+ exports.slash = slash;
24
+ exports.isString = isString;
25
+ exports.isNotString = isNotString;
26
+ exports.assignOnlyExistingConfig = assignOnlyExistingConfig;
27
+ exports.getMatchingStatusCodeRange = getMatchingStatusCodeRange;
28
+ exports.isCustomRuleId = isCustomRuleId;
29
+ exports.doesYamlFileExist = doesYamlFileExist;
30
+ exports.showWarningForDeprecatedField = showWarningForDeprecatedField;
31
+ exports.showErrorForDeprecatedField = showErrorForDeprecatedField;
32
+ exports.isTruthy = isTruthy;
33
+ exports.identity = identity;
34
+ exports.keysOf = keysOf;
35
+ exports.pickDefined = pickDefined;
36
+ exports.nextTick = nextTick;
37
+ exports.pause = pause;
38
+ exports.getProxyAgent = getProxyAgent;
39
+ exports.dequal = dequal;
40
+ const fs = require("fs");
41
+ const path_1 = require("path");
42
+ const minimatch = require("minimatch");
43
+ const node_fetch_1 = require("node-fetch");
44
+ const js_yaml_1 = require("./js-yaml");
45
+ const env_1 = require("./env");
46
+ const logger_1 = require("./logger");
47
+ const https_proxy_agent_1 = require("https-proxy-agent");
48
+ const pluralizeOne = require("pluralize");
49
+ var js_yaml_2 = require("./js-yaml");
50
+ Object.defineProperty(exports, "parseYaml", { enumerable: true, get: function () { return js_yaml_2.parseYaml; } });
51
+ Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: function () { return js_yaml_2.stringifyYaml; } });
52
+ function pushStack(head, value) {
53
+ return { prev: head, value };
54
+ }
55
+ function pluralize(sentence, count, inclusive) {
56
+ return sentence
57
+ .split(' ')
58
+ .map((word) => pluralizeOne(word, count, inclusive))
59
+ .join(' ');
60
+ }
61
+ function popStack(head) {
62
+ return head?.prev ?? null;
63
+ }
64
+ async function loadYaml(filename) {
65
+ const contents = await fs.promises.readFile(filename, 'utf-8');
66
+ return (0, js_yaml_1.parseYaml)(contents);
67
+ }
68
+ function isDefined(x) {
69
+ return x !== undefined;
70
+ }
71
+ function isPlainObject(value) {
72
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
73
+ }
74
+ function isEmptyObject(value) {
75
+ return isPlainObject(value) && Object.keys(value).length === 0;
76
+ }
77
+ function isNotEmptyObject(obj) {
78
+ return isPlainObject(obj) && !isEmptyObject(obj);
79
+ }
80
+ function isEmptyArray(value) {
81
+ return Array.isArray(value) && value.length === 0;
82
+ }
83
+ function isNotEmptyArray(args) {
84
+ return !!args && Array.isArray(args) && !!args.length;
85
+ }
86
+ async function readFileFromUrl(url, config) {
87
+ const headers = {};
88
+ for (const header of config.headers) {
89
+ if (match(url, header.matches)) {
90
+ headers[header.name] =
91
+ header.envVariable !== undefined ? env_1.env[header.envVariable] || '' : header.value;
92
+ }
93
+ }
94
+ const req = await (config.customFetch || node_fetch_1.default)(url, {
95
+ headers: headers,
96
+ });
97
+ if (!req.ok) {
98
+ throw new Error(`Failed to load ${url}: ${req.status} ${req.statusText}`);
99
+ }
100
+ return { body: await req.text(), mimeType: req.headers.get('content-type') };
101
+ }
102
+ function match(url, pattern) {
103
+ if (!pattern.match(/^https?:\/\//)) {
104
+ // if pattern doesn't specify protocol directly, do not match against it
105
+ url = url.replace(/^https?:\/\//, '');
106
+ }
107
+ return minimatch(url, pattern);
108
+ }
109
+ function pickObjectProps(object, keys) {
110
+ return Object.fromEntries(keys.filter((key) => key in object).map((key) => [key, object[key]]));
111
+ }
112
+ function omitObjectProps(object, keys) {
113
+ return Object.fromEntries(Object.entries(object).filter(([key]) => !keys.includes(key)));
114
+ }
115
+ function splitCamelCaseIntoWords(str) {
116
+ const camel = str
117
+ .split(/(?:[-._])|([A-Z][a-z]+)/)
118
+ .filter(isTruthy)
119
+ .map((item) => item.toLocaleLowerCase());
120
+ const caps = str
121
+ .split(/([A-Z]{2,})/)
122
+ .filter((e) => e && e === e.toUpperCase())
123
+ .map((item) => item.toLocaleLowerCase());
124
+ return new Set([...camel, ...caps]);
125
+ }
126
+ function validateMimeType({ type, value }, { report, location }, allowedValues) {
127
+ const ruleType = type === 'consumes' ? 'request' : 'response';
128
+ if (!allowedValues)
129
+ throw new Error(`Parameter "allowedValues" is not provided for "${ruleType}-mime-type" rule`);
130
+ if (!value[type])
131
+ return;
132
+ for (const mime of value[type]) {
133
+ if (!allowedValues.includes(mime)) {
134
+ report({
135
+ message: `Mime type "${mime}" is not allowed`,
136
+ location: location.child(value[type].indexOf(mime)).key(),
137
+ });
138
+ }
139
+ }
140
+ }
141
+ function validateMimeTypeOAS3({ type, value }, { report, location }, allowedValues) {
142
+ const ruleType = type === 'consumes' ? 'request' : 'response';
143
+ if (!allowedValues)
144
+ throw new Error(`Parameter "allowedValues" is not provided for "${ruleType}-mime-type" rule`);
145
+ if (!value.content)
146
+ return;
147
+ for (const mime of Object.keys(value.content)) {
148
+ if (!allowedValues.includes(mime)) {
149
+ report({
150
+ message: `Mime type "${mime}" is not allowed`,
151
+ location: location.child('content').child(mime).key(),
152
+ });
153
+ }
154
+ }
155
+ }
156
+ function readFileAsStringSync(filePath) {
157
+ return fs.readFileSync(filePath, 'utf-8');
158
+ }
159
+ function yamlAndJsonSyncReader(filePath) {
160
+ const content = fs.readFileSync(filePath, 'utf-8');
161
+ return (0, js_yaml_1.parseYaml)(content);
162
+ }
163
+ function isPathParameter(pathSegment) {
164
+ return pathSegment.startsWith('{') && pathSegment.endsWith('}');
165
+ }
166
+ /**
167
+ * Convert Windows backslash paths to slash paths: foo\\bar ➔ foo/bar
168
+ */
169
+ function slash(path) {
170
+ const isExtendedLengthPath = /^\\\\\?\\/.test(path);
171
+ if (isExtendedLengthPath) {
172
+ return path;
173
+ }
174
+ return path.replace(/\\/g, '/');
175
+ }
176
+ // TODO: use it everywhere
177
+ function isString(value) {
178
+ return typeof value === 'string';
179
+ }
180
+ function isNotString(value) {
181
+ return !isString(value);
182
+ }
183
+ const assignConfig = (target, obj) => {
184
+ if (!obj)
185
+ return;
186
+ for (const k of Object.keys(obj)) {
187
+ if (isPlainObject(target[k]) && typeof obj[k] === 'string') {
188
+ target[k].severity = obj[k];
189
+ }
190
+ else {
191
+ target[k] = obj[k];
192
+ }
193
+ }
194
+ };
195
+ exports.assignConfig = assignConfig;
196
+ function assignOnlyExistingConfig(target, obj) {
197
+ if (!obj)
198
+ return;
199
+ for (const k of Object.keys(obj)) {
200
+ if (!target.hasOwnProperty(k))
201
+ continue;
202
+ if (isPlainObject(target[k]) && typeof obj[k] === 'string') {
203
+ target[k].severity = obj[k];
204
+ }
205
+ else {
206
+ target[k] = obj[k];
207
+ }
208
+ }
209
+ }
210
+ function getMatchingStatusCodeRange(code) {
211
+ return `${code}`.replace(/^(\d)\d\d$/, (_, firstDigit) => `${firstDigit}XX`);
212
+ }
213
+ function isCustomRuleId(id) {
214
+ return id.includes('/');
215
+ }
216
+ function doesYamlFileExist(filePath) {
217
+ return (((0, path_1.extname)(filePath) === '.yaml' || (0, path_1.extname)(filePath) === '.yml') &&
218
+ fs?.hasOwnProperty?.('existsSync') &&
219
+ fs.existsSync(filePath));
220
+ }
221
+ function showWarningForDeprecatedField(deprecatedField, updatedField, updatedObject, link) {
222
+ const readMoreText = link ? `Read more about this change: ${link}` : '';
223
+ logger_1.logger.warn(`The '${logger_1.colorize.red(deprecatedField)}' field is deprecated. ${updatedField
224
+ ? `Use ${logger_1.colorize.green(getUpdatedFieldName(updatedField, updatedObject))} instead. `
225
+ : ''}${readMoreText}\n`);
226
+ }
227
+ function showErrorForDeprecatedField(deprecatedField, updatedField, updatedObject) {
228
+ throw new Error(`Do not use '${deprecatedField}' field. ${updatedField ? `Use '${getUpdatedFieldName(updatedField, updatedObject)}' instead. ` : ''}\n`);
229
+ }
230
+ function isTruthy(value) {
231
+ return !!value;
232
+ }
233
+ function identity(value) {
234
+ return value;
235
+ }
236
+ function keysOf(obj) {
237
+ if (!obj)
238
+ return [];
239
+ return Object.keys(obj);
240
+ }
241
+ function pickDefined(obj) {
242
+ if (!obj)
243
+ return undefined;
244
+ const res = {};
245
+ for (const key in obj) {
246
+ if (obj[key] !== undefined) {
247
+ res[key] = obj[key];
248
+ }
249
+ }
250
+ return res;
251
+ }
252
+ function nextTick() {
253
+ return new Promise((resolve) => {
254
+ setTimeout(resolve);
255
+ });
256
+ }
257
+ async function pause(ms) {
258
+ return new Promise((resolve) => setTimeout(resolve, ms));
259
+ }
260
+ function getUpdatedFieldName(updatedField, updatedObject) {
261
+ return `${typeof updatedObject !== 'undefined' ? `${updatedObject}.` : ''}${updatedField}`;
262
+ }
263
+ function getProxyAgent() {
264
+ const proxy = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
265
+ return proxy ? new https_proxy_agent_1.HttpsProxyAgent(proxy) : undefined;
266
+ }
267
+ /**
268
+ * Checks if two objects are deeply equal.
269
+ * Borrowed the source code from https://github.com/lukeed/dequal.
270
+ */
271
+ function dequal(foo, bar) {
272
+ let ctor, len;
273
+ if (foo === bar)
274
+ return true;
275
+ if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
276
+ if (ctor === Date)
277
+ return foo.getTime() === bar.getTime();
278
+ if (ctor === RegExp)
279
+ return foo.toString() === bar.toString();
280
+ if (ctor === Array) {
281
+ if ((len = foo.length) === bar.length) {
282
+ while (len-- && dequal(foo[len], bar[len]))
283
+ ;
284
+ }
285
+ return len === -1;
286
+ }
287
+ if (!ctor || typeof foo === 'object') {
288
+ len = 0;
289
+ for (ctor in foo) {
290
+ if (Object.prototype.hasOwnProperty.call(foo, ctor) &&
291
+ ++len &&
292
+ !Object.prototype.hasOwnProperty.call(bar, ctor))
293
+ return false;
294
+ if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor]))
295
+ return false;
296
+ }
297
+ return Object.keys(bar).length === len;
298
+ }
299
+ }
300
+ return foo !== foo && bar !== bar;
301
+ }