@redocly/openapi-core 1.0.0-beta.125 → 1.0.0-beta.127

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 (281) hide show
  1. package/lib/bundle.js +5 -2
  2. package/lib/config/all.js +8 -1
  3. package/lib/resolve.js +5 -1
  4. package/lib/rules/common/required-string-property-missing-min-length.d.ts +1 -1
  5. package/lib/rules/common/required-string-property-missing-min-length.js +3 -3
  6. package/lib/rules/common/spec.js +1 -0
  7. package/lib/rules/oas2/index.js +1 -1
  8. package/lib/rules/oas2/request-mime-type.d.ts +1 -1
  9. package/lib/rules/oas2/response-mime-type.d.ts +1 -1
  10. package/lib/rules/oas3/index.js +1 -1
  11. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +2 -2
  12. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +3 -3
  13. package/lib/rules/oas3/request-mime-type.d.ts +1 -1
  14. package/lib/rules/oas3/response-mime-type.d.ts +1 -1
  15. package/lib/walk.d.ts +6 -5
  16. package/lib/walk.js +23 -27
  17. package/package.json +1 -1
  18. package/__tests__/utils.ts +0 -88
  19. package/src/__tests__/__snapshots__/bundle.test.ts.snap +0 -437
  20. package/src/__tests__/bundle.test.ts +0 -236
  21. package/src/__tests__/codeframes.test.ts +0 -530
  22. package/src/__tests__/fixtures/.redocly.lint-ignore.yaml +0 -5
  23. package/src/__tests__/fixtures/extension.js +0 -24
  24. package/src/__tests__/fixtures/refs/definitions.yaml +0 -3
  25. package/src/__tests__/fixtures/refs/examples.yaml +0 -8
  26. package/src/__tests__/fixtures/refs/external-request-body.yaml +0 -13
  27. package/src/__tests__/fixtures/refs/externalref.yaml +0 -35
  28. package/src/__tests__/fixtures/refs/hosted.yaml +0 -35
  29. package/src/__tests__/fixtures/refs/openapi-with-external-refs-conflicting-names.yaml +0 -21
  30. package/src/__tests__/fixtures/refs/openapi-with-external-refs.yaml +0 -33
  31. package/src/__tests__/fixtures/refs/openapi-with-url-refs.yaml +0 -18
  32. package/src/__tests__/fixtures/refs/param-b.yaml +0 -1
  33. package/src/__tests__/fixtures/refs/param-c.yaml +0 -1
  34. package/src/__tests__/fixtures/refs/rename.yaml +0 -1
  35. package/src/__tests__/fixtures/refs/requestBody.yaml +0 -9
  36. package/src/__tests__/fixtures/refs/schema-a.yaml +0 -1
  37. package/src/__tests__/fixtures/refs/simple.yaml +0 -1
  38. package/src/__tests__/fixtures/refs/vendor.schema.yaml +0 -20
  39. package/src/__tests__/fixtures/resolve/External.yaml +0 -10
  40. package/src/__tests__/fixtures/resolve/External2.yaml +0 -4
  41. package/src/__tests__/fixtures/resolve/description.md +0 -3
  42. package/src/__tests__/fixtures/resolve/externalInfo.yaml +0 -4
  43. package/src/__tests__/fixtures/resolve/externalLicense.yaml +0 -1
  44. package/src/__tests__/fixtures/resolve/openapi-with-back.yaml +0 -13
  45. package/src/__tests__/fixtures/resolve/openapi-with-md-description.yaml +0 -5
  46. package/src/__tests__/fixtures/resolve/openapi.yaml +0 -28
  47. package/src/__tests__/fixtures/resolve/schemas/type-a.yaml +0 -10
  48. package/src/__tests__/fixtures/resolve/schemas/type-b.yaml +0 -6
  49. package/src/__tests__/fixtures/resolve/transitive/a.yaml +0 -1
  50. package/src/__tests__/fixtures/resolve/transitive/components.yaml +0 -5
  51. package/src/__tests__/fixtures/resolve/transitive/schemas.yaml +0 -3
  52. package/src/__tests__/format.test.ts +0 -76
  53. package/src/__tests__/js-yaml.test.ts +0 -73
  54. package/src/__tests__/lint.test.ts +0 -388
  55. package/src/__tests__/logger-browser.test.ts +0 -53
  56. package/src/__tests__/logger.test.ts +0 -47
  57. package/src/__tests__/login.test.ts +0 -17
  58. package/src/__tests__/normalizeVisitors.test.ts +0 -151
  59. package/src/__tests__/output-browser.test.ts +0 -18
  60. package/src/__tests__/output.test.ts +0 -15
  61. package/src/__tests__/ref-utils.test.ts +0 -120
  62. package/src/__tests__/resolve-http.test.ts +0 -77
  63. package/src/__tests__/resolve.test.ts +0 -408
  64. package/src/__tests__/utils-browser.test.ts +0 -11
  65. package/src/__tests__/utils.test.ts +0 -144
  66. package/src/__tests__/walk.test.ts +0 -1545
  67. package/src/benchmark/benches/lint-with-many-rules.bench.ts +0 -35
  68. package/src/benchmark/benches/lint-with-nested-rule.bench.ts +0 -39
  69. package/src/benchmark/benches/lint-with-no-rules.bench.ts +0 -20
  70. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +0 -35
  71. package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +0 -32
  72. package/src/benchmark/benches/rebilly.yaml +0 -32275
  73. package/src/benchmark/benches/recommended-oas3.bench.ts +0 -22
  74. package/src/benchmark/benches/resolve-with-no-external.bench.ts +0 -23
  75. package/src/benchmark/benchmark.js +0 -311
  76. package/src/benchmark/colors.js +0 -29
  77. package/src/benchmark/fork.js +0 -83
  78. package/src/benchmark/utils.ts +0 -36
  79. package/src/bundle.ts +0 -399
  80. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +0 -161
  81. package/src/config/__tests__/__snapshots__/config.test.ts.snap +0 -144
  82. package/src/config/__tests__/config-resolvers.test.ts +0 -491
  83. package/src/config/__tests__/config.test.ts +0 -307
  84. package/src/config/__tests__/fixtures/ingore-file.ts +0 -8
  85. package/src/config/__tests__/fixtures/load-redocly.yaml +0 -2
  86. package/src/config/__tests__/fixtures/plugin-config.yaml +0 -2
  87. package/src/config/__tests__/fixtures/plugin.js +0 -56
  88. package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +0 -11
  89. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +0 -69
  90. package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +0 -7
  91. package/src/config/__tests__/fixtures/resolve-config/local-config-with-custom-function.yaml +0 -17
  92. package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +0 -18
  93. package/src/config/__tests__/fixtures/resolve-config/local-config-with-wrong-custom-function.yaml +0 -15
  94. package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +0 -9
  95. package/src/config/__tests__/fixtures/resolve-config/plugin.js +0 -80
  96. package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +0 -3
  97. package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +0 -4
  98. package/src/config/__tests__/load.test.ts +0 -167
  99. package/src/config/__tests__/resolve-plugins.test.ts +0 -27
  100. package/src/config/__tests__/utils.test.ts +0 -204
  101. package/src/config/all.ts +0 -66
  102. package/src/config/builtIn.ts +0 -37
  103. package/src/config/config-resolvers.ts +0 -465
  104. package/src/config/config.ts +0 -330
  105. package/src/config/index.ts +0 -7
  106. package/src/config/load.ts +0 -144
  107. package/src/config/minimal.ts +0 -60
  108. package/src/config/recommended.ts +0 -60
  109. package/src/config/rules.ts +0 -54
  110. package/src/config/types.ts +0 -216
  111. package/src/config/utils.ts +0 -333
  112. package/src/decorators/__tests__/filter-in.test.ts +0 -310
  113. package/src/decorators/__tests__/filter-out.test.ts +0 -335
  114. package/src/decorators/__tests__/media-type-examples-override.test.ts +0 -665
  115. package/src/decorators/__tests__/remove-x-internal.test.ts +0 -316
  116. package/src/decorators/__tests__/resources/request.yaml +0 -3
  117. package/src/decorators/__tests__/resources/response.yaml +0 -3
  118. package/src/decorators/common/filters/filter-helper.ts +0 -72
  119. package/src/decorators/common/filters/filter-in.ts +0 -18
  120. package/src/decorators/common/filters/filter-out.ts +0 -18
  121. package/src/decorators/common/info-description-override.ts +0 -24
  122. package/src/decorators/common/info-override.ts +0 -15
  123. package/src/decorators/common/media-type-examples-override.ts +0 -79
  124. package/src/decorators/common/operation-description-override.ts +0 -30
  125. package/src/decorators/common/registry-dependencies.ts +0 -25
  126. package/src/decorators/common/remove-x-internal.ts +0 -59
  127. package/src/decorators/common/tag-description-override.ts +0 -25
  128. package/src/decorators/oas2/index.ts +0 -20
  129. package/src/decorators/oas3/index.ts +0 -22
  130. package/src/env.ts +0 -5
  131. package/src/format/codeframes.ts +0 -216
  132. package/src/format/format.ts +0 -375
  133. package/src/index.ts +0 -71
  134. package/src/js-yaml/index.ts +0 -14
  135. package/src/lint.ts +0 -130
  136. package/src/logger.ts +0 -34
  137. package/src/oas-types.ts +0 -57
  138. package/src/output.ts +0 -7
  139. package/src/redocly/__tests__/redocly-client.test.ts +0 -146
  140. package/src/redocly/index.ts +0 -187
  141. package/src/redocly/redocly-client-types.ts +0 -10
  142. package/src/redocly/registry-api-types.ts +0 -32
  143. package/src/redocly/registry-api.ts +0 -149
  144. package/src/ref-utils.ts +0 -85
  145. package/src/resolve.ts +0 -412
  146. package/src/rules/__tests__/fixtures/code-sample.php +0 -9
  147. package/src/rules/__tests__/fixtures/invalid-yaml.yaml +0 -1
  148. package/src/rules/__tests__/fixtures/ref.yaml +0 -1
  149. package/src/rules/__tests__/no-unresolved-refs.test.ts +0 -257
  150. package/src/rules/__tests__/utils.test.ts +0 -160
  151. package/src/rules/ajv.ts +0 -102
  152. package/src/rules/common/__tests__/info-license.test.ts +0 -62
  153. package/src/rules/common/__tests__/license-url.test.ts +0 -63
  154. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +0 -96
  155. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +0 -210
  156. package/src/rules/common/__tests__/no-identical-paths.test.ts +0 -58
  157. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +0 -85
  158. package/src/rules/common/__tests__/operation-2xx-response.test.ts +0 -192
  159. package/src/rules/common/__tests__/operation-4xx-response.test.ts +0 -231
  160. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +0 -76
  161. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +0 -45
  162. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +0 -167
  163. package/src/rules/common/__tests__/operation-singular-tag.test.ts +0 -72
  164. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +0 -95
  165. package/src/rules/common/__tests__/path-not-include-query.test.ts +0 -64
  166. package/src/rules/common/__tests__/path-params-defined.test.ts +0 -202
  167. package/src/rules/common/__tests__/paths-kebab-case.test.ts +0 -108
  168. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +0 -264
  169. package/src/rules/common/__tests__/security-defined.test.ts +0 -175
  170. package/src/rules/common/__tests__/spec.test.ts +0 -555
  171. package/src/rules/common/__tests__/tag-description.test.ts +0 -65
  172. package/src/rules/common/__tests__/tags-alphabetical.test.ts +0 -64
  173. package/src/rules/common/assertions/__tests__/asserts.test.ts +0 -869
  174. package/src/rules/common/assertions/__tests__/index.test.ts +0 -100
  175. package/src/rules/common/assertions/__tests__/utils.test.ts +0 -236
  176. package/src/rules/common/assertions/asserts.ts +0 -357
  177. package/src/rules/common/assertions/index.ts +0 -56
  178. package/src/rules/common/assertions/utils.ts +0 -331
  179. package/src/rules/common/info-contact.ts +0 -15
  180. package/src/rules/common/info-license-url.ts +0 -10
  181. package/src/rules/common/info-license.ts +0 -15
  182. package/src/rules/common/no-ambiguous-paths.ts +0 -50
  183. package/src/rules/common/no-enum-type-mismatch.ts +0 -52
  184. package/src/rules/common/no-http-verbs-in-paths.ts +0 -36
  185. package/src/rules/common/no-identical-paths.ts +0 -24
  186. package/src/rules/common/no-invalid-parameter-examples.ts +0 -36
  187. package/src/rules/common/no-invalid-schema-examples.ts +0 -27
  188. package/src/rules/common/no-path-trailing-slash.ts +0 -15
  189. package/src/rules/common/operation-2xx-response.ts +0 -24
  190. package/src/rules/common/operation-4xx-response.ts +0 -24
  191. package/src/rules/common/operation-description.ts +0 -13
  192. package/src/rules/common/operation-operationId-unique.ts +0 -21
  193. package/src/rules/common/operation-operationId-url-safe.ts +0 -19
  194. package/src/rules/common/operation-operationId.ts +0 -17
  195. package/src/rules/common/operation-parameters-unique.ts +0 -48
  196. package/src/rules/common/operation-singular-tag.ts +0 -17
  197. package/src/rules/common/operation-summary.ts +0 -13
  198. package/src/rules/common/operation-tag-defined.ts +0 -26
  199. package/src/rules/common/parameter-description.ts +0 -22
  200. package/src/rules/common/path-declaration-must-exist.ts +0 -15
  201. package/src/rules/common/path-excludes-patterns.ts +0 -23
  202. package/src/rules/common/path-http-verbs-order.ts +0 -30
  203. package/src/rules/common/path-not-include-query.ts +0 -17
  204. package/src/rules/common/path-params-defined.ts +0 -65
  205. package/src/rules/common/path-segment-plural.ts +0 -31
  206. package/src/rules/common/paths-kebab-case.ts +0 -19
  207. package/src/rules/common/required-string-property-missing-min-length.ts +0 -44
  208. package/src/rules/common/response-contains-header.ts +0 -35
  209. package/src/rules/common/scalar-property-missing-example.ts +0 -58
  210. package/src/rules/common/security-defined.ts +0 -65
  211. package/src/rules/common/spec.ts +0 -174
  212. package/src/rules/common/tag-description.ts +0 -10
  213. package/src/rules/common/tags-alphabetical.ts +0 -20
  214. package/src/rules/no-unresolved-refs.ts +0 -51
  215. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +0 -110
  216. package/src/rules/oas2/__tests__/response-contains-header.test.ts +0 -174
  217. package/src/rules/oas2/__tests__/response-contains-property.test.ts +0 -155
  218. package/src/rules/oas2/__tests__/spec/fixtures/description.md +0 -1
  219. package/src/rules/oas2/__tests__/spec/info.test.ts +0 -355
  220. package/src/rules/oas2/__tests__/spec/operation.test.ts +0 -123
  221. package/src/rules/oas2/__tests__/spec/paths.test.ts +0 -245
  222. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +0 -35
  223. package/src/rules/oas2/__tests__/spec/utils.ts +0 -32
  224. package/src/rules/oas2/boolean-parameter-prefixes.ts +0 -26
  225. package/src/rules/oas2/index.ts +0 -89
  226. package/src/rules/oas2/remove-unused-components.ts +0 -81
  227. package/src/rules/oas2/request-mime-type.ts +0 -17
  228. package/src/rules/oas2/response-contains-property.ts +0 -36
  229. package/src/rules/oas2/response-mime-type.ts +0 -17
  230. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +0 -111
  231. package/src/rules/oas3/__tests__/fixtures/common.yaml +0 -11
  232. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +0 -205
  233. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +0 -65
  234. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +0 -473
  235. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +0 -60
  236. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +0 -79
  237. package/src/rules/oas3/__tests__/no-unused-components.test.ts +0 -131
  238. package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +0 -145
  239. package/src/rules/oas3/__tests__/response-contains-header.test.ts +0 -389
  240. package/src/rules/oas3/__tests__/response-contains-property.test.ts +0 -403
  241. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +0 -41
  242. package/src/rules/oas3/__tests__/spec/fixtures/description.md +0 -1
  243. package/src/rules/oas3/__tests__/spec/info.test.ts +0 -391
  244. package/src/rules/oas3/__tests__/spec/operation.test.ts +0 -253
  245. package/src/rules/oas3/__tests__/spec/paths.test.ts +0 -284
  246. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +0 -77
  247. package/src/rules/oas3/__tests__/spec/servers.test.ts +0 -505
  248. package/src/rules/oas3/__tests__/spec/spec.test.ts +0 -298
  249. package/src/rules/oas3/__tests__/spec/utils.ts +0 -32
  250. package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +0 -305
  251. package/src/rules/oas3/boolean-parameter-prefixes.ts +0 -28
  252. package/src/rules/oas3/index.ts +0 -109
  253. package/src/rules/oas3/no-empty-servers.ts +0 -22
  254. package/src/rules/oas3/no-example-value-and-externalValue.ts +0 -14
  255. package/src/rules/oas3/no-invalid-media-type-examples.ts +0 -49
  256. package/src/rules/oas3/no-server-example.com.ts +0 -14
  257. package/src/rules/oas3/no-server-trailing-slash.ts +0 -15
  258. package/src/rules/oas3/no-server-variables-empty-enum.ts +0 -66
  259. package/src/rules/oas3/no-undefined-server-variable.ts +0 -30
  260. package/src/rules/oas3/no-unused-components.ts +0 -75
  261. package/src/rules/oas3/operation-4xx-problem-details-rfc7807.ts +0 -36
  262. package/src/rules/oas3/remove-unused-components.ts +0 -95
  263. package/src/rules/oas3/request-mime-type.ts +0 -31
  264. package/src/rules/oas3/response-contains-property.ts +0 -38
  265. package/src/rules/oas3/response-mime-type.ts +0 -31
  266. package/src/rules/oas3/spec-components-invalid-map-name.ts +0 -74
  267. package/src/rules/other/stats.ts +0 -73
  268. package/src/rules/utils.ts +0 -191
  269. package/src/types/index.ts +0 -149
  270. package/src/types/oas2.ts +0 -478
  271. package/src/types/oas3.ts +0 -597
  272. package/src/types/oas3_1.ts +0 -258
  273. package/src/types/redocly-yaml.ts +0 -1010
  274. package/src/typings/common.ts +0 -17
  275. package/src/typings/openapi.ts +0 -298
  276. package/src/typings/swagger.ts +0 -236
  277. package/src/utils.ts +0 -276
  278. package/src/visitors.ts +0 -491
  279. package/src/walk.ts +0 -453
  280. package/tsconfig.json +0 -8
  281. package/tsconfig.tsbuildinfo +0 -1
