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

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 (123) hide show
  1. package/README.md +1 -1
  2. package/__tests__/bundle.test.ts +6 -6
  3. package/__tests__/fixtures/extension.js +1 -1
  4. package/__tests__/login.test.ts +2 -2
  5. package/__tests__/ref-utils.test.ts +1 -1
  6. package/__tests__/utils.ts +30 -18
  7. package/lib/benchmark/benches/recommended-oas3.bench.js +2 -3
  8. package/lib/benchmark/utils.d.ts +2 -1
  9. package/lib/benchmark/utils.js +10 -7
  10. package/lib/bundle.d.ts +2 -2
  11. package/lib/config/all.d.ts +2 -2
  12. package/lib/config/builtIn.d.ts +1 -1
  13. package/lib/config/config-resolvers.d.ts +16 -0
  14. package/lib/config/config-resolvers.js +242 -0
  15. package/lib/config/config.d.ts +18 -130
  16. package/lib/config/config.js +34 -245
  17. package/lib/config/index.d.ts +7 -0
  18. package/lib/config/index.js +19 -0
  19. package/lib/config/load.d.ts +2 -1
  20. package/lib/config/load.js +20 -13
  21. package/lib/config/minimal.d.ts +2 -2
  22. package/lib/config/recommended.d.ts +2 -2
  23. package/lib/config/types.d.ts +113 -0
  24. package/lib/config/types.js +2 -0
  25. package/lib/config/utils.d.ts +13 -0
  26. package/lib/config/utils.js +160 -0
  27. package/lib/format/format.d.ts +1 -1
  28. package/lib/format/format.js +30 -1
  29. package/lib/index.d.ts +1 -2
  30. package/lib/index.js +5 -6
  31. package/lib/lint.d.ts +1 -1
  32. package/lib/lint.js +5 -7
  33. package/lib/redocly/index.d.ts +1 -1
  34. package/lib/redocly/index.js +10 -26
  35. package/lib/redocly/redocly-client-types.d.ts +1 -1
  36. package/lib/redocly/registry-api-types.d.ts +1 -0
  37. package/lib/redocly/registry-api.d.ts +2 -2
  38. package/lib/redocly/registry-api.js +2 -1
  39. package/lib/resolve.d.ts +1 -1
  40. package/lib/resolve.js +1 -2
  41. package/lib/rules/common/assertions/index.js +1 -1
  42. package/lib/rules/common/assertions/utils.d.ts +1 -1
  43. package/lib/rules/common/assertions/utils.js +6 -2
  44. package/lib/utils.d.ts +4 -2
  45. package/lib/utils.js +20 -3
  46. package/package.json +9 -6
  47. package/src/__tests__/lint.test.ts +1 -1
  48. package/src/benchmark/benches/recommended-oas3.bench.ts +2 -3
  49. package/src/benchmark/benchmark.js +1 -1
  50. package/src/benchmark/utils.ts +13 -8
  51. package/src/bundle.ts +2 -1
  52. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +157 -0
  53. package/src/config/__tests__/config-resolvers.test.ts +429 -0
  54. package/src/config/__tests__/config.test.ts +17 -29
  55. package/src/config/__tests__/fixtures/plugin.js +1 -1
  56. package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +12 -0
  57. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +67 -0
  58. package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +8 -0
  59. package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +19 -0
  60. package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +10 -0
  61. package/src/config/__tests__/fixtures/resolve-config/plugin.js +66 -0
  62. package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +4 -0
  63. package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +5 -0
  64. package/src/config/__tests__/load.test.ts +8 -1
  65. package/src/config/all.ts +3 -2
  66. package/src/config/builtIn.ts +2 -1
  67. package/src/config/config-resolvers.ts +359 -0
  68. package/src/config/config.ts +60 -468
  69. package/src/config/index.ts +7 -0
  70. package/src/config/load.ts +37 -31
  71. package/src/config/minimal.ts +2 -2
  72. package/src/config/recommended.ts +2 -2
  73. package/src/config/types.ts +168 -0
  74. package/src/config/utils.ts +208 -0
  75. package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
  76. package/src/format/format.ts +38 -7
  77. package/src/index.ts +6 -2
  78. package/src/lint.ts +4 -5
  79. package/src/redocly/__tests__/redocly-client.test.ts +7 -0
  80. package/src/redocly/index.ts +14 -41
  81. package/src/redocly/redocly-client-types.ts +1 -1
  82. package/src/redocly/registry-api-types.ts +1 -0
  83. package/src/redocly/registry-api.ts +5 -1
  84. package/src/resolve.ts +2 -4
  85. package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
  86. package/src/rules/common/__tests__/info-description.test.ts +3 -3
  87. package/src/rules/common/__tests__/info-license.test.ts +2 -2
  88. package/src/rules/common/__tests__/license-url.test.ts +2 -2
  89. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
  90. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +5 -5
  91. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
  92. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
  93. package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
  94. package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
  95. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
  96. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
  97. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
  98. package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
  99. package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
  100. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
  101. package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
  102. package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
  103. package/src/rules/common/__tests__/paths-kebab-case.test.ts +3 -3
  104. package/src/rules/common/__tests__/spec.test.ts +1 -1
  105. package/src/rules/common/__tests__/tag-description.test.ts +2 -2
  106. package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
  107. package/src/rules/common/assertions/index.ts +1 -1
  108. package/src/rules/common/assertions/utils.ts +5 -2
  109. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  110. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +1 -1
  111. package/src/rules/oas2/__tests__/spec/utils.ts +10 -7
  112. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  113. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +6 -6
  114. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
  115. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +8 -8
  116. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
  117. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  118. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
  119. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +23 -14
  120. package/src/rules/oas3/__tests__/spec/spec.test.ts +4 -4
  121. package/src/rules/oas3/__tests__/spec/utils.ts +10 -7
  122. package/src/utils.ts +21 -4
  123. package/tsconfig.tsbuildinfo +1 -1
