@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/config/minimal.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PluginStyleguideConfig } from './types';
|
|
2
2
|
|
|
3
3
|
export default {
|
|
4
4
|
rules: {
|
|
@@ -18,7 +18,7 @@ export default {
|
|
|
18
18
|
'operation-description': 'off',
|
|
19
19
|
'operation-2xx-response': 'warn',
|
|
20
20
|
'operation-4xx-response': 'off',
|
|
21
|
-
|
|
21
|
+
assertions: 'warn',
|
|
22
22
|
'operation-operationId': 'warn',
|
|
23
23
|
'operation-summary': 'warn',
|
|
24
24
|
'operation-operationId-unique': 'warn',
|
|
@@ -36,7 +36,7 @@ export default {
|
|
|
36
36
|
oas3_0Rules: {
|
|
37
37
|
'no-invalid-media-type-examples': {
|
|
38
38
|
severity: 'warn',
|
|
39
|
-
|
|
39
|
+
allowAdditionalProperties: false,
|
|
40
40
|
},
|
|
41
41
|
'no-server-example.com': 'warn',
|
|
42
42
|
'no-server-trailing-slash': 'error',
|
|
@@ -44,15 +44,16 @@ export default {
|
|
|
44
44
|
'no-example-value-and-externalValue': 'warn',
|
|
45
45
|
'no-unused-components': 'warn',
|
|
46
46
|
'no-undefined-server-variable': 'warn',
|
|
47
|
-
'no-
|
|
47
|
+
'no-server-variables-empty-enum': 'error',
|
|
48
48
|
},
|
|
49
49
|
oas3_1Rules: {
|
|
50
|
+
'no-invalid-media-type-examples': 'warn',
|
|
50
51
|
'no-server-example.com': 'warn',
|
|
51
52
|
'no-server-trailing-slash': 'error',
|
|
52
53
|
'no-empty-servers': 'warn',
|
|
53
54
|
'no-example-value-and-externalValue': 'warn',
|
|
54
55
|
'no-unused-components': 'warn',
|
|
55
56
|
'no-undefined-server-variable': 'warn',
|
|
56
|
-
'no-
|
|
57
|
+
'no-server-variables-empty-enum': 'error',
|
|
57
58
|
},
|
|
58
|
-
} as
|
|
59
|
+
} as PluginStyleguideConfig;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PluginStyleguideConfig } from './types';
|
|
2
2
|
|
|
3
3
|
export default {
|
|
4
4
|
rules: {
|
|
@@ -17,7 +17,7 @@ export default {
|
|
|
17
17
|
'path-parameters-defined': 'error',
|
|
18
18
|
'operation-description': 'off',
|
|
19
19
|
'operation-2xx-response': 'warn',
|
|
20
|
-
|
|
20
|
+
assertions: 'warn',
|
|
21
21
|
'operation-4xx-response': 'warn',
|
|
22
22
|
'operation-operationId': 'warn',
|
|
23
23
|
'operation-summary': 'error',
|
|
@@ -36,7 +36,7 @@ export default {
|
|
|
36
36
|
oas3_0Rules: {
|
|
37
37
|
'no-invalid-media-type-examples': {
|
|
38
38
|
severity: 'warn',
|
|
39
|
-
|
|
39
|
+
allowAdditionalProperties: false,
|
|
40
40
|
},
|
|
41
41
|
'no-server-example.com': 'warn',
|
|
42
42
|
'no-server-trailing-slash': 'error',
|
|
@@ -44,15 +44,16 @@ export default {
|
|
|
44
44
|
'no-example-value-and-externalValue': 'error',
|
|
45
45
|
'no-unused-components': 'warn',
|
|
46
46
|
'no-undefined-server-variable': 'error',
|
|
47
|
-
'no-
|
|
47
|
+
'no-server-variables-empty-enum': 'error',
|
|
48
48
|
},
|
|
49
49
|
oas3_1Rules: {
|
|
50
|
+
'no-invalid-media-type-examples': 'warn',
|
|
50
51
|
'no-server-example.com': 'warn',
|
|
51
52
|
'no-server-trailing-slash': 'error',
|
|
52
53
|
'no-empty-servers': 'error',
|
|
53
54
|
'no-example-value-and-externalValue': 'error',
|
|
54
55
|
'no-unused-components': 'warn',
|
|
55
56
|
'no-undefined-server-variable': 'error',
|
|
56
|
-
'no-
|
|
57
|
+
'no-server-variables-empty-enum': 'error',
|
|
57
58
|
},
|
|
58
|
-
} as
|
|
59
|
+
} as PluginStyleguideConfig;
|
package/src/config/rules.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { RuleSet, OasVersion } from '../oas-types';
|
|
2
|
-
import {
|
|
2
|
+
import { StyleguideConfig } from './config';
|
|
3
3
|
import { notUndefined } from '../utils';
|
|
4
4
|
|
|
5
5
|
export function initRules<T extends Function, P extends RuleSet<T>>(
|
|
6
6
|
rules: P[],
|
|
7
|
-
config:
|
|
7
|
+
config: StyleguideConfig,
|
|
8
8
|
type: 'rules' | 'preprocessors' | 'decorators',
|
|
9
|
-
oasVersion: OasVersion
|
|
9
|
+
oasVersion: OasVersion
|
|
10
10
|
) {
|
|
11
11
|
return rules
|
|
12
12
|
.flatMap((ruleset) =>
|
|
@@ -31,7 +31,7 @@ export function initRules<T extends Function, P extends RuleSet<T>>(
|
|
|
31
31
|
severity: ruleSettings.severity,
|
|
32
32
|
ruleId,
|
|
33
33
|
visitor: visitor,
|
|
34
|
-
}))
|
|
34
|
+
}));
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
return {
|
|
@@ -39,8 +39,8 @@ export function initRules<T extends Function, P extends RuleSet<T>>(
|
|
|
39
39
|
ruleId,
|
|
40
40
|
visitor: visitors, // note: actually it is only one visitor object
|
|
41
41
|
};
|
|
42
|
-
})
|
|
42
|
+
})
|
|
43
43
|
)
|
|
44
|
-
.flatMap(visitor => visitor)
|
|
44
|
+
.flatMap((visitor) => visitor)
|
|
45
45
|
.filter(notUndefined);
|
|
46
46
|
}
|
package/src/config/types.ts
CHANGED
|
@@ -29,7 +29,7 @@ export type PreprocessorConfig =
|
|
|
29
29
|
|
|
30
30
|
export type DecoratorConfig = PreprocessorConfig;
|
|
31
31
|
|
|
32
|
-
export type
|
|
32
|
+
export type StyleguideRawConfig = {
|
|
33
33
|
plugins?: (string | Plugin)[];
|
|
34
34
|
extends?: string[];
|
|
35
35
|
doNotResolveExamples?: boolean;
|
|
@@ -51,7 +51,9 @@ export type LintRawConfig = {
|
|
|
51
51
|
oas3_1Decorators?: Record<string, DecoratorConfig>;
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
export type
|
|
54
|
+
export type ApiStyleguideRawConfig = Omit<StyleguideRawConfig, 'plugins'>;
|
|
55
|
+
|
|
56
|
+
export type ResolvedStyleguideConfig = PluginStyleguideConfig & {
|
|
55
57
|
plugins?: Plugin[];
|
|
56
58
|
recommendedFallback?: boolean;
|
|
57
59
|
extends?: void | never;
|
|
@@ -71,7 +73,7 @@ export type DecoratorsConfig = {
|
|
|
71
73
|
|
|
72
74
|
export type TypesExtensionFn = (
|
|
73
75
|
types: Record<string, NodeType>,
|
|
74
|
-
oasVersion: OasVersion
|
|
76
|
+
oasVersion: OasVersion
|
|
75
77
|
) => Record<string, NodeType>;
|
|
76
78
|
|
|
77
79
|
export type TypeExtensionsConfig = Partial<Record<OasMajorVersion, TypesExtensionFn>>;
|
|
@@ -83,14 +85,14 @@ export type CustomRulesConfig = {
|
|
|
83
85
|
|
|
84
86
|
export type Plugin = {
|
|
85
87
|
id: string;
|
|
86
|
-
configs?: Record<string,
|
|
88
|
+
configs?: Record<string, PluginStyleguideConfig>;
|
|
87
89
|
rules?: CustomRulesConfig;
|
|
88
90
|
preprocessors?: PreprocessorsConfig;
|
|
89
91
|
decorators?: DecoratorsConfig;
|
|
90
92
|
typeExtension?: TypeExtensionsConfig;
|
|
91
93
|
};
|
|
92
94
|
|
|
93
|
-
export type
|
|
95
|
+
export type PluginStyleguideConfig = Omit<StyleguideRawConfig, 'plugins' | 'extends'>;
|
|
94
96
|
|
|
95
97
|
export type ResolveHeader =
|
|
96
98
|
| {
|
|
@@ -123,35 +125,42 @@ export type Region = 'us' | 'eu';
|
|
|
123
125
|
|
|
124
126
|
export type AccessTokens = { [region in Region]?: string };
|
|
125
127
|
|
|
126
|
-
export type
|
|
128
|
+
export type DeprecatedInRawConfig = {
|
|
127
129
|
apiDefinitions?: Record<string, string>;
|
|
128
|
-
lint?:
|
|
129
|
-
resolve?: RawResolveConfig;
|
|
130
|
-
region?: Region;
|
|
130
|
+
lint?: StyleguideRawConfig;
|
|
131
131
|
referenceDocs?: Record<string, any>;
|
|
132
|
+
apis?: Record<string, Api & DeprecatedInApi>;
|
|
132
133
|
};
|
|
133
134
|
|
|
134
135
|
export type Api = {
|
|
135
136
|
root: string;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
styleguide?: ApiStyleguideRawConfig;
|
|
138
|
+
} & FeaturesConfig;
|
|
139
|
+
|
|
140
|
+
export type DeprecatedInApi = {
|
|
141
|
+
lint?: ApiStyleguideRawConfig;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export type ResolvedApi = Omit<Api, 'styleguide'> & {
|
|
145
|
+
styleguide: ResolvedStyleguideConfig;
|
|
139
146
|
};
|
|
140
|
-
export type ResolvedApi = Omit<Api, 'lint'> & { lint: Omit<ResolvedLintConfig, 'plugins'>};
|
|
141
147
|
|
|
142
148
|
export type RawConfig = {
|
|
143
149
|
apis?: Record<string, Api>;
|
|
144
|
-
|
|
150
|
+
styleguide?: StyleguideRawConfig;
|
|
145
151
|
resolve?: RawResolveConfig;
|
|
146
152
|
region?: Region;
|
|
147
|
-
'features.openapi'?: Record<string, any>;
|
|
148
|
-
'features.mockServer'?: Record<string, any>;
|
|
149
153
|
organization?: string;
|
|
154
|
+
} & FeaturesConfig;
|
|
155
|
+
|
|
156
|
+
export type ResolvedConfig = Omit<RawConfig, 'apis' | 'styleguide'> & {
|
|
157
|
+
apis: Record<string, ResolvedApi>;
|
|
158
|
+
styleguide: ResolvedStyleguideConfig;
|
|
150
159
|
};
|
|
151
160
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
161
|
+
type FeaturesConfig = {
|
|
162
|
+
'features.openapi'?: Record<string, any>;
|
|
163
|
+
'features.mockServer'?: Record<string, any>;
|
|
155
164
|
};
|
|
156
165
|
|
|
157
166
|
export type RulesFields =
|
package/src/config/utils.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
assignExisting,
|
|
3
|
+
isTruthy,
|
|
4
|
+
showErrorForDeprecatedField,
|
|
5
|
+
showWarningForDeprecatedField,
|
|
6
|
+
} from '../utils';
|
|
3
7
|
import { Config } from './config';
|
|
4
8
|
|
|
5
9
|
import type {
|
|
6
10
|
Api,
|
|
7
|
-
|
|
11
|
+
DeprecatedInApi,
|
|
12
|
+
DeprecatedInRawConfig,
|
|
8
13
|
Plugin,
|
|
9
14
|
RawConfig,
|
|
10
15
|
RawResolveConfig,
|
|
11
16
|
ResolveConfig,
|
|
12
|
-
|
|
17
|
+
ResolvedStyleguideConfig,
|
|
13
18
|
RulesFields,
|
|
14
19
|
} from './types';
|
|
20
|
+
import { logger, colorize } from '../logger';
|
|
15
21
|
|
|
16
22
|
export function parsePresetName(presetName: string): { pluginId: string; configName: string } {
|
|
17
23
|
if (presetName.indexOf('/') > -1) {
|
|
@@ -23,15 +29,27 @@ export function parsePresetName(presetName: string): { pluginId: string; configN
|
|
|
23
29
|
}
|
|
24
30
|
|
|
25
31
|
export function transformApiDefinitionsToApis(
|
|
26
|
-
apiDefinitions
|
|
27
|
-
): Record<string, Api> {
|
|
28
|
-
|
|
32
|
+
apiDefinitions?: DeprecatedInRawConfig['apiDefinitions']
|
|
33
|
+
): Record<string, Api> | undefined {
|
|
34
|
+
if (!apiDefinitions) return undefined;
|
|
35
|
+
const apis: Record<string, Api> = {};
|
|
29
36
|
for (const [apiName, apiPath] of Object.entries(apiDefinitions)) {
|
|
30
37
|
apis[apiName] = { root: apiPath };
|
|
31
38
|
}
|
|
32
39
|
return apis;
|
|
33
40
|
}
|
|
34
41
|
|
|
42
|
+
function transformApis(
|
|
43
|
+
legacyApis?: Record<string, Api & DeprecatedInApi>
|
|
44
|
+
): Record<string, Api> | undefined {
|
|
45
|
+
if (!legacyApis) return undefined;
|
|
46
|
+
const apis: Record<string, Api> = {};
|
|
47
|
+
for (const [apiName, { lint, ...apiContent }] of Object.entries(legacyApis)) {
|
|
48
|
+
apis[apiName] = { styleguide: lint, ...apiContent };
|
|
49
|
+
}
|
|
50
|
+
return apis;
|
|
51
|
+
}
|
|
52
|
+
|
|
35
53
|
export function prefixRules<T extends Record<string, any>>(rules: T, prefix: string) {
|
|
36
54
|
if (!prefix) return rules;
|
|
37
55
|
|
|
@@ -43,9 +61,9 @@ export function prefixRules<T extends Record<string, any>>(rules: T, prefix: str
|
|
|
43
61
|
return res;
|
|
44
62
|
}
|
|
45
63
|
|
|
46
|
-
export function mergeExtends(rulesConfList:
|
|
47
|
-
const result: Omit<
|
|
48
|
-
Required<Pick<
|
|
64
|
+
export function mergeExtends(rulesConfList: ResolvedStyleguideConfig[]) {
|
|
65
|
+
const result: Omit<ResolvedStyleguideConfig, RulesFields> &
|
|
66
|
+
Required<Pick<ResolvedStyleguideConfig, RulesFields>> = {
|
|
49
67
|
rules: {},
|
|
50
68
|
oas2Rules: {},
|
|
51
69
|
oas3_0Rules: {},
|
|
@@ -66,14 +84,10 @@ export function mergeExtends(rulesConfList: ResolvedLintConfig[]) {
|
|
|
66
84
|
extendPaths: [],
|
|
67
85
|
};
|
|
68
86
|
|
|
69
|
-
for (
|
|
87
|
+
for (const rulesConf of rulesConfList) {
|
|
70
88
|
if (rulesConf.extends) {
|
|
71
89
|
throw new Error(
|
|
72
|
-
|
|
73
|
-
rulesConf,
|
|
74
|
-
null,
|
|
75
|
-
2,
|
|
76
|
-
)}.`,
|
|
90
|
+
`'extends' is not supported in shared configs yet: ${JSON.stringify(rulesConf, null, 2)}.`
|
|
77
91
|
);
|
|
78
92
|
}
|
|
79
93
|
|
|
@@ -109,75 +123,84 @@ export function mergeExtends(rulesConfList: ResolvedLintConfig[]) {
|
|
|
109
123
|
return result;
|
|
110
124
|
}
|
|
111
125
|
|
|
112
|
-
export function getMergedConfig(config: Config,
|
|
126
|
+
export function getMergedConfig(config: Config, apiName?: string): Config {
|
|
113
127
|
const extendPaths = [
|
|
114
|
-
...Object.values(config.apis).map((api) => api?.
|
|
115
|
-
config.rawConfig?.
|
|
128
|
+
...Object.values(config.apis).map((api) => api?.styleguide?.extendPaths),
|
|
129
|
+
config.rawConfig?.styleguide?.extendPaths,
|
|
116
130
|
]
|
|
117
131
|
.flat()
|
|
118
|
-
.filter(
|
|
132
|
+
.filter(isTruthy);
|
|
119
133
|
|
|
120
134
|
const pluginPaths = [
|
|
121
|
-
...Object.values(config.apis).map((api) => api?.
|
|
122
|
-
config.rawConfig?.
|
|
135
|
+
...Object.values(config.apis).map((api) => api?.styleguide?.pluginPaths),
|
|
136
|
+
config.rawConfig?.styleguide?.pluginPaths,
|
|
123
137
|
]
|
|
124
138
|
.flat()
|
|
125
|
-
.filter(
|
|
139
|
+
.filter(isTruthy);
|
|
126
140
|
|
|
127
|
-
return
|
|
141
|
+
return apiName
|
|
128
142
|
? new Config(
|
|
129
143
|
{
|
|
130
144
|
...config.rawConfig,
|
|
131
|
-
|
|
132
|
-
...(config.apis[
|
|
133
|
-
? config.apis[
|
|
134
|
-
: config.rawConfig.
|
|
145
|
+
styleguide: {
|
|
146
|
+
...(config.apis[apiName]
|
|
147
|
+
? config.apis[apiName].styleguide
|
|
148
|
+
: config.rawConfig.styleguide),
|
|
135
149
|
extendPaths,
|
|
136
150
|
pluginPaths,
|
|
137
151
|
},
|
|
138
152
|
'features.openapi': {
|
|
139
153
|
...config['features.openapi'],
|
|
140
|
-
...config.apis[
|
|
154
|
+
...config.apis[apiName]?.['features.openapi'],
|
|
141
155
|
},
|
|
142
156
|
'features.mockServer': {
|
|
143
157
|
...config['features.mockServer'],
|
|
144
|
-
...config.apis[
|
|
158
|
+
...config.apis[apiName]?.['features.mockServer'],
|
|
145
159
|
},
|
|
146
160
|
// TODO: merge everything else here
|
|
147
161
|
},
|
|
148
|
-
config.configFile
|
|
162
|
+
config.configFile
|
|
149
163
|
)
|
|
150
164
|
: config;
|
|
151
165
|
}
|
|
152
166
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
const { apiDefinitions, referenceDocs, ...rest } = rawConfig as DeprecatedRawConfig & RawConfig;
|
|
164
|
-
if (apiDefinitions) {
|
|
165
|
-
process.stderr.write(
|
|
166
|
-
`The ${yellow('apiDefinitions')} field is deprecated. Use ${green(
|
|
167
|
-
'apis',
|
|
168
|
-
)} instead. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`,
|
|
167
|
+
function checkForDeprecatedFields(
|
|
168
|
+
deprecatedField: keyof DeprecatedInRawConfig,
|
|
169
|
+
updatedField: keyof RawConfig,
|
|
170
|
+
rawConfig: DeprecatedInRawConfig & RawConfig
|
|
171
|
+
): void {
|
|
172
|
+
const isDeprecatedFieldInApis =
|
|
173
|
+
rawConfig.apis &&
|
|
174
|
+
Object.values(rawConfig.apis).some(
|
|
175
|
+
(api: Api & DeprecatedInApi & DeprecatedInRawConfig) => api[deprecatedField]
|
|
169
176
|
);
|
|
177
|
+
|
|
178
|
+
if (rawConfig[deprecatedField] && rawConfig[updatedField]) {
|
|
179
|
+
showErrorForDeprecatedField(deprecatedField, updatedField);
|
|
170
180
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
181
|
+
|
|
182
|
+
if (rawConfig[deprecatedField] || isDeprecatedFieldInApis) {
|
|
183
|
+
showWarningForDeprecatedField(deprecatedField, updatedField);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function transformConfig(rawConfig: DeprecatedInRawConfig & RawConfig): RawConfig {
|
|
188
|
+
const migratedFields: [keyof DeprecatedInRawConfig, keyof RawConfig][] = [
|
|
189
|
+
['apiDefinitions', 'apis'],
|
|
190
|
+
['referenceDocs', 'features.openapi'],
|
|
191
|
+
['lint', 'styleguide'], // TODO: update docs
|
|
192
|
+
];
|
|
193
|
+
|
|
194
|
+
for (const [deprecatedField, updatedField] of migratedFields) {
|
|
195
|
+
checkForDeprecatedFields(deprecatedField, updatedField, rawConfig);
|
|
177
196
|
}
|
|
197
|
+
|
|
198
|
+
const { apis, apiDefinitions, referenceDocs, lint, ...rest } = rawConfig;
|
|
199
|
+
|
|
178
200
|
return {
|
|
179
201
|
'features.openapi': referenceDocs,
|
|
180
|
-
apis: transformApiDefinitionsToApis(apiDefinitions),
|
|
202
|
+
apis: transformApis(apis) || transformApiDefinitionsToApis(apiDefinitions),
|
|
203
|
+
styleguide: lint,
|
|
181
204
|
...rest,
|
|
182
205
|
};
|
|
183
206
|
}
|
|
@@ -199,9 +222,7 @@ export function getUniquePlugins(plugins: Plugin[]): Plugin[] {
|
|
|
199
222
|
results.push(p);
|
|
200
223
|
seen.add(p.id);
|
|
201
224
|
} else if (p.id) {
|
|
202
|
-
|
|
203
|
-
`Duplicate plugin id "${yellow(p.id)}".\n`,
|
|
204
|
-
);
|
|
225
|
+
logger.warn(`Duplicate plugin id "${colorize.red(p.id)}".\n`);
|
|
205
226
|
}
|
|
206
227
|
}
|
|
207
228
|
return results;
|
|
@@ -27,7 +27,8 @@ describe('oas3 filter-out', () => {
|
|
|
27
27
|
callbacks:
|
|
28
28
|
x-access: protected
|
|
29
29
|
orderInProgress:
|
|
30
|
-
x-internal: true`
|
|
30
|
+
x-internal: true`
|
|
31
|
+
);
|
|
31
32
|
|
|
32
33
|
it('should remove /pet path and y parameter', async () => {
|
|
33
34
|
const testDocument = parseYamlToDocument(
|
|
@@ -132,7 +133,8 @@ describe('oas3 filter-out', () => {
|
|
|
132
133
|
type: object
|
|
133
134
|
components: {}
|
|
134
135
|
|
|
135
|
-
`
|
|
136
|
+
`
|
|
137
|
+
);
|
|
136
138
|
const { bundle: res } = await bundleDocument({
|
|
137
139
|
document: testDoc,
|
|
138
140
|
externalRefResolver: new BaseResolver(),
|
|
@@ -185,7 +187,8 @@ describe('oas3 filter-out', () => {
|
|
|
185
187
|
x:
|
|
186
188
|
name: x
|
|
187
189
|
|
|
188
|
-
`
|
|
190
|
+
`
|
|
191
|
+
);
|
|
189
192
|
const { bundle: res } = await bundleDocument({
|
|
190
193
|
document: testDocument,
|
|
191
194
|
externalRefResolver: new BaseResolver(),
|
|
@@ -236,7 +239,8 @@ describe('oas3 filter-out', () => {
|
|
|
236
239
|
x:
|
|
237
240
|
name: x
|
|
238
241
|
|
|
239
|
-
`
|
|
242
|
+
`
|
|
243
|
+
);
|
|
240
244
|
const { bundle: res } = await bundleDocument({
|
|
241
245
|
document: testDocument,
|
|
242
246
|
externalRefResolver: new BaseResolver(),
|
|
@@ -18,7 +18,7 @@ describe('oas3 remove-x-internal', () => {
|
|
|
18
18
|
parameters:
|
|
19
19
|
x:
|
|
20
20
|
name: x
|
|
21
|
-
|
|
21
|
+
`
|
|
22
22
|
);
|
|
23
23
|
|
|
24
24
|
it('should use `internalFlagProperty` option to remove internal paths', async () => {
|
|
@@ -87,7 +87,7 @@ describe('oas3 remove-x-internal', () => {
|
|
|
87
87
|
name: x
|
|
88
88
|
y:
|
|
89
89
|
name: y
|
|
90
|
-
|
|
90
|
+
`
|
|
91
91
|
);
|
|
92
92
|
const { bundle: res } = await bundleDocument({
|
|
93
93
|
document: testDoc,
|
|
@@ -160,7 +160,7 @@ describe('oas3 remove-x-internal', () => {
|
|
|
160
160
|
servers:
|
|
161
161
|
- url: //callback-url.path-level/v1
|
|
162
162
|
description: Path level server
|
|
163
|
-
|
|
163
|
+
`
|
|
164
164
|
);
|
|
165
165
|
const { bundle: res } = await bundleDocument({
|
|
166
166
|
document: testDoc,
|
|
@@ -234,7 +234,7 @@ describe('oas3 remove-x-internal', () => {
|
|
|
234
234
|
schema:
|
|
235
235
|
type: string
|
|
236
236
|
x-internal: true
|
|
237
|
-
|
|
237
|
+
`
|
|
238
238
|
);
|
|
239
239
|
const { bundle: res } = await bundleDocument({
|
|
240
240
|
document: testDoc,
|
|
@@ -297,7 +297,7 @@ describe('oas2 remove-x-internal', () => {
|
|
|
297
297
|
'200':
|
|
298
298
|
x-internal: true
|
|
299
299
|
description: List of recent media entries.
|
|
300
|
-
|
|
300
|
+
`
|
|
301
301
|
);
|
|
302
302
|
const { bundle: res } = await bundleDocument({
|
|
303
303
|
document: testDoc,
|
|
@@ -8,7 +8,7 @@ export const InfoDescriptionOverride: Oas3Decorator | Oas2Decorator = ({ filePat
|
|
|
8
8
|
leave(info, { report, location }: UserContext) {
|
|
9
9
|
if (!filePath)
|
|
10
10
|
throw new Error(
|
|
11
|
-
`Parameter "filePath" is not provided for "info-description-override" rule
|
|
11
|
+
`Parameter "filePath" is not provided for "info-description-override" rule`
|
|
12
12
|
);
|
|
13
13
|
try {
|
|
14
14
|
info.description = readFileAsStringSync(filePath);
|
|
@@ -11,7 +11,7 @@ export const OperationDescriptionOverride: Oas3Decorator | Oas2Decorator = ({ op
|
|
|
11
11
|
if (!operation.operationId) return;
|
|
12
12
|
if (!operationIds)
|
|
13
13
|
throw new Error(
|
|
14
|
-
`Parameter "operationIds" is not provided for "operation-description-override" rule
|
|
14
|
+
`Parameter "operationIds" is not provided for "operation-description-override" rule`
|
|
15
15
|
);
|
|
16
16
|
const operationId = operation.operationId;
|
|
17
17
|
if (operationIds[operationId]) {
|
|
@@ -4,7 +4,7 @@ import { isRedoclyRegistryURL } from '../../redocly';
|
|
|
4
4
|
import { Oas3Decorator, Oas2Decorator } from '../../visitors';
|
|
5
5
|
|
|
6
6
|
export const RegistryDependencies: Oas3Decorator | Oas2Decorator = () => {
|
|
7
|
-
|
|
7
|
+
const registryDependencies = new Set<string>();
|
|
8
8
|
|
|
9
9
|
return {
|
|
10
10
|
DefinitionRoot: {
|
|
@@ -8,7 +8,7 @@ export const TagDescriptionOverride: Oas3Decorator | Oas2Decorator = ({ tagNames
|
|
|
8
8
|
leave(tag, { report }: UserContext) {
|
|
9
9
|
if (!tagNames)
|
|
10
10
|
throw new Error(
|
|
11
|
-
`Parameter "tagNames" is not provided for "tag-description-override" rule
|
|
11
|
+
`Parameter "tagNames" is not provided for "tag-description-override" rule`
|
|
12
12
|
);
|
|
13
13
|
if (tagNames[tag.name]) {
|
|
14
14
|
try {
|
package/src/env.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const isBrowser =
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
typeof window !== 'undefined' || typeof self !== 'undefined' || typeof process === 'undefined'; // main and worker thread
|
|
5
|
+
export const env = isBrowser ? {} : process.env || {};
|