@@ -1,22 +0,0 @@
1
- import { readFileSync } from 'fs';
2
- import { join as pathJoin, resolve as pathResolve } from 'path';
3
- import { lintDocument } from '../../lint';
4
- import { StyleguideConfig, defaultPlugin, resolvePreset } from '../../config';
5
- import { BaseResolver } from '../../resolve';
6
- import { parseYamlToDocument } from '../utils';
7
-
8
- export const name = 'Validate with recommended rules';
9
- export const count = 10;
10
- const rebillyDefinitionRef = pathResolve(pathJoin(__dirname, 'rebilly.yaml'));
11
- const rebillyDocument = parseYamlToDocument(
12
- readFileSync(rebillyDefinitionRef, 'utf-8'),
13
- rebillyDefinitionRef
14
- );
15
-
16
- export function measureAsync() {
17
- return lintDocument({
18
- externalRefResolver: new BaseResolver(),
19
- document: rebillyDocument,
20
- config: new StyleguideConfig(resolvePreset('recommended', [defaultPlugin])),
21
- });
22
- }
@@ -1,23 +0,0 @@
1
- import * as path from 'path';
2
- import { readFileSync } from 'fs';
3
- import { resolveDocument, BaseResolver } from '../../resolve';
4
- import { parseYamlToDocument } from '../utils';
5
- import { Oas3Types } from '../../types/oas3';
6
- import { normalizeTypes } from '../../types';
7
-
8
- export const name = 'Resolve with no external refs';
9
- export const count = 10;
10
- const rebillyDefinitionRef = path.resolve(path.join(__dirname, 'rebilly.yaml'));
11
- const rebillyDocument = parseYamlToDocument(
12
- readFileSync(rebillyDefinitionRef, 'utf-8'),
13
- rebillyDefinitionRef
14
- );
15
- const externalRefResolver = new BaseResolver();
16
-
17
- export function measureAsync() {
18
- return resolveDocument({
19
- rootDocument: rebillyDocument,
20
- externalRefResolver,
21
- rootType: normalizeTypes(Oas3Types).Root,
22
- });
23
- }
@@ -1,311 +0,0 @@
1
- 'use strict';
2
- const os = require('os');
3
- const fs = require('fs');
4
- const path = require('path');
5
- const assert = require('assert');
6
- const { execSync } = require('child_process');
7
- const { red, green, yellow, cyan, grey } = require('./colors');
8
- const { sampleModule } = require('./fork');
9
- const NS_PER_SEC = 1e9;
10
- const LOCAL = 'local';
11
-
12
- // The maximum time in seconds a benchmark is allowed to run before finishing.
13
- const maxTime = 10;
14
- // The minimum sample size required to perform statistical analysis.
15
- const minSamples = 5;
16
-
17
- function LOCAL_DIR(...paths) {
18
- return path.join(__dirname, '..', ...paths);
19
- }
20
-
21
- // Build a benchmark-friendly environment for the given revision
22
- // and returns path to its 'lib' directory.
23
- function prepareRevision(revision) {
24
- console.log(`🍳 Preparing ${revision}...`);
25
-
26
- if (revision === LOCAL) {
27
- return tscBuild(path.join(LOCAL_DIR(), '../../..'));
28
- }
29
-
30
- // Returns the complete git hash for a given git revision reference.
31
- const hash = exec(`git rev-parse "${revision}"`);
32
- const dir = path.join(os.tmpdir(), 'redocly-cli-benchmark', hash);
33
- if (fs.existsSync(dir)) {
34
- fs.rmdirSync(dir, { recursive: true });
35
- }
36
- fs.mkdirSync(dir, { recursive: true });
37
-
38
- exec(`git archive "${hash}" | tar -xC "${dir}"`);
39
- exec('npm ci', { cwd: dir });
40
- const to = path.join(dir, 'packages/core/src/benchmark/benches');
41
- exec(`rm -rf ${to}`);
42
- exec(`cp -R ${LOCAL_DIR('benchmark/benches')} ${to}`);
43
- return tscBuild(dir);
44
- }
45
-
46
- function tscBuild(dir) {
47
- const oldCwd = process.cwd();
48
- process.chdir(dir);
49
- execSync('npm run compile', { stdio: 'inherit' });
50
- exec(
51
- `cp ${path.join(dir, 'packages/core/src/benchmark/benches/*.yaml')} ${path.join(
52
- dir,
53
- 'packages/core/lib/benchmark/benches/'
54
- )}`
55
- );
56
- process.chdir(oldCwd);
57
- return path.join(dir, 'packages/core/lib/benchmark/benches');
58
- }
59
-
60
- async function collectSamples(modulePath) {
61
- const samples = [];
62
-
63
- // If time permits, increase sample size to reduce the margin of error.
64
- const start = Date.now();
65
- while (samples.length < minSamples || (Date.now() - start) / 1e3 < maxTime) {
66
- const { clocked, memUsed } = await sampleModule(modulePath);
67
- assert(clocked > 0);
68
- assert(memUsed > 0);
69
- samples.push({ clocked, memUsed });
70
- }
71
- return samples;
72
- }
73
-
74
- // T-Distribution two-tailed critical values for 95% confidence.
75
- // See http://www.itl.nist.gov/div898/handbook/eda/section3/eda3672.htm.
76
- const tTable =
77
- /* prettier-ignore */ {
78
- '1': 12.706, '2': 4.303, '3': 3.182, '4': 2.776, '5': 2.571, '6': 2.447,
79
- '7': 2.365, '8': 2.306, '9': 2.262, '10': 2.228, '11': 2.201, '12': 2.179,
80
- '13': 2.16, '14': 2.145, '15': 2.131, '16': 2.12, '17': 2.11, '18': 2.101,
81
- '19': 2.093, '20': 2.086, '21': 2.08, '22': 2.074, '23': 2.069, '24': 2.064,
82
- '25': 2.06, '26': 2.056, '27': 2.052, '28': 2.048, '29': 2.045, '30': 2.042,
83
- infinity: 1.96,
84
- };
85
-
86
- // Computes stats on benchmark results.
87
- function computeStats(samples) {
88
- assert(samples.length > 1);
89
-
90
- // Compute the sample mean (estimate of the population mean).
91
- let mean = 0;
92
- let meanMemUsed = 0;
93
- for (const { clocked, memUsed } of samples) {
94
- mean += clocked;
95
- meanMemUsed += memUsed;
96
- }
97
- mean /= samples.length;
98
- meanMemUsed /= samples.length;
99
-
100
- // Compute the sample variance (estimate of the population variance).
101
- let variance = 0;
102
- for (const { clocked } of samples) {
103
- variance += (clocked - mean) ** 2;
104
- }
105
- variance /= samples.length - 1;
106
-
107
- // Compute the sample standard deviation (estimate of the population standard deviation).
108
- const sd = Math.sqrt(variance);
109
-
110
- // Compute the standard error of the mean (a.k.a. the standard deviation of the sampling distribution of the sample mean).
111
- const sem = sd / Math.sqrt(samples.length);
112
-
113
- // Compute the degrees of freedom.
114
- const df = samples.length - 1;
115
-
116
- // Compute the critical value.
117
- const critical = tTable[df] || tTable.infinity;
118
-
119
- // Compute the margin of error.
120
- const moe = sem * critical;
121
-
122
- // The relative margin of error (expressed as a percentage of the mean).
123
- const rme = (moe / mean) * 100 || 0;
124
-
125
- return {
126
- memPerOp: Math.floor(meanMemUsed),
127
- ops: NS_PER_SEC / mean,
128
- deviation: rme,
129
- numSamples: samples.length,
130
- };
131
- }
132
-
133
- function beautifyBenchmark(results) {
134
- const nameMaxLen = maxBy(results, ({ name }) => name.length);
135
- const opsTop = maxBy(results, ({ ops }) => ops);
136
- const opsMaxLen = maxBy(results, ({ ops }) => beautifyNumber(ops).length);
137
- const memPerOpMaxLen = maxBy(results, ({ memPerOp }) => beautifyBytes(memPerOp).length);
138
-
139
- for (const result of results) {
140
- printBench(result);
141
- }
142
-
143
- function printBench(bench) {
144
- const { name, memPerOp, ops, deviation, numSamples } = bench;
145
- console.log(
146
- ' ' +
147
- nameStr() +
148
- grey(' x ') +
149
- opsStr() +
150
- ' ops/sec ' +
151
- grey('\xb1') +
152
- deviationStr() +
153
- cyan('%') +
154
- grey(' x ') +
155
- memPerOpStr() +
156
- '/op' +
157
- grey(' (' + numSamples + ' runs sampled)')
158
- );
159
-
160
- function nameStr() {
161
- const nameFmt = name.padEnd(nameMaxLen);
162
- return ops === opsTop ? green(nameFmt) : nameFmt;
163
- }
164
-
165
- function opsStr() {
166
- const percent = ops / opsTop;
167
- const colorFn = percent > 0.95 ? green : percent > 0.8 ? yellow : red;
168
- return colorFn(beautifyNumber(ops).padStart(opsMaxLen));
169
- }
170
-
171
- function deviationStr() {
172
- const colorFn = deviation > 5 ? red : deviation > 2 ? yellow : green;
173
- return colorFn(deviation.toFixed(2));
174
- }
175
-
176
- function memPerOpStr() {
177
- return beautifyBytes(memPerOp).padStart(memPerOpMaxLen);
178
- }
179
- }
180
- }
181
-
182
- function beautifyBytes(bytes) {
183
- const sizes = ['Bytes', 'KB', 'MB', 'GB'];
184
- const i = Math.floor(Math.log2(bytes) / 10);
185
- return beautifyNumber(bytes / 2 ** (i * 10)) + ' ' + sizes[i];
186
- }
187
-
188
- function beautifyNumber(num) {
189
- return Number(num.toFixed(num > 100 ? 0 : 2)).toLocaleString();
190
- }
191
-
192
- function maxBy(array, fn) {
193
- return Math.max(...array.map(fn));
194
- }
195
-
196
- // Prepare all revisions and run benchmarks matching a pattern against them.
197
- async function prepareAndRunBenchmarks(benchmarkPatterns, revisions) {
198
- const environments = revisions.map((revision) => ({
199
- revision,
200
- distPath: prepareRevision(revision),
201
- }));
202
-
203
- console.log(`🚀 Starting benchmarks...`);
204
-
205
- for (const benchmark of matchBenchmarks(benchmarkPatterns)) {
206
- const results = [];
207
- for (let i = 0; i < environments.length; ++i) {
208
- const environment = environments[i];
209
- const modulePath = path.join(environment.distPath, benchmark);
210
-
211
- if (i === 0) {
212
- const { name } = await sampleModule(modulePath);
213
- console.log('⏱️ ' + name);
214
- }
215
-
216
- try {
217
- const samples = await collectSamples(modulePath);
218
-
219
- results.push({
220
- name: environment.revision,
221
- samples,
222
- ...computeStats(samples),
223
- });
224
- process.stdout.write(' ' + cyan(i + 1) + ' tests completed.\u000D');
225
- } catch (error) {
226
- console.log(' ' + environment.revision + ': ' + red(String(error)));
227
- }
228
- }
229
- console.log('\n');
230
-
231
- beautifyBenchmark(results);
232
- console.log('');
233
- }
234
- }
235
-
236
- function findFiles(cwd, pattern) {
237
- const out = exec(`find . -path '${pattern}'`, { cwd });
238
- return out.split('\n').filter(Boolean);
239
- }
240
-
241
- function removeTrailingNewLine(str) {
242
- if (str == null) {
243
- return str;
244
- }
245
- return str.split('\n').slice(0, -1).join('\n');
246
- }
247
-
248
- function exec(command, options) {
249
- const output = execSync(command, {
250
- maxBuffer: 10 * 1024 * 1024, // 10MB
251
- encoding: 'utf-8',
252
- ...options,
253
- });
254
- return removeTrailingNewLine(output);
255
- }
256
-
257
- // Find all benchmark tests to be run.
258
- function matchBenchmarks(patterns) {
259
- let benchmarks = findFiles(LOCAL_DIR('../lib/benchmark/benches'), '*.bench.js');
260
- if (patterns.length > 0) {
261
- benchmarks = benchmarks.filter((benchmark) =>
262
- patterns.some((pattern) => path.join('../lib/benchmark/benches', benchmark).includes(pattern))
263
- );
264
- }
265
-
266
- if (benchmarks.length === 0) {
267
- console.warn('No benchmarks matching: ' + patterns.map(bold).join(''));
268
- }
269
-
270
- return benchmarks;
271
- }
272
-
273
- function getArguments(argv) {
274
- const revsIdx = argv.indexOf('--revs');
275
- const revsArgs = revsIdx === -1 ? [] : argv.slice(revsIdx + 1);
276
- const benchmarkPatterns = revsIdx === -1 ? argv : argv.slice(0, revsIdx);
277
- let assumeArgs;
278
- let revisions;
279
- switch (revsArgs.length) {
280
- case 0:
281
- assumeArgs = [...benchmarkPatterns, '--revs', 'local', 'HEAD'];
282
- revisions = [LOCAL, 'HEAD'];
283
- break;
284
- case 1:
285
- if (revsArgs[0] === LOCAL) {
286
- assumeArgs = [...benchmarkPatterns, '--revs', revsArgs[0]];
287
- revisions = [revsArgs[0]];
288
- } else {
289
- assumeArgs = [...benchmarkPatterns, '--revs', 'local', revsArgs[0]];
290
- revisions = [LOCAL, revsArgs[0]];
291
- }
292
- break;
293
- default:
294
- revisions = revsArgs;
295
- break;
296
- }
297
- if (assumeArgs) {
298
- console.warn('Assuming you meant: ' + bold('benchmark ' + assumeArgs.join(' ')));
299
- }
300
- return { benchmarkPatterns, revisions };
301
- }
302
-
303
- function bold(str) {
304
- return '\u001b[1m' + str + '\u001b[0m';
305
- }
306
-
307
- // Get the revisions and make things happen!
308
- if (require.main === module) {
309
- const { benchmarkPatterns, revisions } = getArguments(process.argv.slice(2));
310
- prepareAndRunBenchmarks(benchmarkPatterns, revisions);
311
- }
@@ -1,29 +0,0 @@
1
- 'use strict';
2
-
3
- function red(str) {
4
- return '\u001b[31m' + str + '\u001b[0m';
5
- }
6
-
7
- function green(str) {
8
- return '\u001b[32m' + str + '\u001b[0m';
9
- }
10
-
11
- function yellow(str) {
12
- return '\u001b[33m' + str + '\u001b[0m';
13
- }
14
-
15
- function cyan(str) {
16
- return '\u001b[36m' + str + '\u001b[0m';
17
- }
18
-
19
- function grey(str) {
20
- return '\u001b[90m' + str + '\u001b[0m';
21
- }
22
-
23
- module.exports = {
24
- red,
25
- green,
26
- yellow,
27
- cyan,
28
- grey,
29
- };
@@ -1,83 +0,0 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const cp = require('child_process');
5
-
6
- // Clocks the time taken to execute a test per cycle (secs).
7
- function clock(count, fn) {
8
- const start = process.hrtime.bigint();
9
- for (let i = 0; i < count; ++i) {
10
- fn();
11
- }
12
- return Number(process.hrtime.bigint() - start);
13
- }
14
-
15
- async function clockAsync(count, fn) {
16
- const start = process.hrtime.bigint();
17
- for (let i = 0; i < count; ++i) {
18
- await fn();
19
- }
20
- return Number(process.hrtime.bigint() - start);
21
- }
22
-
23
- if (require.main === module) {
24
- const modulePath = process.env.BENCHMARK_MODULE_PATH;
25
- assert(typeof modulePath === 'string');
26
- assert(process.send);
27
- const module = require(modulePath);
28
-
29
- if (module.measureAsync) {
30
- async function run() {
31
- await clockAsync(7, module.measureAsync); // warm up
32
- global.gc();
33
- process.nextTick(async () => {
34
- const memBaseline = process.memoryUsage().heapUsed;
35
- const clocked = await clockAsync(module.count, module.measureAsync);
36
- process.send({
37
- name: module.name,
38
- clocked: clocked / module.count,
39
- memUsed: (process.memoryUsage().heapUsed - memBaseline) / module.count,
40
- });
41
- });
42
- }
43
- run();
44
- } else {
45
- clock(7, module.measure); // warm up
46
- global.gc();
47
- process.nextTick(() => {
48
- const memBaseline = process.memoryUsage().heapUsed;
49
- const clocked = clock(module.count, module.measure);
50
- process.send({
51
- name: module.name,
52
- clocked: clocked / module.count,
53
- memUsed: (process.memoryUsage().heapUsed - memBaseline) / module.count,
54
- });
55
- });
56
- }
57
- }
58
-
59
- function sampleModule(modulePath) {
60
- return new Promise((resolve, reject) => {
61
- const env = {
62
- NODE_ENV: 'production',
63
- BENCHMARK_MODULE_PATH: modulePath,
64
- };
65
- const child = cp.fork(__filename, { env });
66
- let message;
67
- let error;
68
-
69
- child.on('message', (msg) => (message = msg));
70
- child.on('error', (e) => (error = e));
71
- child.on('close', () => {
72
- if (message) {
73
- return resolve(message);
74
- }
75
- reject(error || new Error('Forked process closed without error'));
76
- });
77
- }).then((result) => {
78
- global.gc();
79
- return result;
80
- });
81
- }
82
-
83
- module.exports = { sampleModule };
@@ -1,36 +0,0 @@
1
- import { parseYaml } from '../js-yaml';
2
- import { Document, Source } from '../resolve';
3
- import { Oas3RuleSet } from '../oas-types';
4
- import { StyleguideConfig, mergeExtends, resolvePlugins } from '../config';
5
-
6
- import type { RuleConfig, Plugin, ResolvedStyleguideConfig } from '../config/types';
7
-
8
- export function parseYamlToDocument(body: string, absoluteRef: string = ''): Document {
9
- return {
10
- source: new Source(absoluteRef, body),
11
- parsed: parseYaml(body, { filename: absoluteRef }),
12
- };
13
- }
14
-
15
- export function makeConfigForRuleset(rules: Oas3RuleSet, plugin?: Partial<Plugin>) {
16
- const rulesConf: Record<string, RuleConfig> = {};
17
- const ruleId = 'test';
18
- Object.keys(rules).forEach((name) => {
19
- rulesConf[`${ruleId}/${name}`] = 'error';
20
- });
21
- const extendConfigs = [
22
- resolvePlugins([
23
- {
24
- ...plugin,
25
- id: ruleId,
26
- rules: { oas3: rules },
27
- },
28
- ]) as ResolvedStyleguideConfig,
29
- ];
30
- if (rules) {
31
- extendConfigs.push({ rules });
32
- }
33
- const styleguide = mergeExtends(extendConfigs);
34
-
35
- return new StyleguideConfig(styleguide);
36
- }