@redocly/openapi-core 1.0.0-beta.105 → 1.0.0-beta.108
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 +5 -5
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
- 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 +7 -4
- package/lib/config/all.d.ts +2 -2
- package/lib/config/all.js +3 -3
- 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 +70 -49
- package/lib/config/config.d.ts +8 -10
- package/lib/config/config.js +10 -7
- package/lib/config/load.d.ts +7 -0
- package/lib/config/load.js +18 -10
- package/lib/config/minimal.d.ts +2 -2
- package/lib/config/minimal.js +5 -4
- package/lib/config/recommended.d.ts +2 -2
- package/lib/config/recommended.js +5 -4
- package/lib/config/rules.d.ts +3 -3
- 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 +48 -31
- package/lib/decorators/common/registry-dependencies.js +1 -1
- package/lib/decorators/common/remove-x-internal.js +2 -2
- package/lib/env.d.ts +3 -0
- package/lib/env.js +8 -0
- package/lib/format/codeframes.js +16 -10
- package/lib/format/format.js +29 -27
- package/lib/index.d.ts +5 -5
- package/lib/index.js +4 -2
- package/lib/js-yaml/index.js +2 -6
- package/lib/lint.d.ts +2 -2
- package/lib/lint.js +16 -6
- package/lib/logger.d.ts +10 -0
- package/lib/logger.js +31 -0
- package/lib/output.d.ts +3 -0
- package/lib/output.js +9 -0
- package/lib/redocly/index.js +10 -9
- package/lib/redocly/registry-api-types.d.ts +28 -30
- package/lib/redocly/registry-api.d.ts +4 -3
- package/lib/redocly/registry-api.js +9 -4
- package/lib/ref-utils.js +2 -1
- package/lib/resolve.d.ts +1 -1
- package/lib/resolve.js +1 -1
- package/lib/rules/ajv.d.ts +1 -1
- package/lib/rules/ajv.js +7 -7
- package/lib/rules/common/assertions/asserts.js +4 -4
- package/lib/rules/common/assertions/index.js +1 -1
- 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/operation-security-defined.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 +3 -3
- package/lib/rules/oas2/index.js +4 -4
- package/lib/rules/oas2/remove-unused-components.js +5 -5
- package/lib/rules/oas3/index.js +6 -6
- 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/no-server-variables-empty-enum.d.ts +2 -0
- package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +4 -4
- package/lib/rules/oas3/no-unused-components.js +1 -1
- package/lib/rules/oas3/remove-unused-components.js +5 -5
- package/lib/rules/other/stats.js +43 -14
- package/lib/rules/utils.d.ts +3 -2
- package/lib/rules/utils.js +20 -5
- package/lib/types/index.d.ts +2 -2
- package/lib/types/redocly-yaml.js +9 -8
- package/lib/utils.d.ts +5 -0
- package/lib/utils.js +22 -5
- package/lib/visitors.d.ts +1 -1
- package/lib/visitors.js +2 -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__/js-yaml.test.ts +6 -4
- package/src/__tests__/lint.test.ts +74 -6
- package/src/__tests__/logger-browser.test.ts +53 -0
- package/src/__tests__/logger.test.ts +47 -0
- package/src/__tests__/login.test.ts +2 -2
- package/src/__tests__/normalizeVisitors.test.ts +4 -4
- package/src/__tests__/output-browser.test.ts +18 -0
- package/src/__tests__/output.test.ts +15 -0
- 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-browser.test.ts +11 -0
- package/src/__tests__/utils.test.ts +7 -0
- 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 -2
- 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 +24 -20
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +7 -5
- package/src/config/__tests__/config-resolvers.test.ts +123 -121
- package/src/config/__tests__/config.test.ts +111 -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 +79 -1
- package/src/config/__tests__/resolve-plugins.test.ts +3 -3
- package/src/config/__tests__/utils.test.ts +83 -0
- package/src/config/all.ts +5 -6
- package/src/config/builtIn.ts +5 -5
- package/src/config/config-resolvers.ts +161 -96
- package/src/config/config.ts +15 -13
- package/src/config/load.ts +34 -11
- package/src/config/minimal.ts +7 -6
- package/src/config/recommended.ts +7 -6
- package/src/config/rules.ts +6 -6
- package/src/config/types.ts +28 -19
- package/src/config/utils.ts +78 -57
- 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/registry-dependencies.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/env.ts +5 -0
- package/src/format/codeframes.ts +18 -12
- package/src/format/format.ts +37 -42
- package/src/index.ts +8 -7
- package/src/js-yaml/index.ts +4 -8
- package/src/lint.ts +22 -18
- package/src/logger.ts +34 -0
- package/src/oas-types.ts +1 -6
- package/src/output.ts +7 -0
- package/src/redocly/__tests__/redocly-client.test.ts +25 -19
- package/src/redocly/index.ts +12 -7
- package/src/redocly/registry-api-types.ts +27 -29
- package/src/redocly/registry-api.ts +22 -12
- package/src/ref-utils.ts +4 -3
- package/src/resolve.ts +11 -8
- 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/asserts.ts +4 -4
- package/src/rules/common/assertions/index.ts +7 -7
- 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/operation-security-defined.ts +1 -1
- 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 +12 -9
- 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 +14 -9
- package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
- package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
- 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 +5 -5
- 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 → no-server-variables-empty-enum.ts} +10 -11
- package/src/rules/oas3/no-unused-components.ts +1 -1
- package/src/rules/oas3/remove-unused-components.ts +21 -10
- package/src/rules/other/stats.ts +46 -17
- package/src/rules/utils.ts +20 -4
- package/src/types/index.ts +5 -5
- package/src/types/redocly-yaml.ts +9 -8
- package/src/typings/common.ts +9 -1
- package/src/typings/openapi.ts +1 -1
- package/src/utils.ts +26 -3
- package/src/visitors.ts +9 -9
- 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/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
- package/src/rules/common/license-url.ts +0 -10
|
@@ -23,7 +23,7 @@ describe('OpenAPI Schema', () => {
|
|
|
23
23
|
expect(
|
|
24
24
|
await validateDoc(source, {
|
|
25
25
|
spec: 'error',
|
|
26
|
-
})
|
|
26
|
+
})
|
|
27
27
|
).toMatchInlineSnapshot(`Array []`);
|
|
28
28
|
});
|
|
29
29
|
|
|
@@ -43,7 +43,7 @@ describe('OpenAPI Schema', () => {
|
|
|
43
43
|
expect(
|
|
44
44
|
await validateDoc(source, {
|
|
45
45
|
spec: 'error',
|
|
46
|
-
})
|
|
46
|
+
})
|
|
47
47
|
).toMatchInlineSnapshot(`Array []`);
|
|
48
48
|
});
|
|
49
49
|
|
|
@@ -61,7 +61,7 @@ describe('OpenAPI Schema', () => {
|
|
|
61
61
|
expect(
|
|
62
62
|
await validateDoc(source, {
|
|
63
63
|
spec: 'error',
|
|
64
|
-
})
|
|
64
|
+
})
|
|
65
65
|
).toMatchInlineSnapshot(`
|
|
66
66
|
Array [
|
|
67
67
|
Object {
|
|
@@ -88,7 +88,7 @@ describe('OpenAPI Schema', () => {
|
|
|
88
88
|
expect(
|
|
89
89
|
await validateDoc(source, {
|
|
90
90
|
spec: 'error',
|
|
91
|
-
})
|
|
91
|
+
})
|
|
92
92
|
).toMatchInlineSnapshot(`Array []`);
|
|
93
93
|
});
|
|
94
94
|
|
|
@@ -114,7 +114,7 @@ describe('OpenAPI Schema', () => {
|
|
|
114
114
|
expect(
|
|
115
115
|
await validateDoc(source, {
|
|
116
116
|
spec: 'error',
|
|
117
|
-
})
|
|
117
|
+
})
|
|
118
118
|
).toMatchInlineSnapshot(`
|
|
119
119
|
Array [
|
|
120
120
|
Object {
|
|
@@ -151,7 +151,7 @@ describe('OpenAPI Schema', () => {
|
|
|
151
151
|
expect(
|
|
152
152
|
await validateDoc(source, {
|
|
153
153
|
'no-identical-paths': 'error',
|
|
154
|
-
})
|
|
154
|
+
})
|
|
155
155
|
).toMatchInlineSnapshot(`
|
|
156
156
|
Array [
|
|
157
157
|
Object {
|
|
@@ -188,7 +188,7 @@ describe('OpenAPI Schema', () => {
|
|
|
188
188
|
expect(
|
|
189
189
|
await validateDoc(source, {
|
|
190
190
|
spec: 'error',
|
|
191
|
-
})
|
|
191
|
+
})
|
|
192
192
|
).toMatchInlineSnapshot(`Array []`);
|
|
193
193
|
});
|
|
194
194
|
|
|
@@ -218,7 +218,7 @@ describe('OpenAPI Schema', () => {
|
|
|
218
218
|
expect(
|
|
219
219
|
await validateDoc(source, {
|
|
220
220
|
spec: 'error',
|
|
221
|
-
})
|
|
221
|
+
})
|
|
222
222
|
).toMatchInlineSnapshot(`Array []`);
|
|
223
223
|
});
|
|
224
224
|
|
|
@@ -239,7 +239,7 @@ describe('OpenAPI Schema', () => {
|
|
|
239
239
|
expect(
|
|
240
240
|
await validateDoc(source, {
|
|
241
241
|
spec: 'error',
|
|
242
|
-
})
|
|
242
|
+
})
|
|
243
243
|
).toMatchInlineSnapshot(`Array []`);
|
|
244
244
|
});
|
|
245
245
|
|
|
@@ -278,7 +278,7 @@ describe('OpenAPI Schema', () => {
|
|
|
278
278
|
expect(
|
|
279
279
|
await validateDoc(source, {
|
|
280
280
|
spec: 'error',
|
|
281
|
-
})
|
|
281
|
+
})
|
|
282
282
|
).toMatchInlineSnapshot(`Array []`);
|
|
283
283
|
});
|
|
284
284
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { outdent } from 'outdent';
|
|
2
2
|
import { parseYamlToDocument, replaceSourceWithRef } from '../../../../../__tests__/utils';
|
|
3
3
|
import { lintDocument } from '../../../../lint';
|
|
4
|
-
import {
|
|
4
|
+
import { StyleguideConfig } from '../../../..';
|
|
5
5
|
import { BaseResolver } from '../../../../resolve';
|
|
6
|
-
import {
|
|
6
|
+
import { resolveStyleguideConfig } from '../../../../config';
|
|
7
7
|
|
|
8
8
|
describe('Referenceable scalars', () => {
|
|
9
9
|
it('should not report $ref description', async () => {
|
|
@@ -17,22 +17,22 @@ describe('Referenceable scalars', () => {
|
|
|
17
17
|
$ref: fixtures/description.md
|
|
18
18
|
paths: {}
|
|
19
19
|
`,
|
|
20
|
-
__dirname + '/foobar.yaml'
|
|
20
|
+
__dirname + '/foobar.yaml'
|
|
21
21
|
);
|
|
22
22
|
|
|
23
23
|
const results = await lintDocument({
|
|
24
24
|
externalRefResolver: new BaseResolver(),
|
|
25
25
|
document,
|
|
26
|
-
config: new
|
|
27
|
-
await
|
|
28
|
-
|
|
26
|
+
config: new StyleguideConfig(
|
|
27
|
+
await resolveStyleguideConfig({
|
|
28
|
+
styleguideConfig: {
|
|
29
29
|
extends: [],
|
|
30
30
|
rules: {
|
|
31
31
|
spec: 'error',
|
|
32
32
|
'no-unresolved-refs': 'error',
|
|
33
33
|
},
|
|
34
34
|
},
|
|
35
|
-
})
|
|
35
|
+
})
|
|
36
36
|
),
|
|
37
37
|
});
|
|
38
38
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
|
|
@@ -54,22 +54,22 @@ describe('Referenceable scalars', () => {
|
|
|
54
54
|
example:
|
|
55
55
|
$ref: not $ref, example
|
|
56
56
|
`,
|
|
57
|
-
__dirname + '/foobar.yaml'
|
|
57
|
+
__dirname + '/foobar.yaml'
|
|
58
58
|
);
|
|
59
59
|
|
|
60
60
|
const results = await lintDocument({
|
|
61
61
|
externalRefResolver: new BaseResolver(),
|
|
62
62
|
document,
|
|
63
|
-
config: new
|
|
64
|
-
await
|
|
65
|
-
|
|
63
|
+
config: new StyleguideConfig(
|
|
64
|
+
await resolveStyleguideConfig({
|
|
65
|
+
styleguideConfig: {
|
|
66
66
|
extends: [],
|
|
67
67
|
rules: {
|
|
68
68
|
'no-unresolved-refs': 'error',
|
|
69
69
|
},
|
|
70
70
|
doNotResolveExamples: true,
|
|
71
71
|
},
|
|
72
|
-
})
|
|
72
|
+
})
|
|
73
73
|
),
|
|
74
74
|
});
|
|
75
75
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
|
|
@@ -24,7 +24,7 @@ describe('OpenAPI Schema', () => {
|
|
|
24
24
|
expect(
|
|
25
25
|
await validateDoc(source, {
|
|
26
26
|
spec: 'error',
|
|
27
|
-
})
|
|
27
|
+
})
|
|
28
28
|
).toMatchInlineSnapshot(`Array []`);
|
|
29
29
|
});
|
|
30
30
|
|
|
@@ -49,7 +49,7 @@ describe('OpenAPI Schema', () => {
|
|
|
49
49
|
expect(
|
|
50
50
|
await validateDoc(source, {
|
|
51
51
|
spec: 'error',
|
|
52
|
-
})
|
|
52
|
+
})
|
|
53
53
|
).toMatchInlineSnapshot(`
|
|
54
54
|
Array [
|
|
55
55
|
Object {
|
|
@@ -81,7 +81,7 @@ describe('OpenAPI Schema', () => {
|
|
|
81
81
|
expect(
|
|
82
82
|
await validateDoc(source, {
|
|
83
83
|
spec: 'error',
|
|
84
|
-
})
|
|
84
|
+
})
|
|
85
85
|
).toMatchInlineSnapshot(`
|
|
86
86
|
Array [
|
|
87
87
|
Object {
|
|
@@ -114,7 +114,7 @@ describe('OpenAPI Schema', () => {
|
|
|
114
114
|
expect(
|
|
115
115
|
await validateDoc(source, {
|
|
116
116
|
spec: 'error',
|
|
117
|
-
})
|
|
117
|
+
})
|
|
118
118
|
).toMatchInlineSnapshot(`
|
|
119
119
|
Array [
|
|
120
120
|
Object {
|
|
@@ -146,7 +146,7 @@ describe('OpenAPI Schema', () => {
|
|
|
146
146
|
expect(
|
|
147
147
|
await validateDoc(source, {
|
|
148
148
|
spec: 'error',
|
|
149
|
-
})
|
|
149
|
+
})
|
|
150
150
|
).toMatchInlineSnapshot(`Array []`);
|
|
151
151
|
});
|
|
152
152
|
|
|
@@ -171,7 +171,7 @@ describe('OpenAPI Schema', () => {
|
|
|
171
171
|
expect(
|
|
172
172
|
await validateDoc(source, {
|
|
173
173
|
spec: 'error',
|
|
174
|
-
})
|
|
174
|
+
})
|
|
175
175
|
).toMatchInlineSnapshot(`
|
|
176
176
|
Array [
|
|
177
177
|
Object {
|
|
@@ -208,7 +208,7 @@ describe('OpenAPI Schema', () => {
|
|
|
208
208
|
expect(
|
|
209
209
|
await validateDoc(source, {
|
|
210
210
|
spec: 'error',
|
|
211
|
-
})
|
|
211
|
+
})
|
|
212
212
|
).toMatchInlineSnapshot(`Array []`);
|
|
213
213
|
});
|
|
214
214
|
|
|
@@ -243,7 +243,7 @@ describe('OpenAPI Schema', () => {
|
|
|
243
243
|
expect(
|
|
244
244
|
await validateDoc(source, {
|
|
245
245
|
spec: 'error',
|
|
246
|
-
})
|
|
246
|
+
})
|
|
247
247
|
).toMatchInlineSnapshot(`Array []`);
|
|
248
248
|
});
|
|
249
249
|
|
|
@@ -277,7 +277,7 @@ describe('OpenAPI Schema', () => {
|
|
|
277
277
|
expect(
|
|
278
278
|
await validateDoc(source, {
|
|
279
279
|
spec: 'error',
|
|
280
|
-
})
|
|
280
|
+
})
|
|
281
281
|
).toMatchInlineSnapshot(`
|
|
282
282
|
Array [
|
|
283
283
|
Object {
|
|
@@ -317,7 +317,7 @@ describe('OpenAPI Schema', () => {
|
|
|
317
317
|
expect(
|
|
318
318
|
await validateDoc(source, {
|
|
319
319
|
'no-undefined-server-variable': 'error',
|
|
320
|
-
})
|
|
320
|
+
})
|
|
321
321
|
).toMatchInlineSnapshot(`
|
|
322
322
|
Array [
|
|
323
323
|
Object {
|
|
@@ -357,7 +357,7 @@ describe('OpenAPI Schema', () => {
|
|
|
357
357
|
expect(
|
|
358
358
|
await validateDoc(source, {
|
|
359
359
|
spec: 'error',
|
|
360
|
-
})
|
|
360
|
+
})
|
|
361
361
|
).toMatchInlineSnapshot(`
|
|
362
362
|
Array [
|
|
363
363
|
Object {
|
|
@@ -403,7 +403,7 @@ describe('OpenAPI Schema', () => {
|
|
|
403
403
|
expect(
|
|
404
404
|
await validateDoc(source, {
|
|
405
405
|
spec: 'error',
|
|
406
|
-
})
|
|
406
|
+
})
|
|
407
407
|
).toMatchInlineSnapshot(`
|
|
408
408
|
Array [
|
|
409
409
|
Object {
|
|
@@ -447,7 +447,7 @@ describe('OpenAPI Schema', () => {
|
|
|
447
447
|
expect(
|
|
448
448
|
await validateDoc(source, {
|
|
449
449
|
spec: 'error',
|
|
450
|
-
})
|
|
450
|
+
})
|
|
451
451
|
).toMatchInlineSnapshot(`Array []`);
|
|
452
452
|
});
|
|
453
453
|
|
|
@@ -469,7 +469,7 @@ describe('OpenAPI Schema', () => {
|
|
|
469
469
|
expect(
|
|
470
470
|
await validateDoc(source, {
|
|
471
471
|
spec: 'error',
|
|
472
|
-
})
|
|
472
|
+
})
|
|
473
473
|
).toMatchInlineSnapshot(`Array []`);
|
|
474
474
|
});
|
|
475
475
|
|
|
@@ -493,7 +493,7 @@ describe('OpenAPI Schema', () => {
|
|
|
493
493
|
expect(
|
|
494
494
|
await validateDoc(source, {
|
|
495
495
|
spec: 'error',
|
|
496
|
-
})
|
|
496
|
+
})
|
|
497
497
|
).toMatchInlineSnapshot(`Array []`);
|
|
498
498
|
});
|
|
499
499
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { outdent } from 'outdent';
|
|
2
2
|
import { lintDocument } from '../../../../lint';
|
|
3
3
|
import { parseYamlToDocument, replaceSourceWithRef } from '../../../../../__tests__/utils';
|
|
4
|
-
import {
|
|
4
|
+
import { StyleguideConfig, defaultPlugin, resolvePlugins, resolvePreset } from '../../../../config';
|
|
5
5
|
|
|
6
6
|
import { BaseResolver } from '../../../../resolve';
|
|
7
7
|
|
|
8
8
|
const plugins = resolvePlugins([defaultPlugin]);
|
|
9
9
|
const pressets = resolvePreset('all', plugins);
|
|
10
|
-
const allConfig = new
|
|
10
|
+
const allConfig = new StyleguideConfig({ ...pressets, plugins });
|
|
11
11
|
describe('Oas3 Structural visitor basic', () => {
|
|
12
12
|
it('should report wrong types', async () => {
|
|
13
13
|
const document = parseYamlToDocument(
|
|
@@ -35,7 +35,7 @@ describe('Oas3 Structural visitor basic', () => {
|
|
|
35
35
|
license: invalid
|
|
36
36
|
paths: {}
|
|
37
37
|
`,
|
|
38
|
-
'foobar.yaml'
|
|
38
|
+
'foobar.yaml'
|
|
39
39
|
);
|
|
40
40
|
|
|
41
41
|
const results = await lintDocument({
|
|
@@ -110,7 +110,7 @@ describe('Oas3 Structural visitor basic', () => {
|
|
|
110
110
|
"source": "foobar.yaml",
|
|
111
111
|
},
|
|
112
112
|
],
|
|
113
|
-
"message": "Expected type \`string\` but got \`
|
|
113
|
+
"message": "Expected type \`string\` but got \`integer\`.",
|
|
114
114
|
"ruleId": "spec",
|
|
115
115
|
"severity": "error",
|
|
116
116
|
"suggest": Array [],
|
|
@@ -163,7 +163,7 @@ describe('Oas3 Structural visitor basic', () => {
|
|
|
163
163
|
x-test: vendor
|
|
164
164
|
paths: {}
|
|
165
165
|
`,
|
|
166
|
-
'foobar.yaml'
|
|
166
|
+
'foobar.yaml'
|
|
167
167
|
);
|
|
168
168
|
|
|
169
169
|
const results = await lintDocument({
|
|
@@ -232,7 +232,7 @@ describe('Oas3 Structural visitor basic', () => {
|
|
|
232
232
|
contact:
|
|
233
233
|
name: string
|
|
234
234
|
`,
|
|
235
|
-
'foobar.yaml'
|
|
235
|
+
'foobar.yaml'
|
|
236
236
|
);
|
|
237
237
|
|
|
238
238
|
const results = await lintDocument({
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StyleguideConfig, RuleConfig, resolveStyleguideConfig } from '../../../../config';
|
|
2
2
|
import { parseYamlToDocument } from '../../../../../__tests__/utils';
|
|
3
3
|
import { lintDocument } from '../../../../lint';
|
|
4
4
|
import { BaseResolver } from '../../../../resolve';
|
|
5
5
|
|
|
6
6
|
export async function validateDoc(
|
|
7
7
|
source: string,
|
|
8
|
-
rules: Record<string, RuleConfig> = { spec: 'error' }
|
|
8
|
+
rules: Record<string, RuleConfig> = { spec: 'error' }
|
|
9
9
|
) {
|
|
10
10
|
const document = parseYamlToDocument(source, 'foobar.yaml');
|
|
11
11
|
|
|
12
12
|
const results = await lintDocument({
|
|
13
13
|
externalRefResolver: new BaseResolver(),
|
|
14
14
|
document,
|
|
15
|
-
config: new
|
|
16
|
-
await
|
|
17
|
-
|
|
15
|
+
config: new StyleguideConfig(
|
|
16
|
+
await resolveStyleguideConfig({
|
|
17
|
+
styleguideConfig: {
|
|
18
18
|
plugins: [],
|
|
19
19
|
extends: [],
|
|
20
20
|
rules,
|
|
21
21
|
},
|
|
22
|
-
})
|
|
22
|
+
})
|
|
23
23
|
),
|
|
24
24
|
});
|
|
25
25
|
|
package/src/rules/oas3/index.ts
CHANGED
|
@@ -18,13 +18,13 @@ import { NoServerTrailingSlash } from './no-server-trailing-slash';
|
|
|
18
18
|
import { InfoDescription } from '../common/info-description';
|
|
19
19
|
import { TagDescription } from '../common/tag-description';
|
|
20
20
|
import { InfoContact } from '../common/info-contact';
|
|
21
|
-
import { InfoLicense } from '../common/info-license
|
|
21
|
+
import { InfoLicense } from '../common/info-license';
|
|
22
|
+
import { InfoLicenseUrl } from '../common/info-license-url';
|
|
22
23
|
import { OperationDescription } from '../common/operation-description';
|
|
23
24
|
import { NoUnusedComponents } from './no-unused-components';
|
|
24
25
|
import { PathNotIncludeQuery } from '../common/path-not-include-query';
|
|
25
26
|
import { ParameterDescription } from '../common/parameter-description';
|
|
26
27
|
import { OperationSingularTag } from '../common/operation-singular-tag';
|
|
27
|
-
import { InfoLicenseUrl } from '../common/license-url';
|
|
28
28
|
import { OperationSecurityDefined } from '../common/operation-security-defined';
|
|
29
29
|
import { NoUnresolvedRefs } from '../no-unresolved-refs';
|
|
30
30
|
import { BooleanParameterPrefixes } from './boolean-parameter-prefixes';
|
|
@@ -37,7 +37,7 @@ import { NoUndefinedServerVariable } from './no-undefined-server-variable';
|
|
|
37
37
|
import { OperationOperationId } from '../common/operation-operationId';
|
|
38
38
|
import { OperationSummary } from '../common/operation-summary';
|
|
39
39
|
import { NoAmbiguousPaths } from '../common/no-ambiguous-paths';
|
|
40
|
-
import {
|
|
40
|
+
import { NoServerVariablesEmptyEnum } from './no-server-variables-empty-enum';
|
|
41
41
|
import { NoHttpVerbsInPaths } from '../common/no-http-verbs-in-paths';
|
|
42
42
|
import { RequestMimeType } from './request-mime-type';
|
|
43
43
|
import { ResponseMimeType } from './response-mime-type';
|
|
@@ -57,7 +57,7 @@ export const rules = {
|
|
|
57
57
|
'info-license-url': InfoLicenseUrl,
|
|
58
58
|
'operation-2xx-response': Operation2xxResponse,
|
|
59
59
|
'operation-4xx-response': Operation4xxResponse,
|
|
60
|
-
|
|
60
|
+
assertions: Assertions,
|
|
61
61
|
'operation-operationId-unique': OperationIdUnique,
|
|
62
62
|
'operation-parameters-unique': OperationParametersUnique,
|
|
63
63
|
'path-parameters-defined': PathParamsDefined,
|
|
@@ -89,7 +89,7 @@ export const rules = {
|
|
|
89
89
|
'no-identical-paths': NoIdenticalPaths,
|
|
90
90
|
'no-ambiguous-paths': NoAmbiguousPaths,
|
|
91
91
|
'no-undefined-server-variable': NoUndefinedServerVariable,
|
|
92
|
-
'no-
|
|
92
|
+
'no-server-variables-empty-enum': NoServerVariablesEmptyEnum,
|
|
93
93
|
'no-http-verbs-in-paths': NoHttpVerbsInPaths,
|
|
94
94
|
'path-excludes-patterns': PathExcludesPatterns,
|
|
95
95
|
'request-mime-type': RequestMimeType,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Oas3Rule } from '../../visitors';
|
|
2
2
|
import { Location, isRef } from '../../ref-utils';
|
|
3
3
|
import { Oas3Example } from '../../typings/openapi';
|
|
4
|
-
import { validateExample } from '../utils';
|
|
4
|
+
import { getAdditionalPropertiesOption, validateExample } from '../utils';
|
|
5
5
|
import { UserContext } from '../../walk';
|
|
6
6
|
|
|
7
7
|
export const ValidContentExamples: Oas3Rule = (opts) => {
|
|
8
|
-
const
|
|
8
|
+
const allowAdditionalProperties = getAdditionalPropertiesOption(opts) ?? false;
|
|
9
9
|
|
|
10
10
|
return {
|
|
11
11
|
MediaType: {
|
|
@@ -13,14 +13,22 @@ export const ValidContentExamples: Oas3Rule = (opts) => {
|
|
|
13
13
|
const { location, resolve } = ctx;
|
|
14
14
|
if (!mediaType.schema) return;
|
|
15
15
|
if (mediaType.example) {
|
|
16
|
-
|
|
16
|
+
resolveAndValidateExample(mediaType.example, location.child('example'));
|
|
17
17
|
} else if (mediaType.examples) {
|
|
18
18
|
for (const exampleName of Object.keys(mediaType.examples)) {
|
|
19
|
-
resolveAndValidateExample(
|
|
19
|
+
resolveAndValidateExample(
|
|
20
|
+
mediaType.examples[exampleName],
|
|
21
|
+
location.child(['examples', exampleName, 'value']),
|
|
22
|
+
true
|
|
23
|
+
);
|
|
20
24
|
}
|
|
21
25
|
}
|
|
22
26
|
|
|
23
|
-
function resolveAndValidateExample(
|
|
27
|
+
function resolveAndValidateExample(
|
|
28
|
+
example: Oas3Example | any,
|
|
29
|
+
location: Location,
|
|
30
|
+
isMultiple?: boolean
|
|
31
|
+
) {
|
|
24
32
|
if (isRef(example)) {
|
|
25
33
|
const resolved = resolve<Oas3Example>(example);
|
|
26
34
|
if (!resolved.location) return;
|
|
@@ -32,7 +40,7 @@ export const ValidContentExamples: Oas3Rule = (opts) => {
|
|
|
32
40
|
mediaType.schema!,
|
|
33
41
|
location,
|
|
34
42
|
ctx,
|
|
35
|
-
|
|
43
|
+
allowAdditionalProperties
|
|
36
44
|
);
|
|
37
45
|
}
|
|
38
46
|
},
|
|
@@ -6,7 +6,7 @@ enum enumError {
|
|
|
6
6
|
invalidDefaultValue = 'invalidDefaultValue',
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export const
|
|
9
|
+
export const NoServerVariablesEmptyEnum: Oas3Rule = () => {
|
|
10
10
|
return {
|
|
11
11
|
DefinitionRoot(root, { report, location }) {
|
|
12
12
|
if (!root.servers || root.servers.length === 0) return;
|
|
@@ -25,16 +25,17 @@ export const NoEmptyEnumServers: Oas3Rule = () => {
|
|
|
25
25
|
invalidVariables.push(...enumErrors);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
for(const invalidVariable of invalidVariables) {
|
|
29
|
-
if(invalidVariable === enumError.empty) {
|
|
28
|
+
for (const invalidVariable of invalidVariables) {
|
|
29
|
+
if (invalidVariable === enumError.empty) {
|
|
30
30
|
report({
|
|
31
31
|
message: 'Server variable with `enum` must be a non-empty array.',
|
|
32
32
|
location: location.child(['servers']).key(),
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
-
if(invalidVariable === enumError.invalidDefaultValue) {
|
|
35
|
+
if (invalidVariable === enumError.invalidDefaultValue) {
|
|
36
36
|
report({
|
|
37
|
-
message:
|
|
37
|
+
message:
|
|
38
|
+
'Server variable define `enum` and `default`. `enum` must include default value',
|
|
38
39
|
location: location.child(['servers']).key(),
|
|
39
40
|
});
|
|
40
41
|
}
|
|
@@ -43,20 +44,18 @@ export const NoEmptyEnumServers: Oas3Rule = () => {
|
|
|
43
44
|
};
|
|
44
45
|
};
|
|
45
46
|
|
|
46
|
-
function checkEnumVariables(server: Oas3Server): enumError[] | undefined{
|
|
47
|
-
if (server.variables && Object.keys(server.variables).length === 0)
|
|
48
|
-
return;
|
|
47
|
+
function checkEnumVariables(server: Oas3Server): enumError[] | undefined {
|
|
48
|
+
if (server.variables && Object.keys(server.variables).length === 0) return;
|
|
49
49
|
|
|
50
50
|
const errors: enumError[] = [];
|
|
51
|
-
for(
|
|
51
|
+
for (const variable in server.variables) {
|
|
52
52
|
const serverVariable = server.variables[variable];
|
|
53
53
|
if (!serverVariable.enum) continue;
|
|
54
54
|
|
|
55
55
|
if (Array.isArray(serverVariable.enum) && serverVariable.enum?.length === 0)
|
|
56
56
|
errors.push(enumError.empty);
|
|
57
57
|
|
|
58
|
-
if (!serverVariable.default)
|
|
59
|
-
continue;
|
|
58
|
+
if (!serverVariable.default) continue;
|
|
60
59
|
|
|
61
60
|
const defaultValue = server.variables[variable].default;
|
|
62
61
|
if (serverVariable.enum && !serverVariable.enum.includes(defaultValue))
|
|
@@ -2,7 +2,7 @@ import { Oas3Rule } from '../../visitors';
|
|
|
2
2
|
import { Location } from '../../ref-utils';
|
|
3
3
|
|
|
4
4
|
export const NoUnusedComponents: Oas3Rule = () => {
|
|
5
|
-
|
|
5
|
+
const components = new Map<string, { used: boolean; location: Location; name: string }>();
|
|
6
6
|
|
|
7
7
|
function registerComponent(location: Location, name: string): void {
|
|
8
8
|
components.set(location.absolutePointer, {
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { Oas3Rule } from '../../visitors';
|
|
2
2
|
import { Location } from '../../ref-utils';
|
|
3
|
-
import { Oas3Components } from '../../typings/openapi'
|
|
3
|
+
import { Oas3Components } from '../../typings/openapi';
|
|
4
4
|
import { isEmptyObject } from '../../utils';
|
|
5
5
|
|
|
6
6
|
export const RemoveUnusedComponents: Oas3Rule = () => {
|
|
7
|
-
|
|
7
|
+
const components = new Map<
|
|
8
|
+
string,
|
|
9
|
+
{ used: boolean; componentType?: keyof Oas3Components; name: string }
|
|
10
|
+
>();
|
|
8
11
|
|
|
9
|
-
function registerComponent(
|
|
12
|
+
function registerComponent(
|
|
13
|
+
location: Location,
|
|
14
|
+
componentType: keyof Oas3Components,
|
|
15
|
+
name: string
|
|
16
|
+
): void {
|
|
10
17
|
components.set(location.absolutePointer, {
|
|
11
18
|
used: components.get(location.absolutePointer)?.used || false,
|
|
12
19
|
componentType,
|
|
@@ -18,7 +25,9 @@ export const RemoveUnusedComponents: Oas3Rule = () => {
|
|
|
18
25
|
ref: {
|
|
19
26
|
leave(ref, { type, resolve, key }) {
|
|
20
27
|
if (
|
|
21
|
-
['Schema', 'Header', 'Parameter', 'Response', 'Example', 'RequestBody'].includes(
|
|
28
|
+
['Schema', 'Header', 'Parameter', 'Response', 'Example', 'RequestBody'].includes(
|
|
29
|
+
type.name
|
|
30
|
+
)
|
|
22
31
|
) {
|
|
23
32
|
const resolvedRef = resolve(ref);
|
|
24
33
|
if (!resolvedRef.location) return;
|
|
@@ -27,25 +36,27 @@ export const RemoveUnusedComponents: Oas3Rule = () => {
|
|
|
27
36
|
name: key.toString(),
|
|
28
37
|
});
|
|
29
38
|
}
|
|
30
|
-
}
|
|
39
|
+
},
|
|
31
40
|
},
|
|
32
41
|
DefinitionRoot: {
|
|
33
42
|
leave(root, ctx) {
|
|
34
43
|
const data = ctx.getVisitorData() as { removedCount: number };
|
|
35
44
|
data.removedCount = 0;
|
|
36
45
|
|
|
37
|
-
components.forEach(usageInfo => {
|
|
46
|
+
components.forEach((usageInfo) => {
|
|
38
47
|
const { used, componentType, name } = usageInfo;
|
|
39
|
-
if (!used && componentType) {
|
|
40
|
-
|
|
48
|
+
if (!used && componentType && root.components) {
|
|
49
|
+
const componentChild = root.components[componentType];
|
|
41
50
|
delete componentChild![name];
|
|
42
51
|
data.removedCount++;
|
|
43
52
|
if (isEmptyObject(componentChild)) {
|
|
44
|
-
delete root.components
|
|
53
|
+
delete root.components[componentType];
|
|
45
54
|
}
|
|
46
55
|
}
|
|
47
56
|
});
|
|
48
|
-
if (isEmptyObject(root.components)) {
|
|
57
|
+
if (isEmptyObject(root.components)) {
|
|
58
|
+
delete root.components;
|
|
59
|
+
}
|
|
49
60
|
},
|
|
50
61
|
},
|
|
51
62
|
NamedSchemas: {
|