@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/README.md
CHANGED
|
@@ -9,9 +9,9 @@ See https://github.com/Redocly/redocly-cli
|
|
|
9
9
|
```js
|
|
10
10
|
import { formatProblems, lint, loadConfig } from '@redocly/openapi-core';
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const pathToApi = 'openapi.yaml';
|
|
13
13
|
const config = loadConfig('optional/path/to/.redocly.yaml');
|
|
14
|
-
const lintResults = await lint({ ref:
|
|
14
|
+
const lintResults = await lint({ ref: pathToApi, config });
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
### Bundle
|
|
@@ -19,7 +19,7 @@ const lintResults = await lint({ ref: pathToEntryPoint, config });
|
|
|
19
19
|
```js
|
|
20
20
|
import { formatProblems, bundle, loadConfig } from '@redocly/openapi-core';
|
|
21
21
|
|
|
22
|
-
const
|
|
22
|
+
const pathToApi = 'openapi.yaml';
|
|
23
23
|
const config = loadConfig('optional/path/to/.redocly.yaml');
|
|
24
|
-
const { bundle, problems } = await bundle({ ref:
|
|
24
|
+
const { bundle, problems } = await bundle({ ref: pathToApi, config });
|
|
25
25
|
```
|
package/__tests__/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
|
|
3
3
|
import { Document, Source, NormalizedProblem, parseYaml, stringifyYaml } from '../src';
|
|
4
|
-
import {
|
|
4
|
+
import { StyleguideConfig, resolveStyleguideConfig, resolvePlugins } from '../src/config';
|
|
5
5
|
import { Oas3RuleSet } from '../src/oas-types';
|
|
6
6
|
|
|
7
7
|
import type { RuleConfig, Plugin, DecoratorConfig } from '../src/config';
|
|
@@ -63,7 +63,7 @@ export function makeConfigForRuleset(
|
|
|
63
63
|
},
|
|
64
64
|
]);
|
|
65
65
|
|
|
66
|
-
return new
|
|
66
|
+
return new StyleguideConfig({
|
|
67
67
|
plugins,
|
|
68
68
|
rules: rulesConf,
|
|
69
69
|
});
|
|
@@ -74,9 +74,9 @@ export async function makeConfig(
|
|
|
74
74
|
decorators?: Record<string, DecoratorConfig>,
|
|
75
75
|
configPath?: string
|
|
76
76
|
) {
|
|
77
|
-
return new
|
|
78
|
-
await
|
|
79
|
-
|
|
77
|
+
return new StyleguideConfig(
|
|
78
|
+
await resolveStyleguideConfig({
|
|
79
|
+
styleguideConfig: {
|
|
80
80
|
plugins: [],
|
|
81
81
|
extends: [],
|
|
82
82
|
rules,
|
|
@@ -15,7 +15,7 @@ function measureAsync() {
|
|
|
15
15
|
return lint_1.lintDocument({
|
|
16
16
|
externalRefResolver: new resolve_1.BaseResolver(),
|
|
17
17
|
document: rebillyDocument,
|
|
18
|
-
config: new config_1.
|
|
18
|
+
config: new config_1.StyleguideConfig(config_1.resolvePreset('recommended', [config_1.defaultPlugin])),
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
exports.measureAsync = measureAsync;
|
package/lib/benchmark/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Document } from '../resolve';
|
|
2
2
|
import { Oas3RuleSet } from '../oas-types';
|
|
3
|
-
import {
|
|
3
|
+
import { StyleguideConfig } from '../config';
|
|
4
4
|
import type { Plugin } from '../config/types';
|
|
5
5
|
export declare function parseYamlToDocument(body: string, absoluteRef?: string): Document;
|
|
6
|
-
export declare function makeConfigForRuleset(rules: Oas3RuleSet, plugin?: Partial<Plugin>):
|
|
6
|
+
export declare function makeConfigForRuleset(rules: Oas3RuleSet, plugin?: Partial<Plugin>): StyleguideConfig;
|
package/lib/benchmark/utils.js
CHANGED
|
@@ -25,7 +25,7 @@ function makeConfigForRuleset(rules, plugin) {
|
|
|
25
25
|
if (rules) {
|
|
26
26
|
extendConfigs.push({ rules });
|
|
27
27
|
}
|
|
28
|
-
const
|
|
29
|
-
return new config_1.
|
|
28
|
+
const styleguide = config_1.mergeExtends(extendConfigs);
|
|
29
|
+
return new config_1.StyleguideConfig(styleguide);
|
|
30
30
|
}
|
|
31
31
|
exports.makeConfigForRuleset = makeConfigForRuleset;
|
package/lib/bundle.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { BaseResolver, Document } from './resolve';
|
|
|
2
2
|
import { Oas3Rule } from './visitors';
|
|
3
3
|
import { NormalizedNodeType, NodeType } from './types';
|
|
4
4
|
import { OasMajorVersion } from './oas-types';
|
|
5
|
-
import type { Config,
|
|
5
|
+
import type { Config, StyleguideConfig } from './config';
|
|
6
6
|
export declare type Oas3RuleSet = Record<string, Oas3Rule>;
|
|
7
7
|
export declare enum OasVersion {
|
|
8
8
|
Version2 = "oas2",
|
|
@@ -29,7 +29,7 @@ export declare function bundle(opts: {
|
|
|
29
29
|
}>;
|
|
30
30
|
export declare function bundleDocument(opts: {
|
|
31
31
|
document: Document;
|
|
32
|
-
config:
|
|
32
|
+
config: StyleguideConfig;
|
|
33
33
|
customTypes?: Record<string, NodeType>;
|
|
34
34
|
externalRefResolver: BaseResolver;
|
|
35
35
|
dereference?: boolean;
|
package/lib/bundle.js
CHANGED
|
@@ -42,7 +42,7 @@ function bundle(opts) {
|
|
|
42
42
|
if (document instanceof Error) {
|
|
43
43
|
throw document;
|
|
44
44
|
}
|
|
45
|
-
return bundleDocument(Object.assign(Object.assign({ document }, opts), { config: opts.config.
|
|
45
|
+
return bundleDocument(Object.assign(Object.assign({ document }, opts), { config: opts.config.styleguide, externalRefResolver }));
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
exports.bundle = bundle;
|
|
@@ -71,7 +71,7 @@ function bundleDocument(opts) {
|
|
|
71
71
|
ruleId: 'remove-unused-components',
|
|
72
72
|
visitor: oasMajorVersion === oas_types_1.OasMajorVersion.Version2
|
|
73
73
|
? remove_unused_components_1.RemoveUnusedComponents({})
|
|
74
|
-
: remove_unused_components_2.RemoveUnusedComponents({})
|
|
74
|
+
: remove_unused_components_2.RemoveUnusedComponents({}),
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
const resolvedRefMap = yield resolve_1.resolveDocument({
|
|
@@ -231,9 +231,12 @@ function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDo
|
|
|
231
231
|
ctx.parent[ctx.key] = resolved.node;
|
|
232
232
|
}
|
|
233
233
|
else {
|
|
234
|
+
// TODO: why $ref isn't optional in OasRef?
|
|
235
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
234
236
|
// @ts-ignore
|
|
235
237
|
delete ref.$ref;
|
|
236
|
-
Object.assign(
|
|
238
|
+
const obj = Object.assign({}, resolved.node, ref);
|
|
239
|
+
Object.assign(ref, obj); // assign ref itself again so ref fields take precedence
|
|
237
240
|
}
|
|
238
241
|
}
|
|
239
242
|
function saveComponent(componentType, target, ctx) {
|
|
@@ -259,7 +262,7 @@ function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDo
|
|
|
259
262
|
const [fileRef, pointer] = [target.location.source.absoluteRef, target.location.pointer];
|
|
260
263
|
const componentsGroup = components[componentType];
|
|
261
264
|
let name = '';
|
|
262
|
-
const refParts = pointer.slice(2).split('/').filter(
|
|
265
|
+
const refParts = pointer.slice(2).split('/').filter(utils_1.isTruthy); // slice(2) removes "#/"
|
|
263
266
|
while (refParts.length > 0) {
|
|
264
267
|
name = refParts.pop() + (name ? `-${name}` : '');
|
|
265
268
|
if (!componentsGroup ||
|
package/lib/config/all.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
declare const _default:
|
|
1
|
+
import type { PluginStyleguideConfig } from './types';
|
|
2
|
+
declare const _default: PluginStyleguideConfig;
|
|
3
3
|
export default _default;
|
package/lib/config/all.js
CHANGED
|
@@ -19,7 +19,7 @@ exports.default = {
|
|
|
19
19
|
'operation-description': 'error',
|
|
20
20
|
'operation-2xx-response': 'error',
|
|
21
21
|
'operation-4xx-response': 'error',
|
|
22
|
-
|
|
22
|
+
assertions: 'error',
|
|
23
23
|
'operation-operationId': 'error',
|
|
24
24
|
'operation-summary': 'error',
|
|
25
25
|
'operation-operationId-unique': 'error',
|
|
@@ -51,7 +51,7 @@ exports.default = {
|
|
|
51
51
|
'no-example-value-and-externalValue': 'error',
|
|
52
52
|
'no-unused-components': 'error',
|
|
53
53
|
'no-undefined-server-variable': 'error',
|
|
54
|
-
'no-
|
|
54
|
+
'no-server-variables-empty-enum': 'error',
|
|
55
55
|
},
|
|
56
56
|
oas3_1Rules: {
|
|
57
57
|
'no-server-example.com': 'error',
|
|
@@ -60,6 +60,6 @@ exports.default = {
|
|
|
60
60
|
'no-example-value-and-externalValue': 'error',
|
|
61
61
|
'no-unused-components': 'error',
|
|
62
62
|
'no-undefined-server-variable': 'error',
|
|
63
|
-
'no-
|
|
63
|
+
'no-server-variables-empty-enum': 'error',
|
|
64
64
|
},
|
|
65
65
|
};
|
package/lib/config/builtIn.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const builtInConfigs: Record<string,
|
|
1
|
+
import type { StyleguideRawConfig, Plugin } from './types';
|
|
2
|
+
export declare const builtInConfigs: Record<string, StyleguideRawConfig>;
|
|
3
3
|
export declare const defaultPlugin: Plugin;
|
package/lib/config/builtIn.js
CHANGED
|
@@ -15,8 +15,8 @@ exports.builtInConfigs = {
|
|
|
15
15
|
minimal: minimal_1.default,
|
|
16
16
|
all: all_1.default,
|
|
17
17
|
'redocly-registry': {
|
|
18
|
-
decorators: { 'registry-dependencies': 'on' }
|
|
19
|
-
}
|
|
18
|
+
decorators: { 'registry-dependencies': 'on' },
|
|
19
|
+
},
|
|
20
20
|
};
|
|
21
21
|
exports.defaultPlugin = {
|
|
22
22
|
id: '',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseResolver } from '../resolve';
|
|
2
|
-
import type {
|
|
2
|
+
import type { StyleguideRawConfig, Plugin, RawConfig, ResolvedApi, ResolvedStyleguideConfig } from './types';
|
|
3
3
|
import { Config } from './config';
|
|
4
4
|
export declare function resolveConfig(rawConfig: RawConfig, configPath?: string): Promise<Config>;
|
|
5
5
|
export declare function resolvePlugins(plugins: (string | Plugin)[] | null, configPath?: string): Plugin[];
|
|
@@ -8,9 +8,9 @@ export declare function resolveApis({ rawConfig, configPath, resolver, }: {
|
|
|
8
8
|
configPath?: string;
|
|
9
9
|
resolver?: BaseResolver;
|
|
10
10
|
}): Promise<Record<string, ResolvedApi>>;
|
|
11
|
-
export declare function
|
|
12
|
-
|
|
11
|
+
export declare function resolveStyleguideConfig(opts: {
|
|
12
|
+
styleguideConfig?: StyleguideRawConfig;
|
|
13
13
|
configPath?: string;
|
|
14
14
|
resolver?: BaseResolver;
|
|
15
|
-
}, parentConfigPaths?: string[], extendPaths?: string[]): Promise<
|
|
16
|
-
export declare function resolvePreset(presetName: string, plugins: Plugin[]):
|
|
15
|
+
}, parentConfigPaths?: string[], extendPaths?: string[]): Promise<ResolvedStyleguideConfig>;
|
|
16
|
+
export declare function resolvePreset(presetName: string, plugins: Plugin[]): ResolvedStyleguideConfig;
|
|
@@ -20,62 +20,80 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.resolvePreset = exports.
|
|
23
|
+
exports.resolvePreset = exports.resolveStyleguideConfig = exports.resolveApis = exports.resolvePlugins = exports.resolveConfig = void 0;
|
|
24
24
|
const path = require("path");
|
|
25
|
-
const colorette_1 = require("colorette");
|
|
26
25
|
const ref_utils_1 = require("../ref-utils");
|
|
27
26
|
const resolve_1 = require("../resolve");
|
|
28
27
|
const builtIn_1 = require("./builtIn");
|
|
29
28
|
const utils_1 = require("./utils");
|
|
29
|
+
const env_1 = require("../env");
|
|
30
30
|
const utils_2 = require("../utils");
|
|
31
31
|
const config_1 = require("./config");
|
|
32
|
+
const logger_1 = require("../logger");
|
|
32
33
|
function resolveConfig(rawConfig, configPath) {
|
|
33
34
|
var _a, _b, _c, _d, _e;
|
|
34
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
if ((_b = (_a = rawConfig.
|
|
36
|
+
if ((_b = (_a = rawConfig.styleguide) === null || _a === void 0 ? void 0 : _a.extends) === null || _b === void 0 ? void 0 : _b.some(utils_2.isNotString)) {
|
|
36
37
|
throw new Error(`Error configuration format not detected in extends value must contain strings`);
|
|
37
38
|
}
|
|
38
39
|
const resolver = new resolve_1.BaseResolver(utils_1.getResolveConfig(rawConfig.resolve));
|
|
39
|
-
const configExtends = (_d = (_c = rawConfig === null || rawConfig === void 0 ? void 0 : rawConfig.
|
|
40
|
-
const recommendedFallback = !((_e = rawConfig === null || rawConfig === void 0 ? void 0 : rawConfig.
|
|
41
|
-
const
|
|
40
|
+
const configExtends = (_d = (_c = rawConfig === null || rawConfig === void 0 ? void 0 : rawConfig.styleguide) === null || _c === void 0 ? void 0 : _c.extends) !== null && _d !== void 0 ? _d : ['recommended'];
|
|
41
|
+
const recommendedFallback = !((_e = rawConfig === null || rawConfig === void 0 ? void 0 : rawConfig.styleguide) === null || _e === void 0 ? void 0 : _e.extends);
|
|
42
|
+
const styleguideConfig = Object.assign(Object.assign({}, rawConfig === null || rawConfig === void 0 ? void 0 : rawConfig.styleguide), { extends: configExtends, recommendedFallback });
|
|
42
43
|
const apis = yield resolveApis({
|
|
43
|
-
rawConfig: Object.assign(Object.assign({}, rawConfig), {
|
|
44
|
+
rawConfig: Object.assign(Object.assign({}, rawConfig), { styleguide: styleguideConfig }),
|
|
44
45
|
configPath,
|
|
45
46
|
resolver,
|
|
46
47
|
});
|
|
47
|
-
const
|
|
48
|
-
|
|
48
|
+
const styleguide = yield resolveStyleguideConfig({
|
|
49
|
+
styleguideConfig,
|
|
49
50
|
configPath,
|
|
50
51
|
resolver,
|
|
51
52
|
});
|
|
52
53
|
return new config_1.Config(Object.assign(Object.assign({}, rawConfig), { apis,
|
|
53
|
-
|
|
54
|
+
styleguide }), configPath);
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
exports.resolveConfig = resolveConfig;
|
|
57
58
|
function resolvePlugins(plugins, configPath = '') {
|
|
58
59
|
if (!plugins)
|
|
59
60
|
return [];
|
|
60
|
-
//
|
|
61
|
-
const requireFunc =
|
|
61
|
+
// TODO: implement or reuse Resolver approach so it will work in node and browser envs
|
|
62
|
+
const requireFunc = (plugin) => {
|
|
63
|
+
if (env_1.isBrowser && utils_2.isString(plugin)) {
|
|
64
|
+
logger_1.logger.error(`Cannot load ${plugin}. Plugins aren't supported in browser yet.`);
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
if (utils_2.isString(plugin)) {
|
|
68
|
+
const absoltePluginPath = path.resolve(path.dirname(configPath), plugin);
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
return typeof __webpack_require__ === 'function'
|
|
72
|
+
? // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
__non_webpack_require__(absoltePluginPath)
|
|
75
|
+
: require(absoltePluginPath);
|
|
76
|
+
}
|
|
77
|
+
return plugin;
|
|
78
|
+
};
|
|
62
79
|
const seenPluginIds = new Map();
|
|
63
80
|
return plugins
|
|
64
81
|
.map((p) => {
|
|
65
82
|
if (utils_2.isString(p) && ref_utils_1.isAbsoluteUrl(p)) {
|
|
66
|
-
throw new Error(
|
|
83
|
+
throw new Error(logger_1.colorize.red(`We don't support remote plugins yet.`));
|
|
67
84
|
}
|
|
68
85
|
// TODO: resolve npm packages similar to eslint
|
|
69
|
-
const pluginModule =
|
|
70
|
-
|
|
71
|
-
|
|
86
|
+
const pluginModule = requireFunc(p);
|
|
87
|
+
if (!pluginModule) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
72
90
|
const id = pluginModule.id;
|
|
73
91
|
if (typeof id !== 'string') {
|
|
74
|
-
throw new Error(
|
|
92
|
+
throw new Error(logger_1.colorize.red(`Plugin must define \`id\` property in ${logger_1.colorize.blue(p.toString())}.`));
|
|
75
93
|
}
|
|
76
94
|
if (seenPluginIds.has(id)) {
|
|
77
95
|
const pluginPath = seenPluginIds.get(id);
|
|
78
|
-
throw new Error(
|
|
96
|
+
throw new Error(logger_1.colorize.red(`Plugin "id" must be unique. Plugin ${logger_1.colorize.blue(p.toString())} uses id "${logger_1.colorize.blue(id)}" already seen in ${logger_1.colorize.blue(pluginPath)}`));
|
|
79
97
|
}
|
|
80
98
|
seenPluginIds.set(id, p.toString());
|
|
81
99
|
const plugin = Object.assign(Object.assign({ id }, (pluginModule.configs ? { configs: pluginModule.configs } : {})), (pluginModule.typeExtension ? { typeExtension: pluginModule.typeExtension } : {}));
|
|
@@ -123,36 +141,36 @@ exports.resolvePlugins = resolvePlugins;
|
|
|
123
141
|
function resolveApis({ rawConfig, configPath = '', resolver, }) {
|
|
124
142
|
var _a, _b;
|
|
125
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
-
const { apis = {},
|
|
127
|
-
|
|
144
|
+
const { apis = {}, styleguide: styleguideConfig = {} } = rawConfig;
|
|
145
|
+
const resolvedApis = {};
|
|
128
146
|
for (const [apiName, apiContent] of Object.entries(apis || {})) {
|
|
129
|
-
if ((_b = (_a = apiContent.
|
|
147
|
+
if ((_b = (_a = apiContent.styleguide) === null || _a === void 0 ? void 0 : _a.extends) === null || _b === void 0 ? void 0 : _b.some(utils_2.isNotString)) {
|
|
130
148
|
throw new Error(`Error configuration format not detected in extends value must contain strings`);
|
|
131
149
|
}
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
|
|
150
|
+
const rawStyleguideConfig = getMergedRawStyleguideConfig(styleguideConfig, apiContent.styleguide);
|
|
151
|
+
const resolvedApiConfig = yield resolveStyleguideConfig({
|
|
152
|
+
styleguideConfig: rawStyleguideConfig,
|
|
135
153
|
configPath,
|
|
136
154
|
resolver,
|
|
137
155
|
});
|
|
138
|
-
resolvedApis[apiName] = Object.assign(Object.assign({}, apiContent), {
|
|
156
|
+
resolvedApis[apiName] = Object.assign(Object.assign({}, apiContent), { styleguide: resolvedApiConfig });
|
|
139
157
|
}
|
|
140
158
|
return resolvedApis;
|
|
141
159
|
});
|
|
142
160
|
}
|
|
143
161
|
exports.resolveApis = resolveApis;
|
|
144
|
-
function
|
|
162
|
+
function resolveAndMergeNestedStyleguideConfig({ styleguideConfig, configPath = '', resolver = new resolve_1.BaseResolver(), }, parentConfigPaths = [], extendPaths = []) {
|
|
145
163
|
var _a, _b, _c;
|
|
146
164
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
165
|
if (parentConfigPaths.includes(configPath)) {
|
|
148
166
|
throw new Error(`Circular dependency in config file: "${configPath}"`);
|
|
149
167
|
}
|
|
150
|
-
const plugins = utils_1.getUniquePlugins(resolvePlugins([...((
|
|
151
|
-
const pluginPaths = (_a =
|
|
168
|
+
const plugins = utils_1.getUniquePlugins(resolvePlugins([...((styleguideConfig === null || styleguideConfig === void 0 ? void 0 : styleguideConfig.plugins) || []), builtIn_1.defaultPlugin], configPath));
|
|
169
|
+
const pluginPaths = (_a = styleguideConfig === null || styleguideConfig === void 0 ? void 0 : styleguideConfig.plugins) === null || _a === void 0 ? void 0 : _a.filter(utils_2.isString).map((p) => path.resolve(path.dirname(configPath), p));
|
|
152
170
|
const resolvedConfigPath = ref_utils_1.isAbsoluteUrl(configPath)
|
|
153
171
|
? configPath
|
|
154
172
|
: configPath && path.resolve(configPath);
|
|
155
|
-
const extendConfigs = yield Promise.all(((_b =
|
|
173
|
+
const extendConfigs = yield Promise.all(((_b = styleguideConfig === null || styleguideConfig === void 0 ? void 0 : styleguideConfig.extends) === null || _b === void 0 ? void 0 : _b.map((presetItem) => __awaiter(this, void 0, void 0, function* () {
|
|
156
174
|
if (!ref_utils_1.isAbsoluteUrl(presetItem) && !path.extname(presetItem)) {
|
|
157
175
|
return resolvePreset(presetItem, plugins);
|
|
158
176
|
}
|
|
@@ -161,63 +179,66 @@ function resolveAndMergeNestedLint({ lintConfig, configPath = '', resolver = new
|
|
|
161
179
|
: ref_utils_1.isAbsoluteUrl(configPath)
|
|
162
180
|
? new URL(presetItem, configPath).href
|
|
163
181
|
: path.resolve(path.dirname(configPath), presetItem);
|
|
164
|
-
const
|
|
165
|
-
return yield
|
|
166
|
-
|
|
182
|
+
const extendedStyleguideConfig = yield loadExtendStyleguideConfig(pathItem, resolver);
|
|
183
|
+
return yield resolveAndMergeNestedStyleguideConfig({
|
|
184
|
+
styleguideConfig: extendedStyleguideConfig,
|
|
167
185
|
configPath: pathItem,
|
|
168
186
|
resolver: resolver,
|
|
169
187
|
}, [...parentConfigPaths, resolvedConfigPath], extendPaths);
|
|
170
188
|
}))) || []);
|
|
171
189
|
const _d = utils_1.mergeExtends([
|
|
172
190
|
...extendConfigs,
|
|
173
|
-
Object.assign(Object.assign({},
|
|
174
|
-
]), { plugins: mergedPlugins = [] } = _d,
|
|
175
|
-
return Object.assign(Object.assign({},
|
|
191
|
+
Object.assign(Object.assign({}, styleguideConfig), { plugins, extends: undefined, extendPaths: [...parentConfigPaths, resolvedConfigPath], pluginPaths }),
|
|
192
|
+
]), { plugins: mergedPlugins = [] } = _d, styleguide = __rest(_d, ["plugins"]);
|
|
193
|
+
return Object.assign(Object.assign({}, styleguide), { extendPaths: (_c = styleguide.extendPaths) === null || _c === void 0 ? void 0 : _c.filter((path) => path && !ref_utils_1.isAbsoluteUrl(path)), plugins: utils_1.getUniquePlugins(mergedPlugins), recommendedFallback: styleguideConfig === null || styleguideConfig === void 0 ? void 0 : styleguideConfig.recommendedFallback, doNotResolveExamples: styleguideConfig === null || styleguideConfig === void 0 ? void 0 : styleguideConfig.doNotResolveExamples });
|
|
176
194
|
});
|
|
177
195
|
}
|
|
178
|
-
function
|
|
196
|
+
function resolveStyleguideConfig(opts, parentConfigPaths = [], extendPaths = []) {
|
|
179
197
|
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
-
const
|
|
181
|
-
return Object.assign(Object.assign({},
|
|
198
|
+
const resolvedStyleguideConfig = yield resolveAndMergeNestedStyleguideConfig(opts, parentConfigPaths, extendPaths);
|
|
199
|
+
return Object.assign(Object.assign({}, resolvedStyleguideConfig), { rules: resolvedStyleguideConfig.rules &&
|
|
200
|
+
groupStyleguideAssertionRules(resolvedStyleguideConfig.rules) });
|
|
182
201
|
});
|
|
183
202
|
}
|
|
184
|
-
exports.
|
|
203
|
+
exports.resolveStyleguideConfig = resolveStyleguideConfig;
|
|
185
204
|
function resolvePreset(presetName, plugins) {
|
|
186
205
|
var _a;
|
|
187
206
|
const { pluginId, configName } = utils_1.parsePresetName(presetName);
|
|
188
207
|
const plugin = plugins.find((p) => p.id === pluginId);
|
|
189
208
|
if (!plugin) {
|
|
190
|
-
throw new Error(`Invalid config ${
|
|
209
|
+
throw new Error(`Invalid config ${logger_1.colorize.red(presetName)}: plugin ${pluginId} is not included.`);
|
|
191
210
|
}
|
|
192
211
|
const preset = (_a = plugin.configs) === null || _a === void 0 ? void 0 : _a[configName];
|
|
193
212
|
if (!preset) {
|
|
194
213
|
throw new Error(pluginId
|
|
195
|
-
? `Invalid config ${
|
|
196
|
-
: `Invalid config ${
|
|
214
|
+
? `Invalid config ${logger_1.colorize.red(presetName)}: plugin ${pluginId} doesn't export config with name ${configName}.`
|
|
215
|
+
: `Invalid config ${logger_1.colorize.red(presetName)}: there is no such built-in config.`);
|
|
197
216
|
}
|
|
198
217
|
return preset;
|
|
199
218
|
}
|
|
200
219
|
exports.resolvePreset = resolvePreset;
|
|
201
|
-
function
|
|
220
|
+
function loadExtendStyleguideConfig(filePath, resolver) {
|
|
202
221
|
return __awaiter(this, void 0, void 0, function* () {
|
|
203
222
|
try {
|
|
204
223
|
const fileSource = yield resolver.loadExternalRef(filePath);
|
|
205
224
|
const rawConfig = utils_1.transformConfig(utils_2.parseYaml(fileSource.body));
|
|
206
|
-
if (!rawConfig.
|
|
207
|
-
throw new Error(`
|
|
225
|
+
if (!rawConfig.styleguide) {
|
|
226
|
+
throw new Error(`Styleguide configuration format not detected: "${filePath}"`);
|
|
208
227
|
}
|
|
209
|
-
return rawConfig.
|
|
228
|
+
return rawConfig.styleguide;
|
|
210
229
|
}
|
|
211
230
|
catch (error) {
|
|
212
231
|
throw new Error(`Failed to load "${filePath}": ${error.message}`);
|
|
213
232
|
}
|
|
214
233
|
});
|
|
215
234
|
}
|
|
216
|
-
function
|
|
217
|
-
const resultLint = Object.assign(Object.assign(Object.assign({},
|
|
235
|
+
function getMergedRawStyleguideConfig(rootStyleguideConfig, apiStyleguideConfig) {
|
|
236
|
+
const resultLint = Object.assign(Object.assign(Object.assign({}, rootStyleguideConfig), apiStyleguideConfig), { rules: Object.assign(Object.assign({}, rootStyleguideConfig === null || rootStyleguideConfig === void 0 ? void 0 : rootStyleguideConfig.rules), apiStyleguideConfig === null || apiStyleguideConfig === void 0 ? void 0 : apiStyleguideConfig.rules), oas2Rules: Object.assign(Object.assign({}, rootStyleguideConfig === null || rootStyleguideConfig === void 0 ? void 0 : rootStyleguideConfig.oas2Rules), apiStyleguideConfig === null || apiStyleguideConfig === void 0 ? void 0 : apiStyleguideConfig.oas2Rules), oas3_0Rules: Object.assign(Object.assign({}, rootStyleguideConfig === null || rootStyleguideConfig === void 0 ? void 0 : rootStyleguideConfig.oas3_0Rules), apiStyleguideConfig === null || apiStyleguideConfig === void 0 ? void 0 : apiStyleguideConfig.oas3_0Rules), oas3_1Rules: Object.assign(Object.assign({}, rootStyleguideConfig === null || rootStyleguideConfig === void 0 ? void 0 : rootStyleguideConfig.oas3_1Rules), apiStyleguideConfig === null || apiStyleguideConfig === void 0 ? void 0 : apiStyleguideConfig.oas3_1Rules), preprocessors: Object.assign(Object.assign({}, rootStyleguideConfig === null || rootStyleguideConfig === void 0 ? void 0 : rootStyleguideConfig.preprocessors), apiStyleguideConfig === null || apiStyleguideConfig === void 0 ? void 0 : apiStyleguideConfig.preprocessors), oas2Preprocessors: Object.assign(Object.assign({}, rootStyleguideConfig === null || rootStyleguideConfig === void 0 ? void 0 : rootStyleguideConfig.oas2Preprocessors), apiStyleguideConfig === null || apiStyleguideConfig === void 0 ? void 0 : apiStyleguideConfig.oas2Preprocessors), oas3_0Preprocessors: Object.assign(Object.assign({}, rootStyleguideConfig === null || rootStyleguideConfig === void 0 ? void 0 : rootStyleguideConfig.oas3_0Preprocessors), apiStyleguideConfig === null || apiStyleguideConfig === void 0 ? void 0 : apiStyleguideConfig.oas3_0Preprocessors), oas3_1Preprocessors: Object.assign(Object.assign({}, rootStyleguideConfig === null || rootStyleguideConfig === void 0 ? void 0 : rootStyleguideConfig.oas3_1Preprocessors), apiStyleguideConfig === null || apiStyleguideConfig === void 0 ? void 0 : apiStyleguideConfig.oas3_1Preprocessors), decorators: Object.assign(Object.assign({}, rootStyleguideConfig === null || rootStyleguideConfig === void 0 ? void 0 : rootStyleguideConfig.decorators), apiStyleguideConfig === null || apiStyleguideConfig === void 0 ? void 0 : apiStyleguideConfig.decorators), oas2Decorators: Object.assign(Object.assign({}, rootStyleguideConfig === null || rootStyleguideConfig === void 0 ? void 0 : rootStyleguideConfig.oas2Decorators), apiStyleguideConfig === null || apiStyleguideConfig === void 0 ? void 0 : apiStyleguideConfig.oas2Decorators), oas3_0Decorators: Object.assign(Object.assign({}, rootStyleguideConfig === null || rootStyleguideConfig === void 0 ? void 0 : rootStyleguideConfig.oas3_0Decorators), apiStyleguideConfig === null || apiStyleguideConfig === void 0 ? void 0 : apiStyleguideConfig.oas3_0Decorators), oas3_1Decorators: Object.assign(Object.assign({}, rootStyleguideConfig === null || rootStyleguideConfig === void 0 ? void 0 : rootStyleguideConfig.oas3_1Decorators), apiStyleguideConfig === null || apiStyleguideConfig === void 0 ? void 0 : apiStyleguideConfig.oas3_1Decorators), recommendedFallback: (apiStyleguideConfig === null || apiStyleguideConfig === void 0 ? void 0 : apiStyleguideConfig.extends)
|
|
237
|
+
? false
|
|
238
|
+
: rootStyleguideConfig.recommendedFallback });
|
|
218
239
|
return resultLint;
|
|
219
240
|
}
|
|
220
|
-
function
|
|
241
|
+
function groupStyleguideAssertionRules(rules) {
|
|
221
242
|
if (!rules) {
|
|
222
243
|
return rules;
|
|
223
244
|
}
|
package/lib/config/config.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { NormalizedProblem } from '../walk';
|
|
3
2
|
import { OasVersion, OasMajorVersion, Oas2RuleSet, Oas3RuleSet } from '../oas-types';
|
|
4
3
|
import type { NodeType } from '../types';
|
|
5
|
-
import type { DecoratorConfig, Plugin, PreprocessorConfig, Region, ResolveConfig, ResolvedApi, ResolvedConfig,
|
|
6
|
-
export declare const env: NodeJS.ProcessEnv;
|
|
4
|
+
import type { DecoratorConfig, Plugin, PreprocessorConfig, Region, ResolveConfig, ResolvedApi, ResolvedConfig, ResolvedStyleguideConfig, RuleConfig } from './types';
|
|
7
5
|
export declare const IGNORE_FILE = ".redocly.lint-ignore.yaml";
|
|
8
6
|
export declare const DEFAULT_REGION = "us";
|
|
9
7
|
export declare const DOMAINS: {
|
|
@@ -11,8 +9,8 @@ export declare const DOMAINS: {
|
|
|
11
9
|
eu: string;
|
|
12
10
|
};
|
|
13
11
|
export declare const AVAILABLE_REGIONS: Region[];
|
|
14
|
-
export declare class
|
|
15
|
-
rawConfig:
|
|
12
|
+
export declare class StyleguideConfig {
|
|
13
|
+
rawConfig: ResolvedStyleguideConfig;
|
|
16
14
|
configFile?: string | undefined;
|
|
17
15
|
plugins: Plugin[];
|
|
18
16
|
ignore: Record<string, Record<string, Set<string>>>;
|
|
@@ -25,20 +23,20 @@ export declare class LintConfig {
|
|
|
25
23
|
recommendedFallback: boolean;
|
|
26
24
|
extendPaths: string[];
|
|
27
25
|
pluginPaths: string[];
|
|
28
|
-
constructor(rawConfig:
|
|
26
|
+
constructor(rawConfig: ResolvedStyleguideConfig, configFile?: string | undefined);
|
|
29
27
|
resolveIgnore(ignoreFile?: string): void;
|
|
30
28
|
saveIgnore(): void;
|
|
31
29
|
addIgnore(problem: NormalizedProblem): void;
|
|
32
30
|
addProblemToIgnore(problem: NormalizedProblem): NormalizedProblem;
|
|
33
31
|
extendTypes(types: Record<string, NodeType>, version: OasVersion): Record<string, NodeType>;
|
|
34
32
|
getRuleSettings(ruleId: string, oasVersion: OasVersion): {
|
|
35
|
-
severity:
|
|
33
|
+
severity: string;
|
|
36
34
|
};
|
|
37
35
|
getPreprocessorSettings(ruleId: string, oasVersion: OasVersion): {
|
|
38
|
-
severity:
|
|
36
|
+
severity: string;
|
|
39
37
|
};
|
|
40
38
|
getDecoratorSettings(ruleId: string, oasVersion: OasVersion): {
|
|
41
|
-
severity:
|
|
39
|
+
severity: string;
|
|
42
40
|
};
|
|
43
41
|
getUnusedRules(): {
|
|
44
42
|
rules: string[];
|
|
@@ -54,7 +52,7 @@ export declare class Config {
|
|
|
54
52
|
rawConfig: ResolvedConfig;
|
|
55
53
|
configFile?: string | undefined;
|
|
56
54
|
apis: Record<string, ResolvedApi>;
|
|
57
|
-
|
|
55
|
+
styleguide: StyleguideConfig;
|
|
58
56
|
resolve: ResolveConfig;
|
|
59
57
|
licenseKey?: string;
|
|
60
58
|
region?: Region;
|
package/lib/config/config.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Config = exports.
|
|
3
|
+
exports.Config = exports.StyleguideConfig = exports.AVAILABLE_REGIONS = exports.DOMAINS = exports.DEFAULT_REGION = exports.IGNORE_FILE = void 0;
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const path = require("path");
|
|
6
6
|
const js_yaml_1 = require("../js-yaml");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
const oas_types_1 = require("../oas-types");
|
|
9
|
+
const env_1 = require("../env");
|
|
9
10
|
const utils_2 = require("./utils");
|
|
10
|
-
// Alias environment here so this file can work in browser environments too.
|
|
11
|
-
exports.env = typeof process !== 'undefined' ? process.env || {} : {};
|
|
12
11
|
exports.IGNORE_FILE = '.redocly.lint-ignore.yaml';
|
|
13
12
|
const IGNORE_BANNER = `# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API.\n` +
|
|
14
13
|
`# See https://redoc.ly/docs/cli/ for more information.\n`;
|
|
@@ -19,7 +18,7 @@ function getDomains() {
|
|
|
19
18
|
eu: 'eu.redocly.com',
|
|
20
19
|
};
|
|
21
20
|
// FIXME: temporary fix for our lab environments
|
|
22
|
-
const domain =
|
|
21
|
+
const domain = env_1.env.REDOCLY_DOMAIN;
|
|
23
22
|
if (domain === null || domain === void 0 ? void 0 : domain.endsWith('.redocly.host')) {
|
|
24
23
|
domains[domain.split('.')[0]] = domain;
|
|
25
24
|
}
|
|
@@ -40,7 +39,7 @@ function getIgnoreFilePath(configFile) {
|
|
|
40
39
|
}
|
|
41
40
|
exports.DOMAINS = getDomains();
|
|
42
41
|
exports.AVAILABLE_REGIONS = Object.keys(exports.DOMAINS);
|
|
43
|
-
class
|
|
42
|
+
class StyleguideConfig {
|
|
44
43
|
constructor(rawConfig, configFile) {
|
|
45
44
|
this.rawConfig = rawConfig;
|
|
46
45
|
this.configFile = configFile;
|
|
@@ -125,10 +124,12 @@ class LintConfig {
|
|
|
125
124
|
if (!plugin.typeExtension.oas3)
|
|
126
125
|
continue;
|
|
127
126
|
extendedTypes = plugin.typeExtension.oas3(extendedTypes, version);
|
|
127
|
+
break;
|
|
128
128
|
case oas_types_1.OasVersion.Version2:
|
|
129
129
|
if (!plugin.typeExtension.oas2)
|
|
130
130
|
continue;
|
|
131
131
|
extendedTypes = plugin.typeExtension.oas2(extendedTypes, version);
|
|
132
|
+
break;
|
|
132
133
|
default:
|
|
133
134
|
throw new Error('Not implemented');
|
|
134
135
|
}
|
|
@@ -193,12 +194,14 @@ class LintConfig {
|
|
|
193
194
|
getRulesForOasVersion(version) {
|
|
194
195
|
switch (version) {
|
|
195
196
|
case oas_types_1.OasMajorVersion.Version3:
|
|
197
|
+
// eslint-disable-next-line no-case-declarations
|
|
196
198
|
const oas3Rules = []; // default ruleset
|
|
197
199
|
this.plugins.forEach((p) => { var _a; return ((_a = p.preprocessors) === null || _a === void 0 ? void 0 : _a.oas3) && oas3Rules.push(p.preprocessors.oas3); });
|
|
198
200
|
this.plugins.forEach((p) => { var _a; return ((_a = p.rules) === null || _a === void 0 ? void 0 : _a.oas3) && oas3Rules.push(p.rules.oas3); });
|
|
199
201
|
this.plugins.forEach((p) => { var _a; return ((_a = p.decorators) === null || _a === void 0 ? void 0 : _a.oas3) && oas3Rules.push(p.decorators.oas3); });
|
|
200
202
|
return oas3Rules;
|
|
201
203
|
case oas_types_1.OasMajorVersion.Version2:
|
|
204
|
+
// eslint-disable-next-line no-case-declarations
|
|
202
205
|
const oas2Rules = []; // default ruleset
|
|
203
206
|
this.plugins.forEach((p) => { var _a; return ((_a = p.preprocessors) === null || _a === void 0 ? void 0 : _a.oas2) && oas2Rules.push(p.preprocessors.oas2); });
|
|
204
207
|
this.plugins.forEach((p) => { var _a; return ((_a = p.rules) === null || _a === void 0 ? void 0 : _a.oas2) && oas2Rules.push(p.rules.oas2); });
|
|
@@ -234,13 +237,13 @@ class LintConfig {
|
|
|
234
237
|
}
|
|
235
238
|
}
|
|
236
239
|
}
|
|
237
|
-
exports.
|
|
240
|
+
exports.StyleguideConfig = StyleguideConfig;
|
|
238
241
|
class Config {
|
|
239
242
|
constructor(rawConfig, configFile) {
|
|
240
243
|
this.rawConfig = rawConfig;
|
|
241
244
|
this.configFile = configFile;
|
|
242
245
|
this.apis = rawConfig.apis || {};
|
|
243
|
-
this.
|
|
246
|
+
this.styleguide = new StyleguideConfig(rawConfig.styleguide || {}, configFile);
|
|
244
247
|
this['features.openapi'] = rawConfig['features.openapi'] || {};
|
|
245
248
|
this['features.mockServer'] = rawConfig['features.mockServer'] || {};
|
|
246
249
|
this.resolve = utils_2.getResolveConfig(rawConfig === null || rawConfig === void 0 ? void 0 : rawConfig.resolve);
|
package/lib/config/load.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Config } from './config';
|
|
2
2
|
import type { RawConfig } from './types';
|
|
3
|
+
import { RegionalTokenWithValidity } from '../redocly/redocly-client-types';
|
|
3
4
|
export declare function loadConfig(configPath?: string | undefined, customExtends?: string[], processRawConfig?: (rawConfig: RawConfig) => void | Promise<void>): Promise<Config>;
|
|
4
5
|
export declare const CONFIG_FILE_NAMES: string[];
|
|
5
6
|
export declare function findConfig(dir?: string): string | undefined;
|
|
6
7
|
export declare function getConfig(configPath?: string | undefined): Promise<RawConfig>;
|
|
8
|
+
declare type CreateConfigOptions = {
|
|
9
|
+
extends?: string[];
|
|
10
|
+
tokens?: RegionalTokenWithValidity[];
|
|
11
|
+
};
|
|
12
|
+
export declare function createConfig(config: string | RawConfig, options?: CreateConfigOptions): Promise<Config>;
|
|
13
|
+
export {};
|