@redocly/openapi-core 1.3.0 → 1.4.1
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 +18 -0
- package/lib/benchmark/benches/lint-with-many-rules.bench.js +4 -4
- package/lib/benchmark/benches/lint-with-nested-rule.bench.js +4 -4
- package/lib/benchmark/benches/lint-with-no-rules.bench.js +4 -4
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +4 -4
- package/lib/benchmark/benches/lint-with-top-level-rule.bench.js +4 -4
- package/lib/benchmark/benches/recommended-oas3.bench.js +4 -4
- package/lib/benchmark/benches/resolve-with-no-external.bench.js +3 -3
- package/lib/benchmark/utils.js +3 -3
- package/lib/bundle.d.ts +4 -4
- package/lib/bundle.js +25 -25
- package/lib/config/all.d.ts +2 -2
- package/lib/config/all.js +44 -8
- package/lib/config/builtIn.js +2 -0
- package/lib/config/config-resolvers.js +25 -25
- package/lib/config/config.js +9 -9
- package/lib/config/index.js +5 -1
- package/lib/config/load.d.ts +1 -1
- package/lib/config/load.js +6 -6
- package/lib/config/minimal.d.ts +2 -2
- package/lib/config/minimal.js +34 -3
- package/lib/config/recommended-strict.d.ts +3 -0
- package/lib/config/recommended-strict.js +92 -0
- package/lib/config/recommended.d.ts +2 -2
- package/lib/config/recommended.js +34 -3
- package/lib/config/rules.d.ts +1 -1
- package/lib/config/types.d.ts +47 -46
- package/lib/config/types.js +2 -2
- package/lib/config/utils.js +26 -14
- package/lib/decorators/common/filters/filter-helper.js +4 -4
- package/lib/decorators/common/filters/filter-in.js +2 -2
- package/lib/decorators/common/filters/filter-out.js +2 -2
- package/lib/decorators/common/info-description-override.js +1 -1
- package/lib/decorators/common/media-type-examples-override.js +3 -3
- package/lib/decorators/common/operation-description-override.js +1 -1
- package/lib/decorators/common/registry-dependencies.js +1 -1
- package/lib/decorators/common/remove-x-internal.js +4 -4
- package/lib/decorators/common/tag-description-override.js +1 -1
- package/lib/decorators/oas2/remove-unused-components.d.ts +2 -0
- package/lib/{rules → decorators}/oas2/remove-unused-components.js +1 -1
- package/lib/decorators/oas3/remove-unused-components.d.ts +2 -0
- package/lib/{rules → decorators}/oas3/remove-unused-components.js +2 -2
- package/lib/env.js +1 -1
- package/lib/format/codeframes.d.ts +6 -6
- package/lib/format/format.d.ts +2 -2
- package/lib/format/format.js +12 -12
- package/lib/js-yaml/index.d.ts +2 -2
- package/lib/js-yaml/index.js +2 -2
- package/lib/lint.js +18 -18
- package/lib/oas-types.d.ts +12 -10
- package/lib/oas-types.js +2 -2
- package/lib/redocly/index.js +10 -10
- package/lib/redocly/registry-api.js +2 -2
- package/lib/resolve.d.ts +4 -4
- package/lib/resolve.js +18 -18
- package/lib/rules/ajv.js +1 -1
- package/lib/rules/async2/index.d.ts +2 -11
- package/lib/rules/common/assertions/asserts.d.ts +3 -3
- package/lib/rules/common/assertions/asserts.js +21 -21
- package/lib/rules/common/assertions/index.d.ts +4 -4
- package/lib/rules/common/assertions/index.js +3 -3
- package/lib/rules/common/assertions/utils.d.ts +4 -4
- package/lib/rules/common/assertions/utils.js +3 -3
- package/lib/rules/common/info-contact.js +1 -1
- package/lib/rules/common/info-license-url.js +1 -1
- package/lib/rules/common/info-license.js +1 -1
- package/lib/rules/common/no-enum-type-mismatch.js +3 -3
- package/lib/rules/common/no-http-verbs-in-paths.js +2 -2
- 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-2xx-response.js +2 -2
- package/lib/rules/common/operation-4xx-response.js +2 -2
- package/lib/rules/common/operation-description.js +1 -1
- package/lib/rules/common/operation-operationId.js +1 -1
- package/lib/rules/common/operation-summary.js +1 -1
- package/lib/rules/common/path-segment-plural.js +1 -1
- package/lib/rules/common/response-contains-header.js +2 -2
- package/lib/rules/common/spec-strict-refs.js +1 -1
- package/lib/rules/common/spec.js +11 -11
- package/lib/rules/common/tag-description.js +1 -1
- package/lib/rules/oas2/boolean-parameter-prefixes.d.ts +1 -1
- package/lib/rules/oas2/index.d.ts +2 -46
- package/lib/rules/oas2/request-mime-type.js +2 -2
- package/lib/rules/oas2/response-contains-property.js +2 -2
- package/lib/rules/oas2/response-mime-type.js +2 -2
- package/lib/rules/oas3/boolean-parameter-prefixes.d.ts +1 -1
- package/lib/rules/oas3/index.d.ts +1 -1
- package/lib/rules/oas3/index.js +1 -1
- package/lib/rules/oas3/no-invalid-media-type-examples.js +3 -3
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +3 -3
- package/lib/rules/oas3/request-mime-type.js +3 -3
- package/lib/rules/oas3/response-contains-property.js +2 -2
- package/lib/rules/oas3/response-mime-type.js +3 -3
- package/lib/rules/utils.js +3 -3
- package/lib/types/asyncapi.js +21 -21
- package/lib/types/index.d.ts +8 -8
- package/lib/types/oas2.js +14 -14
- package/lib/types/oas3.js +27 -27
- package/lib/types/oas3_1.js +18 -6
- package/lib/types/redocly-yaml.d.ts +11 -0
- package/lib/types/redocly-yaml.js +71 -53
- package/lib/types/theme-config.js +1 -1
- package/lib/typings/common.d.ts +2 -2
- package/lib/typings/openapi.d.ts +6 -6
- package/lib/typings/swagger.d.ts +3 -3
- package/lib/utils.d.ts +5 -5
- package/lib/utils.js +3 -3
- package/lib/visitors.d.ts +38 -40
- package/lib/walk.d.ts +14 -15
- package/lib/walk.js +11 -11
- package/package.json +2 -2
- package/src/__tests__/lint.test.ts +40 -40
- package/src/__tests__/normalizeVisitors.test.ts +23 -5
- package/src/__tests__/ref-utils.test.ts +7 -7
- package/src/__tests__/resolve-http.test.ts +10 -10
- package/src/__tests__/resolve.test.ts +39 -39
- package/src/__tests__/walk.test.ts +48 -48
- package/src/bundle.ts +4 -4
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +95 -32
- package/src/config/__tests__/__snapshots__/config.test.ts.snap +81 -81
- package/src/config/__tests__/config-resolvers.test.ts +30 -1
- package/src/config/__tests__/config.test.ts +88 -88
- package/src/config/__tests__/load.test.ts +12 -8
- package/src/config/__tests__/utils.test.ts +18 -18
- package/src/config/all.ts +46 -9
- package/src/config/builtIn.ts +2 -0
- package/src/config/minimal.ts +36 -4
- package/src/config/recommended-strict.ts +93 -0
- package/src/config/recommended.ts +36 -4
- package/src/config/types.ts +22 -8
- package/src/config/utils.ts +15 -0
- package/src/decorators/common/media-type-examples-override.ts +2 -2
- package/src/{rules → decorators}/oas2/remove-unused-components.ts +3 -3
- package/src/{rules → decorators}/oas3/remove-unused-components.ts +3 -3
- package/src/env.ts +1 -1
- package/src/lint.ts +3 -3
- package/src/oas-types.ts +26 -3
- package/src/rules/__tests__/no-unresolved-refs.test.ts +26 -26
- package/src/rules/async2/__tests__/channels-kebab-case.test.ts +12 -12
- package/src/rules/async2/__tests__/no-channel-trailing-slash.test.ts +7 -7
- package/src/rules/async2/index.ts +2 -1
- package/src/rules/common/__tests__/info-license.test.ts +6 -6
- package/src/rules/common/__tests__/license-url.test.ts +6 -6
- package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +13 -13
- package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +18 -18
- package/src/rules/common/__tests__/no-identical-paths.test.ts +5 -5
- package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +12 -12
- package/src/rules/common/__tests__/operation-2xx-response.test.ts +18 -18
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +23 -23
- package/src/rules/common/__tests__/operation-operationId-unique.test.ts +6 -6
- package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +5 -5
- package/src/rules/common/__tests__/operation-parameters-unique.test.ts +16 -16
- package/src/rules/common/__tests__/operation-singular-tag.test.ts +6 -6
- package/src/rules/common/__tests__/path-http-verbs-order.test.ts +10 -10
- package/src/rules/common/__tests__/path-not-include-query.test.ts +6 -6
- package/src/rules/common/__tests__/path-params-defined.test.ts +21 -21
- package/src/rules/common/__tests__/paths-kebab-case.test.ts +11 -11
- package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +18 -18
- package/src/rules/common/__tests__/security-defined.test.ts +21 -21
- package/src/rules/common/__tests__/spec-strict-refs.test.ts +9 -9
- package/src/rules/common/__tests__/spec.test.ts +102 -102
- package/src/rules/common/__tests__/tag-description.test.ts +6 -6
- package/src/rules/common/__tests__/tags-alphabetical.test.ts +12 -12
- package/src/rules/common/assertions/__tests__/index.test.ts +15 -15
- package/src/rules/common/assertions/__tests__/utils.test.ts +9 -9
- package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +7 -7
- package/src/rules/oas2/__tests__/response-contains-header.test.ts +13 -13
- package/src/rules/oas2/__tests__/response-contains-property.test.ts +8 -8
- package/src/rules/oas2/__tests__/spec/info.test.ts +21 -21
- package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
- package/src/rules/oas2/__tests__/spec/paths.test.ts +12 -12
- package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +1 -1
- package/src/rules/oas2/index.ts +3 -1
- package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +7 -7
- package/src/rules/oas3/__tests__/component-name-unique.test.ts +186 -186
- package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +18 -18
- package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +6 -6
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +36 -36
- package/src/rules/oas3/__tests__/no-server-example.com.test.ts +11 -11
- package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +7 -7
- package/src/rules/oas3/__tests__/no-unused-components.test.ts +31 -31
- package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +15 -15
- package/src/rules/oas3/__tests__/response-contains-header.test.ts +26 -26
- package/src/rules/oas3/__tests__/response-contains-property.test.ts +27 -27
- package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
- package/src/rules/oas3/__tests__/spec/info.test.ts +21 -21
- package/src/rules/oas3/__tests__/spec/operation.test.ts +10 -10
- package/src/rules/oas3/__tests__/spec/paths.test.ts +13 -13
- package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +2 -2
- package/src/rules/oas3/__tests__/spec/servers.test.ts +25 -25
- package/src/rules/oas3/__tests__/spec/spec.test.ts +56 -56
- package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +28 -28
- package/src/rules/oas3/index.ts +3 -3
- package/src/types/oas3_1.ts +12 -0
- package/src/types/redocly-yaml.ts +75 -40
- package/src/visitors.ts +10 -21
- package/src/walk.ts +23 -10
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/oas2/remove-unused-components.d.ts +0 -2
- package/lib/rules/oas3/remove-unused-components.d.ts +0 -2
- /package/src/{rules → decorators}/oas2/__tests__/remove-unused-components.test.ts +0 -0
- /package/src/{rules → decorators}/oas3/__tests__/remove-unused-components.test.ts +0 -0
package/lib/walk.js
CHANGED
|
@@ -33,9 +33,9 @@ function walkDocument(opts) {
|
|
|
33
33
|
function walkNode(node, type, location, parent, key) {
|
|
34
34
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
35
35
|
const resolve = (ref, from = currentLocation.source.absoluteRef) => {
|
|
36
|
-
if (!ref_utils_1.isRef(ref))
|
|
36
|
+
if (!(0, ref_utils_1.isRef)(ref))
|
|
37
37
|
return { location, node: ref };
|
|
38
|
-
const refId = resolve_1.makeRefId(from, ref.$ref);
|
|
38
|
+
const refId = (0, resolve_1.makeRefId)(from, ref.$ref);
|
|
39
39
|
const resolvedRef = resolvedRefMap.get(refId);
|
|
40
40
|
if (!resolvedRef) {
|
|
41
41
|
return {
|
|
@@ -55,7 +55,7 @@ function walkDocument(opts) {
|
|
|
55
55
|
let currentLocation = location;
|
|
56
56
|
const { node: resolvedNode, location: resolvedLocation, error } = resolve(node);
|
|
57
57
|
const enteredContexts = new Set();
|
|
58
|
-
if (ref_utils_1.isRef(node)) {
|
|
58
|
+
if ((0, ref_utils_1.isRef)(node)) {
|
|
59
59
|
const refEnterVisitors = normalizedVisitors.ref.enter;
|
|
60
60
|
for (const { visit: visitor, ruleId, severity, context } of refEnterVisitors) {
|
|
61
61
|
enteredContexts.add(context);
|
|
@@ -120,10 +120,10 @@ function walkDocument(opts) {
|
|
|
120
120
|
rawNode: node,
|
|
121
121
|
})))) !== null && _k !== void 0 ? _k : false,
|
|
122
122
|
};
|
|
123
|
-
context.activatedOn = utils_1.pushStack(context.activatedOn, activatedOn);
|
|
123
|
+
context.activatedOn = (0, utils_1.pushStack)(context.activatedOn, activatedOn);
|
|
124
124
|
let ctx = context.parent;
|
|
125
125
|
while (ctx) {
|
|
126
|
-
ctx.activatedOn.value.nextLevelTypeActivated = utils_1.pushStack(ctx.activatedOn.value.nextLevelTypeActivated, type);
|
|
126
|
+
ctx.activatedOn.value.nextLevelTypeActivated = (0, utils_1.pushStack)(ctx.activatedOn.value.nextLevelTypeActivated, type);
|
|
127
127
|
ctx = ctx.parent;
|
|
128
128
|
}
|
|
129
129
|
if (!activatedOn.skipped) {
|
|
@@ -154,7 +154,7 @@ function walkDocument(opts) {
|
|
|
154
154
|
else if (type.extensionsPrefix) {
|
|
155
155
|
props.push(...Object.keys(resolvedNode).filter((k) => k.startsWith(type.extensionsPrefix)));
|
|
156
156
|
}
|
|
157
|
-
if (ref_utils_1.isRef(node)) {
|
|
157
|
+
if ((0, ref_utils_1.isRef)(node)) {
|
|
158
158
|
props.push(...Object.keys(node).filter((k) => k !== '$ref' && !props.includes(k))); // properties on the same level as $ref
|
|
159
159
|
}
|
|
160
160
|
for (const propName of props) {
|
|
@@ -174,14 +174,14 @@ function walkDocument(opts) {
|
|
|
174
174
|
propName.startsWith(type.extensionsPrefix)) {
|
|
175
175
|
propType = types_1.SpecExtension;
|
|
176
176
|
}
|
|
177
|
-
if (!types_1.isNamedType(propType) && (propType === null || propType === void 0 ? void 0 : propType.directResolveAs)) {
|
|
177
|
+
if (!(0, types_1.isNamedType)(propType) && (propType === null || propType === void 0 ? void 0 : propType.directResolveAs)) {
|
|
178
178
|
propType = propType.directResolveAs;
|
|
179
179
|
value = { $ref: value };
|
|
180
180
|
}
|
|
181
181
|
if (propType && propType.name === undefined && propType.resolvable !== false) {
|
|
182
182
|
propType = { name: 'scalar', properties: {} };
|
|
183
183
|
}
|
|
184
|
-
if (!types_1.isNamedType(propType) || (propType.name === 'scalar' && !ref_utils_1.isRef(value))) {
|
|
184
|
+
if (!(0, types_1.isNamedType)(propType) || (propType.name === 'scalar' && !(0, ref_utils_1.isRef)(value))) {
|
|
185
185
|
continue;
|
|
186
186
|
}
|
|
187
187
|
walkNode(value, propType, loc.child([propName]), resolvedNode, propName);
|
|
@@ -195,11 +195,11 @@ function walkDocument(opts) {
|
|
|
195
195
|
context.seen.delete(resolvedNode);
|
|
196
196
|
}
|
|
197
197
|
else {
|
|
198
|
-
context.activatedOn = utils_1.popStack(context.activatedOn);
|
|
198
|
+
context.activatedOn = (0, utils_1.popStack)(context.activatedOn);
|
|
199
199
|
if (context.parent) {
|
|
200
200
|
let ctx = context.parent;
|
|
201
201
|
while (ctx) {
|
|
202
|
-
ctx.activatedOn.value.nextLevelTypeActivated = utils_1.popStack(ctx.activatedOn.value.nextLevelTypeActivated);
|
|
202
|
+
ctx.activatedOn.value.nextLevelTypeActivated = (0, utils_1.popStack)(ctx.activatedOn.value.nextLevelTypeActivated);
|
|
203
203
|
ctx = ctx.parent;
|
|
204
204
|
}
|
|
205
205
|
}
|
|
@@ -212,7 +212,7 @@ function walkDocument(opts) {
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
currentLocation = location;
|
|
215
|
-
if (ref_utils_1.isRef(node)) {
|
|
215
|
+
if ((0, ref_utils_1.isRef)(node)) {
|
|
216
216
|
const refLeaveVisitors = normalizedVisitors.ref.leave;
|
|
217
217
|
for (const { visit: visitor, ruleId, severity, context } of refLeaveVisitors) {
|
|
218
218
|
if (enteredContexts.has(context)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/openapi-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -52,6 +52,6 @@
|
|
|
52
52
|
"@types/minimatch": "^3.0.5",
|
|
53
53
|
"@types/node-fetch": "^2.5.7",
|
|
54
54
|
"@types/pluralize": "^0.0.29",
|
|
55
|
-
"typescript": "^
|
|
55
|
+
"typescript": "^5.2.2"
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -27,11 +27,11 @@ describe('lint', () => {
|
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
[
|
|
31
|
+
{
|
|
32
32
|
"from": undefined,
|
|
33
|
-
"location":
|
|
34
|
-
|
|
33
|
+
"location": [
|
|
34
|
+
{
|
|
35
35
|
"pointer": "#/info/license",
|
|
36
36
|
"reportOnKey": false,
|
|
37
37
|
"source": "/test/spec.yaml",
|
|
@@ -40,7 +40,7 @@ describe('lint', () => {
|
|
|
40
40
|
"message": "Expected type \`License\` (object) but got \`string\`",
|
|
41
41
|
"ruleId": "spec",
|
|
42
42
|
"severity": "error",
|
|
43
|
-
"suggest":
|
|
43
|
+
"suggest": [],
|
|
44
44
|
},
|
|
45
45
|
]
|
|
46
46
|
`);
|
|
@@ -56,11 +56,11 @@ describe('lint', () => {
|
|
|
56
56
|
|
|
57
57
|
expect(replaceSourceWithRef(results, path.join(__dirname, 'fixtures/lint/')))
|
|
58
58
|
.toMatchInlineSnapshot(`
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
[
|
|
60
|
+
{
|
|
61
61
|
"from": undefined,
|
|
62
|
-
"location":
|
|
63
|
-
|
|
62
|
+
"location": [
|
|
63
|
+
{
|
|
64
64
|
"pointer": "#/info/license",
|
|
65
65
|
"reportOnKey": false,
|
|
66
66
|
"source": "openapi.yaml",
|
|
@@ -69,7 +69,7 @@ describe('lint', () => {
|
|
|
69
69
|
"message": "Expected type \`License\` (object) but got \`string\`",
|
|
70
70
|
"ruleId": "spec",
|
|
71
71
|
"severity": "error",
|
|
72
|
-
"suggest":
|
|
72
|
+
"suggest": [],
|
|
73
73
|
},
|
|
74
74
|
]
|
|
75
75
|
`);
|
|
@@ -125,11 +125,11 @@ describe('lint', () => {
|
|
|
125
125
|
const results = await lintConfig({ document });
|
|
126
126
|
|
|
127
127
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
[
|
|
129
|
+
{
|
|
130
130
|
"from": undefined,
|
|
131
|
-
"location":
|
|
132
|
-
|
|
131
|
+
"location": [
|
|
132
|
+
{
|
|
133
133
|
"pointer": "#/eme",
|
|
134
134
|
"reportOnKey": true,
|
|
135
135
|
"source": "",
|
|
@@ -138,17 +138,17 @@ describe('lint', () => {
|
|
|
138
138
|
"message": "Property \`eme\` is not expected here.",
|
|
139
139
|
"ruleId": "configuration spec",
|
|
140
140
|
"severity": "error",
|
|
141
|
-
"suggest":
|
|
141
|
+
"suggest": [
|
|
142
142
|
"theme",
|
|
143
143
|
"env",
|
|
144
144
|
"seo",
|
|
145
145
|
"sso",
|
|
146
146
|
],
|
|
147
147
|
},
|
|
148
|
-
|
|
148
|
+
{
|
|
149
149
|
"from": undefined,
|
|
150
|
-
"location":
|
|
151
|
-
|
|
150
|
+
"location": [
|
|
151
|
+
{
|
|
152
152
|
"pointer": "#/openapi",
|
|
153
153
|
"reportOnKey": true,
|
|
154
154
|
"source": "",
|
|
@@ -157,12 +157,12 @@ describe('lint', () => {
|
|
|
157
157
|
"message": "Property \`openapi\` is not expected here.",
|
|
158
158
|
"ruleId": "configuration spec",
|
|
159
159
|
"severity": "error",
|
|
160
|
-
"suggest":
|
|
160
|
+
"suggest": [],
|
|
161
161
|
},
|
|
162
|
-
|
|
162
|
+
{
|
|
163
163
|
"from": undefined,
|
|
164
|
-
"location":
|
|
165
|
-
|
|
164
|
+
"location": [
|
|
165
|
+
{
|
|
166
166
|
"pointer": "#/apis",
|
|
167
167
|
"reportOnKey": false,
|
|
168
168
|
"source": "",
|
|
@@ -171,7 +171,7 @@ describe('lint', () => {
|
|
|
171
171
|
"message": "Expected type \`ConfigApis\` (object) but got \`string\`",
|
|
172
172
|
"ruleId": "configuration spec",
|
|
173
173
|
"severity": "error",
|
|
174
|
-
"suggest":
|
|
174
|
+
"suggest": [],
|
|
175
175
|
},
|
|
176
176
|
]
|
|
177
177
|
`);
|
|
@@ -191,11 +191,11 @@ describe('lint', () => {
|
|
|
191
191
|
const results = await lintConfig({ document });
|
|
192
192
|
|
|
193
193
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
[
|
|
195
|
+
{
|
|
196
196
|
"from": undefined,
|
|
197
|
-
"location":
|
|
198
|
-
|
|
197
|
+
"location": [
|
|
198
|
+
{
|
|
199
199
|
"pointer": "#/api",
|
|
200
200
|
"reportOnKey": true,
|
|
201
201
|
"source": "",
|
|
@@ -204,7 +204,7 @@ describe('lint', () => {
|
|
|
204
204
|
"message": "Property \`api\` is not expected here.",
|
|
205
205
|
"ruleId": "configuration spec",
|
|
206
206
|
"severity": "error",
|
|
207
|
-
"suggest":
|
|
207
|
+
"suggest": [
|
|
208
208
|
"apis",
|
|
209
209
|
"seo",
|
|
210
210
|
"sso",
|
|
@@ -231,11 +231,11 @@ describe('lint', () => {
|
|
|
231
231
|
const results = await lintConfig({ document });
|
|
232
232
|
|
|
233
233
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
234
|
-
|
|
235
|
-
|
|
234
|
+
[
|
|
235
|
+
{
|
|
236
236
|
"from": undefined,
|
|
237
|
-
"location":
|
|
238
|
-
|
|
237
|
+
"location": [
|
|
238
|
+
{
|
|
239
239
|
"pointer": "#/referenceDocs",
|
|
240
240
|
"reportOnKey": true,
|
|
241
241
|
"source": "",
|
|
@@ -244,7 +244,7 @@ describe('lint', () => {
|
|
|
244
244
|
"message": "Property \`referenceDocs\` is not expected here.",
|
|
245
245
|
"ruleId": "configuration spec",
|
|
246
246
|
"severity": "error",
|
|
247
|
-
"suggest":
|
|
247
|
+
"suggest": [],
|
|
248
248
|
},
|
|
249
249
|
]
|
|
250
250
|
`);
|
|
@@ -266,11 +266,11 @@ describe('lint', () => {
|
|
|
266
266
|
const results = await lintConfig({ document });
|
|
267
267
|
|
|
268
268
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
269
|
-
|
|
270
|
-
|
|
269
|
+
[
|
|
270
|
+
{
|
|
271
271
|
"from": undefined,
|
|
272
|
-
"location":
|
|
273
|
-
|
|
272
|
+
"location": [
|
|
273
|
+
{
|
|
274
274
|
"pointer": "#/apis/main/plugins",
|
|
275
275
|
"reportOnKey": true,
|
|
276
276
|
"source": "",
|
|
@@ -279,7 +279,7 @@ describe('lint', () => {
|
|
|
279
279
|
"message": "Property \`plugins\` is not expected here.",
|
|
280
280
|
"ruleId": "configuration spec",
|
|
281
281
|
"severity": "error",
|
|
282
|
-
"suggest":
|
|
282
|
+
"suggest": [],
|
|
283
283
|
},
|
|
284
284
|
]
|
|
285
285
|
`);
|
|
@@ -323,7 +323,7 @@ describe('lint', () => {
|
|
|
323
323
|
config: await makeConfig({ spec: 'error' }),
|
|
324
324
|
});
|
|
325
325
|
|
|
326
|
-
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
326
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
|
|
327
327
|
});
|
|
328
328
|
|
|
329
329
|
it('detect OpenAPI should throw an error when version is not string', () => {
|
|
@@ -402,7 +402,7 @@ describe('lint', () => {
|
|
|
402
402
|
config: await makeConfig({ spec: 'error' }),
|
|
403
403
|
});
|
|
404
404
|
|
|
405
|
-
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
405
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
|
|
406
406
|
});
|
|
407
407
|
|
|
408
408
|
it('should ignore error because ignore file passed', async () => {
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
BaseVisitor,
|
|
3
|
+
NestedVisitObject,
|
|
4
|
+
normalizeVisitors,
|
|
5
|
+
RuleInstanceConfig,
|
|
6
|
+
VisitorLevelContext,
|
|
7
|
+
} from '../visitors';
|
|
2
8
|
import { Oas3RuleSet } from '../oas-types';
|
|
3
9
|
import { Oas3Types } from '../types/oas3';
|
|
4
10
|
import { normalizeTypes } from '../types';
|
|
@@ -25,7 +31,10 @@ describe('Normalize visitors', () => {
|
|
|
25
31
|
}))
|
|
26
32
|
);
|
|
27
33
|
|
|
28
|
-
const normalized = normalizeVisitors(
|
|
34
|
+
const normalized = normalizeVisitors(
|
|
35
|
+
visitors as (RuleInstanceConfig & { visitor: NestedVisitObject<any, BaseVisitor> })[],
|
|
36
|
+
normalizeTypes(Oas3Types)
|
|
37
|
+
);
|
|
29
38
|
expect(normalized).toBeDefined();
|
|
30
39
|
expect(normalized.Schema.enter).toHaveLength(1);
|
|
31
40
|
expect(normalized.Schema.enter[0].visit).toEqual(schemaEnter);
|
|
@@ -69,7 +78,10 @@ describe('Normalize visitors', () => {
|
|
|
69
78
|
}))
|
|
70
79
|
);
|
|
71
80
|
|
|
72
|
-
const normalized = normalizeVisitors(
|
|
81
|
+
const normalized = normalizeVisitors(
|
|
82
|
+
visitors as (RuleInstanceConfig & { visitor: NestedVisitObject<any, BaseVisitor> })[],
|
|
83
|
+
normalizeTypes(Oas3Types)
|
|
84
|
+
);
|
|
73
85
|
expect(normalized).toBeDefined();
|
|
74
86
|
expect(normalized.Info.enter).toHaveLength(1);
|
|
75
87
|
|
|
@@ -107,7 +119,10 @@ describe('Normalize visitors', () => {
|
|
|
107
119
|
}))
|
|
108
120
|
);
|
|
109
121
|
|
|
110
|
-
const normalized = normalizeVisitors(
|
|
122
|
+
const normalized = normalizeVisitors(
|
|
123
|
+
visitors as (RuleInstanceConfig & { visitor: NestedVisitObject<any, BaseVisitor> })[],
|
|
124
|
+
normalizeTypes(Oas3Types)
|
|
125
|
+
);
|
|
111
126
|
expect(normalized).toBeDefined();
|
|
112
127
|
expect(normalized.PathItem.enter).toHaveLength(1);
|
|
113
128
|
expect(normalized.Operation.enter).toHaveLength(1);
|
|
@@ -142,7 +157,10 @@ describe('Normalize visitors', () => {
|
|
|
142
157
|
}))
|
|
143
158
|
);
|
|
144
159
|
|
|
145
|
-
const normalized = normalizeVisitors(
|
|
160
|
+
const normalized = normalizeVisitors(
|
|
161
|
+
visitors as (RuleInstanceConfig & { visitor: NestedVisitObject<any, BaseVisitor> })[],
|
|
162
|
+
normalizeTypes(Oas3Types)
|
|
163
|
+
);
|
|
146
164
|
expect(normalized).toBeDefined();
|
|
147
165
|
expect(normalized.Parameter.enter).toHaveLength(2);
|
|
148
166
|
expect(normalized.Parameter.enter[0].visit).toStrictEqual(operationParam);
|
|
@@ -9,8 +9,8 @@ describe('ref-utils', () => {
|
|
|
9
9
|
it(`should unescape refs with '/'`, () => {
|
|
10
10
|
const reference = 'somefile.yaml#/components/schemas/scope~1domain-schema';
|
|
11
11
|
expect(parseRef(reference)).toMatchInlineSnapshot(`
|
|
12
|
-
|
|
13
|
-
"pointer":
|
|
12
|
+
{
|
|
13
|
+
"pointer": [
|
|
14
14
|
"components",
|
|
15
15
|
"schemas",
|
|
16
16
|
"scope/domain-schema",
|
|
@@ -23,8 +23,8 @@ describe('ref-utils', () => {
|
|
|
23
23
|
it(`should unescape refs with '~'`, () => {
|
|
24
24
|
const reference = 'somefile.yaml#/components/schemas/complex~0name';
|
|
25
25
|
expect(parseRef(reference)).toMatchInlineSnapshot(`
|
|
26
|
-
|
|
27
|
-
"pointer":
|
|
26
|
+
{
|
|
27
|
+
"pointer": [
|
|
28
28
|
"components",
|
|
29
29
|
"schemas",
|
|
30
30
|
"complex~name",
|
|
@@ -37,8 +37,8 @@ describe('ref-utils', () => {
|
|
|
37
37
|
it(`should unescape complex urlencoded paths`, () => {
|
|
38
38
|
const referene = 'somefile.yaml#/components/schemas/scope%2Fcomplex~name';
|
|
39
39
|
expect(parseRef(referene)).toMatchInlineSnapshot(`
|
|
40
|
-
|
|
41
|
-
"pointer":
|
|
40
|
+
{
|
|
41
|
+
"pointer": [
|
|
42
42
|
"components",
|
|
43
43
|
"schemas",
|
|
44
44
|
"scope/complex~name",
|
|
@@ -93,7 +93,7 @@ describe('ref-utils', () => {
|
|
|
93
93
|
config: new StyleguideConfig({}),
|
|
94
94
|
});
|
|
95
95
|
|
|
96
|
-
expect(result).toMatchInlineSnapshot(`
|
|
96
|
+
expect(result).toMatchInlineSnapshot(`[]`);
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
describe('refBaseName', () => {
|
|
@@ -48,25 +48,25 @@ describe('Resolve http-headers', () => {
|
|
|
48
48
|
|
|
49
49
|
expect(fetchMock).toBeCalledTimes(3);
|
|
50
50
|
expect(fetchMock.mock.calls).toMatchInlineSnapshot(`
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
[
|
|
52
|
+
[
|
|
53
53
|
"https://example.com/test.yaml",
|
|
54
|
-
|
|
55
|
-
"headers":
|
|
54
|
+
{
|
|
55
|
+
"headers": {
|
|
56
56
|
"X_TEST": "123",
|
|
57
57
|
},
|
|
58
58
|
},
|
|
59
59
|
],
|
|
60
|
-
|
|
60
|
+
[
|
|
61
61
|
"https://sample.com/test.yaml",
|
|
62
|
-
|
|
63
|
-
"headers":
|
|
62
|
+
{
|
|
63
|
+
"headers": {},
|
|
64
64
|
},
|
|
65
65
|
],
|
|
66
|
-
|
|
66
|
+
[
|
|
67
67
|
"https://sample.com/test/a/test.yaml",
|
|
68
|
-
|
|
69
|
-
"headers":
|
|
68
|
+
{
|
|
69
|
+
"headers": {
|
|
70
70
|
"X_TEST": "321",
|
|
71
71
|
},
|
|
72
72
|
},
|
|
@@ -33,7 +33,7 @@ describe('collect refs', () => {
|
|
|
33
33
|
expect(Array.from(resolvedRefs.keys())).toMatchInlineSnapshot(
|
|
34
34
|
[`foobar.yaml::#/defs/info`],
|
|
35
35
|
`
|
|
36
|
-
|
|
36
|
+
[
|
|
37
37
|
"foobar.yaml::#/defs/info",
|
|
38
38
|
]
|
|
39
39
|
`
|
|
@@ -198,7 +198,7 @@ describe('collect refs', () => {
|
|
|
198
198
|
.map((ref) => ref.substring(cwd.length + 1))
|
|
199
199
|
.sort()
|
|
200
200
|
).toMatchInlineSnapshot(`
|
|
201
|
-
|
|
201
|
+
[
|
|
202
202
|
"openapi-with-back.yaml::./schemas/type-a.yaml#/",
|
|
203
203
|
"openapi-with-back.yaml::./schemas/type-b.yaml#/",
|
|
204
204
|
"schemas/type-a.yaml::../openapi-with-back.yaml#/components/schemas/TypeB",
|
|
@@ -214,19 +214,19 @@ describe('collect refs', () => {
|
|
|
214
214
|
return getKey(firstEl).localeCompare(getKey(secondEl));
|
|
215
215
|
})
|
|
216
216
|
).toMatchInlineSnapshot(`
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
"allOf":
|
|
220
|
-
|
|
221
|
-
"properties":
|
|
222
|
-
"integration_type":
|
|
217
|
+
[
|
|
218
|
+
{
|
|
219
|
+
"allOf": [
|
|
220
|
+
{
|
|
221
|
+
"properties": {
|
|
222
|
+
"integration_type": {
|
|
223
223
|
"$ref": "../openapi-with-back.yaml#/components/schemas/TypeB",
|
|
224
224
|
},
|
|
225
|
-
"name":
|
|
225
|
+
"name": {
|
|
226
226
|
"type": "string",
|
|
227
227
|
},
|
|
228
228
|
},
|
|
229
|
-
"required":
|
|
229
|
+
"required": [
|
|
230
230
|
"name",
|
|
231
231
|
"integration_type",
|
|
232
232
|
],
|
|
@@ -234,8 +234,8 @@ describe('collect refs', () => {
|
|
|
234
234
|
},
|
|
235
235
|
],
|
|
236
236
|
},
|
|
237
|
-
|
|
238
|
-
"enum":
|
|
237
|
+
{
|
|
238
|
+
"enum": [
|
|
239
239
|
"webhook",
|
|
240
240
|
"api_key",
|
|
241
241
|
"sftp",
|
|
@@ -243,8 +243,8 @@ describe('collect refs', () => {
|
|
|
243
243
|
],
|
|
244
244
|
"type": "string",
|
|
245
245
|
},
|
|
246
|
-
|
|
247
|
-
"enum":
|
|
246
|
+
{
|
|
247
|
+
"enum": [
|
|
248
248
|
"webhook",
|
|
249
249
|
"api_key",
|
|
250
250
|
"sftp",
|
|
@@ -270,7 +270,7 @@ describe('collect refs', () => {
|
|
|
270
270
|
expect(resolvedRefs).toBeDefined();
|
|
271
271
|
expect(Array.from(resolvedRefs.keys()).map((ref) => ref.substring(cwd.length + 1)))
|
|
272
272
|
.toMatchInlineSnapshot(`
|
|
273
|
-
|
|
273
|
+
[
|
|
274
274
|
"openapi.yaml::#/components/schemas/Local",
|
|
275
275
|
"openapi.yaml::#/components/schemas/Local/properties/string",
|
|
276
276
|
"openapi.yaml::./External.yaml#/properties/string",
|
|
@@ -281,62 +281,62 @@ describe('collect refs', () => {
|
|
|
281
281
|
`);
|
|
282
282
|
|
|
283
283
|
expect(Array.from(resolvedRefs.values()).map((val) => val.node)).toMatchInlineSnapshot(`
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
"properties":
|
|
287
|
-
"localCircular":
|
|
284
|
+
[
|
|
285
|
+
{
|
|
286
|
+
"properties": {
|
|
287
|
+
"localCircular": {
|
|
288
288
|
"$ref": "#/components/schemas/Local",
|
|
289
289
|
},
|
|
290
|
-
"number":
|
|
290
|
+
"number": {
|
|
291
291
|
"type": "number",
|
|
292
292
|
},
|
|
293
|
-
"string":
|
|
293
|
+
"string": {
|
|
294
294
|
"type": "string",
|
|
295
295
|
},
|
|
296
296
|
},
|
|
297
297
|
},
|
|
298
|
-
|
|
298
|
+
{
|
|
299
299
|
"type": "string",
|
|
300
300
|
},
|
|
301
|
-
|
|
301
|
+
{
|
|
302
302
|
"type": "string",
|
|
303
303
|
},
|
|
304
|
-
|
|
305
|
-
"properties":
|
|
306
|
-
"external":
|
|
304
|
+
{
|
|
305
|
+
"properties": {
|
|
306
|
+
"external": {
|
|
307
307
|
"$ref": "./External2.yaml",
|
|
308
308
|
},
|
|
309
|
-
"number":
|
|
309
|
+
"number": {
|
|
310
310
|
"type": "number",
|
|
311
311
|
},
|
|
312
|
-
"string":
|
|
312
|
+
"string": {
|
|
313
313
|
"type": "string",
|
|
314
314
|
},
|
|
315
|
-
"unknown":
|
|
315
|
+
"unknown": {
|
|
316
316
|
"type": "string",
|
|
317
317
|
},
|
|
318
318
|
},
|
|
319
319
|
"type": "object",
|
|
320
320
|
},
|
|
321
|
-
|
|
322
|
-
"properties":
|
|
323
|
-
"circularParent":
|
|
321
|
+
{
|
|
322
|
+
"properties": {
|
|
323
|
+
"circularParent": {
|
|
324
324
|
"$ref": "./External.yaml#/properties",
|
|
325
325
|
},
|
|
326
326
|
},
|
|
327
327
|
"type": "object",
|
|
328
328
|
},
|
|
329
|
-
|
|
330
|
-
"external":
|
|
329
|
+
{
|
|
330
|
+
"external": {
|
|
331
331
|
"$ref": "./External2.yaml",
|
|
332
332
|
},
|
|
333
|
-
"number":
|
|
333
|
+
"number": {
|
|
334
334
|
"type": "number",
|
|
335
335
|
},
|
|
336
|
-
"string":
|
|
336
|
+
"string": {
|
|
337
337
|
"type": "string",
|
|
338
338
|
},
|
|
339
|
-
"unknown":
|
|
339
|
+
"unknown": {
|
|
340
340
|
"type": "string",
|
|
341
341
|
},
|
|
342
342
|
},
|
|
@@ -366,12 +366,12 @@ describe('collect refs', () => {
|
|
|
366
366
|
// expect(resolvedRefs.size).toEqual(2);
|
|
367
367
|
expect(Array.from(resolvedRefs.keys()).map((ref) => ref.substring(cwd.length + 1)))
|
|
368
368
|
.toMatchInlineSnapshot(`
|
|
369
|
-
|
|
369
|
+
[
|
|
370
370
|
"openapi-with-md-description.yaml::./description.md",
|
|
371
371
|
]
|
|
372
372
|
`);
|
|
373
373
|
expect(Array.from(resolvedRefs.values()).map((val) => val.node)).toMatchInlineSnapshot(`
|
|
374
|
-
|
|
374
|
+
[
|
|
375
375
|
"# Hello World
|
|
376
376
|
|
|
377
377
|
Lorem ipsum
|