@redocly/openapi-core 1.0.0-beta.105 → 1.0.0-beta.108

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 (240) hide show
  1. package/README.md +4 -4
  2. package/__tests__/utils.ts +5 -5
  3. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
  4. package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
  5. package/lib/benchmark/utils.d.ts +2 -2
  6. package/lib/benchmark/utils.js +2 -2
  7. package/lib/bundle.d.ts +2 -2
  8. package/lib/bundle.js +7 -4
  9. package/lib/config/all.d.ts +2 -2
  10. package/lib/config/all.js +3 -3
  11. package/lib/config/builtIn.d.ts +2 -2
  12. package/lib/config/builtIn.js +2 -2
  13. package/lib/config/config-resolvers.d.ts +5 -5
  14. package/lib/config/config-resolvers.js +70 -49
  15. package/lib/config/config.d.ts +8 -10
  16. package/lib/config/config.js +10 -7
  17. package/lib/config/load.d.ts +7 -0
  18. package/lib/config/load.js +18 -10
  19. package/lib/config/minimal.d.ts +2 -2
  20. package/lib/config/minimal.js +5 -4
  21. package/lib/config/recommended.d.ts +2 -2
  22. package/lib/config/recommended.js +5 -4
  23. package/lib/config/rules.d.ts +3 -3
  24. package/lib/config/rules.js +1 -1
  25. package/lib/config/types.d.ts +23 -19
  26. package/lib/config/utils.d.ts +5 -5
  27. package/lib/config/utils.js +48 -31
  28. package/lib/decorators/common/registry-dependencies.js +1 -1
  29. package/lib/decorators/common/remove-x-internal.js +2 -2
  30. package/lib/env.d.ts +3 -0
  31. package/lib/env.js +8 -0
  32. package/lib/format/codeframes.js +16 -10
  33. package/lib/format/format.js +29 -27
  34. package/lib/index.d.ts +5 -5
  35. package/lib/index.js +4 -2
  36. package/lib/js-yaml/index.js +2 -6
  37. package/lib/lint.d.ts +2 -2
  38. package/lib/lint.js +16 -6
  39. package/lib/logger.d.ts +10 -0
  40. package/lib/logger.js +31 -0
  41. package/lib/output.d.ts +3 -0
  42. package/lib/output.js +9 -0
  43. package/lib/redocly/index.js +10 -9
  44. package/lib/redocly/registry-api-types.d.ts +28 -30
  45. package/lib/redocly/registry-api.d.ts +4 -3
  46. package/lib/redocly/registry-api.js +9 -4
  47. package/lib/ref-utils.js +2 -1
  48. package/lib/resolve.d.ts +1 -1
  49. package/lib/resolve.js +1 -1
  50. package/lib/rules/ajv.d.ts +1 -1
  51. package/lib/rules/ajv.js +7 -7
  52. package/lib/rules/common/assertions/asserts.js +4 -4
  53. package/lib/rules/common/assertions/index.js +1 -1
  54. package/lib/rules/common/info-license-url.d.ts +1 -1
  55. package/lib/rules/common/info-license-url.js +5 -10
  56. package/lib/rules/common/info-license.d.ts +2 -0
  57. package/lib/rules/common/info-license.js +17 -0
  58. package/lib/rules/common/no-enum-type-mismatch.js +1 -3
  59. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  60. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  61. package/lib/rules/common/operation-operationId.js +1 -1
  62. package/lib/rules/common/operation-security-defined.js +1 -1
  63. package/lib/rules/common/path-not-include-query.js +1 -1
  64. package/lib/rules/common/paths-kebab-case.js +4 -1
  65. package/lib/rules/common/spec.js +3 -3
  66. package/lib/rules/oas2/index.js +4 -4
  67. package/lib/rules/oas2/remove-unused-components.js +5 -5
  68. package/lib/rules/oas3/index.js +6 -6
  69. package/lib/rules/oas3/no-empty-servers.js +1 -1
  70. package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
  71. package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
  72. package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +4 -4
  73. package/lib/rules/oas3/no-unused-components.js +1 -1
  74. package/lib/rules/oas3/remove-unused-components.js +5 -5
  75. package/lib/rules/other/stats.js +43 -14
  76. package/lib/rules/utils.d.ts +3 -2
  77. package/lib/rules/utils.js +20 -5
  78. package/lib/types/index.d.ts +2 -2
  79. package/lib/types/redocly-yaml.js +9 -8
  80. package/lib/utils.d.ts +5 -0
  81. package/lib/utils.js +22 -5
  82. package/lib/visitors.d.ts +1 -1
  83. package/lib/visitors.js +2 -2
  84. package/lib/walk.d.ts +2 -1
  85. package/lib/walk.js +6 -3
  86. package/package.json +2 -2
  87. package/src/__tests__/__snapshots__/bundle.test.ts.snap +141 -0
  88. package/src/__tests__/bundle.test.ts +68 -34
  89. package/src/__tests__/codeframes.test.ts +13 -14
  90. package/src/__tests__/js-yaml.test.ts +6 -4
  91. package/src/__tests__/lint.test.ts +74 -6
  92. package/src/__tests__/logger-browser.test.ts +53 -0
  93. package/src/__tests__/logger.test.ts +47 -0
  94. package/src/__tests__/login.test.ts +2 -2
  95. package/src/__tests__/normalizeVisitors.test.ts +4 -4
  96. package/src/__tests__/output-browser.test.ts +18 -0
  97. package/src/__tests__/output.test.ts +15 -0
  98. package/src/__tests__/ref-utils.test.ts +13 -13
  99. package/src/__tests__/resolve-http.test.ts +1 -1
  100. package/src/__tests__/resolve.test.ts +14 -11
  101. package/src/__tests__/utils-browser.test.ts +11 -0
  102. package/src/__tests__/utils.test.ts +7 -0
  103. package/src/__tests__/walk.test.ts +48 -56
  104. package/src/benchmark/benches/lint-with-many-rules.bench.ts +1 -1
  105. package/src/benchmark/benches/lint-with-nested-rule.bench.ts +1 -1
  106. package/src/benchmark/benches/lint-with-no-rules.bench.ts +1 -1
  107. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +1 -2
  108. package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +1 -1
  109. package/src/benchmark/benches/recommended-oas3.bench.ts +3 -3
  110. package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
  111. package/src/benchmark/benchmark.js +9 -5
  112. package/src/benchmark/utils.ts +5 -5
  113. package/src/bundle.ts +24 -20
  114. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +7 -5
  115. package/src/config/__tests__/config-resolvers.test.ts +123 -121
  116. package/src/config/__tests__/config.test.ts +111 -76
  117. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +4 -2
  118. package/src/config/__tests__/fixtures/resolve-config/plugin.js +4 -1
  119. package/src/config/__tests__/load.test.ts +79 -1
  120. package/src/config/__tests__/resolve-plugins.test.ts +3 -3
  121. package/src/config/__tests__/utils.test.ts +83 -0
  122. package/src/config/all.ts +5 -6
  123. package/src/config/builtIn.ts +5 -5
  124. package/src/config/config-resolvers.ts +161 -96
  125. package/src/config/config.ts +15 -13
  126. package/src/config/load.ts +34 -11
  127. package/src/config/minimal.ts +7 -6
  128. package/src/config/recommended.ts +7 -6
  129. package/src/config/rules.ts +6 -6
  130. package/src/config/types.ts +28 -19
  131. package/src/config/utils.ts +78 -57
  132. package/src/decorators/__tests__/filter-out.test.ts +8 -4
  133. package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
  134. package/src/decorators/common/filters/filter-helper.ts +1 -1
  135. package/src/decorators/common/info-description-override.ts +1 -1
  136. package/src/decorators/common/operation-description-override.ts +1 -1
  137. package/src/decorators/common/registry-dependencies.ts +1 -1
  138. package/src/decorators/common/remove-x-internal.ts +4 -4
  139. package/src/decorators/common/tag-description-override.ts +1 -1
  140. package/src/env.ts +5 -0
  141. package/src/format/codeframes.ts +18 -12
  142. package/src/format/format.ts +37 -42
  143. package/src/index.ts +8 -7
  144. package/src/js-yaml/index.ts +4 -8
  145. package/src/lint.ts +22 -18
  146. package/src/logger.ts +34 -0
  147. package/src/oas-types.ts +1 -6
  148. package/src/output.ts +7 -0
  149. package/src/redocly/__tests__/redocly-client.test.ts +25 -19
  150. package/src/redocly/index.ts +12 -7
  151. package/src/redocly/registry-api-types.ts +27 -29
  152. package/src/redocly/registry-api.ts +22 -12
  153. package/src/ref-utils.ts +4 -3
  154. package/src/resolve.ts +11 -8
  155. package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
  156. package/src/rules/__tests__/utils.test.ts +160 -0
  157. package/src/rules/ajv.ts +7 -8
  158. package/src/rules/common/__tests__/info-description.test.ts +3 -3
  159. package/src/rules/common/__tests__/info-license.test.ts +2 -2
  160. package/src/rules/common/__tests__/license-url.test.ts +2 -2
  161. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
  162. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +8 -8
  163. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
  164. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
  165. package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
  166. package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
  167. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
  168. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
  169. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
  170. package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
  171. package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
  172. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
  173. package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
  174. package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
  175. package/src/rules/common/__tests__/paths-kebab-case.test.ts +15 -15
  176. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
  177. package/src/rules/common/__tests__/spec.test.ts +2 -2
  178. package/src/rules/common/__tests__/tag-description.test.ts +2 -2
  179. package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
  180. package/src/rules/common/assertions/__tests__/asserts.test.ts +513 -130
  181. package/src/rules/common/assertions/asserts.ts +4 -4
  182. package/src/rules/common/assertions/index.ts +7 -7
  183. package/src/rules/common/info-license-url.ts +4 -9
  184. package/src/rules/common/info-license.ts +15 -0
  185. package/src/rules/common/no-ambiguous-paths.ts +1 -1
  186. package/src/rules/common/no-enum-type-mismatch.ts +12 -9
  187. package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
  188. package/src/rules/common/no-invalid-schema-examples.ts +4 -4
  189. package/src/rules/common/operation-operationId.ts +1 -1
  190. package/src/rules/common/operation-parameters-unique.ts +2 -2
  191. package/src/rules/common/operation-security-defined.ts +1 -1
  192. package/src/rules/common/path-not-include-query.ts +1 -1
  193. package/src/rules/common/path-params-defined.ts +1 -1
  194. package/src/rules/common/paths-kebab-case.ts +4 -1
  195. package/src/rules/common/scalar-property-missing-example.ts +1 -1
  196. package/src/rules/common/spec.ts +12 -9
  197. package/src/rules/no-unresolved-refs.ts +1 -1
  198. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  199. package/src/rules/oas2/__tests__/spec/info.test.ts +12 -12
  200. package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
  201. package/src/rules/oas2/__tests__/spec/paths.test.ts +10 -10
  202. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +6 -2
  203. package/src/rules/oas2/__tests__/spec/utils.ts +6 -6
  204. package/src/rules/oas2/index.ts +3 -3
  205. package/src/rules/oas2/remove-unused-components.ts +14 -9
  206. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  207. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
  208. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
  209. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +13 -13
  210. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
  211. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  212. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
  213. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
  214. package/src/rules/oas3/__tests__/spec/info.test.ts +12 -12
  215. package/src/rules/oas3/__tests__/spec/operation.test.ts +8 -8
  216. package/src/rules/oas3/__tests__/spec/paths.test.ts +10 -10
  217. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +12 -12
  218. package/src/rules/oas3/__tests__/spec/servers.test.ts +15 -15
  219. package/src/rules/oas3/__tests__/spec/spec.test.ts +6 -6
  220. package/src/rules/oas3/__tests__/spec/utils.ts +6 -6
  221. package/src/rules/oas3/index.ts +5 -5
  222. package/src/rules/oas3/no-empty-servers.ts +1 -1
  223. package/src/rules/oas3/no-invalid-media-type-examples.ts +14 -6
  224. package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +10 -11
  225. package/src/rules/oas3/no-unused-components.ts +1 -1
  226. package/src/rules/oas3/remove-unused-components.ts +21 -10
  227. package/src/rules/other/stats.ts +46 -17
  228. package/src/rules/utils.ts +20 -4
  229. package/src/types/index.ts +5 -5
  230. package/src/types/redocly-yaml.ts +9 -8
  231. package/src/typings/common.ts +9 -1
  232. package/src/typings/openapi.ts +1 -1
  233. package/src/utils.ts +26 -3
  234. package/src/visitors.ts +9 -9
  235. package/src/walk.ts +15 -11
  236. package/tsconfig.tsbuildinfo +1 -1
  237. package/lib/rules/common/license-url.d.ts +0 -2
  238. package/lib/rules/common/license-url.js +0 -12
  239. package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
  240. package/src/rules/common/license-url.ts +0 -10
