@kubb/adapter-oas 5.0.0-alpha.30 → 5.0.0-alpha.32

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,5 +1,5 @@
1
- import { collectImports, createRoot } from '@kubb/ast'
2
- import type { RootNode } from '@kubb/ast/types'
1
+ import { collectImports, createImport, createInput } from '@kubb/ast'
2
+ import type { InputNode } from '@kubb/ast/types'
3
3
  import { createAdapter } from '@kubb/core'
4
4
  import { DEFAULT_PARSER_OPTIONS } from './constants.ts'
5
5
  import { applyDiscriminatorInheritance } from './discriminator.ts'
@@ -17,7 +17,7 @@ export const adapterOasName = 'oas' satisfies AdapterOas['name']
17
17
  * Creates the default OpenAPI / Swagger adapter for Kubb.
18
18
  *
19
19
  * Parses the spec, optionally validates it, resolves the base URL, and converts
20
- * everything into a `RootNode` that downstream plugins consume.
20
+ * everything into an `InputNode` that downstream plugins consume.
21
21
  *
22
22
  * @example
23
23
  * ```ts
@@ -49,7 +49,7 @@ export const adapterOas = createAdapter<AdapterOas>((options) => {
49
49
  // Let-binding so parse() can replace it with a simple reassignment (no clear+loop).
50
50
  let nameMapping = new Map<string, string>()
51
51
  let parsedDocument: Document | null
52
- let rootNode: RootNode | null
52
+ let inputNode: InputNode | null
53
53
 
54
54
  return {
55
55
  name: adapterOasName,
@@ -71,8 +71,8 @@ export const adapterOas = createAdapter<AdapterOas>((options) => {
71
71
  get document() {
72
72
  return parsedDocument
73
73
  },
74
- get rootNode() {
75
- return rootNode
74
+ get inputNode() {
75
+ return inputNode
76
76
  },
77
77
  getImports(node, resolve) {
78
78
  return collectImports({
@@ -82,7 +82,7 @@ export const adapterOas = createAdapter<AdapterOas>((options) => {
82
82
  const result = resolve(schemaName)
83
83
  if (!result) return
84
84
 
85
- return { name: [result.name], path: result.path }
85
+ return createImport({ name: [result.name], path: result.path })
86
86
  },
87
87
  })
88
88
  },
@@ -112,7 +112,7 @@ export const adapterOas = createAdapter<AdapterOas>((options) => {
112
112
  // Expose the raw document so consumers (e.g. plugin-redoc) can access it.
113
113
  parsedDocument = document
114
114
 
115
- rootNode = createRoot({
115
+ inputNode = createInput({
116
116
  ...node,
117
117
  meta: {
118
118
  title: document.info?.title,
@@ -122,7 +122,7 @@ export const adapterOas = createAdapter<AdapterOas>((options) => {
122
122
  },
123
123
  })
124
124
 
125
- return rootNode
125
+ return inputNode
126
126
  },
127
127
  }
128
128
  })
@@ -1,16 +1,16 @@
1
1
  import { createProperty, createSchema, narrowSchema, transform } from '@kubb/ast'
2
- import type { RootNode } from '@kubb/ast/types'
2
+ import type { InputNode } from '@kubb/ast/types'
3
3
 
4
4
  type DiscriminatorTarget = { propertyName: string; enumValues: Array<string | number | boolean> }
5
5
 
6
6
  /**
7
7
  * Injects discriminator enum values into child schemas so they know which value identifies them.
8
8
  *
9
- * Finds every union schema in `root.schemas` that has a `discriminatorPropertyName`, collects the
9
+ * Finds every union schema in `input.schemas` that has a `discriminatorPropertyName`, collects the
10
10
  * enum value each union member is mapped to, then adds (or replaces) that property on the matching
11
11
  * child object schema.
12
12
  *
13
- * Returns a new `RootNode` — the original is never mutated.
13
+ * Returns a new `InputNode` — the original is never mutated.
14
14
  *
15
15
  * @example
16
16
  * ```ts
@@ -18,7 +18,7 @@ type DiscriminatorTarget = { propertyName: string; enumValues: Array<string | nu
18
18
  * const next = applyDiscriminatorInheritance(root)
19
19
  * ```
20
20
  */
21
- export function applyDiscriminatorInheritance(root: RootNode): RootNode {
21
+ export function applyDiscriminatorInheritance(root: InputNode): InputNode {
22
22
  const childMap = new Map<string, DiscriminatorTarget>()
23
23
 
24
24
  for (const schema of root.schemas) {
@@ -78,7 +78,7 @@ export function applyDiscriminatorInheritance(root: RootNode): RootNode {
78
78
 
79
79
  return transform(root, {
80
80
  schema(node, { parent }) {
81
- if (parent?.kind !== 'Root' || !node.name) return
81
+ if (parent?.kind !== 'Input' || !node.name) return
82
82
 
83
83
  const entry = childMap.get(node.name)
84
84
  if (!entry) return
package/src/parser.ts CHANGED
@@ -2,11 +2,11 @@ import { URLPath } from '@internals/utils'
2
2
  import {
3
3
  childName,
4
4
  createDiscriminantNode,
5
+ createInput,
5
6
  createOperation,
6
7
  createParameter,
7
8
  createProperty,
8
9
  createResponse,
9
- createRoot,
10
10
  createSchema,
11
11
  enumPropName,
12
12
  extractRefName,
@@ -22,13 +22,13 @@ import {
22
22
  import type {
23
23
  DistributiveOmit,
24
24
  HttpMethod,
25
+ InputNode,
25
26
  OperationNode,
26
27
  ParameterLocation,
27
28
  ParameterNode,
28
29
  PrimitiveSchemaType,
29
30
  PropertyNode,
30
31
  ResponseNode,
31
- RootNode,
32
32
  ScalarSchemaType,
33
33
  SchemaNode,
34
34
  StatusCode,
@@ -832,7 +832,7 @@ export function parseSchema(ctx: OasParserContext, { schema, name }: { schema: S
832
832
  }
833
833
 
834
834
  /**
835
- * Converts the entire OpenAPI spec into a `RootNode` (the top-level `@kubb/ast` tree).
835
+ * Converts the entire OpenAPI spec into an `InputNode` (the top-level `@kubb/ast` tree).
836
836
  *
837
837
  * This is the main entry point: `OpenAPI / Swagger → Kubb AST`.
838
838
  * No code is generated here — the resulting tree is spec-agnostic and consumed by
@@ -847,7 +847,7 @@ export function parseSchema(ctx: OasParserContext, { schema, name }: { schema: S
847
847
  export function parseOas(
848
848
  document: Document,
849
849
  options: Partial<ParserOptions> & { contentType?: ContentType } = {},
850
- ): { root: RootNode; nameMapping: Map<string, string> } {
850
+ ): { root: InputNode; nameMapping: Map<string, string> } {
851
851
  const { contentType, ...parserOptions } = options
852
852
  const mergedOptions: ParserOptions = { ...DEFAULT_PARSER_OPTIONS, ...parserOptions }
853
853
 
@@ -865,7 +865,7 @@ export function parseOas(
865
865
  .filter((op): op is OperationNode => op !== null),
866
866
  )
867
867
 
868
- const root = createRoot({ schemas, operations })
868
+ const root = createInput({ schemas, operations })
869
869
 
870
870
  return { root, nameMapping }
871
871
  }