@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
|
@@ -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';
|
|
@@ -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,
|
|
@@ -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
|
},
|
|
@@ -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(var variable in server.variables) {
|
|
51
|
+
for (var 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))
|
|
@@ -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
|
-
let components = new Map<
|
|
7
|
+
let 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,14 +36,14 @@ 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
48
|
if (!used && componentType) {
|
|
40
49
|
let componentChild = root.components![componentType];
|
|
@@ -45,7 +54,9 @@ export const RemoveUnusedComponents: Oas3Rule = () => {
|
|
|
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: {
|
package/src/rules/other/stats.ts
CHANGED
|
@@ -4,10 +4,26 @@ import { StatsAccumulator } from '../../typings/common';
|
|
|
4
4
|
|
|
5
5
|
export const Stats = (statsAccumulator: StatsAccumulator) => {
|
|
6
6
|
return {
|
|
7
|
-
ExternalDocs: {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
ExternalDocs: {
|
|
8
|
+
leave() {
|
|
9
|
+
statsAccumulator.externalDocs.total++;
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
ref: {
|
|
13
|
+
enter(ref: OasRef) {
|
|
14
|
+
statsAccumulator.refs.items!.add(ref['$ref']);
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
Tag: {
|
|
18
|
+
leave(tag: Oas3Tag) {
|
|
19
|
+
statsAccumulator.tags.items!.add(tag.name);
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
Link: {
|
|
23
|
+
leave(link: any) {
|
|
24
|
+
statsAccumulator.links.items!.add(link.operationId);
|
|
25
|
+
},
|
|
26
|
+
},
|
|
11
27
|
DefinitionRoot: {
|
|
12
28
|
leave() {
|
|
13
29
|
statsAccumulator.parameters.total = statsAccumulator.parameters.items!.size;
|
|
@@ -19,26 +35,39 @@ export const Stats = (statsAccumulator: StatsAccumulator) => {
|
|
|
19
35
|
WebhooksMap: {
|
|
20
36
|
Operation: {
|
|
21
37
|
leave(operation: any) {
|
|
22
|
-
operation.tags.forEach((tag: string) => {
|
|
23
|
-
|
|
24
|
-
|
|
38
|
+
operation.tags.forEach((tag: string) => {
|
|
39
|
+
statsAccumulator.tags.items!.add(tag);
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
},
|
|
25
43
|
},
|
|
26
44
|
PathMap: {
|
|
27
45
|
PathItem: {
|
|
28
|
-
leave() {
|
|
46
|
+
leave() {
|
|
47
|
+
statsAccumulator.pathItems.total++;
|
|
48
|
+
},
|
|
29
49
|
Operation: {
|
|
30
50
|
leave(operation: any) {
|
|
31
51
|
statsAccumulator.operations.total++;
|
|
32
|
-
operation.tags &&
|
|
33
|
-
|
|
52
|
+
operation.tags &&
|
|
53
|
+
operation.tags.forEach((tag: string) => {
|
|
54
|
+
statsAccumulator.tags.items!.add(tag);
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
Parameter: {
|
|
59
|
+
leave(parameter: Oas2Parameter | Oas3Parameter) {
|
|
60
|
+
statsAccumulator.parameters.items!.add(parameter.name);
|
|
61
|
+
},
|
|
34
62
|
},
|
|
35
|
-
Parameter: { leave(parameter: Oas2Parameter | Oas3Parameter) {
|
|
36
|
-
statsAccumulator.parameters.items!.add(parameter.name)
|
|
37
|
-
}},
|
|
38
63
|
},
|
|
39
64
|
},
|
|
40
65
|
NamedSchemas: {
|
|
41
|
-
Schema: {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
66
|
+
Schema: {
|
|
67
|
+
leave() {
|
|
68
|
+
statsAccumulator.schemas.total++;
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
};
|
package/src/rules/utils.ts
CHANGED
|
@@ -3,12 +3,15 @@ import { UserContext } from '../walk';
|
|
|
3
3
|
import { Location } from '../ref-utils';
|
|
4
4
|
import { validateJsonSchema } from './ajv';
|
|
5
5
|
import { Oas3Schema, Referenced } from '../typings/openapi';
|
|
6
|
+
import { showErrorForDeprecatedField, showWarningForDeprecatedField } from '../utils';
|
|
6
7
|
|
|
7
8
|
export function oasTypeOf(value: unknown) {
|
|
8
9
|
if (Array.isArray(value)) {
|
|
9
10
|
return 'array';
|
|
10
11
|
} else if (value === null) {
|
|
11
12
|
return 'null';
|
|
13
|
+
} else if (Number.isInteger(value)) {
|
|
14
|
+
return 'integer';
|
|
12
15
|
} else {
|
|
13
16
|
return typeof value;
|
|
14
17
|
}
|
|
@@ -23,7 +26,7 @@ export function oasTypeOf(value: unknown) {
|
|
|
23
26
|
*/
|
|
24
27
|
export function matchesJsonSchemaType(value: unknown, type: string, nullable: boolean): boolean {
|
|
25
28
|
if (nullable && value === null) {
|
|
26
|
-
return
|
|
29
|
+
return true;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
switch (type) {
|
|
@@ -89,7 +92,7 @@ export function validateExample(
|
|
|
89
92
|
schema: Referenced<Oas3Schema>,
|
|
90
93
|
dataLoc: Location,
|
|
91
94
|
{ resolve, location, report }: UserContext,
|
|
92
|
-
|
|
95
|
+
allowAdditionalProperties: boolean
|
|
93
96
|
) {
|
|
94
97
|
try {
|
|
95
98
|
const { valid, errors } = validateJsonSchema(
|
|
@@ -98,7 +101,7 @@ export function validateExample(
|
|
|
98
101
|
location.child('schema'),
|
|
99
102
|
dataLoc.pointer,
|
|
100
103
|
resolve,
|
|
101
|
-
|
|
104
|
+
allowAdditionalProperties
|
|
102
105
|
);
|
|
103
106
|
if (!valid) {
|
|
104
107
|
for (let error of errors) {
|
|
@@ -121,3 +124,16 @@ export function validateExample(
|
|
|
121
124
|
});
|
|
122
125
|
}
|
|
123
126
|
}
|
|
127
|
+
|
|
128
|
+
export function getAdditionalPropertiesOption(opts: Record<string, any>): boolean {
|
|
129
|
+
if (opts.disallowAdditionalProperties === undefined) {
|
|
130
|
+
return opts.allowAdditionalProperties;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (opts.allowAdditionalProperties !== undefined) {
|
|
134
|
+
showErrorForDeprecatedField('disallowAdditionalProperties', 'allowAdditionalProperties');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
showWarningForDeprecatedField('disallowAdditionalProperties', 'allowAdditionalProperties');
|
|
138
|
+
return !opts.disallowAdditionalProperties;
|
|
139
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -24,7 +24,7 @@ export type NodeType = {
|
|
|
24
24
|
items?: string;
|
|
25
25
|
required?: string[] | ((value: any, key: string | number | undefined) => string[]);
|
|
26
26
|
requiredOneOf?: string[];
|
|
27
|
-
allowed?: (
|
|
27
|
+
allowed?: (value: any) => string[] | undefined;
|
|
28
28
|
extensionsPrefix?: string;
|
|
29
29
|
};
|
|
30
30
|
type PropType = string | NodeType | ScalarSchema | undefined | null;
|
|
@@ -37,14 +37,14 @@ export type NormalizedNodeType = {
|
|
|
37
37
|
items?: NormalizedNodeType;
|
|
38
38
|
required?: string[] | ((value: any, key: string | number | undefined) => string[]);
|
|
39
39
|
requiredOneOf?: string[];
|
|
40
|
-
allowed?: (
|
|
40
|
+
allowed?: (value: any) => string[] | undefined;
|
|
41
41
|
extensionsPrefix?: string;
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
type NormalizedPropType = NormalizedNodeType | NormalizedScalarSchema | undefined | null;
|
|
45
45
|
type NormalizedResolveTypeFn = (
|
|
46
46
|
value: any,
|
|
47
|
-
key: string
|
|
47
|
+
key: string
|
|
48
48
|
) => NormalizedNodeType | NormalizedScalarSchema | undefined | null;
|
|
49
49
|
|
|
50
50
|
export function listOf(typeName: string) {
|
|
@@ -65,7 +65,7 @@ export function mapOf(typeName: string) {
|
|
|
65
65
|
|
|
66
66
|
export function normalizeTypes(
|
|
67
67
|
types: Record<string, NodeType>,
|
|
68
|
-
options: { doNotResolveExamples?: boolean } = {}
|
|
68
|
+
options: { doNotResolveExamples?: boolean } = {}
|
|
69
69
|
): Record<string, NormalizedNodeType> {
|
|
70
70
|
const normalizedTypes: Record<string, NormalizedNodeType> = {};
|
|
71
71
|
|
|
@@ -132,7 +132,7 @@ export function normalizeTypes(
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
export function isNamedType(
|
|
135
|
-
t: NormalizedNodeType | NormalizedScalarSchema | null | undefined
|
|
135
|
+
t: NormalizedNodeType | NormalizedScalarSchema | null | undefined
|
|
136
136
|
): t is NormalizedNodeType {
|
|
137
137
|
return typeof t?.name === 'string';
|
|
138
138
|
}
|
|
@@ -110,7 +110,8 @@ const ConfigRoot: NodeType = {
|
|
|
110
110
|
properties: {},
|
|
111
111
|
additionalProperties: { properties: { type: 'string' } },
|
|
112
112
|
}, // deprecated
|
|
113
|
-
|
|
113
|
+
styleguide: 'RootConfigStyleguide',
|
|
114
|
+
lint: 'RootConfigStyleguide', // deprecated
|
|
114
115
|
'features.openapi': 'ConfigReferenceDocs',
|
|
115
116
|
referenceDocs: 'ConfigReferenceDocs', // deprecated
|
|
116
117
|
'features.mockServer': 'ConfigMockServer',
|
|
@@ -137,7 +138,7 @@ const ConfigApisProperties: NodeType = {
|
|
|
137
138
|
type: 'string',
|
|
138
139
|
},
|
|
139
140
|
},
|
|
140
|
-
|
|
141
|
+
styleguide: 'ConfigStyleguide',
|
|
141
142
|
'features.openapi': 'ConfigReferenceDocs',
|
|
142
143
|
'features.mockServer': 'ConfigMockServer',
|
|
143
144
|
},
|
|
@@ -155,7 +156,7 @@ const ConfigHTTP: NodeType = {
|
|
|
155
156
|
},
|
|
156
157
|
};
|
|
157
158
|
|
|
158
|
-
const
|
|
159
|
+
const ConfigStyleguide: NodeType = {
|
|
159
160
|
properties: {
|
|
160
161
|
extends: {
|
|
161
162
|
type: 'array',
|
|
@@ -179,13 +180,13 @@ const ConfigLint: NodeType = {
|
|
|
179
180
|
},
|
|
180
181
|
};
|
|
181
182
|
|
|
182
|
-
const
|
|
183
|
+
const RootConfigStyleguide: NodeType = {
|
|
183
184
|
properties: {
|
|
184
185
|
plugins: {
|
|
185
186
|
type: 'array',
|
|
186
187
|
items: { type: 'string' },
|
|
187
188
|
},
|
|
188
|
-
...
|
|
189
|
+
...ConfigStyleguide.properties,
|
|
189
190
|
},
|
|
190
191
|
};
|
|
191
192
|
|
|
@@ -877,8 +878,8 @@ export const ConfigTypes: Record<string, NodeType> = {
|
|
|
877
878
|
ConfigRoot,
|
|
878
879
|
ConfigApis,
|
|
879
880
|
ConfigApisProperties,
|
|
880
|
-
|
|
881
|
-
|
|
881
|
+
RootConfigStyleguide,
|
|
882
|
+
ConfigStyleguide,
|
|
882
883
|
ConfigReferenceDocs,
|
|
883
884
|
ConfigMockServer,
|
|
884
885
|
ConfigHTTP,
|
package/src/typings/common.ts
CHANGED
|
@@ -5,5 +5,13 @@ export interface StatsRow {
|
|
|
5
5
|
items?: Set<string>;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export type StatsName =
|
|
8
|
+
export type StatsName =
|
|
9
|
+
| 'operations'
|
|
10
|
+
| 'refs'
|
|
11
|
+
| 'tags'
|
|
12
|
+
| 'externalDocs'
|
|
13
|
+
| 'pathItems'
|
|
14
|
+
| 'links'
|
|
15
|
+
| 'schemas'
|
|
16
|
+
| 'parameters';
|
|
9
17
|
export type StatsAccumulator = Record<StatsName, StatsRow>;
|
package/src/typings/openapi.ts
CHANGED