@redocly/openapi-core 1.0.0-beta.104 → 1.0.0-beta.107
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 +8 -6
- 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 +2 -2
- package/lib/config/all.d.ts +2 -2
- package/lib/config/all.js +1 -1
- 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 +39 -36
- package/lib/config/config.d.ts +6 -5
- package/lib/config/config.js +27 -20
- package/lib/config/load.js +6 -7
- package/lib/config/minimal.d.ts +2 -2
- package/lib/config/minimal.js +3 -2
- package/lib/config/recommended.d.ts +2 -2
- package/lib/config/recommended.js +3 -2
- package/lib/config/rules.d.ts +2 -2
- 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 +43 -26
- package/lib/decorators/common/remove-x-internal.js +2 -2
- package/lib/format/format.js +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +3 -2
- package/lib/js-yaml/index.js +1 -6
- package/lib/lint.d.ts +2 -2
- package/lib/lint.js +16 -6
- package/lib/redocly/registry-api.d.ts +1 -1
- package/lib/redocly/registry-api.js +2 -2
- package/lib/rules/ajv.d.ts +1 -1
- package/lib/rules/ajv.js +6 -6
- 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/path-not-include-query.js +1 -1
- package/lib/rules/common/paths-kebab-case.js +4 -1
- package/lib/rules/common/spec.js +1 -1
- package/lib/rules/oas2/index.js +4 -4
- package/lib/rules/oas2/remove-unused-components.js +3 -3
- package/lib/rules/oas3/index.js +4 -4
- 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/remove-unused-components.js +2 -2
- package/lib/rules/other/stats.js +43 -14
- package/lib/rules/utils.d.ts +3 -2
- package/lib/rules/utils.js +19 -4
- package/lib/types/index.d.ts +2 -2
- package/lib/types/redocly-yaml.js +8 -7
- package/lib/utils.d.ts +5 -2
- package/lib/utils.js +20 -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__/fixtures/.redocly.lint-ignore.yaml +5 -0
- package/src/__tests__/js-yaml.test.ts +6 -4
- package/src/__tests__/lint.test.ts +127 -12
- package/src/__tests__/login.test.ts +2 -2
- package/src/__tests__/normalizeVisitors.test.ts +4 -4
- 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.test.ts +42 -1
- 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 -1
- 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 +18 -17
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +3 -1
- package/src/config/__tests__/config-resolvers.test.ts +123 -121
- package/src/config/__tests__/config.test.ts +76 -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 +2 -2
- package/src/config/__tests__/resolve-plugins.test.ts +3 -3
- package/src/config/__tests__/utils.test.ts +83 -0
- package/src/config/all.ts +3 -4
- package/src/config/builtIn.ts +5 -5
- package/src/config/config-resolvers.ts +122 -83
- package/src/config/config.ts +36 -32
- package/src/config/load.ts +13 -16
- package/src/config/minimal.ts +5 -4
- package/src/config/recommended.ts +5 -4
- package/src/config/rules.ts +6 -6
- package/src/config/types.ts +28 -19
- package/src/config/utils.ts +74 -54
- 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/remove-x-internal.ts +4 -4
- package/src/decorators/common/tag-description-override.ts +1 -1
- package/src/format/codeframes.ts +4 -4
- package/src/format/format.ts +10 -10
- package/src/index.ts +3 -4
- package/src/js-yaml/index.ts +3 -8
- package/src/lint.ts +22 -18
- package/src/oas-types.ts +1 -6
- package/src/redocly/__tests__/redocly-client.test.ts +25 -19
- package/src/redocly/index.ts +6 -4
- package/src/redocly/registry-api.ts +6 -6
- package/src/ref-utils.ts +2 -2
- package/src/resolve.ts +7 -4
- 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/index.ts +6 -6
- 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/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 +10 -7
- 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 +13 -8
- package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
- 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 +3 -3
- 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 +9 -10
- package/src/rules/oas3/remove-unused-components.ts +18 -7
- package/src/rules/other/stats.ts +46 -17
- package/src/rules/utils.ts +19 -3
- package/src/types/index.ts +5 -5
- package/src/types/redocly-yaml.ts +8 -7
- package/src/typings/common.ts +9 -1
- package/src/typings/openapi.ts +1 -1
- package/src/utils.ts +31 -8
- package/src/visitors.ts +4 -4
- 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/src/rules/common/license-url.ts +0 -10
|
@@ -2,11 +2,21 @@ import outdent from 'outdent';
|
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
|
|
4
4
|
import { bundleDocument, bundle } from '../bundle';
|
|
5
|
-
import { parseYamlToDocument, yamlSerializer } from '../../__tests__/utils';
|
|
6
|
-
import {
|
|
5
|
+
import { parseYamlToDocument, yamlSerializer, makeConfig } from '../../__tests__/utils';
|
|
6
|
+
import { StyleguideConfig, Config, ResolvedConfig } from '../config';
|
|
7
7
|
import { BaseResolver } from '../resolve';
|
|
8
8
|
|
|
9
9
|
describe('bundle', () => {
|
|
10
|
+
const fetchMock = jest.fn(() =>
|
|
11
|
+
Promise.resolve({
|
|
12
|
+
ok: true,
|
|
13
|
+
text: () => 'External schema content',
|
|
14
|
+
headers: {
|
|
15
|
+
get: () => '',
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
);
|
|
19
|
+
|
|
10
20
|
expect.addSnapshotSerializer(yamlSerializer);
|
|
11
21
|
|
|
12
22
|
const testDocument = parseYamlToDocument(
|
|
@@ -28,14 +38,14 @@ describe('bundle', () => {
|
|
|
28
38
|
shared_a:
|
|
29
39
|
name: shared-a
|
|
30
40
|
`,
|
|
31
|
-
''
|
|
41
|
+
''
|
|
32
42
|
);
|
|
33
43
|
|
|
34
44
|
it('change nothing with only internal refs', async () => {
|
|
35
45
|
const { bundle, problems } = await bundleDocument({
|
|
36
46
|
document: testDocument,
|
|
37
47
|
externalRefResolver: new BaseResolver(),
|
|
38
|
-
config: new
|
|
48
|
+
config: new StyleguideConfig({}),
|
|
39
49
|
});
|
|
40
50
|
|
|
41
51
|
const origCopy = JSON.parse(JSON.stringify(testDocument.parsed));
|
|
@@ -60,7 +70,7 @@ describe('bundle', () => {
|
|
|
60
70
|
});
|
|
61
71
|
expect(problems).toHaveLength(1);
|
|
62
72
|
expect(problems[0].message).toEqual(
|
|
63
|
-
`Two schemas are referenced with the same name but different content. Renamed param-b to param-b-2
|
|
73
|
+
`Two schemas are referenced with the same name but different content. Renamed param-b to param-b-2.`
|
|
64
74
|
);
|
|
65
75
|
expect(res.parsed).toMatchSnapshot();
|
|
66
76
|
});
|
|
@@ -68,7 +78,7 @@ describe('bundle', () => {
|
|
|
68
78
|
it('should dereferenced correctly when used with dereference', async () => {
|
|
69
79
|
const { bundle: res, problems } = await bundleDocument({
|
|
70
80
|
externalRefResolver: new BaseResolver(),
|
|
71
|
-
config: new
|
|
81
|
+
config: new StyleguideConfig({}),
|
|
72
82
|
document: testDocument,
|
|
73
83
|
dereference: true,
|
|
74
84
|
});
|
|
@@ -98,47 +108,25 @@ describe('bundle', () => {
|
|
|
98
108
|
});
|
|
99
109
|
|
|
100
110
|
it('should pull hosted schema', async () => {
|
|
101
|
-
const fetchMock = jest.fn(
|
|
102
|
-
() => Promise.resolve({
|
|
103
|
-
ok: true,
|
|
104
|
-
text: () => 'External schema content',
|
|
105
|
-
headers: {
|
|
106
|
-
get: () => ''
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
);
|
|
110
|
-
|
|
111
111
|
const { bundle: res, problems } = await bundle({
|
|
112
112
|
config: new Config({} as ResolvedConfig),
|
|
113
113
|
externalRefResolver: new BaseResolver({
|
|
114
114
|
http: {
|
|
115
115
|
customFetch: fetchMock,
|
|
116
|
-
headers: []
|
|
117
|
-
}
|
|
116
|
+
headers: [],
|
|
117
|
+
},
|
|
118
118
|
}),
|
|
119
|
-
ref: path.join(__dirname, 'fixtures/refs/hosted.yaml')
|
|
119
|
+
ref: path.join(__dirname, 'fixtures/refs/hosted.yaml'),
|
|
120
120
|
});
|
|
121
121
|
|
|
122
122
|
expect(problems).toHaveLength(0);
|
|
123
|
-
expect(fetchMock).toHaveBeenCalledWith(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
headers: {}
|
|
127
|
-
}
|
|
128
|
-
);
|
|
123
|
+
expect(fetchMock).toHaveBeenCalledWith('https://someexternal.schema', {
|
|
124
|
+
headers: {},
|
|
125
|
+
});
|
|
129
126
|
expect(res.parsed).toMatchSnapshot();
|
|
130
127
|
});
|
|
131
128
|
|
|
132
129
|
it('should not bundle url refs if used with keepUrlRefs', async () => {
|
|
133
|
-
const fetchMock = jest.fn(() =>
|
|
134
|
-
Promise.resolve({
|
|
135
|
-
ok: true,
|
|
136
|
-
text: () => 'External schema content',
|
|
137
|
-
headers: {
|
|
138
|
-
get: () => '',
|
|
139
|
-
},
|
|
140
|
-
}),
|
|
141
|
-
);
|
|
142
130
|
const { bundle: res, problems } = await bundle({
|
|
143
131
|
config: new Config({} as ResolvedConfig),
|
|
144
132
|
externalRefResolver: new BaseResolver({
|
|
@@ -153,4 +141,50 @@ describe('bundle', () => {
|
|
|
153
141
|
expect(problems).toHaveLength(0);
|
|
154
142
|
expect(res.parsed).toMatchSnapshot();
|
|
155
143
|
});
|
|
144
|
+
|
|
145
|
+
it('should add to meta ref from redocly registry', async () => {
|
|
146
|
+
const testDocument = parseYamlToDocument(
|
|
147
|
+
outdent`
|
|
148
|
+
openapi: 3.0.0
|
|
149
|
+
paths:
|
|
150
|
+
/pet:
|
|
151
|
+
get:
|
|
152
|
+
operationId: get
|
|
153
|
+
parameters:
|
|
154
|
+
- $ref: '#/components/parameters/shared_a'
|
|
155
|
+
- name: get_b
|
|
156
|
+
post:
|
|
157
|
+
operationId: post
|
|
158
|
+
parameters:
|
|
159
|
+
- $ref: 'https://api.redocly.com/registry/params'
|
|
160
|
+
components:
|
|
161
|
+
parameters:
|
|
162
|
+
shared_a:
|
|
163
|
+
name: shared-a
|
|
164
|
+
`,
|
|
165
|
+
''
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
const config = await makeConfig({}, { 'registry-dependencies': 'on' });
|
|
169
|
+
|
|
170
|
+
const {
|
|
171
|
+
bundle: result,
|
|
172
|
+
problems,
|
|
173
|
+
...meta
|
|
174
|
+
} = await bundleDocument({
|
|
175
|
+
document: testDocument,
|
|
176
|
+
config: config,
|
|
177
|
+
externalRefResolver: new BaseResolver({
|
|
178
|
+
http: {
|
|
179
|
+
customFetch: fetchMock,
|
|
180
|
+
headers: [],
|
|
181
|
+
},
|
|
182
|
+
}),
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const parsedMeta = JSON.parse(JSON.stringify(meta));
|
|
186
|
+
|
|
187
|
+
expect(problems).toHaveLength(0);
|
|
188
|
+
expect(parsedMeta).toMatchSnapshot();
|
|
189
|
+
});
|
|
156
190
|
});
|
|
@@ -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
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
1
2
|
import { outdent } from 'outdent';
|
|
2
3
|
|
|
3
4
|
import { lintFromString, lintConfig, lintDocument } from '../lint';
|
|
@@ -48,7 +49,7 @@ describe('lint', () => {
|
|
|
48
49
|
const document = parseYamlToDocument(
|
|
49
50
|
outdent`
|
|
50
51
|
apis: error string
|
|
51
|
-
|
|
52
|
+
styleguide:
|
|
52
53
|
plugins:
|
|
53
54
|
- './local-plugin.js'
|
|
54
55
|
extends:
|
|
@@ -70,7 +71,7 @@ describe('lint', () => {
|
|
|
70
71
|
links:
|
|
71
72
|
color: '#6CC496'
|
|
72
73
|
`,
|
|
73
|
-
''
|
|
74
|
+
''
|
|
74
75
|
);
|
|
75
76
|
const results = await lintConfig({ document });
|
|
76
77
|
|
|
@@ -106,18 +107,86 @@ describe('lint', () => {
|
|
|
106
107
|
`);
|
|
107
108
|
});
|
|
108
109
|
|
|
109
|
-
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 () => {
|
|
110
179
|
const document = parseYamlToDocument(
|
|
111
180
|
outdent`
|
|
112
181
|
apis:
|
|
113
|
-
|
|
182
|
+
styleguide:
|
|
114
183
|
plugins:
|
|
115
184
|
- './local-plugin.js'
|
|
116
|
-
|
|
185
|
+
styleguide:
|
|
117
186
|
plugins:
|
|
118
187
|
- './local-plugin.js'
|
|
119
188
|
`,
|
|
120
|
-
''
|
|
189
|
+
''
|
|
121
190
|
);
|
|
122
191
|
const results = await lintConfig({ document });
|
|
123
192
|
|
|
@@ -126,7 +195,7 @@ describe('lint', () => {
|
|
|
126
195
|
Object {
|
|
127
196
|
"location": Array [
|
|
128
197
|
Object {
|
|
129
|
-
"pointer": "#/apis/
|
|
198
|
+
"pointer": "#/apis/styleguide",
|
|
130
199
|
"reportOnKey": true,
|
|
131
200
|
"source": "",
|
|
132
201
|
},
|
|
@@ -139,7 +208,7 @@ describe('lint', () => {
|
|
|
139
208
|
Object {
|
|
140
209
|
"location": Array [
|
|
141
210
|
Object {
|
|
142
|
-
"pointer": "#/apis/
|
|
211
|
+
"pointer": "#/apis/styleguide/plugins",
|
|
143
212
|
"reportOnKey": true,
|
|
144
213
|
"source": "",
|
|
145
214
|
},
|
|
@@ -182,7 +251,7 @@ describe('lint', () => {
|
|
|
182
251
|
type: string
|
|
183
252
|
const: ABC
|
|
184
253
|
`,
|
|
185
|
-
'foobar.yaml'
|
|
254
|
+
'foobar.yaml'
|
|
186
255
|
);
|
|
187
256
|
|
|
188
257
|
const results = await lintDocument({
|
|
@@ -199,10 +268,10 @@ describe('lint', () => {
|
|
|
199
268
|
outdent`
|
|
200
269
|
openapi: 3.0
|
|
201
270
|
`,
|
|
202
|
-
''
|
|
271
|
+
''
|
|
203
272
|
);
|
|
204
273
|
expect(() => detectOpenAPI(testDocument.parsed)).toThrow(
|
|
205
|
-
`Invalid OpenAPI version: should be a string but got "number"
|
|
274
|
+
`Invalid OpenAPI version: should be a string but got "number"`
|
|
206
275
|
);
|
|
207
276
|
});
|
|
208
277
|
|
|
@@ -231,7 +300,7 @@ describe('lint', () => {
|
|
|
231
300
|
'200':
|
|
232
301
|
description: callback successfully processed
|
|
233
302
|
`,
|
|
234
|
-
'foobar.yaml'
|
|
303
|
+
'foobar.yaml'
|
|
235
304
|
);
|
|
236
305
|
|
|
237
306
|
const results = await lintDocument({
|
|
@@ -242,4 +311,50 @@ describe('lint', () => {
|
|
|
242
311
|
|
|
243
312
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
|
|
244
313
|
});
|
|
314
|
+
|
|
315
|
+
it('should ignore error because ignore file passed', async () => {
|
|
316
|
+
const absoluteRef = path.join(__dirname, 'fixtures/openapi.yaml');
|
|
317
|
+
const document = parseYamlToDocument(
|
|
318
|
+
outdent`
|
|
319
|
+
openapi: 3.0.0
|
|
320
|
+
info:
|
|
321
|
+
version: 1.0.0
|
|
322
|
+
title: Example OpenAPI 3 definition.
|
|
323
|
+
description: Information about API
|
|
324
|
+
license:
|
|
325
|
+
name: MIT
|
|
326
|
+
url: 'https://opensource.org/licenses/MIT'
|
|
327
|
+
servers:
|
|
328
|
+
- url: 'https://redocly.com/v1'
|
|
329
|
+
paths:
|
|
330
|
+
'/pets/{petId}':
|
|
331
|
+
post:
|
|
332
|
+
responses:
|
|
333
|
+
'201':
|
|
334
|
+
summary: Exist
|
|
335
|
+
description: example description
|
|
336
|
+
`,
|
|
337
|
+
absoluteRef
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
const configFilePath = path.join(__dirname, 'fixtures');
|
|
341
|
+
|
|
342
|
+
const result = await lintDocument({
|
|
343
|
+
externalRefResolver: new BaseResolver(),
|
|
344
|
+
document,
|
|
345
|
+
config: await makeConfig({ 'operation-operationId': 'error' }, undefined, configFilePath),
|
|
346
|
+
});
|
|
347
|
+
expect(result).toHaveLength(1);
|
|
348
|
+
expect(result).toMatchObject([
|
|
349
|
+
{
|
|
350
|
+
ignored: true,
|
|
351
|
+
location: [{ pointer: '#/paths/~1pets~1{petId}/post/operationId' }],
|
|
352
|
+
message: 'Operation object should contain `operationId` field.',
|
|
353
|
+
ruleId: 'operation-operationId',
|
|
354
|
+
severity: 'error',
|
|
355
|
+
},
|
|
356
|
+
]);
|
|
357
|
+
expect(result[0]).toHaveProperty('ignored', true);
|
|
358
|
+
expect(result[0]).toHaveProperty('ruleId', 'operation-operationId');
|
|
359
|
+
});
|
|
245
360
|
});
|
|
@@ -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));
|
|
@@ -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
|
});
|