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

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 (159) hide show
  1. package/README.md +2 -2
  2. package/lib/benchmark/benches/resolve-with-no-external.bench.js +1 -1
  3. package/lib/bundle.d.ts +1 -1
  4. package/lib/bundle.js +4 -4
  5. package/lib/config/all.js +3 -1
  6. package/lib/config/config-resolvers.js +22 -4
  7. package/lib/config/config.d.ts +1 -0
  8. package/lib/config/config.js +1 -0
  9. package/lib/config/load.d.ts +8 -2
  10. package/lib/config/load.js +4 -2
  11. package/lib/config/minimal.js +3 -1
  12. package/lib/config/recommended.js +3 -1
  13. package/lib/config/rules.js +1 -1
  14. package/lib/config/types.d.ts +17 -0
  15. package/lib/config/utils.d.ts +2 -2
  16. package/lib/config/utils.js +44 -6
  17. package/lib/decorators/common/registry-dependencies.js +1 -1
  18. package/lib/format/format.d.ts +1 -1
  19. package/lib/format/format.js +22 -1
  20. package/lib/lint.js +2 -2
  21. package/lib/redocly/registry-api.d.ts +0 -1
  22. package/lib/redocly/registry-api.js +5 -4
  23. package/lib/resolve.js +3 -1
  24. package/lib/rules/ajv.d.ts +1 -1
  25. package/lib/rules/ajv.js +5 -5
  26. package/lib/rules/common/assertions/asserts.d.ts +3 -5
  27. package/lib/rules/common/assertions/asserts.js +137 -97
  28. package/lib/rules/common/assertions/index.js +2 -6
  29. package/lib/rules/common/assertions/utils.d.ts +12 -6
  30. package/lib/rules/common/assertions/utils.js +33 -20
  31. package/lib/rules/common/no-ambiguous-paths.js +1 -1
  32. package/lib/rules/common/no-identical-paths.js +1 -1
  33. package/lib/rules/common/operation-2xx-response.js +1 -1
  34. package/lib/rules/common/operation-4xx-response.js +1 -1
  35. package/lib/rules/common/operation-operationId.js +1 -1
  36. package/lib/rules/common/operation-tag-defined.js +1 -1
  37. package/lib/rules/common/path-not-include-query.js +1 -1
  38. package/lib/rules/common/security-defined.d.ts +2 -0
  39. package/lib/rules/common/{operation-security-defined.js → security-defined.js} +18 -4
  40. package/lib/rules/common/spec.js +12 -1
  41. package/lib/rules/common/tags-alphabetical.js +1 -1
  42. package/lib/rules/oas2/index.d.ts +1 -1
  43. package/lib/rules/oas2/index.js +2 -2
  44. package/lib/rules/oas2/remove-unused-components.js +1 -1
  45. package/lib/rules/oas2/request-mime-type.js +1 -1
  46. package/lib/rules/oas2/response-mime-type.js +1 -1
  47. package/lib/rules/oas3/index.js +6 -2
  48. package/lib/rules/oas3/no-empty-servers.js +1 -1
  49. package/lib/rules/oas3/no-server-variables-empty-enum.js +1 -1
  50. package/lib/rules/oas3/no-unused-components.js +1 -1
  51. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +5 -0
  52. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +36 -0
  53. package/lib/rules/oas3/remove-unused-components.js +1 -1
  54. package/lib/rules/oas3/request-mime-type.js +1 -1
  55. package/lib/rules/oas3/response-mime-type.js +1 -1
  56. package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
  57. package/lib/rules/oas3/spec-components-invalid-map-name.js +46 -0
  58. package/lib/rules/other/stats.d.ts +2 -2
  59. package/lib/rules/other/stats.js +2 -2
  60. package/lib/rules/utils.js +1 -1
  61. package/lib/types/oas2.js +5 -5
  62. package/lib/types/oas3.js +27 -20
  63. package/lib/types/oas3_1.js +3 -3
  64. package/lib/types/redocly-yaml.js +60 -54
  65. package/lib/utils.d.ts +3 -3
  66. package/lib/utils.js +5 -5
  67. package/lib/visitors.d.ts +11 -11
  68. package/lib/visitors.js +13 -1
  69. package/package.json +3 -5
  70. package/src/__tests__/__snapshots__/bundle.test.ts.snap +3 -3
  71. package/src/__tests__/fixtures/extension.js +3 -3
  72. package/src/__tests__/format.test.ts +76 -0
  73. package/src/__tests__/lint.test.ts +184 -121
  74. package/src/__tests__/resolve-http.test.ts +1 -1
  75. package/src/__tests__/resolve.test.ts +9 -9
  76. package/src/__tests__/walk.test.ts +78 -10
  77. package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
  78. package/src/bundle.ts +4 -4
  79. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +6 -2
  80. package/src/config/__tests__/config-resolvers.test.ts +37 -1
  81. package/src/config/__tests__/config.test.ts +5 -0
  82. package/src/config/__tests__/fixtures/plugin-config.yaml +2 -3
  83. package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +11 -12
  84. package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +7 -8
  85. package/src/config/__tests__/fixtures/resolve-config/local-config-with-custom-function.yaml +16 -0
  86. package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +18 -19
  87. package/src/config/__tests__/fixtures/resolve-config/local-config-with-wrong-custom-function.yaml +16 -0
  88. package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +9 -10
  89. package/src/config/__tests__/fixtures/resolve-config/plugin.js +11 -0
  90. package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +3 -4
  91. package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +4 -5
  92. package/src/config/__tests__/load.test.ts +13 -16
  93. package/src/config/__tests__/resolve-plugins.test.ts +3 -3
  94. package/src/config/__tests__/utils.test.ts +64 -4
  95. package/src/config/all.ts +3 -1
  96. package/src/config/config-resolvers.ts +30 -7
  97. package/src/config/config.ts +2 -0
  98. package/src/config/load.ts +13 -6
  99. package/src/config/minimal.ts +3 -1
  100. package/src/config/recommended.ts +3 -1
  101. package/src/config/rules.ts +2 -2
  102. package/src/config/types.ts +24 -0
  103. package/src/config/utils.ts +103 -13
  104. package/src/decorators/common/registry-dependencies.ts +1 -1
  105. package/src/format/format.ts +32 -2
  106. package/src/lint.ts +2 -2
  107. package/src/redocly/registry-api.ts +5 -4
  108. package/src/resolve.ts +3 -1
  109. package/src/rules/__tests__/utils.test.ts +1 -1
  110. package/src/rules/ajv.ts +4 -4
  111. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +1 -0
  112. package/src/rules/common/__tests__/operation-2xx-response.test.ts +1 -1
  113. package/src/rules/common/__tests__/operation-4xx-response.test.ts +26 -3
  114. package/src/rules/common/__tests__/security-defined.test.ts +175 -0
  115. package/src/rules/common/__tests__/spec.test.ts +79 -0
  116. package/src/rules/common/assertions/__tests__/asserts.test.ts +491 -428
  117. package/src/rules/common/assertions/__tests__/utils.test.ts +2 -2
  118. package/src/rules/common/assertions/asserts.ts +155 -97
  119. package/src/rules/common/assertions/index.ts +2 -11
  120. package/src/rules/common/assertions/utils.ts +66 -36
  121. package/src/rules/common/no-ambiguous-paths.ts +1 -1
  122. package/src/rules/common/no-identical-paths.ts +1 -1
  123. package/src/rules/common/operation-2xx-response.ts +1 -1
  124. package/src/rules/common/operation-4xx-response.ts +1 -1
  125. package/src/rules/common/operation-operationId.ts +1 -1
  126. package/src/rules/common/operation-tag-defined.ts +1 -1
  127. package/src/rules/common/path-not-include-query.ts +1 -1
  128. package/src/rules/common/{operation-security-defined.ts → security-defined.ts} +19 -4
  129. package/src/rules/common/spec.ts +15 -1
  130. package/src/rules/common/tags-alphabetical.ts +1 -1
  131. package/src/rules/oas2/index.ts +2 -2
  132. package/src/rules/oas2/remove-unused-components.ts +1 -1
  133. package/src/rules/oas2/request-mime-type.ts +1 -1
  134. package/src/rules/oas2/response-mime-type.ts +1 -1
  135. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +51 -2
  136. package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +145 -0
  137. package/src/rules/oas3/__tests__/spec/spec.test.ts +10 -0
  138. package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +217 -0
  139. package/src/rules/oas3/index.ts +6 -2
  140. package/src/rules/oas3/no-empty-servers.ts +1 -1
  141. package/src/rules/oas3/no-server-variables-empty-enum.ts +1 -1
  142. package/src/rules/oas3/no-unused-components.ts +1 -1
  143. package/src/rules/oas3/operation-4xx-problem-details-rfc7807.ts +36 -0
  144. package/src/rules/oas3/remove-unused-components.ts +1 -1
  145. package/src/rules/oas3/request-mime-type.ts +1 -1
  146. package/src/rules/oas3/response-mime-type.ts +1 -1
  147. package/src/rules/oas3/spec-components-invalid-map-name.ts +53 -0
  148. package/src/rules/other/stats.ts +2 -2
  149. package/src/rules/utils.ts +2 -1
  150. package/src/types/index.ts +2 -2
  151. package/src/types/oas2.ts +5 -5
  152. package/src/types/oas3.ts +27 -20
  153. package/src/types/oas3_1.ts +3 -3
  154. package/src/types/redocly-yaml.ts +66 -38
  155. package/src/utils.ts +11 -7
  156. package/src/visitors.ts +29 -13
  157. package/tsconfig.tsbuildinfo +1 -1
  158. package/lib/rules/common/operation-security-defined.d.ts +0 -2
  159. package/src/rules/common/__tests__/operation-security-defined.test.ts +0 -69
