@kubb/oas 4.33.4 → 4.34.0

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/oas",
3
- "version": "4.33.4",
3
+ "version": "4.34.0",
4
4
  "description": "OpenAPI Specification (OAS) utilities and helpers for Kubb, providing parsing, normalization, and manipulation of OpenAPI/Swagger schemas.",
5
5
  "keywords": [
6
6
  "openapi",
@@ -52,20 +52,25 @@
52
52
  }
53
53
  ],
54
54
  "dependencies": {
55
+ "@kubb/fabric-core": "0.13.3",
55
56
  "@redocly/openapi-core": "^2.21.1",
57
+ "@stoplight/yaml": "^4.3.0",
56
58
  "jsonpointer": "^5.0.1",
57
59
  "oas": "^31.1.2",
58
60
  "oas-normalize": "^16.0.2",
59
61
  "openapi-types": "^12.1.3",
60
62
  "remeda": "^2.33.6",
61
63
  "swagger2openapi": "^7.0.8",
62
- "@kubb/core": "4.33.4"
64
+ "@kubb/ast": "4.34.0",
65
+ "@kubb/core": "4.34.0"
63
66
  },
64
67
  "devDependencies": {
65
- "@stoplight/yaml": "^4.3.0",
66
68
  "@types/swagger2openapi": "^7.0.4",
67
69
  "@internals/utils": "0.0.0"
68
70
  },
71
+ "peerDependencies": {
72
+ "@kubb/fabric-core": "0.13.3"
73
+ },
69
74
  "engines": {
70
75
  "node": ">=20"
71
76
  },
@@ -75,13 +80,6 @@
75
80
  },
76
81
  "main": "./dist/index.cjs",
77
82
  "module": "./dist/index.js",
