@redocly/openapi-core 1.18.0 → 1.19.0
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/CHANGELOG.md +20 -0
- package/lib/benchmark/benches/lint-with-many-rules.bench.js +2 -2
- package/lib/benchmark/benches/lint-with-nested-rule.bench.js +2 -2
- package/lib/benchmark/benches/lint-with-no-rules.bench.js +2 -2
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +2 -2
- package/lib/benchmark/benches/lint-with-top-level-rule.bench.js +2 -2
- package/lib/benchmark/benches/recommended-oas3.bench.js +2 -2
- package/lib/benchmark/benches/resolve-with-no-external.bench.js +2 -2
- package/lib/benchmark/utils.js +7 -4
- package/lib/bundle.d.ts +3 -3
- package/lib/bundle.js +128 -122
- package/lib/config/all.js +9 -0
- package/lib/config/builtIn.js +7 -1
- package/lib/config/config-resolvers.js +179 -138
- package/lib/config/config.d.ts +2 -2
- package/lib/config/config.js +53 -34
- package/lib/config/load.d.ts +1 -2
- package/lib/config/load.js +105 -117
- package/lib/config/minimal.js +9 -0
- package/lib/config/recommended-strict.js +9 -0
- package/lib/config/recommended.js +9 -0
- package/lib/config/rules.d.ts +3 -3
- package/lib/config/rules.js +1 -2
- package/lib/config/types.d.ts +9 -3
- package/lib/config/utils.js +70 -49
- package/lib/decorators/async3/index.d.ts +1 -0
- package/lib/decorators/async3/index.js +4 -0
- package/lib/decorators/common/filters/filter-helper.js +2 -3
- package/lib/decorators/common/filters/filter-in.js +1 -1
- package/lib/decorators/common/filters/filter-out.js +1 -1
- package/lib/decorators/common/info-override.js +1 -12
- package/lib/decorators/common/media-type-examples-override.js +8 -2
- package/lib/decorators/common/remove-x-internal.js +4 -5
- package/lib/decorators/oas2/remove-unused-components.js +1 -2
- package/lib/decorators/oas3/remove-unused-components.js +1 -2
- package/lib/env.d.ts +0 -1
- package/lib/env.js +1 -1
- package/lib/format/codeframes.js +10 -8
- package/lib/format/format.js +23 -15
- package/lib/index.d.ts +2 -1
- package/lib/index.js +6 -4
- package/lib/js-yaml/index.js +1 -1
- package/lib/lint.d.ts +2 -0
- package/lib/lint.js +92 -99
- package/lib/oas-types.d.ts +9 -5
- package/lib/oas-types.js +22 -12
- package/lib/redocly/domains.js +6 -6
- package/lib/redocly/index.js +60 -73
- package/lib/redocly/registry-api.js +64 -82
- package/lib/ref-utils.js +13 -13
- package/lib/resolve.js +186 -205
- package/lib/rules/ajv.js +10 -8
- package/lib/rules/async3/channels-kebab-case.d.ts +2 -0
- package/lib/rules/async3/channels-kebab-case.js +19 -0
- package/lib/rules/async3/index.d.ts +3 -0
- package/lib/rules/async3/index.js +22 -0
- package/lib/rules/async3/no-channel-trailing-slash.d.ts +2 -0
- package/lib/rules/async3/no-channel-trailing-slash.js +16 -0
- package/lib/rules/common/assertions/asserts.js +5 -5
- package/lib/rules/common/assertions/index.d.ts +5 -4
- package/lib/rules/common/assertions/utils.js +43 -28
- package/lib/rules/common/no-invalid-parameter-examples.js +1 -2
- package/lib/rules/common/no-invalid-schema-examples.js +1 -2
- package/lib/rules/common/no-required-schema-properties-undefined.js +1 -2
- package/lib/rules/common/operation-tag-defined.js +1 -2
- package/lib/rules/common/path-http-verbs-order.js +1 -1
- package/lib/rules/common/path-segment-plural.js +2 -1
- package/lib/rules/common/required-string-property-missing-min-length.js +2 -2
- package/lib/rules/common/response-contains-header.js +2 -2
- package/lib/rules/common/security-defined.js +3 -7
- package/lib/rules/common/spec.d.ts +2 -2
- package/lib/rules/common/spec.js +6 -7
- package/lib/rules/no-unresolved-refs.js +3 -4
- package/lib/rules/oas2/response-contains-property.js +1 -2
- package/lib/rules/oas3/array-parameter-serialization.js +1 -2
- package/lib/rules/oas3/component-name-unique.js +2 -4
- package/lib/rules/oas3/no-invalid-media-type-examples.js +1 -2
- package/lib/rules/oas3/no-server-variables-empty-enum.js +1 -2
- package/lib/rules/oas3/no-undefined-server-variable.js +2 -3
- package/lib/rules/oas3/no-unused-components.js +1 -2
- package/lib/rules/oas3/response-contains-property.js +1 -2
- package/lib/rules/utils.js +14 -12
- package/lib/types/arazzo.d.ts +1299 -73
- package/lib/types/arazzo.js +41 -36
- package/lib/types/asyncapi2.d.ts +17 -0
- package/lib/types/{asyncapi.js → asyncapi2.js} +71 -93
- package/lib/types/asyncapi3.d.ts +2 -0
- package/lib/types/asyncapi3.js +347 -0
- package/lib/types/index.js +19 -10
- package/lib/types/json-schema-adapter.js +4 -18
- package/lib/types/oas2.js +6 -6
- package/lib/types/oas3.js +10 -10
- package/lib/types/oas3_1.js +15 -9
- package/lib/types/redocly-yaml.d.ts +3 -1
- package/lib/types/redocly-yaml.js +131 -35
- package/lib/typings/arazzo.d.ts +28 -1
- package/lib/typings/asyncapi3.d.ts +53 -0
- package/lib/typings/asyncapi3.js +2 -0
- package/lib/utils.d.ts +12 -7
- package/lib/utils.js +91 -77
- package/lib/visitors.d.ts +11 -0
- package/lib/visitors.js +21 -8
- package/lib/walk.js +30 -23
- package/package.json +3 -3
- package/src/__tests__/bundle.test.ts +142 -0
- package/src/__tests__/lint.test.ts +0 -50
- package/src/bundle.ts +19 -6
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +22 -0
- package/src/config/__tests__/__snapshots__/config.test.ts.snap +24 -0
- package/src/config/__tests__/config.test.ts +11 -0
- package/src/config/all.ts +9 -0
- package/src/config/builtIn.ts +6 -0
- package/src/config/config-resolvers.ts +15 -2
- package/src/config/config.ts +24 -5
- package/src/config/load.ts +1 -2
- package/src/config/minimal.ts +9 -0
- package/src/config/recommended-strict.ts +9 -0
- package/src/config/recommended.ts +9 -0
- package/src/config/rules.ts +12 -4
- package/src/config/types.ts +15 -2
- package/src/config/utils.ts +15 -0
- package/src/decorators/async3/index.ts +1 -0
- package/src/decorators/common/remove-x-internal.ts +2 -2
- package/src/index.ts +2 -1
- package/src/lint.ts +26 -3
- package/src/oas-types.ts +31 -13
- package/src/rules/arazzo/index.ts +1 -1
- package/src/rules/async2/index.ts +5 -5
- package/src/rules/async3/__tests__/channels-kebab-case.test.ts +141 -0
- package/src/rules/async3/__tests__/no-channel-trailing-slash.test.ts +96 -0
- package/src/rules/async3/channels-kebab-case.ts +19 -0
- package/src/rules/async3/index.ts +23 -0
- package/src/rules/async3/no-channel-trailing-slash.ts +16 -0
- package/src/rules/common/__tests__/spec.test.ts +47 -0
- package/src/rules/common/assertions/index.ts +13 -4
- package/src/rules/common/no-invalid-schema-examples.ts +3 -2
- package/src/rules/common/path-segment-plural.ts +3 -2
- package/src/rules/common/spec.ts +2 -2
- package/src/rules/oas2/index.ts +4 -4
- package/src/rules/oas3/index.ts +39 -37
- package/src/types/arazzo.ts +28 -23
- package/src/types/{asyncapi.ts → asyncapi2.ts} +58 -76
- package/src/types/asyncapi3.ts +381 -0
- package/src/types/oas3_1.ts +3 -2
- package/src/types/redocly-yaml.ts +14 -0
- package/src/typings/arazzo.ts +41 -1
- package/src/typings/asyncapi3.ts +61 -0
- package/src/utils.ts +46 -11
- package/src/visitors.ts +18 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/types/asyncapi.d.ts +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @redocly/openapi-core
|
|
2
2
|
|
|
3
|
+
## 1.19.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added support for AsyncAPI 3.0 description linting.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Fixed an issue where `patternProperties` incorrectly caused linting errors due to a missing `PatternProperties` node.
|
|
12
|
+
|
|
13
|
+
## 1.18.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Allowed the `theme.openapi` configuration option to accept settings specific to Redoc 2.x and earlier.
|
|
18
|
+
- Fixed an issue in the OpenAPI `spec` rule where `dependentSchemas` was parsed as an array.
|
|
19
|
+
It is now correctly parsed as a map.
|
|
20
|
+
- Fixed bundling of `$refs` inside `patternProperties`.
|
|
21
|
+
- Updated AsyncAPI v2 typings to abide by JSON Schema draft-07 specification.
|
|
22
|
+
|
|
3
23
|
## 1.18.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.count = exports.name = void 0;
|
|
4
|
+
exports.measureAsync = measureAsync;
|
|
4
5
|
const fs_1 = require("fs");
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
const lint_1 = require("../../lint");
|
|
@@ -31,4 +32,3 @@ function measureAsync() {
|
|
|
31
32
|
config,
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
|
-
exports.measureAsync = measureAsync;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.count = exports.name = void 0;
|
|
4
|
+
exports.measureAsync = measureAsync;
|
|
4
5
|
const fs_1 = require("fs");
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
const lint_1 = require("../../lint");
|
|
@@ -37,4 +38,3 @@ function measureAsync() {
|
|
|
37
38
|
config,
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
|
-
exports.measureAsync = measureAsync;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.count = exports.name = void 0;
|
|
4
|
+
exports.measureAsync = measureAsync;
|
|
4
5
|
const fs_1 = require("fs");
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
const lint_1 = require("../../lint");
|
|
@@ -18,4 +19,3 @@ function measureAsync() {
|
|
|
18
19
|
config,
|
|
19
20
|
});
|
|
20
21
|
}
|
|
21
|
-
exports.measureAsync = measureAsync;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.count = exports.name = void 0;
|
|
4
|
+
exports.measureAsync = measureAsync;
|
|
4
5
|
const fs_1 = require("fs");
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
const lint_1 = require("../../lint");
|
|
@@ -30,4 +31,3 @@ function measureAsync() {
|
|
|
30
31
|
config,
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
|
-
exports.measureAsync = measureAsync;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.count = exports.name = void 0;
|
|
4
|
+
exports.measureAsync = measureAsync;
|
|
4
5
|
const fs_1 = require("fs");
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
const lint_1 = require("../../lint");
|
|
@@ -29,4 +30,3 @@ function measureAsync() {
|
|
|
29
30
|
config,
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
|
-
exports.measureAsync = measureAsync;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.count = exports.name = void 0;
|
|
4
|
+
exports.measureAsync = measureAsync;
|
|
4
5
|
const fs_1 = require("fs");
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
const lint_1 = require("../../lint");
|
|
@@ -18,4 +19,3 @@ function measureAsync() {
|
|
|
18
19
|
config: new config_1.StyleguideConfig((0, config_1.resolvePreset)('recommended', [config_1.defaultPlugin])),
|
|
19
20
|
});
|
|
20
21
|
}
|
|
21
|
-
exports.measureAsync = measureAsync;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.count = exports.name = void 0;
|
|
4
|
+
exports.measureAsync = measureAsync;
|
|
4
5
|
const path = require("path");
|
|
5
6
|
const fs_1 = require("fs");
|
|
6
7
|
const resolve_1 = require("../../resolve");
|
|
@@ -19,4 +20,3 @@ function measureAsync() {
|
|
|
19
20
|
rootType: (0, types_1.normalizeTypes)(oas3_1.Oas3Types).Root,
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
|
-
exports.measureAsync = measureAsync;
|
package/lib/benchmark/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.parseYamlToDocument = parseYamlToDocument;
|
|
4
|
+
exports.makeConfigForRuleset = makeConfigForRuleset;
|
|
4
5
|
const js_yaml_1 = require("../js-yaml");
|
|
5
6
|
const resolve_1 = require("../resolve");
|
|
6
7
|
const config_1 = require("../config");
|
|
@@ -10,7 +11,6 @@ function parseYamlToDocument(body, absoluteRef = '') {
|
|
|
10
11
|
parsed: (0, js_yaml_1.parseYaml)(body, { filename: absoluteRef }),
|
|
11
12
|
};
|
|
12
13
|
}
|
|
13
|
-
exports.parseYamlToDocument = parseYamlToDocument;
|
|
14
14
|
function makeConfigForRuleset(rules, plugin) {
|
|
15
15
|
const rulesConf = {};
|
|
16
16
|
const ruleId = 'test';
|
|
@@ -19,7 +19,11 @@ function makeConfigForRuleset(rules, plugin) {
|
|
|
19
19
|
});
|
|
20
20
|
const extendConfigs = [
|
|
21
21
|
(0, config_1.resolvePlugins)([
|
|
22
|
-
|
|
22
|
+
{
|
|
23
|
+
...plugin,
|
|
24
|
+
id: ruleId,
|
|
25
|
+
rules: { oas3: rules },
|
|
26
|
+
},
|
|
23
27
|
]),
|
|
24
28
|
];
|
|
25
29
|
if (rules) {
|
|
@@ -28,4 +32,3 @@ function makeConfigForRuleset(rules, plugin) {
|
|
|
28
32
|
const styleguide = (0, config_1.mergeExtends)(extendConfigs);
|
|
29
33
|
return new config_1.StyleguideConfig(styleguide);
|
|
30
34
|
}
|
|
31
|
-
exports.makeConfigForRuleset = makeConfigForRuleset;
|
package/lib/bundle.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { BaseResolver } from './resolve';
|
|
2
2
|
import { SpecMajorVersion } from './oas-types';
|
|
3
|
-
import type { Oas3Rule } from './visitors';
|
|
4
3
|
import type { NormalizedNodeType, NodeType } from './types';
|
|
5
4
|
import type { NormalizedProblem } from './walk';
|
|
6
5
|
import type { Config, StyleguideConfig } from './config';
|
|
7
6
|
import type { Document, ResolvedRefMap } from './resolve';
|
|
8
|
-
|
|
7
|
+
import type { CollectFn } from './utils';
|
|
9
8
|
export declare enum OasVersion {
|
|
10
9
|
Version2 = "oas2",
|
|
11
10
|
Version3_0 = "oas3_0",
|
|
@@ -24,6 +23,7 @@ export declare function bundleConfig(document: Document, resolvedRefMap: Resolve
|
|
|
24
23
|
export declare function bundle(opts: {
|
|
25
24
|
ref?: string;
|
|
26
25
|
doc?: Document;
|
|
26
|
+
collectSpecData?: CollectFn;
|
|
27
27
|
} & BundleOptions): Promise<BundleResult>;
|
|
28
28
|
export declare function bundleFromString(opts: {
|
|
29
29
|
source: string;
|
|
@@ -47,4 +47,4 @@ export declare function bundleDocument(opts: {
|
|
|
47
47
|
removeUnusedComponents?: boolean;
|
|
48
48
|
keepUrlRefs?: boolean;
|
|
49
49
|
}): Promise<BundleResult>;
|
|
50
|
-
export declare function mapTypeToComponent(typeName: string, version: SpecMajorVersion): "definitions" | "
|
|
50
|
+
export declare function mapTypeToComponent(typeName: string, version: SpecMajorVersion): "definitions" | "links" | "responses" | "parameters" | "examples" | "headers" | "schemas" | "requestBodies" | "securitySchemes" | "callbacks" | null;
|
package/lib/bundle.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
|
|
3
|
+
exports.OasVersion = void 0;
|
|
4
|
+
exports.bundleConfig = bundleConfig;
|
|
5
|
+
exports.bundle = bundle;
|
|
6
|
+
exports.bundleFromString = bundleFromString;
|
|
7
|
+
exports.bundleDocument = bundleDocument;
|
|
8
|
+
exports.mapTypeToComponent = mapTypeToComponent;
|
|
14
9
|
const resolve_1 = require("./resolve");
|
|
15
10
|
const visitors_1 = require("./visitors");
|
|
16
11
|
const types_1 = require("./types");
|
|
@@ -30,132 +25,130 @@ var OasVersion;
|
|
|
30
25
|
OasVersion["Version3_0"] = "oas3_0";
|
|
31
26
|
OasVersion["Version3_1"] = "oas3_1";
|
|
32
27
|
})(OasVersion || (exports.OasVersion = OasVersion = {}));
|
|
33
|
-
function bundleConfig(document, resolvedRefMap) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
leave(node, ctx, resolved) {
|
|
50
|
-
replaceRef(node, resolved, ctx);
|
|
51
|
-
},
|
|
28
|
+
async function bundleConfig(document, resolvedRefMap) {
|
|
29
|
+
const types = (0, types_1.normalizeTypes)(redocly_yaml_1.ConfigTypes);
|
|
30
|
+
const ctx = {
|
|
31
|
+
problems: [],
|
|
32
|
+
oasVersion: oas_types_1.SpecVersion.OAS3_0,
|
|
33
|
+
refTypes: new Map(),
|
|
34
|
+
visitorsData: {},
|
|
35
|
+
};
|
|
36
|
+
const bundleVisitor = (0, visitors_1.normalizeVisitors)([
|
|
37
|
+
{
|
|
38
|
+
severity: 'error',
|
|
39
|
+
ruleId: 'configBundler',
|
|
40
|
+
visitor: {
|
|
41
|
+
ref: {
|
|
42
|
+
leave(node, ctx, resolved) {
|
|
43
|
+
replaceRef(node, resolved, ctx);
|
|
52
44
|
},
|
|
53
45
|
},
|
|
54
46
|
},
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return (_a = document.parsed) !== null && _a !== void 0 ? _a : {};
|
|
47
|
+
},
|
|
48
|
+
], types);
|
|
49
|
+
(0, walk_1.walkDocument)({
|
|
50
|
+
document,
|
|
51
|
+
rootType: types.ConfigRoot,
|
|
52
|
+
normalizedVisitors: bundleVisitor,
|
|
53
|
+
resolvedRefMap,
|
|
54
|
+
ctx,
|
|
64
55
|
});
|
|
56
|
+
return document.parsed ?? {};
|
|
65
57
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
58
|
+
async function bundle(opts) {
|
|
59
|
+
const { ref, doc, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve), base = null, } = opts;
|
|
60
|
+
if (!(ref || doc)) {
|
|
61
|
+
throw new Error('Document or reference is required.\n');
|
|
62
|
+
}
|
|
63
|
+
const document = doc === undefined ? await externalRefResolver.resolveDocument(base, ref, true) : doc;
|
|
64
|
+
if (document instanceof Error) {
|
|
65
|
+
throw document;
|
|
66
|
+
}
|
|
67
|
+
opts.collectSpecData?.(document.parsed);
|
|
68
|
+
return bundleDocument({
|
|
69
|
+
document,
|
|
70
|
+
...opts,
|
|
71
|
+
config: opts.config.styleguide,
|
|
72
|
+
externalRefResolver,
|
|
78
73
|
});
|
|
79
74
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
async function bundleFromString(opts) {
|
|
76
|
+
const { source, absoluteRef, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve) } = opts;
|
|
77
|
+
const document = (0, resolve_1.makeDocumentFromString)(source, absoluteRef || '/');
|
|
78
|
+
return bundleDocument({
|
|
79
|
+
document,
|
|
80
|
+
...opts,
|
|
81
|
+
externalRefResolver,
|
|
82
|
+
config: opts.config.styleguide,
|
|
86
83
|
});
|
|
87
84
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
? (0, remove_unused_components_1.RemoveUnusedComponents)({})
|
|
110
|
-
: (0, remove_unused_components_2.RemoveUnusedComponents)({}),
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
let resolvedRefMap = yield (0, resolve_1.resolveDocument)({
|
|
114
|
-
rootDocument: document,
|
|
115
|
-
rootType: types.Root,
|
|
116
|
-
externalRefResolver,
|
|
85
|
+
async function bundleDocument(opts) {
|
|
86
|
+
const { document, config, customTypes, externalRefResolver, dereference = false, skipRedoclyRegistryRefs = false, removeUnusedComponents = false, keepUrlRefs = false, } = opts;
|
|
87
|
+
const specVersion = (0, oas_types_1.detectSpec)(document.parsed);
|
|
88
|
+
const specMajorVersion = (0, oas_types_1.getMajorSpecVersion)(specVersion);
|
|
89
|
+
const rules = config.getRulesForOasVersion(specMajorVersion);
|
|
90
|
+
const types = (0, types_1.normalizeTypes)(config.extendTypes(customTypes ?? (0, oas_types_1.getTypes)(specVersion), specVersion), config);
|
|
91
|
+
const preprocessors = (0, rules_1.initRules)(rules, config, 'preprocessors', specVersion);
|
|
92
|
+
const decorators = (0, rules_1.initRules)(rules, config, 'decorators', specVersion);
|
|
93
|
+
const ctx = {
|
|
94
|
+
problems: [],
|
|
95
|
+
oasVersion: specVersion,
|
|
96
|
+
refTypes: new Map(),
|
|
97
|
+
visitorsData: {},
|
|
98
|
+
};
|
|
99
|
+
if (removeUnusedComponents) {
|
|
100
|
+
decorators.push({
|
|
101
|
+
severity: 'error',
|
|
102
|
+
ruleId: 'remove-unused-components',
|
|
103
|
+
visitor: specMajorVersion === oas_types_1.SpecMajorVersion.OAS2
|
|
104
|
+
? (0, remove_unused_components_1.RemoveUnusedComponents)({})
|
|
105
|
+
: (0, remove_unused_components_2.RemoveUnusedComponents)({}),
|
|
117
106
|
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
});
|
|
127
|
-
resolvedRefMap = yield (0, resolve_1.resolveDocument)({
|
|
128
|
-
rootDocument: document,
|
|
129
|
-
rootType: types.Root,
|
|
130
|
-
externalRefResolver,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
const bundleVisitor = (0, visitors_1.normalizeVisitors)([
|
|
134
|
-
{
|
|
135
|
-
severity: 'error',
|
|
136
|
-
ruleId: 'bundler',
|
|
137
|
-
visitor: makeBundleVisitor(specMajorVersion, dereference, skipRedoclyRegistryRefs, document, resolvedRefMap, keepUrlRefs),
|
|
138
|
-
},
|
|
139
|
-
...decorators,
|
|
140
|
-
], types);
|
|
107
|
+
}
|
|
108
|
+
let resolvedRefMap = await (0, resolve_1.resolveDocument)({
|
|
109
|
+
rootDocument: document,
|
|
110
|
+
rootType: types.Root,
|
|
111
|
+
externalRefResolver,
|
|
112
|
+
});
|
|
113
|
+
if (preprocessors.length > 0) {
|
|
114
|
+
// Make additional pass to resolve refs defined in preprocessors.
|
|
141
115
|
(0, walk_1.walkDocument)({
|
|
142
116
|
document,
|
|
143
117
|
rootType: types.Root,
|
|
144
|
-
normalizedVisitors:
|
|
118
|
+
normalizedVisitors: (0, visitors_1.normalizeVisitors)(preprocessors, types),
|
|
145
119
|
resolvedRefMap,
|
|
146
120
|
ctx,
|
|
147
121
|
});
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
problems: ctx.problems.map((problem) => config.addProblemToIgnore(problem)),
|
|
151
|
-
fileDependencies: externalRefResolver.getFiles(),
|
|
122
|
+
resolvedRefMap = await (0, resolve_1.resolveDocument)({
|
|
123
|
+
rootDocument: document,
|
|
152
124
|
rootType: types.Root,
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
125
|
+
externalRefResolver,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
const bundleVisitor = (0, visitors_1.normalizeVisitors)([
|
|
129
|
+
{
|
|
130
|
+
severity: 'error',
|
|
131
|
+
ruleId: 'bundler',
|
|
132
|
+
visitor: makeBundleVisitor(specMajorVersion, dereference, skipRedoclyRegistryRefs, document, resolvedRefMap, keepUrlRefs),
|
|
133
|
+
},
|
|
134
|
+
...decorators,
|
|
135
|
+
], types);
|
|
136
|
+
(0, walk_1.walkDocument)({
|
|
137
|
+
document,
|
|
138
|
+
rootType: types.Root,
|
|
139
|
+
normalizedVisitors: bundleVisitor,
|
|
140
|
+
resolvedRefMap,
|
|
141
|
+
ctx,
|
|
156
142
|
});
|
|
143
|
+
return {
|
|
144
|
+
bundle: document,
|
|
145
|
+
problems: ctx.problems.map((problem) => config.addProblemToIgnore(problem)),
|
|
146
|
+
fileDependencies: externalRefResolver.getFiles(),
|
|
147
|
+
rootType: types.Root,
|
|
148
|
+
refTypes: ctx.refTypes,
|
|
149
|
+
visitorsData: ctx.visitorsData,
|
|
150
|
+
};
|
|
157
151
|
}
|
|
158
|
-
exports.bundleDocument = bundleDocument;
|
|
159
152
|
function mapTypeToComponent(typeName, version) {
|
|
160
153
|
switch (version) {
|
|
161
154
|
case oas_types_1.SpecMajorVersion.OAS3:
|
|
@@ -201,6 +194,15 @@ function mapTypeToComponent(typeName, version) {
|
|
|
201
194
|
default:
|
|
202
195
|
return null;
|
|
203
196
|
}
|
|
197
|
+
case oas_types_1.SpecMajorVersion.Async3:
|
|
198
|
+
switch (typeName) {
|
|
199
|
+
case 'Schema':
|
|
200
|
+
return 'schemas';
|
|
201
|
+
case 'Parameter':
|
|
202
|
+
return 'parameters';
|
|
203
|
+
default:
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
204
206
|
case oas_types_1.SpecMajorVersion.Arazzo:
|
|
205
207
|
switch (typeName) {
|
|
206
208
|
case 'Root.x-parameters_items':
|
|
@@ -212,7 +214,6 @@ function mapTypeToComponent(typeName, version) {
|
|
|
212
214
|
}
|
|
213
215
|
}
|
|
214
216
|
}
|
|
215
|
-
exports.mapTypeToComponent = mapTypeToComponent;
|
|
216
217
|
function replaceRef(ref, resolved, ctx) {
|
|
217
218
|
if (!(0, utils_1.isPlainObject)(resolved.node)) {
|
|
218
219
|
ctx.parent[ctx.key] = resolved.node;
|
|
@@ -277,6 +278,9 @@ function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDo
|
|
|
277
278
|
else if (version === oas_types_1.SpecMajorVersion.Async2) {
|
|
278
279
|
components = root.components = root.components || {};
|
|
279
280
|
}
|
|
281
|
+
else if (version === oas_types_1.SpecMajorVersion.Async3) {
|
|
282
|
+
components = root.components = root.components || {};
|
|
283
|
+
}
|
|
280
284
|
else if (version === oas_types_1.SpecMajorVersion.Arazzo) {
|
|
281
285
|
components = root.components = root.components || {};
|
|
282
286
|
}
|
|
@@ -321,18 +325,20 @@ function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDo
|
|
|
321
325
|
if (version === oas_types_1.SpecMajorVersion.OAS3) {
|
|
322
326
|
return `#/components/${componentType}/${name}`;
|
|
323
327
|
}
|
|
328
|
+
else if (version === oas_types_1.SpecMajorVersion.Async2 || version === oas_types_1.SpecMajorVersion.Async3) {
|
|
329
|
+
return `#/components/${componentType}/${name}`;
|
|
330
|
+
}
|
|
324
331
|
else {
|
|
325
332
|
return `#/${componentType}/${name}`;
|
|
326
333
|
}
|
|
327
334
|
}
|
|
328
335
|
function isEqualOrEqualRef(node, target, ctx) {
|
|
329
|
-
var _a;
|
|
330
336
|
if ((0, ref_utils_1.isRef)(node) &&
|
|
331
|
-
|
|
337
|
+
ctx.resolve(node, rootLocation.absolutePointer).location?.absolutePointer ===
|
|
332
338
|
target.location.absolutePointer) {
|
|
333
339
|
return true;
|
|
334
340
|
}
|
|
335
|
-
return
|
|
341
|
+
return (0, utils_1.dequal)(node, target.node);
|
|
336
342
|
}
|
|
337
343
|
function getComponentName(target, componentType, ctx) {
|
|
338
344
|
const [fileRef, pointer] = [target.location.source.absoluteRef, target.location.pointer];
|
package/lib/config/all.js
CHANGED
|
@@ -114,6 +114,15 @@ const all = {
|
|
|
114
114
|
'channels-kebab-case': 'error',
|
|
115
115
|
'no-channel-trailing-slash': 'error',
|
|
116
116
|
},
|
|
117
|
+
async3Rules: {
|
|
118
|
+
spec: 'error',
|
|
119
|
+
'info-contact': 'error',
|
|
120
|
+
'operation-operationId': 'error',
|
|
121
|
+
'tag-description': 'error',
|
|
122
|
+
'tags-alphabetical': 'error',
|
|
123
|
+
'channels-kebab-case': 'error',
|
|
124
|
+
'no-channel-trailing-slash': 'error',
|
|
125
|
+
},
|
|
117
126
|
arazzoRules: { spec: 'error' },
|
|
118
127
|
};
|
|
119
128
|
exports.default = all;
|
package/lib/config/builtIn.js
CHANGED
|
@@ -8,14 +8,17 @@ const minimal_1 = require("./minimal");
|
|
|
8
8
|
const oas3_1 = require("../rules/oas3");
|
|
9
9
|
const oas2_1 = require("../rules/oas2");
|
|
10
10
|
const async2_1 = require("../rules/async2");
|
|
11
|
+
const async3_1 = require("../rules/async3");
|
|
11
12
|
const arazzo_1 = require("../rules/arazzo");
|
|
12
13
|
const oas3_2 = require("../rules/oas3");
|
|
13
14
|
const oas2_2 = require("../rules/oas2");
|
|
14
15
|
const async2_2 = require("../rules/async2");
|
|
16
|
+
const async3_2 = require("../rules/async3");
|
|
15
17
|
const arazzo_2 = require("../rules/arazzo");
|
|
16
18
|
const oas3_3 = require("../decorators/oas3");
|
|
17
19
|
const oas2_3 = require("../decorators/oas2");
|
|
18
20
|
const async2_3 = require("../decorators/async2");
|
|
21
|
+
const async3_3 = require("../decorators/async3");
|
|
19
22
|
const arazzo_3 = require("../decorators/arazzo");
|
|
20
23
|
exports.builtInConfigs = {
|
|
21
24
|
recommended: recommended_1.default,
|
|
@@ -27,23 +30,26 @@ exports.builtInConfigs = {
|
|
|
27
30
|
},
|
|
28
31
|
};
|
|
29
32
|
exports.defaultPlugin = {
|
|
30
|
-
id: '',
|
|
33
|
+
id: '', // default plugin doesn't have id
|
|
31
34
|
rules: {
|
|
32
35
|
oas3: oas3_1.rules,
|
|
33
36
|
oas2: oas2_1.rules,
|
|
34
37
|
async2: async2_1.rules,
|
|
38
|
+
async3: async3_1.rules,
|
|
35
39
|
arazzo: arazzo_1.rules,
|
|
36
40
|
},
|
|
37
41
|
preprocessors: {
|
|
38
42
|
oas3: oas3_2.preprocessors,
|
|
39
43
|
oas2: oas2_2.preprocessors,
|
|
40
44
|
async2: async2_2.preprocessors,
|
|
45
|
+
async3: async3_2.preprocessors,
|
|
41
46
|
arazzo: arazzo_2.preprocessors,
|
|
42
47
|
},
|
|
43
48
|
decorators: {
|
|
44
49
|
oas3: oas3_3.decorators,
|
|
45
50
|
oas2: oas2_3.decorators,
|
|
46
51
|
async2: async2_3.decorators,
|
|
52
|
+
async3: async3_3.decorators,
|
|
47
53
|
arazzo: arazzo_3.decorators,
|
|
48
54
|
},
|
|
49
55
|
configs: exports.builtInConfigs,
|