@redocly/openapi-core 1.0.0-beta.94 → 1.0.0-beta.95

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.
Files changed (115) hide show
  1. package/__tests__/bundle.test.ts +6 -6
  2. package/__tests__/fixtures/extension.js +1 -1
  3. package/__tests__/login.test.ts +2 -2
  4. package/__tests__/ref-utils.test.ts +1 -1
  5. package/__tests__/utils.ts +30 -18
  6. package/lib/benchmark/benches/recommended-oas3.bench.js +2 -3
  7. package/lib/benchmark/utils.d.ts +2 -1
  8. package/lib/benchmark/utils.js +10 -7
  9. package/lib/bundle.d.ts +2 -2
  10. package/lib/config/all.d.ts +2 -2
  11. package/lib/config/builtIn.d.ts +1 -1
  12. package/lib/config/config-resolvers.d.ts +16 -0
  13. package/lib/config/config-resolvers.js +213 -0
  14. package/lib/config/config.d.ts +14 -129
  15. package/lib/config/config.js +17 -234
  16. package/lib/config/index.d.ts +7 -0
  17. package/lib/config/index.js +19 -0
  18. package/lib/config/load.d.ts +2 -1
  19. package/lib/config/load.js +20 -13
  20. package/lib/config/minimal.d.ts +2 -2
  21. package/lib/config/recommended.d.ts +2 -2
  22. package/lib/config/types.d.ts +113 -0
  23. package/lib/config/types.js +2 -0
  24. package/lib/config/utils.d.ts +13 -0
  25. package/lib/config/utils.js +160 -0
  26. package/lib/format/format.d.ts +1 -1
  27. package/lib/format/format.js +28 -0
  28. package/lib/index.d.ts +1 -2
  29. package/lib/index.js +5 -6
  30. package/lib/lint.d.ts +1 -1
  31. package/lib/lint.js +5 -7
  32. package/lib/redocly/index.d.ts +1 -1
  33. package/lib/redocly/redocly-client-types.d.ts +1 -1
  34. package/lib/redocly/registry-api.d.ts +1 -1
  35. package/lib/resolve.d.ts +1 -1
  36. package/lib/resolve.js +1 -2
  37. package/lib/rules/common/assertions/utils.d.ts +1 -1
  38. package/lib/rules/common/assertions/utils.js +6 -2
  39. package/lib/utils.d.ts +4 -1
  40. package/lib/utils.js +18 -1
  41. package/package.json +5 -2
  42. package/src/__tests__/lint.test.ts +1 -1
  43. package/src/benchmark/benches/recommended-oas3.bench.ts +2 -3
  44. package/src/benchmark/utils.ts +13 -8
  45. package/src/bundle.ts +2 -1
  46. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +140 -0
  47. package/src/config/__tests__/config-resolvers.test.ts +398 -0
  48. package/src/config/__tests__/config.test.ts +17 -29
  49. package/src/config/__tests__/fixtures/plugin.js +1 -1
  50. package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +7 -0
  51. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +67 -0
  52. package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +8 -0
  53. package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +12 -0
  54. package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +10 -0
  55. package/src/config/__tests__/fixtures/resolve-config/plugin.js +66 -0
  56. package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +4 -0
  57. package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +5 -0
  58. package/src/config/__tests__/load.test.ts +8 -1
  59. package/src/config/all.ts +3 -2
  60. package/src/config/builtIn.ts +2 -1
  61. package/src/config/config-resolvers.ts +304 -0
  62. package/src/config/config.ts +40 -457
  63. package/src/config/index.ts +7 -0
  64. package/src/config/load.ts +37 -31
  65. package/src/config/minimal.ts +2 -2
  66. package/src/config/recommended.ts +2 -2
  67. package/src/config/types.ts +168 -0
  68. package/src/config/utils.ts +208 -0
  69. package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
  70. package/src/format/format.ts +36 -6
  71. package/src/index.ts +6 -2
  72. package/src/lint.ts +4 -5
  73. package/src/redocly/__tests__/redocly-client.test.ts +7 -0
  74. package/src/redocly/index.ts +3 -1
  75. package/src/redocly/redocly-client-types.ts +1 -1
  76. package/src/redocly/registry-api.ts +3 -1
  77. package/src/resolve.ts +2 -4
  78. package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
  79. package/src/rules/common/__tests__/info-description.test.ts +3 -3
  80. package/src/rules/common/__tests__/info-license.test.ts +2 -2
  81. package/src/rules/common/__tests__/license-url.test.ts +2 -2
  82. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
  83. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +5 -5
  84. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
  85. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
  86. package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
  87. package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
  88. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
  89. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
  90. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
  91. package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
  92. package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
  93. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
  94. package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
  95. package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
  96. package/src/rules/common/__tests__/paths-kebab-case.test.ts +3 -3
  97. package/src/rules/common/__tests__/spec.test.ts +1 -1
  98. package/src/rules/common/__tests__/tag-description.test.ts +2 -2
  99. package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
  100. package/src/rules/common/assertions/utils.ts +5 -2
  101. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  102. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +1 -1
  103. package/src/rules/oas2/__tests__/spec/utils.ts +10 -7
  104. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  105. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +6 -6
  106. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
  107. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +8 -8
  108. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
  109. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  110. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
  111. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +23 -14
  112. package/src/rules/oas3/__tests__/spec/spec.test.ts +4 -4
  113. package/src/rules/oas3/__tests__/spec/utils.ts +10 -7
  114. package/src/utils.ts +18 -2
  115. package/tsconfig.tsbuildinfo +1 -1
