@redocly/openapi-core 1.0.0-beta.104 → 1.0.0-beta.107
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.
- package/README.md +4 -4
- package/__tests__/utils.ts +8 -6
- package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
- package/lib/benchmark/utils.d.ts +2 -2
- package/lib/benchmark/utils.js +2 -2
- package/lib/bundle.d.ts +2 -2
- package/lib/bundle.js +2 -2
- package/lib/config/all.d.ts +2 -2
- package/lib/config/all.js +1 -1
- package/lib/config/builtIn.d.ts +2 -2
- package/lib/config/builtIn.js +2 -2
- package/lib/config/config-resolvers.d.ts +5 -5
- package/lib/config/config-resolvers.js +39 -36
- package/lib/config/config.d.ts +6 -5
- package/lib/config/config.js +27 -20
- package/lib/config/load.js +6 -7
- package/lib/config/minimal.d.ts +2 -2
- package/lib/config/minimal.js +3 -2
- package/lib/config/recommended.d.ts +2 -2
- package/lib/config/recommended.js +3 -2
- package/lib/config/rules.d.ts +2 -2
- package/lib/config/rules.js +1 -1
- package/lib/config/types.d.ts +23 -19
- package/lib/config/utils.d.ts +5 -5
- package/lib/config/utils.js +43 -26
- package/lib/decorators/common/remove-x-internal.js +2 -2
- package/lib/format/format.js +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +3 -2
- package/lib/js-yaml/index.js +1 -6
- package/lib/lint.d.ts +2 -2
- package/lib/lint.js +16 -6
- package/lib/redocly/registry-api.d.ts +1 -1
- package/lib/redocly/registry-api.js +2 -2
- package/lib/rules/ajv.d.ts +1 -1
- package/lib/rules/ajv.js +6 -6
- package/lib/rules/common/info-license-url.d.ts +1 -1
- package/lib/rules/common/info-license-url.js +5 -10
- package/lib/rules/common/info-license.d.ts +2 -0
- package/lib/rules/common/info-license.js +17 -0
- package/lib/rules/common/no-enum-type-mismatch.js +1 -3
- package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
- package/lib/rules/common/no-invalid-schema-examples.js +3 -3
- package/lib/rules/common/operation-operationId.js +1 -1
- package/lib/rules/common/path-not-include-query.js +1 -1
- package/lib/rules/common/paths-kebab-case.js +4 -1
- package/lib/rules/common/spec.js +1 -1
- package/lib/rules/oas2/index.js +4 -4
- package/lib/rules/oas2/remove-unused-components.js +3 -3
- package/lib/rules/oas3/index.js +4 -4
- package/lib/rules/oas3/no-empty-servers.js +1 -1
- package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
- package/lib/rules/oas3/remove-unused-components.js +2 -2
- package/lib/rules/other/stats.js +43 -14
- package/lib/rules/utils.d.ts +3 -2
- package/lib/rules/utils.js +19 -4
- package/lib/types/index.d.ts +2 -2
- package/lib/types/redocly-yaml.js +8 -7
- package/lib/utils.d.ts +5 -2
- package/lib/utils.js +20 -2
- package/lib/walk.d.ts +2 -1
- package/lib/walk.js +6 -3
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/bundle.test.ts.snap +141 -0
- package/src/__tests__/bundle.test.ts +68 -34
- package/src/__tests__/codeframes.test.ts +13 -14
- package/src/__tests__/fixtures/.redocly.lint-ignore.yaml +5 -0
- package/src/__tests__/js-yaml.test.ts +6 -4
- package/src/__tests__/lint.test.ts +127 -12
- package/src/__tests__/login.test.ts +2 -2
- package/src/__tests__/normalizeVisitors.test.ts +4 -4
- package/src/__tests__/ref-utils.test.ts +13 -13
- package/src/__tests__/resolve-http.test.ts +1 -1
- package/src/__tests__/resolve.test.ts +14 -11
- package/src/__tests__/utils.test.ts +42 -1
- package/src/__tests__/walk.test.ts +48 -56
- package/src/benchmark/benches/lint-with-many-rules.bench.ts +1 -1
- package/src/benchmark/benches/lint-with-nested-rule.bench.ts +1 -1
- package/src/benchmark/benches/lint-with-no-rules.bench.ts +1 -1
- package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +1 -1
- package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +1 -1
- package/src/benchmark/benches/recommended-oas3.bench.ts +3 -3
- package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
- package/src/benchmark/benchmark.js +9 -5
- package/src/benchmark/utils.ts +5 -5
- package/src/bundle.ts +18 -17
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +3 -1
- package/src/config/__tests__/config-resolvers.test.ts +123 -121
- package/src/config/__tests__/config.test.ts +76 -76
- package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +4 -2
- package/src/config/__tests__/fixtures/resolve-config/plugin.js +4 -1
- package/src/config/__tests__/load.test.ts +2 -2
- package/src/config/__tests__/resolve-plugins.test.ts +3 -3
- package/src/config/__tests__/utils.test.ts +83 -0
- package/src/config/all.ts +3 -4
- package/src/config/builtIn.ts +5 -5
- package/src/config/config-resolvers.ts +122 -83
- package/src/config/config.ts +36 -32
- package/src/config/load.ts +13 -16
- package/src/config/minimal.ts +5 -4
- package/src/config/recommended.ts +5 -4
- package/src/config/rules.ts +6 -6
- package/src/config/types.ts +28 -19
- package/src/config/utils.ts +74 -54
- package/src/decorators/__tests__/filter-out.test.ts +8 -4
- package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
- package/src/decorators/common/filters/filter-helper.ts +1 -1
- package/src/decorators/common/info-description-override.ts +1 -1
- package/src/decorators/common/operation-description-override.ts +1 -1
- package/src/decorators/common/remove-x-internal.ts +4 -4
- package/src/decorators/common/tag-description-override.ts +1 -1
- package/src/format/codeframes.ts +4 -4
- package/src/format/format.ts +10 -10
- package/src/index.ts +3 -4
- package/src/js-yaml/index.ts +3 -8
- package/src/lint.ts +22 -18
- package/src/oas-types.ts +1 -6
- package/src/redocly/__tests__/redocly-client.test.ts +25 -19
- package/src/redocly/index.ts +6 -4
- package/src/redocly/registry-api.ts +6 -6
- package/src/ref-utils.ts +2 -2
- package/src/resolve.ts +7 -4
- package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
- package/src/rules/__tests__/utils.test.ts +160 -0
- package/src/rules/ajv.ts +7 -8
- package/src/rules/common/__tests__/info-description.test.ts +3 -3
- package/src/rules/common/__tests__/info-license.test.ts +2 -2
- package/src/rules/common/__tests__/license-url.test.ts +2 -2
- package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
- package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +8 -8
- package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
- package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
- package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
- package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
- package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
- package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
- package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
- package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
- package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
- package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
- package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
- package/src/rules/common/__tests__/paths-kebab-case.test.ts +15 -15
- package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
- package/src/rules/common/__tests__/spec.test.ts +2 -2
- package/src/rules/common/__tests__/tag-description.test.ts +2 -2
- package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
- package/src/rules/common/assertions/__tests__/asserts.test.ts +513 -130
- package/src/rules/common/assertions/index.ts +6 -6
- package/src/rules/common/info-license-url.ts +4 -9
- package/src/rules/common/info-license.ts +15 -0
- package/src/rules/common/no-ambiguous-paths.ts +1 -1
- package/src/rules/common/no-enum-type-mismatch.ts +12 -9
- package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
- package/src/rules/common/no-invalid-schema-examples.ts +4 -4
- package/src/rules/common/operation-operationId.ts +1 -1
- package/src/rules/common/operation-parameters-unique.ts +2 -2
- package/src/rules/common/path-not-include-query.ts +1 -1
- package/src/rules/common/path-params-defined.ts +1 -1
- package/src/rules/common/paths-kebab-case.ts +4 -1
- package/src/rules/common/scalar-property-missing-example.ts +1 -1
- package/src/rules/common/spec.ts +10 -7
- package/src/rules/no-unresolved-refs.ts +1 -1
- package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
- package/src/rules/oas2/__tests__/spec/info.test.ts +12 -12
- package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
- package/src/rules/oas2/__tests__/spec/paths.test.ts +10 -10
- package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +6 -2
- package/src/rules/oas2/__tests__/spec/utils.ts +6 -6
- package/src/rules/oas2/index.ts +3 -3
- package/src/rules/oas2/remove-unused-components.ts +13 -8
- package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
- package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +13 -13
- package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
- package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
- package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
- package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
- package/src/rules/oas3/__tests__/spec/info.test.ts +12 -12
- package/src/rules/oas3/__tests__/spec/operation.test.ts +8 -8
- package/src/rules/oas3/__tests__/spec/paths.test.ts +10 -10
- package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +12 -12
- package/src/rules/oas3/__tests__/spec/servers.test.ts +15 -15
- package/src/rules/oas3/__tests__/spec/spec.test.ts +6 -6
- package/src/rules/oas3/__tests__/spec/utils.ts +6 -6
- package/src/rules/oas3/index.ts +3 -3
- package/src/rules/oas3/no-empty-servers.ts +1 -1
- package/src/rules/oas3/no-invalid-media-type-examples.ts +14 -6
- package/src/rules/oas3/no-servers-empty-enum.ts +9 -10
- package/src/rules/oas3/remove-unused-components.ts +18 -7
- package/src/rules/other/stats.ts +46 -17
- package/src/rules/utils.ts +19 -3
- package/src/types/index.ts +5 -5
- package/src/types/redocly-yaml.ts +8 -7
- package/src/typings/common.ts +9 -1
- package/src/typings/openapi.ts +1 -1
- package/src/utils.ts +31 -8
- package/src/visitors.ts +4 -4
- package/src/walk.ts +15 -11
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/common/license-url.d.ts +0 -2
- package/lib/rules/common/license-url.js +0 -12
- package/src/rules/common/license-url.ts +0 -10
|
@@ -18,7 +18,7 @@ describe('collect refs', () => {
|
|
|
18
18
|
contact: {}
|
|
19
19
|
license: {}
|
|
20
20
|
`,
|
|
21
|
-
'foobar.yaml'
|
|
21
|
+
'foobar.yaml'
|
|
22
22
|
);
|
|
23
23
|
|
|
24
24
|
const resolvedRefs = await resolveDocument({
|
|
@@ -35,7 +35,7 @@ describe('collect refs', () => {
|
|
|
35
35
|
Array [
|
|
36
36
|
"foobar.yaml::#/defs/info",
|
|
37
37
|
]
|
|
38
|
-
|
|
38
|
+
`
|
|
39
39
|
);
|
|
40
40
|
expect(Array.from(resolvedRefs.values()).map((info) => info.node)).toEqual([
|
|
41
41
|
{ contact: {}, license: {} },
|
|
@@ -56,7 +56,7 @@ describe('collect refs', () => {
|
|
|
56
56
|
contact: {}
|
|
57
57
|
license: {}
|
|
58
58
|
`,
|
|
59
|
-
''
|
|
59
|
+
''
|
|
60
60
|
);
|
|
61
61
|
|
|
62
62
|
try {
|
|
@@ -89,7 +89,7 @@ describe('collect refs', () => {
|
|
|
89
89
|
contact: {}
|
|
90
90
|
license: {}
|
|
91
91
|
`,
|
|
92
|
-
'foobar.yaml'
|
|
92
|
+
'foobar.yaml'
|
|
93
93
|
);
|
|
94
94
|
|
|
95
95
|
const resolvedRefs = await resolveDocument({
|
|
@@ -125,7 +125,7 @@ describe('collect refs', () => {
|
|
|
125
125
|
loop2:
|
|
126
126
|
$ref: '#/info'
|
|
127
127
|
`,
|
|
128
|
-
'foobar.yaml'
|
|
128
|
+
'foobar.yaml'
|
|
129
129
|
);
|
|
130
130
|
|
|
131
131
|
try {
|
|
@@ -147,7 +147,7 @@ describe('collect refs', () => {
|
|
|
147
147
|
info:
|
|
148
148
|
$ref: "./externalInfo.yaml#/info"
|
|
149
149
|
`,
|
|
150
|
-
path.join(cwd, 'foobar.yaml')
|
|
150
|
+
path.join(cwd, 'foobar.yaml')
|
|
151
151
|
);
|
|
152
152
|
|
|
153
153
|
const resolvedRefs = await resolveDocument({
|
|
@@ -181,7 +181,7 @@ describe('collect refs', () => {
|
|
|
181
181
|
const externalRefResolver = new BaseResolver();
|
|
182
182
|
const rootDocument = await externalRefResolver.resolveDocument(
|
|
183
183
|
null,
|
|
184
|
-
`${cwd}/openapi-with-back.yaml
|
|
184
|
+
`${cwd}/openapi-with-back.yaml`
|
|
185
185
|
);
|
|
186
186
|
|
|
187
187
|
const resolvedRefs = await resolveDocument({
|
|
@@ -192,8 +192,11 @@ describe('collect refs', () => {
|
|
|
192
192
|
|
|
193
193
|
expect(resolvedRefs).toBeDefined();
|
|
194
194
|
|
|
195
|
-
expect(
|
|
196
|
-
.
|
|
195
|
+
expect(
|
|
196
|
+
Array.from(resolvedRefs.keys())
|
|
197
|
+
.map((ref) => ref.substring(cwd.length + 1))
|
|
198
|
+
.sort()
|
|
199
|
+
).toMatchInlineSnapshot(`
|
|
197
200
|
Array [
|
|
198
201
|
"openapi-with-back.yaml::./schemas/type-a.yaml#/",
|
|
199
202
|
"openapi-with-back.yaml::./schemas/type-b.yaml#/",
|
|
@@ -345,7 +348,7 @@ describe('collect refs', () => {
|
|
|
345
348
|
const externalRefResolver = new BaseResolver();
|
|
346
349
|
const rootDocument = await externalRefResolver.resolveDocument(
|
|
347
350
|
null,
|
|
348
|
-
`${cwd}/openapi-with-md-description.yaml
|
|
351
|
+
`${cwd}/openapi-with-md-description.yaml`
|
|
349
352
|
);
|
|
350
353
|
|
|
351
354
|
expect(rootDocument).toBeDefined();
|
|
@@ -383,7 +386,7 @@ describe('collect refs', () => {
|
|
|
383
386
|
components:
|
|
384
387
|
$ref: "./transitive/components.yaml#/components/schemas/a"
|
|
385
388
|
`,
|
|
386
|
-
path.join(cwd, 'foobar.yaml')
|
|
389
|
+
path.join(cwd, 'foobar.yaml')
|
|
387
390
|
);
|
|
388
391
|
|
|
389
392
|
const resolvedRefs = await resolveDocument({
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
pickObjectProps,
|
|
3
|
+
omitObjectProps,
|
|
4
|
+
slash,
|
|
5
|
+
getMatchingStatusCodeRange,
|
|
6
|
+
doesYamlFileExist,
|
|
7
|
+
} from '../utils';
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
2
10
|
|
|
3
11
|
describe('utils', () => {
|
|
4
12
|
const testObject = {
|
|
@@ -81,5 +89,38 @@ describe('utils', () => {
|
|
|
81
89
|
expect(getMatchingStatusCodeRange('2002')).toEqual('2002');
|
|
82
90
|
expect(getMatchingStatusCodeRange(4000)).toEqual('4000');
|
|
83
91
|
});
|
|
92
|
+
|
|
93
|
+
describe('isConfigFileExist', () => {
|
|
94
|
+
beforeEach(() => {
|
|
95
|
+
jest
|
|
96
|
+
.spyOn(fs, 'existsSync')
|
|
97
|
+
.mockImplementation((path) => path === 'redocly.yaml' || path === 'redocly.yml');
|
|
98
|
+
jest.spyOn(path, 'extname').mockImplementation((path) => {
|
|
99
|
+
if (path.endsWith('.yaml')) {
|
|
100
|
+
return '.yaml';
|
|
101
|
+
} else if (path.endsWith('.yml')) {
|
|
102
|
+
return '.yml';
|
|
103
|
+
} else {
|
|
104
|
+
return '';
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should return true because of valid path provided', () => {
|
|
110
|
+
expect(doesYamlFileExist('redocly.yaml')).toBe(true);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should return true because of valid path provided with yml', () => {
|
|
114
|
+
expect(doesYamlFileExist('redocly.yml')).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should return false because of fail do not exist', () => {
|
|
118
|
+
expect(doesYamlFileExist('redoccccly.yaml')).toBe(false);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should return false because of it is not yaml file', () => {
|
|
122
|
+
expect(doesYamlFileExist('redocly.yam')).toBe(false);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
84
125
|
});
|
|
85
126
|
});
|
|
@@ -4,7 +4,11 @@ import * as path from 'path';
|
|
|
4
4
|
|
|
5
5
|
import { lintDocument } from '../lint';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
parseYamlToDocument,
|
|
9
|
+
replaceSourceWithRef,
|
|
10
|
+
makeConfigForRuleset,
|
|
11
|
+
} from '../../__tests__/utils';
|
|
8
12
|
import { BaseResolver, Document } from '../resolve';
|
|
9
13
|
import { listOf } from '../types';
|
|
10
14
|
import { Oas3RuleSet } from '../oas-types';
|
|
@@ -43,7 +47,7 @@ describe('walk order', () => {
|
|
|
43
47
|
contact: {}
|
|
44
48
|
license: {}
|
|
45
49
|
`,
|
|
46
|
-
''
|
|
50
|
+
''
|
|
47
51
|
);
|
|
48
52
|
|
|
49
53
|
await lintDocument({
|
|
@@ -70,14 +74,10 @@ describe('walk order', () => {
|
|
|
70
74
|
leave: jest.fn((op) => calls.push(`leave operation: ${op.operationId}`)),
|
|
71
75
|
Parameter: {
|
|
72
76
|
enter: jest.fn((param, _ctx, parents) =>
|
|
73
|
-
calls.push(
|
|
74
|
-
`enter operation ${parents.Operation.operationId} > param ${param.name}`,
|
|
75
|
-
),
|
|
77
|
+
calls.push(`enter operation ${parents.Operation.operationId} > param ${param.name}`)
|
|
76
78
|
),
|
|
77
79
|
leave: jest.fn((param, _ctx, parents) =>
|
|
78
|
-
calls.push(
|
|
79
|
-
`leave operation ${parents.Operation.operationId} > param ${param.name}`,
|
|
80
|
-
),
|
|
80
|
+
calls.push(`leave operation ${parents.Operation.operationId} > param ${param.name}`)
|
|
81
81
|
),
|
|
82
82
|
},
|
|
83
83
|
},
|
|
@@ -110,7 +110,7 @@ describe('walk order', () => {
|
|
|
110
110
|
- name: post_a
|
|
111
111
|
|
|
112
112
|
`,
|
|
113
|
-
''
|
|
113
|
+
''
|
|
114
114
|
);
|
|
115
115
|
|
|
116
116
|
await lintDocument({
|
|
@@ -154,14 +154,10 @@ describe('walk order', () => {
|
|
|
154
154
|
leave: jest.fn((op) => calls.push(`leave operation: ${op.operationId}`)),
|
|
155
155
|
Parameter: {
|
|
156
156
|
enter: jest.fn((param, _ctx, parents) =>
|
|
157
|
-
calls.push(
|
|
158
|
-
`enter operation ${parents.Operation.operationId} > param ${param.name}`,
|
|
159
|
-
),
|
|
157
|
+
calls.push(`enter operation ${parents.Operation.operationId} > param ${param.name}`)
|
|
160
158
|
),
|
|
161
159
|
leave: jest.fn((param, _ctx, parents) =>
|
|
162
|
-
calls.push(
|
|
163
|
-
`leave operation ${parents.Operation.operationId} > param ${param.name}`,
|
|
164
|
-
),
|
|
160
|
+
calls.push(`leave operation ${parents.Operation.operationId} > param ${param.name}`)
|
|
165
161
|
),
|
|
166
162
|
},
|
|
167
163
|
},
|
|
@@ -194,7 +190,7 @@ describe('walk order', () => {
|
|
|
194
190
|
- name: post_a
|
|
195
191
|
|
|
196
192
|
`,
|
|
197
|
-
''
|
|
193
|
+
''
|
|
198
194
|
);
|
|
199
195
|
|
|
200
196
|
await lintDocument({
|
|
@@ -238,14 +234,10 @@ describe('walk order', () => {
|
|
|
238
234
|
leave: jest.fn((op) => calls.push(`leave operation: ${op.operationId}`)),
|
|
239
235
|
Parameter: {
|
|
240
236
|
enter: jest.fn((param, _ctx, parents) =>
|
|
241
|
-
calls.push(
|
|
242
|
-
`enter operation ${parents.Operation.operationId} > param ${param.name}`,
|
|
243
|
-
),
|
|
237
|
+
calls.push(`enter operation ${parents.Operation.operationId} > param ${param.name}`)
|
|
244
238
|
),
|
|
245
239
|
leave: jest.fn((param, _ctx, parents) =>
|
|
246
|
-
calls.push(
|
|
247
|
-
`leave operation ${parents.Operation.operationId} > param ${param.name}`,
|
|
248
|
-
),
|
|
240
|
+
calls.push(`leave operation ${parents.Operation.operationId} > param ${param.name}`)
|
|
249
241
|
),
|
|
250
242
|
},
|
|
251
243
|
},
|
|
@@ -279,7 +271,7 @@ describe('walk order', () => {
|
|
|
279
271
|
shared_a:
|
|
280
272
|
name: shared-a
|
|
281
273
|
`,
|
|
282
|
-
''
|
|
274
|
+
''
|
|
283
275
|
);
|
|
284
276
|
|
|
285
277
|
await lintDocument({
|
|
@@ -317,7 +309,7 @@ describe('walk order', () => {
|
|
|
317
309
|
PathItem: {
|
|
318
310
|
Parameter: {
|
|
319
311
|
enter: jest.fn((param, _ctx, parents) =>
|
|
320
|
-
calls.push(`enter path ${parents.PathItem.id} > param ${param.name}`)
|
|
312
|
+
calls.push(`enter path ${parents.PathItem.id} > param ${param.name}`)
|
|
321
313
|
),
|
|
322
314
|
},
|
|
323
315
|
},
|
|
@@ -351,7 +343,7 @@ describe('walk order', () => {
|
|
|
351
343
|
shared_a:
|
|
352
344
|
name: shared-a
|
|
353
345
|
`,
|
|
354
|
-
''
|
|
346
|
+
''
|
|
355
347
|
);
|
|
356
348
|
|
|
357
349
|
await lintDocument({
|
|
@@ -379,15 +371,15 @@ describe('walk order', () => {
|
|
|
379
371
|
PathItem: {
|
|
380
372
|
Parameter: {
|
|
381
373
|
enter: jest.fn((param, _ctx, parents) =>
|
|
382
|
-
calls.push(`enter path ${parents.PathItem.id} > param ${param.name}`)
|
|
374
|
+
calls.push(`enter path ${parents.PathItem.id} > param ${param.name}`)
|
|
383
375
|
),
|
|
384
376
|
},
|
|
385
377
|
Operation: {
|
|
386
378
|
Parameter: {
|
|
387
379
|
enter: jest.fn((param, _ctx, parents) =>
|
|
388
380
|
calls.push(
|
|
389
|
-
`enter operation ${parents.Operation.operationId} > param ${param.name}
|
|
390
|
-
)
|
|
381
|
+
`enter operation ${parents.Operation.operationId} > param ${param.name}`
|
|
382
|
+
)
|
|
391
383
|
),
|
|
392
384
|
},
|
|
393
385
|
},
|
|
@@ -423,7 +415,7 @@ describe('walk order', () => {
|
|
|
423
415
|
shared_b:
|
|
424
416
|
name: shared-b
|
|
425
417
|
`,
|
|
426
|
-
''
|
|
418
|
+
''
|
|
427
419
|
);
|
|
428
420
|
|
|
429
421
|
await lintDocument({
|
|
@@ -452,10 +444,10 @@ describe('walk order', () => {
|
|
|
452
444
|
PathItem: {
|
|
453
445
|
Parameter: {
|
|
454
446
|
enter: jest.fn((param, _ctx, parents) =>
|
|
455
|
-
calls.push(`enter path ${parents.PathItem.id} > param ${param.name}`)
|
|
447
|
+
calls.push(`enter path ${parents.PathItem.id} > param ${param.name}`)
|
|
456
448
|
),
|
|
457
449
|
leave: jest.fn((param, _ctx, parents) =>
|
|
458
|
-
calls.push(`leave path ${parents.PathItem.id} > param ${param.name}`)
|
|
450
|
+
calls.push(`leave path ${parents.PathItem.id} > param ${param.name}`)
|
|
459
451
|
),
|
|
460
452
|
},
|
|
461
453
|
Operation(op, _ctx, parents) {
|
|
@@ -490,7 +482,7 @@ describe('walk order', () => {
|
|
|
490
482
|
shared_a:
|
|
491
483
|
name: shared-a
|
|
492
484
|
`,
|
|
493
|
-
''
|
|
485
|
+
''
|
|
494
486
|
);
|
|
495
487
|
|
|
496
488
|
await lintDocument({
|
|
@@ -544,7 +536,7 @@ describe('walk order', () => {
|
|
|
544
536
|
- $ref: "#/components/parameters/shared_a"
|
|
545
537
|
- id: 'nested'
|
|
546
538
|
`,
|
|
547
|
-
''
|
|
539
|
+
''
|
|
548
540
|
);
|
|
549
541
|
|
|
550
542
|
await lintDocument({
|
|
@@ -569,7 +561,7 @@ describe('walk order', () => {
|
|
|
569
561
|
return {
|
|
570
562
|
Parameter: {
|
|
571
563
|
Schema: jest.fn((schema: any, _ctx, parents) =>
|
|
572
|
-
calls.push(`enter param ${parents.Parameter.name} > schema ${schema.id}`)
|
|
564
|
+
calls.push(`enter param ${parents.Parameter.name} > schema ${schema.id}`)
|
|
573
565
|
),
|
|
574
566
|
},
|
|
575
567
|
};
|
|
@@ -600,7 +592,7 @@ describe('walk order', () => {
|
|
|
600
592
|
- $ref: "#/components/parameters/shared_a"
|
|
601
593
|
- id: 'nested'
|
|
602
594
|
`,
|
|
603
|
-
''
|
|
595
|
+
''
|
|
604
596
|
);
|
|
605
597
|
|
|
606
598
|
await lintDocument({
|
|
@@ -642,7 +634,7 @@ describe('walk order', () => {
|
|
|
642
634
|
put:
|
|
643
635
|
operationId: put
|
|
644
636
|
`,
|
|
645
|
-
''
|
|
637
|
+
''
|
|
646
638
|
);
|
|
647
639
|
|
|
648
640
|
await lintDocument({
|
|
@@ -668,7 +660,7 @@ describe('walk order', () => {
|
|
|
668
660
|
Operation: {
|
|
669
661
|
skip: (op) => op.operationId === 'put',
|
|
670
662
|
Parameter: jest.fn((param, _ctx, parents) =>
|
|
671
|
-
calls.push(`enter operation ${parents.Operation.operationId} > param ${param.name}`)
|
|
663
|
+
calls.push(`enter operation ${parents.Operation.operationId} > param ${param.name}`)
|
|
672
664
|
),
|
|
673
665
|
},
|
|
674
666
|
};
|
|
@@ -697,7 +689,7 @@ describe('walk order', () => {
|
|
|
697
689
|
shared_a:
|
|
698
690
|
name: shared-a
|
|
699
691
|
`,
|
|
700
|
-
''
|
|
692
|
+
''
|
|
701
693
|
);
|
|
702
694
|
|
|
703
695
|
await lintDocument({
|
|
@@ -724,10 +716,10 @@ describe('walk order', () => {
|
|
|
724
716
|
PathItem: {
|
|
725
717
|
Parameter: {
|
|
726
718
|
enter: jest.fn((param, _ctx, parents) =>
|
|
727
|
-
calls.push(`enter path ${parents.PathItem.id} > param ${param.name}`)
|
|
719
|
+
calls.push(`enter path ${parents.PathItem.id} > param ${param.name}`)
|
|
728
720
|
),
|
|
729
721
|
leave: jest.fn((param, _ctx, parents) =>
|
|
730
|
-
calls.push(`leave path ${parents.PathItem.id} > param ${param.name}`)
|
|
722
|
+
calls.push(`leave path ${parents.PathItem.id} > param ${param.name}`)
|
|
731
723
|
),
|
|
732
724
|
},
|
|
733
725
|
Operation: {
|
|
@@ -735,13 +727,13 @@ describe('walk order', () => {
|
|
|
735
727
|
Parameter: {
|
|
736
728
|
enter: jest.fn((param, _ctx, parents) =>
|
|
737
729
|
calls.push(
|
|
738
|
-
`enter operation ${parents.Operation.operationId} > param ${param.name}
|
|
739
|
-
)
|
|
730
|
+
`enter operation ${parents.Operation.operationId} > param ${param.name}`
|
|
731
|
+
)
|
|
740
732
|
),
|
|
741
733
|
leave: jest.fn((param, _ctx, parents) =>
|
|
742
734
|
calls.push(
|
|
743
|
-
`leave operation ${parents.Operation.operationId} > param ${param.name}
|
|
744
|
-
)
|
|
735
|
+
`leave operation ${parents.Operation.operationId} > param ${param.name}`
|
|
736
|
+
)
|
|
745
737
|
),
|
|
746
738
|
},
|
|
747
739
|
},
|
|
@@ -783,7 +775,7 @@ describe('walk order', () => {
|
|
|
783
775
|
shared_b:
|
|
784
776
|
name: shared-b
|
|
785
777
|
`,
|
|
786
|
-
''
|
|
778
|
+
''
|
|
787
779
|
);
|
|
788
780
|
|
|
789
781
|
await lintDocument({
|
|
@@ -817,10 +809,10 @@ describe('walk order', () => {
|
|
|
817
809
|
Schema: {
|
|
818
810
|
Schema: {
|
|
819
811
|
enter: jest.fn((schema: any, _ctx, parents) =>
|
|
820
|
-
calls.push(`enter nested schema ${parents.Schema.id} > ${schema.id}`)
|
|
812
|
+
calls.push(`enter nested schema ${parents.Schema.id} > ${schema.id}`)
|
|
821
813
|
),
|
|
822
814
|
leave: jest.fn((schema: any, _ctx, parents) =>
|
|
823
|
-
calls.push(`leave nested schema ${parents.Schema.id} > ${schema.id}`)
|
|
815
|
+
calls.push(`leave nested schema ${parents.Schema.id} > ${schema.id}`)
|
|
824
816
|
),
|
|
825
817
|
},
|
|
826
818
|
},
|
|
@@ -862,7 +854,7 @@ describe('walk order', () => {
|
|
|
862
854
|
a:
|
|
863
855
|
id: inline-nested-nested
|
|
864
856
|
`,
|
|
865
|
-
'foobar.yaml'
|
|
857
|
+
'foobar.yaml'
|
|
866
858
|
);
|
|
867
859
|
|
|
868
860
|
await lintDocument({
|
|
@@ -934,7 +926,7 @@ describe('walk order', () => {
|
|
|
934
926
|
schema:
|
|
935
927
|
$ref: '#/components/parameters/shared_b'
|
|
936
928
|
`,
|
|
937
|
-
'foobar.yaml'
|
|
929
|
+
'foobar.yaml'
|
|
938
930
|
);
|
|
939
931
|
|
|
940
932
|
await lintDocument({
|
|
@@ -978,7 +970,7 @@ describe('walk order', () => {
|
|
|
978
970
|
b:
|
|
979
971
|
type: number
|
|
980
972
|
`,
|
|
981
|
-
'foobar.yaml'
|
|
973
|
+
'foobar.yaml'
|
|
982
974
|
);
|
|
983
975
|
|
|
984
976
|
await lintDocument({
|
|
@@ -1043,7 +1035,7 @@ describe('walk order', () => {
|
|
|
1043
1035
|
a:
|
|
1044
1036
|
type: object
|
|
1045
1037
|
`,
|
|
1046
|
-
''
|
|
1038
|
+
''
|
|
1047
1039
|
);
|
|
1048
1040
|
|
|
1049
1041
|
await lintDocument({
|
|
@@ -1131,7 +1123,7 @@ describe('context.report', () => {
|
|
|
1131
1123
|
shared_a:
|
|
1132
1124
|
name: shared_a
|
|
1133
1125
|
`,
|
|
1134
|
-
'foobar.yaml'
|
|
1126
|
+
'foobar.yaml'
|
|
1135
1127
|
);
|
|
1136
1128
|
|
|
1137
1129
|
const results = await lintDocument({
|
|
@@ -1207,7 +1199,7 @@ describe('context.report', () => {
|
|
|
1207
1199
|
const externalRefResolver = new BaseResolver();
|
|
1208
1200
|
const document = (await externalRefResolver.resolveDocument(
|
|
1209
1201
|
null,
|
|
1210
|
-
`${cwd}/openapi-with-external-refs.yaml
|
|
1202
|
+
`${cwd}/openapi-with-external-refs.yaml`
|
|
1211
1203
|
)) as Document;
|
|
1212
1204
|
|
|
1213
1205
|
if (document === null) {
|
|
@@ -1319,7 +1311,7 @@ describe('context.resolve', () => {
|
|
|
1319
1311
|
a:
|
|
1320
1312
|
$ref: '#/components/schemas/b'
|
|
1321
1313
|
`,
|
|
1322
|
-
'foobar.yaml'
|
|
1314
|
+
'foobar.yaml'
|
|
1323
1315
|
);
|
|
1324
1316
|
|
|
1325
1317
|
await lintDocument({
|
|
@@ -1368,7 +1360,7 @@ describe('type extensions', () => {
|
|
|
1368
1360
|
parameters:
|
|
1369
1361
|
- name: a
|
|
1370
1362
|
`,
|
|
1371
|
-
'foobar.yaml'
|
|
1363
|
+
'foobar.yaml'
|
|
1372
1364
|
);
|
|
1373
1365
|
|
|
1374
1366
|
await lintDocument({
|
|
@@ -1462,7 +1454,7 @@ describe('ignoreNextRules', () => {
|
|
|
1462
1454
|
put:
|
|
1463
1455
|
operationId: put
|
|
1464
1456
|
`,
|
|
1465
|
-
''
|
|
1457
|
+
''
|
|
1466
1458
|
);
|
|
1467
1459
|
|
|
1468
1460
|
await lintDocument({
|
|
@@ -9,7 +9,7 @@ export const count = 10;
|
|
|
9
9
|
const rebillyDefinitionRef = pathResolve(pathJoin(__dirname, 'rebilly.yaml'));
|
|
10
10
|
const rebillyDocument = parseYamlToDocument(
|
|
11
11
|
readFileSync(rebillyDefinitionRef, 'utf-8'),
|
|
12
|
-
rebillyDefinitionRef
|
|
12
|
+
rebillyDefinitionRef
|
|
13
13
|
);
|
|
14
14
|
|
|
15
15
|
const ruleset: any = {};
|
|
@@ -9,7 +9,7 @@ export const count = 10;
|
|
|
9
9
|
const rebillyDefinitionRef = pathResolve(pathJoin(__dirname, 'rebilly.yaml'));
|
|
10
10
|
const rebillyDocument = parseYamlToDocument(
|
|
11
11
|
readFileSync(rebillyDefinitionRef, 'utf-8'),
|
|
12
|
-
rebillyDefinitionRef
|
|
12
|
+
rebillyDefinitionRef
|
|
13
13
|
);
|
|
14
14
|
const visitor = {
|
|
15
15
|
test: () => {
|
|
@@ -8,7 +8,7 @@ export const count = 10;
|
|
|
8
8
|
const rebillyDefinitionRef = pathResolve(pathJoin(__dirname, 'rebilly.yaml'));
|
|
9
9
|
const rebillyDocument = parseYamlToDocument(
|
|
10
10
|
readFileSync(rebillyDefinitionRef, 'utf-8'),
|
|
11
|
-
rebillyDefinitionRef
|
|
11
|
+
rebillyDefinitionRef
|
|
12
12
|
);
|
|
13
13
|
const config = makeConfigForRuleset({});
|
|
14
14
|
export function measureAsync() {
|
|
@@ -9,7 +9,7 @@ export const count = 10;
|
|
|
9
9
|
const rebillyDefinitionRef = pathResolve(pathJoin(__dirname, 'rebilly.yaml'));
|
|
10
10
|
const rebillyDocument = parseYamlToDocument(
|
|
11
11
|
readFileSync(rebillyDefinitionRef, 'utf-8'),
|
|
12
|
-
rebillyDefinitionRef
|
|
12
|
+
rebillyDefinitionRef
|
|
13
13
|
);
|
|
14
14
|
|
|
15
15
|
const config = makeConfigForRuleset({
|
|
@@ -8,7 +8,7 @@ export const count = 10;
|
|
|
8
8
|
const rebillyDefinitionRef = pathResolve(pathJoin(__dirname, 'rebilly.yaml'));
|
|
9
9
|
const rebillyDocument = parseYamlToDocument(
|
|
10
10
|
readFileSync(rebillyDefinitionRef, 'utf-8'),
|
|
11
|
-
rebillyDefinitionRef
|
|
11
|
+
rebillyDefinitionRef
|
|
12
12
|
);
|
|
13
13
|
|
|
14
14
|
const config = makeConfigForRuleset({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
2
|
import { join as pathJoin, resolve as pathResolve } from 'path';
|
|
3
3
|
import { lintDocument } from '../../lint';
|
|
4
|
-
import {
|
|
4
|
+
import { StyleguideConfig, defaultPlugin, resolvePreset } from '../../config';
|
|
5
5
|
import { BaseResolver } from '../../resolve';
|
|
6
6
|
import { parseYamlToDocument } from '../utils';
|
|
7
7
|
|
|
@@ -10,13 +10,13 @@ export const count = 10;
|
|
|
10
10
|
const rebillyDefinitionRef = pathResolve(pathJoin(__dirname, 'rebilly.yaml'));
|
|
11
11
|
const rebillyDocument = parseYamlToDocument(
|
|
12
12
|
readFileSync(rebillyDefinitionRef, 'utf-8'),
|
|
13
|
-
rebillyDefinitionRef
|
|
13
|
+
rebillyDefinitionRef
|
|
14
14
|
);
|
|
15
15
|
|
|
16
16
|
export function measureAsync() {
|
|
17
17
|
return lintDocument({
|
|
18
18
|
externalRefResolver: new BaseResolver(),
|
|
19
19
|
document: rebillyDocument,
|
|
20
|
-
config: new
|
|
20
|
+
config: new StyleguideConfig(resolvePreset('recommended', [defaultPlugin])),
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -10,7 +10,7 @@ export const count = 10;
|
|
|
10
10
|
const rebillyDefinitionRef = path.resolve(path.join(__dirname, 'rebilly.yaml'));
|
|
11
11
|
const rebillyDocument = parseYamlToDocument(
|
|
12
12
|
readFileSync(rebillyDefinitionRef, 'utf-8'),
|
|
13
|
-
rebillyDefinitionRef
|
|
13
|
+
rebillyDefinitionRef
|
|
14
14
|
);
|
|
15
15
|
const externalRefResolver = new BaseResolver();
|
|
16
16
|
|
|
@@ -31,7 +31,7 @@ function prepareRevision(revision) {
|
|
|
31
31
|
const hash = exec(`git rev-parse "${revision}"`);
|
|
32
32
|
const dir = path.join(os.tmpdir(), 'redocly-cli-benchmark', hash);
|
|
33
33
|
if (fs.existsSync(dir)) {
|
|
34
|
-
fs.rmdirSync(dir, { recursive: true});
|
|
34
|
+
fs.rmdirSync(dir, { recursive: true });
|
|
35
35
|
}
|
|
36
36
|
fs.mkdirSync(dir, { recursive: true });
|
|
37
37
|
|
|
@@ -48,7 +48,10 @@ function tscBuild(dir) {
|
|
|
48
48
|
process.chdir(dir);
|
|
49
49
|
execSync('npm run compile', { stdio: 'inherit' });
|
|
50
50
|
exec(
|
|
51
|
-
`cp ${path.join(dir, 'packages/core/src/benchmark/benches/*.yaml')} ${path.join(
|
|
51
|
+
`cp ${path.join(dir, 'packages/core/src/benchmark/benches/*.yaml')} ${path.join(
|
|
52
|
+
dir,
|
|
53
|
+
'packages/core/lib/benchmark/benches/'
|
|
54
|
+
)}`
|
|
52
55
|
);
|
|
53
56
|
process.chdir(oldCwd);
|
|
54
57
|
return path.join(dir, 'packages/core/lib/benchmark/benches');
|
|
@@ -70,7 +73,8 @@ async function collectSamples(modulePath) {
|
|
|
70
73
|
|
|
71
74
|
// T-Distribution two-tailed critical values for 95% confidence.
|
|
72
75
|
// See http://www.itl.nist.gov/div898/handbook/eda/section3/eda3672.htm.
|
|
73
|
-
const tTable =
|
|
76
|
+
const tTable =
|
|
77
|
+
/* prettier-ignore */ {
|
|
74
78
|
'1': 12.706, '2': 4.303, '3': 3.182, '4': 2.776, '5': 2.571, '6': 2.447,
|
|
75
79
|
'7': 2.365, '8': 2.306, '9': 2.262, '10': 2.228, '11': 2.201, '12': 2.179,
|
|
76
80
|
'13': 2.16, '14': 2.145, '15': 2.131, '16': 2.12, '17': 2.11, '18': 2.101,
|
|
@@ -150,7 +154,7 @@ function beautifyBenchmark(results) {
|
|
|
150
154
|
grey(' x ') +
|
|
151
155
|
memPerOpStr() +
|
|
152
156
|
'/op' +
|
|
153
|
-
grey(' (' + numSamples + ' runs sampled)')
|
|
157
|
+
grey(' (' + numSamples + ' runs sampled)')
|
|
154
158
|
);
|
|
155
159
|
|
|
156
160
|
function nameStr() {
|
|
@@ -255,7 +259,7 @@ function matchBenchmarks(patterns) {
|
|
|
255
259
|
let benchmarks = findFiles(LOCAL_DIR('../lib/benchmark/benches'), '*.bench.js');
|
|
256
260
|
if (patterns.length > 0) {
|
|
257
261
|
benchmarks = benchmarks.filter((benchmark) =>
|
|
258
|
-
patterns.some((pattern) => path.join('../lib/benchmark/benches', benchmark).includes(pattern))
|
|
262
|
+
patterns.some((pattern) => path.join('../lib/benchmark/benches', benchmark).includes(pattern))
|
|
259
263
|
);
|
|
260
264
|
}
|
|
261
265
|
|
package/src/benchmark/utils.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { parseYaml } from '../js-yaml';
|
|
2
2
|
import { Document, Source } from '../resolve';
|
|
3
3
|
import { Oas3RuleSet } from '../oas-types';
|
|
4
|
-
import {
|
|
4
|
+
import { StyleguideConfig, mergeExtends, resolvePlugins } from '../config';
|
|
5
5
|
|
|
6
|
-
import type { RuleConfig, Plugin,
|
|
6
|
+
import type { RuleConfig, Plugin, ResolvedStyleguideConfig } from '../config/types';
|
|
7
7
|
|
|
8
8
|
export function parseYamlToDocument(body: string, absoluteRef: string = ''): Document {
|
|
9
9
|
return {
|
|
@@ -25,12 +25,12 @@ export function makeConfigForRuleset(rules: Oas3RuleSet, plugin?: Partial<Plugin
|
|
|
25
25
|
id: ruleId,
|
|
26
26
|
rules: { oas3: rules },
|
|
27
27
|
},
|
|
28
|
-
]) as
|
|
28
|
+
]) as ResolvedStyleguideConfig,
|
|
29
29
|
];
|
|
30
30
|
if (rules) {
|
|
31
31
|
extendConfigs.push({ rules });
|
|
32
32
|
}
|
|
33
|
-
const
|
|
33
|
+
const styleguide = mergeExtends(extendConfigs);
|
|
34
34
|
|
|
35
|
-
return new
|
|
35
|
+
return new StyleguideConfig(styleguide);
|
|
36
36
|
}
|