@redocly/openapi-core 1.0.0-beta.79 → 1.0.0-beta.83

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 (93) hide show
  1. package/__tests__/utils.ts +11 -1
  2. package/lib/config/builtIn.js +18 -4
  3. package/lib/{rules → decorators}/common/info-description-override.d.ts +0 -0
  4. package/lib/{rules → decorators}/common/info-description-override.js +0 -0
  5. package/lib/{rules → decorators}/common/operation-description-override.d.ts +0 -0
  6. package/lib/{rules → decorators}/common/operation-description-override.js +0 -0
  7. package/lib/{rules → decorators}/common/registry-dependencies.d.ts +0 -0
  8. package/lib/{rules → decorators}/common/registry-dependencies.js +0 -0
  9. package/lib/{rules → decorators}/common/remove-x-internal.d.ts +0 -0
  10. package/lib/{rules → decorators}/common/remove-x-internal.js +0 -0
  11. package/lib/{rules → decorators}/common/tag-description-override.d.ts +0 -0
  12. package/lib/{rules → decorators}/common/tag-description-override.js +0 -0
  13. package/lib/decorators/oas2/index.d.ts +8 -0
  14. package/lib/decorators/oas2/index.js +15 -0
  15. package/lib/decorators/oas3/index.d.ts +8 -0
  16. package/lib/decorators/oas3/index.js +15 -0
  17. package/lib/index.d.ts +2 -2
  18. package/lib/index.js +2 -1
  19. package/lib/js-yaml/index.js +1 -1
  20. package/lib/rules/common/operation-security-defined.js +1 -4
  21. package/lib/rules/common/spec.js +18 -3
  22. package/lib/rules/oas2/index.d.ts +1 -8
  23. package/lib/rules/oas2/index.js +1 -13
  24. package/lib/rules/oas3/index.d.ts +0 -8
  25. package/lib/rules/oas3/index.js +1 -13
  26. package/lib/rules/oas3/no-invalid-media-type-examples.js +12 -11
  27. package/lib/types/index.d.ts +4 -0
  28. package/lib/types/oas2.js +42 -35
  29. package/lib/types/oas3.js +68 -139
  30. package/lib/types/oas3_1.js +52 -49
  31. package/lib/typings/openapi.d.ts +7 -0
  32. package/lib/utils.js +1 -1
  33. package/package.json +1 -1
  34. package/src/__tests__/js-yaml.test.ts +29 -5
  35. package/src/__tests__/lint.test.ts +1 -3
  36. package/src/config/builtIn.ts +20 -7
  37. package/src/{rules/__tests__/hide-internals.test.ts → decorators/__tests__/remove-x-internal.test.ts} +1 -2
  38. package/src/{rules → decorators}/common/info-description-override.ts +0 -0
  39. package/src/{rules → decorators}/common/operation-description-override.ts +0 -0
  40. package/src/{rules → decorators}/common/registry-dependencies.ts +0 -0
  41. package/src/{rules → decorators}/common/remove-x-internal.ts +0 -0
  42. package/src/{rules → decorators}/common/tag-description-override.ts +0 -0
  43. package/src/decorators/oas2/index.ts +14 -0
  44. package/src/decorators/oas3/index.ts +14 -0
  45. package/src/index.ts +5 -1
  46. package/src/js-yaml/index.ts +1 -2
  47. package/src/redocly/registry-api.ts +4 -1
  48. package/src/rules/__tests__/no-unresolved-refs.test.ts +1 -4
  49. package/src/rules/common/__tests__/info-description.test.ts +1 -3
  50. package/src/rules/common/__tests__/info-license.test.ts +1 -2
  51. package/src/rules/common/__tests__/license-url.test.ts +1 -2
  52. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -2
  53. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +1 -2
  54. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -2
  55. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +1 -2
  56. package/src/rules/common/__tests__/operation-2xx-response.test.ts +1 -2
  57. package/src/rules/common/__tests__/operation-4xx-response.test.ts +1 -2
  58. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +1 -2
  59. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -2
  60. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +1 -2
  61. package/src/rules/common/__tests__/operation-security-defined.test.ts +1 -2
  62. package/src/rules/common/__tests__/operation-singular-tag.test.ts +1 -2
  63. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +1 -2
  64. package/src/rules/common/__tests__/path-not-include-query.test.ts +1 -2
  65. package/src/rules/common/__tests__/path-params-defined.test.ts +1 -2
  66. package/src/rules/common/__tests__/paths-kebab-case.test.ts +1 -2
  67. package/src/rules/common/__tests__/tag-description.test.ts +1 -2
  68. package/src/rules/common/__tests__/tags-alphabetical.test.ts +1 -2
  69. package/src/rules/common/operation-security-defined.ts +4 -5
  70. package/src/rules/common/spec.ts +18 -0
  71. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +1 -2
  72. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +1 -2
  73. package/src/rules/oas2/index.ts +1 -13
  74. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +1 -2
  75. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +1 -2
  76. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +1 -2
  77. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +1 -2
  78. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +1 -2
  79. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +1 -2
  80. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -2
  81. package/src/rules/oas3/index.ts +0 -14
  82. package/src/rules/oas3/no-invalid-media-type-examples.ts +17 -21
  83. package/src/types/index.ts +4 -0
  84. package/src/types/oas2.ts +42 -40
  85. package/src/types/oas3.ts +68 -141
  86. package/src/types/oas3_1.ts +51 -50
  87. package/src/typings/openapi.ts +9 -0
  88. package/src/utils.ts +1 -1
  89. package/tsconfig.tsbuildinfo +1 -1
  90. package/lib/rules/builtin.d.ts +0 -22
  91. package/lib/rules/builtin.js +0 -17
  92. package/src/rules/__tests__/config.ts +0 -11
  93. package/src/rules/builtin.ts +0 -18