package/lib/rules/ajv.js CHANGED
@@ -8,7 +8,7 @@ function releaseAjvInstance() {
8
8
  ajvInstance = null;
9
9
  }
10
10
  exports.releaseAjvInstance = releaseAjvInstance;
11
- function getAjv(resolve, disallowAdditionalProperties) {
11
+ function getAjv(resolve, allowAdditionalProperties) {
12
12
  if (!ajvInstance) {
13
13
  ajvInstance = new ajv_1.default({
14
14
  schemaId: '$id',
@@ -20,7 +20,7 @@ function getAjv(resolve, disallowAdditionalProperties) {
20
20
  discriminator: true,
21
21
  allowUnionTypes: true,
22
22
  validateFormats: false,
23
- defaultAdditionalProperties: !disallowAdditionalProperties,
23
+ defaultAdditionalProperties: allowAdditionalProperties,
24
24
  loadSchemaSync(base, $ref) {
25
25
  const resolvedRef = resolve({ $ref }, base.split('#')[0]);
26
26
  if (!resolvedRef || !resolvedRef.location)
@@ -32,15 +32,15 @@ function getAjv(resolve, disallowAdditionalProperties) {
32
32
  }
33
33
  return ajvInstance;
34
34
  }
35
- function getAjvValidator(schema, loc, resolve, disallowAdditionalProperties) {
36
- const ajv = getAjv(resolve, disallowAdditionalProperties);
35
+ function getAjvValidator(schema, loc, resolve, allowAdditionalProperties) {
36
+ const ajv = getAjv(resolve, allowAdditionalProperties);
37
37
  if (!ajv.getSchema(loc.absolutePointer)) {
38
38
  ajv.addSchema(Object.assign({ $id: loc.absolutePointer }, schema), loc.absolutePointer);
39
39
  }
40
40
  return ajv.getSchema(loc.absolutePointer);
41
41
  }
42
- function validateJsonSchema(data, schema, schemaLoc, instancePath, resolve, disallowAdditionalProperties) {
43
- const validate = getAjvValidator(schema, schemaLoc, resolve, disallowAdditionalProperties);
42
+ function validateJsonSchema(data, schema, schemaLoc, instancePath, resolve, allowAdditionalProperties) {
43
+ const validate = getAjvValidator(schema, schemaLoc, resolve, allowAdditionalProperties);
44
44
  if (!validate)
45
45
  return { valid: true, errors: [] }; // unresolved refs are reported
46
46
  const valid = validate(data, {
@@ -56,7 +56,7 @@ function validateJsonSchema(data, schema, schemaLoc, instancePath, resolve, disa
56
56
  };
57
57
  function beatifyErrorMessage(error) {
58
58
  let message = error.message;
59
- let suggest = error.keyword === 'enum' ? error.params.allowedValues : undefined;
59
+ const suggest = error.keyword === 'enum' ? error.params.allowedValues : undefined;
60
60
  if (suggest) {
61
61
  message += ` ${suggest.map((e) => `"${e}"`).join(', ')}`;
62
62
  }
@@ -35,7 +35,7 @@ exports.asserts = {
35
35
  return { isValid: true }; // property doesn't exist, no need to lint it with this assert
36
36
  const values = utils_1.isString(value) ? [value] : value;
37
37
  const regx = utils_2.regexFromString(condition);
38
- for (let _val of values) {
38
+ for (const _val of values) {
39
39
  if (!(regx === null || regx === void 0 ? void 0 : regx.test(_val))) {
40
40
  return { isValid: false, location: utils_1.isString(value) ? baseLocation : baseLocation.key() };
41
41
  }
@@ -46,7 +46,7 @@ exports.asserts = {
46
46
  if (typeof value === 'undefined')
47
47
  return { isValid: true }; // property doesn't exist, no need to lint it with this assert
48
48
  const values = utils_1.isString(value) ? [value] : value;
49
- for (let _val of values) {
49
+ for (const _val of values) {
50
50
  if (!condition.includes(_val)) {
51
51
  return {
52
52
  isValid: false,
@@ -72,7 +72,7 @@ exports.asserts = {
72
72
  if (typeof value === 'undefined')
73
73
  return { isValid: true }; // property doesn't exist, no need to lint it with this assert
74
74
  const values = utils_1.isString(value) ? [value] : value;
75
- for (let _val of values) {
75
+ for (const _val of values) {
76
76
  if (condition.includes(_val)) {
77
77
  return {
78
78
  isValid: false,
@@ -104,7 +104,7 @@ exports.asserts = {
104
104
  if (typeof value === 'undefined')
105
105
  return { isValid: true }; // property doesn't exist, no need to lint it with this assert
106
106
  const values = utils_1.isString(value) ? [value] : value;
107
- for (let _val of values) {
107
+ for (const _val of values) {
108
108
  let matchCase = false;
109
109
  switch (condition) {
110
110
  case 'camelCase':
@@ -4,7 +4,7 @@ exports.Assertions = void 0;
4
4
  const asserts_1 = require("./asserts");
5
5
  const utils_1 = require("./utils");
6
6
  const Assertions = (opts) => {
7
- let visitors = [];
7
+ const visitors = [];
8
8
  // As 'Assertions' has an array of asserts,
9
9
  // that array spreads into an 'opts' object on init rules phase here
10
10
  // https://github.com/Redocly/redocly-cli/blob/master/packages/core/src/config/config.ts#L311
@@ -1,2 +1,2 @@
1
1
  import { Oas3Rule, Oas2Rule } from '../../visitors';
2
- export declare const InfoLicense: Oas3Rule | Oas2Rule;
2
+ export declare const InfoLicenseUrl: Oas3Rule | Oas2Rule;
@@ -1,17 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InfoLicense = void 0;
3
+ exports.InfoLicenseUrl = void 0;
4
4
  const utils_1 = require("../utils");
5
- const InfoLicense = () => {
5
+ const InfoLicenseUrl = () => {
6
6
  return {
7
- Info(info, { report }) {
8
- if (!info.license) {
9
- report({
10
- message: utils_1.missingRequiredField('Info', 'license'),
11
- location: { reportOnKey: true }
12
- });
13
- }
7
+ License(license, ctx) {
8
+ utils_1.validateDefinedAndNonEmpty('url', license, ctx);
14
9
  },
15
10
  };
16
11
  };
17
- exports.InfoLicense = InfoLicense;
12
+ exports.InfoLicenseUrl = InfoLicenseUrl;
@@ -0,0 +1,2 @@
1
+ import { Oas3Rule, Oas2Rule } from '../../visitors';
2
+ export declare const InfoLicense: Oas3Rule | Oas2Rule;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InfoLicense = void 0;
4
+ const utils_1 = require("../utils");
5
+ const InfoLicense = () => {
6
+ return {
7
+ Info(info, { report }) {
8
+ if (!info.license) {
9
+ report({
10
+ message: utils_1.missingRequiredField('Info', 'license'),
11
+ location: { reportOnKey: true },
12
+ });
13
+ }
14
+ },
15
+ };
16
+ };
17
+ exports.InfoLicense = InfoLicense;
@@ -28,14 +28,12 @@ const NoEnumTypeMismatch = () => {
28
28
  if (mismatchedResults[enumValue].length !== schema.type.length)
29
29
  delete mismatchedResults[enumValue];
30
30
  }
31
- ;
32
31
  for (const mismatchedKey of Object.keys(mismatchedResults)) {
33
32
  report({
34
- message: `Enum value \`${mismatchedKey}\` must be of one type. Allowed types: \`${schema.type}\`.`,
33
+ message: `Enum value \`${mismatchedKey}\` must be of allowed types: \`${schema.type}\`.`,
35
34
  location: location.child(['enum', schema.enum.indexOf(mismatchedKey)]),
36
35
  });
37
36
  }
38
- ;
39
37
  }
40
38
  },
41
39
  };
@@ -4,17 +4,17 @@ exports.NoInvalidParameterExamples = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  const NoInvalidParameterExamples = (opts) => {
6
6
  var _a;
7
- const disallowAdditionalProperties = (_a = opts.disallowAdditionalProperties) !== null && _a !== void 0 ? _a : true;
7
+ const allowAdditionalProperties = (_a = utils_1.getAdditionalPropertiesOption(opts)) !== null && _a !== void 0 ? _a : false;
8
8
  return {
9
9
  Parameter: {
10
10
  leave(parameter, ctx) {
11
11
  if (parameter.example) {
12
- utils_1.validateExample(parameter.example, parameter.schema, ctx.location.child('example'), ctx, disallowAdditionalProperties);
12
+ utils_1.validateExample(parameter.example, parameter.schema, ctx.location.child('example'), ctx, allowAdditionalProperties);
13
13
  }
14
14
  if (parameter.examples) {
15
15
  for (const [key, example] of Object.entries(parameter.examples)) {
16
16
  if ('value' in example) {
17
- utils_1.validateExample(example.value, parameter.schema, ctx.location.child(['examples', key]), ctx, false);
17
+ utils_1.validateExample(example.value, parameter.schema, ctx.location.child(['examples', key]), ctx, true);
18
18
  }
19
19
  }
20
20
  }
@@ -4,17 +4,17 @@ exports.NoInvalidSchemaExamples = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  const NoInvalidSchemaExamples = (opts) => {
6
6
  var _a;
7
- const disallowAdditionalProperties = (_a = opts.disallowAdditionalProperties) !== null && _a !== void 0 ? _a : true;
7
+ const allowAdditionalProperties = (_a = utils_1.getAdditionalPropertiesOption(opts)) !== null && _a !== void 0 ? _a : false;
8
8
  return {
9
9
  Schema: {
10
10
  leave(schema, ctx) {
11
11
  if (schema.examples) {
12
12
  for (const example of schema.examples) {
13
- utils_1.validateExample(example, schema, ctx.location.child(['examples', schema.examples.indexOf(example)]), ctx, disallowAdditionalProperties);
13
+ utils_1.validateExample(example, schema, ctx.location.child(['examples', schema.examples.indexOf(example)]), ctx, allowAdditionalProperties);
14
14
  }
15
15
  }
16
16
  if (schema.example) {
17
- utils_1.validateExample(schema.example, schema, ctx.location.child('example'), ctx, false);
17
+ utils_1.validateExample(schema.example, schema, ctx.location.child('example'), ctx, true);
18
18
  }
19
19
  },
20
20
  },
@@ -10,7 +10,7 @@ const OperationOperationId = () => {
10
10
  utils_1.validateDefinedAndNonEmpty('operationId', operation, ctx);
11
11
  },
12
12
  },
13
- }
13
+ },
14
14
  };
15
15
  };
16
16
  exports.OperationOperationId = OperationOperationId;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OperationSecurityDefined = void 0;
4
4
  const OperationSecurityDefined = () => {
5
- let referencedSchemes = new Map();
5
+ const referencedSchemes = new Map();
6
6
  return {
7
7
  DefinitionRoot: {
8
8
  leave(_, { report }) {
@@ -12,7 +12,7 @@ const PathNotIncludeQuery = () => {
12
12
  });
13
13
  }
14
14
  },
15
- }
15
+ },
16
16
  };
17
17
  };
18
18
  exports.PathNotIncludeQuery = PathNotIncludeQuery;
@@ -4,7 +4,10 @@ exports.PathsKebabCase = void 0;
4
4
  const PathsKebabCase = () => {
5
5
  return {
6
6
  PathItem(_path, { report, key }) {
7
- const segments = key.substr(1).split('/').filter(s => s !== ''); // filter out empty segments
7
+ const segments = key
8
+ .substr(1)
9
+ .split('/')
10
+ .filter((s) => s !== ''); // filter out empty segments
8
11
  if (!segments.every((segment) => /^{.+}$/.test(segment) || /^[a-z0-9-.]+$/.test(segment))) {
9
12
  report({
10
13
  message: `\`${key}\` does not use kebab-case.`,
@@ -27,7 +27,7 @@ const OasSpec = () => {
27
27
  return;
28
28
  }
29
29
  const required = typeof type.required === 'function' ? type.required(node, key) : type.required;
30
- for (let propName of required || []) {
30
+ for (const propName of required || []) {
31
31
  if (!node.hasOwnProperty(propName)) {
32
32
  report({
33
33
  message: `The field \`${propName}\` must be present on this level.`,
@@ -45,14 +45,14 @@ const OasSpec = () => {
45
45
  }
46
46
  report({
47
47
  message: `The field \`${propName}\` is not allowed here.`,
48
- location: location.child([propName]).key()
48
+ location: location.child([propName]).key(),
49
49
  });
50
50
  }
51
51
  }
52
52
  const requiredOneOf = type.requiredOneOf || null;
53
53
  if (requiredOneOf) {
54
54
  let hasProperty = false;
55
- for (let propName of requiredOneOf || []) {
55
+ for (const propName of requiredOneOf || []) {
56
56
  if (node.hasOwnProperty(propName)) {
57
57
  hasProperty = true;
58
58
  }
@@ -6,8 +6,8 @@ const no_invalid_schema_examples_1 = require("../common/no-invalid-schema-exampl
6
6
  const no_invalid_parameter_examples_1 = require("../common/no-invalid-parameter-examples");
7
7
  const info_description_1 = require("../common/info-description");
8
8
  const info_contact_1 = require("../common/info-contact");
9
+ const info_license_1 = require("../common/info-license");
9
10
  const info_license_url_1 = require("../common/info-license-url");
10
- const license_url_1 = require("../common/license-url");
11
11
  const boolean_parameter_prefixes_1 = require("./boolean-parameter-prefixes");
12
12
  const tag_description_1 = require("../common/tag-description");
13
13
  const tags_alphabetical_1 = require("../common/tags-alphabetical");
@@ -48,8 +48,8 @@ exports.rules = {
48
48
  'no-invalid-parameter-examples': no_invalid_parameter_examples_1.NoInvalidParameterExamples,
49
49
  'info-description': info_description_1.InfoDescription,
50
50
  'info-contact': info_contact_1.InfoContact,
51
- 'info-license': info_license_url_1.InfoLicense,
52
- 'info-license-url': license_url_1.InfoLicenseUrl,
51
+ 'info-license': info_license_1.InfoLicense,
52
+ 'info-license-url': info_license_url_1.InfoLicenseUrl,
53
53
  'tag-description': tag_description_1.TagDescription,
54
54
  'tags-alphabetical': tags_alphabetical_1.TagsAlphabetical,
55
55
  'paths-kebab-case': paths_kebab_case_1.PathsKebabCase,
@@ -58,7 +58,7 @@ exports.rules = {
58
58
  'no-path-trailing-slash': no_path_trailing_slash_1.NoPathTrailingSlash,
59
59
  'operation-2xx-response': operation_2xx_response_1.Operation2xxResponse,
60
60
  'operation-4xx-response': operation_4xx_response_1.Operation4xxResponse,
61
- 'assertions': assertions_1.Assertions,
61
+ assertions: assertions_1.Assertions,
62
62
  'operation-operationId-unique': operation_operationId_unique_1.OperationIdUnique,
63
63
  'operation-parameters-unique': operation_parameters_unique_1.OperationParametersUnique,
64
64
  'path-parameters-defined': path_params_defined_1.PathParamsDefined,
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RemoveUnusedComponents = void 0;
4
4
  const utils_1 = require("../../utils");
5
5
  const RemoveUnusedComponents = () => {
6
- let components = new Map();
6
+ const components = new Map();
7
7
  function registerComponent(location, componentType, name) {
8
8
  var _a;
9
9
  components.set(location.absolutePointer, {
@@ -24,14 +24,14 @@ const RemoveUnusedComponents = () => {
24
24
  name: key.toString(),
25
25
  });
26
26
  }
27
- }
27
+ },
28
28
  },
29
29
  DefinitionRoot: {
30
30
  leave(root, ctx) {
31
31
  const data = ctx.getVisitorData();
32
32
  data.removedCount = 0;
33
- let rootComponents = new Set();
34
- components.forEach(usageInfo => {
33
+ const rootComponents = new Set();
34
+ components.forEach((usageInfo) => {
35
35
  const { used, name, componentType } = usageInfo;
36
36
  if (!used && componentType) {
37
37
  rootComponents.add(componentType);
@@ -67,7 +67,7 @@ const RemoveUnusedComponents = () => {
67
67
  SecurityScheme(_securityScheme, { location, key }) {
68
68
  registerComponent(location, 'securityDefinitions', key.toString());
69
69
  },
70
- }
70
+ },
71
71
  };
72
72
  };
73
73
  exports.RemoveUnusedComponents = RemoveUnusedComponents;
@@ -20,13 +20,13 @@ const no_server_trailing_slash_1 = require("./no-server-trailing-slash");
20
20
  const info_description_1 = require("../common/info-description");
21
21
  const tag_description_1 = require("../common/tag-description");
22
22
  const info_contact_1 = require("../common/info-contact");
23
+ const info_license_1 = require("../common/info-license");
23
24
  const info_license_url_1 = require("../common/info-license-url");
24
25
  const operation_description_1 = require("../common/operation-description");
25
26
  const no_unused_components_1 = require("./no-unused-components");
26
27
  const path_not_include_query_1 = require("../common/path-not-include-query");
27
28
  const parameter_description_1 = require("../common/parameter-description");
28
29
  const operation_singular_tag_1 = require("../common/operation-singular-tag");
29
- const license_url_1 = require("../common/license-url");
30
30
  const operation_security_defined_1 = require("../common/operation-security-defined");
31
31
  const no_unresolved_refs_1 = require("../no-unresolved-refs");
32
32
  const boolean_parameter_prefixes_1 = require("./boolean-parameter-prefixes");
@@ -39,7 +39,7 @@ const no_undefined_server_variable_1 = require("./no-undefined-server-variable")
39
39
  const operation_operationId_1 = require("../common/operation-operationId");
40
40
  const operation_summary_1 = require("../common/operation-summary");
41
41
  const no_ambiguous_paths_1 = require("../common/no-ambiguous-paths");
42
- const no_servers_empty_enum_1 = require("./no-servers-empty-enum");
42
+ const no_server_variables_empty_enum_1 = require("./no-server-variables-empty-enum");
43
43
  const no_http_verbs_in_paths_1 = require("../common/no-http-verbs-in-paths");
44
44
  const request_mime_type_1 = require("./request-mime-type");
45
45
  const response_mime_type_1 = require("./response-mime-type");
@@ -54,11 +54,11 @@ exports.rules = {
54
54
  spec: spec_1.OasSpec,
55
55
  'info-description': info_description_1.InfoDescription,
56
56
  'info-contact': info_contact_1.InfoContact,
57
- 'info-license': info_license_url_1.InfoLicense,
58
- 'info-license-url': license_url_1.InfoLicenseUrl,
57
+ 'info-license': info_license_1.InfoLicense,
58
+ 'info-license-url': info_license_url_1.InfoLicenseUrl,
59
59
  'operation-2xx-response': operation_2xx_response_1.Operation2xxResponse,
60
60
  'operation-4xx-response': operation_4xx_response_1.Operation4xxResponse,
61
- 'assertions': assertions_1.Assertions,
61
+ assertions: assertions_1.Assertions,
62
62
  'operation-operationId-unique': operation_operationId_unique_1.OperationIdUnique,
63
63
  'operation-parameters-unique': operation_parameters_unique_1.OperationParametersUnique,
64
64
  'path-parameters-defined': path_params_defined_1.PathParamsDefined,
@@ -90,7 +90,7 @@ exports.rules = {
90
90
  'no-identical-paths': no_identical_paths_1.NoIdenticalPaths,
91
91
  'no-ambiguous-paths': no_ambiguous_paths_1.NoAmbiguousPaths,
92
92
  'no-undefined-server-variable': no_undefined_server_variable_1.NoUndefinedServerVariable,
93
- 'no-servers-empty-enum': no_servers_empty_enum_1.NoEmptyEnumServers,
93
+ 'no-server-variables-empty-enum': no_server_variables_empty_enum_1.NoServerVariablesEmptyEnum,
94
94
  'no-http-verbs-in-paths': no_http_verbs_in_paths_1.NoHttpVerbsInPaths,
95
95
  'path-excludes-patterns': path_excludes_patterns_1.PathExcludesPatterns,
96
96
  'request-mime-type': request_mime_type_1.RequestMimeType,
@@ -7,7 +7,7 @@ const NoEmptyServers = () => {
7
7
  if (!root.hasOwnProperty('servers')) {
8
8
  report({
9
9
  message: 'Servers must be present.',
10
- location: location.child(['openapi']).key()
10
+ location: location.child(['openapi']).key(),
11
11
  });
12
12
  return;
13
13
  }
@@ -5,7 +5,7 @@ const ref_utils_1 = require("../../ref-utils");
5
5
  const utils_1 = require("../utils");
6
6
  const ValidContentExamples = (opts) => {
7
7
  var _a;
8
- const disallowAdditionalProperties = (_a = opts.disallowAdditionalProperties) !== null && _a !== void 0 ? _a : true;
8
+ const allowAdditionalProperties = (_a = utils_1.getAdditionalPropertiesOption(opts)) !== null && _a !== void 0 ? _a : false;
9
9
  return {
10
10
  MediaType: {
11
11
  leave(mediaType, ctx) {
@@ -28,7 +28,7 @@ const ValidContentExamples = (opts) => {
28
28
  location = isMultiple ? resolved.location.child('value') : resolved.location;
29
29
  example = resolved.node;
30
30
  }
31
- utils_1.validateExample(isMultiple ? example.value : example, mediaType.schema, location, ctx, disallowAdditionalProperties);
31
+ utils_1.validateExample(isMultiple ? example.value : example, mediaType.schema, location, ctx, allowAdditionalProperties);
32
32
  }
33
33
  },
34
34
  },
@@ -0,0 +1,2 @@
1
+ import { Oas3Rule } from '../../visitors';
2
+ export declare const NoServerVariablesEmptyEnum: Oas3Rule;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NoEmptyEnumServers = void 0;
3
+ exports.NoServerVariablesEmptyEnum = void 0;
4
4
  var enumError;
5
5
  (function (enumError) {
6
6
  enumError["empty"] = "empty";
7
7
  enumError["invalidDefaultValue"] = "invalidDefaultValue";
8
8
  })(enumError || (enumError = {}));
9
- const NoEmptyEnumServers = () => {
9
+ const NoServerVariablesEmptyEnum = () => {
10
10
  return {
11
11
  DefinitionRoot(root, { report, location }) {
12
12
  if (!root.servers || root.servers.length === 0)
@@ -43,13 +43,13 @@ const NoEmptyEnumServers = () => {
43
43
  },
44
44
  };
45
45
  };
46
- exports.NoEmptyEnumServers = NoEmptyEnumServers;
46
+ exports.NoServerVariablesEmptyEnum = NoServerVariablesEmptyEnum;
47
47
  function checkEnumVariables(server) {
48
48
  var _a;
49
49
  if (server.variables && Object.keys(server.variables).length === 0)
50
50
  return;
51
51
  const errors = [];
52
- for (var variable in server.variables) {
52
+ for (const variable in server.variables) {
53
53
  const serverVariable = server.variables[variable];
54
54
  if (!serverVariable.enum)
55
55
  continue;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NoUnusedComponents = void 0;
4
4
  const NoUnusedComponents = () => {
5
- let components = new Map();
5
+ const components = new Map();
6
6
  function registerComponent(location, name) {
7
7
  var _a;
8
8
  components.set(location.absolutePointer, {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RemoveUnusedComponents = void 0;
4
4
  const utils_1 = require("../../utils");
5
5
  const RemoveUnusedComponents = () => {
6
- let components = new Map();
6
+ const components = new Map();
7
7
  function registerComponent(location, componentType, name) {
8
8
  var _a;
9
9
  components.set(location.absolutePointer, {
@@ -24,16 +24,16 @@ const RemoveUnusedComponents = () => {
24
24
  name: key.toString(),
25
25
  });
26
26
  }
27
- }
27
+ },
28
28
  },
29
29
  DefinitionRoot: {
30
30
  leave(root, ctx) {
31
31
  const data = ctx.getVisitorData();
32
32
  data.removedCount = 0;
33
- components.forEach(usageInfo => {
33
+ components.forEach((usageInfo) => {
34
34
  const { used, componentType, name } = usageInfo;
35
- if (!used && componentType) {
36
- let componentChild = root.components[componentType];
35
+ if (!used && componentType && root.components) {
36
+ const componentChild = root.components[componentType];
37
37
  delete componentChild[name];
38
38
  data.removedCount++;
39
39
  if (utils_1.isEmptyObject(componentChild)) {
@@ -3,10 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Stats = void 0;
4
4
  const Stats = (statsAccumulator) => {
5
5
  return {
6
- ExternalDocs: { leave() { statsAccumulator.externalDocs.total++; } },
7
- ref: { enter(ref) { statsAccumulator.refs.items.add(ref['$ref']); } },
8
- Tag: { leave(tag) { statsAccumulator.tags.items.add(tag.name); } },
9
- Link: { leave(link) { statsAccumulator.links.items.add(link.operationId); } },
6
+ ExternalDocs: {
7
+ leave() {
8
+ statsAccumulator.externalDocs.total++;
9
+ },
10
+ },
11
+ ref: {
12
+ enter(ref) {
13
+ statsAccumulator.refs.items.add(ref['$ref']);
14
+ },
15
+ },
16
+ Tag: {
17
+ leave(tag) {
18
+ statsAccumulator.tags.items.add(tag.name);
19
+ },
20
+ },
21
+ Link: {
22
+ leave(link) {
23
+ statsAccumulator.links.items.add(link.operationId);
24
+ },
25
+ },
10
26
  DefinitionRoot: {
11
27
  leave() {
12
28
  statsAccumulator.parameters.total = statsAccumulator.parameters.items.size;
@@ -18,27 +34,40 @@ const Stats = (statsAccumulator) => {
18
34
  WebhooksMap: {
19
35
  Operation: {
20
36
  leave(operation) {
21
- operation.tags.forEach((tag) => { statsAccumulator.tags.items.add(tag); });
22
- }
23
- }
37
+ operation.tags.forEach((tag) => {
38
+ statsAccumulator.tags.items.add(tag);
39
+ });
40
+ },
41
+ },
24
42
  },
25
43
  PathMap: {
26
44
  PathItem: {
27
- leave() { statsAccumulator.pathItems.total++; },
45
+ leave() {
46
+ statsAccumulator.pathItems.total++;
47
+ },
28
48
  Operation: {
29
49
  leave(operation) {
30
50
  statsAccumulator.operations.total++;
31
- operation.tags && operation.tags.forEach((tag) => { statsAccumulator.tags.items.add(tag); });
32
- }
51
+ operation.tags &&
52
+ operation.tags.forEach((tag) => {
53
+ statsAccumulator.tags.items.add(tag);
54
+ });
55
+ },
33
56
  },
34
- Parameter: { leave(parameter) {
57
+ Parameter: {
58
+ leave(parameter) {
35
59
  statsAccumulator.parameters.items.add(parameter.name);
36
- } },
60
+ },
61
+ },
37
62
  },
38
63
  },
39
64
  NamedSchemas: {
40
- Schema: { leave() { statsAccumulator.schemas.total++; } }
41
- }
65
+ Schema: {
66
+ leave() {
67
+ statsAccumulator.schemas.total++;
68
+ },
69
+ },
70
+ },
42
71
  };
43
72
  };
44
73
  exports.Stats = Stats;
@@ -1,7 +1,7 @@
1
1
  import { UserContext } from '../walk';
2
2
  import { Location } from '../ref-utils';
3
3
  import { Oas3Schema, Referenced } from '../typings/openapi';
4
- export declare function oasTypeOf(value: unknown): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "array" | "null";
4
+ export declare function oasTypeOf(value: unknown): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "null" | "integer" | "array";
5
5
  /**
6
6
  * Checks if value matches specified JSON schema type
7
7
  *
@@ -14,4 +14,5 @@ export declare function missingRequiredField(type: string, field: string): strin
14
14
  export declare function fieldNonEmpty(type: string, field: string): string;
15
15
  export declare function validateDefinedAndNonEmpty(fieldName: string, value: any, ctx: UserContext): void;
16
16
  export declare function getSuggest(given: string, variants: string[]): string[];
17
- export declare function validateExample(example: any, schema: Referenced<Oas3Schema>, dataLoc: Location, { resolve, location, report }: UserContext, disallowAdditionalProperties: boolean): void;
17
+ export declare function validateExample(example: any, schema: Referenced<Oas3Schema>, dataLoc: Location, { resolve, location, report }: UserContext, allowAdditionalProperties: boolean): void;
18
+ export declare function getAdditionalPropertiesOption(opts: Record<string, any>): boolean;