@@ -19,7 +19,7 @@ describe('Oas3 tag-description', () => {
19
19
  const results = await lintDocument({
20
20
  externalRefResolver: new BaseResolver(),
21
21
  document,
22
- config: makeConfig({ 'tag-description': 'error' }),
22
+ config: await makeConfig({ 'tag-description': 'error' }),
23
23
  });
24
24
 
25
25
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -57,7 +57,7 @@ describe('Oas3 tag-description', () => {
57
57
  const results = await lintDocument({
58
58
  externalRefResolver: new BaseResolver(),
59
59
  document,
60
- config: makeConfig({ 'tag-description': 'error' }),
60
+ config: await makeConfig({ 'tag-description': 'error' }),
61
61
  });
62
62
 
63
63
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -19,7 +19,7 @@ describe('Oas3 tags-alphabetical', () => {
19
19
  const results = await lintDocument({
20
20
  externalRefResolver: new BaseResolver(),
21
21
  document,
22
- config: makeConfig({ 'tags-alphabetical': 'error' }),
22
+ config: await makeConfig({ 'tags-alphabetical': 'error' }),
23
23
  });
24
24
 
25
25
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -56,7 +56,7 @@ describe('Oas3 tags-alphabetical', () => {
56
56
  const results = await lintDocument({
57
57
  externalRefResolver: new BaseResolver(),
58
58
  document,
59
- config: makeConfig({ 'tags-alphabetical': 'error' }),
59
+ config: await makeConfig({ 'tags-alphabetical': 'error' }),
60
60
  });
61
61
 
62
62
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -7,7 +7,7 @@ export const Assertions: Oas3Rule | Oas2Rule = (opts: object) => {
7
7
 
8
8
  // As 'Assertions' has an array of asserts,
9
9
  // that array spreads into an 'opts' object on init rules phase here
10
- // https://github.com/Redocly/openapi-cli/blob/master/packages/core/src/config/config.ts#L311
10
+ // https://github.com/Redocly/redocly-cli/blob/master/packages/core/src/config/config.ts#L311
11
11
  // that is why we need to iterate through 'opts' values;
12
12
  // before - filter only object 'opts' values
13
13
  const assertions: any[] = Object.values(opts).filter(
@@ -1,3 +1,4 @@
1
+ import { isRef } from '../../../ref-utils';
1
2
  import { Problem, ProblemSeverity, UserContext } from '../../../walk';
2
3
  import { asserts } from './asserts';
3
4
 
@@ -76,7 +77,7 @@ export function buildSubjectVisitor(
76
77
  asserts: AssertToApply[],
77
78
  context?: Record<string, any>[],
78
79
  ) {
79
- return function (node: any, { report, location, key, type }: UserContext) {
80
+ return function (node: any, { report, location, key, type, resolve }: UserContext) {
80
81
  // We need to check context's last node if it has the same type as subject node;
81
82
  // if yes - that means we didn't create context's last node visitor,
82
83
  // so we need to handle 'matchParentKeys' and 'excludeParentKeys' conditions here;
@@ -102,7 +103,9 @@ export function buildSubjectVisitor(
102
103
  for (const assert of asserts) {
103
104
  if (properties) {
104
105
  for (const property of properties) {
105
- runAssertion(node[property], assert, location.child(property), report);
106
+ // we can have resolvable scalar so need to resolve value here.
107
+ const value = isRef(node[property]) ? resolve(node[property])?.node : node[property];
108
+ runAssertion(value, assert, location.child(property), report);
106
109
  }
107
110
  } else {
108
111
  runAssertion(Object.keys(node), assert, location.key(), report);
@@ -21,7 +21,7 @@ describe('oas2 boolean-parameter-prefixes', () => {
21
21
  const results = await lintDocument({
22
22
  externalRefResolver: new BaseResolver(),
23
23
  document,
24
- config: makeConfig({ 'boolean-parameter-prefixes': 'error' }),
24
+ config: await makeConfig({ 'boolean-parameter-prefixes': 'error' }),
25
25
  });
26
26
 
27
27
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -73,7 +73,7 @@ describe('oas2 boolean-parameter-prefixes', () => {
73
73
  const results = await lintDocument({
74
74
  externalRefResolver: new BaseResolver(),
75
75
  document,
76
- config: makeConfig({ 'boolean-parameter-prefixes': 'error' }),
76
+ config: await makeConfig({ 'boolean-parameter-prefixes': 'error' }),
77
77
  });
78
78
 
79
79
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -97,7 +97,7 @@ describe('oas2 boolean-parameter-prefixes', () => {
97
97
  const results = await lintDocument({
98
98
  externalRefResolver: new BaseResolver(),
99
99
  document,
100
- config: makeConfig({
100
+ config: await makeConfig({
101
101
  'boolean-parameter-prefixes': {
102
102
  severity: 'error',
103
103
  prefixes: ['should'],
@@ -21,7 +21,7 @@ describe('Referenceable scalars', () => {
21
21
  const results = await lintDocument({
22
22
  externalRefResolver: new BaseResolver(),
23
23
  document,
24
- config: makeConfig({
24
+ config: await makeConfig({
25
25
  spec: 'error',
26
26
  }),
27
27
  });
@@ -1,8 +1,7 @@
1
- import { LintConfig, RuleConfig } from '../../../../config/config';
1
+ import { LintConfig, RuleConfig, resolveLint } from '../../../../config';
2
2
  import { parseYamlToDocument } from '../../../../../__tests__/utils';
3
3
  import { lintDocument } from '../../../../lint';
4
4
  import { BaseResolver } from '../../../../resolve';
5
- import { defaultPlugin } from '../../../../config/builtIn';
6
5
 
7
6
  export async function lintDoc(
8
7
  source: string,
@@ -13,11 +12,15 @@ export async function lintDoc(
13
12
  const results = await lintDocument({
14
13
  externalRefResolver: new BaseResolver(),
15
14
  document,
16
- config: new LintConfig({
17
- plugins: [defaultPlugin],
18
- extends: [],
19
- rules,
20
- }),
15
+ config: new LintConfig(
16
+ await resolveLint({
17
+ lintConfig: {
18
+ plugins: [],
19
+ extends: [],
20
+ rules,
21
+ },
22
+ }),
23
+ ),
21
24
  });
22
25
 
23
26
  return results.map((res) => {
@@ -22,7 +22,7 @@ describe('oas3 boolean-parameter-prefixes', () => {
22
22
  const results = await lintDocument({
23
23
  externalRefResolver: new BaseResolver(),
24
24
  document,
25
- config: makeConfig({ 'boolean-parameter-prefixes': 'error' }),
25
+ config: await makeConfig({ 'boolean-parameter-prefixes': 'error' }),
26
26
  });
27
27
 
28
28
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -74,7 +74,7 @@ describe('oas3 boolean-parameter-prefixes', () => {
74
74
  const results = await lintDocument({
75
75
  externalRefResolver: new BaseResolver(),
76
76
  document,
77
- config: makeConfig({ 'boolean-parameter-prefixes': 'error' }),
77
+ config: await makeConfig({ 'boolean-parameter-prefixes': 'error' }),
78
78
  });
79
79
 
80
80
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -98,7 +98,7 @@ describe('oas3 boolean-parameter-prefixes', () => {
98
98
  const results = await lintDocument({
99
99
  externalRefResolver: new BaseResolver(),
100
100
  document,
101
- config: makeConfig({
101
+ config: await makeConfig({
102
102
  'boolean-parameter-prefixes': {
103
103
  severity: 'error',
104
104
  prefixes: ['should'],
@@ -24,7 +24,7 @@ describe('Oas3 as3-no-servers-empty-enum', () => {
24
24
  const results = await lintDocument({
25
25
  externalRefResolver: new BaseResolver(),
26
26
  document,
27
- config: makeConfig({ 'no-servers-empty-enum': 'error' }),
27
+ config: await makeConfig({ 'no-servers-empty-enum': 'error' }),
28
28
  });
29
29
 
30
30
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -78,7 +78,7 @@ describe('Oas3 as3-no-servers-empty-enum', () => {
78
78
  const results = await lintDocument({
79
79
  externalRefResolver: new BaseResolver(),
80
80
  document,
81
- config: makeConfig({ 'no-servers-empty-enum': 'error' }),
81
+ config: await makeConfig({ 'no-servers-empty-enum': 'error' }),
82
82
  });
83
83
 
84
84
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -117,7 +117,7 @@ describe('Oas3 as3-no-servers-empty-enum', () => {
117
117
  const results = await lintDocument({
118
118
  externalRefResolver: new BaseResolver(),
119
119
  document,
120
- config: makeConfig({ 'no-servers-empty-enum': 'error' }),
120
+ config: await makeConfig({ 'no-servers-empty-enum': 'error' }),
121
121
  });
122
122
 
123
123
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -141,7 +141,7 @@ describe('Oas3 as3-no-servers-empty-enum', () => {
141
141
  const results = await lintDocument({
142
142
  externalRefResolver: new BaseResolver(),
143
143
  document,
144
- config: makeConfig({ 'no-servers-empty-enum': 'error' }),
144
+ config: await makeConfig({ 'no-servers-empty-enum': 'error' }),
145
145
  });
146
146
 
147
147
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -168,7 +168,7 @@ describe('Oas3 as3-no-servers-empty-enum', () => {
168
168
  const results = await lintDocument({
169
169
  externalRefResolver: new BaseResolver(),
170
170
  document,
171
- config: makeConfig({ 'no-servers-empty-enum': 'error' }),
171
+ config: await makeConfig({ 'no-servers-empty-enum': 'error' }),
172
172
  });
173
173
 
174
174
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -197,7 +197,7 @@ describe('Oas3 as3-no-servers-empty-enum', () => {
197
197
  const results = await lintDocument({
198
198
  externalRefResolver: new BaseResolver(),
199
199
  document,
200
- config: makeConfig({ 'no-servers-empty-enum': 'error' }),
200
+ config: await makeConfig({ 'no-servers-empty-enum': 'error' }),
201
201
  });
202
202
 
203
203
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -20,7 +20,7 @@ describe('Oas3 oas3-no-example-value-and-externalValue', () => {
20
20
  const results = await lintDocument({
21
21
  externalRefResolver: new BaseResolver(),
22
22
  document,
23
- config: makeConfig({ 'no-example-value-and-externalValue': 'error' }),
23
+ config: await makeConfig({ 'no-example-value-and-externalValue': 'error' }),
24
24
  });
25
25
 
26
26
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -57,7 +57,7 @@ describe('Oas3 oas3-no-example-value-and-externalValue', () => {
57
57
  const results = await lintDocument({
58
58
  externalRefResolver: new BaseResolver(),
59
59
  document,
60
- config: makeConfig({ 'no-example-value-and-externalValue': 'error' }),
60
+ config: await makeConfig({ 'no-example-value-and-externalValue': 'error' }),
61
61
  });
62
62
 
63
63
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -33,7 +33,7 @@ describe('no-invalid-media-type-examples', () => {
33
33
  const results = await lintDocument({
34
34
  externalRefResolver: new BaseResolver(),
35
35
  document,
36
- config: makeConfig({ 'no-invalid-media-type-examples': 'error' }),
36
+ config: await makeConfig({ 'no-invalid-media-type-examples': 'error' }),
37
37
  });
38
38
 
39
39
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -106,7 +106,7 @@ describe('no-invalid-media-type-examples', () => {
106
106
  const results = await lintDocument({
107
107
  externalRefResolver: new BaseResolver(),
108
108
  document,
109
- config: makeConfig({
109
+ config: await makeConfig({
110
110
  'no-invalid-media-type-examples': {
111
111
  severity: 'error',
112
112
  disallowAdditionalProperties: true,
@@ -166,7 +166,7 @@ describe('no-invalid-media-type-examples', () => {
166
166
  const results = await lintDocument({
167
167
  externalRefResolver: new BaseResolver(),
168
168
  document,
169
- config: makeConfig({
169
+ config: await makeConfig({
170
170
  'no-invalid-media-type-examples': {
171
171
  severity: 'error',
172
172
  disallowAdditionalProperties: true,
@@ -216,7 +216,7 @@ describe('no-invalid-media-type-examples', () => {
216
216
  const results = await lintDocument({
217
217
  externalRefResolver: new BaseResolver(),
218
218
  document,
219
- config: makeConfig({
219
+ config: await makeConfig({
220
220
  'no-invalid-media-type-examples': {
221
221
  severity: 'error',
222
222
  disallowAdditionalProperties: true,
@@ -269,7 +269,7 @@ describe('no-invalid-media-type-examples', () => {
269
269
  const results = await lintDocument({
270
270
  externalRefResolver: new BaseResolver(),
271
271
  document,
272
- config: makeConfig({ 'no-invalid-media-type-examples': 'error' }),
272
+ config: await makeConfig({ 'no-invalid-media-type-examples': 'error' }),
273
273
  });
274
274
 
275
275
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -301,7 +301,7 @@ describe('no-invalid-media-type-examples', () => {
301
301
  const results = await lintDocument({
302
302
  externalRefResolver: new BaseResolver(),
303
303
  document,
304
- config: makeConfig({ 'no-invalid-media-type-examples': 'error' }),
304
+ config: await makeConfig({ 'no-invalid-media-type-examples': 'error' }),
305
305
  });
306
306
 
307
307
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -336,7 +336,7 @@ describe('no-invalid-media-type-examples', () => {
336
336
  const results = await lintDocument({
337
337
  externalRefResolver: new BaseResolver(),
338
338
  document,
339
- config: makeConfig({ 'no-invalid-media-type-examples': 'error' }),
339
+ config: await makeConfig({ 'no-invalid-media-type-examples': 'error' }),
340
340
  });
341
341
 
342
342
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -364,7 +364,7 @@ describe('no-invalid-media-type-examples', () => {
364
364
  const results = await lintDocument({
365
365
  externalRefResolver: new BaseResolver(),
366
366
  document,
367
- config: makeConfig({ 'no-invalid-media-type-examples': 'error' }),
367
+ config: await makeConfig({ 'no-invalid-media-type-examples': 'error' }),
368
368
  });
369
369
 
370
370
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -17,7 +17,7 @@ describe('Oas3 oas3-no-server-example.com', () => {
17
17
  const results = await lintDocument({
18
18
  externalRefResolver: new BaseResolver(),
19
19
  document,
20
- config: makeConfig({ 'no-server-example.com': 'error' }),
20
+ config: await makeConfig({ 'no-server-example.com': 'error' }),
21
21
  });
22
22
 
23
23
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -52,7 +52,7 @@ describe('Oas3 oas3-no-server-example.com', () => {
52
52
  const results = await lintDocument({
53
53
  externalRefResolver: new BaseResolver(),
54
54
  document,
55
- config: makeConfig({ 'no-server-example.com': 'error' }),
55
+ config: await makeConfig({ 'no-server-example.com': 'error' }),
56
56
  });
57
57
 
58
58
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -17,7 +17,7 @@ describe('Oas3 oas3-no-server-trailing-slash', () => {
17
17
  const results = await lintDocument({
18
18
  externalRefResolver: new BaseResolver(),
19
19
  document,
20
- config: makeConfig({ 'no-server-trailing-slash': 'error' }),
20
+ config: await makeConfig({ 'no-server-trailing-slash': 'error' }),
21
21
  });
22
22
 
23
23
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -52,7 +52,7 @@ describe('Oas3 oas3-no-server-trailing-slash', () => {
52
52
  const results = await lintDocument({
53
53
  externalRefResolver: new BaseResolver(),
54
54
  document,
55
- config: makeConfig({ 'no-server-trailing-slash': 'error' }),
55
+ config: await makeConfig({ 'no-server-trailing-slash': 'error' }),
56
56
  });
57
57
 
58
58
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -71,7 +71,7 @@ describe('Oas3 oas3-no-server-trailing-slash', () => {
71
71
  const results = await lintDocument({
72
72
  externalRefResolver: new BaseResolver(),
73
73
  document,
74
- config: makeConfig({ 'no-server-trailing-slash': 'error' }),
74
+ config: await makeConfig({ 'no-server-trailing-slash': 'error' }),
75
75
  });
76
76
 
77
77
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -42,7 +42,7 @@ describe('Oas3 no-unused-components', () => {
42
42
  const results = await lintDocument({
43
43
  externalRefResolver: new BaseResolver(),
44
44
  document,
45
- config: makeConfig({ 'no-unused-components': 'error' }),
45
+ config: await makeConfig({ 'no-unused-components': 'error' }),
46
46
  });
47
47
 
48
48
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -3,6 +3,7 @@ import { parseYamlToDocument, replaceSourceWithRef } from '../../../../../__test
3
3
  import { lintDocument } from '../../../../lint';
4
4
  import { LintConfig } from '../../../..';
5
5
  import { BaseResolver } from '../../../../resolve';
6
+ import { resolveLint } from '../../../../config';
6
7
 
7
8
  describe('Referenceable scalars', () => {
8
9
  it('should not report $ref description', async () => {
@@ -22,13 +23,17 @@ describe('Referenceable scalars', () => {
22
23
  const results = await lintDocument({
23
24
  externalRefResolver: new BaseResolver(),
24
25
  document,
25
- config: new LintConfig({
26
- extends: [],
27
- rules: {
28
- spec: 'error',
29
- 'no-unresolved-refs': 'error',
30
- },
31
- }),
26
+ config: new LintConfig(
27
+ await resolveLint({
28
+ lintConfig: {
29
+ extends: [],
30
+ rules: {
31
+ spec: 'error',
32
+ 'no-unresolved-refs': 'error',
33
+ },
34
+ },
35
+ }),
36
+ ),
32
37
  });
33
38
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
34
39
  });
@@ -55,13 +60,17 @@ describe('Referenceable scalars', () => {
55
60
  const results = await lintDocument({
56
61
  externalRefResolver: new BaseResolver(),
57
62
  document,
58
- config: new LintConfig({
59
- extends: [],
60
- rules: {
61
- 'no-unresolved-refs': 'error',
62
- },
63
- doNotResolveExamples: true,
64
- }),
63
+ config: new LintConfig(
64
+ await resolveLint({
65
+ lintConfig: {
66
+ extends: [],
67
+ rules: {
68
+ 'no-unresolved-refs': 'error',
69
+ },
70
+ doNotResolveExamples: true,
71
+ },
72
+ }),
73
+ ),
65
74
  });
66
75
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
67
76
  });
@@ -1,13 +1,13 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../../lint';
3
3
  import { parseYamlToDocument, replaceSourceWithRef } from '../../../../../__tests__/utils';
4
- import { LintConfig } from '../../../../config/config';
5
- import { defaultPlugin } from '../../../../config/builtIn';
4
+ import { LintConfig, defaultPlugin, resolvePlugins, resolvePreset } from '../../../../config';
6
5
 
7
6
  import { BaseResolver } from '../../../../resolve';
8
7
 
9
- const allConfig = new LintConfig({ plugins: [defaultPlugin], extends: ['all'] });
10
-
8
+ const plugins = resolvePlugins([defaultPlugin]);
9
+ const pressets = resolvePreset('all', plugins);
10
+ const allConfig = new LintConfig({ ...pressets, plugins });
11
11
  describe('Oas3 Structural visitor basic', () => {
12
12
  it('should report wrong types', async () => {
13
13
  const document = parseYamlToDocument(
@@ -1,8 +1,7 @@
1
- import { LintConfig, RuleConfig } from '../../../../config/config';
1
+ import { LintConfig, RuleConfig, resolveLint } from '../../../../config';
2
2
  import { parseYamlToDocument } from '../../../../../__tests__/utils';
3
3
  import { lintDocument } from '../../../../lint';
4
4
  import { BaseResolver } from '../../../../resolve';
5
- import { defaultPlugin } from '../../../../config/builtIn';
6
5
 
7
6
  export async function validateDoc(
8
7
  source: string,
@@ -13,11 +12,15 @@ export async function validateDoc(
13
12
  const results = await lintDocument({
14
13
  externalRefResolver: new BaseResolver(),
15
14
  document,
16
- config: new LintConfig({
17
- plugins: [defaultPlugin],
18
- extends: [],
19
- rules,
20
- }),
15
+ config: new LintConfig(
16
+ await resolveLint({
17
+ lintConfig: {
18
+ plugins: [],
19
+ extends: [],
20
+ rules,
21
+ },
22
+ }),
23
+ ),
21
24
  });
22
25
 
23
26
  return results.map((res) => {
package/src/utils.ts CHANGED
@@ -2,10 +2,10 @@ import * as fs from 'fs';
2
2
  import * as minimatch from 'minimatch';
3
3
  import fetch from 'node-fetch';
4
4
  import * as pluralize from 'pluralize';
5
-
6
5
  import { parseYaml } from './js-yaml';
7
- import { HttpResolveConfig } from './config/config';
8
6
  import { UserContext } from './walk';
7
+ import type { HttpResolveConfig } from './config';
8
+ import { env } from "./config";
9
9
 
10
10
  export { parseYaml, stringifyYaml } from './js-yaml';
11
11
 
@@ -52,7 +52,7 @@ export async function readFileFromUrl(url: string, config: HttpResolveConfig) {
52
52
  for (const header of config.headers) {
53
53
  if (match(url, header.matches)) {
54
54
  headers[header.name] =
55
- header.envVariable !== undefined ? process.env[header.envVariable] || '' : header.value;
55
+ header.envVariable !== undefined ? env[header.envVariable] || '' : header.value;
56
56
  }
57
57
  }
58
58
 
@@ -67,7 +67,7 @@ export async function readFileFromUrl(url: string, config: HttpResolveConfig) {
67
67
  return { body: await req.text(), mimeType: req.headers.get('content-type') };
68
68
  }
69
69
 
70
- export function match(url: string, pattern: string) {
70
+ function match(url: string, pattern: string) {
71
71
  if (!pattern.match(/^https?:\/\//)) {
72
72
  // if pattern doesn't specify protocol directly, do not match against it
73
73
  url = url.replace(/^https?:\/\//, '');
@@ -171,3 +171,20 @@ export function isPathParameter(pathSegment: string) {
171
171
  export function isNotEmptyObject(obj: any) {
172
172
  return !!obj && Object.keys(obj).length > 0;
173
173
  }
174
+
175
+ // TODO: use it everywhere
176
+ export function isString(value: unknown): value is string {
177
+ return typeof value === 'string';
178
+ }
179
+
180
+ export function isNotString<T>(value: string | T): value is T {
181
+ return !isString(value);
182
+ }
183
+
184
+ export function assignExisting<T>(target: Record<string, T>, obj: Record<string, T>) {
185
+ for (let k of Object.keys(obj)) {
186
+ if (target.hasOwnProperty(k)) {
187
+ target[k] = obj[k];
188
+ }
189
+ }
190
+ }