@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
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,10 +101,10 @@ 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
|
-
for (
|
|
107
|
+
for (const error of errors) {
|
|
105
108
|
report({
|
|
106
109
|
message: `Example value must conform to the schema: ${error.message}.`,
|
|
107
110
|
location: {
|
|
@@ -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
|
}
|
|
@@ -40,7 +40,7 @@ const builtInRulesList = [
|
|
|
40
40
|
'no-identical-paths',
|
|
41
41
|
'no-ambiguous-paths',
|
|
42
42
|
'no-undefined-server-variable',
|
|
43
|
-
'no-
|
|
43
|
+
'no-server-variables-empty-enum',
|
|
44
44
|
'no-http-verbs-in-paths',
|
|
45
45
|
'path-excludes-patterns',
|
|
46
46
|
'request-mime-type',
|
|
@@ -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
package/src/utils.ts
CHANGED
|
@@ -6,7 +6,8 @@ import * as pluralize from 'pluralize';
|
|
|
6
6
|
import { parseYaml } from './js-yaml';
|
|
7
7
|
import { UserContext } from './walk';
|
|
8
8
|
import { HttpResolveConfig } from './config';
|
|
9
|
-
import { env } from './
|
|
9
|
+
import { env } from './env';
|
|
10
|
+
import { logger, colorize } from './logger';
|
|
10
11
|
|
|
11
12
|
export { parseYaml, stringifyYaml } from './js-yaml';
|
|
12
13
|
|
|
@@ -95,7 +96,7 @@ export function omitObjectProps<T extends Record<string, unknown>>(
|
|
|
95
96
|
export function splitCamelCaseIntoWords(str: string) {
|
|
96
97
|
const camel = str
|
|
97
98
|
.split(/(?:[-._])|([A-Z][a-z]+)/)
|
|
98
|
-
.filter(
|
|
99
|
+
.filter(isTruthy)
|
|
99
100
|
.map((item) => item.toLocaleLowerCase());
|
|
100
101
|
const caps = str
|
|
101
102
|
.split(/([A-Z]{2,})/)
|
|
@@ -182,7 +183,7 @@ export function isNotString<T>(value: string | T): value is T {
|
|
|
182
183
|
}
|
|
183
184
|
|
|
184
185
|
export function assignExisting<T>(target: Record<string, T>, obj: Record<string, T>) {
|
|
185
|
-
for (
|
|
186
|
+
for (const k of Object.keys(obj)) {
|
|
186
187
|
if (target.hasOwnProperty(k)) {
|
|
187
188
|
target[k] = obj[k];
|
|
188
189
|
}
|
|
@@ -204,3 +205,25 @@ export function doesYamlFileExist(filePath: string): boolean {
|
|
|
204
205
|
fs.existsSync(filePath)
|
|
205
206
|
);
|
|
206
207
|
}
|
|
208
|
+
|
|
209
|
+
export function showWarningForDeprecatedField(deprecatedField: string, updatedField: string) {
|
|
210
|
+
logger.warn(
|
|
211
|
+
`The ${colorize.red(deprecatedField)} field is deprecated. Use ${colorize.green(
|
|
212
|
+
updatedField
|
|
213
|
+
)} instead. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function showErrorForDeprecatedField(deprecatedField: string, updatedField: string) {
|
|
218
|
+
throw new Error(`Do not use '${deprecatedField}' field. Use '${updatedField}' instead.\n`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export type Falsy = undefined | null | false | '' | 0;
|
|
222
|
+
|
|
223
|
+
export function isTruthy<Truthy>(value: Truthy | Falsy): value is Truthy {
|
|
224
|
+
return !!value;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function identity<T>(value: T): T {
|
|
228
|
+
return value;
|
|
229
|
+
}
|
package/src/visitors.ts
CHANGED
|
@@ -53,7 +53,7 @@ export type VisitFunction<T> = (
|
|
|
53
53
|
node: T,
|
|
54
54
|
ctx: UserContext & { ignoreNextVisitorsOnNode: () => void },
|
|
55
55
|
parents?: any,
|
|
56
|
-
context?: any
|
|
56
|
+
context?: any
|
|
57
57
|
) => void;
|
|
58
58
|
|
|
59
59
|
type VisitRefFunction = (node: OasRef, ctx: UserContext, resolved: ResolveResult<any>) => void;
|
|
@@ -70,7 +70,7 @@ type NestedVisitObject<T, P> = VisitObject<T> & NestedVisitor<P>;
|
|
|
70
70
|
|
|
71
71
|
type VisitFunctionOrObject<T> = VisitFunction<T> | VisitObject<T>;
|
|
72
72
|
|
|
73
|
-
type VisitorNode<T
|
|
73
|
+
type VisitorNode<T> = {
|
|
74
74
|
ruleId: string;
|
|
75
75
|
severity: ProblemSeverity;
|
|
76
76
|
context: VisitorLevelContext | VisitorSkippedLevelContext;
|
|
@@ -264,7 +264,7 @@ export type RuleInstanceConfig = {
|
|
|
264
264
|
|
|
265
265
|
export function normalizeVisitors<T extends BaseVisitor>(
|
|
266
266
|
visitorsConfig: (RuleInstanceConfig & { visitor: NestedVisitObject<any, T> })[],
|
|
267
|
-
types: Record<keyof T, NormalizedNodeType
|
|
267
|
+
types: Record<keyof T, NormalizedNodeType>
|
|
268
268
|
): NormalizedOasVisitors<T> {
|
|
269
269
|
const normalizedVisitors: NormalizedOasVisitors<T> = {} as any;
|
|
270
270
|
|
|
@@ -301,7 +301,7 @@ export function normalizeVisitors<T extends BaseVisitor>(
|
|
|
301
301
|
from: NormalizedNodeType,
|
|
302
302
|
to: NormalizedNodeType,
|
|
303
303
|
parentContext: VisitorLevelContext,
|
|
304
|
-
stack: NormalizedNodeType[] = []
|
|
304
|
+
stack: NormalizedNodeType[] = []
|
|
305
305
|
) {
|
|
306
306
|
if (stack.includes(from)) return;
|
|
307
307
|
|
|
@@ -309,7 +309,7 @@ export function normalizeVisitors<T extends BaseVisitor>(
|
|
|
309
309
|
|
|
310
310
|
const possibleChildren = new Set<NormalizedNodeType>();
|
|
311
311
|
|
|
312
|
-
for (
|
|
312
|
+
for (const type of Object.values(from.properties)) {
|
|
313
313
|
if (type === to) {
|
|
314
314
|
addWeakFromStack(ruleConf, stack);
|
|
315
315
|
continue;
|
|
@@ -333,7 +333,7 @@ export function normalizeVisitors<T extends BaseVisitor>(
|
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
-
for (
|
|
336
|
+
for (const fromType of Array.from(possibleChildren.values())) {
|
|
337
337
|
addWeakNodes(ruleConf, fromType, to, parentContext, stack);
|
|
338
338
|
}
|
|
339
339
|
|
|
@@ -350,7 +350,7 @@ export function normalizeVisitors<T extends BaseVisitor>(
|
|
|
350
350
|
visit: () => undefined,
|
|
351
351
|
depth: 0,
|
|
352
352
|
context: {
|
|
353
|
-
isSkippedLevel: true
|
|
353
|
+
isSkippedLevel: true,
|
|
354
354
|
seen: new Set(),
|
|
355
355
|
parent: parentContext,
|
|
356
356
|
},
|
|
@@ -363,7 +363,7 @@ export function normalizeVisitors<T extends BaseVisitor>(
|
|
|
363
363
|
ruleConf: RuleInstanceConfig,
|
|
364
364
|
visitor: NestedVisitObject<any, T>,
|
|
365
365
|
parentContext: VisitorLevelContext | null,
|
|
366
|
-
depth = 0
|
|
366
|
+
depth = 0
|
|
367
367
|
) {
|
|
368
368
|
const visitorKeys = Object.keys(types) as Array<keyof T | 'any'>;
|
|
369
369
|
|
|
@@ -407,7 +407,7 @@ export function normalizeVisitors<T extends BaseVisitor>(
|
|
|
407
407
|
activatedOn: null,
|
|
408
408
|
type: types[typeName],
|
|
409
409
|
parent: parentContext,
|
|
410
|
-
isSkippedLevel: false
|
|
410
|
+
isSkippedLevel: false,
|
|
411
411
|
};
|
|
412
412
|
|
|
413
413
|
if (typeof typeVisitor === 'object') {
|
package/src/walk.ts
CHANGED
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
import { pushStack, popStack } from './utils';
|
|
19
19
|
import { OasVersion } from './oas-types';
|
|
20
20
|
import { NormalizedNodeType, isNamedType } from './types';
|
|
21
|
+
import type { RuleSeverity } from './config';
|
|
22
|
+
|
|
21
23
|
type NonUndefined = string | number | boolean | symbol | bigint | object | Record<string, any>;
|
|
22
24
|
|
|
23
25
|
export type ResolveResult<T extends NonUndefined> =
|
|
@@ -66,7 +68,7 @@ export type Problem = {
|
|
|
66
68
|
suggest?: string[];
|
|
67
69
|
location?: Partial<LocationObject> | Array<Partial<LocationObject>>;
|
|
68
70
|
from?: LocationObject;
|
|
69
|
-
forceSeverity?:
|
|
71
|
+
forceSeverity?: RuleSeverity;
|
|
70
72
|
ruleId?: string;
|
|
71
73
|
};
|
|
72
74
|
|
|
@@ -409,17 +411,19 @@ export function walkDocument<T>(opts: {
|
|
|
409
411
|
: [opts.location]
|
|
410
412
|
: [{ ...currentLocation, reportOnKey: false }];
|
|
411
413
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
414
|
+
const ruleSeverity = opts.forceSeverity || severity;
|
|
415
|
+
if (ruleSeverity !== 'off') {
|
|
416
|
+
ctx.problems.push({
|
|
417
|
+
ruleId: opts.ruleId || ruleId,
|
|
418
|
+
severity: ruleSeverity,
|
|
419
|
+
...opts,
|
|
420
|
+
suggest: opts.suggest || [],
|
|
421
|
+
location: loc.map((loc: any) => {
|
|
422
|
+
return { ...currentLocation, reportOnKey: false, ...loc };
|
|
423
|
+
}),
|
|
424
|
+
});
|
|
425
|
+
}
|
|
421
426
|
}
|
|
422
|
-
|
|
423
427
|
function getVisitorDataFn(ruleId: string) {
|
|
424
428
|
ctx.visitorsData[ruleId] = ctx.visitorsData[ruleId] || {};
|
|
425
429
|
return ctx.visitorsData[ruleId];
|