@redocly/openapi-core 1.0.0-beta.103 → 1.0.0-beta.106
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 +1 -1
- package/lib/config/recommended.d.ts +2 -2
- package/lib/config/recommended.js +1 -1
- 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/filters/filter-helper.js +1 -1
- 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 +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/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/remove-unused-components.js +2 -2
- package/lib/rules/other/stats.js +43 -14
- package/lib/rules/utils.d.ts +1 -1
- package/lib/rules/utils.js +4 -1
- package/lib/types/index.d.ts +2 -2
- package/lib/types/redocly-yaml.js +9 -7
- package/lib/utils.d.ts +3 -2
- package/lib/utils.js +11 -2
- package/lib/walk.d.ts +2 -14
- package/lib/walk.js +19 -19
- package/package.json +3 -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 +1 -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 +3 -3
- package/src/config/recommended.ts +3 -3
- package/src/config/rules.ts +6 -6
- package/src/config/types.ts +28 -19
- package/src/config/utils.ts +70 -50
- package/src/decorators/__tests__/filter-out.test.ts +113 -5
- 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 +122 -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 +2 -2
- package/src/rules/common/no-invalid-schema-examples.ts +1 -1
- 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 +8 -8
- 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 +12 -4
- 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 +5 -3
- package/src/types/index.ts +5 -5
- package/src/types/redocly-yaml.ts +9 -7
- package/src/typings/common.ts +9 -1
- package/src/typings/openapi.ts +1 -1
- package/src/utils.ts +18 -8
- package/src/visitors.ts +4 -4
- package/src/walk.ts +23 -31
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Config } from '../config';
|
|
1
|
+
import { Config, StyleguideConfig } from '../config';
|
|
2
2
|
import { getMergedConfig } from '../utils';
|
|
3
3
|
|
|
4
4
|
const testConfig: Config = {
|
|
@@ -6,11 +6,11 @@ const testConfig: Config = {
|
|
|
6
6
|
apis: {
|
|
7
7
|
'test@v1': {
|
|
8
8
|
root: 'resources/pets.yaml',
|
|
9
|
-
|
|
9
|
+
styleguide: { rules: { 'operation-summary': 'warn' } },
|
|
10
10
|
},
|
|
11
11
|
},
|
|
12
12
|
organization: 'redocly-test',
|
|
13
|
-
|
|
13
|
+
styleguide: {
|
|
14
14
|
rules: { 'operation-summary': 'error', 'no-empty-servers': 'error' },
|
|
15
15
|
plugins: [],
|
|
16
16
|
},
|
|
@@ -19,11 +19,11 @@ const testConfig: Config = {
|
|
|
19
19
|
apis: {
|
|
20
20
|
'test@v1': {
|
|
21
21
|
root: 'resources/pets.yaml',
|
|
22
|
-
|
|
22
|
+
styleguide: { rules: { 'operation-summary': 'warn' } },
|
|
23
23
|
},
|
|
24
24
|
},
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
|
|
26
|
+
styleguide: {
|
|
27
27
|
rawConfig: {
|
|
28
28
|
rules: { 'operation-summary': 'error', 'no-empty-servers': 'error' },
|
|
29
29
|
plugins: [],
|
|
@@ -42,7 +42,7 @@ const testConfig: Config = {
|
|
|
42
42
|
},
|
|
43
43
|
preprocessors: { oas2: {}, oas3_0: {}, oas3_1: {} },
|
|
44
44
|
decorators: { oas2: {}, oas3_0: {}, oas3_1: {} },
|
|
45
|
-
},
|
|
45
|
+
} as unknown as StyleguideConfig,
|
|
46
46
|
'features.openapi': {},
|
|
47
47
|
'features.mockServer': {},
|
|
48
48
|
resolve: { http: { headers: [] } },
|
|
@@ -50,23 +50,53 @@ const testConfig: Config = {
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
describe('getMergedConfig', () => {
|
|
53
|
-
it('should get
|
|
53
|
+
it('should get styleguide defined in "apis" section', () => {
|
|
54
54
|
expect(getMergedConfig(testConfig, 'test@v1')).toMatchInlineSnapshot(`
|
|
55
55
|
Config {
|
|
56
56
|
"apis": Object {
|
|
57
57
|
"test@v1": Object {
|
|
58
|
-
"
|
|
58
|
+
"root": "resources/pets.yaml",
|
|
59
|
+
"styleguide": Object {
|
|
59
60
|
"rules": Object {
|
|
60
61
|
"operation-summary": "warn",
|
|
61
62
|
},
|
|
62
63
|
},
|
|
63
|
-
"root": "resources/pets.yaml",
|
|
64
64
|
},
|
|
65
65
|
},
|
|
66
66
|
"configFile": "redocly.yaml",
|
|
67
67
|
"features.mockServer": Object {},
|
|
68
68
|
"features.openapi": Object {},
|
|
69
|
-
"
|
|
69
|
+
"organization": "redocly-test",
|
|
70
|
+
"rawConfig": Object {
|
|
71
|
+
"apis": Object {
|
|
72
|
+
"test@v1": Object {
|
|
73
|
+
"root": "resources/pets.yaml",
|
|
74
|
+
"styleguide": Object {
|
|
75
|
+
"rules": Object {
|
|
76
|
+
"operation-summary": "warn",
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
"features.mockServer": Object {},
|
|
82
|
+
"features.openapi": Object {},
|
|
83
|
+
"organization": "redocly-test",
|
|
84
|
+
"styleguide": Object {
|
|
85
|
+
"extendPaths": Array [],
|
|
86
|
+
"pluginPaths": Array [],
|
|
87
|
+
"rules": Object {
|
|
88
|
+
"operation-summary": "warn",
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
"region": undefined,
|
|
93
|
+
"resolve": Object {
|
|
94
|
+
"http": Object {
|
|
95
|
+
"customFetch": undefined,
|
|
96
|
+
"headers": Array [],
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
"styleguide": StyleguideConfig {
|
|
70
100
|
"_usedRules": Set {},
|
|
71
101
|
"_usedVersions": Set {},
|
|
72
102
|
"configFile": "redocly.yaml",
|
|
@@ -105,28 +135,57 @@ describe('getMergedConfig', () => {
|
|
|
105
135
|
},
|
|
106
136
|
},
|
|
107
137
|
},
|
|
138
|
+
}
|
|
139
|
+
`);
|
|
140
|
+
});
|
|
141
|
+
it('should take into account a config file', () => {
|
|
142
|
+
const result = getMergedConfig(testConfig, 'test@v1');
|
|
143
|
+
expect(result.configFile).toEqual('redocly.yaml');
|
|
144
|
+
expect(result.styleguide.configFile).toEqual('redocly.yaml');
|
|
145
|
+
});
|
|
146
|
+
it('should return the same config when there is no alias provided', () => {
|
|
147
|
+
expect(getMergedConfig(testConfig)).toEqual(testConfig);
|
|
148
|
+
});
|
|
149
|
+
it('should handle wrong alias - return the same styleguide, empty features', () => {
|
|
150
|
+
expect(getMergedConfig(testConfig, 'wrong-alias')).toMatchInlineSnapshot(`
|
|
151
|
+
Config {
|
|
152
|
+
"apis": Object {
|
|
153
|
+
"test@v1": Object {
|
|
154
|
+
"root": "resources/pets.yaml",
|
|
155
|
+
"styleguide": Object {
|
|
156
|
+
"rules": Object {
|
|
157
|
+
"operation-summary": "warn",
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
"configFile": "redocly.yaml",
|
|
163
|
+
"features.mockServer": Object {},
|
|
164
|
+
"features.openapi": Object {},
|
|
108
165
|
"organization": "redocly-test",
|
|
109
166
|
"rawConfig": Object {
|
|
110
167
|
"apis": Object {
|
|
111
168
|
"test@v1": Object {
|
|
112
|
-
"
|
|
169
|
+
"root": "resources/pets.yaml",
|
|
170
|
+
"styleguide": Object {
|
|
113
171
|
"rules": Object {
|
|
114
172
|
"operation-summary": "warn",
|
|
115
173
|
},
|
|
116
174
|
},
|
|
117
|
-
"root": "resources/pets.yaml",
|
|
118
175
|
},
|
|
119
176
|
},
|
|
120
177
|
"features.mockServer": Object {},
|
|
121
178
|
"features.openapi": Object {},
|
|
122
|
-
"
|
|
179
|
+
"organization": "redocly-test",
|
|
180
|
+
"styleguide": Object {
|
|
123
181
|
"extendPaths": Array [],
|
|
124
182
|
"pluginPaths": Array [],
|
|
183
|
+
"plugins": Array [],
|
|
125
184
|
"rules": Object {
|
|
126
|
-
"
|
|
185
|
+
"no-empty-servers": "error",
|
|
186
|
+
"operation-summary": "error",
|
|
127
187
|
},
|
|
128
188
|
},
|
|
129
|
-
"organization": "redocly-test",
|
|
130
189
|
},
|
|
131
190
|
"region": undefined,
|
|
132
191
|
"resolve": Object {
|
|
@@ -135,34 +194,7 @@ describe('getMergedConfig', () => {
|
|
|
135
194
|
"headers": Array [],
|
|
136
195
|
},
|
|
137
196
|
},
|
|
138
|
-
|
|
139
|
-
`);
|
|
140
|
-
});
|
|
141
|
-
it('should take into account a config file', () => {
|
|
142
|
-
const result = getMergedConfig(testConfig, 'test@v1');
|
|
143
|
-
expect(result.configFile).toEqual('redocly.yaml');
|
|
144
|
-
expect(result.lint.configFile).toEqual('redocly.yaml');
|
|
145
|
-
});
|
|
146
|
-
it('should return the same config when there is no alias provided', () => {
|
|
147
|
-
expect(getMergedConfig(testConfig)).toEqual(testConfig);
|
|
148
|
-
});
|
|
149
|
-
it('should handle wrong alias - return the same lint, empty features', () => {
|
|
150
|
-
expect(getMergedConfig(testConfig, 'wrong-alias')).toMatchInlineSnapshot(`
|
|
151
|
-
Config {
|
|
152
|
-
"apis": Object {
|
|
153
|
-
"test@v1": Object {
|
|
154
|
-
"lint": Object {
|
|
155
|
-
"rules": Object {
|
|
156
|
-
"operation-summary": "warn",
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
"root": "resources/pets.yaml",
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
"configFile": "redocly.yaml",
|
|
163
|
-
"features.mockServer": Object {},
|
|
164
|
-
"features.openapi": Object {},
|
|
165
|
-
"lint": LintConfig {
|
|
197
|
+
"styleguide": StyleguideConfig {
|
|
166
198
|
"_usedRules": Set {},
|
|
167
199
|
"_usedVersions": Set {},
|
|
168
200
|
"configFile": "redocly.yaml",
|
|
@@ -206,38 +238,6 @@ describe('getMergedConfig', () => {
|
|
|
206
238
|
},
|
|
207
239
|
},
|
|
208
240
|
},
|
|
209
|
-
"organization": "redocly-test",
|
|
210
|
-
"rawConfig": Object {
|
|
211
|
-
"apis": Object {
|
|
212
|
-
"test@v1": Object {
|
|
213
|
-
"lint": Object {
|
|
214
|
-
"rules": Object {
|
|
215
|
-
"operation-summary": "warn",
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
"root": "resources/pets.yaml",
|
|
219
|
-
},
|
|
220
|
-
},
|
|
221
|
-
"features.mockServer": Object {},
|
|
222
|
-
"features.openapi": Object {},
|
|
223
|
-
"lint": Object {
|
|
224
|
-
"extendPaths": Array [],
|
|
225
|
-
"pluginPaths": Array [],
|
|
226
|
-
"plugins": Array [],
|
|
227
|
-
"rules": Object {
|
|
228
|
-
"no-empty-servers": "error",
|
|
229
|
-
"operation-summary": "error",
|
|
230
|
-
},
|
|
231
|
-
},
|
|
232
|
-
"organization": "redocly-test",
|
|
233
|
-
},
|
|
234
|
-
"region": undefined,
|
|
235
|
-
"resolve": Object {
|
|
236
|
-
"http": Object {
|
|
237
|
-
"customFetch": undefined,
|
|
238
|
-
"headers": Array [],
|
|
239
|
-
},
|
|
240
|
-
},
|
|
241
241
|
}
|
|
242
242
|
`);
|
|
243
243
|
});
|
|
@@ -21,7 +21,10 @@ const rules = {
|
|
|
21
21
|
return {
|
|
22
22
|
SecurityScheme(scheme, { location, report }) {
|
|
23
23
|
if (scheme.type === 'openIdConnect') {
|
|
24
|
-
if (
|
|
24
|
+
if (
|
|
25
|
+
scheme.openIdConnectUrl &&
|
|
26
|
+
!scheme.openIdConnectUrl.endsWith('/.well-known/openid-configuration')
|
|
27
|
+
) {
|
|
25
28
|
report({
|
|
26
29
|
message:
|
|
27
30
|
'openIdConnectUrl must be a URL that ends with /.well-known/openid-configuration',
|
|
@@ -57,7 +60,6 @@ const configs = {
|
|
|
57
60
|
},
|
|
58
61
|
};
|
|
59
62
|
|
|
60
|
-
|
|
61
63
|
module.exports = {
|
|
62
64
|
id,
|
|
63
65
|
preprocessors,
|
|
@@ -21,7 +21,10 @@ const rules = {
|
|
|
21
21
|
return {
|
|
22
22
|
SecurityScheme(scheme, { location, report }) {
|
|
23
23
|
if (scheme.type === 'openIdConnect') {
|
|
24
|
-
if (
|
|
24
|
+
if (
|
|
25
|
+
scheme.openIdConnectUrl &&
|
|
26
|
+
!scheme.openIdConnectUrl.endsWith('/.well-known/openid-configuration')
|
|
27
|
+
) {
|
|
25
28
|
report({
|
|
26
29
|
message:
|
|
27
30
|
'openIdConnectUrl must be a URL that ends with /.well-known/openid-configuration',
|
|
@@ -9,7 +9,7 @@ describe('loadConfig', () => {
|
|
|
9
9
|
jest
|
|
10
10
|
.spyOn(RedoclyClient.prototype, 'getTokens')
|
|
11
11
|
.mockImplementation(() =>
|
|
12
|
-
Promise.resolve([{ region: 'us', token: 'accessToken', valid: true }])
|
|
12
|
+
Promise.resolve([{ region: 'us', token: 'accessToken', valid: true }])
|
|
13
13
|
);
|
|
14
14
|
const config = await loadConfig();
|
|
15
15
|
expect(config.resolve.http.headers).toStrictEqual([
|
|
@@ -32,7 +32,7 @@ describe('loadConfig', () => {
|
|
|
32
32
|
jest
|
|
33
33
|
.spyOn(RedoclyClient.prototype, 'getTokens')
|
|
34
34
|
.mockImplementation(() =>
|
|
35
|
-
Promise.resolve([{ region: 'eu', token: 'accessToken', valid: true }])
|
|
35
|
+
Promise.resolve([{ region: 'eu', token: 'accessToken', valid: true }])
|
|
36
36
|
);
|
|
37
37
|
const config = await loadConfig();
|
|
38
38
|
expect(config.resolve.http.headers).toStrictEqual([
|
|
@@ -6,21 +6,21 @@ describe('resolving a plugin', () => {
|
|
|
6
6
|
|
|
7
7
|
it('should prefix rule names with the plugin id', async () => {
|
|
8
8
|
const config = await loadConfig(configPath);
|
|
9
|
-
const plugin = config.
|
|
9
|
+
const plugin = config.styleguide.plugins[0];
|
|
10
10
|
|
|
11
11
|
expect(plugin.rules?.oas3).toHaveProperty('test-plugin/openid-connect-url-well-known');
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
it('should prefix preprocessor names with the plugin id', async () => {
|
|
15
15
|
const config = await loadConfig(configPath);
|
|
16
|
-
const plugin = config.
|
|
16
|
+
const plugin = config.styleguide.plugins[0];
|
|
17
17
|
|
|
18
18
|
expect(plugin.preprocessors?.oas2).toHaveProperty('test-plugin/description-preprocessor');
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
it('should prefix decorator names with the plugin id', async () => {
|
|
22
22
|
const config = await loadConfig(configPath);
|
|
23
|
-
const plugin = config.
|
|
23
|
+
const plugin = config.styleguide.plugins[0];
|
|
24
24
|
|
|
25
25
|
expect(plugin.decorators?.oas3).toHaveProperty('test-plugin/inject-x-stats');
|
|
26
26
|
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { DeprecatedInRawConfig, RawConfig } from '../types';
|
|
2
|
+
import * as utils from '../utils';
|
|
3
|
+
|
|
4
|
+
const makeTestRawConfig = (
|
|
5
|
+
apiStyleguideName: string,
|
|
6
|
+
rootStyleguideName: string
|
|
7
|
+
): RawConfig & DeprecatedInRawConfig => ({
|
|
8
|
+
apis: {
|
|
9
|
+
'test@v1': {
|
|
10
|
+
root: 'root.yaml',
|
|
11
|
+
[apiStyleguideName]: {
|
|
12
|
+
rules: {
|
|
13
|
+
'operation-2xx-response': 'error',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
[rootStyleguideName]: {
|
|
19
|
+
rules: {
|
|
20
|
+
'operation-4xx-response': 'warn',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('transformConfig', () => {
|
|
26
|
+
it('should work for new syntax', () => {
|
|
27
|
+
const transformedRawConfig: RawConfig = utils.transformConfig(
|
|
28
|
+
makeTestRawConfig('styleguide', 'styleguide')
|
|
29
|
+
);
|
|
30
|
+
expect(transformedRawConfig).toMatchInlineSnapshot(`
|
|
31
|
+
Object {
|
|
32
|
+
"apis": Object {
|
|
33
|
+
"test@v1": Object {
|
|
34
|
+
"root": "root.yaml",
|
|
35
|
+
"styleguide": Object {
|
|
36
|
+
"rules": Object {
|
|
37
|
+
"operation-2xx-response": "error",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
"features.openapi": undefined,
|
|
43
|
+
"styleguide": Object {
|
|
44
|
+
"rules": Object {
|
|
45
|
+
"operation-4xx-response": "warn",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
`);
|
|
50
|
+
});
|
|
51
|
+
it('should be equal for both `lint` and `styleguide` names', () => {
|
|
52
|
+
expect(utils.transformConfig(makeTestRawConfig('lint', 'styleguide'))).toEqual(
|
|
53
|
+
utils.transformConfig(makeTestRawConfig('styleguide', 'lint'))
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
it('should work for `apiDefinitions`', () => {
|
|
57
|
+
const testRawConfig = makeTestRawConfig('styleguide', 'lint');
|
|
58
|
+
testRawConfig.apis = undefined;
|
|
59
|
+
testRawConfig.apiDefinitions = { legacyApiDefinition: 'file.yaml' };
|
|
60
|
+
expect(utils.transformConfig(testRawConfig)).toMatchInlineSnapshot(`
|
|
61
|
+
Object {
|
|
62
|
+
"apis": Object {
|
|
63
|
+
"legacyApiDefinition": Object {
|
|
64
|
+
"root": "file.yaml",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
"features.openapi": undefined,
|
|
68
|
+
"styleguide": Object {
|
|
69
|
+
"rules": Object {
|
|
70
|
+
"operation-4xx-response": "warn",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
`);
|
|
75
|
+
});
|
|
76
|
+
it('should throw an error if both new and old syntax used together', () => {
|
|
77
|
+
const testRawConfig = makeTestRawConfig('styleguide', 'lint');
|
|
78
|
+
testRawConfig.apiDefinitions = { legacyApiDefinition: 'file.yaml' };
|
|
79
|
+
expect(() => utils.transformConfig(testRawConfig)).toThrowError(
|
|
80
|
+
`Do not use 'apiDefinitions' field. Use 'apis' instead.`
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
});
|
package/src/config/all.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { PluginStyleguideConfig } from './types';
|
|
3
2
|
|
|
4
3
|
export default {
|
|
5
4
|
rules: {
|
|
@@ -20,7 +19,7 @@ export default {
|
|
|
20
19
|
'operation-description': 'error',
|
|
21
20
|
'operation-2xx-response': 'error',
|
|
22
21
|
'operation-4xx-response': 'error',
|
|
23
|
-
|
|
22
|
+
assertions: 'error',
|
|
24
23
|
'operation-operationId': 'error',
|
|
25
24
|
'operation-summary': 'error',
|
|
26
25
|
'operation-operationId-unique': 'error',
|
|
@@ -63,4 +62,4 @@ export default {
|
|
|
63
62
|
'no-undefined-server-variable': 'error',
|
|
64
63
|
'no-servers-empty-enum': 'error',
|
|
65
64
|
},
|
|
66
|
-
} as
|
|
65
|
+
} as PluginStyleguideConfig;
|
package/src/config/builtIn.ts
CHANGED
|
@@ -8,15 +8,15 @@ import { preprocessors as oas2Preprocessors } from '../rules/oas2';
|
|
|
8
8
|
import { decorators as oas3Decorators } from '../decorators/oas3';
|
|
9
9
|
import { decorators as oas2Decorators } from '../decorators/oas2';
|
|
10
10
|
|
|
11
|
-
import type { CustomRulesConfig,
|
|
11
|
+
import type { CustomRulesConfig, StyleguideRawConfig, Plugin } from './types';
|
|
12
12
|
|
|
13
|
-
export const builtInConfigs: Record<string,
|
|
13
|
+
export const builtInConfigs: Record<string, StyleguideRawConfig> = {
|
|
14
14
|
recommended,
|
|
15
15
|
minimal,
|
|
16
16
|
all,
|
|
17
17
|
'redocly-registry': {
|
|
18
|
-
decorators: { 'registry-dependencies': 'on' }
|
|
19
|
-
}
|
|
18
|
+
decorators: { 'registry-dependencies': 'on' },
|
|
19
|
+
},
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
export const defaultPlugin: Plugin = {
|
|
@@ -34,4 +34,4 @@ export const defaultPlugin: Plugin = {
|
|
|
34
34
|
oas2: oas2Decorators,
|
|
35
35
|
},
|
|
36
36
|
configs: builtInConfigs,
|
|
37
|
-
}
|
|
37
|
+
};
|