@redocly/openapi-core 1.3.0 → 1.4.0

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 (190) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/lib/benchmark/benches/lint-with-many-rules.bench.js +4 -4
  3. package/lib/benchmark/benches/lint-with-nested-rule.bench.js +4 -4
  4. package/lib/benchmark/benches/lint-with-no-rules.bench.js +4 -4
  5. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +4 -4
  6. package/lib/benchmark/benches/lint-with-top-level-rule.bench.js +4 -4
  7. package/lib/benchmark/benches/recommended-oas3.bench.js +4 -4
  8. package/lib/benchmark/benches/resolve-with-no-external.bench.js +3 -3
  9. package/lib/benchmark/utils.js +3 -3
  10. package/lib/bundle.d.ts +4 -4
  11. package/lib/bundle.js +23 -23
  12. package/lib/config/all.d.ts +2 -2
  13. package/lib/config/all.js +44 -8
  14. package/lib/config/builtIn.js +2 -0
  15. package/lib/config/config-resolvers.js +25 -25
  16. package/lib/config/config.js +9 -9
  17. package/lib/config/index.js +5 -1
  18. package/lib/config/load.d.ts +1 -1
  19. package/lib/config/load.js +6 -6
  20. package/lib/config/minimal.d.ts +2 -2
  21. package/lib/config/minimal.js +34 -3
  22. package/lib/config/recommended-strict.d.ts +3 -0
  23. package/lib/config/recommended-strict.js +92 -0
  24. package/lib/config/recommended.d.ts +2 -2
  25. package/lib/config/recommended.js +34 -3
  26. package/lib/config/rules.d.ts +1 -1
  27. package/lib/config/types.d.ts +47 -46
  28. package/lib/config/types.js +2 -2
  29. package/lib/config/utils.js +26 -14
  30. package/lib/decorators/common/filters/filter-helper.js +4 -4
  31. package/lib/decorators/common/filters/filter-in.js +2 -2
  32. package/lib/decorators/common/filters/filter-out.js +2 -2
  33. package/lib/decorators/common/info-description-override.js +1 -1
  34. package/lib/decorators/common/media-type-examples-override.js +3 -3
  35. package/lib/decorators/common/operation-description-override.js +1 -1
  36. package/lib/decorators/common/registry-dependencies.js +1 -1
  37. package/lib/decorators/common/remove-x-internal.js +4 -4
  38. package/lib/decorators/common/tag-description-override.js +1 -1
  39. package/lib/format/codeframes.d.ts +6 -6
  40. package/lib/format/format.d.ts +2 -2
  41. package/lib/format/format.js +12 -12
  42. package/lib/js-yaml/index.d.ts +2 -2
  43. package/lib/js-yaml/index.js +2 -2
  44. package/lib/lint.js +18 -18
  45. package/lib/oas-types.d.ts +12 -10
  46. package/lib/oas-types.js +2 -2
  47. package/lib/redocly/index.js +10 -10
  48. package/lib/redocly/registry-api.js +2 -2
  49. package/lib/resolve.d.ts +4 -4
  50. package/lib/resolve.js +18 -18
  51. package/lib/rules/ajv.js +1 -1
  52. package/lib/rules/async2/index.d.ts +2 -11
  53. package/lib/rules/common/assertions/asserts.d.ts +3 -3
  54. package/lib/rules/common/assertions/asserts.js +21 -21
  55. package/lib/rules/common/assertions/index.d.ts +4 -4
  56. package/lib/rules/common/assertions/index.js +3 -3
  57. package/lib/rules/common/assertions/utils.d.ts +4 -4
  58. package/lib/rules/common/assertions/utils.js +3 -3
  59. package/lib/rules/common/info-contact.js +1 -1
  60. package/lib/rules/common/info-license-url.js +1 -1
  61. package/lib/rules/common/info-license.js +1 -1
  62. package/lib/rules/common/no-enum-type-mismatch.js +3 -3
  63. package/lib/rules/common/no-http-verbs-in-paths.js +2 -2
  64. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  65. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  66. package/lib/rules/common/operation-2xx-response.js +2 -2
  67. package/lib/rules/common/operation-4xx-response.js +2 -2
  68. package/lib/rules/common/operation-description.js +1 -1
  69. package/lib/rules/common/operation-operationId.js +1 -1
  70. package/lib/rules/common/operation-summary.js +1 -1
  71. package/lib/rules/common/path-segment-plural.js +1 -1
  72. package/lib/rules/common/response-contains-header.js +2 -2
  73. package/lib/rules/common/spec-strict-refs.js +1 -1
  74. package/lib/rules/common/spec.js +11 -11
  75. package/lib/rules/common/tag-description.js +1 -1
  76. package/lib/rules/oas2/boolean-parameter-prefixes.d.ts +1 -1
  77. package/lib/rules/oas2/index.d.ts +2 -46
  78. package/lib/rules/oas2/remove-unused-components.js +1 -1
  79. package/lib/rules/oas2/request-mime-type.js +2 -2
  80. package/lib/rules/oas2/response-contains-property.js +2 -2
  81. package/lib/rules/oas2/response-mime-type.js +2 -2
  82. package/lib/rules/oas3/boolean-parameter-prefixes.d.ts +1 -1
  83. package/lib/rules/oas3/index.d.ts +1 -1
  84. package/lib/rules/oas3/index.js +1 -1
  85. package/lib/rules/oas3/no-invalid-media-type-examples.js +3 -3
  86. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +3 -3
  87. package/lib/rules/oas3/remove-unused-components.js +2 -2
  88. package/lib/rules/oas3/request-mime-type.js +3 -3
  89. package/lib/rules/oas3/response-contains-property.js +2 -2
  90. package/lib/rules/oas3/response-mime-type.js +3 -3
  91. package/lib/rules/utils.js +3 -3
  92. package/lib/types/asyncapi.js +21 -21
  93. package/lib/types/index.d.ts +8 -8
  94. package/lib/types/oas2.js +14 -14
  95. package/lib/types/oas3.js +27 -27
  96. package/lib/types/oas3_1.js +6 -6
  97. package/lib/types/redocly-yaml.d.ts +11 -0
  98. package/lib/types/redocly-yaml.js +71 -53
  99. package/lib/types/theme-config.js +1 -1
  100. package/lib/typings/common.d.ts +2 -2
  101. package/lib/typings/openapi.d.ts +6 -6
  102. package/lib/typings/swagger.d.ts +3 -3
  103. package/lib/utils.d.ts +5 -5
  104. package/lib/utils.js +3 -3
  105. package/lib/visitors.d.ts +40 -40
  106. package/lib/walk.d.ts +14 -15
  107. package/lib/walk.js +11 -11
  108. package/package.json +2 -2
  109. package/src/__tests__/lint.test.ts +40 -40
  110. package/src/__tests__/normalizeVisitors.test.ts +23 -5
  111. package/src/__tests__/ref-utils.test.ts +7 -7
  112. package/src/__tests__/resolve-http.test.ts +10 -10
  113. package/src/__tests__/resolve.test.ts +39 -39
  114. package/src/__tests__/walk.test.ts +48 -48
  115. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +95 -32
  116. package/src/config/__tests__/__snapshots__/config.test.ts.snap +81 -81
  117. package/src/config/__tests__/config-resolvers.test.ts +30 -1
  118. package/src/config/__tests__/config.test.ts +88 -88
  119. package/src/config/__tests__/load.test.ts +12 -8
  120. package/src/config/__tests__/utils.test.ts +18 -18
  121. package/src/config/all.ts +46 -9
  122. package/src/config/builtIn.ts +2 -0
  123. package/src/config/minimal.ts +36 -4
  124. package/src/config/recommended-strict.ts +93 -0
  125. package/src/config/recommended.ts +36 -4
  126. package/src/config/types.ts +22 -8
  127. package/src/config/utils.ts +15 -0
  128. package/src/decorators/common/media-type-examples-override.ts +2 -2
  129. package/src/lint.ts +3 -3
  130. package/src/oas-types.ts +26 -3
  131. package/src/rules/__tests__/no-unresolved-refs.test.ts +26 -26
  132. package/src/rules/async2/__tests__/channels-kebab-case.test.ts +12 -12
  133. package/src/rules/async2/__tests__/no-channel-trailing-slash.test.ts +7 -7
  134. package/src/rules/async2/index.ts +2 -1
  135. package/src/rules/common/__tests__/info-license.test.ts +6 -6
  136. package/src/rules/common/__tests__/license-url.test.ts +6 -6
  137. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +13 -13
  138. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +18 -18
  139. package/src/rules/common/__tests__/no-identical-paths.test.ts +5 -5
  140. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +12 -12
  141. package/src/rules/common/__tests__/operation-2xx-response.test.ts +18 -18
  142. package/src/rules/common/__tests__/operation-4xx-response.test.ts +23 -23
  143. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +6 -6
  144. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +5 -5
  145. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +16 -16
  146. package/src/rules/common/__tests__/operation-singular-tag.test.ts +6 -6
  147. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +10 -10
  148. package/src/rules/common/__tests__/path-not-include-query.test.ts +6 -6
  149. package/src/rules/common/__tests__/path-params-defined.test.ts +21 -21
  150. package/src/rules/common/__tests__/paths-kebab-case.test.ts +11 -11
  151. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +18 -18
  152. package/src/rules/common/__tests__/security-defined.test.ts +21 -21
  153. package/src/rules/common/__tests__/spec-strict-refs.test.ts +9 -9
  154. package/src/rules/common/__tests__/spec.test.ts +102 -102
  155. package/src/rules/common/__tests__/tag-description.test.ts +6 -6
  156. package/src/rules/common/__tests__/tags-alphabetical.test.ts +12 -12
  157. package/src/rules/common/assertions/__tests__/index.test.ts +15 -15
  158. package/src/rules/common/assertions/__tests__/utils.test.ts +9 -9
  159. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +7 -7
  160. package/src/rules/oas2/__tests__/response-contains-header.test.ts +13 -13
  161. package/src/rules/oas2/__tests__/response-contains-property.test.ts +8 -8
  162. package/src/rules/oas2/__tests__/spec/info.test.ts +21 -21
  163. package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
  164. package/src/rules/oas2/__tests__/spec/paths.test.ts +12 -12
  165. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +1 -1
  166. package/src/rules/oas2/index.ts +3 -1
  167. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +7 -7
  168. package/src/rules/oas3/__tests__/component-name-unique.test.ts +186 -186
  169. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +18 -18
  170. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +6 -6
  171. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +36 -36
  172. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +11 -11
  173. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +7 -7
  174. package/src/rules/oas3/__tests__/no-unused-components.test.ts +31 -31
  175. package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +15 -15
  176. package/src/rules/oas3/__tests__/response-contains-header.test.ts +26 -26
  177. package/src/rules/oas3/__tests__/response-contains-property.test.ts +27 -27
  178. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
  179. package/src/rules/oas3/__tests__/spec/info.test.ts +21 -21
  180. package/src/rules/oas3/__tests__/spec/operation.test.ts +10 -10
  181. package/src/rules/oas3/__tests__/spec/paths.test.ts +13 -13
  182. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +2 -2
  183. package/src/rules/oas3/__tests__/spec/servers.test.ts +25 -25
  184. package/src/rules/oas3/__tests__/spec/spec.test.ts +56 -56
  185. package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +28 -28
  186. package/src/rules/oas3/index.ts +3 -3
  187. package/src/types/redocly-yaml.ts +75 -40
  188. package/src/visitors.ts +3 -3
  189. package/src/walk.ts +23 -10
  190. package/tsconfig.tsbuildinfo +1 -1
