@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.
Files changed (203) hide show
  1. package/README.md +4 -4
  2. package/__tests__/utils.ts +8 -6
  3. package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
  4. package/lib/benchmark/utils.d.ts +2 -2
  5. package/lib/benchmark/utils.js +2 -2
  6. package/lib/bundle.d.ts +2 -2
  7. package/lib/bundle.js +2 -2
  8. package/lib/config/all.d.ts +2 -2
  9. package/lib/config/all.js +1 -1
  10. package/lib/config/builtIn.d.ts +2 -2
  11. package/lib/config/builtIn.js +2 -2
  12. package/lib/config/config-resolvers.d.ts +5 -5
  13. package/lib/config/config-resolvers.js +39 -36
  14. package/lib/config/config.d.ts +6 -5
  15. package/lib/config/config.js +27 -20
  16. package/lib/config/load.js +6 -7
  17. package/lib/config/minimal.d.ts +2 -2
  18. package/lib/config/minimal.js +3 -2
  19. package/lib/config/recommended.d.ts +2 -2
  20. package/lib/config/recommended.js +3 -2
  21. package/lib/config/rules.d.ts +2 -2
  22. package/lib/config/rules.js +1 -1
  23. package/lib/config/types.d.ts +23 -19
  24. package/lib/config/utils.d.ts +5 -5
  25. package/lib/config/utils.js +43 -26
  26. package/lib/decorators/common/remove-x-internal.js +2 -2
  27. package/lib/format/format.js +1 -1
  28. package/lib/index.d.ts +2 -2
  29. package/lib/index.js +3 -2
  30. package/lib/js-yaml/index.js +1 -6
  31. package/lib/lint.d.ts +2 -2
  32. package/lib/lint.js +16 -6
  33. package/lib/redocly/registry-api.d.ts +1 -1
  34. package/lib/redocly/registry-api.js +2 -2
  35. package/lib/rules/ajv.d.ts +1 -1
  36. package/lib/rules/ajv.js +6 -6
  37. package/lib/rules/common/info-license-url.d.ts +1 -1
  38. package/lib/rules/common/info-license-url.js +5 -10
  39. package/lib/rules/common/info-license.d.ts +2 -0
  40. package/lib/rules/common/info-license.js +17 -0
  41. package/lib/rules/common/no-enum-type-mismatch.js +1 -3
  42. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  43. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  44. package/lib/rules/common/operation-operationId.js +1 -1
  45. package/lib/rules/common/path-not-include-query.js +1 -1
  46. package/lib/rules/common/paths-kebab-case.js +4 -1
  47. package/lib/rules/common/spec.js +1 -1
  48. package/lib/rules/oas2/index.js +4 -4
  49. package/lib/rules/oas2/remove-unused-components.js +3 -3
  50. package/lib/rules/oas3/index.js +4 -4
  51. package/lib/rules/oas3/no-empty-servers.js +1 -1
  52. package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
  53. package/lib/rules/oas3/remove-unused-components.js +2 -2
  54. package/lib/rules/other/stats.js +43 -14
  55. package/lib/rules/utils.d.ts +3 -2
  56. package/lib/rules/utils.js +19 -4
  57. package/lib/types/index.d.ts +2 -2
  58. package/lib/types/redocly-yaml.js +8 -7
  59. package/lib/utils.d.ts +5 -2
  60. package/lib/utils.js +20 -2
  61. package/lib/walk.d.ts +2 -1
  62. package/lib/walk.js +6 -3
  63. package/package.json +2 -2
  64. package/src/__tests__/__snapshots__/bundle.test.ts.snap +141 -0
  65. package/src/__tests__/bundle.test.ts +68 -34
  66. package/src/__tests__/codeframes.test.ts +13 -14
  67. package/src/__tests__/fixtures/.redocly.lint-ignore.yaml +5 -0
  68. package/src/__tests__/js-yaml.test.ts +6 -4
  69. package/src/__tests__/lint.test.ts +127 -12
  70. package/src/__tests__/login.test.ts +2 -2
  71. package/src/__tests__/normalizeVisitors.test.ts +4 -4
  72. package/src/__tests__/ref-utils.test.ts +13 -13
  73. package/src/__tests__/resolve-http.test.ts +1 -1
  74. package/src/__tests__/resolve.test.ts +14 -11
  75. package/src/__tests__/utils.test.ts +42 -1
  76. package/src/__tests__/walk.test.ts +48 -56
  77. package/src/benchmark/benches/lint-with-many-rules.bench.ts +1 -1
  78. package/src/benchmark/benches/lint-with-nested-rule.bench.ts +1 -1
  79. package/src/benchmark/benches/lint-with-no-rules.bench.ts +1 -1
  80. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +1 -1
  81. package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +1 -1
  82. package/src/benchmark/benches/recommended-oas3.bench.ts +3 -3
  83. package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
  84. package/src/benchmark/benchmark.js +9 -5
  85. package/src/benchmark/utils.ts +5 -5
  86. package/src/bundle.ts +18 -17
  87. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +3 -1
  88. package/src/config/__tests__/config-resolvers.test.ts +123 -121
  89. package/src/config/__tests__/config.test.ts +76 -76
  90. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +4 -2
  91. package/src/config/__tests__/fixtures/resolve-config/plugin.js +4 -1
  92. package/src/config/__tests__/load.test.ts +2 -2
  93. package/src/config/__tests__/resolve-plugins.test.ts +3 -3
  94. package/src/config/__tests__/utils.test.ts +83 -0
  95. package/src/config/all.ts +3 -4
  96. package/src/config/builtIn.ts +5 -5
  97. package/src/config/config-resolvers.ts +122 -83
  98. package/src/config/config.ts +36 -32
  99. package/src/config/load.ts +13 -16
  100. package/src/config/minimal.ts +5 -4
  101. package/src/config/recommended.ts +5 -4
  102. package/src/config/rules.ts +6 -6
  103. package/src/config/types.ts +28 -19
  104. package/src/config/utils.ts +74 -54
  105. package/src/decorators/__tests__/filter-out.test.ts +8 -4
  106. package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
  107. package/src/decorators/common/filters/filter-helper.ts +1 -1
  108. package/src/decorators/common/info-description-override.ts +1 -1
  109. package/src/decorators/common/operation-description-override.ts +1 -1
  110. package/src/decorators/common/remove-x-internal.ts +4 -4
  111. package/src/decorators/common/tag-description-override.ts +1 -1
  112. package/src/format/codeframes.ts +4 -4
  113. package/src/format/format.ts +10 -10
  114. package/src/index.ts +3 -4
  115. package/src/js-yaml/index.ts +3 -8
  116. package/src/lint.ts +22 -18
  117. package/src/oas-types.ts +1 -6
  118. package/src/redocly/__tests__/redocly-client.test.ts +25 -19
  119. package/src/redocly/index.ts +6 -4
  120. package/src/redocly/registry-api.ts +6 -6
  121. package/src/ref-utils.ts +2 -2
  122. package/src/resolve.ts +7 -4
  123. package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
  124. package/src/rules/__tests__/utils.test.ts +160 -0
  125. package/src/rules/ajv.ts +7 -8
  126. package/src/rules/common/__tests__/info-description.test.ts +3 -3
  127. package/src/rules/common/__tests__/info-license.test.ts +2 -2
  128. package/src/rules/common/__tests__/license-url.test.ts +2 -2
  129. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
  130. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +8 -8
  131. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
  132. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
  133. package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
  134. package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
  135. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
  136. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
  137. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
  138. package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
  139. package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
  140. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
  141. package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
  142. package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
  143. package/src/rules/common/__tests__/paths-kebab-case.test.ts +15 -15
  144. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
  145. package/src/rules/common/__tests__/spec.test.ts +2 -2
  146. package/src/rules/common/__tests__/tag-description.test.ts +2 -2
  147. package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
  148. package/src/rules/common/assertions/__tests__/asserts.test.ts +513 -130
  149. package/src/rules/common/assertions/index.ts +6 -6
  150. package/src/rules/common/info-license-url.ts +4 -9
  151. package/src/rules/common/info-license.ts +15 -0
  152. package/src/rules/common/no-ambiguous-paths.ts +1 -1
  153. package/src/rules/common/no-enum-type-mismatch.ts +12 -9
  154. package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
  155. package/src/rules/common/no-invalid-schema-examples.ts +4 -4
  156. package/src/rules/common/operation-operationId.ts +1 -1
  157. package/src/rules/common/operation-parameters-unique.ts +2 -2
  158. package/src/rules/common/path-not-include-query.ts +1 -1
  159. package/src/rules/common/path-params-defined.ts +1 -1
  160. package/src/rules/common/paths-kebab-case.ts +4 -1
  161. package/src/rules/common/scalar-property-missing-example.ts +1 -1
  162. package/src/rules/common/spec.ts +10 -7
  163. package/src/rules/no-unresolved-refs.ts +1 -1
  164. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  165. package/src/rules/oas2/__tests__/spec/info.test.ts +12 -12
  166. package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
  167. package/src/rules/oas2/__tests__/spec/paths.test.ts +10 -10
  168. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +6 -2
  169. package/src/rules/oas2/__tests__/spec/utils.ts +6 -6
  170. package/src/rules/oas2/index.ts +3 -3
  171. package/src/rules/oas2/remove-unused-components.ts +13 -8
  172. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  173. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
  174. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +13 -13
  175. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
  176. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  177. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
  178. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
  179. package/src/rules/oas3/__tests__/spec/info.test.ts +12 -12
  180. package/src/rules/oas3/__tests__/spec/operation.test.ts +8 -8
  181. package/src/rules/oas3/__tests__/spec/paths.test.ts +10 -10
  182. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +12 -12
  183. package/src/rules/oas3/__tests__/spec/servers.test.ts +15 -15
  184. package/src/rules/oas3/__tests__/spec/spec.test.ts +6 -6
  185. package/src/rules/oas3/__tests__/spec/utils.ts +6 -6
  186. package/src/rules/oas3/index.ts +3 -3
  187. package/src/rules/oas3/no-empty-servers.ts +1 -1
  188. package/src/rules/oas3/no-invalid-media-type-examples.ts +14 -6
  189. package/src/rules/oas3/no-servers-empty-enum.ts +9 -10
  190. package/src/rules/oas3/remove-unused-components.ts +18 -7
  191. package/src/rules/other/stats.ts +46 -17
  192. package/src/rules/utils.ts +19 -3
  193. package/src/types/index.ts +5 -5
  194. package/src/types/redocly-yaml.ts +8 -7
  195. package/src/typings/common.ts +9 -1
  196. package/src/typings/openapi.ts +1 -1
  197. package/src/utils.ts +31 -8
  198. package/src/visitors.ts +4 -4
  199. package/src/walk.ts +15 -11
  200. package/tsconfig.tsbuildinfo +1 -1
  201. package/lib/rules/common/license-url.d.ts +0 -2
  202. package/lib/rules/common/license-url.js +0 -12
  203. package/src/rules/common/license-url.ts +0 -10
