@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
@@ -1,12 +1,12 @@
1
1
  import { RuleSet, OasVersion } from '../oas-types';
2
- import { LintConfig } from './config';
2
+ import { StyleguideConfig } from './config';
3
3
  import { notUndefined } from '../utils';
4
4
 
5
5
  export function initRules<T extends Function, P extends RuleSet<T>>(
6
6
  rules: P[],
7
- config: LintConfig,
7
+ config: StyleguideConfig,
8
8
  type: 'rules' | 'preprocessors' | 'decorators',
9
- oasVersion: OasVersion,
9
+ oasVersion: OasVersion
10
10
  ) {
11
11
  return rules
12
12
  .flatMap((ruleset) =>
@@ -31,7 +31,7 @@ export function initRules<T extends Function, P extends RuleSet<T>>(
31
31
  severity: ruleSettings.severity,
32
32
  ruleId,
33
33
  visitor: visitor,
34
- }))
34
+ }));
35
35
  }
36
36
 
37
37
  return {
@@ -39,8 +39,8 @@ export function initRules<T extends Function, P extends RuleSet<T>>(
39
39
  ruleId,
40
40
  visitor: visitors, // note: actually it is only one visitor object
41
41
  };
42
- }),
42
+ })
43
43
  )
44
- .flatMap(visitor => visitor)
44
+ .flatMap((visitor) => visitor)
45
45
  .filter(notUndefined);
46
46
  }
@@ -29,7 +29,7 @@ export type PreprocessorConfig =
29
29
 
30
30
  export type DecoratorConfig = PreprocessorConfig;
31
31
 
