@redocly/openapi-core 1.0.0-beta.62 → 1.0.0-beta.66

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 (76) hide show
  1. package/__tests__/lint.test.ts +17 -0
  2. package/__tests__/resolve.test.ts +10 -2
  3. package/__tests__/utils.ts +3 -5
  4. package/lib/benchmark/utils.js +2 -2
  5. package/lib/config/all.js +8 -1
  6. package/lib/config/config.d.ts +1 -0
  7. package/lib/config/config.js +4 -4
  8. package/lib/index.d.ts +2 -1
  9. package/lib/index.js +5 -1
  10. package/lib/js-yaml/index.d.ts +3 -0
  11. package/lib/js-yaml/index.js +19 -0
  12. package/lib/oas-types.js +3 -0
  13. package/lib/resolve.d.ts +1 -1
  14. package/lib/resolve.js +3 -4
  15. package/lib/rules/builtin.d.ts +6 -0
  16. package/lib/rules/common/info-description-override.d.ts +2 -0
  17. package/lib/rules/common/info-description-override.js +24 -0
  18. package/lib/rules/common/info-license-url.js +1 -0
  19. package/lib/rules/common/no-http-verbs-in-paths.d.ts +2 -0
  20. package/lib/rules/common/no-http-verbs-in-paths.js +33 -0
  21. package/lib/rules/common/operation-description-override.d.ts +2 -0
  22. package/lib/rules/common/operation-description-override.js +29 -0
  23. package/lib/rules/common/path-excludes-patterns.d.ts +2 -0
  24. package/lib/rules/common/path-excludes-patterns.js +22 -0
  25. package/lib/rules/common/path-segment-plural.d.ts +2 -0
  26. package/lib/rules/common/path-segment-plural.js +32 -0
  27. package/lib/rules/common/tag-description-override.d.ts +2 -0
  28. package/lib/rules/common/tag-description-override.js +25 -0
  29. package/lib/rules/oas2/index.d.ts +8 -0
  30. package/lib/rules/oas2/index.js +16 -0
  31. package/lib/rules/oas2/request-mime-type.d.ts +2 -0
  32. package/lib/rules/oas2/request-mime-type.js +17 -0
  33. package/lib/rules/oas2/response-mime-type.d.ts +2 -0
  34. package/lib/rules/oas2/response-mime-type.js +17 -0
  35. package/lib/rules/oas3/index.d.ts +3 -0
  36. package/lib/rules/oas3/index.js +17 -1
  37. package/lib/rules/oas3/request-mime-type.d.ts +2 -0
  38. package/lib/rules/oas3/request-mime-type.js +31 -0
  39. package/lib/rules/oas3/response-mime-type.d.ts +2 -0
  40. package/lib/rules/oas3/response-mime-type.js +31 -0
  41. package/lib/types/oas3_1.js +6 -0
  42. package/lib/types/redocly-yaml.js +332 -21
  43. package/lib/utils.d.ts +15 -1
  44. package/lib/utils.js +82 -3
  45. package/package.json +6 -4
  46. package/src/__tests__/js-yaml.test.ts +47 -0
  47. package/src/__tests__/lint.test.ts +13 -0
  48. package/src/__tests__/utils.test.ts +74 -0
  49. package/src/benchmark/utils.ts +2 -2
  50. package/src/config/all.ts +8 -1
  51. package/src/config/config.ts +6 -5
  52. package/src/index.ts +3 -1
  53. package/src/js-yaml/index.ts +19 -0
  54. package/src/oas-types.ts +4 -0
  55. package/src/resolve.ts +5 -5
  56. package/src/rules/__tests__/no-unresolved-refs.test.ts +2 -2
  57. package/src/rules/common/__tests__/info-license.test.ts +1 -1
  58. package/src/rules/common/info-description-override.ts +24 -0
  59. package/src/rules/common/info-license-url.ts +1 -0
  60. package/src/rules/common/no-http-verbs-in-paths.ts +36 -0
  61. package/src/rules/common/operation-description-override.ts +30 -0
  62. package/src/rules/common/path-excludes-patterns.ts +23 -0
  63. package/src/rules/common/path-segment-plural.ts +31 -0
  64. package/src/rules/common/tag-description-override.ts +25 -0
  65. package/src/rules/oas2/index.ts +16 -0
  66. package/src/rules/oas2/request-mime-type.ts +17 -0
  67. package/src/rules/oas2/response-mime-type.ts +17 -0
  68. package/src/rules/oas3/index.ts +18 -3
  69. package/src/rules/oas3/request-mime-type.ts +31 -0
  70. package/src/rules/oas3/response-mime-type.ts +31 -0
  71. package/src/rules/utils.ts +1 -1
  72. package/src/types/oas3_1.ts +7 -0
  73. package/src/types/redocly-yaml.ts +434 -22
  74. package/src/typings/swagger.ts +0 -1
  75. package/src/utils.ts +101 -2
  76. package/tsconfig.tsbuildinfo +1 -1
