@kubb/adapter-oas 5.0.0-alpha.42 → 5.0.0-alpha.43

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-alpha.42",
3
+ "version": "5.0.0-alpha.43",
4
4
  "description": "OpenAPI / Swagger adapter for Kubb converts OAS input into a @kubb/ast RootNode.",
5
5
  "keywords": [
6
6
  "openapi",
@@ -37,18 +37,14 @@
37
37
  ],
38
38
  "dependencies": {
39
39
  "@redocly/openapi-core": "^2.28.1",
40
- "@stoplight/yaml": "^4.3.0",
41
- "fflate": "^0.8.2",
42
- "jsonpointer": "^5.0.1",
43
40
  "oas": "^31.1.2",
44
41
  "oas-normalize": "^16.0.4",
45
- "openapi-types": "^12.1.3",
46
- "remeda": "^2.33.7",
47
42
  "swagger2openapi": "^7.0.8",
48
- "@kubb/core": "5.0.0-alpha.42"
43
+ "@kubb/core": "5.0.0-alpha.43"
49
44
  },
50
45
  "devDependencies": {
51
46
  "@types/swagger2openapi": "^7.0.4",
47
+ "openapi-types": "^12.1.3",
52
48
  "@internals/utils": "0.0.0"
53
49
  },
54
50
  "engines": {
@@ -60,6 +56,9 @@
60
56
  },
61
57
  "main": "./dist/index.cjs",
62
58
  "module": "./dist/index.js",
59
+ "inlinedDependencies": {
60
+ "openapi-types": "12.1.3"
61
+ },
63
62
  "scripts": {
64
63
  "build": "tsdown",
65
64
  "clean": "npx rimraf ./dist",
package/src/factory.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import path from 'node:path'
2
- import { URLPath } from '@internals/utils'
2
+ import { mergeDeep, URLPath } from '@internals/utils'
3
3
  import type { AdapterSource } from '@kubb/core'
4
4
  import { bundle, loadConfig } from '@redocly/openapi-core'
5
- import yaml from '@stoplight/yaml'
6
5
  import OASNormalize from 'oas-normalize'
7
- import { mergeDeep } from 'remeda'
8
6
  import swagger2openapi from 'swagger2openapi'
9
7
  import { MERGE_DEFAULT_TITLE, MERGE_DEFAULT_VERSION, MERGE_OPENAPI_VERSION } from './constants.ts'
10
8
  import { isOpenApiV2Document } from './guards.ts'
@@ -60,7 +58,7 @@ export async function parseDocument(pathOrApi: string | Document, { canBundle =
60
58
  /**
61
59
  * Deep-merges multiple OpenAPI documents into a single `Document`.
62
60
  *
63
- * Each document is parsed independently then recursively merged with `remeda`'s `mergeDeep`.
61
+ * Each document is parsed independently then recursively merged via `mergeDeep` from `@internals/utils`.
64
62
  * Throws when the input array is empty.
65
63
  *
66
64
  * @example
@@ -85,9 +83,12 @@ export async function mergeDocuments(pathOrApi: Array<string | Document>): Promi
85
83
  components: { schemas: {} },
86
84
  } as Document
87
85
 
88
- const merged = documents.reduce((acc, current) => mergeDeep(acc, current as Document), seed)
86
+ const merged = documents.reduce(
87
+ (acc, current) => mergeDeep(acc as Record<string, unknown>, current as Record<string, unknown>),
88
+ seed as Record<string, unknown>,
89
+ )
89
90
 
90
- return parseDocument(merged)
91
+ return parseDocument(merged as Document)
91
92
  }
92
93
 
93
94
  /**
@@ -110,12 +111,7 @@ export function parseFromConfig(source: AdapterSource): Promise<Document> {
110
111
  return parseDocument(structuredClone(source.data) as Document)
111
112
  }
112
113
 
113
- try {
114
- const api: string = yaml.parse(source.data as string)
115
- return parseDocument(api)
116
- } catch {
117
- return parseDocument(source.data as string)
118
- }
114
+ return parseDocument(source.data as string, { canBundle: false })
119
115
  }
120
116
 
121
117
  if (source.type === 'paths') {
package/src/guards.ts CHANGED
@@ -1,5 +1,5 @@
1
+ import { isPlainObject } from '@internals/utils'
1
2
  import type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'
2
- import { isPlainObject } from 'remeda'
3
3
  import type { DiscriminatorObject, SchemaObject } from './types.ts'
4
4
 
5
5
  /**
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { adapterOas, adapterOasName } from './adapter.ts'
2
+ export type { ParseOptions, ValidateDocumentOptions } from './factory.ts'
2
3
  export { mergeDocuments, parseDocument, parseFromConfig, validateDocument } from './factory.ts'
3
- export { HttpMethods } from './types.ts'
4
4
  export type {
5
5
  AdapterOas,
6
6
  AdapterOasOptions,
@@ -15,4 +15,4 @@ export type {
15
15
  ResponseObject,
16
16
  SchemaObject,
17
17
  } from './types.ts'
18
- export type { ParseOptions, ValidateDocumentOptions } from './factory.ts'
18
+ export { HttpMethods } from './types.ts'
package/src/parser.ts CHANGED
@@ -404,18 +404,24 @@ function createSchemaParser(ctx: OasParserContext) {
404
404
  | 'number'
405
405
  | 'boolean'
406
406
  | 'string'
407
- const sourceValues = extensionKey
408
- ? [...new Set((schema as Record<string, unknown>)[extensionKey] as Array<string | number>)]
409
- : [...new Set(filteredValues)]
407
+ const rawEnumNames = extensionKey ? ((schema as Record<string, unknown>)[extensionKey] as Array<string | number>) : undefined
408
+ const uniqueValues = [...new Set(filteredValues)]
409
+ const seenNames = new Set<string>()
410
410
 
411
411
  return ast.createSchema({
412
412
  ...enumBase,
413
413
  primitive: enumPrimitiveType,
414
- namedEnumValues: sourceValues.map((label, index) => ({
415
- name: String(label),
416
- value: extensionKey ? (filteredValues[index] ?? label) : label,
417
- primitive: enumPrimitiveType,
418
- })),
414
+ namedEnumValues: uniqueValues
415
+ .map((value, index) => ({
416
+ name: String(rawEnumNames?.[index] ?? value),
417
+ value,
418
+ primitive: enumPrimitiveType,
419
+ }))
420
+ .filter((entry) => {
421
+ if (seenNames.has(entry.name)) return false
422
+ seenNames.add(entry.name)
423
+ return true
424
+ }),
419
425
  })
420
426
  }
421
427
 
package/src/refs.ts CHANGED
@@ -1,4 +1,3 @@
1
- import jsonpointer from 'jsonpointer'
2
1
  import { isReference } from './guards.ts'
3
2
  import type { Document } from './types.ts'
4
3
 
@@ -24,7 +23,10 @@ export function resolveRef<T = unknown>(document: Document, $ref: string): T | n
24
23
  } else {
25
24
  return null
26
25
  }
27
- const current = jsonpointer.get(document, $ref)
26
+ const current = $ref
27
+ .split('/')
28
+ .filter(Boolean)
29
+ .reduce((obj: unknown, key: string) => (obj as Record<string, unknown>)?.[key], document as unknown)
28
30
 
29
31
  if (!current) {
30
32
  throw new Error(`Could not find a definition for ${origRef}.`)