@@ -24,7 +24,7 @@ describe('OpenAPI Schema', () => {
24
24
  expect(
25
25
  await validateDoc(source, {
26
26
  spec: 'error',
27
- }),
27
+ })
28
28
  ).toMatchInlineSnapshot(`Array []`);
29
29
  });
30
30
 
@@ -49,7 +49,7 @@ describe('OpenAPI Schema', () => {
49
49
  expect(
50
50
  await validateDoc(source, {
51
51
  spec: 'error',
52
- }),
52
+ })
53
53
  ).toMatchInlineSnapshot(`
54
54
  Array [
55
55
  Object {
@@ -81,7 +81,7 @@ describe('OpenAPI Schema', () => {
81
81
  expect(
82
82
  await validateDoc(source, {
83
83
  spec: 'error',
84
- }),
84
+ })
85
85
  ).toMatchInlineSnapshot(`
86
86
  Array [
87
87
  Object {
@@ -114,7 +114,7 @@ describe('OpenAPI Schema', () => {
114
114
  expect(
115
115
  await validateDoc(source, {
116
116
  spec: 'error',
117
- }),
117
+ })
118
118
  ).toMatchInlineSnapshot(`
119
119
  Array [
120
120
  Object {
@@ -146,7 +146,7 @@ describe('OpenAPI Schema', () => {
146
146
  expect(
147
147
  await validateDoc(source, {
148
148
  spec: 'error',
149
- }),
149
+ })
150
150
  ).toMatchInlineSnapshot(`Array []`);
151
151
  });
152
152
 
@@ -171,7 +171,7 @@ describe('OpenAPI Schema', () => {
171
171
  expect(
172
172
  await validateDoc(source, {
173
173
  spec: 'error',
174
- }),
174
+ })
175
175
  ).toMatchInlineSnapshot(`
176
176
  Array [
177
177
  Object {
@@ -208,7 +208,7 @@ describe('OpenAPI Schema', () => {
208
208
  expect(
209
209
  await validateDoc(source, {
210
210
  spec: 'error',
211
- }),
211
+ })
212
212
  ).toMatchInlineSnapshot(`Array []`);
213
213
  });
214
214
 
@@ -243,7 +243,7 @@ describe('OpenAPI Schema', () => {
243
243
  expect(
244
244
  await validateDoc(source, {
245
245
  spec: 'error',
246
- }),
246
+ })
247
247
  ).toMatchInlineSnapshot(`Array []`);
248
248
  });
249
249
 
@@ -277,7 +277,7 @@ describe('OpenAPI Schema', () => {
277
277
  expect(
278
278
  await validateDoc(source, {
279
279
  spec: 'error',
280
- }),
280
+ })
281
281
  ).toMatchInlineSnapshot(`
282
282
  Array [
283
283
  Object {
@@ -317,7 +317,7 @@ describe('OpenAPI Schema', () => {
317
317
  expect(
318
318
  await validateDoc(source, {
319
319
  'no-undefined-server-variable': 'error',
320
- }),
320
+ })
321
321
  ).toMatchInlineSnapshot(`
322
322
  Array [
323
323
  Object {
@@ -357,7 +357,7 @@ describe('OpenAPI Schema', () => {
357
357
  expect(
358
358
  await validateDoc(source, {
359
359
  spec: 'error',
360
- }),
360
+ })
361
361
  ).toMatchInlineSnapshot(`
362
362
  Array [
363
363
  Object {
@@ -403,7 +403,7 @@ describe('OpenAPI Schema', () => {
403
403
  expect(
404
404
  await validateDoc(source, {
405
405
  spec: 'error',
406
- }),
406
+ })
407
407
  ).toMatchInlineSnapshot(`
408
408
  Array [
409
409
  Object {
@@ -447,7 +447,7 @@ describe('OpenAPI Schema', () => {
447
447
  expect(
448
448
  await validateDoc(source, {
449
449
  spec: 'error',
450
- }),
450
+ })
451
451
  ).toMatchInlineSnapshot(`Array []`);
452
452
  });
453
453
 
@@ -469,7 +469,7 @@ describe('OpenAPI Schema', () => {
469
469
  expect(
470
470
  await validateDoc(source, {
471
471
  spec: 'error',
472
- }),
472
+ })
473
473
  ).toMatchInlineSnapshot(`Array []`);
474
474
  });
475
475
 
@@ -493,7 +493,7 @@ describe('OpenAPI Schema', () => {
493
493
  expect(
494
494
  await validateDoc(source, {
495
495
  spec: 'error',
496
- }),
496
+ })
497
497
  ).toMatchInlineSnapshot(`Array []`);
498
498
  });
499
499
  });