@@ -39,6 +39,14 @@ const operation_operationId_1 = require("../common/operation-operationId");
39
39
  const operation_summary_1 = require("../common/operation-summary");
40
40
  const no_ambiguous_paths_1 = require("../common/no-ambiguous-paths");
41
41
  const no_servers_empty_enum_1 = require("./no-servers-empty-enum");
42
+ const no_http_verbs_in_paths_1 = require("../common/no-http-verbs-in-paths");
43
+ const request_mime_type_1 = require("./request-mime-type");
44
+ const response_mime_type_1 = require("./response-mime-type");
45
+ const path_segment_plural_1 = require("../common/path-segment-plural");
46
+ const operation_description_override_1 = require("../common/operation-description-override");
47
+ const tag_description_override_1 = require("../common/tag-description-override");
48
+ const info_description_override_1 = require("../common/info-description-override");
49
+ const path_excludes_patterns_1 = require("../common/path-excludes-patterns");
42
50
  exports.rules = {
43
51
  spec: spec_1.OasSpec,
44
52
  'info-description': info_description_1.InfoDescription,
@@ -77,9 +85,17 @@ exports.rules = {
77
85
  'no-identical-paths': no_identical_paths_1.NoIdenticalPaths,
78
86
  'no-ambiguous-paths': no_ambiguous_paths_1.NoAmbiguousPaths,
79
87
  'no-undefined-server-variable': no_undefined_server_variable_1.NoUndefinedServerVariable,
80
- 'no-servers-empty-enum': no_servers_empty_enum_1.NoEmptyEnumServers
88
+ 'no-servers-empty-enum': no_servers_empty_enum_1.NoEmptyEnumServers,
89
+ 'no-http-verbs-in-paths': no_http_verbs_in_paths_1.NoHttpVerbsInPaths,
90
+ 'path-excludes-patterns': path_excludes_patterns_1.PathExcludesPatterns,
91
+ 'request-mime-type': request_mime_type_1.RequestMimeType,
92
+ 'response-mime-type': response_mime_type_1.ResponseMimeType,
93
+ 'path-segment-plural': path_segment_plural_1.PathSegmentPlural,
81
94
  };
82
95
  exports.preprocessors = {};
83
96
  exports.decorators = {
84
97
  'registry-dependencies': registry_dependencies_1.RegistryDependencies,
98
+ 'operation-description-override': operation_description_override_1.OperationDescriptionOverride,
99
+ 'tag-description-override': tag_description_override_1.TagDescriptionOverride,
100
+ 'info-description-override': info_description_override_1.InfoDescriptionOverride,
85
101
  };
@@ -0,0 +1,2 @@
1
+ import { Oas3Rule } from '../../visitors';
2
+ export declare const RequestMimeType: Oas3Rule;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RequestMimeType = void 0;
4
+ const utils_1 = require("../../utils");
5
+ const RequestMimeType = ({ allowedValues }) => {
6
+ return {
7
+ PathMap: {
8
+ RequestBody: {
9
+ leave(requestBody, ctx) {
10
+ utils_1.validateMimeTypeOAS3({ type: 'consumes', value: requestBody }, ctx, allowedValues);
11
+ },
12
+ },
13
+ Callback: {
14
+ RequestBody() { },
15
+ Response: {
16
+ leave(response, ctx) {
17
+ utils_1.validateMimeTypeOAS3({ type: 'consumes', value: response }, ctx, allowedValues);
18
+ },
19
+ },
20
+ },
21
+ },
22
+ WebhooksMap: {
23
+ Response: {
24
+ leave(response, ctx) {
25
+ utils_1.validateMimeTypeOAS3({ type: 'consumes', value: response }, ctx, allowedValues);
26
+ },
27
+ },
28
+ },
29
+ };
30
+ };
31
+ exports.RequestMimeType = RequestMimeType;
@@ -0,0 +1,2 @@
1
+ import { Oas3Rule } from '../../visitors';
2
+ export declare const ResponseMimeType: Oas3Rule;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResponseMimeType = void 0;
4
+ const utils_1 = require("../../utils");
5
+ const ResponseMimeType = ({ allowedValues }) => {
6
+ return {
7
+ PathMap: {
8
+ Response: {
9
+ leave(response, ctx) {
10
+ utils_1.validateMimeTypeOAS3({ type: 'produces', value: response }, ctx, allowedValues);
11
+ },
12
+ },
13
+ Callback: {
14
+ Response() { },
15
+ RequestBody: {
16
+ leave(requestBody, ctx) {
17
+ utils_1.validateMimeTypeOAS3({ type: 'produces', value: requestBody }, ctx, allowedValues);
18
+ },
19
+ },
20
+ },
21
+ },
22
+ WebhooksMap: {
23
+ RequestBody: {
24
+ leave(requestBody, ctx) {
25
+ utils_1.validateMimeTypeOAS3({ type: 'produces', value: requestBody }, ctx, allowedValues);
26
+ },
27
+ },
28
+ },
29
+ };
30
+ };
31
+ exports.ResponseMimeType = ResponseMimeType;
@@ -94,6 +94,12 @@ const Operation = {
94
94
  };
95
95
  const Schema = {
96
96
  properties: {
97
+ $id: { type: 'string' },
98
+ id: { type: 'string' },
99
+ $schema: { type: 'string' },
100
+ definitions: 'NamedSchemas',
101
+ $defs: 'NamedSchemas',
102
+ $vocabulary: { type: 'string' },
97
103
  externalDocs: 'ExternalDocs',
98
104
  discriminator: 'Discriminator',
99
105
  myArbitraryKeyword: { type: 'boolean' },
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConfigTypes = void 0;
4
4
  const _1 = require(".");
5
+ const utils_1 = require("../utils");
5
6
  const ConfigRoot = {
6
7
  properties: {
7
8
  apiDefinitions: {
8
9
  type: 'object',
9
10
  properties: {},
10
- additionalProperties: { properties: { type: 'string' } }
11
+ additionalProperties: { properties: { type: 'string' } },
11
12
  },
12
13
  lint: 'ConfigLint',
13
14
  referenceDocs: 'ConfigReferenceDocs',
@@ -87,25 +88,297 @@ const ConfigSidebarLinks = {
87
88
  target: { type: 'string' },
88
89
  },
89
90
  };
91
+ const CommonThemeColors = {
92
+ properties: {
93
+ main: { type: 'string' },
94
+ light: { type: 'string' },
95
+ dark: { type: 'string' },
96
+ contrastText: { type: 'string' },
97
+ },
98
+ };
99
+ const CommonColorProps = {
100
+ properties: {
101
+ backgroundColor: { type: 'string' },
102
+ borderColor: { type: 'string' },
103
+ color: { type: 'string' },
104
+ tabTextColor: { type: 'string' },
105
+ },
106
+ };
107
+ const BorderThemeColors = {
108
+ properties: utils_1.pickObjectProps(CommonThemeColors.properties, ['light', 'dark']),
109
+ };
110
+ const HttpColors = {
111
+ properties: {
112
+ basic: { type: 'string' },
113
+ delete: { type: 'string' },
114
+ get: { type: 'string' },
115
+ head: { type: 'string' },
116
+ link: { type: 'string' },
117
+ options: { type: 'string' },
118
+ patch: { type: 'string' },
119
+ post: { type: 'string' },
120
+ put: { type: 'string' },
121
+ },
122
+ };
123
+ const ResponseColors = {
124
+ properties: {
125
+ errors: 'CommonColorProps',
126
+ info: 'CommonColorProps',
127
+ redirect: 'CommonColorProps',
128
+ success: 'CommonColorProps',
129
+ },
130
+ };
131
+ const SecondaryColors = {
132
+ properties: utils_1.omitObjectProps(CommonThemeColors.properties, ['dark']),
133
+ };
134
+ const TextThemeColors = {
135
+ properties: {
136
+ primary: { type: 'string' },
137
+ secondary: { type: 'string' },
138
+ light: { type: 'string' },
139
+ },
140
+ };
141
+ const ThemeColors = {
142
+ properties: {
143
+ accent: 'CommonThemeColors',
144
+ border: 'BorderThemeColors',
145
+ error: 'CommonThemeColors',
146
+ http: 'HttpColors',
147
+ primary: 'CommonThemeColors',
148
+ responses: 'ResponseColors',
149
+ secondary: 'SecondaryColors',
150
+ success: 'CommonThemeColors',
151
+ text: 'TextThemeColors',
152
+ tonalOffset: { type: 'number' },
153
+ warning: 'CommonThemeColors',
154
+ },
155
+ };
156
+ const SizeProps = {
157
+ properties: {
158
+ fontSize: { type: 'string' },
159
+ padding: { type: 'string' },
160
+ minWidth: { type: 'string' },
161
+ },
162
+ };
163
+ const Sizes = {
164
+ properties: {
165
+ small: 'SizeProps',
166
+ medium: 'SizeProps',
167
+ large: 'SizeProps',
168
+ xlarge: 'SizeProps',
169
+ },
170
+ };
171
+ const FontConfig = {
172
+ properties: {
173
+ fontFamily: { type: 'string' },
174
+ fontSize: { type: 'string' },
175
+ fontWeight: { type: 'string' },
176
+ lineHeight: { type: 'string' },
177
+ },
178
+ };
179
+ const ButtonsConfig = {
180
+ properties: Object.assign(Object.assign({}, utils_1.omitObjectProps(FontConfig.properties, ['fontSize', 'lineHeight'])), { borderRadius: { type: 'string' }, hoverStyle: { type: 'string' }, boxShadow: { type: 'string' }, hoverBoxShadow: { type: 'string' }, sizes: 'Sizes' }),
181
+ };
182
+ const BadgeFontConfig = {
183
+ properties: utils_1.pickObjectProps(FontConfig.properties, ['fontSize', 'lineHeight']),
184
+ };
185
+ const BadgeSizes = {
186
+ properties: {
187
+ medium: 'BadgeFontConfig',
188
+ small: 'BadgeFontConfig',
189
+ },
190
+ };
191
+ const HttpBadgesConfig = {
192
+ properties: Object.assign(Object.assign({}, utils_1.omitObjectProps(FontConfig.properties, ['fontSize', 'lineHeight'])), { borderRadius: { type: 'string' }, color: { type: 'string' }, sizes: 'BadgeSizes' }),
193
+ };
194
+ const LabelControls = {
195
+ properties: {
196
+ top: { type: 'string' },
197
+ },
198
+ };
199
+ const Panels = {
200
+ properties: {
201
+ borderRadius: { type: 'string' },
202
+ },
203
+ };
204
+ const TryItButton = {
205
+ properties: {
206
+ fullWidth: { type: 'boolean' },
207
+ },
208
+ };
209
+ const Components = {
210
+ properties: {
211
+ buttons: 'ButtonsConfig',
212
+ httpBadges: 'HttpBadgesConfig',
213
+ layoutControls: 'LabelControls',
214
+ panels: 'Panels',
215
+ tryItButton: 'TryItButton',
216
+ tryItSendButton: 'TryItButton',
217
+ },
218
+ };
219
+ const Breakpoints = {
220
+ properties: {
221
+ small: { type: 'string' },
222
+ medium: { type: 'string' },
223
+ large: { type: 'string' },
224
+ },
225
+ };
226
+ const StackedConfig = {
227
+ properties: {
228
+ maxWidth: 'Breakpoints',
229
+ },
230
+ };
231
+ const ThreePanelConfig = {
232
+ properties: {
233
+ maxWidth: 'Breakpoints',
234
+ },
235
+ };
236
+ const Layout = {
237
+ properties: {
238
+ showDarkRightPanel: { type: 'boolean' },
239
+ stacked: 'StackedConfig',
240
+ 'three-panel': 'ThreePanelConfig',
241
+ },
242
+ };
243
+ const SchemaColorsConfig = {
244
+ properties: {
245
+ backgroundColor: { type: 'string' },
246
+ border: { type: 'string' },
247
+ },
248
+ };
249
+ const Schema = {
250
+ properties: {
251
+ breakFieldNames: { type: 'boolean' },
252
+ caretColor: { type: 'string' },
253
+ caretSize: { type: 'string' },
254
+ constraints: 'SchemaColorsConfig',
255
+ defaultDetailsWidth: { type: 'string' },
256
+ examples: 'SchemaColorsConfig',
257
+ labelsTextSize: { type: 'string' },
258
+ linesColor: { type: 'string' },
259
+ nestedBackground: { type: 'string' },
260
+ nestingSpacing: { type: 'string' },
261
+ requireLabelColor: { type: 'string' },
262
+ typeNameColor: { type: 'string' },
263
+ typeTitleColor: { type: 'string' },
264
+ },
265
+ };
266
+ const GroupItemsConfig = {
267
+ properties: {
268
+ subItemsColor: { type: 'string' },
269
+ textTransform: { type: 'string' },
270
+ fontWeight: { type: 'string' },
271
+ },
272
+ };
273
+ const Level1Items = {
274
+ properties: utils_1.pickObjectProps(GroupItemsConfig.properties, ['textTransform']),
275
+ };
276
+ const SpacingConfig = {
277
+ properties: {
278
+ unit: { type: 'number' },
279
+ paddingHorizontal: { type: 'string' },
280
+ paddingVertical: { type: 'string' },
281
+ offsetTop: { type: 'string' },
282
+ offsetLeft: { type: 'string' },
283
+ offsetNesting: { type: 'string' },
284
+ },
285
+ };
286
+ const Sidebar = {
287
+ properties: Object.assign(Object.assign({}, utils_1.omitObjectProps(FontConfig.properties, ['fontWeight', 'lineHeight'])), { activeBgColor: { type: 'string' }, activeTextColor: { type: 'string' }, backgroundColor: { type: 'string' }, borderRadius: { type: 'string' }, breakPath: { type: 'boolean' }, caretColor: { type: 'string' }, caretSize: { type: 'string' }, groupItems: 'GroupItemsConfig', level1items: 'Level1Items', rightLineColor: { type: 'string' }, separatorLabelColor: { type: 'string' }, showAtBreakpoint: { type: 'string' }, spacing: 'SpacingConfig', textColor: { type: 'string' }, width: { type: 'string' } }),
288
+ };
289
+ const Heading = {
290
+ properties: Object.assign(Object.assign({}, FontConfig.properties), { color: { type: 'string' }, transform: { type: 'string' } }),
291
+ };
292
+ const CodeConfig = {
293
+ properties: Object.assign(Object.assign({}, FontConfig.properties), { backgroundColor: { type: 'string' }, color: { type: 'string' }, wordBreak: { type: 'string' }, wrap: { type: 'boolean' } }),
294
+ };
295
+ const HeadingsConfig = {
296
+ properties: utils_1.omitObjectProps(FontConfig.properties, ['fontSize']),
297
+ };
298
+ const LinksConfig = {
299
+ properties: {
300
+ color: { type: 'string' },
301
+ hover: { type: 'string' },
302
+ textDecoration: { type: 'string' },
303
+ visited: { type: 'string' },
304
+ },
305
+ };
306
+ const Typography = {
307
+ properties: Object.assign(Object.assign({ code: 'CodeConfig', fieldName: 'FontConfig' }, utils_1.pickObjectProps(FontConfig.properties, ['fontSize', 'fontFamily'])), { fontWeightBold: { type: 'string' }, fontWeightLight: { type: 'string' }, fontWeightRegular: { type: 'string' }, heading1: 'Heading', heading2: 'Heading', heading3: 'Heading', headings: 'HeadingsConfig', lineHeight: { type: 'string' }, links: 'LinksConfig', optimizeSpeed: { type: 'boolean' }, rightPanelHeading: 'Heading', smoothing: { type: 'string' } }),
308
+ };
309
+ const TokenProps = {
310
+ properties: Object.assign({ color: { type: 'string' } }, utils_1.omitObjectProps(FontConfig.properties, ['fontWeight'])),
311
+ };
312
+ const CodeBlock = {
313
+ properties: {
314
+ backgroundColor: { type: 'string' },
315
+ borderRadius: { type: 'string' },
316
+ tokens: 'TokenProps',
317
+ },
318
+ };
319
+ const Logo = {
320
+ properties: {
321
+ gutter: { type: 'string' },
322
+ maxHeight: { type: 'string' },
323
+ maxWidth: { type: 'string' },
324
+ },
325
+ };
326
+ const ButtonOverrides = {
327
+ properties: {
328
+ custom: { type: 'string' },
329
+ },
330
+ };
331
+ const Overrides = {
332
+ properties: {
333
+ DownloadButton: 'ButtonOverrides',
334
+ NextSectionButton: 'ButtonOverrides',
335
+ },
336
+ };
337
+ const RightPanel = {
338
+ properties: {
339
+ backgroundColor: { type: 'string' },
340
+ panelBackgroundColor: { type: 'string' },
341
+ panelControlsBackgroundColor: { type: 'string' },
342
+ showAtBreakpoint: { type: 'string' },
343
+ textColor: { type: 'string' },
344
+ width: { type: 'string' },
345
+ },
346
+ };
347
+ const Shape = {
348
+ properties: { borderRadius: { type: 'string' } },
349
+ };
350
+ const ThemeSpacing = {
351
+ properties: {
352
+ sectionHorizontal: { type: 'number' },
353
+ sectionVertical: { type: 'number' },
354
+ unit: { type: 'number' },
355
+ },
356
+ };
90
357
  const ConfigTheme = {
91
358
  properties: {
92
- breakpoints: { type: 'object', additionalProperties: { type: 'string' } },
93
- codeBlock: { type: 'object', additionalProperties: { type: 'string' } },
94
- colors: { type: 'object', additionalProperties: { type: 'string' } },
95
- components: { type: 'object', additionalProperties: { type: 'string' } },
96
- layout: { type: 'object', additionalProperties: { type: 'string' } },
97
- logo: { type: 'object', additionalProperties: { type: 'string' } },
98
- overrides: { type: 'object', additionalProperties: { type: 'string' } },
99
- rightPanel: { type: 'object', additionalProperties: { type: 'string' } },
100
- schema: { type: 'object', additionalProperties: { type: 'string' } },
101
- shape: { type: 'object', additionalProperties: { type: 'string' } },
102
- sidebar: { type: 'object', additionalProperties: { type: 'string' } },
103
- spacing: { type: 'object', additionalProperties: { type: 'string' } },
104
- typography: { type: 'object', additionalProperties: { type: 'string' } },
359
+ breakpoints: 'Breakpoints',
360
+ codeBlock: 'CodeBlock',
361
+ colors: 'ThemeColors',
362
+ components: 'Components',
363
+ layout: 'Layout',
364
+ logo: 'Logo',
365
+ overrides: 'Overrides',
366
+ rightPanel: 'RightPanel',
367
+ schema: 'Schema',
368
+ shape: 'Shape',
369
+ sidebar: 'Sidebar',
370
+ spacing: 'ThemeSpacing',
371
+ typography: 'Typography',
105
372
  links: { properties: { color: { type: 'string' } } },
106
373
  codeSample: { properties: { backgroundColor: { type: 'string' } } },
107
374
  },
108
375
  };
376
+ const GenerateCodeSamples = {
377
+ properties: {
378
+ skipOptionalParameters: { type: 'boolean' },
379
+ languages: _1.listOf('ConfigLanguage'),
380
+ },
381
+ };
109
382
  const ConfigReferenceDocs = {
110
383
  properties: {
111
384
  theme: 'ConfigTheme',
@@ -119,12 +392,7 @@ const ConfigReferenceDocs = {
119
392
  expandDefaultServerVariables: { type: 'boolean' },
120
393
  expandResponses: { type: 'string' },
121
394
  expandSingleSchemaField: { type: 'boolean' },
122
- generateCodeSamples: {
123
- properties: {
124
- skipOptionalParameters: { type: 'boolean' },
125
- languages: _1.listOf('ConfigLanguage'),
126
- },
127
- },
395
+ generateCodeSamples: 'GenerateCodeSamples',
128
396
  generatedPayloadSamplesMaxDepth: { type: 'number' },
129
397
  hideDownloadButton: { type: 'boolean' },
130
398
  hideHostname: { type: 'boolean' },
@@ -138,7 +406,7 @@ const ConfigReferenceDocs = {
138
406
  htmlTemplate: { type: 'string' },
139
407
  jsonSampleExpandLevel: { type: 'string' },
140
408
  labels: 'ConfigLabels',
141
- layout: { type: 'object' },
409
+ layout: { type: 'string' },
142
410
  maxDisplayedEnumValues: { type: 'number' },
143
411
  menuToggle: { type: 'boolean' },
144
412
  nativeScrollbars: { type: 'boolean' },
@@ -186,4 +454,47 @@ exports.ConfigTypes = {
186
454
  ConfigLabels,
187
455
  ConfigSidebarLinks,
188
456
  ConfigTheme,
457
+ ThemeColors,
458
+ CommonThemeColors,
459
+ BorderThemeColors,
460
+ HttpColors,
461
+ ResponseColors,
462
+ SecondaryColors,
463
+ TextThemeColors,
464
+ Sizes,
465
+ ButtonsConfig,
466
+ CommonColorProps,
467
+ BadgeFontConfig,
468
+ BadgeSizes,
469
+ HttpBadgesConfig,
470
+ LabelControls,
471
+ Panels,
472
+ TryItButton,
473
+ Breakpoints,
474
+ StackedConfig,
475
+ ThreePanelConfig,
476
+ SchemaColorsConfig,
477
+ SizeProps,
478
+ Level1Items,
479
+ SpacingConfig,
480
+ FontConfig,
481
+ CodeConfig,
482
+ HeadingsConfig,
483
+ LinksConfig,
484
+ TokenProps,
485
+ CodeBlock,
486
+ Logo,
487
+ ButtonOverrides,
488
+ Overrides,
489
+ RightPanel,
490
+ Shape,
491
+ ThemeSpacing,
492
+ GenerateCodeSamples,
493
+ GroupItemsConfig,
494
+ Components,
495
+ Layout,
496
+ Schema,
497
+ Sidebar,
498
+ Heading,
499
+ Typography,
189
500
  };
package/lib/utils.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { HttpResolveConfig } from './config/config';
2
+ import { UserContext } from './walk';
3
+ export { parseYaml, stringifyYaml } from './js-yaml';
2
4
  export declare type StackFrame<T> = {
3
5
  prev: StackFrame<T> | null;
4
6
  value: T;
@@ -11,7 +13,7 @@ export declare function pushStack<T, P extends Stack<T> = Stack<T>>(head: P, val
11
13
  };
12
14
  export declare function popStack<T, P extends Stack<T>>(head: P): StackFrame<T> | null;
13
15
  export declare type BundleOutputFormat = 'json' | 'yml' | 'yaml';
14
- export declare function loadYaml(filename: string): Promise<string | object | undefined>;
16
+ export declare function loadYaml(filename: string): Promise<unknown>;
15
17
  export declare function notUndefined<T>(x: T | undefined): x is T;
16
18
  export declare function isPlainObject(value: any): value is object;
17
19
  export declare function readFileFromUrl(url: string, config: HttpResolveConfig): Promise<{
@@ -19,3 +21,15 @@ export declare function readFileFromUrl(url: string, config: HttpResolveConfig):
19
21
  mimeType: any;
20
22
  }>;
21
23
  export declare function match(url: string, pattern: string): boolean;
24
+ export declare function pickObjectProps<T extends Record<string, unknown>>(object: T, keys: Array<string>): T;
25
+ export declare function omitObjectProps<T extends Record<string, unknown>>(object: T, keys: Array<string>): T;
26
+ export declare function splitCamelCaseIntoWords(str: string): Set<string>;
27
+ export declare function validateMimeType({ type, value }: any, { report, location }: UserContext, allowedValues: string[]): void;
28
+ export declare function validateMimeTypeOAS3({ type, value }: any, { report, location }: UserContext, allowedValues: string[]): void;
29
+ export declare function isSingular(path: string): boolean;
30
+ export declare function readFileAsStringSync(filePath: string): string;
31
+ export declare function isPathParameter(pathSegment: string): boolean;
32
+ /**
33
+ * Convert Windows backslash paths to slash paths: foo\\bar ➔ foo/bar
34
+ */
35
+ export declare function slash(path: string): string;
package/lib/utils.js CHANGED
@@ -9,11 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.match = exports.readFileFromUrl = exports.isPlainObject = exports.notUndefined = exports.loadYaml = exports.popStack = exports.pushStack = void 0;
13
- const yaml = require("js-yaml");
12
+ exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.match = exports.readFileFromUrl = exports.isPlainObject = exports.notUndefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
14
13
  const fs = require("fs");
15
14
  const minimatch = require("minimatch");
16
15
  const node_fetch_1 = require("node-fetch");
16
+ const pluralize = require("pluralize");
17
+ const js_yaml_1 = require("./js-yaml");
18
+ var js_yaml_2 = require("./js-yaml");
19
+ Object.defineProperty(exports, "parseYaml", { enumerable: true, get: function () { return js_yaml_2.parseYaml; } });
20
+ Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: function () { return js_yaml_2.stringifyYaml; } });
17
21
  function pushStack(head, value) {
18
22
  return { prev: head, value };
19
23
  }
@@ -26,7 +30,7 @@ exports.popStack = popStack;
26
30
  function loadYaml(filename) {
27
31
  return __awaiter(this, void 0, void 0, function* () {
28
32
  const contents = yield fs.promises.readFile(filename, 'utf-8');
29
- return yaml.safeLoad(contents);
33
+ return js_yaml_1.parseYaml(contents);
30
34
  });
31
35
  }
32
36
  exports.loadYaml = loadYaml;
@@ -65,3 +69,78 @@ function match(url, pattern) {
65
69
  return minimatch(url, pattern);
66
70
  }
67
71
  exports.match = match;
72
+ function pickObjectProps(object, keys) {
73
+ return Object.fromEntries(keys.filter((key) => key in object).map((key) => [key, object[key]]));
74
+ }
75
+ exports.pickObjectProps = pickObjectProps;
76
+ function omitObjectProps(object, keys) {
77
+ return Object.fromEntries(Object.entries(object).filter(([key]) => !keys.includes(key)));
78
+ }
79
+ exports.omitObjectProps = omitObjectProps;
80
+ function splitCamelCaseIntoWords(str) {
81
+ const camel = str
82
+ .split(/(?:[-._])|([A-Z][a-z]+)/)
83
+ .filter(Boolean)
84
+ .map((item) => item.toLocaleLowerCase());
85
+ const caps = str
86
+ .split(/([A-Z]{2,})/)
87
+ .filter((e) => e && e === e.toUpperCase())
88
+ .map((item) => item.toLocaleLowerCase());
89
+ return new Set([...camel, ...caps]);
90
+ }
91
+ exports.splitCamelCaseIntoWords = splitCamelCaseIntoWords;
92
+ function validateMimeType({ type, value }, { report, location }, allowedValues) {
93
+ const ruleType = type === 'consumes' ? 'request' : 'response';
94
+ if (!allowedValues)
95
+ throw new Error(`Parameter "allowedValues" is not provided for "${ruleType}-mime-type" rule`);
96
+ if (!value[type])
97
+ return;
98
+ for (const mime of value[type]) {
99
+ if (!allowedValues.includes(mime)) {
100
+ report({
101
+ message: `Mime type "${mime}" is not allowed`,
102
+ location: location.child(value[type].indexOf(mime)).key(),
103
+ });
104
+ }
105
+ }
106
+ }
107
+ exports.validateMimeType = validateMimeType;
108
+ function validateMimeTypeOAS3({ type, value }, { report, location }, allowedValues) {
109
+ const ruleType = type === 'consumes' ? 'request' : 'response';
110
+ if (!allowedValues)
111
+ throw new Error(`Parameter "allowedValues" is not provided for "${ruleType}-mime-type" rule`);
112
+ if (!value.content)
113
+ return;
114
+ for (const mime of Object.keys(value.content)) {
115
+ if (!allowedValues.includes(mime)) {
116
+ report({
117
+ message: `Mime type "${mime}" is not allowed`,
118
+ location: location.child('content').child(mime).key(),
119
+ });
120
+ }
121
+ }
122
+ }
123
+ exports.validateMimeTypeOAS3 = validateMimeTypeOAS3;
124
+ function isSingular(path) {
125
+ return pluralize.isSingular(path);
126
+ }
127
+ exports.isSingular = isSingular;
128
+ function readFileAsStringSync(filePath) {
129
+ return fs.readFileSync(filePath, 'utf-8');
130
+ }
131
+ exports.readFileAsStringSync = readFileAsStringSync;
132
+ function isPathParameter(pathSegment) {
133
+ return pathSegment.startsWith('{') && pathSegment.endsWith('{');
134
+ }
135
+ exports.isPathParameter = isPathParameter;
136
+ /**
137
+ * Convert Windows backslash paths to slash paths: foo\\bar ➔ foo/bar
138
+ */
139
+ function slash(path) {
140
+ const isExtendedLengthPath = /^\\\\\?\\/.test(path);
141
+ if (isExtendedLengthPath) {
142
+ return path;
143
+ }
144
+ return path.replace(/\\/g, '/');
145
+ }
146
+ exports.slash = slash;