package/lib/types/oas3.js CHANGED
@@ -28,23 +28,15 @@ const Tag = {
28
28
  };
29
29
  const ExternalDocs = {
30
30
  properties: {
31
- description: {
32
- type: 'string',
33
- },
34
- url: {
35
- type: 'string',
36
- },
31
+ description: { type: 'string' },
32
+ url: { type: 'string' },
37
33
  },
38
34
  required: ['url'],
39
35
  };
40
36
  const Server = {
41
37
  properties: {
42
- url: {
43
- type: 'string',
44
- },
45
- description: {
46
- type: 'string',
47
- },
38
+ url: { type: 'string' },
39
+ description: { type: 'string' },
48
40
  variables: _1.mapOf('ServerVariable'),
49
41
  },
50
42
  required: ['url'],
@@ -55,9 +47,7 @@ const ServerVariable = {
55
47
  type: 'array',
56
48
  items: { type: 'string' },
57
49
  },
58
- default: {
59
- type: 'string',
60
- },
50
+ default: { type: 'string' },
61
51
  description: null,
62
52
  },
63
53
  required: ['default'],
@@ -68,18 +58,10 @@ const SecurityRequirement = {
68
58
  };
69
59
  const Info = {
70
60
  properties: {
71
- title: {
72
- type: 'string',
73
- },
74
- version: {
75
- type: 'string',
76
- },
77
- description: {
78
- type: 'string',
79
- },
80
- termsOfService: {
81
- type: 'string',
82
- },
61
+ title: { type: 'string' },
62
+ version: { type: 'string' },
63
+ description: { type: 'string' },
64
+ termsOfService: { type: 'string' },
83
65
  contact: 'Contact',
84
66
  license: 'License',
85
67
  },
@@ -87,25 +69,15 @@ const Info = {
87
69
  };
88
70
  const Contact = {
89
71
  properties: {
90
- name: {
91
- type: 'string',
92
- },
93
- url: {
94
- type: 'string',
95
- },
96
- email: {
97
- type: 'string',
98
- },
72
+ name: { type: 'string' },
73
+ url: { type: 'string' },
74
+ email: { type: 'string' },
99
75
  },
100
76
  };
101
77
  const License = {
102
78
  properties: {
103
- name: {
104
- type: 'string',
105
- },
106
- url: {
107
- type: 'string',
108
- },
79
+ name: { type: 'string' },
80
+ url: { type: 'string' },
109
81
  },
110
82
  required: ['name'],
111
83
  };
@@ -122,12 +94,8 @@ const PathItem = {
122
94
  $ref: { type: 'string' },
123
95
  servers: _1.listOf('Server'),
124
96
  parameters: _1.listOf('Parameter'),
125
- summary: {
126
- type: 'string',
127
- },
128
- description: {
129
- type: 'string',
130
- },
97
+ summary: { type: 'string' },
98
+ description: { type: 'string' },
131
99
  get: 'Operation',
132
100
  put: 'Operation',
133
101
  post: 'Operation',
@@ -140,33 +108,17 @@ const PathItem = {
140
108
  };
141
109
  const Parameter = {
142
110
  properties: {
143
- name: {
144
- type: 'string',
145
- },
146
- in: {
147
- enum: ['query', 'header', 'path', 'cookie'],
148
- },
149
- description: {
150
- type: 'string',
151
- },
152
- required: {
153
- type: 'boolean',
154
- },
155
- deprecated: {
156
- type: 'boolean',
157
- },
158
- allowEmptyValue: {
159
- type: 'boolean',
160
- },
111
+ name: { type: 'string' },
112
+ in: { enum: ['query', 'header', 'path', 'cookie'] },
113
+ description: { type: 'string' },
114
+ required: { type: 'boolean' },
115
+ deprecated: { type: 'boolean' },
116
+ allowEmptyValue: { type: 'boolean' },
161
117
  style: {
162
118
  enum: ['form', 'simple', 'label', 'matrix', 'spaceDelimited', 'pipeDelimited', 'deepObject'],
163
119
  },
164
- explode: {
165
- type: 'boolean',
166
- },
167
- allowReserved: {
168
- type: 'boolean',
169
- },
120
+ explode: { type: 'boolean' },
121
+ allowReserved: { type: 'boolean' },
170
122
  schema: 'Schema',
171
123
  example: { isExample: true },
172
124
  examples: _1.mapOf('Example'),
@@ -193,9 +145,7 @@ const Operation = {
193
145
  servers: _1.listOf('Server'),
194
146
  requestBody: 'RequestBody',
195
147
  responses: 'ResponsesMap',
196
- deprecated: {
197
- type: 'boolean',
198
- },
148
+ deprecated: { type: 'boolean' },
199
149
  callbacks: _1.mapOf('Callback'),
200
150
  'x-codeSamples': _1.listOf('XCodeSample'),
201
151
  'x-code-samples': _1.listOf('XCodeSample'), // deprecated
@@ -211,12 +161,8 @@ const XCodeSample = {
211
161
  };
212
162
  const RequestBody = {
213
163
  properties: {
214
- description: {
215
- type: 'string',
216
- },
217
- required: {
218
- type: 'boolean',
219
- },
164
+ description: { type: 'string' },
165
+ required: { type: 'boolean' },
220
166
  content: 'MediaTypeMap',
221
167
  },
222
168
  required: ['content'],
@@ -236,57 +182,33 @@ const MediaType = {
236
182
  const Example = {
237
183
  properties: {
238
184
  value: { isExample: true },
239
- summary: {
240
- type: 'string',
241
- },
242
- description: {
243
- type: 'string',
244
- },
245
- externalValue: {
246
- type: 'string',
247
- },
185
+ summary: { type: 'string' },
186
+ description: { type: 'string' },
187
+ externalValue: { type: 'string' },
248
188
  },
249
189
  };
250
190
  const Encoding = {
251
191
  properties: {
252
- contentType: {
253
- type: 'string',
254
- },
192
+ contentType: { type: 'string' },
255
193
  headers: _1.mapOf('Header'),
256
194
  style: {
257
195
  enum: ['form', 'simple', 'label', 'matrix', 'spaceDelimited', 'pipeDelimited', 'deepObject'],
258
196
  },
259
- explode: {
260
- type: 'boolean',
261
- },
262
- allowReserved: {
263
- type: 'boolean',
264
- },
197
+ explode: { type: 'boolean' },
198
+ allowReserved: { type: 'boolean' },
265
199
  },
266
200
  };
267
201
  const Header = {
268
202
  properties: {
269
- description: {
270
- type: 'string',
271
- },
272
- required: {
273
- type: 'boolean',
274
- },
275
- deprecated: {
276
- type: 'boolean',
277
- },
278
- allowEmptyValue: {
279
- type: 'boolean',
280
- },
203
+ description: { type: 'string' },
204
+ required: { type: 'boolean' },
205
+ deprecated: { type: 'boolean' },
206
+ allowEmptyValue: { type: 'boolean' },
281
207
  style: {
282
208
  enum: ['form', 'simple', 'label', 'matrix', 'spaceDelimited', 'pipeDelimited', 'deepObject'],
283
209
  },
284
- explode: {
285
- type: 'boolean',
286
- },
287
- allowReserved: {
288
- type: 'boolean',
289
- },
210
+ explode: { type: 'boolean' },
211
+ allowReserved: { type: 'boolean' },
290
212
  schema: 'Schema',
291
213
  example: { isExample: true },
292
214
  examples: _1.mapOf('Example'),
@@ -294,16 +216,12 @@ const Header = {
294
216
  },
295
217
  };
296
218
  const ResponsesMap = {
297
- properties: {
298
- default: 'Response',
299
- },
219
+ properties: { default: 'Response' },
300
220
  additionalProperties: (_v, key) => responseCodeRegexp.test(key) ? 'Response' : undefined,
301
221
  };
302
222
  const Response = {
303
223
  properties: {
304
- description: {
305
- type: 'string',
306
- },
224
+ description: { type: 'string' },
307
225
  headers: _1.mapOf('Header'),
308
226
  content: 'MediaTypeMap',
309
227
  links: _1.mapOf('Link'),
@@ -425,7 +343,7 @@ const ImplicitFlow = {
425
343
  scopes: { type: 'object', additionalProperties: { type: 'string' } },
426
344
  authorizationUrl: { type: 'string' },
427
345
  },
428
- required: ['authorizationUrl', 'scopes'],
346
+ required: ['authorizationUrl', 'scopes']
429
347
  };
430
348
  const PasswordFlow = {
431
349
  properties: {
@@ -465,30 +383,41 @@ const SecurityScheme = {
465
383
  type: { enum: ['apiKey', 'http', 'oauth2', 'openIdConnect'] },
466
384
  description: { type: 'string' },
467
385
  name: { type: 'string' },
468
- in: { type: 'string' },
386
+ in: { type: 'string', enum: ['query', 'header', 'cookie'] },
469
387
  scheme: { type: 'string' },
470
388
  bearerFormat: { type: 'string' },
471
389
  flows: 'SecuritySchemeFlows',
472
390
  openIdConnectUrl: { type: 'string' },
473
391
  },
474
392
  required(value) {
475
- if (!(value === null || value === void 0 ? void 0 : value.type)) {
476
- return ['type'];
393
+ switch (value === null || value === void 0 ? void 0 : value.type) {
394
+ case 'apiKey':
395
+ return ['type', 'name', 'in'];
396
+ case 'http':
397
+ return ['type', 'scheme'];
398
+ case 'oauth2':
399
+ return ['type', 'flows'];
400
+ case 'openIdConnect':
401
+ return ['type', 'openIdConnectUrl'];
402
+ default:
403
+ return ['type'];
477
404
  }
478
- if (value.type === 'apiKey') {
479
- return ['type', 'name', 'in'];
480
- }
481
- else if (value.type === 'http') {
482
- return ['type', 'scheme'];
483
- }
484
- else if (value.type === 'oauth2') {
485
- return ['type', 'flows'];
486
- }
487
- else if (value.type === 'openIdConnect') {
488
- return ['type', 'openIdConnectUrl'];
405
+ },
406
+ allowed(value) {
407
+ switch (value === null || value === void 0 ? void 0 : value.type) {
408
+ case 'apiKey':
409
+ return ['type', 'name', 'in', 'description'];
410
+ case 'http':
411
+ return ['type', 'scheme', 'bearerFormat', 'description'];
412
+ case 'oauth2':
413
+ return ['type', 'flows', 'description'];
414
+ case 'openIdConnect':
415
+ return ['type', 'openIdConnectUrl', 'description'];
416
+ default:
417
+ return ['type', 'description'];
489
418
  }
490
- return ['type'];
491
419
  },
420
+ extensionsPrefix: 'x-',
492
421
  };
493
422
  exports.Oas3Types = {
494
423
  DefinitionRoot,
@@ -21,35 +21,19 @@ const DefinitionRoot = {
21
21
  };
22
22
  const License = {
23
23
  properties: {
24
- name: {
25
- type: 'string',
26
- },
27
- url: {
28
- type: 'string',
29
- },
30
- identifier: {
31
- type: 'string',
32
- },
24
+ name: { type: 'string' },
25
+ url: { type: 'string' },
26
+ identifier: { type: 'string' },
33
27
  },
34
28
  required: ['name'],
35
29
  };
36
30
  const Info = {
37
31
  properties: {
38
- title: {
39
- type: 'string',
40
- },
41
- version: {
42
- type: 'string',
43
- },
44
- description: {
45
- type: 'string',
46
- },
47
- termsOfService: {
48
- type: 'string',
49
- },
50
- summary: {
51
- type: 'string',
52
- },
32
+ title: { type: 'string' },
33
+ version: { type: 'string' },
34
+ description: { type: 'string' },
35
+ termsOfService: { type: 'string' },
36
+ summary: { type: 'string' },
53
37
  contact: 'Contact',
54
38
  license: 'License',
55
39
  },
@@ -84,9 +68,7 @@ const Operation = {
84
68
  servers: _1.listOf('Server'),
85
69
  requestBody: 'RequestBody',
86
70
  responses: 'ResponsesMap',
87
- deprecated: {
88
- type: 'boolean',
89
- },
71
+ deprecated: { type: 'boolean' },
90
72
  callbacks: _1.mapOf('Callback'),
91
73
  'x-codeSamples': _1.listOf('XCodeSample'),
92
74
  'x-code-samples': _1.listOf('XCodeSample'), // deprecated
@@ -137,7 +119,7 @@ const Schema = {
137
119
  then: 'Schema',
138
120
  else: 'Schema',
139
121
  dependentSchemas: _1.listOf('Schema'),
140
- prefixItems: { type: 'array' },
122
+ prefixItems: _1.listOf('Schema'),
141
123
  contains: 'Schema',
142
124
  patternProperties: { type: 'object' },
143
125
  propertyNames: 'Schema',
@@ -149,18 +131,16 @@ const Schema = {
149
131
  if (Array.isArray(value)) {
150
132
  return _1.listOf('Schema');
151
133
  }
152
- else {
153
- return 'Schema';
154
- }
155
- },
156
- additionalProperties: (value) => {
157
- if (typeof value === 'boolean') {
134
+ else if (typeof value === 'boolean') {
158
135
  return { type: 'boolean' };
159
136
  }
160
137
  else {
161
138
  return 'Schema';
162
139
  }
163
140
  },
141
+ additionalProperties: (value) => {
142
+ return typeof value === 'boolean' ? { type: 'boolean' } : 'Schema';
143
+ },
164
144
  description: { type: 'string' },
165
145
  format: { type: 'string' },
166
146
  contentEncoding: { type: 'string' },
@@ -181,30 +161,53 @@ const SecurityScheme = {
181
161
  type: { enum: ['apiKey', 'http', 'oauth2', 'openIdConnect', 'mutualTLS'] },
182
162
  description: { type: 'string' },
183
163
  name: { type: 'string' },
184
- in: { type: 'string' },
164
+ in: { type: 'string', enum: ['query', 'header', 'cookie'] },
185
165
  scheme: { type: 'string' },
186
166
  bearerFormat: { type: 'string' },
187
167
  flows: 'SecuritySchemeFlows',
188
168
  openIdConnectUrl: { type: 'string' },
189
169
  },
190
170
  required(value) {
191
- if (!(value === null || value === void 0 ? void 0 : value.type)) {
192
- return ['type'];
193
- }
194
- if (value.type === 'apiKey') {
195
- return ['type', 'name', 'in'];
171
+ switch (value === null || value === void 0 ? void 0 : value.type) {
172
+ case 'apiKey':
173
+ return ['type', 'name', 'in'];
174
+ case 'http':
175
+ return ['type', 'scheme'];
176
+ case 'oauth2':
177
+ return ['type', 'flows'];
178
+ case 'openIdConnect':
179
+ return ['type', 'openIdConnectUrl'];
180
+ default:
181
+ return ['type'];
196
182
  }
197
- else if (value.type === 'http') {
198
- return ['type', 'scheme'];
199
- }
200
- else if (value.type === 'oauth2') {
201
- return ['type', 'flows'];
202
- }
203
- else if (value.type === 'openIdConnect') {
204
- return ['type', 'openIdConnectUrl'];
183
+ },
184
+ allowed(value) {
185
+ switch (value === null || value === void 0 ? void 0 : value.type) {
186
+ case 'apiKey':
187
+ return ['type', 'name', 'in', 'description'];
188
+ case 'http':
189
+ return ['type', 'scheme', 'bearerFormat', 'description'];
190
+ case 'oauth2':
191
+ switch (value === null || value === void 0 ? void 0 : value.flows) {
192
+ case 'implicit':
193
+ return ['type', 'flows', 'authorizationUrl', 'refreshUrl', 'description', 'scopes'];
194
+ case 'password':
195
+ case 'clientCredentials':
196
+ return ['type', 'flows', 'tokenUrl', 'refreshUrl', 'description', 'scopes'];
197
+ case 'authorizationCode':
198
+ return ['type', 'flows', 'authorizationUrl', 'refreshUrl', 'tokenUrl', 'description', 'scopes'];
199
+ default:
200
+ return ['type', 'flows', 'authorizationUrl', 'refreshUrl', 'tokenUrl', 'description', 'scopes'];
201
+ }
202
+ case 'openIdConnect':
203
+ return ['type', 'openIdConnectUrl', 'description'];
204
+ case 'mutualTLS':
205
+ return ['type', 'description'];
206
+ default:
207
+ return ['type', 'description'];
205
208
  }
206
- return ['type'];
207
209
  },
210
+ extensionsPrefix: 'x-',
208
211
  };
209
212
  exports.Oas3_1Types = Object.assign(Object.assign({}, oas3_1.Oas3Types), { Info,
210
213
  DefinitionRoot,
@@ -7,6 +7,7 @@ export interface Oas3Definition {
7
7
  security?: Oas3SecurityRequirement[];
8
8
  tags?: Oas3Tag[];
9
9
  externalDocs?: Oas3ExternalDocs;
10
+ 'x-webhooks'?: Oas3_1Webhooks;
10
11
  }
11
12
  export interface Oas3Info {
12
13
  title: string;
@@ -147,6 +148,12 @@ export interface Oas3Schema {
147
148
  export interface Oas3_1Schema extends Oas3Schema {
148
149
  examples?: any[];
149
150
  }
151
+ export interface Oas3_1Definition extends Oas3Definition {
152
+ webhooks?: Oas3_1Webhooks;
153
+ }
154
+ export interface Oas3_1Webhooks {
155
+ [webhook: string]: Referenced<Oas3PathItem>;
156
+ }
150
157
  export interface Oas3Discriminator {
151
158
  propertyName: string;
152
159
  mapping?: {
package/lib/utils.js CHANGED
@@ -138,7 +138,7 @@ function readFileAsStringSync(filePath) {
138
138
  }
139
139
  exports.readFileAsStringSync = readFileAsStringSync;
140
140
  function isPathParameter(pathSegment) {
141
- return pathSegment.startsWith('{') && pathSegment.endsWith('{');
141
+ return pathSegment.startsWith('{') && pathSegment.endsWith('}');
142
142
  }
143
143
  exports.isPathParameter = isPathParameter;
144
144
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/openapi-core",
3
- "version": "1.0.0-beta.79",
3
+ "version": "1.0.0-beta.83",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "engines": {
@@ -1,3 +1,4 @@
1
+ import { outdent } from 'outdent';
1
2
  import { parseYaml, stringifyYaml } from '../js-yaml';
2
3
 
3
4
  const yaml = `
@@ -7,7 +8,8 @@ const yaml = `
7
8
  number: 1000
8
9
  decimal: 12.34
9
10
  boolean: true
10
- date: 2020-01-01
11
+ dateWithoutQuotes: 2020-01-01
12
+ dateWithQuotes: '2020-01-01'
11
13
  array:
12
14
  - 1
13
15
  - 2
@@ -16,6 +18,16 @@ const yaml = `
16
18
  key2: 2
17
19
  `;
18
20
 
21
+ const yamlToDump = outdent`
22
+ date: '2022-01-21T11:29:56.694Z'
23
+ dateWithoutQuotes: 2020-01-01
24
+ dateWithQuotes: '2020-01-01'
25
+ dateImplicit: !!str 2020-01-01
26
+ string: test
27
+ stringWithQuotes: 'test'
28
+ stringWithDoubleQuotes: "test"
29
+ `;
30
+
19
31
  const jsObject = {
20
32
  emptyValue: null,
21
33
  'spaces in keys': 'spaces in keys',
@@ -23,7 +35,8 @@ const jsObject = {
23
35
  number: 1000,
24
36
  decimal: 12.34,
25
37
  boolean: true,
26
- date: '2020-01-01',
38
+ dateWithoutQuotes: '2020-01-01',
39
+ dateWithQuotes: '2020-01-01',
27
40
  array: [1, 2],
28
41
  object: { key1: 1, key2: 2 },
29
42
  };
@@ -33,14 +46,25 @@ describe('js-yaml', () => {
33
46
  expect(parseYaml(yaml)).toEqual(jsObject);
34
47
  });
35
48
 
49
+ test('should correctly dump date and string', () => {
50
+ expect(stringifyYaml(parseYaml(yamlToDump))).toMatchInlineSnapshot(
51
+ `
52
+ "date: '2022-01-21T11:29:56.694Z'
53
+ dateWithoutQuotes: '2020-01-01'
54
+ dateWithQuotes: '2020-01-01'
55
+ dateImplicit: '2020-01-01'
56
+ string: test
57
+ stringWithQuotes: test
58
+ stringWithDoubleQuotes: test
59
+ "
60
+ `);
61
+ });
62
+
36
63
  test('parse and stringify', () => {
37
64
  expect(parseYaml(stringifyYaml(jsObject))).toEqual(jsObject);
38
65
  });
39
66
 
40
67
  test('should throw an error for unsupported types', () => {
41
- expect(() => stringifyYaml({ date: new Date() }))
42
- .toThrow('unacceptable kind of an object to dump [object Date]');
43
-
44
68
  expect(() => stringifyYaml({ foo: () => {} }))
45
69
  .toThrow('unacceptable kind of an object to dump [object Function]');
46
70
  });
@@ -3,9 +3,7 @@ import { outdent } from 'outdent';
3
3
  import { lintFromString, lintConfig, lintDocument } from '../lint';
4
4
  import { BaseResolver } from '../resolve';
5
5
  import { loadConfig } from '../config/load';
6
- import { parseYamlToDocument, replaceSourceWithRef } from '../../__tests__/utils';
7
- // todo create general utils for tests and move this config.
8
- import { makeConfig } from '../rules/__tests__/config';
6
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../__tests__/utils';
9
7
 
10
8
  describe('lint', () => {
11
9
  it('lintFromString should work', async () => {
@@ -1,9 +1,13 @@
1
1
  import recommended from './recommended';
2
2
  import all from './all';
3
3
  import minimal from './minimal';
4
- import { LintRawConfig, Plugin } from './config';
5
-
6
- import * as builtinRules from '../rules/builtin';
4
+ import { CustomRulesConfig, LintRawConfig, Plugin } from './config';
5
+ import { rules as oas3Rules } from '../rules/oas3';
6
+ import { rules as oas2Rules } from '../rules/oas2';
7
+ import { preprocessors as oas3Preprocessors } from '../rules/oas3';
8
+ import { preprocessors as oas2Preprocessors } from '../rules/oas2';
9
+ import { decorators as oas3Decorators } from '../decorators/oas3';
10
+ import { decorators as oas2Decorators } from '../decorators/oas2';
7
11
 
8
12
  export const builtInConfigs: Record<string, LintRawConfig> = {
9
13
  recommended,
@@ -16,8 +20,17 @@ export const builtInConfigs: Record<string, LintRawConfig> = {
16
20
 
17
21
  export const defaultPlugin: Plugin = {
18
22
  id: '', // default plugin doesn't have id
19
- rules: builtinRules.rules,
20
- preprocessors: builtinRules.preprocessors,
21
- decorators: builtinRules.decorators,
23
+ rules: {
24
+ oas3: oas3Rules,
25
+ oas2: oas2Rules,
26
+ } as CustomRulesConfig,
27
+ preprocessors: {
28
+ oas3: oas3Preprocessors,
29
+ oas2: oas2Preprocessors,
30
+ },
31
+ decorators: {
32
+ oas3: oas3Decorators,
33
+ oas2: oas2Decorators,
34
+ },
22
35
  configs: builtInConfigs,
23
- }
36
+ }
@@ -1,8 +1,7 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { bundleDocument } from '../../bundle';
3
3
  import { BaseResolver } from '../../resolve';
4
- import { parseYamlToDocument, yamlSerializer } from '../../../__tests__/utils';
5
- import { makeConfig } from './config';
4
+ import { parseYamlToDocument, yamlSerializer, makeConfig } from '../../../__tests__/utils';
6
5
 
7
6
  describe('oas3 remove-x-internal', () => {
8
7
  expect.addSnapshotSerializer(yamlSerializer);