@@ -1,16 +1,16 @@
1
- import { Config, getMergedConfig } from '../config';
1
+ import { Config } from '../config';
2
+ import { getMergedConfig } from '../utils';
2
3
 
3
4
  const testConfig: Config = {
4
5
  rawConfig: {
5
6
  apis: {
6
7
  'test@v1': {
7
8
  root: 'resources/pets.yaml',
8
- lint: { extends: [], rules: { 'operation-summary': 'warn' } },
9
+ lint: { rules: { 'operation-summary': 'warn' } },
9
10
  },
10
11
  },
11
12
  organization: 'redocly-test',
12
13
  lint: {
13
- extends: [],
14
14
  rules: { 'operation-summary': 'error', 'no-empty-servers': 'error' },
15
15
  plugins: [],
16
16
  },
@@ -19,13 +19,12 @@ const testConfig: Config = {
19
19
  apis: {
20
20
  'test@v1': {
21
21
  root: 'resources/pets.yaml',
22
- lint: { extends: [], rules: { 'operation-summary': 'warn' } },
22
+ lint: { rules: { 'operation-summary': 'warn' } },
23
23
  },
24
24
  },
25
25
  // @ts-ignore
26
26
  lint: {
27
27
  rawConfig: {
28
- extends: [],
29
28
  rules: { 'operation-summary': 'error', 'no-empty-servers': 'error' },
30
29
  plugins: [],
31
30
  },
@@ -51,13 +50,12 @@ const testConfig: Config = {
51
50
  };
52
51
 
53
52
  describe('getMergedConfig', () => {
54
- it('should merge lint defined in "apis" section the root one', () => {
53
+ it('should get lint defined in "apis" section', () => {
55
54
  expect(getMergedConfig(testConfig, 'test@v1')).toMatchInlineSnapshot(`
56
55
  Config {
57
56
  "apis": Object {
58
57
  "test@v1": Object {
59
58
  "lint": Object {
60
- "extends": Array [],
61
59
  "rules": Object {
62
60
  "operation-summary": "warn",
63
61
  },
@@ -78,7 +76,9 @@ describe('getMergedConfig', () => {
78
76
  "oas3_1": Object {},
79
77
  },
80
78
  "doNotResolveExamples": false,
79
+ "extendPaths": Array [],
81
80
  "ignore": Object {},
81
+ "pluginPaths": Array [],
82
82
  "plugins": Array [],
83
83
  "preprocessors": Object {
84
84
  "oas2": Object {},
@@ -86,27 +86,21 @@ describe('getMergedConfig', () => {
86
86
  "oas3_1": Object {},
87
87
  },
88
88
  "rawConfig": Object {
89
- "decorators": Object {},
90
- "extends": Array [],
91
- "plugins": Array [],
92
- "preprocessors": Object {},
89
+ "extendPaths": Array [],
90
+ "pluginPaths": Array [],
93
91
  "rules": Object {
94
- "no-empty-servers": "error",
95
92
  "operation-summary": "warn",
96
93
  },
97
94
  },
98
95
  "recommendedFallback": false,
99
96
  "rules": Object {
100
97
  "oas2": Object {
101
- "no-empty-servers": "error",
102
98
  "operation-summary": "warn",
103
99
  },
104
100
  "oas3_0": Object {
105
- "no-empty-servers": "error",
106
101
  "operation-summary": "warn",
107
102
  },
108
103
  "oas3_1": Object {
109
- "no-empty-servers": "error",
110
104
  "operation-summary": "warn",
111
105
  },
112
106
  },
@@ -116,7 +110,6 @@ describe('getMergedConfig', () => {
116
110
  "apis": Object {
117
111
  "test@v1": Object {
118
112
  "lint": Object {
119
- "extends": Array [],
120
113
  "rules": Object {
121
114
  "operation-summary": "warn",
122
115
  },
@@ -127,12 +120,9 @@ describe('getMergedConfig', () => {
127
120
  "features.mockServer": Object {},
128
121
  "features.openapi": Object {},
129
122
  "lint": Object {
130
- "decorators": Object {},
131
- "extends": Array [],
132
- "plugins": Array [],
133
- "preprocessors": Object {},
123
+ "extendPaths": Array [],
124
+ "pluginPaths": Array [],
134
125
  "rules": Object {
135
- "no-empty-servers": "error",
136
126
  "operation-summary": "warn",
137
127
  },
138
128
  },
@@ -162,7 +152,6 @@ describe('getMergedConfig', () => {
162
152
  "apis": Object {
163
153
  "test@v1": Object {
164
154
  "lint": Object {
165
- "extends": Array [],
166
155
  "rules": Object {
167
156
  "operation-summary": "warn",
168
157
  },
@@ -183,7 +172,9 @@ describe('getMergedConfig', () => {
183
172
  "oas3_1": Object {},
184
173
  },
185
174
  "doNotResolveExamples": false,
175
+ "extendPaths": Array [],
186
176
  "ignore": Object {},
177
+ "pluginPaths": Array [],
187
178
  "plugins": Array [],
188
179
  "preprocessors": Object {
189
180
  "oas2": Object {},
@@ -191,10 +182,9 @@ describe('getMergedConfig', () => {
191
182
  "oas3_1": Object {},
192
183
  },
193
184
  "rawConfig": Object {
194
- "decorators": Object {},
195
- "extends": Array [],
185
+ "extendPaths": Array [],
186
+ "pluginPaths": Array [],
196
187
  "plugins": Array [],
197
- "preprocessors": Object {},
198
188
  "rules": Object {
199
189
  "no-empty-servers": "error",
200
190
  "operation-summary": "error",
@@ -221,7 +211,6 @@ describe('getMergedConfig', () => {
221
211
  "apis": Object {
222
212
  "test@v1": Object {
223
213
  "lint": Object {
224
- "extends": Array [],
225
214
  "rules": Object {
226
215
  "operation-summary": "warn",
227
216
  },
@@ -232,10 +221,9 @@ describe('getMergedConfig', () => {
232
221
  "features.mockServer": Object {},
233
222
  "features.openapi": Object {},
234
223
  "lint": Object {
235
- "decorators": Object {},
236
- "extends": Array [],
224
+ "extendPaths": Array [],
225
+ "pluginPaths": Array [],
237
226
  "plugins": Array [],
238
- "preprocessors": Object {},
239
227
  "rules": Object {
240
228
  "no-empty-servers": "error",
241
229
  "operation-summary": "error",
@@ -21,7 +21,7 @@ const rules = {
21
21
  return {
22
22
  SecurityScheme(scheme, { location, report }) {
23
23
  if (scheme.type === 'openIdConnect') {
24
- if (!scheme.openIdConnectUrl?.endsWith('/.well-known/openid-configuration')) {
24
+ if (!scheme.openIdConnectUrl.endsWith('/.well-known/openid-configuration')) {
25
25
  report({
26
26
  message:
27
27
  'openIdConnectUrl must be a URL that ends with /.well-known/openid-configuration',
@@ -0,0 +1,7 @@
1
+ lint:
2
+ plugins:
3
+ - plugin.js
4
+ rules:
5
+ operation-2xx-response: error
6
+ extends:
7
+ - test-plugin-nested/all
@@ -0,0 +1,67 @@
1
+ const id = 'test-plugin-nested';
2
+
3
+ /** @type {import('../../config').PreprocessorsConfig} */
4
+ const preprocessors = {
5
+ oas2: {
6
+ 'description-preprocessor': () => {
7
+ return {
8
+ Info(info) {
9
+ const title = info.title || 'API title';
10
+ info.description = `# ${title}\n\n${info.description || ''}`;
11
+ },
12
+ };
13
+ },
14
+ },
15
+ };
16
+
17
+ /** @type {import('../../config').CustomRulesConfig} */
18
+ const rules = {
19
+ oas3: {
20
+ 'openid-connect-url-well-known': () => {
21
+ return {
22
+ SecurityScheme(scheme, { location, report }) {
23
+ if (scheme.type === 'openIdConnect') {
24
+ if (scheme.openIdConnectUrl && !scheme.openIdConnectUrl.endsWith('/.well-known/openid-configuration')) {
25
+ report({
26
+ message:
27
+ 'openIdConnectUrl must be a URL that ends with /.well-known/openid-configuration',
28
+ location: location.child('openIdConnectUrl'),
29
+ });
30
+ }
31
+ }
32
+ },
33
+ };
34
+ },
35
+ },
36
+ };
37
+
38
+ /** @type {import('../../config').DecoratorsConfig} */
39
+ const decorators = {
40
+ oas3: {
41
+ 'inject-x-stats': () => {
42
+ return {
43
+ Info(info) {
44
+ info['x-stats'] = { test: 1 };
45
+ },
46
+ };
47
+ },
48
+ },
49
+ };
50
+
51
+ const configs = {
52
+ all: {
53
+ rules: {
54
+ 'local/operation-id-not-test': 'error',
55
+ 'boolean-parameter-prefixes': 'error',
56
+ },
57
+ },
58
+ };
59
+
60
+
61
+ module.exports = {
62
+ id,
63
+ preprocessors,
64
+ rules,
65
+ decorators,
66
+ configs,
67
+ };
@@ -0,0 +1,8 @@
1
+ lint:
2
+ extends:
3
+ - local-config-with-circular.yaml
4
+ rules:
5
+ no-invalid-media-type-examples: error
6
+ operation-description: error
7
+ path-http-verbs-order: error
8
+ operation-2xx-response: off
@@ -0,0 +1,12 @@
1
+ lint:
2
+ rules:
3
+ no-invalid-media-type-examples: warn
4
+ operation-4xx-response: off
5
+ plugins:
6
+ - plugin.js
7
+ - api/plugin.js
8
+ extends:
9
+ - recommended
10
+ - api/nested-config.yaml
11
+ - test-plugin-nested/all
12
+ - test-plugin/all
@@ -0,0 +1,10 @@
1
+ lint:
2
+ plugins:
3
+ - plugin.js
4
+ extends:
5
+ - test-plugin/all
6
+ rules:
7
+ no-invalid-media-type-examples: error
8
+ operation-description: error
9
+ path-http-verbs-order: error
10
+ operation-2xx-response: off
@@ -0,0 +1,66 @@
1
+ const id = 'test-plugin';
2
+
3
+ /** @type {import('../../config').PreprocessorsConfig} */
4
+ const preprocessors = {
5
+ oas2: {
6
+ 'description-preprocessor': () => {
7
+ return {
8
+ Info(info) {
9
+ const title = info.title || 'API title';
10
+ info.description = `# ${title}\n\n${info.description || ''}`;
11
+ },
12
+ };
13
+ },
14
+ },
15
+ };
16
+
17
+ /** @type {import('../../config').CustomRulesConfig} */
18
+ const rules = {
19
+ oas3: {
20
+ 'openid-connect-url-well-known': () => {
21
+ return {
22
+ SecurityScheme(scheme, { location, report }) {
23
+ if (scheme.type === 'openIdConnect') {
24
+ if (scheme.openIdConnectUrl && !scheme.openIdConnectUrl.endsWith('/.well-known/openid-configuration')) {
25
+ report({
26
+ message:
27
+ 'openIdConnectUrl must be a URL that ends with /.well-known/openid-configuration',
28
+ location: location.child('openIdConnectUrl'),
29
+ });
30
+ }
31
+ }
32
+ },
33
+ };
34
+ },
35
+ },
36
+ };
37
+
38
+ /** @type {import('../../config').DecoratorsConfig} */
39
+ const decorators = {
40
+ oas3: {
41
+ 'inject-x-stats': () => {
42
+ return {
43
+ Info(info) {
44
+ info['x-stats'] = { test: 1 };
45
+ },
46
+ };
47
+ },
48
+ },
49
+ };
50
+
51
+ const configs = {
52
+ all: {
53
+ rules: {
54
+ 'local/operation-id-not-test': 'error',
55
+ 'boolean-parameter-prefixes': 'error',
56
+ },
57
+ },
58
+ };
59
+
60
+ module.exports = {
61
+ id,
62
+ preprocessors,
63
+ rules,
64
+ decorators,
65
+ configs,
66
+ };
@@ -0,0 +1,4 @@
1
+ lint:
2
+ rules:
3
+ operation-2xx-response: off
4
+ operation-4xx-response: error
@@ -0,0 +1,5 @@
1
+ lint:
2
+ extends:
3
+ - nested-remote-config.yaml
4
+ rules:
5
+ operation-2xx-response: error
@@ -1,4 +1,4 @@
1
- import { loadConfig, findConfig } from '../load';
1
+ import { loadConfig, findConfig, getConfig } from '../load';
2
2
  import { RedoclyClient } from '../../redocly';
3
3
 
4
4
  const fs = require('fs');
@@ -74,3 +74,10 @@ describe('findConfig', () => {
74
74
  expect(configName).toStrictEqual('dir/redocly.yaml');
75
75
  });
76
76
  });
77
+
78
+ describe('getConfig', () => {
79
+ jest.spyOn(fs, 'hasOwnProperty').mockImplementation(() => false);
80
+ it('should return empty object if there is no configPath and config file is not found', () => {
81
+ expect(getConfig()).toEqual(Promise.resolve({}));
82
+ });
83
+ });
package/src/config/all.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { LintRawConfig } from './config';
1
+ import type { PluginLintConfig } from "./types";
2
+
2
3
 
3
4
  export default {
4
5
  rules: {
@@ -61,4 +62,4 @@ export default {
61
62
  'no-undefined-server-variable': 'error',
62
63
  'no-servers-empty-enum': 'error',
63
64
  },
64
- } as LintRawConfig;
65
+ } as PluginLintConfig;
@@ -1,7 +1,6 @@
1
1
  import recommended from './recommended';
2
2
  import all from './all';
3
3
  import minimal from './minimal';
4
- import { CustomRulesConfig, LintRawConfig, Plugin } from './config';
5
4
  import { rules as oas3Rules } from '../rules/oas3';
6
5
  import { rules as oas2Rules } from '../rules/oas2';
7
6
  import { preprocessors as oas3Preprocessors } from '../rules/oas3';
@@ -9,6 +8,8 @@ import { preprocessors as oas2Preprocessors } from '../rules/oas2';
9
8
  import { decorators as oas3Decorators } from '../decorators/oas3';
10
9
  import { decorators as oas2Decorators } from '../decorators/oas2';
11
10
 
11
+ import type { CustomRulesConfig, LintRawConfig, Plugin } from './types';
12
+
12
13
  export const builtInConfigs: Record<string, LintRawConfig> = {
13
14
  recommended,
14
15
  minimal,