78
- "inlinedDependencies": {
79
- "tslib": "2.8.1",
80
- "@stoplight/yaml-ast-parser": "0.0.50",
81
- "@stoplight/yaml": "4.3.0",
82
- "@stoplight/ordered-object-literal": "1.0.5",
83
- "@stoplight/types": "14.1.1"
84
- },
85
83
  "scripts": {
86
84
  "build": "tsdown && size-limit",
87
85
  "clean": "npx rimraf ./dist",
package/src/Oas.ts CHANGED
@@ -548,7 +548,17 @@ export class Oas extends BaseOas {
548
548
  // Collect schemas from components
549
549
  if (includes.includes('schemas')) {
550
550
  const componentSchemas = (components?.schemas as Record<string, SchemaObject>) || {}
551
- for (const [name, schema] of Object.entries(componentSchemas)) {
551
+ for (const [name, schemaObject] of Object.entries(componentSchemas)) {
552
+ // Resolve schema if it's a $ref (can happen when the bundler deduplicates schemas
553
+ // referenced from multiple external files). Without this, a $ref schema would be
554
+ // parsed as a reference to itself, generating `z.lazy(() => schemaName)`.
555
+ let schema = schemaObject
556
+ if (isReference(schemaObject)) {
557
+ const resolved = this.get<SchemaObject>(schemaObject.$ref)
558
+ if (resolved && !isReference(resolved)) {
559
+ schema = resolved
560
+ }
561
+ }
552
562
  schemasWithMeta.push({ schema, source: 'schemas', originalName: name })
553
563
  }
554
564
  }
@@ -559,7 +569,17 @@ export class Oas extends BaseOas {
559
569
  const responseObject = response as ResponseObject
560
570
  const schema = extractSchemaFromContent(responseObject.content, contentType)
561
571
  if (schema) {
562
- schemasWithMeta.push({ schema, source: 'responses', originalName: name })
572
+ // Resolve schema if it's a $ref (can happen when the bundler deduplicates schemas
573
+ // referenced from multiple external files). Without this, a $ref schema would be
574
+ // parsed as a reference to itself, generating `z.lazy(() => schemaName)`.
575
+ let resolvedSchema = schema
576
+ if (isReference(schema)) {
577
+ const resolved = this.get<SchemaObject>(schema.$ref)
578
+ if (resolved && !isReference(resolved)) {
579
+ resolvedSchema = resolved
580
+ }
581
+ }
582
+ schemasWithMeta.push({ schema: resolvedSchema, source: 'responses', originalName: name })
563
583
  }
564
584
  }
565
585
  }
@@ -570,7 +590,17 @@ export class Oas extends BaseOas {
570
590
  const requestObject = request as { content?: Record<string, unknown> }
571
591
  const schema = extractSchemaFromContent(requestObject.content, contentType)
572
592
  if (schema) {
573
- schemasWithMeta.push({ schema, source: 'requestBodies', originalName: name })
593
+ // Resolve schema if it's a $ref (can happen when the bundler deduplicates schemas
594
+ // referenced from multiple external files). Without this, a $ref schema would be
595
+ // parsed as a reference to itself, generating `z.lazy(() => schemaName)`.
596
+ let resolvedSchema = schema
597
+ if (isReference(schema)) {
598
+ const resolved = this.get<SchemaObject>(schema.$ref)
599
+ if (resolved && !isReference(resolved)) {
600
+ resolvedSchema = resolved
601
+ }
602
+ }
603
+ schemasWithMeta.push({ schema: resolvedSchema, source: 'requestBodies', originalName: name })
574
604
  }
575
605
  }
576
606
  }
@@ -0,0 +1,88 @@
1
+ import type { MediaType, SchemaType } from '@kubb/ast/types'
2
+ import type { HttpMethods as OASHttpMethods } from 'oas/types'
3
+
4
+ /**
5
+ * JSON Schema keywords that indicate structural composition.
6
+ * Used when deciding whether an inline `allOf` fragment can be safely flattened
7
+ * into its parent (fragments containing any of these keys must not be inlined).
8
+ */
9
+ export const STRUCTURAL_KEYS = new Set<string>(['properties', 'items', 'additionalProperties', 'oneOf', 'anyOf', 'allOf', 'not'])
10
+
11
+ /**
12
+ * Maps OAS/JSON Schema `format` strings to their Kubb `SchemaType` equivalents.
13
+ *
14
+ * Only formats that require a type different from the raw OAS `type` are listed here.
15
+ * `int64`, `date-time`, `date`, and `time` are handled separately because their
16
+ * output depends on runtime parser options and cannot live in a static map.
17
+ *
18
+ * Note: `ipv4`, `ipv6`, and `hostname` map to `'url'` — not semantically accurate,
19
+ * but `'url'` is the closest supported scalar type in the Kubb AST.
20
+ */
21
+ export const FORMAT_MAP = {
22
+ uuid: 'uuid',
23
+ email: 'email',
24
+ 'idn-email': 'email',
25
+ uri: 'url',
26
+ 'uri-reference': 'url',
27
+ url: 'url',
28
+ ipv4: 'url',
29
+ ipv6: 'url',
30
+ hostname: 'url',
31
+ 'idn-hostname': 'url',
32
+ binary: 'blob',
33
+ byte: 'blob',
34
+ // Numeric formats — format is more specific than type, so these override type.
35
+ // see https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.7
36
+ int32: 'integer',
37
+ float: 'number',
38
+ double: 'number',
39
+ } as const satisfies Record<string, SchemaType>
40
+
41
+ /**
42
+ * Exhaustive list of media types that Kubb recognizes.
43
+ * Kept as a module-level constant to avoid re-allocating the array on every call.
44
+ */
45
+ export const KNOWN_MEDIA_TYPES = [
46
+ 'application/json',
47
+ 'application/xml',
48
+ 'application/x-www-form-urlencoded',
49
+ 'application/octet-stream',
50
+ 'application/pdf',
51
+ 'application/zip',
52
+ 'application/graphql',
53
+ 'multipart/form-data',
54
+ 'text/plain',
55
+ 'text/html',
56
+ 'text/csv',
57
+ 'text/xml',
58
+ 'image/png',
59
+ 'image/jpeg',
60
+ 'image/gif',
61
+ 'image/webp',
62
+ 'image/svg+xml',
63
+ 'audio/mpeg',
64
+ 'video/mp4',
65
+ ] as const satisfies ReadonlyArray<MediaType>
66
+
67
+ /**
68
+ * Vendor extension keys used by various spec generators to attach human-readable
69
+ * labels to enum values. Checked in priority order: the first key found wins.
70
+ */
71
+ export const ENUM_EXTENSION_KEYS = ['x-enumNames', 'x-enum-varnames'] as const
72
+
73
+ /**
74
+ * Canonical HTTP method names used throughout the Kubb OAS layer.
75
+ * Keys are uppercase (as used in generated code); values are the lowercase
76
+ * strings that the `oas` library uses internally.
77
+ * @deprecated use httpMethods from @kubb/ast
78
+ */
79
+ export const httpMethods = {
80
+ GET: 'get',
81
+ POST: 'post',
82
+ PUT: 'put',
83
+ PATCH: 'patch',
84
+ DELETE: 'delete',
85
+ HEAD: 'head',
86
+ OPTIONS: 'options',
87
+ TRACE: 'trace',
88
+ } as const satisfies Record<Uppercase<OASHttpMethods>, OASHttpMethods>
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { ENUM_EXTENSION_KEYS, FORMAT_MAP, httpMethods, KNOWN_MEDIA_TYPES, STRUCTURAL_KEYS } from './constants.ts'
1
2
  export { KUBB_INLINE_REF_PREFIX, Oas } from './Oas.ts'
2
3
  export { resolveServerUrl } from './resolveServerUrl.ts'
3
4
  export * from './types.ts'