32
- export type LintRawConfig = {
32
+ export type StyleguideRawConfig = {
33
33
  plugins?: (string | Plugin)[];
34
34
  extends?: string[];
35
35
  doNotResolveExamples?: boolean;
@@ -51,7 +51,9 @@ export type LintRawConfig = {
51
51
  oas3_1Decorators?: Record<string, DecoratorConfig>;
52
52
  };
53
53
 
54
- export type ResolvedLintConfig = PluginLintConfig & {
54
+ export type ApiStyleguideRawConfig = Omit<StyleguideRawConfig, 'plugins'>;
55
+
56
+ export type ResolvedStyleguideConfig = PluginStyleguideConfig & {
55
57
  plugins?: Plugin[];
56
58
  recommendedFallback?: boolean;
57
59
  extends?: void | never;
@@ -71,7 +73,7 @@ export type DecoratorsConfig = {
71
73
 
72
74
  export type TypesExtensionFn = (
73
75
  types: Record<string, NodeType>,
74
- oasVersion: OasVersion,
76
+ oasVersion: OasVersion
75
77
  ) => Record<string, NodeType>;
76
78
 
77
79
  export type TypeExtensionsConfig = Partial<Record<OasMajorVersion, TypesExtensionFn>>;
@@ -83,14 +85,14 @@ export type CustomRulesConfig = {
83
85
 
84
86
  export type Plugin = {
85
87
  id: string;
86
- configs?: Record<string, PluginLintConfig>;
88
+ configs?: Record<string, PluginStyleguideConfig>;
87
89
  rules?: CustomRulesConfig;
88
90
  preprocessors?: PreprocessorsConfig;
89
91
  decorators?: DecoratorsConfig;
90
92
  typeExtension?: TypeExtensionsConfig;
91
93
  };
92
94
 
93
- export type PluginLintConfig = Omit<LintRawConfig, 'plugins' | 'extends'>;
95
+ export type PluginStyleguideConfig = Omit<StyleguideRawConfig, 'plugins' | 'extends'>;
94
96
 
95
97
  export type ResolveHeader =
96
98
  | {
@@ -123,35 +125,42 @@ export type Region = 'us' | 'eu';
123
125
 
124
126
  export type AccessTokens = { [region in Region]?: string };
125
127
 
126
- export type DeprecatedRawConfig = {
128
+ export type DeprecatedInRawConfig = {
127
129
  apiDefinitions?: Record<string, string>;
128
- lint?: LintRawConfig;
129
- resolve?: RawResolveConfig;
130
- region?: Region;
130
+ lint?: StyleguideRawConfig;
131
131
  referenceDocs?: Record<string, any>;
132
+ apis?: Record<string, Api & DeprecatedInApi>;
132
133
  };
133
134
 
134
135
  export type Api = {
135
136
  root: string;
136
- lint?: Omit<LintRawConfig, 'plugins'>;
137
- 'features.openapi'?: Record<string, any>;
138
- 'features.mockServer'?: Record<string, any>;
137
+ styleguide?: ApiStyleguideRawConfig;
138
+ } & FeaturesConfig;
139
+
140
+ export type DeprecatedInApi = {
141
+ lint?: ApiStyleguideRawConfig;
142
+ };
143
+
144
+ export type ResolvedApi = Omit<Api, 'styleguide'> & {
145
+ styleguide: ResolvedStyleguideConfig;
139
146
  };
140
- export type ResolvedApi = Omit<Api, 'lint'> & { lint: Omit<ResolvedLintConfig, 'plugins'>};
141
147
 
142
148
  export type RawConfig = {
143
149
  apis?: Record<string, Api>;
144
- lint?: LintRawConfig;
150
+ styleguide?: StyleguideRawConfig;
145
151
  resolve?: RawResolveConfig;
146
152
  region?: Region;
147
- 'features.openapi'?: Record<string, any>;
148
- 'features.mockServer'?: Record<string, any>;
149
153
  organization?: string;
154
+ } & FeaturesConfig;
155
+
156
+ export type ResolvedConfig = Omit<RawConfig, 'apis' | 'styleguide'> & {
157
+ apis: Record<string, ResolvedApi>;
158
+ styleguide: ResolvedStyleguideConfig;
150
159
  };
151
160
 
152
- export type ResolvedConfig = Omit<RawConfig, 'lint' | 'apis'> & {
153
- lint: ResolvedLintConfig;
154
- apis: Record<string,ResolvedApi>
161
+ type FeaturesConfig = {
162
+ 'features.openapi'?: Record<string, any>;
163
+ 'features.mockServer'?: Record<string, any>;
155
164
  };
156
165
 
157
166
  export type RulesFields =
@@ -1,15 +1,20 @@
1
- import { green, yellow } from 'colorette';
2
- import { assignExisting } from '../utils';
1
+ import { yellow } from 'colorette';
2
+ import {
3
+ assignExisting,
4
+ showErrorForDeprecatedField,
5
+ showWarningForDeprecatedField,
6
+ } from '../utils';
3
7
  import { Config } from './config';
4
8
 
5
9
  import type {
6
10
  Api,
7
- DeprecatedRawConfig,
11
+ DeprecatedInApi,
12
+ DeprecatedInRawConfig,
8
13
  Plugin,
9
14
  RawConfig,
10
15
  RawResolveConfig,
11
16
  ResolveConfig,
12
- ResolvedLintConfig,
17
+ ResolvedStyleguideConfig,
13
18
  RulesFields,
14
19
  } from './types';
15
20
 
@@ -23,15 +28,27 @@ export function parsePresetName(presetName: string): { pluginId: string; configN
23
28
  }
24
29
 
25
30
  export function transformApiDefinitionsToApis(
26
- apiDefinitions: Record<string, string> = {},
27
- ): Record<string, Api> {
28
- let apis: Record<string, Api> = {};
31
+ apiDefinitions?: DeprecatedInRawConfig['apiDefinitions']
32
+ ): Record<string, Api> | undefined {
33
+ if (!apiDefinitions) return undefined;
34
+ const apis: Record<string, Api> = {};
29
35
  for (const [apiName, apiPath] of Object.entries(apiDefinitions)) {
30
36
  apis[apiName] = { root: apiPath };
31
37
  }
32
38
  return apis;
33
39
  }
34
40
 
41
+ function transformApis(
42
+ legacyApis?: Record<string, Api & DeprecatedInApi>
43
+ ): Record<string, Api> | undefined {
44
+ if (!legacyApis) return undefined;
45
+ const apis: Record<string, Api> = {};
46
+ for (const [apiName, { lint, ...apiContent }] of Object.entries(legacyApis)) {
47
+ apis[apiName] = { styleguide: lint, ...apiContent };
48
+ }
49
+ return apis;
50
+ }
51
+
35
52
  export function prefixRules<T extends Record<string, any>>(rules: T, prefix: string) {
36
53
  if (!prefix) return rules;
37
54
 
@@ -43,9 +60,9 @@ export function prefixRules<T extends Record<string, any>>(rules: T, prefix: str
43
60
  return res;
44
61
  }
45
62
 
46
- export function mergeExtends(rulesConfList: ResolvedLintConfig[]) {
47
- const result: Omit<ResolvedLintConfig, RulesFields> &
48
- Required<Pick<ResolvedLintConfig, RulesFields>> = {
63
+ export function mergeExtends(rulesConfList: ResolvedStyleguideConfig[]) {
64
+ const result: Omit<ResolvedStyleguideConfig, RulesFields> &
65
+ Required<Pick<ResolvedStyleguideConfig, RulesFields>> = {
49
66
  rules: {},
50
67
  oas2Rules: {},
51
68
  oas3_0Rules: {},
@@ -69,11 +86,7 @@ export function mergeExtends(rulesConfList: ResolvedLintConfig[]) {
69
86
  for (let rulesConf of rulesConfList) {
70
87
  if (rulesConf.extends) {
71
88
  throw new Error(
72
- `\`extends\` is not supported in shared configs yet: ${JSON.stringify(
73
- rulesConf,
74
- null,
75
- 2,
76
- )}.`,
89
+ `'extends' is not supported in shared configs yet: ${JSON.stringify(rulesConf, null, 2)}.`
77
90
  );
78
91
  }
79
92
 
@@ -109,75 +122,84 @@ export function mergeExtends(rulesConfList: ResolvedLintConfig[]) {
109
122
  return result;
110
123
  }
111
124
 
112
- export function getMergedConfig(config: Config, entrypointAlias?: string): Config {
125
+ export function getMergedConfig(config: Config, apiName?: string): Config {
113
126
  const extendPaths = [
114
- ...Object.values(config.apis).map((api) => api?.lint?.extendPaths),
115
- config.rawConfig?.lint?.extendPaths,
127
+ ...Object.values(config.apis).map((api) => api?.styleguide?.extendPaths),
128
+ config.rawConfig?.styleguide?.extendPaths,
116
129
  ]
117
130
  .flat()
118
131
  .filter(Boolean) as string[];
119
132
 
120
133
  const pluginPaths = [
121
- ...Object.values(config.apis).map((api) => api?.lint?.pluginPaths),
122
- config.rawConfig?.lint?.pluginPaths,
134
+ ...Object.values(config.apis).map((api) => api?.styleguide?.pluginPaths),
135
+ config.rawConfig?.styleguide?.pluginPaths,
123
136
  ]
124
137
  .flat()
125
138
  .filter(Boolean) as string[];
126
139
 
127
- return entrypointAlias
140
+ return apiName
128
141
  ? new Config(
129
142
  {
130
143
  ...config.rawConfig,
131
- lint: {
132
- ...(config.apis[entrypointAlias]
133
- ? config.apis[entrypointAlias].lint
134
- : config.rawConfig.lint),
144
+ styleguide: {
145
+ ...(config.apis[apiName]
146
+ ? config.apis[apiName].styleguide
147
+ : config.rawConfig.styleguide),
135
148
  extendPaths,
136
149
  pluginPaths,
137
150
  },
138
151
  'features.openapi': {
139
152
  ...config['features.openapi'],
140
- ...config.apis[entrypointAlias]?.['features.openapi'],
153
+ ...config.apis[apiName]?.['features.openapi'],
141
154
  },
142
155
  'features.mockServer': {
143
156
  ...config['features.mockServer'],
144
- ...config.apis[entrypointAlias]?.['features.mockServer'],
157
+ ...config.apis[apiName]?.['features.mockServer'],
145
158
  },
146
159
  // TODO: merge everything else here
147
160
  },
148
- config.configFile,
161
+ config.configFile
149
162
  )
150
163
  : config;
151
164
  }
152
165
 
153
- export function transformConfig(rawConfig: DeprecatedRawConfig | RawConfig): RawConfig {
154
- if ((rawConfig as RawConfig).apis && (rawConfig as DeprecatedRawConfig).apiDefinitions) {
155
- throw new Error("Do not use 'apiDefinitions' field. Use 'apis' instead.\n");
156
- }
157
- if (
158
- (rawConfig as RawConfig)['features.openapi'] &&
159
- (rawConfig as DeprecatedRawConfig).referenceDocs
160
- ) {
161
- throw new Error("Do not use 'referenceDocs' field. Use 'features.openapi' instead.\n");
162
- }
163
- const { apiDefinitions, referenceDocs, ...rest } = rawConfig as DeprecatedRawConfig & RawConfig;
164
- if (apiDefinitions) {
165
- process.stderr.write(
166
- `The ${yellow('apiDefinitions')} field is deprecated. Use ${green(
167
- 'apis',
168
- )} instead. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`,
166
+ function checkForDeprecatedFields(
167
+ deprecatedField: keyof DeprecatedInRawConfig,
168
+ updatedField: keyof RawConfig,
169
+ rawConfig: DeprecatedInRawConfig & RawConfig
170
+ ): void {
171
+ const isDeprecatedFieldInApis =
172
+ rawConfig.apis &&
173
+ Object.values(rawConfig.apis).some(
174
+ (api: Api & DeprecatedInApi & DeprecatedInRawConfig) => api[deprecatedField]
169
175
  );
176
+
177
+ if (rawConfig[deprecatedField] && rawConfig[updatedField]) {
178
+ showErrorForDeprecatedField(deprecatedField, updatedField);
170
179
  }
171
- if (referenceDocs) {
172
- process.stderr.write(
173
- `The ${yellow('referenceDocs')} field is deprecated. Use ${green(
174
- 'features.openapi',
175
- )} instead. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`,
176
- );
180
+
181
+ if (rawConfig[deprecatedField] || isDeprecatedFieldInApis) {
182
+ showWarningForDeprecatedField(deprecatedField, updatedField);
183
+ }
184
+ }
185
+
186
+ export function transformConfig(rawConfig: DeprecatedInRawConfig & RawConfig): RawConfig {
187
+ const migratedFields: [keyof DeprecatedInRawConfig, keyof RawConfig][] = [
188
+ ['apiDefinitions', 'apis'],
189
+ ['referenceDocs', 'features.openapi'],
190
+ ['lint', 'styleguide'], // TODO: update docs
191
+ ];
192
+
193
+ for (const [deprecatedField, updatedField] of migratedFields) {
194
+ checkForDeprecatedFields(deprecatedField, updatedField, rawConfig);
177
195
  }
196
+
197
+ const { apis, apiDefinitions, referenceDocs, lint, ...rest } = rawConfig;
198
+
178
199
  return {
179
200
  'features.openapi': referenceDocs,
180
- apis: transformApiDefinitionsToApis(apiDefinitions),
201
+ apis: transformApis(apis) || transformApiDefinitionsToApis(apiDefinitions),
202
+ styleguide: lint,
181
203
  ...rest,
182
204
  };
183
205
  }
@@ -199,9 +221,7 @@ export function getUniquePlugins(plugins: Plugin[]): Plugin[] {
199
221
  results.push(p);
200
222
  seen.add(p.id);
201
223
  } else if (p.id) {
202
- process.stderr.write(
203
- `Duplicate plugin id "${yellow(p.id)}".\n`,
204
- );
224
+ process.stderr.write(`Duplicate plugin id "${yellow(p.id)}".\n`);
205
225
  }
206
226
  }
207
227
  return results;
@@ -27,7 +27,8 @@ describe('oas3 filter-out', () => {
27
27
  callbacks:
28
28
  x-access: protected
29
29
  orderInProgress:
30
- x-internal: true`);
30
+ x-internal: true`
31
+ );
31
32
 
32
33
  it('should remove /pet path and y parameter', async () => {
33
34
  const testDocument = parseYamlToDocument(
@@ -132,7 +133,8 @@ describe('oas3 filter-out', () => {
132
133
  type: object
133
134
  components: {}
134
135
 
135
- `);
136
+ `
137
+ );
136
138
  const { bundle: res } = await bundleDocument({
137
139
  document: testDoc,
138
140
  externalRefResolver: new BaseResolver(),
@@ -185,7 +187,8 @@ describe('oas3 filter-out', () => {
185
187
  x:
186
188
  name: x
187
189
 
188
- `);
190
+ `
191
+ );
189
192
  const { bundle: res } = await bundleDocument({
190
193
  document: testDocument,
191
194
  externalRefResolver: new BaseResolver(),
@@ -236,7 +239,8 @@ describe('oas3 filter-out', () => {
236
239
  x:
237
240
  name: x
238
241
 
239
- `);
242
+ `
243
+ );
240
244
  const { bundle: res } = await bundleDocument({
241
245
  document: testDocument,
242
246
  externalRefResolver: new BaseResolver(),
@@ -18,7 +18,7 @@ describe('oas3 remove-x-internal', () => {
18
18
  parameters:
19
19
  x:
20
20
  name: x
21
- `,
21
+ `
22
22
  );
23
23
 
24
24
  it('should use `internalFlagProperty` option to remove internal paths', async () => {
@@ -87,7 +87,7 @@ describe('oas3 remove-x-internal', () => {
87
87
  name: x
88
88
  y:
89
89
  name: y
90
- `,
90
+ `
91
91
  );
92
92
  const { bundle: res } = await bundleDocument({
93
93
  document: testDoc,
@@ -160,7 +160,7 @@ describe('oas3 remove-x-internal', () => {
160
160
  servers:
161
161
  - url: //callback-url.path-level/v1
162
162
  description: Path level server
163
- `,
163
+ `
164
164
  );
165
165
  const { bundle: res } = await bundleDocument({
166
166
  document: testDoc,
@@ -234,7 +234,7 @@ describe('oas3 remove-x-internal', () => {
234
234
  schema:
235
235
  type: string
236
236
  x-internal: true
237
- `,
237
+ `
238
238
  );
239
239
  const { bundle: res } = await bundleDocument({
240
240
  document: testDoc,
@@ -297,7 +297,7 @@ describe('oas2 remove-x-internal', () => {
297
297
  '200':
298
298
  x-internal: true
299
299
  description: List of recent media entries.
300
- `,
300
+ `
301
301
  );
302
302
  const { bundle: res } = await bundleDocument({
303
303
  document: testDoc,
@@ -47,7 +47,7 @@ export function checkIfMatchByStrategy(
47
47
  decoratorValue: any,
48
48
  strategy: 'all' | 'any'
49
49
  ): boolean {
50
- if (nodeValue===undefined || decoratorValue===undefined) {
50
+ if (nodeValue === undefined || decoratorValue === undefined) {
51
51
  return false;
52
52
  }
53
53
 
@@ -8,7 +8,7 @@ export const InfoDescriptionOverride: Oas3Decorator | Oas2Decorator = ({ filePat
8
8
  leave(info, { report, location }: UserContext) {
9
9
  if (!filePath)
10
10
  throw new Error(
11
- `Parameter "filePath" is not provided for "info-description-override" rule`,
11
+ `Parameter "filePath" is not provided for "info-description-override" rule`
12
12
  );
13
13
  try {
14
14
  info.description = readFileAsStringSync(filePath);
@@ -11,7 +11,7 @@ export const OperationDescriptionOverride: Oas3Decorator | Oas2Decorator = ({ op
11
11
  if (!operation.operationId) return;
12
12
  if (!operationIds)
13
13
  throw new Error(
14
- `Parameter "operationIds" is not provided for "operation-description-override" rule`,
14
+ `Parameter "operationIds" is not provided for "operation-description-override" rule`
15
15
  );
16
16
  const operationId = operation.operationId;
17
17
  if (operationIds[operationId]) {
@@ -53,7 +53,7 @@ export const RemoveXInternal: Oas3Decorator | Oas2Decorator = ({ internalFlagPro
53
53
  any: {
54
54
  enter: (node, ctx) => {
55
55
  removeInternal(node, ctx);
56
- }
57
- }
58
- }
59
- }
56
+ },
57
+ },
58
+ };
59
+ };
@@ -8,7 +8,7 @@ export const TagDescriptionOverride: Oas3Decorator | Oas2Decorator = ({ tagNames
8
8
  leave(tag, { report }: UserContext) {
9
9
  if (!tagNames)
10
10
  throw new Error(
11
- `Parameter "tagNames" is not provided for "tag-description-override" rule`,
11
+ `Parameter "tagNames" is not provided for "tag-description-override" rule`
12
12
  );
13
13
  if (tagNames[tag.name]) {
14
14
  try {
@@ -63,7 +63,7 @@ export function getCodeframe(location: LineColLocationObject, color: boolean) {
63
63
  line: string,
64
64
  startIdx: number = -1,
65
65
  endIdx: number = +Infinity,
66
- variant = gray,
66
+ variant = gray
67
67
  ) {
68
68
  if (!color) return line;
69
69
  if (!line) return line;
@@ -84,14 +84,14 @@ function printPrefixedLines(lines: [string, string][]): string {
84
84
 
85
85
  const padLen = Math.max(...existingLines.map(([prefix]) => prefix.length));
86
86
  const dedentLen = Math.min(
87
- ...existingLines.map(([_, line]) => (line === '' ? Infinity : padSize(line))),
87
+ ...existingLines.map(([_, line]) => (line === '' ? Infinity : padSize(line)))
88
88
  );
89
89
 
90
90
  return existingLines
91
91
  .map(
92
92
  ([prefix, line]) =>
93
93
  gray(leftPad(padLen, prefix) + ' |') +
94
- (line ? ' ' + limitLineLength(line.substring(dedentLen)) : ''),
94
+ (line ? ' ' + limitLineLength(line.substring(dedentLen)) : '')
95
95
  )
96
96
  .join('\n');
97
97
  }
@@ -146,7 +146,7 @@ export function getLineColLocation(location: LocationObject): LineColLocationObj
146
146
  function positionsToLoc(
147
147
  source: string,
148
148
  startPos: number,
149
- endPos: number,
149
+ endPos: number
150
150
  ): { start: Loc; end: Loc } {
151
151
  let currentLine = 1;
152
152
  let currentCol = 1;
@@ -14,7 +14,7 @@ const coreVersion = require('../../package.json').version;
14
14
 
15
15
  import { NormalizedProblem, ProblemSeverity, LineColLocationObject, LocationObject } from '../walk';
16
16
  import { getCodeframe, getLineColLocation } from './codeframes';
17
- import { env } from "../config";
17
+ import { env } from '../config';
18
18
 
19
19
  export type Totals = {
20
20
  errors: number;
@@ -84,7 +84,7 @@ export function formatProblems(
84
84
  color?: boolean;
85
85
  totals: Totals;
86
86
  version: string;
87
- },
87
+ }
88
88
  ) {
89
89
  const {
90
90
  maxProblems = 100,
@@ -120,7 +120,7 @@ export function formatProblems(
120
120
  case 'stylish': {
121
121
  const groupedByFile = groupByFiles(problems);
122
122
  for (const [file, { ruleIdPad, locationPad: positionPad, fileProblems }] of Object.entries(
123
- groupedByFile,
123
+ groupedByFile
124
124
  )) {
125
125
  process.stderr.write(`${blue(path.relative(cwd, file))}:\n`);
126
126
 
@@ -156,8 +156,8 @@ export function formatProblems(
156
156
  if (totalProblems - ignoredProblems > maxProblems) {
157
157
  process.stderr.write(
158
158
  `< ... ${totalProblems - maxProblems} more problems hidden > ${gray(
159
- 'increase with `--max-problems N`',
160
- )}\n`,
159
+ 'increase with `--max-problems N`'
160
+ )}\n`
161
161
  );
162
162
  }
163
163
 
@@ -243,12 +243,12 @@ export function formatProblems(
243
243
  function formatStylish(problem: OnlyLineColProblem, locationPad: number, ruleIdPad: number) {
244
244
  const color = COLORS[problem.severity];
245
245
  if (!SEVERITY_NAMES[problem.severity]) {
246
- return 'Error not found severity. Please check your config file. Allowed values: \`warn,error,off\`'
246
+ return 'Error not found severity. Please check your config file. Allowed values: `warn,error,off`';
247
247
  }
248
248
  const severityName = color(SEVERITY_NAMES[problem.severity].toLowerCase().padEnd(7));
249
249
  const { start } = problem.location[0];
250
250
  return ` ${`${start.line}:${start.col}`.padEnd(
251
- locationPad,
251
+ locationPad
252
252
  )} ${severityName} ${problem.ruleId.padEnd(ruleIdPad)} ${problem.message}`;
253
253
  }
254
254
 
@@ -258,7 +258,7 @@ export function formatProblems(
258
258
  const message = xmlEscape(problem.message);
259
259
  const source = xmlEscape(problem.ruleId);
260
260
  process.stdout.write(
261
- `<error line="${line}" column="${col}" severity="${severity}" message="${message}" source="${source}" />\n`,
261
+ `<error line="${line}" column="${col}" severity="${severity}" message="${message}" source="${source}" />\n`
262
262
  );
263
263
  }
264
264
  }
@@ -307,12 +307,12 @@ const groupByFiles = (problems: NormalizedProblem[]) => {
307
307
  fileGroups[absoluteRef].fileProblems.push(mappedProblem);
308
308
  fileGroups[absoluteRef].ruleIdPad = Math.max(
309
309
  problem.ruleId.length,
310
- fileGroups[absoluteRef].ruleIdPad,
310
+ fileGroups[absoluteRef].ruleIdPad
311
311
  );
312
312
 
313
313
  fileGroups[absoluteRef].locationPad = Math.max(
314
314
  Math.max(...mappedProblem.location.map((loc) => `${loc.start.line}:${loc.start.col}`.length)),
315
- fileGroups[absoluteRef].locationPad,
315
+ fileGroups[absoluteRef].locationPad
316
316
  );
317
317
  }
318
318
 
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { BundleOutputFormat, readFileFromUrl, slash } from './utils';
1
+ export { BundleOutputFormat, readFileFromUrl, slash, doesYamlFileExist } from './utils';
2
2
  export { Oas3_1Types } from './types/oas3_1';
3
3
  export { Oas3Types } from './types/oas3';
4
4
  export { Oas2Types } from './types/oas2';
@@ -23,7 +23,7 @@ export { Stats } from './rules/other/stats';
23
23
 
24
24
  export {
25
25
  Config,
26
- LintConfig,
26
+ StyleguideConfig,
27
27
  RawConfig,
28
28
  IGNORE_FILE,
29
29
  Region,
@@ -33,10 +33,9 @@ export {
33
33
  getConfig,
34
34
  findConfig,
35
35
  CONFIG_FILE_NAMES,
36
- RuleSeverity
36
+ RuleSeverity,
37
37
  } from './config';
38
38
 
39
-
40
39
  export { RedoclyClient, isRedoclyRegistryURL } from './redocly';
41
40
 
42
41
  export {
@@ -1,18 +1,13 @@
1
1
  // TODO: add a type for "types" https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/js-yaml/index.d.ts
2
2
  // @ts-ignore
3
- import { JSON_SCHEMA, types, LoadOptions, DumpOptions, load, dump } from 'js-yaml';
3
+ import { JSON_SCHEMA, types, LoadOptions, DumpOptions, load, dump } from 'js-yaml';
4
4
 
5
5
  const DEFAULT_SCHEMA_WITHOUT_TIMESTAMP = JSON_SCHEMA.extend({
6
6
  implicit: [types.merge],
7
- explicit: [
8
- types.binary,
9
- types.omap,
10
- types.pairs,
11
- types.set,
12
- ],
7
+ explicit: [types.binary, types.omap, types.pairs, types.set],
13
8
  });
14
9
 
15
10
  export const parseYaml = (str: string, opts?: LoadOptions): unknown =>
16
- load(str, {schema: DEFAULT_SCHEMA_WITHOUT_TIMESTAMP, ...opts});
11
+ load(str, { schema: DEFAULT_SCHEMA_WITHOUT_TIMESTAMP, ...opts });
17
12
 
18
13
  export const stringifyYaml = (obj: any, opts?: DumpOptions): string => dump(obj, opts);