@@ -11,6 +11,7 @@ const builtInRulesList = [
11
11
  'info-license-url',
12
12
  'operation-2xx-response',
13
13
  'operation-4xx-response',
14
+ 'operation-4xx-problem-details-rfc7807',
14
15
  'assertions',
15
16
  'operation-operationId-unique',
16
17
  'operation-parameters-unique',
@@ -34,7 +35,7 @@ const builtInRulesList = [
34
35
  'path-params-defined',
35
36
  'parameter-description',
36
37
  'operation-singular-tag',
37
- 'operation-security-defined',
38
+ 'security-defined',
38
39
  'no-unresolved-refs',
39
40
  'paths-kebab-case',
40
41
  'boolean-parameter-prefixes',
@@ -54,31 +55,38 @@ const builtInRulesList = [
54
55
  'response-contains-header',
55
56
  'response-contains-property',
56
57
  'scalar-property-missing-example',
58
+ 'spec-components-invalid-map-name',
57
59
  ];
58
60
  const nodeTypesList = [
59
- 'DefinitionRoot',
61
+ 'Root',
60
62
  'Tag',
61
63
  'ExternalDocs',
62
64
  'Server',
63
65
  'ServerVariable',
66
+ 'ServerVariablesMap',
64
67
  'SecurityRequirement',
65
68
  'Info',
66
69
  'Contact',
67
70
  'License',
68
- 'PathMap',
71
+ 'PathsMap',
69
72
  'PathItem',
70
73
  'Parameter',
71
74
  'Operation',
72
75
  'Callback',
76
+ 'CallbacksMap',
73
77
  'RequestBody',
74
- 'MediaTypeMap',
78
+ 'MediaTypesMap',
75
79
  'MediaType',
76
80
  'Example',
81
+ 'ExamplesMap',
77
82
  'Encoding',
83
+ 'EncodingsMap',
78
84
  'Header',
85
+ 'HeadersMap',
79
86
  'ResponsesMap',
80
87
  'Response',
81
88
  'Link',
89
+ 'LinksMap',
82
90
  'Schema',
83
91
  'Xml',
84
92
  'SchemaProperties',
@@ -103,86 +111,79 @@ const nodeTypesList = [
103
111
  'XCodeSample',
104
112
  'WebhooksMap',
105
113
  ];
106
- const ConfigRoot = {
114
+ const ConfigStyleguide = {
107
115
  properties: {
108
- organization: { type: 'string' },
109
- apis: 'ConfigApis',
110
- apiDefinitions: {
116
+ extends: {
117
+ type: 'array',
118
+ items: {
119
+ type: 'string',
120
+ },
121
+ },
122
+ rules: 'Rules',
123
+ oas2Rules: 'Rules',
124
+ oas3_0Rules: 'Rules',
125
+ oas3_1Rules: 'Rules',
126
+ preprocessors: { type: 'object' },
127
+ oas2Preprocessors: { type: 'object' },
128
+ oas3_0Preprocessors: { type: 'object' },
129
+ oas3_1Preprocessors: { type: 'object' },
130
+ decorators: { type: 'object' },
131
+ oas2Decorators: { type: 'object' },
132
+ oas3_0Decorators: { type: 'object' },
133
+ oas3_1Decorators: { type: 'object' },
134
+ },
135
+ };
136
+ const RootConfigStyleguide = {
137
+ properties: Object.assign({ plugins: {
138
+ type: 'array',
139
+ items: { type: 'string' },
140
+ } }, ConfigStyleguide.properties),
141
+ };
142
+ const ConfigRoot = {
143
+ properties: Object.assign(Object.assign({ organization: { type: 'string' }, apis: 'ConfigApis', apiDefinitions: {
111
144
  type: 'object',
112
145
  properties: {},
113
146
  additionalProperties: { properties: { type: 'string' } },
114
- },
115
- styleguide: 'RootConfigStyleguide',
116
- lint: 'RootConfigStyleguide',
117
- 'features.openapi': 'ConfigReferenceDocs',
118
- referenceDocs: 'ConfigReferenceDocs',
119
- 'features.mockServer': 'ConfigMockServer',
120
- region: { enum: ['us', 'eu'] },
121
- resolve: {
147
+ } }, RootConfigStyleguide.properties), { styleguide: 'RootConfigStyleguide', lint: 'RootConfigStyleguide', 'features.openapi': 'ConfigReferenceDocs', referenceDocs: 'ConfigReferenceDocs', 'features.mockServer': 'ConfigMockServer', region: { enum: ['us', 'eu'] }, resolve: {
122
148
  properties: {
123
149
  http: 'ConfigHTTP',
150
+ doNotResolveExamples: { type: 'boolean' },
124
151
  },
125
- },
126
- },
152
+ }, files: {
153
+ type: 'array',
154
+ items: {
155
+ type: 'string',
156
+ },
157
+ } }),
127
158
  };
128
159
  const ConfigApis = {
129
160
  properties: {},
130
161
  additionalProperties: 'ConfigApisProperties',
131
162
  };
132
163
  const ConfigApisProperties = {
133
- properties: {
134
- root: { type: 'string' },
135
- labels: {
164
+ properties: Object.assign(Object.assign({ root: { type: 'string' }, labels: {
136
165
  type: 'array',
137
166
  items: {
138
167
  type: 'string',
139
168
  },
140
- },
141
- styleguide: 'ConfigStyleguide',
142
- 'features.openapi': 'ConfigReferenceDocs',
143
- 'features.mockServer': 'ConfigMockServer',
144
- },
145
- required: ['root'],
146
- };
147
- const ConfigHTTP = {
148
- properties: {
149
- headers: {
169
+ }, lint: 'ConfigStyleguide', styleguide: 'ConfigStyleguide' }, ConfigStyleguide.properties), { 'features.openapi': 'ConfigReferenceDocs', 'features.mockServer': 'ConfigMockServer', files: {
150
170
  type: 'array',
151
171
  items: {
152
172
  type: 'string',
153
173
  },
154
- },
155
- },
174
+ } }),
175
+ required: ['root'],
156
176
  };
157
- const ConfigStyleguide = {
177
+ const ConfigHTTP = {
158
178
  properties: {
159
- extends: {
179
+ headers: {
160
180
  type: 'array',
161
181
  items: {
162
182
  type: 'string',
163
183
  },
164
184
  },
165
- doNotResolveExamples: { type: 'boolean' },
166
- rules: 'Rules',
167
- oas2Rules: 'Rules',
168
- oas3_0Rules: 'Rules',
169
- oas3_1Rules: 'Rules',
170
- preprocessors: { type: 'object' },
171
- oas2Preprocessors: { type: 'object' },
172
- oas3_0Preprocessors: { type: 'object' },
173
- oas3_1Preprocessors: { type: 'object' },
174
- decorators: { type: 'object' },
175
- oas2Decorators: { type: 'object' },
176
- oas3_0Decorators: { type: 'object' },
177
- oas3_1Decorators: { type: 'object' },
178
185
  },
179
186
  };
180
- const RootConfigStyleguide = {
181
- properties: Object.assign({ plugins: {
182
- type: 'array',
183
- items: { type: 'string' },
184
- } }, ConfigStyleguide.properties),
185
- };
186
187
  const Rules = {
187
188
  properties: {},
188
189
  additionalProperties: (value, key) => {
@@ -258,6 +259,11 @@ const Assert = {
258
259
  maxLength: { type: 'integer' },
259
260
  ref: (value) => typeof value === 'string' ? { type: 'string' } : { type: 'boolean' },
260
261
  },
262
+ additionalProperties: (_value, key) => {
263
+ if (/^\w+\/\w+$/.test(key))
264
+ return { type: 'object' };
265
+ return;
266
+ },
261
267
  required: ['subject'],
262
268
  };
263
269
  const Context = {
package/lib/utils.d.ts CHANGED
@@ -14,7 +14,7 @@ export declare function pushStack<T, P extends Stack<T> = Stack<T>>(head: P, val
14
14
  export declare function popStack<T, P extends Stack<T>>(head: P): StackFrame<T> | null;
15
15
  export declare type BundleOutputFormat = 'json' | 'yml' | 'yaml';
16
16
  export declare function loadYaml<T>(filename: string): Promise<T>;
17
- export declare function notUndefined<T>(x: T | undefined): x is T;
17
+ export declare function isDefined<T>(x: T | undefined): x is T;
18
18
  export declare function isPlainObject(value: any): value is object;
19
19
  export declare function isEmptyObject(value: any): value is object;
20
20
  export declare function isEmptyArray(value: any): boolean;
@@ -41,8 +41,8 @@ export declare function assignExisting<T>(target: Record<string, T>, obj: Record
41
41
  export declare function getMatchingStatusCodeRange(code: number | string): string;
42
42
  export declare function isCustomRuleId(id: string): boolean;
43
43
  export declare function doesYamlFileExist(filePath: string): boolean;
44
- export declare function showWarningForDeprecatedField(deprecatedField: string, updatedField: string): void;
45
- export declare function showErrorForDeprecatedField(deprecatedField: string, updatedField: string): void;
44
+ export declare function showWarningForDeprecatedField(deprecatedField: string, updatedField?: string): void;
45
+ export declare function showErrorForDeprecatedField(deprecatedField: string, updatedField?: string): void;
46
46
  export declare type Falsy = undefined | null | false | '' | 0;
47
47
  export declare function isTruthy<Truthy>(value: Truthy | Falsy): value is Truthy;
48
48
  export declare function identity<T>(value: T): T;
package/lib/utils.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.identity = exports.isTruthy = exports.showErrorForDeprecatedField = exports.showWarningForDeprecatedField = exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.notUndefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
12
+ exports.identity = exports.isTruthy = exports.showErrorForDeprecatedField = exports.showWarningForDeprecatedField = exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.isDefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
13
13
  const fs = require("fs");
14
14
  const path_1 = require("path");
15
15
  const minimatch = require("minimatch");
@@ -37,10 +37,10 @@ function loadYaml(filename) {
37
37
  });
38
38
  }
39
39
  exports.loadYaml = loadYaml;
40
- function notUndefined(x) {
40
+ function isDefined(x) {
41
41
  return x !== undefined;
42
42
  }
43
- exports.notUndefined = notUndefined;
43
+ exports.isDefined = isDefined;
44
44
  function isPlainObject(value) {
45
45
  return value !== null && typeof value === 'object' && !Array.isArray(value);
46
46
  }
@@ -190,11 +190,11 @@ function doesYamlFileExist(filePath) {
190
190
  }
191
191
  exports.doesYamlFileExist = doesYamlFileExist;
192
192
  function showWarningForDeprecatedField(deprecatedField, updatedField) {
193
- logger_1.logger.warn(`The ${logger_1.colorize.red(deprecatedField)} field is deprecated. Use ${logger_1.colorize.green(updatedField)} instead. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`);
193
+ logger_1.logger.warn(`The '${logger_1.colorize.red(deprecatedField)}' field is deprecated. ${updatedField ? `Use ${logger_1.colorize.green(updatedField)} instead. ` : ''}Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`);
194
194
  }
195
195
  exports.showWarningForDeprecatedField = showWarningForDeprecatedField;
196
196
  function showErrorForDeprecatedField(deprecatedField, updatedField) {
197
- throw new Error(`Do not use '${deprecatedField}' field. Use '${updatedField}' instead.\n`);
197
+ throw new Error(`Do not use '${deprecatedField}' field. ${updatedField ? `Use '${updatedField}' instead. ` : ''}\n`);
198
198
  }
199
199
  exports.showErrorForDeprecatedField = showErrorForDeprecatedField;
200
200
  function isTruthy(value) {
package/lib/visitors.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { Oas3Definition, Oas3ExternalDocs, Oas3Info, Oas3Contact, Oas3Components, Oas3License, Oas3Schema, Oas3Header, Oas3Parameter, Oas3Operation, Oas3PathItem, Oas3ServerVariable, Oas3Server, Oas3MediaType, Oas3Response, Oas3Example, Oas3RequestBody, Oas3Tag, OasRef, Oas3SecurityScheme, Oas3SecurityRequirement, Oas3Encoding, Oas3Link, Oas3Xml, Oas3Discriminator, Oas3Callback } from './typings/openapi';
2
- import { Oas2Definition, Oas2Tag, Oas2ExternalDocs, Oas2SecurityRequirement, Oas2Info, Oas2Contact, Oas2License, Oas2PathItem, Oas2Operation, Oas2Header, Oas2Response, Oas2Schema, Oas2Xml, Oas2Parameter, Oas2SecurityScheme } from './typings/swagger';
3
- import { NormalizedNodeType } from './types';
4
- import { Stack } from './utils';
5
- import { UserContext, ResolveResult, ProblemSeverity } from './walk';
6
- import { Location } from './ref-utils';
2
+ import type { Oas2Definition, Oas2Tag, Oas2ExternalDocs, Oas2SecurityRequirement, Oas2Info, Oas2Contact, Oas2License, Oas2PathItem, Oas2Operation, Oas2Header, Oas2Response, Oas2Schema, Oas2Xml, Oas2Parameter, Oas2SecurityScheme } from './typings/swagger';
3
+ import type { NormalizedNodeType } from './types';
4
+ import type { Stack } from './utils';
5
+ import type { UserContext, ResolveResult, ProblemSeverity } from './walk';
6
+ import type { Location } from './ref-utils';
7
7
  export declare type VisitFunction<T> = (node: T, ctx: UserContext & {
8
8
  ignoreNextVisitorsOnNode: () => void;
9
9
  }, parents?: any, context?: any) => void;
@@ -61,7 +61,7 @@ export declare type BaseVisitor = {
61
61
  } | VisitRefFunction;
62
62
  };
63
63
  declare type Oas3FlatVisitor = {
64
- DefinitionRoot?: VisitFunctionOrObject<Oas3Definition>;
64
+ Root?: VisitFunctionOrObject<Oas3Definition>;
65
65
  Tag?: VisitFunctionOrObject<Oas3Tag>;
66
66
  ExternalDocs?: VisitFunctionOrObject<Oas3ExternalDocs>;
67
67
  Server?: VisitFunctionOrObject<Oas3Server>;
@@ -70,13 +70,13 @@ declare type Oas3FlatVisitor = {
70
70
  Info?: VisitFunctionOrObject<Oas3Info>;
71
71
  Contact?: VisitFunctionOrObject<Oas3Contact>;
72
72
  License?: VisitFunctionOrObject<Oas3License>;
73
- PathMap?: VisitFunctionOrObject<Record<string, Oas3PathItem>>;
73
+ PathsMap?: VisitFunctionOrObject<Record<string, Oas3PathItem>>;
74
74
  PathItem?: VisitFunctionOrObject<Oas3PathItem>;
75
75
  Callback?: VisitFunctionOrObject<Record<string, Oas3PathItem>>;
76
76
  Parameter?: VisitFunctionOrObject<Oas3Parameter>;
77
77
  Operation?: VisitFunctionOrObject<Oas3Operation>;
78
78
  RequestBody?: VisitFunctionOrObject<Oas3RequestBody>;
79
- MediaTypeMap?: VisitFunctionOrObject<Record<string, Oas3MediaType>>;
79
+ MediaTypesMap?: VisitFunctionOrObject<Record<string, Oas3MediaType>>;
80
80
  MediaType?: VisitFunctionOrObject<Oas3MediaType>;
81
81
  Example?: VisitFunctionOrObject<Oas3Example>;
82
82
  Encoding?: VisitFunctionOrObject<Oas3Encoding>;
@@ -107,14 +107,14 @@ declare type Oas3FlatVisitor = {
107
107
  SecurityScheme?: VisitFunctionOrObject<Oas3SecurityScheme>;
108
108
  };
109
109
  declare type Oas2FlatVisitor = {
110
- DefinitionRoot?: VisitFunctionOrObject<Oas2Definition>;
110
+ Root?: VisitFunctionOrObject<Oas2Definition>;
111
111
  Tag?: VisitFunctionOrObject<Oas2Tag>;
112
112
  ExternalDocs?: VisitFunctionOrObject<Oas2ExternalDocs>;
113
113
  SecurityRequirement?: VisitFunctionOrObject<Oas2SecurityRequirement>;
114
114
  Info?: VisitFunctionOrObject<Oas2Info>;
115
115
  Contact?: VisitFunctionOrObject<Oas2Contact>;
116
116
  License?: VisitFunctionOrObject<Oas2License>;
117
- PathMap?: VisitFunctionOrObject<Record<string, Oas2PathItem>>;
117
+ PathsMap?: VisitFunctionOrObject<Record<string, Oas2PathItem>>;
118
118
  PathItem?: VisitFunctionOrObject<Oas2PathItem>;
119
119
  Parameter?: VisitFunctionOrObject<any>;
120
120
  Operation?: VisitFunctionOrObject<Oas2Operation>;
@@ -140,7 +140,7 @@ export declare type Oas3Visitor = BaseVisitor & Oas3NestedVisitor & Record<strin
140
140
  export declare type Oas2Visitor = BaseVisitor & Oas2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas2NestedVisitor>>;
141
141
  export declare type Oas3TransformVisitor = BaseVisitor & Oas3FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
142
142
  export declare type Oas2TransformVisitor = BaseVisitor & Oas2FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
143
- export declare type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | 'DefinitionRoot'>;
143
+ export declare type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | 'Root'>;
144
144
  export declare type NormalizedOasVisitors<T extends BaseVisitor> = {
145
145
  [V in keyof T]-?: {
146
146
  enter: Array<NormalizeVisitor<T[V]>>;
package/lib/visitors.js CHANGED
@@ -1,6 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeVisitors = void 0;
4
+ const legacyTypesMap = {
5
+ Root: 'DefinitionRoot',
6
+ ServerVariablesMap: 'ServerVariableMap',
7
+ PathsMap: 'PathMap',
8
+ CallbacksMap: 'CallbackMap',
9
+ MediaTypesMap: 'MediaTypeMap',
10
+ ExamplesMap: 'ExampleMap',
11
+ EncodingsMap: 'EncodingMap',
12
+ HeadersMap: 'HeaderMap',
13
+ LinksMap: 'LinkMap',
14
+ };
4
15
  function normalizeVisitors(visitorsConfig, types) {
5
16
  const normalizedVisitors = {};
6
17
  normalizedVisitors.any = {
@@ -89,7 +100,8 @@ function normalizeVisitors(visitorsConfig, types) {
89
100
  }
90
101
  }
91
102
  for (const typeName of visitorKeys) {
92
- const typeVisitor = visitor[typeName];
103
+ const typeVisitor = (visitor[typeName] ||
104
+ visitor[legacyTypesMap[typeName]]);
93
105
  const normalizedTypeVisitor = normalizedVisitors[typeName];
94
106
  if (!typeVisitor)
95
107
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/openapi-core",
3
- "version": "1.0.0-beta.108",
3
+ "version": "1.0.0-beta.110",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "engines": {
@@ -29,12 +29,10 @@
29
29
  "oas"
30
30
  ],
31
31
  "contributors": [
32
- "Sergey Dubovyk <serhii@redoc.ly> (https://redoc.ly/)",
33
- "Roman Hotsiy <roman@redoc.ly> (https://redoc.ly/)",
34
- "Andriy Leliv <andriy@redoc.ly> (https://redoc.ly/)"
32
+ "Roman Hotsiy <roman@redoc.ly> (https://redoc.ly/)"
35
33
  ],
36
34
  "dependencies": {
37
- "@redocly/ajv": "^8.6.5",
35
+ "@redocly/ajv": "^8.11.0",
38
36
  "@types/node": "^14.11.8",
39
37
  "colorette": "^1.2.0",
40
38
  "js-levenshtein": "^1.1.6",
@@ -47,7 +47,7 @@ rootType:
47
47
  description:
48
48
  type: string
49
49
  variables:
50
- name: ServerVariableMap
50
+ name: ServerVariablesMap
51
51
  properties: {}
52
52
  required:
53
53
  - url
@@ -94,7 +94,7 @@ rootType:
94
94
  name: ExternalDocs
95
95
  paths:
96
96
  properties: {}
97
- name: PathMap
97
+ name: PathsMap
98
98
  components:
99
99
  properties:
100
100
  parameters:
@@ -132,7 +132,7 @@ rootType:
132
132
  - openapi
133
133
  - paths
134
134
  - info
135
- name: DefinitionRoot
135
+ name: Root
136
136
  refTypes: {}
137
137
  visitorsData:
138
138
  registry-dependencies:
@@ -9,10 +9,10 @@ function oas3_0(types) {
9
9
  parameters: listOf('Parameter'),
10
10
  },
11
11
  },
12
- DefinitionRoot: {
13
- ...types.DefinitionRoot,
12
+ Root: {
13
+ ...types.Root,
14
14
  properties: {
15
- ...types.DefinitionRoot.properties,
15
+ ...types.Root.properties,
16
16
  'x-webhooks': 'XWebHooks',
17
17
  },
18
18
  },
@@ -0,0 +1,76 @@
1
+ import { outdent } from 'outdent';
2
+
3
+ import { formatProblems, getTotals } from '../format/format';
4
+
5
+ describe('format', () => {
6
+ function replaceColors(log: string) {
7
+ return log
8
+ .replace(/\x1b\[33m(.*?)\x1b\[39m/g, '<o>$1</o>') // orange
9
+ .replace(/\x1b\[31m(.*?)\x1b\[39m/g, '<r>$1</r>'); // red
10
+ }
11
+
12
+ const problems = [
13
+ {
14
+ ruleId: 'spec',
15
+ location: [],
16
+ severity: 'error' as const,
17
+ message: 'message',
18
+ suggest: [],
19
+ },
20
+ {
21
+ ruleId: 'spec',
22
+ location: [],
23
+ severity: 'error' as const,
24
+ message: 'message 2',
25
+ suggest: [],
26
+ },
27
+ {
28
+ ruleId: 'other-rule',
29
+ location: [],
30
+ severity: 'warn' as const,
31
+ message: 'message',
32
+ suggest: [],
33
+ },
34
+ ];
35
+
36
+ let output = '';
37
+ beforeEach(() => {
38
+ output = '';
39
+ jest.spyOn(process.stderr, 'write').mockImplementation((str: string | Uint8Array) => {
40
+ output += str;
41
+ return true;
42
+ });
43
+ });
44
+
45
+ it('should correctly format summary output', () => {
46
+ formatProblems(problems, {
47
+ format: 'summary',
48
+ version: '1.0.0',
49
+ totals: getTotals(problems),
50
+ color: false,
51
+ });
52
+
53
+ expect(output).toMatchInlineSnapshot(`
54
+ "error spec: 2
55
+ warning other-rule: 1
56
+
57
+ "
58
+ `);
59
+ });
60
+
61
+ it('should correctly format summary output in color mode', () => {
62
+ formatProblems(problems, {
63
+ format: 'summary',
64
+ version: '1.0.0',
65
+ totals: getTotals(problems),
66
+ color: true,
67
+ });
68
+
69
+ expect(replaceColors(output)).toMatchInlineSnapshot(`
70
+ "<r>error </r> spec: 2
71
+ <o>warning</o> other-rule: 1
72
+
73
+ "
74
+ `);
75
+ });
76
+ });