@redocly/openapi-core 1.0.0-beta.80 → 1.0.0-beta.81

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.
package/src/types/oas3.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { NodeType, listOf, mapOf } from '.';
2
2
  import { isMappingRef } from '../ref-utils';
3
-
4
3
  const responseCodeRegexp = /^[0-9][0-9Xx]{2}$/;
5
4
 
6
5
  const DefinitionRoot: NodeType = {
@@ -29,24 +28,16 @@ const Tag: NodeType = {
29
28
 
30
29
  const ExternalDocs: NodeType = {
31
30
  properties: {
32
- description: {
33
- type: 'string',
34
- },
35
- url: {
36
- type: 'string',
37
- },
31
+ description: { type: 'string' },
32
+ url: { type: 'string' },
38
33
  },
39
34
  required: ['url'],
40
35
  };
41
36
 
42
37
  const Server: NodeType = {
43
38
  properties: {
44
- url: {
45
- type: 'string',
46
- },
47
- description: {
48
- type: 'string',
49
- },
39
+ url: { type: 'string' },
40
+ description: { type: 'string' },
50
41
  variables: mapOf('ServerVariable'),
51
42
  },
52
43
  required: ['url'],
@@ -58,9 +49,7 @@ const ServerVariable: NodeType = {
58
49
  type: 'array',
59
50
  items: { type: 'string' },
60
51
  },
61
- default: {
62
- type: 'string',
63
- },
52
+ default: { type: 'string' },
64
53
  description: null,
65
54
  },
66
55
  required: ['default'],
@@ -73,18 +62,10 @@ const SecurityRequirement: NodeType = {
73
62
 
74
63
  const Info: NodeType = {
75
64
  properties: {
76
- title: {
77
- type: 'string',
78
- },
79
- version: {
80
- type: 'string',
81
- },
82
- description: {
83
- type: 'string',
84
- },
85
- termsOfService: {
86
- type: 'string',
87
- },
65
+ title: { type: 'string' },
66
+ version: { type: 'string' },
67
+ description: { type: 'string' },
68
+ termsOfService: { type: 'string' },
88
69
  contact: 'Contact',
89
70
  license: 'License',
90
71
  },
@@ -93,26 +74,16 @@ const Info: NodeType = {
93
74
 
94
75
  const Contact: NodeType = {
95
76
  properties: {
96
- name: {
97
- type: 'string',
98
- },
99
- url: {
100
- type: 'string',
101
- },
102
- email: {
103
- type: 'string',
104
- },
77
+ name: { type: 'string' },
78
+ url: { type: 'string' },
79
+ email: { type: 'string' },
105
80
  },
106
81
  };
107
82
 
108
83
  const License: NodeType = {
109
84
  properties: {
110
- name: {
111
- type: 'string',
112
- },
113
- url: {
114
- type: 'string',
115
- },
85
+ name: { type: 'string' },
86
+ url: { type: 'string' },
116
87
  },
117
88
  required: ['name'],
118
89
  };
@@ -133,12 +104,8 @@ const PathItem: NodeType = {
133
104
  $ref: { type: 'string' }, // TODO: verify special $ref handling for Path Item
134
105
  servers: listOf('Server'),
135
106
  parameters: listOf('Parameter'),
136
- summary: {
137
- type: 'string',
138
- },
139
- description: {
140
- type: 'string',
141
- },
107
+ summary: { type: 'string' },
108
+ description: { type: 'string' },
142
109
  get: 'Operation',
143
110
  put: 'Operation',
144
111
  post: 'Operation',
@@ -152,33 +119,17 @@ const PathItem: NodeType = {
152
119
 
153
120
  const Parameter: NodeType = {
154
121
  properties: {
155
- name: {
156
- type: 'string',
157
- },
158
- in: {
159
- enum: ['query', 'header', 'path', 'cookie'],
160
- },
161
- description: {
162
- type: 'string',
163
- },
164
- required: {
165
- type: 'boolean',
166
- },
167
- deprecated: {
168
- type: 'boolean',
169
- },
170
- allowEmptyValue: {
171
- type: 'boolean',
172
- },
122
+ name: { type: 'string' },
123
+ in: { enum: ['query', 'header', 'path', 'cookie'] },
124
+ description: { type: 'string' },
125
+ required: { type: 'boolean' },
126
+ deprecated: { type: 'boolean' },
127
+ allowEmptyValue: { type: 'boolean' },
173
128
  style: {
174
129
  enum: ['form', 'simple', 'label', 'matrix', 'spaceDelimited', 'pipeDelimited', 'deepObject'],
175
130
  },
176
- explode: {
177
- type: 'boolean',
178
- },
179
- allowReserved: {
180
- type: 'boolean',
181
- },
131
+ explode: { type: 'boolean' },
132
+ allowReserved: { type: 'boolean' },
182
133
  schema: 'Schema',
183
134
  example: { isExample: true },
184
135
  examples: mapOf('Example'),
@@ -207,9 +158,7 @@ const Operation: NodeType = {
207
158
  servers: listOf('Server'),
208
159
  requestBody: 'RequestBody',
209
160
  responses: 'ResponsesMap',
210
- deprecated: {
211
- type: 'boolean',
212
- },
161
+ deprecated: { type: 'boolean' },
213
162
  callbacks: mapOf('Callback'),
214
163
  'x-codeSamples': listOf('XCodeSample'),
215
164
  'x-code-samples': listOf('XCodeSample'), // deprecated
@@ -227,12 +176,8 @@ const XCodeSample: NodeType = {
227
176
 
228
177
  const RequestBody: NodeType = {
229
178
  properties: {
230
- description: {
231
- type: 'string',
232
- },
233
- required: {
234
- type: 'boolean',
235
- },
179
+ description: { type: 'string' },
180
+ required: { type: 'boolean' },
236
181
  content: 'MediaTypeMap',
237
182
  },
238
183
  required: ['content'],
@@ -255,59 +200,35 @@ const MediaType: NodeType = {
255
200
  const Example: NodeType = {
256
201
  properties: {
257
202
  value: { isExample: true },
258
- summary: {
259
- type: 'string',
260
- },
261
- description: {
262
- type: 'string',
263
- },
264
- externalValue: {
265
- type: 'string',
266
- },
203
+ summary: { type: 'string' },
204
+ description: { type: 'string' },
205
+ externalValue: { type: 'string' },
267
206
  },
268
207
  };
269
208
 
270
209
  const Encoding: NodeType = {
271
210
  properties: {
272
- contentType: {
273
- type: 'string',
274
- },
211
+ contentType: { type: 'string' },
275
212
  headers: mapOf('Header'),
276
213
  style: {
277
214
  enum: ['form', 'simple', 'label', 'matrix', 'spaceDelimited', 'pipeDelimited', 'deepObject'],
278
215
  },
279
- explode: {
280
- type: 'boolean',
281
- },
282
- allowReserved: {
283
- type: 'boolean',
284
- },
216
+ explode: { type: 'boolean' },
217
+ allowReserved: { type: 'boolean' },
285
218
  },
286
219
  };
287
220
 
288
221
  const Header: NodeType = {
289
222
  properties: {
290
- description: {
291
- type: 'string',
292
- },
293
- required: {
294
- type: 'boolean',
295
- },
296
- deprecated: {
297
- type: 'boolean',
298
- },
299
- allowEmptyValue: {
300
- type: 'boolean',
301
- },
223
+ description: { type: 'string' },
224
+ required: { type: 'boolean' },
225
+ deprecated: { type: 'boolean' },
226
+ allowEmptyValue: { type: 'boolean' },
302
227
  style: {
303
228
  enum: ['form', 'simple', 'label', 'matrix', 'spaceDelimited', 'pipeDelimited', 'deepObject'],
304
229
  },
305
- explode: {
306
- type: 'boolean',
307
- },
308
- allowReserved: {
309
- type: 'boolean',
310
- },
230
+ explode: { type: 'boolean' },
231
+ allowReserved: { type: 'boolean' },
311
232
  schema: 'Schema',
312
233
  example: { isExample: true },
313
234
  examples: mapOf('Example'),
@@ -316,18 +237,14 @@ const Header: NodeType = {
316
237
  };
317
238
 
318
239
  const ResponsesMap: NodeType = {
319
- properties: {
320
- default: 'Response',
321
- },
240
+ properties: { default: 'Response' },
322
241
  additionalProperties: (_v: any, key: string) =>
323
242
  responseCodeRegexp.test(key) ? 'Response' : undefined,
324
243
  };
325
244
 
326
245
  const Response: NodeType = {
327
246
  properties: {
328
- description: {
329
- type: 'string',
330
- },
247
+ description: { type: 'string' },
331
248
  headers: mapOf('Header'),
332
249
  content: 'MediaTypeMap',
333
250
  links: mapOf('Link'),
@@ -391,9 +308,7 @@ const Schema: NodeType = {
391
308
  description: { type: 'string' },
392
309
  format: { type: 'string' },
393
310
  default: null,
394
-
395
311
  nullable: { type: 'boolean' },
396
-
397
312
  readOnly: { type: 'boolean' },
398
313
  writeOnly: { type: 'boolean' },
399
314
  xml: 'Xml',
@@ -456,7 +371,7 @@ const ImplicitFlow: NodeType = {
456
371
  scopes: { type: 'object', additionalProperties: { type: 'string' } }, // TODO: validate scopes
457
372
  authorizationUrl: { type: 'string' },
458
373
  },
459
- required: ['authorizationUrl', 'scopes'],
374
+ required: ['authorizationUrl', 'scopes']
460
375
  };
461
376
 
462
377
  const PasswordFlow: NodeType = {
@@ -501,29 +416,41 @@ const SecurityScheme: NodeType = {
501
416
  type: { enum: ['apiKey', 'http', 'oauth2', 'openIdConnect'] },
502
417
  description: { type: 'string' },
503
418
  name: { type: 'string' },
504
- in: { type: 'string' },
419
+ in: { type: 'string', enum: ['query', 'header', 'cookie'] },
505
420
  scheme: { type: 'string' },
506
421
  bearerFormat: { type: 'string' },
507
422
  flows: 'SecuritySchemeFlows',
508
423
  openIdConnectUrl: { type: 'string' },
509
424
  },
510
425
  required(value) {
511
- if (!value?.type) {
512
- return ['type'];
426
+ switch (value?.type) {
427
+ case 'apiKey':
428
+ return ['type', 'name', 'in'];
429
+ case 'http':
430
+ return ['type', 'scheme'];
431
+ case 'oauth2':
432
+ return ['type', 'flows'];
433
+ case 'openIdConnect':
434
+ return ['type', 'openIdConnectUrl'];
435
+ default:
436
+ return ['type'];
513
437
  }
514
-
515
- if (value.type === 'apiKey') {
516
- return ['type', 'name', 'in'];
517
- } else if (value.type === 'http') {
518
- return ['type', 'scheme'];
519
- } else if (value.type === 'oauth2') {
520
- return ['type', 'flows'];
521
- } else if (value.type === 'openIdConnect') {
522
- return ['type', 'openIdConnectUrl'];
438
+ },
439
+ allowed(value) {
440
+ switch (value?.type) {
441
+ case 'apiKey':
442
+ return ['type', 'name', 'in', 'description'];
443
+ case 'http':
444
+ return ['type', 'scheme', 'bearerFormat', 'description'];
445
+ case 'oauth2':
446
+ return ['type', 'flows', 'description'];
447
+ case 'openIdConnect':
448
+ return ['type', 'openIdConnectUrl', 'description'];
449
+ default:
450
+ return ['type', 'description'];
523
451
  }
524
-
525
- return ['type'];
526
452
  },
453
+ extensionsPrefix: 'x-',
527
454
  };
528
455
 
529
456
  export const Oas3Types: Record<string, NodeType> = {
@@ -20,36 +20,20 @@ const DefinitionRoot: NodeType = {
20
20
 
21
21
  const License: NodeType = {
22
22
  properties: {
23
- name: {
24
- type: 'string',
25
- },
26
- url: {
27
- type: 'string',
28
- },
29
- identifier: {
30
- type: 'string',
31
- },
23
+ name: { type: 'string' },
24
+ url: { type: 'string' },
25
+ identifier: { type: 'string' },
32
26
  },
33
27
  required: ['name'],
34
28
  };
35
29
 
36
30
  const Info: NodeType = {
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
  },
@@ -86,9 +70,7 @@ const Operation: NodeType = {
86
70
  servers: listOf('Server'),
87
71
  requestBody: 'RequestBody',
88
72
  responses: 'ResponsesMap',
89
- deprecated: {
90
- type: 'boolean',
91
- },
73
+ deprecated: { type: 'boolean' },
92
74
  callbacks: mapOf('Callback'),
93
75
  'x-codeSamples': listOf('XCodeSample'),
94
76
  'x-code-samples': listOf('XCodeSample'), // deprecated
@@ -103,7 +85,6 @@ const Schema: NodeType = {
103
85
  definitions: 'NamedSchemas',
104
86
  $defs: 'NamedSchemas',
105
87
  $vocabulary: { type: 'string' },
106
-
107
88
  externalDocs: 'ExternalDocs',
108
89
  discriminator: 'Discriminator',
109
90
  myArbitraryKeyword: { type: 'boolean' },
@@ -140,35 +121,31 @@ const Schema: NodeType = {
140
121
  then: 'Schema',
141
122
  else: 'Schema',
142
123
  dependentSchemas: listOf('Schema'),
143
- prefixItems: { type: 'array' },
124
+ prefixItems: listOf('Schema'),
144
125
  contains: 'Schema',
145
126
  patternProperties: { type: 'object' },
146
127
  propertyNames: 'Schema',
147
128
  unevaluatedItems: 'Schema',
148
129
  unevaluatedProperties: 'Schema',
149
130
  summary: { type: 'string' },
150
-
151
131
  properties: 'SchemaProperties',
152
132
  items: (value: any) => {
153
133
  if (Array.isArray(value)) {
154
134
  return listOf('Schema');
135
+ } else if (typeof value === 'boolean') {
136
+ return { type: 'boolean' };
155
137
  } else {
156
138
  return 'Schema';
157
139
  }
158
140
  },
159
141
  additionalProperties: (value: any) => {
160
- if (typeof value === 'boolean') {
161
- return { type: 'boolean' };
162
- } else {
163
- return 'Schema';
164
- }
142
+ return typeof value === 'boolean' ? { type: 'boolean' } : 'Schema';
165
143
  },
166
144
  description: { type: 'string' },
167
145
  format: { type: 'string' },
168
146
  contentEncoding: { type: 'string' },
169
147
  contentMediaType: { type: 'string' },
170
148
  default: null,
171
-
172
149
  readOnly: { type: 'boolean' },
173
150
  writeOnly: { type: 'boolean' },
174
151
  xml: 'Xml',
@@ -185,29 +162,53 @@ const SecurityScheme: NodeType = {
185
162
  type: { enum: ['apiKey', 'http', 'oauth2', 'openIdConnect', 'mutualTLS'] },
186
163
  description: { type: 'string' },
187
164
  name: { type: 'string' },
188
- in: { type: 'string' },
165
+ in: { type: 'string', enum: ['query', 'header', 'cookie'] },
189
166
  scheme: { type: 'string' },
190
167
  bearerFormat: { type: 'string' },
191
168
  flows: 'SecuritySchemeFlows',
192
169
  openIdConnectUrl: { type: 'string' },
193
170
  },
194
171
  required(value) {
195
- if (!value?.type) {
196
- return ['type'];
172
+ switch (value?.type) {
173
+ case 'apiKey':
174
+ return ['type', 'name', 'in'];
175
+ case 'http':
176
+ return ['type', 'scheme'];
177
+ case 'oauth2':
178
+ return ['type', 'flows'];
179
+ case 'openIdConnect':
180
+ return ['type', 'openIdConnectUrl'];
181
+ default:
182
+ return ['type'];
197
183
  }
198
-
199
- if (value.type === 'apiKey') {
200
- return ['type', 'name', 'in'];
201
- } else if (value.type === 'http') {
202
- return ['type', 'scheme'];
203
- } else if (value.type === 'oauth2') {
204
- return ['type', 'flows'];
205
- } else if (value.type === 'openIdConnect') {
206
- return ['type', 'openIdConnectUrl'];
184
+ },
185
+ allowed(value) {
186
+ switch (value?.type) {
187
+ case 'apiKey':
188
+ return ['type', 'name', 'in', 'description'];
189
+ case 'http':
190
+ return ['type', 'scheme', 'bearerFormat', 'description'];
191
+ case 'oauth2':
192
+ switch (value?.flows) {
193
+ case 'implicit':
194
+ return ['type', 'flows', 'authorizationUrl', 'refreshUrl', 'description', 'scopes'];
195
+ case 'password':
196
+ case 'clientCredentials':
197
+ return ['type', 'flows', 'tokenUrl', 'refreshUrl', 'description', 'scopes'];
198
+ case 'authorizationCode':
199
+ return ['type', 'flows', 'authorizationUrl', 'refreshUrl', 'tokenUrl', 'description', 'scopes'];
200
+ default:
201
+ return ['type', 'flows', 'authorizationUrl', 'refreshUrl', 'tokenUrl', 'description', 'scopes'];
202
+ }
203
+ case 'openIdConnect':
204
+ return ['type', 'openIdConnectUrl', 'description'];
205
+ case 'mutualTLS':
206
+ return ['type', 'description'];
207
+ default:
208
+ return ['type', 'description'];
207
209
  }
208
-
209
- return ['type'];
210
210
  },
211
+ extensionsPrefix: 'x-',
211
212
  };
212
213
 
213
214
  export const Oas3_1Types: Record<string, NodeType> = {
package/src/utils.ts CHANGED
@@ -153,7 +153,7 @@ export function readFileAsStringSync(filePath: string) {
153
153
  }
154
154
 
155
155
  export function isPathParameter(pathSegment: string) {
156
- return pathSegment.startsWith('{') && pathSegment.endsWith('{');
156
+ return pathSegment.startsWith('{') && pathSegment.endsWith('}');
157
157
  }
158
158
 
159
159