@kubb/oas 4.33.5 → 4.35.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.5",
3
+ "version": "4.35.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.5"
64
+ "@kubb/ast": "4.35.0",
65
+ "@kubb/core": "4.35.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",
@@ -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,7 +1,9 @@
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'
4
5
  export {
6
+ flattenSchema,
5
7
  getDefaultValue,
6
8
  isAllOptional,
7
9
  isDiscriminator,
package/src/types.ts CHANGED
@@ -20,30 +20,24 @@ export type contentType = 'application/json' | (string & {})
20
20
 
21
21
  export type SchemaObject = OASSchemaObject & {
22
22
  /**
23
- * Oas 3.1 adds support for `x-nullable` to specify that a schema can be null, even if `type` does not include `null`.
23
+ * OAS 3.1 extension: allows marking a schema as nullable even when `type` does not include `'null'`.
24
24
  */
25
25
  'x-nullable'?: boolean
26
26
  /**
27
- * Oas 3.1 adds support for `const` to specify that a schema can only have a single value, which must be equal to the value of `const`.
27
+ * OAS 3.1: constrains the schema to a single fixed value.
28
+ * Semantically equivalent to a one-item `enum`.
28
29
  */
29
30
  const?: string | number | boolean | null
30
31
  /**
31
- * Oas 3.1 adds support for `contentMediaType` to specify the media type of the content being described by the schema.
32
+ * OAS 3.1: specifies the media type of the schema content.
33
+ * When set to `'application/octet-stream'` on a `string` schema, the schema is treated as binary (`blob`).
32
34
  */
33
35
  contentMediaType?: string
34
36
  $ref?: string
35
37
  }
36
38
 
37
- export const HttpMethods = {
38
- GET: 'get',
39
- POST: 'post',
40
- PUT: 'put',
41
- PATCH: 'patch',
42
- DELETE: 'delete',
43
- HEAD: 'head',
44
- OPTIONS: 'options',
45
- TRACE: 'trace',
46
- } satisfies Record<Uppercase<OASHttpMethods>, OASHttpMethods>
39
+ /** Re-exported from `constants.ts` for backwards compatibility. */
40
+ export { httpMethods as HttpMethods } from './constants.ts'
47
41
 
48
42
  export type HttpMethod = OASHttpMethods
49
43
 
package/src/utils.ts CHANGED
@@ -9,28 +9,43 @@ import OASNormalize from 'oas-normalize'
9
9
  import type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'
10
10
  import { isPlainObject, mergeDeep } from 'remeda'
11
11
  import swagger2openapi from 'swagger2openapi'
12
+ import { STRUCTURAL_KEYS } from './constants.ts'
12
13
  import { Oas } from './Oas.ts'
13
14
  import type { contentType, Document, SchemaObject } from './types.ts'
14
15
 
15
- export const STRUCTURAL_KEYS = new Set(['properties', 'items', 'additionalProperties', 'oneOf', 'anyOf', 'allOf', 'not'])
16
-
17
- export function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {
18
- return doc && isPlainObject(doc) && !('openapi' in doc)
16
+ /**
17
+ * Returns `true` when `doc` looks like a Swagger 2.0 document (no `openapi` key).
18
+ */
19
+ export function isOpenApiV2Document(doc: unknown): doc is OpenAPIV2.Document {
20
+ return !!doc && isPlainObject(doc) && !('openapi' in doc)
19
21
  }
20
- export function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {
21
- return doc && isPlainObject(doc) && 'openapi' in doc
22
+
23
+ /**
24
+ * Returns `true` when `doc` looks like an OpenAPI 3.x document (has `openapi` key).
25
+ */
26
+ export function isOpenApiV3Document(doc: unknown): doc is OpenAPIV3.Document {
27
+ return !!doc && isPlainObject(doc) && 'openapi' in doc
22
28
  }
23
29
 
24
- export function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {
25
- return doc && isPlainObject<OpenAPIV3_1.Document>(doc) && 'openapi' in doc && doc.openapi.startsWith('3.1')
30
+ /**
31
+ * Returns `true` when `doc` is an OpenAPI 3.1 document.
32
+ */
33
+ export function isOpenApiV3_1Document(doc: unknown): doc is OpenAPIV3_1.Document {
34
+ return !!doc && isPlainObject(doc) && 'openapi' in (doc as object) && (doc as { openapi: string }).openapi.startsWith('3.1')
26
35
  }
27
36
 
37
+ /**
38
+ * Returns `true` when `obj` is a JSON Schema object recognized by the `oas` library.
39
+ */
28
40
  export function isJSONSchema(obj?: unknown): obj is SchemaObject {
29
41
  return !!obj && isSchema(obj)
30
42
  }
31
43
 
44
+ /**
45
+ * Returns `true` when `obj` is a parameter object (has an `in` field distinguishing it from a schema).
46
+ */
32
47
  export function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject {
33
- return obj && 'in' in obj
48
+ return !!obj && 'in' in obj
34
49
  }
35
50
 
36
51
  /**
@@ -56,17 +71,19 @@ export function isNullable(schema?: SchemaObject & { 'x-nullable'?: boolean }):
56
71
  }
57
72
 
58
73
  /**
59
- * Determines if the given object is an OpenAPI ReferenceObject.
74
+ * Returns `true` when `obj` is an OpenAPI `$ref` pointer object.
60
75
  */
61
- export function isReference(obj?: any): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {
62
- return !!obj && isRef(obj)
76
+ export function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {
77
+ return !!obj && isRef(obj as object)
63
78
  }
64
79
 
65
80
  /**
66
- * Determines if the given object is a SchemaObject with a discriminator property of type DiscriminatorObject.
81
+ * Returns `true` when `obj` is a schema that carries a structured `discriminator` object
82
+ * (as opposed to a plain string discriminator used in some older specs).
67
83
  */
68
- export function isDiscriminator(obj?: any): obj is SchemaObject & { discriminator: OpenAPIV3.DiscriminatorObject } {
69
- return !!obj && obj?.['discriminator'] && typeof obj.discriminator !== 'string'
84
+ export function isDiscriminator(obj?: unknown): obj is SchemaObject & { discriminator: OpenAPIV3.DiscriminatorObject } {
85
+ const record = obj as Record<string, unknown>
86
+ return !!obj && !!record['discriminator'] && typeof record['discriminator'] !== 'string'
70
87
  }
71
88
 
72
89
  /**
@@ -1,41 +0,0 @@
1
- import { createRequire } from "node:module";
2
- //#region \0rolldown/runtime.js
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __name = (target, value) => __defProp(target, "name", {
6
- value,
7
- configurable: true
8
- });
9
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
- var __getOwnPropNames = Object.getOwnPropertyNames;
11
- var __getProtoOf = Object.getPrototypeOf;
12
- var __hasOwnProp = Object.prototype.hasOwnProperty;
13
- var __esmMin = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
14
- var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
15
- var __exportAll = (all, no_symbols) => {
16
- let target = {};
17
- for (var name in all) __defProp(target, name, {
18
- get: all[name],
19
- enumerable: true
20
- });
21
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
22
- return target;
23
- };
24
- var __copyProps = (to, from, except, desc) => {
25
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
26
- key = keys[i];
27
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
28
- get: ((k) => from[k]).bind(null, key),
29
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
30
- });
31
- }
32
- return to;
33
- };
34
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
35
- value: mod,
36
- enumerable: true
37
- }) : target, mod));
38
- var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["module.exports"] : __copyProps(__defProp({}, "__esModule", { value: true }), mod);
39
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
40
- //#endregion
41
- export { __require as a, __name as i, __esmMin as n, __toCommonJS as o, __exportAll as r, __toESM as s, __commonJSMin as t };