@redocly/openapi-core 1.0.0-beta.126 → 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 (275) hide show
  1. package/lib/bundle.js +5 -2
  2. package/lib/rules/common/spec.js +1 -0
  3. package/lib/rules/oas2/request-mime-type.d.ts +1 -1
  4. package/lib/rules/oas2/response-mime-type.d.ts +1 -1
  5. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +2 -2
  6. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +3 -3
  7. package/lib/rules/oas3/request-mime-type.d.ts +1 -1
  8. package/lib/rules/oas3/response-mime-type.d.ts +1 -1
  9. package/lib/walk.d.ts +6 -5
  10. package/lib/walk.js +23 -27
  11. package/package.json +1 -1
  12. package/__tests__/utils.ts +0 -88
  13. package/src/__tests__/__snapshots__/bundle.test.ts.snap +0 -437
  14. package/src/__tests__/bundle.test.ts +0 -236
  15. package/src/__tests__/codeframes.test.ts +0 -530
  16. package/src/__tests__/fixtures/.redocly.lint-ignore.yaml +0 -5
  17. package/src/__tests__/fixtures/extension.js +0 -24
  18. package/src/__tests__/fixtures/refs/definitions.yaml +0 -3
  19. package/src/__tests__/fixtures/refs/examples.yaml +0 -8
  20. package/src/__tests__/fixtures/refs/external-request-body.yaml +0 -13
  21. package/src/__tests__/fixtures/refs/externalref.yaml +0 -35
  22. package/src/__tests__/fixtures/refs/hosted.yaml +0 -35
  23. package/src/__tests__/fixtures/refs/openapi-with-external-refs-conflicting-names.yaml +0 -21
  24. package/src/__tests__/fixtures/refs/openapi-with-external-refs.yaml +0 -33
  25. package/src/__tests__/fixtures/refs/openapi-with-url-refs.yaml +0 -18
  26. package/src/__tests__/fixtures/refs/param-b.yaml +0 -1
  27. package/src/__tests__/fixtures/refs/param-c.yaml +0 -1
  28. package/src/__tests__/fixtures/refs/rename.yaml +0 -1
  29. package/src/__tests__/fixtures/refs/requestBody.yaml +0 -9
  30. package/src/__tests__/fixtures/refs/schema-a.yaml +0 -1
  31. package/src/__tests__/fixtures/refs/simple.yaml +0 -1
  32. package/src/__tests__/fixtures/refs/vendor.schema.yaml +0 -20
  33. package/src/__tests__/fixtures/resolve/External.yaml +0 -10
  34. package/src/__tests__/fixtures/resolve/External2.yaml +0 -4
  35. package/src/__tests__/fixtures/resolve/description.md +0 -3
  36. package/src/__tests__/fixtures/resolve/externalInfo.yaml +0 -4
  37. package/src/__tests__/fixtures/resolve/externalLicense.yaml +0 -1
  38. package/src/__tests__/fixtures/resolve/openapi-with-back.yaml +0 -13
  39. package/src/__tests__/fixtures/resolve/openapi-with-md-description.yaml +0 -5
  40. package/src/__tests__/fixtures/resolve/openapi.yaml +0 -28
  41. package/src/__tests__/fixtures/resolve/schemas/type-a.yaml +0 -10
  42. package/src/__tests__/fixtures/resolve/schemas/type-b.yaml +0 -6
  43. package/src/__tests__/fixtures/resolve/transitive/a.yaml +0 -1
  44. package/src/__tests__/fixtures/resolve/transitive/components.yaml +0 -5
  45. package/src/__tests__/fixtures/resolve/transitive/schemas.yaml +0 -3
  46. package/src/__tests__/format.test.ts +0 -76
  47. package/src/__tests__/js-yaml.test.ts +0 -73
  48. package/src/__tests__/lint.test.ts +0 -388
  49. package/src/__tests__/logger-browser.test.ts +0 -53
  50. package/src/__tests__/logger.test.ts +0 -47
  51. package/src/__tests__/login.test.ts +0 -17
  52. package/src/__tests__/normalizeVisitors.test.ts +0 -151
  53. package/src/__tests__/output-browser.test.ts +0 -18
  54. package/src/__tests__/output.test.ts +0 -15
  55. package/src/__tests__/ref-utils.test.ts +0 -120
  56. package/src/__tests__/resolve-http.test.ts +0 -77
  57. package/src/__tests__/resolve.test.ts +0 -430
  58. package/src/__tests__/utils-browser.test.ts +0 -11
  59. package/src/__tests__/utils.test.ts +0 -144
  60. package/src/__tests__/walk.test.ts +0 -1545
  61. package/src/benchmark/benches/lint-with-many-rules.bench.ts +0 -35
  62. package/src/benchmark/benches/lint-with-nested-rule.bench.ts +0 -39
  63. package/src/benchmark/benches/lint-with-no-rules.bench.ts +0 -20
  64. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +0 -35
  65. package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +0 -32
  66. package/src/benchmark/benches/rebilly.yaml +0 -32275
  67. package/src/benchmark/benches/recommended-oas3.bench.ts +0 -22
  68. package/src/benchmark/benches/resolve-with-no-external.bench.ts +0 -23
  69. package/src/benchmark/benchmark.js +0 -311
  70. package/src/benchmark/colors.js +0 -29
  71. package/src/benchmark/fork.js +0 -83
  72. package/src/benchmark/utils.ts +0 -36
  73. package/src/bundle.ts +0 -399
  74. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +0 -161
  75. package/src/config/__tests__/__snapshots__/config.test.ts.snap +0 -144
  76. package/src/config/__tests__/config-resolvers.test.ts +0 -491
  77. package/src/config/__tests__/config.test.ts +0 -307
  78. package/src/config/__tests__/fixtures/ingore-file.ts +0 -8
  79. package/src/config/__tests__/fixtures/load-redocly.yaml +0 -2
  80. package/src/config/__tests__/fixtures/plugin-config.yaml +0 -2
  81. package/src/config/__tests__/fixtures/plugin.js +0 -56
  82. package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +0 -11
  83. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +0 -69
  84. package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +0 -7
  85. package/src/config/__tests__/fixtures/resolve-config/local-config-with-custom-function.yaml +0 -17
  86. package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +0 -18
  87. package/src/config/__tests__/fixtures/resolve-config/local-config-with-wrong-custom-function.yaml +0 -15
  88. package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +0 -9
  89. package/src/config/__tests__/fixtures/resolve-config/plugin.js +0 -80
  90. package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +0 -3
  91. package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +0 -4
  92. package/src/config/__tests__/load.test.ts +0 -167
  93. package/src/config/__tests__/resolve-plugins.test.ts +0 -27
  94. package/src/config/__tests__/utils.test.ts +0 -204
  95. package/src/config/all.ts +0 -73
  96. package/src/config/builtIn.ts +0 -37
  97. package/src/config/config-resolvers.ts +0 -465
  98. package/src/config/config.ts +0 -330
  99. package/src/config/index.ts +0 -7
  100. package/src/config/load.ts +0 -144
  101. package/src/config/minimal.ts +0 -60
  102. package/src/config/recommended.ts +0 -60
  103. package/src/config/rules.ts +0 -54
  104. package/src/config/types.ts +0 -216
  105. package/src/config/utils.ts +0 -333
  106. package/src/decorators/__tests__/filter-in.test.ts +0 -310
  107. package/src/decorators/__tests__/filter-out.test.ts +0 -335
  108. package/src/decorators/__tests__/media-type-examples-override.test.ts +0 -665
  109. package/src/decorators/__tests__/remove-x-internal.test.ts +0 -316
  110. package/src/decorators/__tests__/resources/request.yaml +0 -3
  111. package/src/decorators/__tests__/resources/response.yaml +0 -3
  112. package/src/decorators/common/filters/filter-helper.ts +0 -72
  113. package/src/decorators/common/filters/filter-in.ts +0 -18
  114. package/src/decorators/common/filters/filter-out.ts +0 -18
  115. package/src/decorators/common/info-description-override.ts +0 -24
  116. package/src/decorators/common/info-override.ts +0 -15
  117. package/src/decorators/common/media-type-examples-override.ts +0 -79
  118. package/src/decorators/common/operation-description-override.ts +0 -30
  119. package/src/decorators/common/registry-dependencies.ts +0 -25
  120. package/src/decorators/common/remove-x-internal.ts +0 -59
  121. package/src/decorators/common/tag-description-override.ts +0 -25
  122. package/src/decorators/oas2/index.ts +0 -20
  123. package/src/decorators/oas3/index.ts +0 -22
  124. package/src/env.ts +0 -5
  125. package/src/format/codeframes.ts +0 -216
  126. package/src/format/format.ts +0 -375
  127. package/src/index.ts +0 -71
  128. package/src/js-yaml/index.ts +0 -14
  129. package/src/lint.ts +0 -130
  130. package/src/logger.ts +0 -34
  131. package/src/oas-types.ts +0 -57
  132. package/src/output.ts +0 -7
  133. package/src/redocly/__tests__/redocly-client.test.ts +0 -146
  134. package/src/redocly/index.ts +0 -187
  135. package/src/redocly/redocly-client-types.ts +0 -10
  136. package/src/redocly/registry-api-types.ts +0 -32
  137. package/src/redocly/registry-api.ts +0 -149
  138. package/src/ref-utils.ts +0 -85
  139. package/src/resolve.ts +0 -417
  140. package/src/rules/__tests__/fixtures/code-sample.php +0 -9
  141. package/src/rules/__tests__/fixtures/invalid-yaml.yaml +0 -1
  142. package/src/rules/__tests__/fixtures/ref.yaml +0 -1
  143. package/src/rules/__tests__/no-unresolved-refs.test.ts +0 -257
  144. package/src/rules/__tests__/utils.test.ts +0 -160
  145. package/src/rules/ajv.ts +0 -102
  146. package/src/rules/common/__tests__/info-license.test.ts +0 -62
  147. package/src/rules/common/__tests__/license-url.test.ts +0 -63
  148. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +0 -96
  149. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +0 -210
  150. package/src/rules/common/__tests__/no-identical-paths.test.ts +0 -58
  151. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +0 -85
  152. package/src/rules/common/__tests__/operation-2xx-response.test.ts +0 -192
  153. package/src/rules/common/__tests__/operation-4xx-response.test.ts +0 -231
  154. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +0 -76
  155. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +0 -45
  156. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +0 -167
  157. package/src/rules/common/__tests__/operation-singular-tag.test.ts +0 -72
  158. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +0 -95
  159. package/src/rules/common/__tests__/path-not-include-query.test.ts +0 -64
  160. package/src/rules/common/__tests__/path-params-defined.test.ts +0 -202
  161. package/src/rules/common/__tests__/paths-kebab-case.test.ts +0 -108
  162. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +0 -264
  163. package/src/rules/common/__tests__/security-defined.test.ts +0 -175
  164. package/src/rules/common/__tests__/spec.test.ts +0 -555
  165. package/src/rules/common/__tests__/tag-description.test.ts +0 -65
  166. package/src/rules/common/__tests__/tags-alphabetical.test.ts +0 -64
  167. package/src/rules/common/assertions/__tests__/asserts.test.ts +0 -869
  168. package/src/rules/common/assertions/__tests__/index.test.ts +0 -100
  169. package/src/rules/common/assertions/__tests__/utils.test.ts +0 -236
  170. package/src/rules/common/assertions/asserts.ts +0 -357
  171. package/src/rules/common/assertions/index.ts +0 -56
  172. package/src/rules/common/assertions/utils.ts +0 -331
  173. package/src/rules/common/info-contact.ts +0 -15
  174. package/src/rules/common/info-license-url.ts +0 -10
  175. package/src/rules/common/info-license.ts +0 -15
  176. package/src/rules/common/no-ambiguous-paths.ts +0 -50
  177. package/src/rules/common/no-enum-type-mismatch.ts +0 -52
  178. package/src/rules/common/no-http-verbs-in-paths.ts +0 -36
  179. package/src/rules/common/no-identical-paths.ts +0 -24
  180. package/src/rules/common/no-invalid-parameter-examples.ts +0 -36
  181. package/src/rules/common/no-invalid-schema-examples.ts +0 -27
  182. package/src/rules/common/no-path-trailing-slash.ts +0 -15
  183. package/src/rules/common/operation-2xx-response.ts +0 -24
  184. package/src/rules/common/operation-4xx-response.ts +0 -24
  185. package/src/rules/common/operation-description.ts +0 -13
  186. package/src/rules/common/operation-operationId-unique.ts +0 -21
  187. package/src/rules/common/operation-operationId-url-safe.ts +0 -19
  188. package/src/rules/common/operation-operationId.ts +0 -17
  189. package/src/rules/common/operation-parameters-unique.ts +0 -48
  190. package/src/rules/common/operation-singular-tag.ts +0 -17
  191. package/src/rules/common/operation-summary.ts +0 -13
  192. package/src/rules/common/operation-tag-defined.ts +0 -26
  193. package/src/rules/common/parameter-description.ts +0 -22
  194. package/src/rules/common/path-declaration-must-exist.ts +0 -15
  195. package/src/rules/common/path-excludes-patterns.ts +0 -23
  196. package/src/rules/common/path-http-verbs-order.ts +0 -30
  197. package/src/rules/common/path-not-include-query.ts +0 -17
  198. package/src/rules/common/path-params-defined.ts +0 -65
  199. package/src/rules/common/path-segment-plural.ts +0 -31
  200. package/src/rules/common/paths-kebab-case.ts +0 -19
  201. package/src/rules/common/required-string-property-missing-min-length.ts +0 -44
  202. package/src/rules/common/response-contains-header.ts +0 -35
  203. package/src/rules/common/scalar-property-missing-example.ts +0 -58
  204. package/src/rules/common/security-defined.ts +0 -65
  205. package/src/rules/common/spec.ts +0 -174
  206. package/src/rules/common/tag-description.ts +0 -10
  207. package/src/rules/common/tags-alphabetical.ts +0 -20
  208. package/src/rules/no-unresolved-refs.ts +0 -51
  209. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +0 -110
  210. package/src/rules/oas2/__tests__/response-contains-header.test.ts +0 -174
  211. package/src/rules/oas2/__tests__/response-contains-property.test.ts +0 -155
  212. package/src/rules/oas2/__tests__/spec/fixtures/description.md +0 -1
  213. package/src/rules/oas2/__tests__/spec/info.test.ts +0 -355
  214. package/src/rules/oas2/__tests__/spec/operation.test.ts +0 -123
  215. package/src/rules/oas2/__tests__/spec/paths.test.ts +0 -245
  216. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +0 -35
  217. package/src/rules/oas2/__tests__/spec/utils.ts +0 -32
  218. package/src/rules/oas2/boolean-parameter-prefixes.ts +0 -26
  219. package/src/rules/oas2/index.ts +0 -89
  220. package/src/rules/oas2/remove-unused-components.ts +0 -81
  221. package/src/rules/oas2/request-mime-type.ts +0 -17
  222. package/src/rules/oas2/response-contains-property.ts +0 -36
  223. package/src/rules/oas2/response-mime-type.ts +0 -17
  224. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +0 -111
  225. package/src/rules/oas3/__tests__/fixtures/common.yaml +0 -11
  226. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +0 -205
  227. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +0 -65
  228. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +0 -473
  229. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +0 -60
  230. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +0 -79
  231. package/src/rules/oas3/__tests__/no-unused-components.test.ts +0 -131
  232. package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +0 -145
  233. package/src/rules/oas3/__tests__/response-contains-header.test.ts +0 -389
  234. package/src/rules/oas3/__tests__/response-contains-property.test.ts +0 -403
  235. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +0 -41
  236. package/src/rules/oas3/__tests__/spec/fixtures/description.md +0 -1
  237. package/src/rules/oas3/__tests__/spec/info.test.ts +0 -391
  238. package/src/rules/oas3/__tests__/spec/operation.test.ts +0 -253
  239. package/src/rules/oas3/__tests__/spec/paths.test.ts +0 -284
  240. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +0 -77
  241. package/src/rules/oas3/__tests__/spec/servers.test.ts +0 -505
  242. package/src/rules/oas3/__tests__/spec/spec.test.ts +0 -298
  243. package/src/rules/oas3/__tests__/spec/utils.ts +0 -32
  244. package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +0 -305
  245. package/src/rules/oas3/boolean-parameter-prefixes.ts +0 -28
  246. package/src/rules/oas3/index.ts +0 -109
  247. package/src/rules/oas3/no-empty-servers.ts +0 -22
  248. package/src/rules/oas3/no-example-value-and-externalValue.ts +0 -14
  249. package/src/rules/oas3/no-invalid-media-type-examples.ts +0 -49
  250. package/src/rules/oas3/no-server-example.com.ts +0 -14
  251. package/src/rules/oas3/no-server-trailing-slash.ts +0 -15
  252. package/src/rules/oas3/no-server-variables-empty-enum.ts +0 -66
  253. package/src/rules/oas3/no-undefined-server-variable.ts +0 -30
  254. package/src/rules/oas3/no-unused-components.ts +0 -75
  255. package/src/rules/oas3/operation-4xx-problem-details-rfc7807.ts +0 -36
  256. package/src/rules/oas3/remove-unused-components.ts +0 -95
  257. package/src/rules/oas3/request-mime-type.ts +0 -31
  258. package/src/rules/oas3/response-contains-property.ts +0 -38
  259. package/src/rules/oas3/response-mime-type.ts +0 -31
  260. package/src/rules/oas3/spec-components-invalid-map-name.ts +0 -74
  261. package/src/rules/other/stats.ts +0 -73
  262. package/src/rules/utils.ts +0 -191
  263. package/src/types/index.ts +0 -149
  264. package/src/types/oas2.ts +0 -478
  265. package/src/types/oas3.ts +0 -597
  266. package/src/types/oas3_1.ts +0 -258
  267. package/src/types/redocly-yaml.ts +0 -1010
  268. package/src/typings/common.ts +0 -17
  269. package/src/typings/openapi.ts +0 -298
  270. package/src/typings/swagger.ts +0 -236
  271. package/src/utils.ts +0 -276
  272. package/src/visitors.ts +0 -491
  273. package/src/walk.ts +0 -453
  274. package/tsconfig.json +0 -8
  275. 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
- }