@@ -35,7 +35,7 @@ export interface Oas3Paths {
35
35
  export interface OasRef {
36
36
  $ref: string;
37
37
  }
38
- export declare type Referenced<T> = OasRef | T;
38
+ export type Referenced<T> = OasRef | T;
39
39
  export interface Oas3PathItem {
40
40
  summary?: string;
41
41
  description?: string;
@@ -147,7 +147,7 @@ export interface Oas3Schema {
147
147
  xml?: Oas3Xml;
148
148
  'x-tags'?: string[];
149
149
  }
150
- export declare type Oas3_1Schema = Oas3Schema & {
150
+ export type Oas3_1Schema = Oas3Schema & {
151
151
  type?: string | string[];
152
152
  examples?: any[];
153
153
  };
@@ -183,8 +183,8 @@ export interface Oas3Encoding {
183
183
  explode: boolean;
184
184
  allowReserved: boolean;
185
185
  }
186
- export declare type Oas3ParameterLocation = 'query' | 'header' | 'path' | 'cookie';
187
- export declare type Oas3ParameterStyle = 'matrix' | 'label' | 'form' | 'simple' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject';
186
+ export type Oas3ParameterLocation = 'query' | 'header' | 'path' | 'cookie';
187
+ export type Oas3ParameterStyle = 'matrix' | 'label' | 'form' | 'simple' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject';
188
188
  export interface Oas3RequestBody {
189
189
  description?: string;
190
190
  required?: boolean;
@@ -210,7 +210,7 @@ export interface Oas3Response {
210
210
  export interface Oas3Link {
211
211
  $ref?: string;
212
212
  }
213
- export declare type Oas3Header = Omit<Oas3Parameter, 'in' | 'name'>;
213
+ export type Oas3Header = Omit<Oas3Parameter, 'in' | 'name'>;
214
214
  export interface Oas3Callback {
215
215
  [name: string]: Oas3PathItem;
216
216
  }
@@ -243,7 +243,7 @@ export interface Oas3Components {
243
243
  [name: string]: Referenced<Oas3Callback>;
244
244
  };
245
245
  }
246
- export declare type Oas3ComponentName = keyof Oas3Components;
246
+ export type Oas3ComponentName = keyof Oas3Components;
247
247
  export interface Oas3SecurityRequirement {
248
248
  [name: string]: string[];
249
249
  }
@@ -73,7 +73,7 @@ export interface Oas2Operation {
73
73
  'x-code-samples'?: Oas2XCodeSample[];
74
74
  'x-hideTryItPanel'?: boolean;
75
75
  }
76
- export declare type Oas2Parameter = Oas2BodyParameter | Oas2SimpleParameter;
76
+ export type Oas2Parameter = Oas2BodyParameter | Oas2SimpleParameter;
77
77
  export interface Oas2BodyParameter {
78
78
  name: string;
79
79
  in: 'body';
@@ -169,11 +169,11 @@ export interface Oas2Schema {
169
169
  xml?: Oas2Xml;
170
170
  'x-tags'?: string[];
171
171
  }
172
- export declare type Oas2ParameterLocation = 'query' | 'header' | 'path' | 'formData';
172
+ export type Oas2ParameterLocation = 'query' | 'header' | 'path' | 'formData';
173
173
  export interface Oas2Responses {
174
174
  [code: string]: Oas2Response;
175
175
  }
176
- export declare type Oas2Header = Oas2Items & {
176
+ export type Oas2Header = Oas2Items & {
177
177
  description?: 'string';
178
178
  };
179
179
  export interface Oas2Response {
package/lib/utils.d.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  import { UserContext } from './walk';
2
2
  import { HttpResolveConfig } from './config';
3
3
  export { parseYaml, stringifyYaml } from './js-yaml';
4
- export declare type StackFrame<T> = {
4
+ export type StackFrame<T> = {
5
5
  prev: StackFrame<T> | null;
6
6
  value: T;
7
7
  };
8
- export declare type Stack<T> = StackFrame<T> | null;
9
- export declare type StackNonEmpty<T> = StackFrame<T>;
8
+ export type Stack<T> = StackFrame<T> | null;
9
+ export type StackNonEmpty<T> = StackFrame<T>;
10
10
  export declare function pushStack<T, P extends Stack<T> = Stack<T>>(head: P, value: T): {
11
11
  prev: P;
12
12
  value: T;
13
13
  };
14
14
  export declare function popStack<T, P extends Stack<T>>(head: P): StackFrame<T> | null;
15
- export declare type BundleOutputFormat = 'json' | 'yml' | 'yaml';
15
+ export type BundleOutputFormat = 'json' | 'yml' | 'yaml';
16
16
  export declare function loadYaml<T>(filename: string): Promise<T>;
17
17
  export declare function isDefined<T>(x: T | undefined): x is T;
18
18
  export declare function isPlainObject(value: any): value is object;
@@ -44,7 +44,7 @@ export declare function isCustomRuleId(id: string): boolean;
44
44
  export declare function doesYamlFileExist(filePath: string): boolean;
45
45
  export declare function showWarningForDeprecatedField(deprecatedField: string, updatedField?: string, updatedObject?: string): void;
46
46
  export declare function showErrorForDeprecatedField(deprecatedField: string, updatedField?: string, updatedObject?: string): void;
47
- export declare type Falsy = undefined | null | false | '' | 0;
47
+ export type Falsy = undefined | null | false | '' | 0;
48
48
  export declare function isTruthy<Truthy>(value: Truthy | Falsy): value is Truthy;
49
49
  export declare function identity<T>(value: T): T;
50
50
  export declare function keysOf<T>(obj: T): (keyof T)[];
package/lib/utils.js CHANGED
@@ -33,7 +33,7 @@ exports.popStack = popStack;
33
33
  function loadYaml(filename) {
34
34
  return __awaiter(this, void 0, void 0, function* () {
35
35
  const contents = yield fs.promises.readFile(filename, 'utf-8');
36
- return js_yaml_1.parseYaml(contents);
36
+ return (0, js_yaml_1.parseYaml)(contents);
37
37
  });
38
38
  }
39
39
  exports.loadYaml = loadYaml;
@@ -141,7 +141,7 @@ function readFileAsStringSync(filePath) {
141
141
  exports.readFileAsStringSync = readFileAsStringSync;
142
142
  function yamlAndJsonSyncReader(filePath) {
143
143
  const content = fs.readFileSync(filePath, 'utf-8');
144
- return js_yaml_1.parseYaml(content);
144
+ return (0, js_yaml_1.parseYaml)(content);
145
145
  }
146
146
  exports.yamlAndJsonSyncReader = yamlAndJsonSyncReader;
147
147
  function isPathParameter(pathSegment) {
@@ -189,7 +189,7 @@ function isCustomRuleId(id) {
189
189
  }
190
190
  exports.isCustomRuleId = isCustomRuleId;
191
191
  function doesYamlFileExist(filePath) {
192
- return ((path_1.extname(filePath) === '.yaml' || path_1.extname(filePath) === '.yml') &&
192
+ return (((0, path_1.extname)(filePath) === '.yaml' || (0, path_1.extname)(filePath) === '.yml') &&
193
193
  fs.hasOwnProperty('existsSync') &&
194
194
  fs.existsSync(filePath));
195
195
  }
package/lib/visitors.d.ts CHANGED
@@ -5,20 +5,20 @@ import type { Stack } from './utils';
5
5
  import type { UserContext, ResolveResult, ProblemSeverity } from './walk';
6
6
  import type { Location } from './ref-utils';
7
7
  import { Async2Definition } from './typings/asyncapi';
8
- export declare type SkipFunctionContext = Pick<UserContext, 'location' | 'rawNode' | 'resolve' | 'rawLocation'>;
9
- export declare type VisitFunction<T> = (node: T, ctx: UserContext & {
8
+ export type SkipFunctionContext = Pick<UserContext, 'location' | 'rawNode' | 'resolve' | 'rawLocation'>;
9
+ export type VisitFunction<T> = (node: T, ctx: UserContext & {
10
10
  ignoreNextVisitorsOnNode: () => void;
11
11
  }, parents?: any, context?: any) => void;
12
- declare type VisitRefFunction = (node: OasRef, ctx: UserContext, resolved: ResolveResult<any>) => void;
13
- declare type SkipFunction<T> = (node: T, key: string | number, ctx: SkipFunctionContext) => boolean;
14
- declare type VisitObject<T> = {
12
+ type VisitRefFunction = (node: OasRef, ctx: UserContext, resolved: ResolveResult<any>) => void;
13
+ type SkipFunction<T> = (node: T, key: string | number, ctx: SkipFunctionContext) => boolean;
14
+ type VisitObject<T> = {
15
15
  enter?: VisitFunction<T>;
16
16
  leave?: VisitFunction<T>;
17
17
  skip?: SkipFunction<T>;
18
18
  };
19
- declare type NestedVisitObject<T, P> = VisitObject<T> & NestedVisitor<P>;
20
- declare type VisitFunctionOrObject<T> = VisitFunction<T> | VisitObject<T>;
21
- declare type VisitorNode<T> = {
19
+ export type NestedVisitObject<T, P> = VisitObject<T> & NestedVisitor<P>;
20
+ type VisitFunctionOrObject<T> = VisitFunction<T> | VisitObject<T>;
21
+ export type VisitorNode<T> = {
22
22
  ruleId: string;
23
23
  severity: ProblemSeverity;
24
24
  context: VisitorLevelContext | VisitorSkippedLevelContext;
@@ -26,14 +26,14 @@ declare type VisitorNode<T> = {
26
26
  visit: VisitFunction<T>;
27
27
  skip?: SkipFunction<T>;
28
28
  };
29
- declare type VisitorRefNode = {
29
+ type VisitorRefNode = {
30
30
  ruleId: string;
31
31
  severity: ProblemSeverity;
32
32
  context: VisitorLevelContext;
33
33
  depth: number;
34
34
  visit: VisitRefFunction;
35
35
  };
36
- export declare type VisitorLevelContext = {
36
+ export type VisitorLevelContext = {
37
37
  isSkippedLevel: false;
38
38
  type: NormalizedNodeType;
39
39
  parent: VisitorLevelContext | null;
@@ -45,13 +45,13 @@ export declare type VisitorLevelContext = {
45
45
  location?: Location;
46
46
  }>;
47
47
  };
48
- export declare type VisitorSkippedLevelContext = {
48
+ export type VisitorSkippedLevelContext = {
49
49
  isSkippedLevel: true;
50
50
  parent: VisitorLevelContext;
51
51
  seen: Set<any>;
52
52
  };
53
- declare type NormalizeVisitor<Fn> = Fn extends VisitFunction<infer T> ? VisitorNode<T> : never;
54
- export declare type BaseVisitor = {
53
+ export type NormalizeVisitor<Fn> = Fn extends VisitFunction<infer T> ? VisitorNode<T> : never;
54
+ export type BaseVisitor = {
55
55
  any?: {
56
56
  enter?: VisitFunction<any>;
57
57
  leave?: VisitFunction<any>;
@@ -62,7 +62,7 @@ export declare type BaseVisitor = {
62
62
  leave?: VisitRefFunction;
63
63
  } | VisitRefFunction;
64
64
  };
65
- declare type Oas3FlatVisitor = {
65
+ type Oas3FlatVisitor = {
66
66
  Root?: VisitFunctionOrObject<Oas3Definition>;
67
67
  Tag?: VisitFunctionOrObject<Oas3Tag>;
68
68
  ExternalDocs?: VisitFunctionOrObject<Oas3ExternalDocs>;
@@ -110,7 +110,7 @@ declare type Oas3FlatVisitor = {
110
110
  SecurityScheme?: VisitFunctionOrObject<Oas3SecurityScheme>;
111
111
  SpecExtension?: VisitFunctionOrObject<unknown>;
112
112
  };
113
- declare type Oas2FlatVisitor = {
113
+ type Oas2FlatVisitor = {
114
114
  Root?: VisitFunctionOrObject<Oas2Definition>;
115
115
  Tag?: VisitFunctionOrObject<Oas2Tag>;
116
116
  ExternalDocs?: VisitFunctionOrObject<Oas2ExternalDocs>;
@@ -135,26 +135,26 @@ declare type Oas2FlatVisitor = {
135
135
  SecurityScheme?: VisitFunctionOrObject<Oas2SecurityScheme>;
136
136
  SpecExtension?: VisitFunctionOrObject<unknown>;
137
137
  };
138
- declare type Async2FlatVisitor = {
138
+ type Async2FlatVisitor = {
139
139
  Root?: VisitFunctionOrObject<Async2Definition>;
140
140
  };
141
- declare type Oas3NestedVisitor = {
141
+ type Oas3NestedVisitor = {
142
142
  [T in keyof Oas3FlatVisitor]: Oas3FlatVisitor[T] extends Function ? Oas3FlatVisitor[T] : Oas3FlatVisitor[T] & NestedVisitor<Oas3NestedVisitor>;
143
143
  };
144
- declare type Oas2NestedVisitor = {
144
+ type Oas2NestedVisitor = {
145
145
  [T in keyof Oas2FlatVisitor]: Oas2FlatVisitor[T] extends Function ? Oas2FlatVisitor[T] : Oas2FlatVisitor[T] & NestedVisitor<Oas2NestedVisitor>;
146
146
  };
147
- declare type Async2NestedVisitor = {
147
+ type Async2NestedVisitor = {
148
148
  [T in keyof Async2FlatVisitor]: Async2FlatVisitor[T] extends Function ? Async2FlatVisitor[T] : Async2FlatVisitor[T] & NestedVisitor<Async2NestedVisitor>;
149
149
  };
150
- export declare type Oas3Visitor = BaseVisitor & Oas3NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas3NestedVisitor>>;
151
- export declare type Oas2Visitor = BaseVisitor & Oas2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas2NestedVisitor>>;
152
- export declare type Async2Visitor = BaseVisitor & Async2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Async2NestedVisitor>>;
153
- export declare type Oas3TransformVisitor = BaseVisitor & Oas3FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
154
- export declare type Oas2TransformVisitor = BaseVisitor & Oas2FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
155
- export declare type Async2TransformVisitor = BaseVisitor & Async2FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
156
- export declare type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | 'Root'>;
157
- export declare type NormalizedOasVisitors<T extends BaseVisitor> = {
150
+ export type Oas3Visitor = BaseVisitor & Oas3NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas3NestedVisitor>>;
151
+ export type Oas2Visitor = BaseVisitor & Oas2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas2NestedVisitor>>;
152
+ export type Async2Visitor = BaseVisitor & Async2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Async2NestedVisitor>>;
153
+ export type Oas3TransformVisitor = BaseVisitor & Oas3FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
154
+ export type Oas2TransformVisitor = BaseVisitor & Oas2FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
155
+ export type Async2TransformVisitor = BaseVisitor & Async2FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
156
+ export type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | 'Root'>;
157
+ export type NormalizedOasVisitors<T extends BaseVisitor> = {
158
158
  [V in keyof T]-?: {
159
159
  enter: Array<NormalizeVisitor<T[V]>>;
160
160
  leave: Array<NormalizeVisitor<T[V]>>;
@@ -169,19 +169,19 @@ export declare type NormalizedOasVisitors<T extends BaseVisitor> = {
169
169
  leave: Array<VisitorNode<any>>;
170
170
  };
171
171
  };
172
- export declare type Oas3Rule = (options: Record<string, any>) => Oas3Visitor | Oas3Visitor[];
173
- export declare type Oas2Rule = (options: Record<string, any>) => Oas2Visitor | Oas2Visitor[];
174
- export declare type Async2Rule = (options: Record<string, any>) => Async2Visitor | Async2Visitor[];
175
- export declare type Oas3Preprocessor = (options: Record<string, any>) => Oas3TransformVisitor;
176
- export declare type Oas2Preprocessor = (options: Record<string, any>) => Oas2TransformVisitor;
177
- export declare type Async2Preprocessor = (options: Record<string, any>) => Async2TransformVisitor;
178
- export declare type Oas3Decorator = (options: Record<string, any>) => Oas3TransformVisitor;
179
- export declare type Oas2Decorator = (options: Record<string, any>) => Oas2TransformVisitor;
180
- export declare type Async2Decorator = (options: Record<string, any>) => Async2TransformVisitor;
181
- export declare type OasRule = Oas3Rule;
182
- export declare type OasPreprocessor = Oas3Preprocessor;
183
- export declare type OasDecorator = Oas3Decorator;
184
- export declare type RuleInstanceConfig = {
172
+ export type Oas3Rule = (options: Record<string, any>) => Oas3Visitor | Oas3Visitor[];
173
+ export type Oas2Rule = (options: Record<string, any>) => Oas2Visitor | Oas2Visitor[];
174
+ export type Async2Rule = (options: Record<string, any>) => Async2Visitor | Async2Visitor[];
175
+ export type Oas3Preprocessor = (options: Record<string, any>) => Oas3TransformVisitor;
176
+ export type Oas2Preprocessor = (options: Record<string, any>) => Oas2TransformVisitor;
177
+ export type Async2Preprocessor = (options: Record<string, any>) => Async2TransformVisitor;
178
+ export type Oas3Decorator = (options: Record<string, any>) => Oas3TransformVisitor;
179
+ export type Oas2Decorator = (options: Record<string, any>) => Oas2TransformVisitor;
180
+ export type Async2Decorator = (options: Record<string, any>) => Async2TransformVisitor;
181
+ export type OasRule = Oas3Rule;
182
+ export type OasPreprocessor = Oas3Preprocessor;
183
+ export type OasDecorator = Oas3Decorator;
184
+ export type RuleInstanceConfig = {
185
185
  ruleId: string;
186
186
  severity: ProblemSeverity;
187
187
  };
package/lib/walk.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import type { Referenced } from './typings/openapi';
2
- import type { NormalizedOasVisitors } from './visitors';
2
+ import type { NormalizedOasVisitors, BaseVisitor } from './visitors';
3
3
  import type { ResolvedRefMap, Document } from './resolve';
4
4
  import type { NormalizedNodeType } from './types';
5
5
  import type { RuleSeverity } from './config';
6
6
  import { Location } from './ref-utils';
7
7
  import { ResolveError, YamlParseError, Source } from './resolve';
8
8
  import { SpecVersion } from './oas-types';
9
- declare type NonUndefined = string | number | boolean | symbol | bigint | object | Record<string, any>;
10
- export declare type ResolveResult<T extends NonUndefined> = {
9
+ export type NonUndefined = string | number | boolean | symbol | bigint | object | Record<string, any>;
10
+ export type ResolveResult<T extends NonUndefined> = {
11
11
  node: T;
12
12
  location: Location;
13
13
  error?: ResolveError | YamlParseError;
@@ -16,8 +16,8 @@ export declare type ResolveResult<T extends NonUndefined> = {
16
16
  location: undefined;
17
17
  error?: ResolveError | YamlParseError;
18
18
  };
19
- export declare type ResolveFn = <T>(node: Referenced<T>, from?: string) => ResolveResult<T>;
20
- export declare type UserContext = {
19
+ export type ResolveFn = <T extends NonUndefined>(node: Referenced<T>, from?: string) => ResolveResult<T>;
20
+ export type UserContext = {
21
21
  report(problem: Problem): void;
22
22
  location: Location;
23
23
  rawNode: any;
@@ -30,23 +30,23 @@ export declare type UserContext = {
30
30
  oasVersion: SpecVersion;
31
31
  getVisitorData: () => Record<string, unknown>;
32
32
  };
33
- export declare type Loc = {
33
+ export type Loc = {
34
34
  line: number;
35
35
  col: number;
36
36
  };
37
- export declare type PointerLocationObject = {
37
+ export type PointerLocationObject = {
38
38
  source: Source;
39
39
  reportOnKey?: boolean;
40
40
  pointer: string;
41
41
  };
42
- export declare type LineColLocationObject = Omit<PointerLocationObject, 'pointer'> & {
42
+ export type LineColLocationObject = Omit<PointerLocationObject, 'pointer'> & {
43
43
  pointer: undefined;
44
44
  start: Loc;
45
45
  end?: Loc;
46
46
  };
47
- export declare type LocationObject = LineColLocationObject | PointerLocationObject;
48
- export declare type ProblemSeverity = 'error' | 'warn';
49
- export declare type Problem = {
47
+ export type LocationObject = LineColLocationObject | PointerLocationObject;
48
+ export type ProblemSeverity = 'error' | 'warn';
49
+ export type Problem = {
50
50
  message: string;
51
51
  suggest?: string[];
52
52
  location?: Partial<LocationObject> | Array<Partial<LocationObject>>;
@@ -54,7 +54,7 @@ export declare type Problem = {
54
54
  forceSeverity?: RuleSeverity;
55
55
  ruleId?: string;
56
56
  };
57
- export declare type NormalizedProblem = {
57
+ export type NormalizedProblem = {
58
58
  message: string;
59
59
  ruleId: string;
60
60
  severity: ProblemSeverity;
@@ -63,17 +63,16 @@ export declare type NormalizedProblem = {
63
63
  suggest: string[];
64
64
  ignored?: boolean;
65
65
  };
66
- export declare type WalkContext = {
66
+ export type WalkContext = {
67
67
  problems: NormalizedProblem[];
68
68
  oasVersion: SpecVersion;
69
69
  visitorsData: Record<string, Record<string, unknown>>;
70
70
  refTypes?: Map<string, NormalizedNodeType>;
71
71
  };
72
- export declare function walkDocument<T>(opts: {
72
+ export declare function walkDocument<T extends BaseVisitor>(opts: {
73
73
  document: Document;
74
74
  rootType: NormalizedNodeType;
75
75
  normalizedVisitors: NormalizedOasVisitors<T>;
76
76
  resolvedRefMap: ResolvedRefMap;
77
77
  ctx: WalkContext;
78
78
  }): void;
79
- export {};
package/lib/walk.js CHANGED
@@ -33,9 +33,9 @@ function walkDocument(opts) {
33
33
  function walkNode(node, type, location, parent, key) {
34
34
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
35
35
  const resolve = (ref, from = currentLocation.source.absoluteRef) => {
36
- if (!ref_utils_1.isRef(ref))
36
+ if (!(0, ref_utils_1.isRef)(ref))
37
37
  return { location, node: ref };
38
- const refId = resolve_1.makeRefId(from, ref.$ref);
38
+ const refId = (0, resolve_1.makeRefId)(from, ref.$ref);
39
39
  const resolvedRef = resolvedRefMap.get(refId);
40
40
  if (!resolvedRef) {
41
41
  return {
@@ -55,7 +55,7 @@ function walkDocument(opts) {
55
55
  let currentLocation = location;
56
56
  const { node: resolvedNode, location: resolvedLocation, error } = resolve(node);
57
57
  const enteredContexts = new Set();
58
- if (ref_utils_1.isRef(node)) {
58
+ if ((0, ref_utils_1.isRef)(node)) {
59
59
  const refEnterVisitors = normalizedVisitors.ref.enter;
60
60
  for (const { visit: visitor, ruleId, severity, context } of refEnterVisitors) {
61
61
  enteredContexts.add(context);
@@ -120,10 +120,10 @@ function walkDocument(opts) {
120
120
  rawNode: node,
121
121
  })))) !== null && _k !== void 0 ? _k : false,
122
122
  };
123
- context.activatedOn = utils_1.pushStack(context.activatedOn, activatedOn);
123
+ context.activatedOn = (0, utils_1.pushStack)(context.activatedOn, activatedOn);
124
124
  let ctx = context.parent;
125
125
  while (ctx) {
126
- ctx.activatedOn.value.nextLevelTypeActivated = utils_1.pushStack(ctx.activatedOn.value.nextLevelTypeActivated, type);
126
+ ctx.activatedOn.value.nextLevelTypeActivated = (0, utils_1.pushStack)(ctx.activatedOn.value.nextLevelTypeActivated, type);
127
127
  ctx = ctx.parent;
128
128
  }
129
129
  if (!activatedOn.skipped) {
@@ -154,7 +154,7 @@ function walkDocument(opts) {
154
154
  else if (type.extensionsPrefix) {
155
155
  props.push(...Object.keys(resolvedNode).filter((k) => k.startsWith(type.extensionsPrefix)));
156
156
  }
157
- if (ref_utils_1.isRef(node)) {
157
+ if ((0, ref_utils_1.isRef)(node)) {
158
158
  props.push(...Object.keys(node).filter((k) => k !== '$ref' && !props.includes(k))); // properties on the same level as $ref
159
159
  }
160
160
  for (const propName of props) {
@@ -174,14 +174,14 @@ function walkDocument(opts) {
174
174
  propName.startsWith(type.extensionsPrefix)) {
175
175
  propType = types_1.SpecExtension;
176
176
  }
177
- if (!types_1.isNamedType(propType) && (propType === null || propType === void 0 ? void 0 : propType.directResolveAs)) {
177
+ if (!(0, types_1.isNamedType)(propType) && (propType === null || propType === void 0 ? void 0 : propType.directResolveAs)) {
178
178
  propType = propType.directResolveAs;
179
179
  value = { $ref: value };
180
180
  }
181
181
  if (propType && propType.name === undefined && propType.resolvable !== false) {
182
182
  propType = { name: 'scalar', properties: {} };
183
183
  }
184
- if (!types_1.isNamedType(propType) || (propType.name === 'scalar' && !ref_utils_1.isRef(value))) {
184
+ if (!(0, types_1.isNamedType)(propType) || (propType.name === 'scalar' && !(0, ref_utils_1.isRef)(value))) {
185
185
  continue;
186
186
  }
187
187
  walkNode(value, propType, loc.child([propName]), resolvedNode, propName);
@@ -195,11 +195,11 @@ function walkDocument(opts) {
195
195
  context.seen.delete(resolvedNode);
196
196
  }
197
197
  else {
198
- context.activatedOn = utils_1.popStack(context.activatedOn);
198
+ context.activatedOn = (0, utils_1.popStack)(context.activatedOn);
199
199
  if (context.parent) {
200
200
  let ctx = context.parent;
201
201
  while (ctx) {
202
- ctx.activatedOn.value.nextLevelTypeActivated = utils_1.popStack(ctx.activatedOn.value.nextLevelTypeActivated);
202
+ ctx.activatedOn.value.nextLevelTypeActivated = (0, utils_1.popStack)(ctx.activatedOn.value.nextLevelTypeActivated);
203
203
  ctx = ctx.parent;
204
204
  }
205
205
  }
@@ -212,7 +212,7 @@ function walkDocument(opts) {
212
212
  }
213
213
  }
214
214
  currentLocation = location;
215
- if (ref_utils_1.isRef(node)) {
215
+ if ((0, ref_utils_1.isRef)(node)) {
216
216
  const refLeaveVisitors = normalizedVisitors.ref.leave;
217
217
  for (const { visit: visitor, ruleId, severity, context } of refLeaveVisitors) {
218
218
  if (enteredContexts.has(context)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/openapi-core",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "engines": {
@@ -52,6 +52,6 @@
52
52
  "@types/minimatch": "^3.0.5",
53
53
  "@types/node-fetch": "^2.5.7",
54
54
  "@types/pluralize": "^0.0.29",
55
- "typescript": "^4.0.5"
55
+ "typescript": "^5.2.2"
56
56
  }
57
57
  }