@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
|
@@ -17,7 +17,7 @@ describe('Location', () => {
|
|
|
17
17
|
license:
|
|
18
18
|
name: MIT
|
|
19
19
|
url: https://google.com
|
|
20
|
-
|
|
20
|
+
`
|
|
21
21
|
),
|
|
22
22
|
};
|
|
23
23
|
const preciseLocation = getLineColLocation(loc);
|
|
@@ -37,7 +37,7 @@ describe('Location', () => {
|
|
|
37
37
|
license:
|
|
38
38
|
name: MIT
|
|
39
39
|
url: https://google.com
|
|
40
|
-
|
|
40
|
+
`
|
|
41
41
|
),
|
|
42
42
|
};
|
|
43
43
|
const preciseLocation = getLineColLocation(loc);
|
|
@@ -57,7 +57,7 @@ describe('Location', () => {
|
|
|
57
57
|
license:
|
|
58
58
|
name: MIT
|
|
59
59
|
url: https://google.com
|
|
60
|
-
|
|
60
|
+
`
|
|
61
61
|
),
|
|
62
62
|
};
|
|
63
63
|
const preciseLocation = getLineColLocation(loc);
|
|
@@ -77,7 +77,7 @@ describe('Location', () => {
|
|
|
77
77
|
license:
|
|
78
78
|
name: MIT
|
|
79
79
|
url: https://google.com
|
|
80
|
-
|
|
80
|
+
`
|
|
81
81
|
),
|
|
82
82
|
};
|
|
83
83
|
const preciseLocation = getLineColLocation(loc);
|
|
@@ -98,7 +98,7 @@ describe('Location', () => {
|
|
|
98
98
|
license:
|
|
99
99
|
name: MIT
|
|
100
100
|
url: https://google.com
|
|
101
|
-
|
|
101
|
+
`
|
|
102
102
|
),
|
|
103
103
|
};
|
|
104
104
|
const preciseLocation = getLineColLocation(loc);
|
|
@@ -106,7 +106,6 @@ describe('Location', () => {
|
|
|
106
106
|
expect(preciseLocation.end).toEqual({ line: 2, col: 9 });
|
|
107
107
|
});
|
|
108
108
|
|
|
109
|
-
|
|
110
109
|
it('should return first line for empty doc', () => {
|
|
111
110
|
const loc = {
|
|
112
111
|
reportOnKey: false,
|
|
@@ -158,7 +157,7 @@ describe('codeframes', () => {
|
|
|
158
157
|
license:
|
|
159
158
|
name: MIT
|
|
160
159
|
url: https://google.com
|
|
161
|
-
|
|
160
|
+
`
|
|
162
161
|
),
|
|
163
162
|
};
|
|
164
163
|
|
|
@@ -222,7 +221,7 @@ describe('codeframes', () => {
|
|
|
222
221
|
license:
|
|
223
222
|
name: MIT
|
|
224
223
|
url: https://google.com
|
|
225
|
-
|
|
224
|
+
`
|
|
226
225
|
),
|
|
227
226
|
};
|
|
228
227
|
|
|
@@ -256,7 +255,7 @@ describe('codeframes', () => {
|
|
|
256
255
|
name: MIT,
|
|
257
256
|
url: https://google.com
|
|
258
257
|
}
|
|
259
|
-
|
|
258
|
+
`
|
|
260
259
|
),
|
|
261
260
|
};
|
|
262
261
|
|
|
@@ -299,7 +298,7 @@ describe('codeframes', () => {
|
|
|
299
298
|
field5: MIT
|
|
300
299
|
url: https://google.com
|
|
301
300
|
openapi: 3.0.2
|
|
302
|
-
|
|
301
|
+
`
|
|
303
302
|
),
|
|
304
303
|
};
|
|
305
304
|
|
|
@@ -343,7 +342,7 @@ describe('codeframes', () => {
|
|
|
343
342
|
field3: MIT
|
|
344
343
|
field4: MIT
|
|
345
344
|
field5: MIT
|
|
346
|
-
|
|
345
|
+
`
|
|
347
346
|
),
|
|
348
347
|
};
|
|
349
348
|
|
|
@@ -390,7 +389,7 @@ describe('codeframes', () => {
|
|
|
390
389
|
in: wrong
|
|
391
390
|
post:
|
|
392
391
|
operationId: test2
|
|
393
|
-
|
|
392
|
+
`
|
|
394
393
|
),
|
|
395
394
|
};
|
|
396
395
|
|
|
@@ -425,7 +424,7 @@ describe('codeframes', () => {
|
|
|
425
424
|
license:
|
|
426
425
|
name: MIT
|
|
427
426
|
url: https://google.com
|
|
428
|
-
|
|
427
|
+
`
|
|
429
428
|
),
|
|
430
429
|
};
|
|
431
430
|
|
|
@@ -483,7 +482,7 @@ describe('codeframes', () => {
|
|
|
483
482
|
license:
|
|
484
483
|
name: MIT
|
|
485
484
|
url: https://google.com
|
|
486
|
-
|
|
485
|
+
`
|
|
487
486
|
),
|
|
488
487
|
};
|
|
489
488
|
|
|
@@ -48,7 +48,7 @@ describe('js-yaml', () => {
|
|
|
48
48
|
|
|
49
49
|
test('should correctly dump date and string', () => {
|
|
50
50
|
expect(stringifyYaml(parseYaml(yamlToDump))).toMatchInlineSnapshot(
|
|
51
|
-
|
|
51
|
+
`
|
|
52
52
|
"date: '2022-01-21T11:29:56.694Z'
|
|
53
53
|
dateWithoutQuotes: '2020-01-01'
|
|
54
54
|
dateWithQuotes: '2020-01-01'
|
|
@@ -57,7 +57,8 @@ describe('js-yaml', () => {
|
|
|
57
57
|
stringWithQuotes: test
|
|
58
58
|
stringWithDoubleQuotes: test
|
|
59
59
|
"
|
|
60
|
-
`
|
|
60
|
+
`
|
|
61
|
+
);
|
|
61
62
|
});
|
|
62
63
|
|
|
63
64
|
test('parse and stringify', () => {
|
|
@@ -65,7 +66,8 @@ describe('js-yaml', () => {
|
|
|
65
66
|
});
|
|
66
67
|
|
|
67
68
|
test('should throw an error for unsupported types', () => {
|
|
68
|
-
expect(() => stringifyYaml({ foo: () => {} }))
|
|
69
|
-
|
|
69
|
+
expect(() => stringifyYaml({ foo: () => {} })).toThrow(
|
|
70
|
+
'unacceptable kind of an object to dump [object Function]'
|
|
71
|
+
);
|
|
70
72
|
});
|
|
71
73
|
});
|
|
@@ -49,7 +49,7 @@ describe('lint', () => {
|
|
|
49
49
|
const document = parseYamlToDocument(
|
|
50
50
|
outdent`
|
|
51
51
|
apis: error string
|
|
52
|
-
|
|
52
|
+
styleguide:
|
|
53
53
|
plugins:
|
|
54
54
|
- './local-plugin.js'
|
|
55
55
|
extends:
|
|
@@ -107,14 +107,82 @@ describe('lint', () => {
|
|
|
107
107
|
`);
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
-
it(
|
|
110
|
+
it('lintConfig should detect wrong fields and suggest correct ones', async () => {
|
|
111
|
+
const document = parseYamlToDocument(
|
|
112
|
+
outdent`
|
|
113
|
+
api:
|
|
114
|
+
name@version:
|
|
115
|
+
root: ./file.yaml
|
|
116
|
+
syleguide:
|
|
117
|
+
rules:
|
|
118
|
+
operation-2xx-response: warn
|
|
119
|
+
`,
|
|
120
|
+
''
|
|
121
|
+
);
|
|
122
|
+
const results = await lintConfig({ document });
|
|
123
|
+
|
|
124
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
125
|
+
Array [
|
|
126
|
+
Object {
|
|
127
|
+
"location": Array [
|
|
128
|
+
Object {
|
|
129
|
+
"pointer": "#/api",
|
|
130
|
+
"reportOnKey": true,
|
|
131
|
+
"source": "",
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
"message": "Property \`api\` is not expected here.",
|
|
135
|
+
"ruleId": "configuration spec",
|
|
136
|
+
"severity": "error",
|
|
137
|
+
"suggest": Array [
|
|
138
|
+
"apis",
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
Object {
|
|
142
|
+
"location": Array [
|
|
143
|
+
Object {
|
|
144
|
+
"pointer": "#/syleguide",
|
|
145
|
+
"reportOnKey": true,
|
|
146
|
+
"source": "",
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
"message": "Property \`syleguide\` is not expected here.",
|
|
150
|
+
"ruleId": "configuration spec",
|
|
151
|
+
"severity": "error",
|
|
152
|
+
"suggest": Array [
|
|
153
|
+
"styleguide",
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
]
|
|
157
|
+
`);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('lintConfig should work with legacy fields', async () => {
|
|
161
|
+
const document = parseYamlToDocument(
|
|
162
|
+
outdent`
|
|
163
|
+
apiDefinitions:
|
|
164
|
+
entry: ./file.yaml
|
|
165
|
+
lint:
|
|
166
|
+
rules:
|
|
167
|
+
operation-2xx-response: warn
|
|
168
|
+
referenceDocs:
|
|
169
|
+
showConsole: true
|
|
170
|
+
`,
|
|
171
|
+
''
|
|
172
|
+
);
|
|
173
|
+
const results = await lintConfig({ document });
|
|
174
|
+
|
|
175
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("'plugins' shouldn't be allowed in 'apis' -> 'styleguide' field", async () => {
|
|
111
179
|
const document = parseYamlToDocument(
|
|
112
180
|
outdent`
|
|
113
181
|
apis:
|
|
114
|
-
|
|
182
|
+
styleguide:
|
|
115
183
|
plugins:
|
|
116
184
|
- './local-plugin.js'
|
|
117
|
-
|
|
185
|
+
styleguide:
|
|
118
186
|
plugins:
|
|
119
187
|
- './local-plugin.js'
|
|
120
188
|
`,
|
|
@@ -127,7 +195,7 @@ describe('lint', () => {
|
|
|
127
195
|
Object {
|
|
128
196
|
"location": Array [
|
|
129
197
|
Object {
|
|
130
|
-
"pointer": "#/apis/
|
|
198
|
+
"pointer": "#/apis/styleguide",
|
|
131
199
|
"reportOnKey": true,
|
|
132
200
|
"source": "",
|
|
133
201
|
},
|
|
@@ -140,7 +208,7 @@ describe('lint', () => {
|
|
|
140
208
|
Object {
|
|
141
209
|
"location": Array [
|
|
142
210
|
Object {
|
|
143
|
-
"pointer": "#/apis/
|
|
211
|
+
"pointer": "#/apis/styleguide/plugins",
|
|
144
212
|
"reportOnKey": true,
|
|
145
213
|
"source": "",
|
|
146
214
|
},
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as colorette from 'colorette';
|
|
6
|
+
import { logger, colorize } from '../logger';
|
|
7
|
+
|
|
8
|
+
describe('Logger in Browser', () => {
|
|
9
|
+
it('should call "console.error"', () => {
|
|
10
|
+
const error = jest.spyOn(console, 'error').mockImplementation();
|
|
11
|
+
|
|
12
|
+
logger.error('error');
|
|
13
|
+
|
|
14
|
+
expect(error).toBeCalledTimes(1);
|
|
15
|
+
expect(error).toBeCalledWith('error');
|
|
16
|
+
|
|
17
|
+
error.mockRestore();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should call "console.log"', () => {
|
|
21
|
+
const log = jest.spyOn(console, 'log').mockImplementation();
|
|
22
|
+
|
|
23
|
+
logger.info('info');
|
|
24
|
+
|
|
25
|
+
expect(log).toBeCalledTimes(1);
|
|
26
|
+
expect(log).toBeCalledWith('info');
|
|
27
|
+
|
|
28
|
+
log.mockRestore();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should call "console.warn"', () => {
|
|
32
|
+
const warn = jest.spyOn(console, 'warn').mockImplementation();
|
|
33
|
+
|
|
34
|
+
logger.warn('warn');
|
|
35
|
+
|
|
36
|
+
expect(warn).toBeCalledTimes(1);
|
|
37
|
+
expect(warn).toBeCalledWith('warn');
|
|
38
|
+
|
|
39
|
+
warn.mockRestore();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('colorize in Browser', () => {
|
|
44
|
+
it('should not call original colorette lib', () => {
|
|
45
|
+
const color = 'cyan';
|
|
46
|
+
const spyingCyan = jest.spyOn(colorette, color);
|
|
47
|
+
|
|
48
|
+
const colorized = colorize.cyan(color);
|
|
49
|
+
|
|
50
|
+
expect(spyingCyan).not.toBeCalled();
|
|
51
|
+
expect(colorized).toEqual(color);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as colorette from 'colorette';
|
|
2
|
+
import { logger, colorize } from '../logger';
|
|
3
|
+
|
|
4
|
+
describe('Logger in nodejs', () => {
|
|
5
|
+
let spyingStderr: jest.SpyInstance;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
spyingStderr = jest.spyOn(process.stderr, 'write').mockImplementation();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
spyingStderr.mockRestore();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should call "process.stderr.write" for error severity', () => {
|
|
16
|
+
logger.error('error');
|
|
17
|
+
|
|
18
|
+
expect(spyingStderr).toBeCalledTimes(1);
|
|
19
|
+
expect(spyingStderr).toBeCalledWith(colorette.red('error'));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should call "process.stderr.write" for warn severity', () => {
|
|
23
|
+
logger.warn('warn');
|
|
24
|
+
|
|
25
|
+
expect(spyingStderr).toBeCalledTimes(1);
|
|
26
|
+
expect(spyingStderr).toBeCalledWith(colorette.yellow('warn'));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should call "process.stderr.write" for info severity', () => {
|
|
30
|
+
logger.info('info');
|
|
31
|
+
|
|
32
|
+
expect(spyingStderr).toBeCalledTimes(1);
|
|
33
|
+
expect(spyingStderr).toBeCalledWith('info');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('colorize in nodejs', () => {
|
|
38
|
+
it('should call original colorette lib', () => {
|
|
39
|
+
const color = 'cyan';
|
|
40
|
+
const spyingCyan = jest.spyOn(colorette, color);
|
|
41
|
+
|
|
42
|
+
const colorized = colorize.cyan(color);
|
|
43
|
+
|
|
44
|
+
expect(spyingCyan).toBeCalledWith(color);
|
|
45
|
+
expect(colorized).toEqual(colorette[color](color));
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -6,10 +6,10 @@ describe.skip('login', () => {
|
|
|
6
6
|
Object.defineProperty(client, 'registryApi', {
|
|
7
7
|
value: {
|
|
8
8
|
setAccessTokens: jest.fn(),
|
|
9
|
-
authStatus: jest.fn(() => true)
|
|
9
|
+
authStatus: jest.fn(() => true),
|
|
10
10
|
},
|
|
11
11
|
writable: true,
|
|
12
|
-
configurable: true
|
|
12
|
+
configurable: true,
|
|
13
13
|
});
|
|
14
14
|
await client.login('token'); // TODO: bug with rewrite local config file
|
|
15
15
|
expect(client.registryApi.setAccessTokens).toHaveBeenCalled();
|
|
@@ -22,7 +22,7 @@ describe('Normalize visitors', () => {
|
|
|
22
22
|
ruleId,
|
|
23
23
|
severity: 'error' as 'error',
|
|
24
24
|
visitor: ruleset[ruleId]({}),
|
|
25
|
-
}))
|
|
25
|
+
}))
|
|
26
26
|
);
|
|
27
27
|
|
|
28
28
|
const normalized = normalizeVisitors(visitors, normalizeTypes(Oas3Types));
|
|
@@ -66,7 +66,7 @@ describe('Normalize visitors', () => {
|
|
|
66
66
|
ruleId,
|
|
67
67
|
severity: 'error' as 'error',
|
|
68
68
|
visitor: ruleset[ruleId]({}),
|
|
69
|
-
}))
|
|
69
|
+
}))
|
|
70
70
|
);
|
|
71
71
|
|
|
72
72
|
const normalized = normalizeVisitors(visitors, normalizeTypes(Oas3Types));
|
|
@@ -104,7 +104,7 @@ describe('Normalize visitors', () => {
|
|
|
104
104
|
ruleId,
|
|
105
105
|
severity: 'error' as 'error',
|
|
106
106
|
visitor: ruleset[ruleId]({}),
|
|
107
|
-
}))
|
|
107
|
+
}))
|
|
108
108
|
);
|
|
109
109
|
|
|
110
110
|
const normalized = normalizeVisitors(visitors, normalizeTypes(Oas3Types));
|
|
@@ -139,7 +139,7 @@ describe('Normalize visitors', () => {
|
|
|
139
139
|
ruleId,
|
|
140
140
|
severity: 'error' as 'error',
|
|
141
141
|
visitor: ruleset[ruleId]({}),
|
|
142
|
-
}))
|
|
142
|
+
}))
|
|
143
143
|
);
|
|
144
144
|
|
|
145
145
|
const normalized = normalizeVisitors(visitors, normalizeTypes(Oas3Types));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { output } from '../output';
|
|
6
|
+
|
|
7
|
+
describe('output', () => {
|
|
8
|
+
it('should ignore all parsable data in browser', () => {
|
|
9
|
+
const spyingStdout = jest.spyOn(process.stdout, 'write').mockImplementation();
|
|
10
|
+
const data = '{ "errors" : [] }';
|
|
11
|
+
|
|
12
|
+
output.write(data);
|
|
13
|
+
|
|
14
|
+
expect(spyingStdout).not.toBeCalled();
|
|
15
|
+
|
|
16
|
+
spyingStdout.mockRestore();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { output } from '../output';
|
|
2
|
+
|
|
3
|
+
describe('output', () => {
|
|
4
|
+
it('should write all parsable data to stdout', () => {
|
|
5
|
+
const spyingStdout = jest.spyOn(process.stdout, 'write').mockImplementation();
|
|
6
|
+
const data = '{ "errors" : [] }';
|
|
7
|
+
|
|
8
|
+
output.write(data);
|
|
9
|
+
|
|
10
|
+
expect(spyingStdout).toBeCalledTimes(1);
|
|
11
|
+
expect(spyingStdout).toBeCalledWith(data);
|
|
12
|
+
|
|
13
|
+
spyingStdout.mockRestore();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -2,7 +2,7 @@ import outdent from 'outdent';
|
|
|
2
2
|
import { parseYamlToDocument } from '../../__tests__/utils';
|
|
3
3
|
import { parseRef, refBaseName } from '../ref-utils';
|
|
4
4
|
import { lintDocument } from '../lint';
|
|
5
|
-
import {
|
|
5
|
+
import { StyleguideConfig } from '../config';
|
|
6
6
|
import { BaseResolver } from '../resolve';
|
|
7
7
|
|
|
8
8
|
describe('ref-utils', () => {
|
|
@@ -84,37 +84,37 @@ describe('ref-utils', () => {
|
|
|
84
84
|
name:
|
|
85
85
|
type: string
|
|
86
86
|
`,
|
|
87
|
-
''
|
|
87
|
+
''
|
|
88
88
|
);
|
|
89
89
|
|
|
90
90
|
const result = await lintDocument({
|
|
91
91
|
document,
|
|
92
92
|
externalRefResolver: new BaseResolver(),
|
|
93
|
-
config: new
|
|
93
|
+
config: new StyleguideConfig({}),
|
|
94
94
|
});
|
|
95
95
|
|
|
96
96
|
expect(result).toMatchInlineSnapshot(`Array []`);
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
describe('refBaseName', () => {
|
|
100
|
-
it(
|
|
101
|
-
expect(refBaseName(
|
|
100
|
+
it('returns base name for file reference', () => {
|
|
101
|
+
expect(refBaseName('../testcase/Pet.yaml')).toStrictEqual('Pet');
|
|
102
102
|
});
|
|
103
103
|
|
|
104
|
-
it(
|
|
105
|
-
expect(refBaseName(
|
|
104
|
+
it('returns base name for local file reference', () => {
|
|
105
|
+
expect(refBaseName('Cat.json')).toStrictEqual('Cat');
|
|
106
106
|
});
|
|
107
107
|
|
|
108
|
-
it(
|
|
109
|
-
expect(refBaseName(
|
|
108
|
+
it('returns base name for url reference', () => {
|
|
109
|
+
expect(refBaseName('http://example.com/tests/crocodile.json')).toStrictEqual('crocodile');
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
-
it(
|
|
113
|
-
expect(refBaseName(
|
|
112
|
+
it('returns base name for file with multiple dots in name', () => {
|
|
113
|
+
expect(refBaseName('feline.tiger.v1.yaml')).toStrictEqual('feline.tiger.v1');
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
-
it(
|
|
117
|
-
expect(refBaseName(
|
|
116
|
+
it('returns base name for file without any dots in name', () => {
|
|
117
|
+
expect(refBaseName('abcdefg')).toStrictEqual('abcdefg');
|
|
118
118
|
});
|
|
119
119
|
});
|
|
120
120
|
});
|
|
@@ -18,7 +18,7 @@ describe('collect refs', () => {
|
|
|
18
18
|
contact: {}
|
|
19
19
|
license: {}
|
|
20
20
|
`,
|
|
21
|
-
'foobar.yaml'
|
|
21
|
+
'foobar.yaml'
|
|
22
22
|
);
|
|
23
23
|
|
|
24
24
|
const resolvedRefs = await resolveDocument({
|
|
@@ -35,7 +35,7 @@ describe('collect refs', () => {
|
|
|
35
35
|
Array [
|
|
36
36
|
"foobar.yaml::#/defs/info",
|
|
37
37
|
]
|
|
38
|
-
|
|
38
|
+
`
|
|
39
39
|
);
|
|
40
40
|
expect(Array.from(resolvedRefs.values()).map((info) => info.node)).toEqual([
|
|
41
41
|
{ contact: {}, license: {} },
|
|
@@ -56,7 +56,7 @@ describe('collect refs', () => {
|
|
|
56
56
|
contact: {}
|
|
57
57
|
license: {}
|
|
58
58
|
`,
|
|
59
|
-
''
|
|
59
|
+
''
|
|
60
60
|
);
|
|
61
61
|
|
|
62
62
|
try {
|
|
@@ -89,7 +89,7 @@ describe('collect refs', () => {
|
|
|
89
89
|
contact: {}
|
|
90
90
|
license: {}
|
|
91
91
|
`,
|
|
92
|
-
'foobar.yaml'
|
|
92
|
+
'foobar.yaml'
|
|
93
93
|
);
|
|
94
94
|
|
|
95
95
|
const resolvedRefs = await resolveDocument({
|
|
@@ -125,7 +125,7 @@ describe('collect refs', () => {
|
|
|
125
125
|
loop2:
|
|
126
126
|
$ref: '#/info'
|
|
127
127
|
`,
|
|
128
|
-
'foobar.yaml'
|
|
128
|
+
'foobar.yaml'
|
|
129
129
|
);
|
|
130
130
|
|
|
131
131
|
try {
|
|
@@ -147,7 +147,7 @@ describe('collect refs', () => {
|
|
|
147
147
|
info:
|
|
148
148
|
$ref: "./externalInfo.yaml#/info"
|
|
149
149
|
`,
|
|
150
|
-
path.join(cwd, 'foobar.yaml')
|
|
150
|
+
path.join(cwd, 'foobar.yaml')
|
|
151
151
|
);
|
|
152
152
|
|
|
153
153
|
const resolvedRefs = await resolveDocument({
|
|
@@ -181,7 +181,7 @@ describe('collect refs', () => {
|
|
|
181
181
|
const externalRefResolver = new BaseResolver();
|
|
182
182
|
const rootDocument = await externalRefResolver.resolveDocument(
|
|
183
183
|
null,
|
|
184
|
-
`${cwd}/openapi-with-back.yaml
|
|
184
|
+
`${cwd}/openapi-with-back.yaml`
|
|
185
185
|
);
|
|
186
186
|
|
|
187
187
|
const resolvedRefs = await resolveDocument({
|
|
@@ -192,8 +192,11 @@ describe('collect refs', () => {
|
|
|
192
192
|
|
|
193
193
|
expect(resolvedRefs).toBeDefined();
|
|
194
194
|
|
|
195
|
-
expect(
|
|
196
|
-
.
|
|
195
|
+
expect(
|
|
196
|
+
Array.from(resolvedRefs.keys())
|
|
197
|
+
.map((ref) => ref.substring(cwd.length + 1))
|
|
198
|
+
.sort()
|
|
199
|
+
).toMatchInlineSnapshot(`
|
|
197
200
|
Array [
|
|
198
201
|
"openapi-with-back.yaml::./schemas/type-a.yaml#/",
|
|
199
202
|
"openapi-with-back.yaml::./schemas/type-b.yaml#/",
|
|
@@ -345,7 +348,7 @@ describe('collect refs', () => {
|
|
|
345
348
|
const externalRefResolver = new BaseResolver();
|
|
346
349
|
const rootDocument = await externalRefResolver.resolveDocument(
|
|
347
350
|
null,
|
|
348
|
-
`${cwd}/openapi-with-md-description.yaml
|
|
351
|
+
`${cwd}/openapi-with-md-description.yaml`
|
|
349
352
|
);
|
|
350
353
|
|
|
351
354
|
expect(rootDocument).toBeDefined();
|
|
@@ -383,7 +386,7 @@ describe('collect refs', () => {
|
|
|
383
386
|
components:
|
|
384
387
|
$ref: "./transitive/components.yaml#/components/schemas/a"
|
|
385
388
|
`,
|
|
386
|
-
path.join(cwd, 'foobar.yaml')
|
|
389
|
+
path.join(cwd, 'foobar.yaml')
|
|
387
390
|
);
|
|
388
391
|
|
|
389
392
|
const resolvedRefs = await resolveDocument({
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
getMatchingStatusCodeRange,
|
|
6
6
|
doesYamlFileExist,
|
|
7
7
|
} from '../utils';
|
|
8
|
+
import { isBrowser } from '../env';
|
|
8
9
|
import * as fs from 'fs';
|
|
9
10
|
import * as path from 'path';
|
|
10
11
|
|
|
@@ -122,5 +123,11 @@ describe('utils', () => {
|
|
|
122
123
|
expect(doesYamlFileExist('redocly.yam')).toBe(false);
|
|
123
124
|
});
|
|
124
125
|
});
|
|
126
|
+
|
|
127
|
+
describe('isBrowser', () => {
|
|
128
|
+
it('should not be browser', () => {
|
|
129
|
+
expect(isBrowser).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
125
132
|
});
|
|
126
133
|
});
|