@kubb/oas 4.12.8 → 4.12.9

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.12.8",
3
+ "version": "4.12.9",
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",
@@ -66,7 +66,7 @@
66
66
  "remeda": "^2.32.0",
67
67
  "swagger2openapi": "^7.0.8",
68
68
  "ts-toolbelt": "^9.6.0",
69
- "@kubb/core": "4.12.8"
69
+ "@kubb/core": "4.12.9"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@stoplight/yaml": "^4.3.0",
package/src/Oas.ts CHANGED
@@ -7,7 +7,7 @@ import OASNormalize from 'oas-normalize'
7
7
  import type { OpenAPIV3 } from 'openapi-types'
8
8
  import type { OasTypes } from './index.ts'
9
9
  import type { contentType } from './types.ts'
10
- import { isDiscriminator, isReference } from './utils.ts'
10
+ import { isDiscriminator, isReference, STRUCTURAL_KEYS } from './utils.ts'
11
11
 
12
12
  type Options = {
13
13
  contentType?: contentType
@@ -445,4 +445,36 @@ export class Oas<const TOAS = unknown> extends BaseOas {
445
445
  },
446
446
  })
447
447
  }
448
+
449
+ flattenSchema(schema?: SchemaObject): SchemaObject | undefined {
450
+ if (!schema?.allOf || schema.allOf.length === 0) {
451
+ return schema
452
+ }
453
+
454
+ // Never touch ref-based or structural composition
455
+ if (schema.allOf.some((item) => isReference(item))) {
456
+ return schema
457
+ }
458
+
459
+ const isPlainFragment = (item: SchemaObject) => !Object.keys(item).some((key) => STRUCTURAL_KEYS.has(key))
460
+
461
+ // Only flatten keyword-only fragments
462
+ if (!schema.allOf.every((item) => isPlainFragment(item as SchemaObject))) {
463
+ return schema
464
+ }
465
+
466
+ const merged: SchemaObject = { ...schema }
467
+ delete merged.allOf
468
+
469
+ for (const fragment of schema.allOf as SchemaObject[]) {
470
+ for (const [key, value] of Object.entries(fragment)) {
471
+ if ((merged as any)[key] === undefined) {
472
+ ;(merged as any)[key] = value
473
+ }
474
+ }
475
+ }
476
+
477
+ // biome-ignore lint/suspicious/noAssignInExpressions: should not trigger this
478
+ return merged
479
+ }
448
480
  }
package/src/utils.ts CHANGED
@@ -11,6 +11,8 @@ import { isPlainObject, mergeDeep } from 'remeda'
11
11
  import swagger2openapi from 'swagger2openapi'
12
12
  import { Oas } from './Oas.ts'
13
13
 
14
+ export const STRUCTURAL_KEYS = new Set(['properties', 'items', 'additionalProperties', 'oneOf', 'anyOf', 'allOf', 'not'])
15
+
14
16
  export function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {
15
17
  return doc && isPlainObject(doc) && !('openapi' in doc)
16
18
  }