@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
package/lib/index.js ADDED
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.validate = exports.lint = exports.getTotals = exports.formatProblems = exports.getLineColLocation = exports.getAstNodeByPointer = exports.walkDocument = exports.normalizeVisitors = exports.getTypes = exports.detectSpec = exports.SpecVersion = exports.getMajorSpecVersion = exports.SpecMajorVersion = exports.isAbsoluteUrl = exports.isRef = exports.unescapePointer = exports.stringifyYaml = exports.parseYaml = exports.makeDocumentFromString = exports.YamlParseError = exports.ResolveError = exports.resolveDocument = exports.BaseResolver = exports.Source = exports.RedoclyClient = exports.createConfig = exports.CONFIG_FILE_NAMES = exports.findConfig = exports.getConfig = exports.loadConfig = exports.transformConfig = exports.getMergedConfig = exports.IGNORE_FILE = exports.StyleguideConfig = exports.Config = exports.Stats = exports.normalizeTypes = exports.ConfigTypes = exports.AsyncApi3Types = exports.AsyncApi2Types = exports.Oas2Types = exports.Oas3Types = exports.Arazzo1Types = exports.Oas3_1Types = exports.pause = exports.getProxyAgent = exports.isTruthy = exports.doesYamlFileExist = exports.slash = exports.readFileFromUrl = void 0;
18
+ exports.bundleFromString = exports.mapTypeToComponent = exports.bundleDocument = exports.bundle = exports.lintConfig = exports.lintFromString = exports.lintDocument = void 0;
19
+ var utils_1 = require("./utils");
20
+ Object.defineProperty(exports, "readFileFromUrl", { enumerable: true, get: function () { return utils_1.readFileFromUrl; } });
21
+ Object.defineProperty(exports, "slash", { enumerable: true, get: function () { return utils_1.slash; } });
22
+ Object.defineProperty(exports, "doesYamlFileExist", { enumerable: true, get: function () { return utils_1.doesYamlFileExist; } });
23
+ Object.defineProperty(exports, "isTruthy", { enumerable: true, get: function () { return utils_1.isTruthy; } });
24
+ Object.defineProperty(exports, "getProxyAgent", { enumerable: true, get: function () { return utils_1.getProxyAgent; } });
25
+ Object.defineProperty(exports, "pause", { enumerable: true, get: function () { return utils_1.pause; } });
26
+ var oas3_1_1 = require("./types/oas3_1");
27
+ Object.defineProperty(exports, "Oas3_1Types", { enumerable: true, get: function () { return oas3_1_1.Oas3_1Types; } });
28
+ var arazzo_1 = require("./types/arazzo");
29
+ Object.defineProperty(exports, "Arazzo1Types", { enumerable: true, get: function () { return arazzo_1.Arazzo1Types; } });
30
+ var oas3_1 = require("./types/oas3");
31
+ Object.defineProperty(exports, "Oas3Types", { enumerable: true, get: function () { return oas3_1.Oas3Types; } });
32
+ var oas2_1 = require("./types/oas2");
33
+ Object.defineProperty(exports, "Oas2Types", { enumerable: true, get: function () { return oas2_1.Oas2Types; } });
34
+ var asyncapi2_1 = require("./types/asyncapi2");
35
+ Object.defineProperty(exports, "AsyncApi2Types", { enumerable: true, get: function () { return asyncapi2_1.AsyncApi2Types; } });
36
+ var asyncapi3_1 = require("./types/asyncapi3");
37
+ Object.defineProperty(exports, "AsyncApi3Types", { enumerable: true, get: function () { return asyncapi3_1.AsyncApi3Types; } });
38
+ var redocly_yaml_1 = require("./types/redocly-yaml");
39
+ Object.defineProperty(exports, "ConfigTypes", { enumerable: true, get: function () { return redocly_yaml_1.ConfigTypes; } });
40
+ var types_1 = require("./types");
41
+ Object.defineProperty(exports, "normalizeTypes", { enumerable: true, get: function () { return types_1.normalizeTypes; } });
42
+ var stats_1 = require("./rules/other/stats");
43
+ Object.defineProperty(exports, "Stats", { enumerable: true, get: function () { return stats_1.Stats; } });
44
+ var config_1 = require("./config");
45
+ Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
46
+ Object.defineProperty(exports, "StyleguideConfig", { enumerable: true, get: function () { return config_1.StyleguideConfig; } });
47
+ Object.defineProperty(exports, "IGNORE_FILE", { enumerable: true, get: function () { return config_1.IGNORE_FILE; } });
48
+ Object.defineProperty(exports, "getMergedConfig", { enumerable: true, get: function () { return config_1.getMergedConfig; } });
49
+ Object.defineProperty(exports, "transformConfig", { enumerable: true, get: function () { return config_1.transformConfig; } });
50
+ Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_1.loadConfig; } });
51
+ Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_1.getConfig; } });
52
+ Object.defineProperty(exports, "findConfig", { enumerable: true, get: function () { return config_1.findConfig; } });
53
+ Object.defineProperty(exports, "CONFIG_FILE_NAMES", { enumerable: true, get: function () { return config_1.CONFIG_FILE_NAMES; } });
54
+ Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return config_1.createConfig; } });
55
+ var redocly_1 = require("./redocly");
56
+ Object.defineProperty(exports, "RedoclyClient", { enumerable: true, get: function () { return redocly_1.RedoclyClient; } });
57
+ __exportStar(require("./redocly/domains"), exports);
58
+ var resolve_1 = require("./resolve");
59
+ Object.defineProperty(exports, "Source", { enumerable: true, get: function () { return resolve_1.Source; } });
60
+ Object.defineProperty(exports, "BaseResolver", { enumerable: true, get: function () { return resolve_1.BaseResolver; } });
61
+ Object.defineProperty(exports, "resolveDocument", { enumerable: true, get: function () { return resolve_1.resolveDocument; } });
62
+ Object.defineProperty(exports, "ResolveError", { enumerable: true, get: function () { return resolve_1.ResolveError; } });
63
+ Object.defineProperty(exports, "YamlParseError", { enumerable: true, get: function () { return resolve_1.YamlParseError; } });
64
+ Object.defineProperty(exports, "makeDocumentFromString", { enumerable: true, get: function () { return resolve_1.makeDocumentFromString; } });
65
+ var js_yaml_1 = require("./js-yaml");
66
+ Object.defineProperty(exports, "parseYaml", { enumerable: true, get: function () { return js_yaml_1.parseYaml; } });
67
+ Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: function () { return js_yaml_1.stringifyYaml; } });
68
+ var ref_utils_1 = require("./ref-utils");
69
+ Object.defineProperty(exports, "unescapePointer", { enumerable: true, get: function () { return ref_utils_1.unescapePointer; } });
70
+ Object.defineProperty(exports, "isRef", { enumerable: true, get: function () { return ref_utils_1.isRef; } });
71
+ Object.defineProperty(exports, "isAbsoluteUrl", { enumerable: true, get: function () { return ref_utils_1.isAbsoluteUrl; } });
72
+ var oas_types_1 = require("./oas-types");
73
+ Object.defineProperty(exports, "SpecMajorVersion", { enumerable: true, get: function () { return oas_types_1.SpecMajorVersion; } });
74
+ Object.defineProperty(exports, "getMajorSpecVersion", { enumerable: true, get: function () { return oas_types_1.getMajorSpecVersion; } });
75
+ Object.defineProperty(exports, "SpecVersion", { enumerable: true, get: function () { return oas_types_1.SpecVersion; } });
76
+ Object.defineProperty(exports, "detectSpec", { enumerable: true, get: function () { return oas_types_1.detectSpec; } });
77
+ Object.defineProperty(exports, "getTypes", { enumerable: true, get: function () { return oas_types_1.getTypes; } });
78
+ var visitors_1 = require("./visitors");
79
+ Object.defineProperty(exports, "normalizeVisitors", { enumerable: true, get: function () { return visitors_1.normalizeVisitors; } });
80
+ var walk_1 = require("./walk");
81
+ Object.defineProperty(exports, "walkDocument", { enumerable: true, get: function () { return walk_1.walkDocument; } });
82
+ var codeframes_1 = require("./format/codeframes");
83
+ Object.defineProperty(exports, "getAstNodeByPointer", { enumerable: true, get: function () { return codeframes_1.getAstNodeByPointer; } });
84
+ Object.defineProperty(exports, "getLineColLocation", { enumerable: true, get: function () { return codeframes_1.getLineColLocation; } });
85
+ var format_1 = require("./format/format");
86
+ Object.defineProperty(exports, "formatProblems", { enumerable: true, get: function () { return format_1.formatProblems; } });
87
+ Object.defineProperty(exports, "getTotals", { enumerable: true, get: function () { return format_1.getTotals; } });
88
+ var lint_1 = require("./lint");
89
+ Object.defineProperty(exports, "lint", { enumerable: true, get: function () { return lint_1.lint; } });
90
+ Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return lint_1.lint; } });
91
+ Object.defineProperty(exports, "lintDocument", { enumerable: true, get: function () { return lint_1.lintDocument; } });
92
+ Object.defineProperty(exports, "lintFromString", { enumerable: true, get: function () { return lint_1.lintFromString; } });
93
+ Object.defineProperty(exports, "lintConfig", { enumerable: true, get: function () { return lint_1.lintConfig; } });
94
+ var bundle_1 = require("./bundle");
95
+ Object.defineProperty(exports, "bundle", { enumerable: true, get: function () { return bundle_1.bundle; } });
96
+ Object.defineProperty(exports, "bundleDocument", { enumerable: true, get: function () { return bundle_1.bundleDocument; } });
97
+ Object.defineProperty(exports, "mapTypeToComponent", { enumerable: true, get: function () { return bundle_1.mapTypeToComponent; } });
98
+ Object.defineProperty(exports, "bundleFromString", { enumerable: true, get: function () { return bundle_1.bundleFromString; } });
@@ -0,0 +1,3 @@
1
+ import type { LoadOptions, DumpOptions } from 'js-yaml';
2
+ export declare const parseYaml: (str: string, opts?: LoadOptions) => unknown;
3
+ export declare const stringifyYaml: (obj: any, opts?: DumpOptions) => string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringifyYaml = exports.parseYaml = void 0;
4
+ // TODO: add a type for "types" https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/js-yaml/index.d.ts
5
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
6
+ // @ts-ignore
7
+ const js_yaml_1 = require("js-yaml");
8
+ const DEFAULT_SCHEMA_WITHOUT_TIMESTAMP = js_yaml_1.JSON_SCHEMA.extend({
9
+ implicit: [js_yaml_1.types.merge],
10
+ explicit: [js_yaml_1.types.binary, js_yaml_1.types.omap, js_yaml_1.types.pairs, js_yaml_1.types.set],
11
+ });
12
+ const parseYaml = (str, opts) => (0, js_yaml_1.load)(str, { schema: DEFAULT_SCHEMA_WITHOUT_TIMESTAMP, ...opts });
13
+ exports.parseYaml = parseYaml;
14
+ const stringifyYaml = (obj, opts) => (0, js_yaml_1.dump)(obj, opts);
15
+ exports.stringifyYaml = stringifyYaml;
package/lib/lint.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { BaseResolver } from './resolve';
2
+ import type { StyleguideConfig, Config } from './config';
3
+ import type { Document, ResolvedRefMap } from './resolve';
4
+ import type { ProblemSeverity } from './walk';
5
+ import type { NodeType } from './types';
6
+ import type { CollectFn } from './utils';
7
+ export declare function lint(opts: {
8
+ ref: string;
9
+ config: Config;
10
+ externalRefResolver?: BaseResolver;
11
+ collectSpecData?: CollectFn;
12
+ }): Promise<import("./walk").NormalizedProblem[]>;
13
+ export declare function lintFromString(opts: {
14
+ source: string;
15
+ absoluteRef?: string;
16
+ config: Config;
17
+ externalRefResolver?: BaseResolver;
18
+ }): Promise<import("./walk").NormalizedProblem[]>;
19
+ export declare function lintDocument(opts: {
20
+ document: Document;
21
+ config: StyleguideConfig;
22
+ customTypes?: Record<string, NodeType>;
23
+ externalRefResolver: BaseResolver;
24
+ }): Promise<import("./walk").NormalizedProblem[]>;
25
+ export declare function lintConfig(opts: {
26
+ document: Document;
27
+ config: Config;
28
+ resolvedRefMap?: ResolvedRefMap;
29
+ severity?: ProblemSeverity;
30
+ externalRefResolver?: BaseResolver;
31
+ externalConfigTypes?: Record<string, NodeType>;
32
+ }): Promise<import("./walk").NormalizedProblem[]>;
package/lib/lint.js ADDED
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lint = lint;
4
+ exports.lintFromString = lintFromString;
5
+ exports.lintDocument = lintDocument;
6
+ exports.lintConfig = lintConfig;
7
+ const config_1 = require("@redocly/config");
8
+ const resolve_1 = require("./resolve");
9
+ const visitors_1 = require("./visitors");
10
+ const walk_1 = require("./walk");
11
+ const config_2 = require("./config");
12
+ const types_1 = require("./types");
13
+ const ajv_1 = require("./rules/ajv");
14
+ const oas_types_1 = require("./oas-types");
15
+ const redocly_yaml_1 = require("./types/redocly-yaml");
16
+ const struct_1 = require("./rules/common/struct");
17
+ const no_unresolved_refs_1 = require("./rules/no-unresolved-refs");
18
+ async function lint(opts) {
19
+ const { ref, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve) } = opts;
20
+ const document = (await externalRefResolver.resolveDocument(null, ref, true));
21
+ opts.collectSpecData?.(document.parsed);
22
+ return lintDocument({
23
+ document,
24
+ ...opts,
25
+ externalRefResolver,
26
+ config: opts.config.styleguide,
27
+ });
28
+ }
29
+ async function lintFromString(opts) {
30
+ const { source, absoluteRef, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve) } = opts;
31
+ const document = (0, resolve_1.makeDocumentFromString)(source, absoluteRef || '/');
32
+ return lintDocument({
33
+ document,
34
+ ...opts,
35
+ externalRefResolver,
36
+ config: opts.config.styleguide,
37
+ });
38
+ }
39
+ async function lintDocument(opts) {
40
+ (0, ajv_1.releaseAjvInstance)(); // FIXME: preprocessors can modify nodes which are then cached to ajv-instance by absolute path
41
+ const { document, customTypes, externalRefResolver, config } = opts;
42
+ const specVersion = (0, oas_types_1.detectSpec)(document.parsed);
43
+ const specMajorVersion = (0, oas_types_1.getMajorSpecVersion)(specVersion);
44
+ const rules = config.getRulesForSpecVersion(specMajorVersion);
45
+ const types = (0, types_1.normalizeTypes)(config.extendTypes(customTypes ?? (0, oas_types_1.getTypes)(specVersion), specVersion), config);
46
+ const ctx = {
47
+ problems: [],
48
+ oasVersion: specVersion,
49
+ visitorsData: {},
50
+ };
51
+ const preprocessors = (0, config_2.initRules)(rules, config, 'preprocessors', specVersion);
52
+ const regularRules = (0, config_2.initRules)(rules, config, 'rules', specVersion);
53
+ let resolvedRefMap = await (0, resolve_1.resolveDocument)({
54
+ rootDocument: document,
55
+ rootType: types.Root,
56
+ externalRefResolver,
57
+ });
58
+ if (preprocessors.length > 0) {
59
+ // Make additional pass to resolve refs defined in preprocessors.
60
+ (0, walk_1.walkDocument)({
61
+ document,
62
+ rootType: types.Root,
63
+ normalizedVisitors: (0, visitors_1.normalizeVisitors)(preprocessors, types),
64
+ resolvedRefMap,
65
+ ctx,
66
+ });
67
+ resolvedRefMap = await (0, resolve_1.resolveDocument)({
68
+ rootDocument: document,
69
+ rootType: types.Root,
70
+ externalRefResolver,
71
+ });
72
+ }
73
+ const normalizedVisitors = (0, visitors_1.normalizeVisitors)(regularRules, types);
74
+ (0, walk_1.walkDocument)({
75
+ document,
76
+ rootType: types.Root,
77
+ normalizedVisitors,
78
+ resolvedRefMap,
79
+ ctx,
80
+ });
81
+ return ctx.problems.map((problem) => config.addProblemToIgnore(problem));
82
+ }
83
+ async function lintConfig(opts) {
84
+ const { document, severity, externalRefResolver = new resolve_1.BaseResolver(), config } = opts;
85
+ const ctx = {
86
+ problems: [],
87
+ oasVersion: oas_types_1.SpecVersion.OAS3_0,
88
+ visitorsData: {},
89
+ };
90
+ const types = (0, types_1.normalizeTypes)(opts.externalConfigTypes || (0, redocly_yaml_1.createConfigTypes)(config_1.rootRedoclyConfigSchema, config), { doNotResolveExamples: config.styleguide.doNotResolveExamples });
91
+ const rules = [
92
+ {
93
+ severity: severity || 'error',
94
+ ruleId: 'configuration spec',
95
+ visitor: (0, struct_1.Struct)({ severity: 'error' }),
96
+ },
97
+ {
98
+ severity: severity || 'error',
99
+ ruleId: 'configuration no-unresolved-refs',
100
+ visitor: (0, no_unresolved_refs_1.NoUnresolvedRefs)({ severity: 'error' }),
101
+ },
102
+ ];
103
+ const normalizedVisitors = (0, visitors_1.normalizeVisitors)(rules, types);
104
+ const resolvedRefMap = opts.resolvedRefMap ||
105
+ (await (0, resolve_1.resolveDocument)({
106
+ rootDocument: document,
107
+ rootType: types.ConfigRoot,
108
+ externalRefResolver,
109
+ }));
110
+ (0, walk_1.walkDocument)({
111
+ document,
112
+ rootType: types.ConfigRoot,
113
+ normalizedVisitors,
114
+ resolvedRefMap,
115
+ ctx,
116
+ });
117
+ return ctx.problems;
118
+ }
@@ -0,0 +1,10 @@
1
+ import * as colorette from 'colorette';
2
+ export { options as colorOptions } from 'colorette';
3
+ export declare const colorize: typeof colorette;
4
+ declare class Logger {
5
+ protected stderr(str: string): boolean;
6
+ info(str: string): boolean | void;
7
+ warn(str: string): boolean | void;
8
+ error(str: string): boolean | void;
9
+ }
10
+ export declare const logger: Logger;
package/lib/logger.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logger = exports.colorize = exports.colorOptions = void 0;
4
+ const colorette = require("colorette");
5
+ const env_1 = require("./env");
6
+ const utils_1 = require("./utils");
7
+ var colorette_1 = require("colorette");
8
+ Object.defineProperty(exports, "colorOptions", { enumerable: true, get: function () { return colorette_1.options; } });
9
+ exports.colorize = new Proxy(colorette, {
10
+ get(target, prop) {
11
+ if (env_1.isBrowser) {
12
+ return utils_1.identity;
13
+ }
14
+ return target[prop];
15
+ },
16
+ });
17
+ class Logger {
18
+ stderr(str) {
19
+ return process.stderr.write(str);
20
+ }
21
+ info(str) {
22
+ return env_1.isBrowser ? console.log(str) : this.stderr(str);
23
+ }
24
+ warn(str) {
25
+ return env_1.isBrowser ? console.warn(str) : this.stderr(exports.colorize.yellow(str));
26
+ }
27
+ error(str) {
28
+ return env_1.isBrowser ? console.error(str) : this.stderr(exports.colorize.red(str));
29
+ }
30
+ }
31
+ exports.logger = new Logger();
@@ -0,0 +1,36 @@
1
+ import type { BuiltInAsync2RuleId, BuiltInAsync3RuleId, BuiltInArazzo1RuleId, BuiltInOAS2RuleId, BuiltInOAS3RuleId } from './types/redocly-yaml';
2
+ import type { Oas3Rule, Oas3Preprocessor, Oas2Rule, Oas2Preprocessor, Async2Preprocessor, Async2Rule, Async3Preprocessor, Async3Rule, Arazzo1Preprocessor, Arazzo1Rule } from './visitors';
3
+ export declare enum SpecVersion {
4
+ OAS2 = "oas2",
5
+ OAS3_0 = "oas3_0",
6
+ OAS3_1 = "oas3_1",
7
+ Async2 = "async2",
8
+ Async3 = "async3",
9
+ Arazzo1 = "arazzo1"
10
+ }
11
+ export declare enum SpecMajorVersion {
12
+ OAS2 = "oas2",
13
+ OAS3 = "oas3",
14
+ Async2 = "async2",
15
+ Async3 = "async3",
16
+ Arazzo1 = "arazzo1"
17
+ }
18
+ export type RuleMap<Key extends string, RuleConfig, T> = Record<T extends 'built-in' ? Key : string, RuleConfig>;
19
+ export type Oas3RuleSet<T = undefined> = RuleMap<BuiltInOAS3RuleId | 'struct' | 'assertions', Oas3Rule, T>;
20
+ export type Oas2RuleSet<T = undefined> = RuleMap<BuiltInOAS2RuleId | 'struct' | 'assertions', Oas2Rule, T>;
21
+ export type Async2RuleSet<T = undefined> = RuleMap<BuiltInAsync2RuleId | 'struct' | 'assertions', Async2Rule, T>;
22
+ export type Async3RuleSet<T = undefined> = RuleMap<BuiltInAsync3RuleId | 'struct' | 'assertions', Async3Rule, T>;
23
+ export type Arazzo1RuleSet<T = undefined> = RuleMap<BuiltInArazzo1RuleId | 'struct' | 'assertions', Arazzo1Rule, T>;
24
+ export type Oas3PreprocessorsSet = Record<string, Oas3Preprocessor>;
25
+ export type Oas2PreprocessorsSet = Record<string, Oas2Preprocessor>;
26
+ export type Async2PreprocessorsSet = Record<string, Async2Preprocessor>;
27
+ export type Async3PreprocessorsSet = Record<string, Async3Preprocessor>;
28
+ export type Arazzo1PreprocessorsSet = Record<string, Arazzo1Preprocessor>;
29
+ export type Oas3DecoratorsSet = Record<string, Oas3Preprocessor>;
30
+ export type Oas2DecoratorsSet = Record<string, Oas2Preprocessor>;
31
+ export type Async2DecoratorsSet = Record<string, Async2Preprocessor>;
32
+ export type Async3DecoratorsSet = Record<string, Async3Preprocessor>;
33
+ export type Arazzo1DecoratorsSet = Record<string, Arazzo1Preprocessor>;
34
+ export declare function detectSpec(root: unknown): SpecVersion;
35
+ export declare function getMajorSpecVersion(version: SpecVersion): SpecMajorVersion;
36
+ export declare function getTypes(spec: SpecVersion): Record<string, import("./types").NodeType> | Record<"Root" | "Tag" | "TagList" | "ExternalDocs" | "SecurityRequirement" | "SecurityRequirementList" | "Info" | "Contact" | "License" | "Paths" | "PathItem" | "Parameter" | "ParameterList" | "ParameterItems" | "Operation" | "Example" | "ExamplesMap" | "Examples" | "Header" | "Responses" | "Response" | "Schema" | "Xml" | "SchemaProperties" | "NamedSchemas" | "NamedResponses" | "NamedParameters" | "NamedSecuritySchemes" | "SecurityScheme" | "TagGroup" | "TagGroups" | "EnumDescriptions" | "Logo" | "XCodeSample" | "XCodeSampleList" | "XServer" | "XServerList", import("./types").NodeType> | Record<"Root" | "Tag" | "TagList" | "ExternalDocs" | "SecurityRequirement" | "SecurityRequirementList" | "Info" | "Contact" | "License" | "Paths" | "PathItem" | "Parameter" | "ParameterList" | "Operation" | "Example" | "ExamplesMap" | "Header" | "Responses" | "Response" | "Schema" | "Xml" | "SchemaProperties" | "NamedSchemas" | "NamedResponses" | "NamedParameters" | "NamedSecuritySchemes" | "SecurityScheme" | "TagGroup" | "TagGroups" | "EnumDescriptions" | "Logo" | "XCodeSample" | "XCodeSampleList" | "Server" | "ServerList" | "ServerVariable" | "ServerVariablesMap" | "Callback" | "CallbacksMap" | "RequestBody" | "MediaTypesMap" | "MediaType" | "Encoding" | "EncodingMap" | "HeadersMap" | "Link" | "LinksMap" | "DiscriminatorMapping" | "Discriminator" | "Components" | "NamedExamples" | "NamedRequestBodies" | "NamedHeaders" | "NamedLinks" | "NamedCallbacks" | "ImplicitFlow" | "PasswordFlow" | "ClientCredentials" | "AuthorizationCode" | "OAuth2Flows" | "XUsePkce" | "WebhooksMap", import("./types").NodeType> | Record<"Root" | "Info" | "License" | "Operation" | "Schema" | "SchemaProperties" | "SecurityScheme" | "Components" | "PatternProperties" | "NamedPathItems" | "DependentRequired", import("./types").NodeType>;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpecMajorVersion = exports.SpecVersion = void 0;
4
+ exports.detectSpec = detectSpec;
5
+ exports.getMajorSpecVersion = getMajorSpecVersion;
6
+ exports.getTypes = getTypes;
7
+ const oas2_1 = require("./types/oas2");
8
+ const oas3_1 = require("./types/oas3");
9
+ const oas3_1_1 = require("./types/oas3_1");
10
+ const asyncapi2_1 = require("./types/asyncapi2");
11
+ const asyncapi3_1 = require("./types/asyncapi3");
12
+ const arazzo_1 = require("./types/arazzo");
13
+ const utils_1 = require("./utils");
14
+ const arazzo_2 = require("./typings/arazzo");
15
+ var SpecVersion;
16
+ (function (SpecVersion) {
17
+ SpecVersion["OAS2"] = "oas2";
18
+ SpecVersion["OAS3_0"] = "oas3_0";
19
+ SpecVersion["OAS3_1"] = "oas3_1";
20
+ SpecVersion["Async2"] = "async2";
21
+ SpecVersion["Async3"] = "async3";
22
+ SpecVersion["Arazzo1"] = "arazzo1";
23
+ })(SpecVersion || (exports.SpecVersion = SpecVersion = {}));
24
+ var SpecMajorVersion;
25
+ (function (SpecMajorVersion) {
26
+ SpecMajorVersion["OAS2"] = "oas2";
27
+ SpecMajorVersion["OAS3"] = "oas3";
28
+ SpecMajorVersion["Async2"] = "async2";
29
+ SpecMajorVersion["Async3"] = "async3";
30
+ SpecMajorVersion["Arazzo1"] = "arazzo1";
31
+ })(SpecMajorVersion || (exports.SpecMajorVersion = SpecMajorVersion = {}));
32
+ const typesMap = {
33
+ [SpecVersion.OAS2]: oas2_1.Oas2Types,
34
+ [SpecVersion.OAS3_0]: oas3_1.Oas3Types,
35
+ [SpecVersion.OAS3_1]: oas3_1_1.Oas3_1Types,
36
+ [SpecVersion.Async2]: asyncapi2_1.AsyncApi2Types,
37
+ [SpecVersion.Async3]: asyncapi3_1.AsyncApi3Types,
38
+ [SpecVersion.Arazzo1]: arazzo_1.Arazzo1Types,
39
+ };
40
+ function detectSpec(root) {
41
+ if (!(0, utils_1.isPlainObject)(root)) {
42
+ throw new Error(`Document must be JSON object, got ${typeof root}`);
43
+ }
44
+ if (root.openapi && typeof root.openapi !== 'string') {
45
+ throw new Error(`Invalid OpenAPI version: should be a string but got "${typeof root.openapi}"`);
46
+ }
47
+ if (typeof root.openapi === 'string' && root.openapi.startsWith('3.0')) {
48
+ return SpecVersion.OAS3_0;
49
+ }
50
+ if (typeof root.openapi === 'string' && root.openapi.startsWith('3.1')) {
51
+ return SpecVersion.OAS3_1;
52
+ }
53
+ if (root.swagger && root.swagger === '2.0') {
54
+ return SpecVersion.OAS2;
55
+ }
56
+ if (root.openapi || root.swagger) {
57
+ throw new Error(`Unsupported OpenAPI version: ${root.openapi || root.swagger}`);
58
+ }
59
+ if (typeof root.asyncapi === 'string' && root.asyncapi.startsWith('2.')) {
60
+ return SpecVersion.Async2;
61
+ }
62
+ if (typeof root.asyncapi === 'string' && root.asyncapi.startsWith('3.')) {
63
+ return SpecVersion.Async3;
64
+ }
65
+ if (root.asyncapi) {
66
+ throw new Error(`Unsupported AsyncAPI version: ${root.asyncapi}`);
67
+ }
68
+ if (typeof root.arazzo === 'string' && arazzo_2.VERSION_PATTERN.test(root.arazzo)) {
69
+ return SpecVersion.Arazzo1;
70
+ }
71
+ throw new Error(`Unsupported specification`);
72
+ }
73
+ function getMajorSpecVersion(version) {
74
+ if (version === SpecVersion.OAS2) {
75
+ return SpecMajorVersion.OAS2;
76
+ }
77
+ else if (version === SpecVersion.Async2) {
78
+ return SpecMajorVersion.Async2;
79
+ }
80
+ else if (version === SpecVersion.Async3) {
81
+ return SpecMajorVersion.Async3;
82
+ }
83
+ else if (version === SpecVersion.Arazzo1) {
84
+ return SpecMajorVersion.Arazzo1;
85
+ }
86
+ else {
87
+ return SpecMajorVersion.OAS3;
88
+ }
89
+ }
90
+ function getTypes(spec) {
91
+ return typesMap[spec];
92
+ }
@@ -0,0 +1,3 @@
1
+ export declare const output: {
2
+ write(str: string): boolean | undefined;
3
+ };
package/lib/output.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.output = void 0;
4
+ const env_1 = require("./env");
5
+ exports.output = {
6
+ write(str) {
7
+ return env_1.isBrowser ? undefined : process.stdout.write(str);
8
+ },
9
+ };
@@ -0,0 +1,14 @@
1
+ import type { Region } from '../config/types';
2
+ export declare const DEFAULT_REGION = "us";
3
+ export declare const DOMAINS: {
4
+ us: string;
5
+ eu: string;
6
+ };
7
+ export declare const AVAILABLE_REGIONS: Region[];
8
+ export declare function getDomains(): {
9
+ us: string;
10
+ eu: string;
11
+ };
12
+ export declare function setRedoclyDomain(domain: string): void;
13
+ export declare function getRedoclyDomain(): string;
14
+ export declare function isRedoclyRegistryURL(link: string): boolean;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AVAILABLE_REGIONS = exports.DOMAINS = exports.DEFAULT_REGION = void 0;
4
+ exports.getDomains = getDomains;
5
+ exports.setRedoclyDomain = setRedoclyDomain;
6
+ exports.getRedoclyDomain = getRedoclyDomain;
7
+ exports.isRedoclyRegistryURL = isRedoclyRegistryURL;
8
+ let redoclyDomain = 'redocly.com';
9
+ exports.DEFAULT_REGION = 'us';
10
+ exports.DOMAINS = getDomains();
11
+ exports.AVAILABLE_REGIONS = Object.keys(exports.DOMAINS);
12
+ function getDomains() {
13
+ const domains = {
14
+ us: 'redocly.com',
15
+ eu: 'eu.redocly.com',
16
+ };
17
+ // FIXME: temporary fix for our lab environments
18
+ const domain = redoclyDomain;
19
+ if (domain?.endsWith('.redocly.host')) {
20
+ domains[domain.split('.')[0]] = domain;
21
+ }
22
+ if (domain === 'redoc.online') {
23
+ domains[domain] = domain;
24
+ }
25
+ return domains;
26
+ }
27
+ function setRedoclyDomain(domain) {
28
+ redoclyDomain = domain;
29
+ }
30
+ function getRedoclyDomain() {
31
+ return redoclyDomain;
32
+ }
33
+ function isRedoclyRegistryURL(link) {
34
+ const domain = getRedoclyDomain() || exports.DOMAINS[exports.DEFAULT_REGION];
35
+ const legacyDomain = domain === 'redocly.com' ? 'redoc.ly' : domain;
36
+ if (!link.startsWith(`https://api.${domain}/registry/`) &&
37
+ !link.startsWith(`https://api.${legacyDomain}/registry/`)) {
38
+ return false;
39
+ }
40
+ return true;
41
+ }
@@ -0,0 +1,30 @@
1
+ import { RegistryApi } from './registry-api';
2
+ import type { RegionalToken, RegionalTokenWithValidity } from './redocly-client-types';
3
+ import type { AccessTokens, Region } from '../config/types';
4
+ export declare const TOKEN_FILENAME = ".redocly-config.json";
5
+ export declare class RedoclyClient {
6
+ private accessTokens;
7
+ private region;
8
+ domain: string;
9
+ registryApi: RegistryApi;
10
+ constructor(region?: Region);
11
+ loadRegion(region?: Region): Region;
12
+ getRegion(): Region;
13
+ hasTokens(): boolean;
14
+ hasToken(): boolean;
15
+ getAuthorizationHeader(): Promise<string | undefined>;
16
+ setAccessTokens(accessTokens: AccessTokens): void;
17
+ loadTokens(): void;
18
+ getAllTokens(): RegionalToken[];
19
+ getValidTokens(): Promise<RegionalTokenWithValidity[]>;
20
+ getTokens(): Promise<RegionalTokenWithValidity[]>;
21
+ isAuthorizedWithRedoclyByRegion(): Promise<boolean>;
22
+ isAuthorizedWithRedocly(): Promise<boolean>;
23
+ readCredentialsFile(credentialsPath: string): any;
24
+ verifyToken(accessToken: string, verbose?: boolean): Promise<{
25
+ viewerId: string;
26
+ organizations: string[];
27
+ }>;
28
+ login(accessToken: string, verbose?: boolean): Promise<void>;
29
+ logout(): void;
30
+ }