@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
@@ -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,
@@ -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
33
  let rootComponents = new Set();
34
- components.forEach(usageInfo => {
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");
@@ -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,
@@ -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
  },
@@ -24,13 +24,13 @@ 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
35
  if (!used && componentType) {
36
36
  let componentChild = root.components[componentType];
@@ -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" | "integer" | "array" | "null";
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;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateExample = exports.getSuggest = exports.validateDefinedAndNonEmpty = exports.fieldNonEmpty = exports.missingRequiredField = exports.matchesJsonSchemaType = exports.oasTypeOf = void 0;
3
+ exports.getAdditionalPropertiesOption = exports.validateExample = exports.getSuggest = exports.validateDefinedAndNonEmpty = exports.fieldNonEmpty = exports.missingRequiredField = exports.matchesJsonSchemaType = exports.oasTypeOf = void 0;
4
4
  const levenshtein = require("js-levenshtein");
5
5
  const ref_utils_1 = require("../ref-utils");
6
6
  const ajv_1 = require("./ajv");
7
+ const utils_1 = require("../utils");
7
8
  function oasTypeOf(value) {
8
9
  if (Array.isArray(value)) {
9
10
  return 'array';
@@ -11,6 +12,9 @@ function oasTypeOf(value) {
11
12
  else if (value === null) {
12
13
  return 'null';
13
14
  }
15
+ else if (Number.isInteger(value)) {
16
+ return 'integer';
17
+ }
14
18
  else {
15
19
  return typeof value;
16
20
  }
@@ -25,7 +29,7 @@ exports.oasTypeOf = oasTypeOf;
25
29
  */
26
30
  function matchesJsonSchemaType(value, type, nullable) {
27
31
  if (nullable && value === null) {
28
- return value === null;
32
+ return true;
29
33
  }
30
34
  switch (type) {
31
35
  case 'array':
@@ -82,9 +86,9 @@ function getSuggest(given, variants) {
82
86
  return distances.map((d) => d.variant);
83
87
  }
84
88
  exports.getSuggest = getSuggest;
85
- function validateExample(example, schema, dataLoc, { resolve, location, report }, disallowAdditionalProperties) {
89
+ function validateExample(example, schema, dataLoc, { resolve, location, report }, allowAdditionalProperties) {
86
90
  try {
87
- const { valid, errors } = ajv_1.validateJsonSchema(example, schema, location.child('schema'), dataLoc.pointer, resolve, disallowAdditionalProperties);
91
+ const { valid, errors } = ajv_1.validateJsonSchema(example, schema, location.child('schema'), dataLoc.pointer, resolve, allowAdditionalProperties);
88
92
  if (!valid) {
89
93
  for (let error of errors) {
90
94
  report({
@@ -105,3 +109,14 @@ function validateExample(example, schema, dataLoc, { resolve, location, report }
105
109
  }
106
110
  }
107
111
  exports.validateExample = validateExample;
112
+ function getAdditionalPropertiesOption(opts) {
113
+ if (opts.disallowAdditionalProperties === undefined) {
114
+ return opts.allowAdditionalProperties;
115
+ }
116
+ if (opts.allowAdditionalProperties !== undefined) {
117
+ utils_1.showErrorForDeprecatedField('disallowAdditionalProperties', 'allowAdditionalProperties');
118
+ }
119
+ utils_1.showWarningForDeprecatedField('disallowAdditionalProperties', 'allowAdditionalProperties');
120
+ return !opts.disallowAdditionalProperties;
121
+ }
122
+ exports.getAdditionalPropertiesOption = getAdditionalPropertiesOption;
@@ -22,7 +22,7 @@ export declare type NodeType = {
22
22
  items?: string;
23
23
  required?: string[] | ((value: any, key: string | number | undefined) => string[]);
24
24
  requiredOneOf?: string[];
25
- allowed?: ((value: any) => string[] | undefined);
25
+ allowed?: (value: any) => string[] | undefined;
26
26
  extensionsPrefix?: string;
27
27
  };
28
28
  declare type PropType = string | NodeType | ScalarSchema | undefined | null;
@@ -34,7 +34,7 @@ export declare type NormalizedNodeType = {
34
34
  items?: NormalizedNodeType;
35
35
  required?: string[] | ((value: any, key: string | number | undefined) => string[]);
36
36
  requiredOneOf?: string[];
37
- allowed?: ((value: any) => string[] | undefined);
37
+ allowed?: (value: any) => string[] | undefined;
38
38
  extensionsPrefix?: string;
39
39
  };
40
40
  declare type NormalizedPropType = NormalizedNodeType | NormalizedScalarSchema | undefined | null;
@@ -112,7 +112,8 @@ const ConfigRoot = {
112
112
  properties: {},
113
113
  additionalProperties: { properties: { type: 'string' } },
114
114
  },
115
- lint: 'RootConfigLint',
115
+ styleguide: 'RootConfigStyleguide',
116
+ lint: 'RootConfigStyleguide',
116
117
  'features.openapi': 'ConfigReferenceDocs',
117
118
  referenceDocs: 'ConfigReferenceDocs',
118
119
  'features.mockServer': 'ConfigMockServer',
@@ -137,7 +138,7 @@ const ConfigApisProperties = {
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
  },
@@ -153,7 +154,7 @@ const ConfigHTTP = {
153
154
  },
154
155
  },
155
156
  };
156
- const ConfigLint = {
157
+ const ConfigStyleguide = {
157
158
  properties: {
158
159
  extends: {
159
160
  type: 'array',
@@ -176,11 +177,11 @@ const ConfigLint = {
176
177
  oas3_1Decorators: { type: 'object' },
177
178
  },
178
179
  };
179
- const RootConfigLint = {
180
+ const RootConfigStyleguide = {
180
181
  properties: Object.assign({ plugins: {
181
182
  type: 'array',
182
183
  items: { type: 'string' },
183
- } }, ConfigLint.properties),
184
+ } }, ConfigStyleguide.properties),
184
185
  };
185
186
  const Rules = {
186
187
  properties: {},
@@ -765,8 +766,8 @@ exports.ConfigTypes = {
765
766
  ConfigRoot,
766
767
  ConfigApis,
767
768
  ConfigApisProperties,
768
- RootConfigLint,
769
- ConfigLint,
769
+ RootConfigStyleguide,
770
+ ConfigStyleguide,
770
771
  ConfigReferenceDocs,
771
772
  ConfigMockServer,
772
773
  ConfigHTTP,
package/lib/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { UserContext } from './walk';
2
- import type { HttpResolveConfig } from './config';
2
+ import { HttpResolveConfig } from './config';
3
3
  export { parseYaml, stringifyYaml } from './js-yaml';
4
4
  export declare type StackFrame<T> = {
5
5
  prev: StackFrame<T> | null;
@@ -38,5 +38,8 @@ export declare function isNotEmptyObject(obj: any): boolean;
38
38
  export declare function isString(value: unknown): value is string;
39
39
  export declare function isNotString<T>(value: string | T): value is T;
40
40
  export declare function assignExisting<T>(target: Record<string, T>, obj: Record<string, T>): void;
41
- export declare const getMatchingStatusCodeRange: (code: number | string) => string;
41
+ export declare function getMatchingStatusCodeRange(code: number | string): string;
42
42
  export declare function isCustomRuleId(id: string): boolean;
43
+ export declare function doesYamlFileExist(filePath: string): boolean;
44
+ export declare function showWarningForDeprecatedField(deprecatedField: string, updatedField: string): void;
45
+ export declare function showErrorForDeprecatedField(deprecatedField: string, updatedField: string): void;
package/lib/utils.js CHANGED
@@ -9,13 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.isCustomRuleId = exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.notUndefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
12
+ exports.showErrorForDeprecatedField = exports.showWarningForDeprecatedField = exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.notUndefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
13
13
  const fs = require("fs");
14
+ const path_1 = require("path");
14
15
  const minimatch = require("minimatch");
15
16
  const node_fetch_1 = require("node-fetch");
16
17
  const pluralize = require("pluralize");
17
18
  const js_yaml_1 = require("./js-yaml");
18
19
  const config_1 = require("./config");
20
+ const colorette_1 = require("colorette");
19
21
  var js_yaml_2 = require("./js-yaml");
20
22
  Object.defineProperty(exports, "parseYaml", { enumerable: true, get: function () { return js_yaml_2.parseYaml; } });
21
23
  Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: function () { return js_yaml_2.stringifyYaml; } });
@@ -173,9 +175,25 @@ function assignExisting(target, obj) {
173
175
  }
174
176
  }
175
177
  exports.assignExisting = assignExisting;
176
- const getMatchingStatusCodeRange = (code) => `${code}`.replace(/^(\d)\d\d$/, (_, firstDigit) => `${firstDigit}XX`);
178
+ function getMatchingStatusCodeRange(code) {
179
+ return `${code}`.replace(/^(\d)\d\d$/, (_, firstDigit) => `${firstDigit}XX`);
180
+ }
177
181
  exports.getMatchingStatusCodeRange = getMatchingStatusCodeRange;
178
182
  function isCustomRuleId(id) {
179
183
  return id.includes('/');
180
184
  }
181
185
  exports.isCustomRuleId = isCustomRuleId;
186
+ function doesYamlFileExist(filePath) {
187
+ return ((path_1.extname(filePath) === '.yaml' || path_1.extname(filePath) === '.yml') &&
188
+ fs.hasOwnProperty('existsSync') &&
189
+ fs.existsSync(filePath));
190
+ }
191
+ exports.doesYamlFileExist = doesYamlFileExist;
192
+ function showWarningForDeprecatedField(deprecatedField, updatedField) {
193
+ process.stderr.write(`The ${colorette_1.yellow(deprecatedField)} field is deprecated. Use ${colorette_1.green(updatedField)} instead. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`);
194
+ }
195
+ exports.showWarningForDeprecatedField = showWarningForDeprecatedField;
196
+ function showErrorForDeprecatedField(deprecatedField, updatedField) {
197
+ throw new Error(`Do not use '${deprecatedField}' field. Use '${updatedField}' instead.\n`);
198
+ }
199
+ exports.showErrorForDeprecatedField = showErrorForDeprecatedField;
package/lib/walk.d.ts CHANGED
@@ -4,6 +4,7 @@ import { NormalizedOasVisitors } from './visitors';
4
4
  import { ResolvedRefMap, Document, ResolveError, YamlParseError, Source } from './resolve';
5
5
  import { OasVersion } from './oas-types';
6
6
  import { NormalizedNodeType } from './types';
7
+ import type { RuleSeverity } from './config';
7
8
  declare type NonUndefined = string | number | boolean | symbol | bigint | object | Record<string, any>;
8
9
  export declare type ResolveResult<T extends NonUndefined> = {
9
10
  node: T;
@@ -49,7 +50,7 @@ export declare type Problem = {
49
50
  suggest?: string[];
50
51
  location?: Partial<LocationObject> | Array<Partial<LocationObject>>;
51
52
  from?: LocationObject;
52
- forceSeverity?: ProblemSeverity;
53
+ forceSeverity?: RuleSeverity;
53
54
  ruleId?: string;
54
55
  };
55
56
  export declare type NormalizedProblem = {
package/lib/walk.js CHANGED
@@ -249,9 +249,12 @@ function walkDocument(opts) {
249
249
  ? opts.location
250
250
  : [opts.location]
251
251
  : [Object.assign(Object.assign({}, currentLocation), { reportOnKey: false })];
252
- ctx.problems.push(Object.assign(Object.assign({ ruleId: opts.ruleId || ruleId, severity: opts.forceSeverity || severity }, opts), { suggest: opts.suggest || [], location: loc.map((loc) => {
253
- return Object.assign(Object.assign(Object.assign({}, currentLocation), { reportOnKey: false }), loc);
254
- }) }));
252
+ const ruleSeverity = opts.forceSeverity || severity;
253
+ if (ruleSeverity !== 'off') {
254
+ ctx.problems.push(Object.assign(Object.assign({ ruleId: opts.ruleId || ruleId, severity: ruleSeverity }, opts), { suggest: opts.suggest || [], location: loc.map((loc) => {
255
+ return Object.assign(Object.assign(Object.assign({}, currentLocation), { reportOnKey: false }), loc);
256
+ }) }));
257
+ }
255
258
  }
256
259
  function getVisitorDataFn(ruleId) {
257
260
  ctx.visitorsData[ruleId] = ctx.visitorsData[ruleId] || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/openapi-core",
3
- "version": "1.0.0-beta.104",
3
+ "version": "1.0.0-beta.107",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "engines": {
@@ -34,7 +34,7 @@
34
34
  "Andriy Leliv <andriy@redoc.ly> (https://redoc.ly/)"
35
35
  ],
36
36
  "dependencies": {
37
- "@redocly/ajv": "^8.6.4",
37
+ "@redocly/ajv": "^8.6.5",
38
38
  "@types/node": "^14.11.8",
39
39
  "colorette": "^1.2.0",
40
40
  "js-levenshtein": "^1.1.6",
@@ -1,5 +1,146 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
+ exports[`bundle should add to meta ref from redocly registry 1`] = `
4
+ fileDependencies: {}
5
+ rootType:
6
+ properties:
7
+ openapi: null
8
+ info:
9
+ properties:
10
+ title:
11
+ type: string
12
+ version:
13
+ type: string
14
+ description:
15
+ type: string
16
+ termsOfService:
17
+ type: string
18
+ contact:
19
+ properties:
20
+ name:
21
+ type: string
22
+ url:
23
+ type: string
24
+ email:
25
+ type: string
26
+ name: Contact
27
+ license:
28
+ properties:
29
+ name:
30
+ type: string
31
+ url:
32
+ type: string
33
+ required:
34
+ - name
35
+ name: License
36
+ required:
37
+ - title
38
+ - version
39
+ name: Info
40
+ servers:
41
+ name: ServerList
42
+ properties: {}
43
+ items:
44
+ properties:
45
+ url:
46
+ type: string
47
+ description:
48
+ type: string
49
+ variables:
50
+ name: ServerVariableMap
51
+ properties: {}
52
+ required:
53
+ - url
54
+ name: Server
55
+ security:
56
+ name: SecurityRequirementList
57
+ properties: {}
58
+ items:
59
+ properties: {}
60
+ additionalProperties:
61
+ type: array
62
+ items:
63
+ type: string
64
+ name: SecurityRequirement
65
+ tags:
66
+ name: TagList
67
+ properties: {}
68
+ items:
69
+ properties:
70
+ name:
71
+ type: string
72
+ description:
73
+ type: string
74
+ externalDocs:
75
+ properties:
76
+ description:
77
+ type: string
78
+ url:
79
+ type: string
80
+ required:
81
+ - url
82
+ name: ExternalDocs
83
+ required:
84
+ - name
85
+ name: Tag
86
+ externalDocs:
87
+ properties:
88
+ description:
89
+ type: string
90
+ url:
91
+ type: string
92
+ required:
93
+ - url
94
+ name: ExternalDocs
95
+ paths:
96
+ properties: {}
97
+ name: PathMap
98
+ components:
99
+ properties:
100
+ parameters:
101
+ name: NamedParameters
102
+ properties: {}
103
+ schemas:
104
+ name: NamedSchemas
105
+ properties: {}
106
+ responses:
107
+ name: NamedResponses
108
+ properties: {}
109
+ examples:
110
+ name: NamedExamples
111
+ properties: {}
112
+ requestBodies:
113
+ name: NamedRequestBodies
114
+ properties: {}
115
+ headers:
116
+ name: NamedHeaders
117
+ properties: {}
118
+ securitySchemes:
119
+ name: NamedSecuritySchemes
120
+ properties: {}
121
+ links:
122
+ name: NamedLinks
123
+ properties: {}
124
+ callbacks:
125
+ name: NamedCallbacks
126
+ properties: {}
127
+ name: Components
128
+ x-webhooks:
129
+ properties: {}
130
+ name: WebhooksMap
131
+ required:
132
+ - openapi
133
+ - paths
134
+ - info
135
+ name: DefinitionRoot
136
+ refTypes: {}
137
+ visitorsData:
138
+ registry-dependencies:
139
+ links:
140
+ - https://api.redocly.com/registry/params
141
+
142
+ `;
143
+
3
144
  exports[`bundle should bundle external refs 1`] = `
4
145
  openapi: 3.0.0
5
146
  paths: