@kubb/adapter-oas 5.0.0-beta.57 → 5.0.0-beta.58

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/adapter-oas",
3
- "version": "5.0.0-beta.57",
3
+ "version": "5.0.0-beta.58",
4
4
  "description": "OpenAPI and Swagger adapter for Kubb. Parses and validates OAS 2.0/3.x specifications into a @kubb/ast RootNode for downstream code generation plugins.",
5
5
  "keywords": [
6
6
  "adapter",
@@ -46,8 +46,8 @@
46
46
  "api-ref-bundler": "0.5.1",
47
47
  "swagger2openapi": "^7.0.8",
48
48
  "yaml": "^2.9.0",
49
- "@kubb/ast": "5.0.0-beta.57",
50
- "@kubb/core": "5.0.0-beta.57"
49
+ "@kubb/ast": "5.0.0-beta.58",
50
+ "@kubb/core": "5.0.0-beta.58"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/json-schema": "^7.0.15",
package/src/adapter.ts CHANGED
@@ -191,7 +191,7 @@ export const adapterOas = createAdapter<AdapterOas>((options) => {
191
191
  const result = resolve(schemaName)
192
192
  if (!result) return null
193
193
 
194
- return ast.createImport({ name: [result.name], path: result.path })
194
+ return ast.factory.createImport({ name: [result.name], path: result.path })
195
195
  },
196
196
  })
197
197
  },
@@ -200,7 +200,7 @@ export const adapterOas = createAdapter<AdapterOas>((options) => {
200
200
 
201
201
  const [schemas, operations] = await Promise.all([Array.fromAsync(streamNode.schemas), Array.fromAsync(streamNode.operations)])
202
202
 
203
- return ast.createInput({ schemas, operations, meta: streamNode.meta })
203
+ return ast.factory.createInput({ schemas, operations, meta: streamNode.meta })
204
204
  },
205
205
  stream: createStream,
206
206
  }
