@kubb/adapter-oas 5.0.0-alpha.20 → 5.0.0-alpha.21

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/src/adapter.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { collectImports, createRoot } from '@kubb/ast'
2
+ import type { RootNode } from '@kubb/ast/types'
2
3
  import { createAdapter } from '@kubb/core'
3
4
  import { DEFAULT_PARSER_OPTIONS } from './constants.ts'
4
5
  import { applyDiscriminatorInheritance } from './discriminator.ts'
@@ -47,7 +48,8 @@ export const adapterOas = createAdapter<AdapterOas>((options) => {
47
48
 
48
49
  // Let-binding so parse() can replace it with a simple reassignment (no clear+loop).
49
50
  let nameMapping = new Map<string, string>()
50
- let parsedDocument: Document | undefined
51
+ let parsedDocument: Document | null
52
+ let rootNode: RootNode | null
51
53
 
52
54
  return {
53
55
  name: adapterOasName,
@@ -69,6 +71,9 @@ export const adapterOas = createAdapter<AdapterOas>((options) => {
69
71
  get document() {
70
72
  return parsedDocument
71
73
  },
74
+ get rootNode() {
75
+ return rootNode
76
+ },
72
77
  getImports(node, resolve) {
73
78
  return collectImports({
74
79
  node,
@@ -100,15 +105,15 @@ export const adapterOas = createAdapter<AdapterOas>((options) => {
100
105
  enumSuffix,
101
106
  })
102
107
 
103
- const root = discriminator === 'inherit' ? applyDiscriminatorInheritance(parsedRoot) : parsedRoot
108
+ const node = discriminator === 'inherit' ? applyDiscriminatorInheritance(parsedRoot) : parsedRoot
104
109
 
105
110
  // This must happen after parseOas() because legacy enum remapping is finalized there.
106
111
  nameMapping = parsedNameMapping
107
112
  // Expose the raw document so consumers (e.g. plugin-redoc) can access it.
108
113
  parsedDocument = document
109
114
 
110
- return createRoot({
111
- ...root,
115
+ rootNode = createRoot({
116
+ ...node,
112
117
  meta: {
113
118
  title: document.info?.title,
114
119
  description: document.info?.description,
@@ -116,6 +121,8 @@ export const adapterOas = createAdapter<AdapterOas>((options) => {
116
121
  baseURL,
117
122
  },
118
123
  })
124
+
125
+ return rootNode
119
126
  },
120
127
  }
121
128
  })
package/src/parser.ts CHANGED
@@ -48,7 +48,7 @@ import {
48
48
  getSchemas,
49
49
  getSchemaType,
50
50
  } from './resolvers.ts'
51
- import type { contentType, Document, Operation, ReferenceObject, SchemaObject } from './types.ts'
51
+ import type { ContentType, Document, Operation, ReferenceObject, SchemaObject } from './types.ts'
52
52
 
53
53
  /**
54
54
  * Construction-time context for the OAS parser.
@@ -58,7 +58,7 @@ import type { contentType, Document, Operation, ReferenceObject, SchemaObject }
58
58
  */
59
59
  export type OasParserContext = {
60
60
  document: Document
61
- contentType?: contentType
61
+ contentType?: ContentType
62
62
  }
63
63
 
64
64
  /**
@@ -796,7 +796,7 @@ export function parseSchema(ctx: OasParserContext, { schema, name }: { schema: S
796
796
  */
797
797
  export function parseOas(
798
798
  document: Document,
799
- options: Partial<ParserOptions> & { contentType?: contentType } = {},
799
+ options: Partial<ParserOptions> & { contentType?: ContentType } = {},
800
800
  ): { root: RootNode; nameMapping: Map<string, string> } {
801
801
  const { contentType, ...parserOptions } = options
802
802
  const mergedOptions: ParserOptions = { ...DEFAULT_PARSER_OPTIONS, ...parserOptions }
package/src/resolvers.ts CHANGED
@@ -7,7 +7,7 @@ import { matchesMimeType } from 'oas/utils'
7
7
  import { formatMap, structuralKeys } from './constants.ts'
8
8
  import { isReference } from './guards.ts'
9
9
  import { dereferenceWithRef, resolveRef } from './refs.ts'
10
- import type { contentType, Document, MediaTypeObject, Operation, ResponseObject, SchemaObject } from './types.ts'
10
+ import type { ContentType, Document, MediaTypeObject, Operation, ResponseObject, SchemaObject } from './types.ts'
11
11
 
12
12
  /**
13
13
  * Resolves `{variable}` placeholders in an OpenAPI server URL.
@@ -76,7 +76,7 @@ export function getMediaType(contentType: string): MediaType | null {
76
76
  }
77
77
 
78
78
  export type OperationsOptions = {
79
- contentType?: contentType
79
+ contentType?: ContentType
80
80
  }
81
81
 
82
82
  /**
@@ -231,7 +231,7 @@ export type SchemaWithMetadata = {
231
231
  }
232
232
 
233
233
  export type GetSchemasOptions = {
234
- contentType?: contentType
234
+ contentType?: ContentType
235
235
  }
236
236
 
237
237
  export type GetSchemasResult = {
@@ -290,7 +290,7 @@ export function flattenSchema(schema: SchemaObject | null): SchemaObject | null
290
290
  * // SchemaObject | null
291
291
  * ```
292
292
  */
293
- export function extractSchemaFromContent(content: Record<string, unknown> | undefined, preferredContentType?: contentType): SchemaObject | null {
293
+ export function extractSchemaFromContent(content: Record<string, unknown> | undefined, preferredContentType?: ContentType): SchemaObject | null {
294
294
  if (!content) return null
295
295
 
296
296
  const firstContentType = Object.keys(content)[0] ?? 'application/json'
package/src/types.ts CHANGED
@@ -28,7 +28,7 @@ export type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'
28
28
  * const ct: contentType = 'application/vnd.api+json'
29
29
  * ```
30
30
  */
31
- export type contentType = 'application/json' | (string & {})
31
+ export type ContentType = 'application/json' | (string & {})
32
32
 
33
33
  /**
34
34
  * Augments `oas`'s `SchemaObject` with OAS 3.1 / JSON Schema fields the parser needs.
@@ -149,7 +149,7 @@ export type AdapterOasOptions = {
149
149
  * Preferred content-type used when extracting request/response schemas.
150
150
  * Defaults to the first valid JSON media type found in the spec.
151
151
  */
152
- contentType?: contentType
152
+ contentType?: ContentType
153
153
  /**
154
154
  * Index into `oas.api.servers` for computing `baseURL`.
155
155
  * `0` → first server, `1` → second server. Omit to leave `baseURL` undefined.