@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
@@ -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,10 +101,10 @@ 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
- for (let error of errors) {
107
+ for (const error of errors) {
105
108
  report({
106
109
  message: `Example value must conform to the schema: ${error.message}.`,
107
110
  location: {
@@ -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
  }
@@ -40,7 +40,7 @@ const builtInRulesList = [
40
40
  'no-identical-paths',
41
41
  'no-ambiguous-paths',
42
42
  'no-undefined-server-variable',
43
- 'no-servers-empty-enum',
43
+ 'no-server-variables-empty-enum',
44
44
  'no-http-verbs-in-paths',
45
45
  'path-excludes-patterns',
46
46
  'request-mime-type',
@@ -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;
package/src/utils.ts CHANGED
@@ -6,7 +6,8 @@ import * as pluralize from 'pluralize';
6
6
  import { parseYaml } from './js-yaml';
7
7
  import { UserContext } from './walk';
8
8
  import { HttpResolveConfig } from './config';
9
- import { env } from './config';
9
+ import { env } from './env';
10
+ import { logger, colorize } from './logger';
10
11
 
11
12
  export { parseYaml, stringifyYaml } from './js-yaml';
12
13
 
@@ -95,7 +96,7 @@ export function omitObjectProps<T extends Record<string, unknown>>(
95
96
  export function splitCamelCaseIntoWords(str: string) {
96
97
  const camel = str
97
98
  .split(/(?:[-._])|([A-Z][a-z]+)/)
98
- .filter(Boolean)
99
+ .filter(isTruthy)
99
100
  .map((item) => item.toLocaleLowerCase());
100
101
  const caps = str
101
102
  .split(/([A-Z]{2,})/)
@@ -182,7 +183,7 @@ export function isNotString<T>(value: string | T): value is T {
182
183
  }
183
184
 
184
185
  export function assignExisting<T>(target: Record<string, T>, obj: Record<string, T>) {
185
- for (let k of Object.keys(obj)) {
186
+ for (const k of Object.keys(obj)) {
186
187
  if (target.hasOwnProperty(k)) {
187
188
  target[k] = obj[k];
188
189
  }
@@ -204,3 +205,25 @@ export function doesYamlFileExist(filePath: string): boolean {
204
205
  fs.existsSync(filePath)
205
206
  );
206
207
  }
208
+
209
+ export function showWarningForDeprecatedField(deprecatedField: string, updatedField: string) {
210
+ logger.warn(
211
+ `The ${colorize.red(deprecatedField)} field is deprecated. Use ${colorize.green(
212
+ updatedField
213
+ )} instead. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`
214
+ );
215
+ }
216
+
217
+ export function showErrorForDeprecatedField(deprecatedField: string, updatedField: string) {
218
+ throw new Error(`Do not use '${deprecatedField}' field. Use '${updatedField}' instead.\n`);
219
+ }
220
+
221
+ export type Falsy = undefined | null | false | '' | 0;
222
+
223
+ export function isTruthy<Truthy>(value: Truthy | Falsy): value is Truthy {
224
+ return !!value;
225
+ }
226
+
227
+ export function identity<T>(value: T): T {
228
+ return value;
229
+ }
package/src/visitors.ts CHANGED
@@ -53,7 +53,7 @@ export type VisitFunction<T> = (
53
53
  node: T,
54
54
  ctx: UserContext & { ignoreNextVisitorsOnNode: () => void },
55
55
  parents?: any,
56
- context?: any,
56
+ context?: any
57
57
  ) => void;
58
58
 
59
59
  type VisitRefFunction = (node: OasRef, ctx: UserContext, resolved: ResolveResult<any>) => void;
@@ -70,7 +70,7 @@ type NestedVisitObject<T, P> = VisitObject<T> & NestedVisitor<P>;
70
70
 
71
71
  type VisitFunctionOrObject<T> = VisitFunction<T> | VisitObject<T>;
72
72
 
73
- type VisitorNode<T extends any> = {
73
+ type VisitorNode<T> = {
74
74
  ruleId: string;
75
75
  severity: ProblemSeverity;
76
76
  context: VisitorLevelContext | VisitorSkippedLevelContext;
@@ -264,7 +264,7 @@ export type RuleInstanceConfig = {
264
264
 
265
265
  export function normalizeVisitors<T extends BaseVisitor>(
266
266
  visitorsConfig: (RuleInstanceConfig & { visitor: NestedVisitObject<any, T> })[],
267
- types: Record<keyof T, NormalizedNodeType>,
267
+ types: Record<keyof T, NormalizedNodeType>
268
268
  ): NormalizedOasVisitors<T> {
269
269
  const normalizedVisitors: NormalizedOasVisitors<T> = {} as any;
270
270
 
@@ -301,7 +301,7 @@ export function normalizeVisitors<T extends BaseVisitor>(
301
301
  from: NormalizedNodeType,
302
302
  to: NormalizedNodeType,
303
303
  parentContext: VisitorLevelContext,
304
- stack: NormalizedNodeType[] = [],
304
+ stack: NormalizedNodeType[] = []
305
305
  ) {
306
306
  if (stack.includes(from)) return;
307
307
 
@@ -309,7 +309,7 @@ export function normalizeVisitors<T extends BaseVisitor>(
309
309
 
310
310
  const possibleChildren = new Set<NormalizedNodeType>();
311
311
 
312
- for (let type of Object.values(from.properties)) {
312
+ for (const type of Object.values(from.properties)) {
313
313
  if (type === to) {
314
314
  addWeakFromStack(ruleConf, stack);
315
315
  continue;
@@ -333,7 +333,7 @@ export function normalizeVisitors<T extends BaseVisitor>(
333
333
  }
334
334
  }
335
335
 
336
- for (let fromType of Array.from(possibleChildren.values())) {
336
+ for (const fromType of Array.from(possibleChildren.values())) {
337
337
  addWeakNodes(ruleConf, fromType, to, parentContext, stack);
338
338
  }
339
339
 
@@ -350,7 +350,7 @@ export function normalizeVisitors<T extends BaseVisitor>(
350
350
  visit: () => undefined,
351
351
  depth: 0,
352
352
  context: {
353
- isSkippedLevel: true as true,
353
+ isSkippedLevel: true,
354
354
  seen: new Set(),
355
355
  parent: parentContext,
356
356
  },
@@ -363,7 +363,7 @@ export function normalizeVisitors<T extends BaseVisitor>(
363
363
  ruleConf: RuleInstanceConfig,
364
364
  visitor: NestedVisitObject<any, T>,
365
365
  parentContext: VisitorLevelContext | null,
366
- depth = 0,
366
+ depth = 0
367
367
  ) {
368
368
  const visitorKeys = Object.keys(types) as Array<keyof T | 'any'>;
369
369
 
@@ -407,7 +407,7 @@ export function normalizeVisitors<T extends BaseVisitor>(
407
407
  activatedOn: null,
408
408
  type: types[typeName],
409
409
  parent: parentContext,
410
- isSkippedLevel: false as false,
410
+ isSkippedLevel: false,
411
411
  };
412
412
 
413
413
  if (typeof typeVisitor === 'object') {
package/src/walk.ts CHANGED
@@ -18,6 +18,8 @@ import {
18
18
  import { pushStack, popStack } from './utils';
19
19
  import { OasVersion } from './oas-types';
20
20
  import { NormalizedNodeType, isNamedType } from './types';
21
+ import type { RuleSeverity } from './config';
22
+
21
23
  type NonUndefined = string | number | boolean | symbol | bigint | object | Record<string, any>;
22
24
 
23
25
  export type ResolveResult<T extends NonUndefined> =
@@ -66,7 +68,7 @@ export type Problem = {
66
68
  suggest?: string[];
67
69
  location?: Partial<LocationObject> | Array<Partial<LocationObject>>;
68
70
  from?: LocationObject;
69
- forceSeverity?: ProblemSeverity;
71
+ forceSeverity?: RuleSeverity;
70
72
  ruleId?: string;
71
73
  };
72
74
 
@@ -409,17 +411,19 @@ export function walkDocument<T>(opts: {
409
411
  : [opts.location]
410
412
  : [{ ...currentLocation, reportOnKey: false }];
411
413
 
412
- ctx.problems.push({
413
- ruleId: opts.ruleId || ruleId,
414
- severity: opts.forceSeverity || severity,
415
- ...opts,
416
- suggest: opts.suggest || [],
417
- location: loc.map((loc: any) => {
418
- return { ...currentLocation, reportOnKey: false, ...loc };
419
- }),
420
- });
414
+ const ruleSeverity = opts.forceSeverity || severity;
415
+ if (ruleSeverity !== 'off') {
416
+ ctx.problems.push({
417
+ ruleId: opts.ruleId || ruleId,
418
+ severity: ruleSeverity,
419
+ ...opts,
420
+ suggest: opts.suggest || [],
421
+ location: loc.map((loc: any) => {
422
+ return { ...currentLocation, reportOnKey: false, ...loc };
423
+ }),
424
+ });
425
+ }
421
426
  }
422
-
423
427
  function getVisitorDataFn(ruleId: string) {
424
428
  ctx.visitorsData[ruleId] = ctx.visitorsData[ruleId] || {};
425
429
  return ctx.visitorsData[ruleId];