@@ -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, defaultPlugin, resolvePlugins, resolvePreset } from '../../../../config';
4
+ import { StyleguideConfig, defaultPlugin, resolvePlugins, resolvePreset } from '../../../../config';
5
5
 
6
6
  import { BaseResolver } from '../../../../resolve';
7
7
 
8
8
  const plugins = resolvePlugins([defaultPlugin]);
9
9
  const pressets = resolvePreset('all', plugins);
10
- const allConfig = new LintConfig({ ...pressets, plugins });
10
+ const allConfig = new StyleguideConfig({ ...pressets, plugins });
11
11
  describe('Oas3 Structural visitor basic', () => {
12
12
  it('should report wrong types', async () => {
13
13
  const document = parseYamlToDocument(
@@ -35,7 +35,7 @@ describe('Oas3 Structural visitor basic', () => {
35
35
  license: invalid
36
36
  paths: {}
37
37
  `,
38
- 'foobar.yaml',
38
+ 'foobar.yaml'
39
39
  );
40
40
 
41
41
  const results = await lintDocument({
@@ -110,7 +110,7 @@ describe('Oas3 Structural visitor basic', () => {
110
110
  "source": "foobar.yaml",
111
111
  },
112
112
  ],
113
- "message": "Expected type \`string\` but got \`number\`.",
113
+ "message": "Expected type \`string\` but got \`integer\`.",
114
114
  "ruleId": "spec",
115
115
  "severity": "error",
116
116
  "suggest": Array [],
@@ -163,7 +163,7 @@ describe('Oas3 Structural visitor basic', () => {
163
163
  x-test: vendor
164
164
  paths: {}
165
165
  `,
166
- 'foobar.yaml',
166
+ 'foobar.yaml'
167
167
  );
168
168
 
169
169
  const results = await lintDocument({
@@ -232,7 +232,7 @@ describe('Oas3 Structural visitor basic', () => {
232
232
  contact:
233
233
  name: string
234
234
  `,
235
- 'foobar.yaml',
235
+ 'foobar.yaml'
236
236
  );
237
237
 
238
238
  const results = await lintDocument({
@@ -1,25 +1,25 @@
1
- import { LintConfig, RuleConfig, resolveLint } from '../../../../config';
1
+ import { StyleguideConfig, RuleConfig, resolveStyleguideConfig } from '../../../../config';
2
2
  import { parseYamlToDocument } from '../../../../../__tests__/utils';
3
3
  import { lintDocument } from '../../../../lint';
4
4
  import { BaseResolver } from '../../../../resolve';
5
5
 
6
6
  export async function validateDoc(
7
7
  source: string,
8
- rules: Record<string, RuleConfig> = { spec: 'error' },
8
+ rules: Record<string, RuleConfig> = { spec: 'error' }
9
9
  ) {
10
10
  const document = parseYamlToDocument(source, 'foobar.yaml');
11
11
 
12
12
  const results = await lintDocument({
13
13
  externalRefResolver: new BaseResolver(),
14
14
  document,
15
- config: new LintConfig(
16
- await resolveLint({
17
- lintConfig: {
15
+ config: new StyleguideConfig(
16
+ await resolveStyleguideConfig({
17
+ styleguideConfig: {
18
18
  plugins: [],
19
19
  extends: [],
20
20
  rules,
21
21
  },
22
- }),
22
+ })
23
23
  ),
24
24
  });
25
25
 
@@ -18,13 +18,13 @@ import { NoServerTrailingSlash } from './no-server-trailing-slash';
18
18
  import { InfoDescription } from '../common/info-description';
19
19
  import { TagDescription } from '../common/tag-description';
20
20
  import { InfoContact } from '../common/info-contact';
21
- import { InfoLicense } from '../common/info-license-url';
21
+ import { InfoLicense } from '../common/info-license';
22
+ import { InfoLicenseUrl } from '../common/info-license-url';
22
23
  import { OperationDescription } from '../common/operation-description';
23
24
  import { NoUnusedComponents } from './no-unused-components';
24
25
  import { PathNotIncludeQuery } from '../common/path-not-include-query';
25
26
  import { ParameterDescription } from '../common/parameter-description';
26
27
  import { OperationSingularTag } from '../common/operation-singular-tag';
27
- import { InfoLicenseUrl } from '../common/license-url';
28
28
  import { OperationSecurityDefined } from '../common/operation-security-defined';
29
29
  import { NoUnresolvedRefs } from '../no-unresolved-refs';
30
30
  import { BooleanParameterPrefixes } from './boolean-parameter-prefixes';
@@ -57,7 +57,7 @@ export const rules = {
57
57
  'info-license-url': InfoLicenseUrl,
58
58
  'operation-2xx-response': Operation2xxResponse,
59
59
  'operation-4xx-response': Operation4xxResponse,
60
- 'assertions': Assertions,
60
+ assertions: Assertions,
61
61
  'operation-operationId-unique': OperationIdUnique,
62
62
  'operation-parameters-unique': OperationParametersUnique,
63
63
  'path-parameters-defined': PathParamsDefined,
@@ -6,7 +6,7 @@ export const NoEmptyServers: Oas3Rule = () => {
6
6
  if (!root.hasOwnProperty('servers')) {
7
7
  report({
8
8
  message: 'Servers must be present.',
9
- location: location.child(['openapi']).key()
9
+ location: location.child(['openapi']).key(),
10
10
  });
11
11
  return;
12
12
  }
@@ -1,11 +1,11 @@
1
1
  import { Oas3Rule } from '../../visitors';
2
2
  import { Location, isRef } from '../../ref-utils';
3
3
  import { Oas3Example } from '../../typings/openapi';
4
- import { validateExample } from '../utils';
4
+ import { getAdditionalPropertiesOption, validateExample } from '../utils';
5
5
  import { UserContext } from '../../walk';
6
6
 
7
7
  export const ValidContentExamples: Oas3Rule = (opts) => {
8
- const disallowAdditionalProperties = opts.disallowAdditionalProperties ?? true;
8
+ const allowAdditionalProperties = getAdditionalPropertiesOption(opts) ?? false;
9
9
 
10
10
  return {
11
11
  MediaType: {
@@ -13,14 +13,22 @@ export const ValidContentExamples: Oas3Rule = (opts) => {
13
13
  const { location, resolve } = ctx;
14
14
  if (!mediaType.schema) return;
15
15
  if (mediaType.example) {
16
- resolveAndValidateExample(mediaType.example, location.child('example'));
16
+ resolveAndValidateExample(mediaType.example, location.child('example'));
17
17
  } else if (mediaType.examples) {
18
18
  for (const exampleName of Object.keys(mediaType.examples)) {
19
- resolveAndValidateExample(mediaType.examples[exampleName], location.child(['examples', exampleName, 'value']), true);
19
+ resolveAndValidateExample(
20
+ mediaType.examples[exampleName],
21
+ location.child(['examples', exampleName, 'value']),
22
+ true
23
+ );
20
24
  }
21
25
  }
22
26
 
23
- function resolveAndValidateExample(example: Oas3Example | any, location: Location, isMultiple?: boolean) {
27
+ function resolveAndValidateExample(
28
+ example: Oas3Example | any,
29
+ location: Location,
30
+ isMultiple?: boolean
31
+ ) {
24
32
  if (isRef(example)) {
25
33
  const resolved = resolve<Oas3Example>(example);
26
34
  if (!resolved.location) return;
@@ -32,7 +40,7 @@ export const ValidContentExamples: Oas3Rule = (opts) => {
32
40
  mediaType.schema!,
33
41
  location,
34
42
  ctx,
35
- disallowAdditionalProperties,
43
+ allowAdditionalProperties
36
44
  );
37
45
  }
38
46
  },
@@ -25,16 +25,17 @@ export const NoEmptyEnumServers: Oas3Rule = () => {
25
25
  invalidVariables.push(...enumErrors);
26
26
  }
27
27
 
28
- for(const invalidVariable of invalidVariables) {
29
- if(invalidVariable === enumError.empty) {
28
+ for (const invalidVariable of invalidVariables) {
29
+ if (invalidVariable === enumError.empty) {
30
30
  report({
31
31
  message: 'Server variable with `enum` must be a non-empty array.',
32
32
  location: location.child(['servers']).key(),
33
33
  });
34
34
  }
35
- if(invalidVariable === enumError.invalidDefaultValue) {
35
+ if (invalidVariable === enumError.invalidDefaultValue) {
36
36
  report({
37
- message: 'Server variable define `enum` and `default`. `enum` must include default value',
37
+ message:
38
+ 'Server variable define `enum` and `default`. `enum` must include default value',
38
39
  location: location.child(['servers']).key(),
39
40
  });
40
41
  }
@@ -43,20 +44,18 @@ export const NoEmptyEnumServers: Oas3Rule = () => {
43
44
  };
44
45
  };
45
46
 
46
- function checkEnumVariables(server: Oas3Server): enumError[] | undefined{
47
- if (server.variables && Object.keys(server.variables).length === 0)
48
- return;
47
+ function checkEnumVariables(server: Oas3Server): enumError[] | undefined {
48
+ if (server.variables && Object.keys(server.variables).length === 0) return;
49
49
 
50
50
  const errors: enumError[] = [];
51
- for(var variable in server.variables) {
51
+ for (var variable in server.variables) {
52
52
  const serverVariable = server.variables[variable];
53
53
  if (!serverVariable.enum) continue;
54
54
 
55
55
  if (Array.isArray(serverVariable.enum) && serverVariable.enum?.length === 0)
56
56
  errors.push(enumError.empty);
57
57
 
58
- if (!serverVariable.default)
59
- continue;
58
+ if (!serverVariable.default) continue;
60
59
 
61
60
  const defaultValue = server.variables[variable].default;
62
61
  if (serverVariable.enum && !serverVariable.enum.includes(defaultValue))
@@ -1,12 +1,19 @@
1
1
  import { Oas3Rule } from '../../visitors';
2
2
  import { Location } from '../../ref-utils';
3
- import { Oas3Components } from '../../typings/openapi'
3
+ import { Oas3Components } from '../../typings/openapi';
4
4
  import { isEmptyObject } from '../../utils';
5
5
 
6
6
  export const RemoveUnusedComponents: Oas3Rule = () => {
7
- let components = new Map<string, { used: boolean; componentType?: keyof Oas3Components; name: string }>();
7
+ let components = new Map<
8
+ string,
9
+ { used: boolean; componentType?: keyof Oas3Components; name: string }
10
+ >();
8
11
 
9
- function registerComponent(location: Location, componentType: keyof Oas3Components, name: string): void {
12
+ function registerComponent(
13
+ location: Location,
14
+ componentType: keyof Oas3Components,
15
+ name: string
16
+ ): void {
10
17
  components.set(location.absolutePointer, {
11
18
  used: components.get(location.absolutePointer)?.used || false,
12
19
  componentType,
@@ -18,7 +25,9 @@ export const RemoveUnusedComponents: Oas3Rule = () => {
18
25
  ref: {
19
26
  leave(ref, { type, resolve, key }) {
20
27
  if (
21
- ['Schema', 'Header', 'Parameter', 'Response', 'Example', 'RequestBody'].includes(type.name)
28
+ ['Schema', 'Header', 'Parameter', 'Response', 'Example', 'RequestBody'].includes(
29
+ type.name
30
+ )
22
31
  ) {
23
32
  const resolvedRef = resolve(ref);
24
33
  if (!resolvedRef.location) return;
@@ -27,14 +36,14 @@ export const RemoveUnusedComponents: Oas3Rule = () => {
27
36
  name: key.toString(),
28
37
  });
29
38
  }
30
- }
39
+ },
31
40
  },
32
41
  DefinitionRoot: {
33
42
  leave(root, ctx) {
34
43
  const data = ctx.getVisitorData() as { removedCount: number };
35
44
  data.removedCount = 0;
36
45
 
37
- components.forEach(usageInfo => {
46
+ components.forEach((usageInfo) => {
38
47
  const { used, componentType, name } = usageInfo;
39
48
  if (!used && componentType) {
40
49
  let componentChild = root.components![componentType];
@@ -45,7 +54,9 @@ export const RemoveUnusedComponents: Oas3Rule = () => {
45
54
  }
46
55
  }
47
56
  });
48
- if (isEmptyObject(root.components)) { delete root.components; }
57
+ if (isEmptyObject(root.components)) {
58
+ delete root.components;
59
+ }
49
60
  },
50
61
  },
51
62
  NamedSchemas: {
@@ -4,10 +4,26 @@ import { StatsAccumulator } from '../../typings/common';
4
4
 
5
5
  export const Stats = (statsAccumulator: StatsAccumulator) => {
6
6
  return {
7
- ExternalDocs: { leave() { statsAccumulator.externalDocs.total++; }},
8
- ref: { enter(ref: OasRef) { statsAccumulator.refs.items!.add(ref['$ref']); }},
9
- Tag: { leave(tag: Oas3Tag) { statsAccumulator.tags.items!.add(tag.name); }},
10
- Link: { leave(link: any) { statsAccumulator.links.items!.add(link.operationId); }},
7
+ ExternalDocs: {
8
+ leave() {
9
+ statsAccumulator.externalDocs.total++;
10
+ },
11
+ },
12
+ ref: {
13
+ enter(ref: OasRef) {
14
+ statsAccumulator.refs.items!.add(ref['$ref']);
15
+ },
16
+ },
17
+ Tag: {
18
+ leave(tag: Oas3Tag) {
19
+ statsAccumulator.tags.items!.add(tag.name);
20
+ },
21
+ },
22
+ Link: {
23
+ leave(link: any) {
24
+ statsAccumulator.links.items!.add(link.operationId);
25
+ },
26
+ },
11
27
  DefinitionRoot: {
12
28
  leave() {
13
29
  statsAccumulator.parameters.total = statsAccumulator.parameters.items!.size;
@@ -19,26 +35,39 @@ export const Stats = (statsAccumulator: StatsAccumulator) => {
19
35
  WebhooksMap: {
20
36
  Operation: {
21
37
  leave(operation: any) {
22
- operation.tags.forEach((tag: string) => { statsAccumulator.tags.items!.add(tag); })
23
- }
24
- }
38
+ operation.tags.forEach((tag: string) => {
39
+ statsAccumulator.tags.items!.add(tag);
40
+ });
41
+ },
42
+ },
25
43
  },
26
44
  PathMap: {
27
45
  PathItem: {
28
- leave() { statsAccumulator.pathItems.total++; },
46
+ leave() {
47
+ statsAccumulator.pathItems.total++;
48
+ },
29
49
  Operation: {
30
50
  leave(operation: any) {
31
51
  statsAccumulator.operations.total++;
32
- operation.tags && operation.tags.forEach((tag: string) => { statsAccumulator.tags.items!.add(tag); })
33
- }
52
+ operation.tags &&
53
+ operation.tags.forEach((tag: string) => {
54
+ statsAccumulator.tags.items!.add(tag);
55
+ });
56
+ },
57
+ },
58
+ Parameter: {
59
+ leave(parameter: Oas2Parameter | Oas3Parameter) {
60
+ statsAccumulator.parameters.items!.add(parameter.name);
61
+ },
34
62
  },
35
- Parameter: { leave(parameter: Oas2Parameter | Oas3Parameter) {
36
- statsAccumulator.parameters.items!.add(parameter.name)
37
- }},
38
63
  },
39
64
  },
40
65
  NamedSchemas: {
41
- Schema: { leave() { statsAccumulator.schemas.total++; }}
42
- }
43
- }
44
- }
66
+ Schema: {
67
+ leave() {
68
+ statsAccumulator.schemas.total++;
69
+ },
70
+ },
71
+ },
72
+ };
73
+ };
@@ -3,12 +3,15 @@ import { UserContext } from '../walk';
3
3
  import { Location } from '../ref-utils';
4
4
  import { validateJsonSchema } from './ajv';
5
5
  import { Oas3Schema, Referenced } from '../typings/openapi';
6
+ import { showErrorForDeprecatedField, showWarningForDeprecatedField } from '../utils';
6
7
 
7
8
  export function oasTypeOf(value: unknown) {
8
9
  if (Array.isArray(value)) {
9
10
  return 'array';
10
11
  } else if (value === null) {
11
12
  return 'null';
13
+ } else if (Number.isInteger(value)) {
14
+ return 'integer';
12
15
  } else {
13
16
  return typeof value;
14
17
  }
@@ -23,7 +26,7 @@ export function oasTypeOf(value: unknown) {
23
26
  */
24
27
  export function matchesJsonSchemaType(value: unknown, type: string, nullable: boolean): boolean {
25
28
  if (nullable && value === null) {
26
- return value === null;
29
+ return true;
27
30
  }
28
31
 
29
32
  switch (type) {
@@ -89,7 +92,7 @@ export function validateExample(
89
92
  schema: Referenced<Oas3Schema>,
90
93
  dataLoc: Location,
91
94
  { resolve, location, report }: UserContext,
92
- disallowAdditionalProperties: boolean,
95
+ allowAdditionalProperties: boolean
93
96
  ) {
94
97
  try {
95
98
  const { valid, errors } = validateJsonSchema(
@@ -98,7 +101,7 @@ export function validateExample(
98
101
  location.child('schema'),
99
102
  dataLoc.pointer,
100
103
  resolve,
101
- disallowAdditionalProperties,
104
+ allowAdditionalProperties
102
105
  );
103
106
  if (!valid) {
104
107
  for (let error of errors) {
@@ -121,3 +124,16 @@ export function validateExample(
121
124
  });
122
125
  }
123
126
  }
127
+
128
+ export function getAdditionalPropertiesOption(opts: Record<string, any>): boolean {
129
+ if (opts.disallowAdditionalProperties === undefined) {
130
+ return opts.allowAdditionalProperties;
131
+ }
132
+
133
+ if (opts.allowAdditionalProperties !== undefined) {
134
+ showErrorForDeprecatedField('disallowAdditionalProperties', 'allowAdditionalProperties');
135
+ }
136
+
137
+ showWarningForDeprecatedField('disallowAdditionalProperties', 'allowAdditionalProperties');
138
+ return !opts.disallowAdditionalProperties;
139
+ }
@@ -24,7 +24,7 @@ export type NodeType = {
24
24
  items?: string;
25
25
  required?: string[] | ((value: any, key: string | number | undefined) => string[]);
26
26
  requiredOneOf?: string[];
27
- allowed?: ((value: any) => string[] | undefined);
27
+ allowed?: (value: any) => string[] | undefined;
28
28
  extensionsPrefix?: string;
29
29
  };
30
30
  type PropType = string | NodeType | ScalarSchema | undefined | null;
@@ -37,14 +37,14 @@ export type NormalizedNodeType = {
37
37
  items?: NormalizedNodeType;
38
38
  required?: string[] | ((value: any, key: string | number | undefined) => string[]);
39
39
  requiredOneOf?: string[];
40
- allowed?: ((value: any) => string[] | undefined);
40
+ allowed?: (value: any) => string[] | undefined;
41
41
  extensionsPrefix?: string;
42
42
  };
43
43
 
44
44
  type NormalizedPropType = NormalizedNodeType | NormalizedScalarSchema | undefined | null;
45
45
  type NormalizedResolveTypeFn = (
46
46
  value: any,
47
- key: string,
47
+ key: string
48
48
  ) => NormalizedNodeType | NormalizedScalarSchema | undefined | null;
49
49
 
50
50
  export function listOf(typeName: string) {
@@ -65,7 +65,7 @@ export function mapOf(typeName: string) {
65
65
 
66
66
  export function normalizeTypes(
67
67
  types: Record<string, NodeType>,
68
- options: { doNotResolveExamples?: boolean } = {},
68
+ options: { doNotResolveExamples?: boolean } = {}
69
69
  ): Record<string, NormalizedNodeType> {
70
70
  const normalizedTypes: Record<string, NormalizedNodeType> = {};
71
71
 
@@ -132,7 +132,7 @@ export function normalizeTypes(
132
132
  }
133
133
 
134
134
  export function isNamedType(
135
- t: NormalizedNodeType | NormalizedScalarSchema | null | undefined,
135
+ t: NormalizedNodeType | NormalizedScalarSchema | null | undefined
136
136
  ): t is NormalizedNodeType {
137
137
  return typeof t?.name === 'string';
138
138
  }
@@ -110,7 +110,8 @@ const ConfigRoot: NodeType = {
110
110
  properties: {},
111
111
  additionalProperties: { properties: { type: 'string' } },
112
112
  }, // deprecated
113
- lint: 'RootConfigLint',
113
+ styleguide: 'RootConfigStyleguide',
114
+ lint: 'RootConfigStyleguide', // deprecated
114
115
  'features.openapi': 'ConfigReferenceDocs',
115
116
  referenceDocs: 'ConfigReferenceDocs', // deprecated
116
117
  'features.mockServer': 'ConfigMockServer',
@@ -137,7 +138,7 @@ const ConfigApisProperties: NodeType = {
137
138
  type: 'string',
138
139
  },
139
140
  },
140
- lint: 'ConfigLint',
141
+ styleguide: 'ConfigStyleguide',
141
142
  'features.openapi': 'ConfigReferenceDocs',
142
143
  'features.mockServer': 'ConfigMockServer',
143
144
  },
@@ -155,7 +156,7 @@ const ConfigHTTP: NodeType = {
155
156
  },
156
157
  };
157
158
 
158
- const ConfigLint: NodeType = {
159
+ const ConfigStyleguide: NodeType = {
159
160
  properties: {
160
161
  extends: {
161
162
  type: 'array',
@@ -179,13 +180,13 @@ const ConfigLint: NodeType = {
179
180
  },
180
181
  };
181
182
 
182
- const RootConfigLint: NodeType = {
183
+ const RootConfigStyleguide: NodeType = {
183
184
  properties: {
184
185
  plugins: {
185
186
  type: 'array',
186
187
  items: { type: 'string' },
187
188
  },
188
- ...ConfigLint.properties,
189
+ ...ConfigStyleguide.properties,
189
190
  },
190
191
  };
191
192
 
@@ -877,8 +878,8 @@ export const ConfigTypes: Record<string, NodeType> = {
877
878
  ConfigRoot,
878
879
  ConfigApis,
879
880
  ConfigApisProperties,
880
- RootConfigLint,
881
- ConfigLint,
881
+ RootConfigStyleguide,
882
+ ConfigStyleguide,
882
883
  ConfigReferenceDocs,
883
884
  ConfigMockServer,
884
885
  ConfigHTTP,
@@ -5,5 +5,13 @@ export interface StatsRow {
5
5
  items?: Set<string>;
6
6
  }
7
7
 
8
- export type StatsName = 'operations' | 'refs' | 'tags' | 'externalDocs' | 'pathItems' | 'links' | 'schemas' | 'parameters';
8
+ export type StatsName =
9
+ | 'operations'
10
+ | 'refs'
11
+ | 'tags'
12
+ | 'externalDocs'
13
+ | 'pathItems'
14
+ | 'links'
15
+ | 'schemas'
16
+ | 'parameters';
9
17
  export type StatsAccumulator = Record<StatsName, StatsRow>;
@@ -156,7 +156,7 @@ export interface Oas3Schema {
156
156
  export type Oas3_1Schema = Oas3Schema & {
157
157
  type?: string | string[];
158
158
  examples?: any[];
159
- }
159
+ };
160
160
 
161
161
  export interface Oas3_1Definition extends Oas3Definition {
162
162
  webhooks?: Oas3_1Webhooks;