@@ -82,8 +82,8 @@ export function patchDiscriminatorNode(node: ast.SchemaNode, entry: { propertyNa
82
82
  if (!objectNode) return node
83
83
 
84
84
  const { propertyName, enumValues } = entry
85
- const enumSchema = ast.createSchema({ type: 'enum', enumValues })
86
- const newProp = ast.createProperty({ name: propertyName, required: true, schema: enumSchema })
85
+ const enumSchema = ast.factory.createSchema({ type: 'enum', enumValues })
86
+ const newProp = ast.factory.createProperty({ name: propertyName, required: true, schema: enumSchema })
87
87
 
88
88
  const existingIdx = objectNode.properties.findIndex((p) => p.name === propertyName)
89
89
  const newProperties = existingIdx >= 0 ? objectNode.properties.map((p, i) => (i === existingIdx ? newProp : p)) : [...objectNode.properties, newProp]
package/src/parser.ts CHANGED
@@ -151,7 +151,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
151
151
  resolvedSchema = resolvedRefCache.get(refPath) ?? null
152
152
  }
153
153
 
154
- return ast.createSchema({
154
+ return ast.factory.createSchema({
155
155
  ...buildSchemaNode(schema, name, nullable, defaultValue),
156
156
  type: 'ref',
157
157
  name: extractRefName(schema.$ref!),
@@ -176,7 +176,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
176
176
  const mergedNullable = nullable || memberNode.nullable || undefined
177
177
  const mergedDefault = schema.default === null && mergedNullable ? undefined : (schema.default ?? memberNode.default)
178
178
 
179
- return ast.createSchema({
179
+ return ast.factory.createSchema({
180
180
  ...memberNodeProps,
181
181
  name,
182
182
  title: schema.title ?? memberNode.title,
@@ -264,10 +264,10 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
264
264
  }
265
265
 
266
266
  for (const { propertyName, value } of filteredDiscriminantValues) {
267
- allOfMembers.push(ast.createDiscriminantNode({ propertyName, value }))
267
+ allOfMembers.push(ast.factory.createDiscriminantNode({ propertyName, value }))
268
268
  }
269
269
 
270
- return ast.createSchema({
270
+ return ast.factory.createSchema({
271
271
  type: 'intersection',
272
272
  members: [...ast.mergeAdjacentObjectsLazy(allOfMembers.slice(0, syntheticStart)), ...ast.mergeAdjacentObjectsLazy(allOfMembers.slice(syntheticStart))],
273
273
  ...buildSchemaNode(schema, name, nullable, defaultValue),
@@ -286,7 +286,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
286
286
  return null
287
287
  }
288
288
 
289
- return ast.createSchema({
289
+ return ast.factory.createSchema({
290
290
  type: 'object',
291
291
  primitive: 'object',
292
292
  properties: [discriminatorProperty],
@@ -332,12 +332,12 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
332
332
  )
333
333
  : undefined
334
334
 
335
- return ast.createSchema({
335
+ return ast.factory.createSchema({
336
336
  type: 'intersection',
337
337
  members: [
338
338
  memberNode,
339
339
  narrowedDiscriminatorNode ??
340
- ast.createDiscriminantNode({
340
+ ast.factory.createDiscriminantNode({
341
341
  propertyName: discriminator.propertyName,
342
342
  value: discriminatorValue,
343
343
  }),
@@ -345,7 +345,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
345
345
  })
346
346
  })
347
347
 
348
- const unionNode = ast.createSchema({
348
+ const unionNode = ast.factory.createSchema({
349
349
  type: 'union',
350
350
  ...unionBase,
351
351
  members,
@@ -355,14 +355,14 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
355
355
  return unionNode
356
356
  }
357
357
 
358
- return ast.createSchema({
358
+ return ast.factory.createSchema({
359
359
  type: 'intersection',
360
360
  ...buildSchemaNode(schema, name, nullable, defaultValue),
361
361
  members: [unionNode, sharedPropertiesNode],
362
362
  })
363
363
  }
364
364
 
365
- return ast.createSchema({
365
+ return ast.factory.createSchema({
366
366
  type: 'union',
367
367
  ...unionBase,
368
368
  members: ast.simplifyUnion(unionMembers.map((s) => parseSchema({ schema: s as SchemaObject, name }, rawOptions))),
@@ -376,7 +376,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
376
376
  const constValue = schema.const
377
377
 
378
378
  if (constValue === null) {
379
- return ast.createSchema({
379
+ return ast.factory.createSchema({
380
380
  type: 'null',
381
381
  primitive: 'null',
382
382
  name,
@@ -388,7 +388,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
388
388
  }
389
389
 
390
390
  const constPrimitive = getPrimitiveType(typeof constValue === 'number' ? 'number' : typeof constValue === 'boolean' ? 'boolean' : 'string')
391
- return ast.createSchema({
391
+ return ast.factory.createSchema({
392
392
  type: 'enum',
393
393
  primitive: constPrimitive,
394
394
  enumValues: [constValue as string | number | boolean],
@@ -404,7 +404,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
404
404
  const base = buildSchemaNode(schema, name, nullable, defaultValue)
405
405
 
406
406
  if (schema.format === 'int64') {
407
- return ast.createSchema({
407
+ return ast.factory.createSchema({
408
408
  type: options.integerType === 'bigint' ? 'bigint' : 'integer',
409
409
  primitive: 'integer',
410
410
  ...base,
@@ -420,7 +420,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
420
420
  if (!dateType) return null
421
421
 
422
422
  if (dateType.type === 'datetime') {
423
- return ast.createSchema({
423
+ return ast.factory.createSchema({
424
424
  ...base,
425
425
  primitive: 'string' as const,
426
426
  type: 'datetime',
@@ -428,7 +428,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
428
428
  local: dateType.local,
429
429
  })
430
430
  }
431
- return ast.createSchema({
431
+ return ast.factory.createSchema({
432
432
  ...base,
433
433
  primitive: 'string' as const,
434
434
  type: dateType.type,
@@ -442,14 +442,14 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
442
442
  const specialPrimitive: ast.PrimitiveSchemaType = specialType === 'number' || specialType === 'integer' || specialType === 'bigint' ? specialType : 'string'
443
443
 
444
444
  if (specialType === 'number' || specialType === 'integer' || specialType === 'bigint') {
445
- return ast.createSchema({
445
+ return ast.factory.createSchema({
446
446
  ...base,
447
447
  primitive: specialPrimitive,
448
448
  type: specialType,
449
449
  })
450
450
  }
451
451
  if (specialType === 'url') {
452
- return ast.createSchema({
452
+ return ast.factory.createSchema({
453
453
  ...base,
454
454
  primitive: 'string' as const,
455
455
  type: 'url',
@@ -458,21 +458,21 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
458
458
  })
459
459
  }
460
460
  if (specialType === 'ipv4') {
461
- return ast.createSchema({
461
+ return ast.factory.createSchema({
462
462
  ...base,
463
463
  primitive: 'string' as const,
464
464
  type: 'ipv4',
465
465
  })
466
466
  }
467
467
  if (specialType === 'ipv6') {
468
- return ast.createSchema({
468
+ return ast.factory.createSchema({
469
469
  ...base,
470
470
  primitive: 'string' as const,
471
471
  type: 'ipv6',
472
472
  })
473
473
  }
474
474
  if (specialType === 'uuid' || specialType === 'email') {
475
- return ast.createSchema({
475
+ return ast.factory.createSchema({
476
476
  ...base,
477
477
  primitive: 'string' as const,
478
478
  type: specialType,
@@ -481,7 +481,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
481
481
  })
482
482
  }
483
483
 
484
- return ast.createSchema({
484
+ return ast.factory.createSchema({
485
485
  ...base,
486
486
  primitive: specialPrimitive,
487
487
  type: specialType as ast.ScalarSchemaType,
@@ -503,7 +503,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
503
503
  // render as `never` (plugin-ts) / invalid `z.enum([])` (plugin-zod). Mirror the `const: null`
504
504
  // branch so it renders as a clean `null` (not `z.null().nullable()`).
505
505
  if (nullInEnum && filteredValues.length === 0) {
506
- return ast.createSchema({
506
+ return ast.factory.createSchema({
507
507
  type: 'null',
508
508
  primitive: 'null',
509
509
  name,
@@ -543,7 +543,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
543
543
  const uniqueValues = [...new Set(filteredValues)]
544
544
  const seenNames = new Set<string>()
545
545
 
546
- return ast.createSchema({
546
+ return ast.factory.createSchema({
547
547
  ...enumBase,
548
548
  primitive: enumPrimitiveType,
549
549
  namedEnumValues: uniqueValues
@@ -560,7 +560,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
560
560
  })
561
561
  }
562
562
 
563
- return ast.createSchema({
563
+ return ast.factory.createSchema({
564
564
  ...enumBase,
565
565
  enumValues: [...new Set(filteredValues)],
566
566
  })
@@ -590,7 +590,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
590
590
  return node
591
591
  })()
592
592
 
593
- return ast.createProperty({
593
+ return ast.factory.createProperty({
594
594
  name: propName,
595
595
  schema: {
596
596
  ...schemaNode,
@@ -608,7 +608,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
608
608
  if (additionalProperties && Object.keys(additionalProperties).length > 0) {
609
609
  return parseSchema({ schema: additionalProperties as SchemaObject }, rawOptions)
610
610
  }
611
- if (additionalProperties) return ast.createSchema({ type: typeOptionMap.get(options.unknownType)! })
611
+ if (additionalProperties) return ast.factory.createSchema({ type: typeOptionMap.get(options.unknownType)! })
612
612
  return undefined
613
613
  })()
614
614
 
@@ -619,7 +619,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
619
619
  Object.entries(rawPatternProperties).map(([pattern, patternSchema]) => [
620
620
  pattern,
621
621
  patternSchema === true || (typeof patternSchema === 'object' && Object.keys(patternSchema).length === 0)
622
- ? ast.createSchema({
622
+ ? ast.factory.createSchema({
623
623
  type: typeOptionMap.get(options.unknownType)!,
624
624
  })
625
625
  : parseSchema({ schema: patternSchema as SchemaObject }, rawOptions),
@@ -627,7 +627,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
627
627
  )
628
628
  : undefined
629
629
 
630
- const objectNode: ast.SchemaNode = ast.createSchema({
630
+ const objectNode: ast.SchemaNode = ast.factory.createSchema({
631
631
  type: 'object',
632
632
  primitive: 'object',
633
633
  properties,
@@ -658,9 +658,9 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
658
658
  */
659
659
  function convertTuple({ schema, name, nullable, defaultValue, rawOptions }: SchemaContext): ast.SchemaNode {
660
660
  const tupleItems = (schema.prefixItems ?? []).map((item) => parseSchema({ schema: item as SchemaObject }, rawOptions))
661
- const rest = schema.items ? parseSchema({ schema: schema.items as SchemaObject }, rawOptions) : ast.createSchema({ type: 'any' })
661
+ const rest = schema.items ? parseSchema({ schema: schema.items as SchemaObject }, rawOptions) : ast.factory.createSchema({ type: 'any' })
662
662
 
663
- return ast.createSchema({
663
+ return ast.factory.createSchema({
664
664
  type: 'tuple',
665
665
  primitive: 'array',
666
666
  items: tupleItems,
@@ -679,7 +679,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
679
679
  const itemName = rawItems?.enum?.length && name ? enumPropName(null, name, options.enumSuffix) : name
680
680
  const items = rawItems ? [parseSchema({ schema: rawItems, name: itemName }, rawOptions)] : []
681
681
 
682
- return ast.createSchema({
682
+ return ast.factory.createSchema({
683
683
  type: 'array',
684
684
  primitive: 'array',
685
685
  items,
@@ -694,7 +694,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
694
694
  * Converts a `type: 'string'` schema into a `StringSchemaNode`.
695
695
  */
696
696
  function convertString({ schema, name, nullable, defaultValue }: SchemaContext): ast.SchemaNode {
697
- return ast.createSchema({
697
+ return ast.factory.createSchema({
698
698
  type: 'string',
699
699
  primitive: 'string',
700
700
  min: schema.minLength,
@@ -708,7 +708,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
708
708
  * Converts a `type: 'number'` or `type: 'integer'` schema.
709
709
  */
710
710
  function convertNumeric({ schema, name, nullable, defaultValue }: SchemaContext, type: 'number' | 'integer'): ast.SchemaNode {
711
- return ast.createSchema({
711
+ return ast.factory.createSchema({
712
712
  type,
713
713
  primitive: type,
714
714
  min: schema.minimum,
@@ -724,7 +724,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
724
724
  * Converts a `type: 'boolean'` schema.
725
725
  */
726
726
  function convertBoolean({ schema, name, nullable, defaultValue }: SchemaContext): ast.SchemaNode {
727
- return ast.createSchema({
727
+ return ast.factory.createSchema({
728
728
  type: 'boolean',
729
729
  primitive: 'boolean',
730
730
  ...buildSchemaNode(schema, name, nullable, defaultValue),
@@ -735,7 +735,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
735
735
  * Converts an explicit `type: 'null'` schema.
736
736
  */
737
737
  function convertNull({ schema, name, nullable }: SchemaContext): ast.SchemaNode {
738
- return ast.createSchema({
738
+ return ast.factory.createSchema({
739
739
  type: 'null',
740
740
  primitive: 'null',
741
741
  name,
@@ -752,7 +752,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
752
752
  * into a `blob` node.
753
753
  */
754
754
  function convertBlob({ schema, name, nullable, defaultValue }: SchemaContext): ast.SchemaNode {
755
- return ast.createSchema({
755
+ return ast.factory.createSchema({
756
756
  type: 'blob',
757
757
  primitive: 'string',
758
758
  ...buildSchemaNode(schema, name, nullable, defaultValue),
@@ -771,7 +771,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
771
771
  if (nonNullTypes.length <= 1) return null
772
772
 
773
773
  const arrayNullable = types.includes('null') || nullable || undefined
774
- return ast.createSchema({
774
+ return ast.factory.createSchema({
775
775
  type: 'union',
776
776
  members: nonNullTypes.map((t) => parseSchema({ schema: { ...schema, type: t } as SchemaObject, name }, rawOptions)),
777
777
  ...buildSchemaNode(schema, name, arrayNullable, defaultValue),
@@ -859,7 +859,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
859
859
  }
860
860
 
861
861
  const emptyType = typeOptionMap.get(options.emptySchemaType)!
862
- return ast.createSchema({
862
+ return ast.factory.createSchema({
863
863
  type: emptyType as ast.ScalarSchemaType,
864
864
  name,
865
865
  title: schema.title,
@@ -878,9 +878,9 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
878
878
 
879
879
  const schema: ast.SchemaNode = param['schema']
880
880
  ? parseSchema({ schema: param['schema'] as SchemaObject, name: schemaName }, options)
881
- : ast.createSchema({ type: typeOptionMap.get(options.unknownType)! })
881
+ : ast.factory.createSchema({ type: typeOptionMap.get(options.unknownType)! })
882
882
 
883
- return ast.createParameter({
883
+ return ast.factory.createParameter({
884
884
  name: paramName,
885
885
  in: param['in'] as ast.ParameterLocation,
886
886
  schema: {
@@ -996,7 +996,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
996
996
  const node =
997
997
  raw && Object.keys(raw).length > 0
998
998
  ? parseSchema({ schema: raw, name: responseName }, options)
999
- : ast.createSchema({ type: typeOptionMap.get(options.emptySchemaType)! })
999
+ : ast.factory.createSchema({ type: typeOptionMap.get(options.emptySchemaType)! })
1000
1000
  return { schema: node, keysToOmit: collectPropertyKeysByFlag(raw, 'writeOnly') }
1001
1001
  }
1002
1002
 
@@ -1011,7 +1011,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
1011
1011
  content.push({ contentType: getRequestContentType({ document, operation }) || 'application/json', ...parseEntrySchema(ctx.contentType) })
1012
1012
  }
1013
1013
 
1014
- return ast.createResponse({
1014
+ return ast.factory.createResponse({
1015
1015
  statusCode: statusCode as ast.StatusCode,
1016
1016
  description,
1017
1017
  content,
@@ -1027,7 +1027,7 @@ export function createSchemaParser(ctx: OasParserContext, dialect: OasDialect =
1027
1027
  return typeof fallback === 'string' ? fallback : undefined
1028
1028
  }
1029
1029
 
1030
- return ast.createOperation({
1030
+ return ast.factory.createOperation({
1031
1031
  operationId,
1032
1032
  protocol: 'http',
1033
1033
  method: operation.method.toUpperCase() as ast.HttpMethod,
@@ -1105,7 +1105,7 @@ export function parseOas(
1105
1105
  .map((operation) => _parseOperation(mergedOptions, operation))
1106
1106
  .filter((op): op is ast.OperationNode => op !== null)
1107
1107
 
1108
- const root = ast.createInput({ schemas, operations })
1108
+ const root = ast.factory.createInput({ schemas, operations })
1109
1109
 
1110
1110
  return { root, nameMapping }
1111
1111
  }
package/src/stream.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { containsCircularRef, findCircularSchemas } from '@kubb/ast/utils'
1
2
  import { ast } from '@kubb/core'
2
3
  import { SCHEMA_REF_PREFIX } from './constants.ts'
3
4
  import { buildDiscriminatorChildMap, patchDiscriminatorNode } from './discriminator.ts'
@@ -44,7 +45,7 @@ function createDedupePlan({
44
45
  if (node.type !== 'object') return false
45
46
  // Skip object shapes that are part of a circular chain, hoisting them would break the cycle.
46
47
  if (node.name && circularSchemas.has(node.name)) return false
47
- return !ast.containsCircularRef(node, { circularSchemas })
48
+ return !containsCircularRef(node, { circularSchemas })
48
49
  },
49
50
  nameFor: (node) => {
50
51
  const base = node.name
@@ -149,7 +150,7 @@ export function preScan({
149
150
  }
150
151
  }
151
152
 
152
- const circularNames = [...ast.findCircularSchemas(allNodes)]
153
+ const circularNames = [...findCircularSchemas(allNodes)]
153
154
  const discriminatorChildMap = discriminatorParentNodes.length > 0 ? buildDiscriminatorChildMap(discriminatorParentNodes) : null
154
155
 
155
156
  let dedupePlan: ast.DedupePlan | null = null
@@ -224,7 +225,7 @@ export function createInputStream({
224
225
 
225
226
  const canonical = dedupePlan.canonicalBySignature.get(ast.signatureOf(node))
226
227
  if (canonical && canonical.name !== node.name) {
227
- return ast.createSchema({
228
+ return ast.factory.createSchema({
228
229
  type: 'ref',
229
230
  name: node.name ?? null,
230
231
  ref: canonical.ref,
@@ -278,5 +279,5 @@ export function createInputStream({
278
279
  },
279
280
  }
280
281
 
281
- return ast.createStreamInput(schemasIterable, operationsIterable, meta)
282
+ return ast.factory.createInput({ stream: true, schemas: schemasIterable, operations: operationsIterable, meta })
282
283
  }