@kubb/adapter-oas 5.0.0-alpha.16 → 5.0.0-alpha.18

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/dist/index.d.ts CHANGED
@@ -1,143 +1,50 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
2
  import * as _kubb_core0 from "@kubb/core";
3
3
  import { AdapterFactoryOptions } from "@kubb/core";
4
- import { DiscriminatorObject, OASDocument, ParameterObject, SchemaObject } from "oas/types";
5
- import BaseOas from "oas";
6
- import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
7
- import { Operation } from "oas/operation";
8
- import { OpenAPIV3 } from "openapi-types";
4
+ import { ParserOptions } from "@kubb/ast/types";
9
5
 
10
- //#region src/oas/types.d.ts
11
- type contentType = 'application/json' | (string & {});
12
- type SchemaObject$1 = SchemaObject & {
13
- /**
14
- * OAS 3.1 extension: allows marking a schema as nullable even when `type` does not include `'null'`.
15
- */
16
- 'x-nullable'?: boolean;
17
- /**
18
- * OAS 3.1: constrains the schema to a single fixed value.
19
- * Semantically equivalent to a one-item `enum`.
20
- */
21
- const?: string | number | boolean | null;
22
- /**
23
- * OAS 3.1: specifies the media type of the schema content.
24
- * When set to `'application/octet-stream'` on a `string` schema, the schema is treated as binary (`blob`).
25
- */
26
- contentMediaType?: string;
27
- $ref?: string;
28
- /**
29
- * OAS 3.1 / JSON Schema: positional items in a tuple schema.
30
- * Replaces the OAS 3.0 multi-item `items` array syntax.
31
- */
32
- prefixItems?: Array<SchemaObject$1 | ReferenceObject>;
33
- /**
34
- * JSON Schema: maps regex patterns to sub-schemas for additional property validation.
35
- */
36
- patternProperties?: Record<string, SchemaObject$1 | boolean>;
37
- /**
38
- * OAS 3.0 / JSON Schema: single-schema form.
39
- * The OAS base type already includes this, but we re-declare it here to ensure
40
- * the single-schema overload takes precedence over the multi-schema tuple form.
41
- */
42
- items?: SchemaObject$1 | ReferenceObject;
43
- /**
44
- * Enum values for this schema (narrowed from `unknown[]` in the base type).
45
- */
46
- enum?: Array<string | number | boolean | null>;
47
- };
48
- type Document = OASDocument;
49
- type Operation$1 = Operation;
50
- type DiscriminatorObject$1 = DiscriminatorObject;
51
- type ReferenceObject = OpenAPIV3.ReferenceObject;
52
- //#endregion
53
- //#region src/oas/Oas.d.ts
54
- type OasOptions = {
55
- contentType?: contentType;
56
- discriminator?: 'strict' | 'inherit';
57
- };
58
- declare class Oas extends BaseOas {
59
- #private;
60
- document: Document;
61
- constructor(document: Document);
62
- setOptions(options: OasOptions): void;
63
- get options(): OasOptions;
64
- get<T = unknown>($ref: string): T | null;
65
- getKey($ref: string): string | undefined;
66
- set($ref: string, value: unknown): false | undefined;
67
- getDiscriminator(schema: SchemaObject$1 | null): DiscriminatorObject$1 | null;
68
- dereferenceWithRef<T = unknown>(schema?: T): T;
69
- getResponseSchema(operation: Operation$1, statusCode: string | number): SchemaObject$1;
70
- getRequestSchema(operation: Operation$1): SchemaObject$1 | undefined;
71
- /**
72
- * Returns all resolved parameters for an operation, merging path-level and operation-level
73
- * parameters and deduplicating by `in:name` (operation-level takes precedence).
74
- *
75
- * oas v31+ filters out `$ref` parameters in `getParameters()`, so this method accesses the
76
- * raw `operation.schema.parameters` and path-item parameters directly and resolves `$ref`
77
- * pointers via `dereferenceWithRef` to preserve backward compatibility.
78
- */
79
- getParameters(operation: Operation$1): Array<ParameterObject>;
80
- getParametersSchema(operation: Operation$1, inKey: 'path' | 'query' | 'header'): SchemaObject$1 | null;
81
- validate(): Promise<oas_normalize_lib_types0.ValidationResult>;
82
- flattenSchema(schema: SchemaObject$1 | null): SchemaObject$1 | null;
83
- /**
84
- * Get schemas from OpenAPI components (schemas, responses, requestBodies).
85
- * Returns schemas in dependency order along with name mapping for collision resolution.
86
- */
87
- getSchemas(options?: {
88
- contentType?: contentType;
89
- includes?: Array<'schemas' | 'responses' | 'requestBodies'>;
90
- }): {
91
- schemas: Record<string, SchemaObject$1>;
92
- nameMapping: Map<string, string>;
93
- };
94
- }
95
- //#endregion
96
6
  //#region src/types.d.ts
97
7
  /**
98
- * Controls how various OAS constructs are mapped to Kubb AST nodes.
8
+ * Content-type string used when selecting request/response schemas from a spec.
9
+ *
10
+ * Accepts `'application/json'` or any arbitrary media type string.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const ct: contentType = 'application/vnd.api+json'
15
+ * ```
99
16
  */
100
- type ParserOptions = {
101
- /**
102
- * How `format: 'date-time'` schemas are represented. `false` falls through to a plain string.
103
- */
104
- dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
105
- /**
106
- * Whether `type: 'integer'` and `format: 'int64'` produce `number` or `bigint` nodes.
107
- */
108
- integerType?: 'number' | 'bigint';
109
- /**
110
- * AST type used when no schema type can be inferred.
111
- */
112
- unknownType: 'any' | 'unknown' | 'void';
113
- /**
114
- * AST type used for completely empty schemas (`{}`).
115
- */
116
- emptySchemaType: 'any' | 'unknown' | 'void';
117
- /**
118
- * Suffix appended to derived enum names when building property schema names.
119
- */
120
- enumSuffix: 'enum' | (string & {});
121
- };
122
- type OasAdapterOptions = {
17
+ type contentType = 'application/json' | (string & {});
18
+ /**
19
+ * User-facing options for `adapterOas(...)`.
20
+ *
21
+ * Extends `ParserOptions` from `@kubb/ast` with adapter-specific controls
22
+ * like spec validation and server URL selection.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * adapterOas({
27
+ * validate: false,
28
+ * dateType: 'date',
29
+ * serverIndex: 0,
30
+ * serverVariables: { env: 'prod' },
31
+ * })
32
+ * ```
33
+ */
34
+ type AdapterOasOptions = {
123
35
  /**
124
36
  * Validate the OpenAPI spec before parsing.
125
37
  * @default true
126
38
  */
127
39
  validate?: boolean;
128
40
  /**
129
- * Override the `Oas` class (e.g. for custom subclass behavior).
130
- */
131
- oasClass?: typeof Oas;
132
- /**
133
- * Restrict which content-type is used when extracting request/response schemas.
134
- * By default, the first valid JSON media type is used.
41
+ * Preferred content-type used when extracting request/response schemas.
42
+ * Defaults to the first valid JSON media type found in the spec.
135
43
  */
136
44
  contentType?: contentType;
137
45
  /**
138
- * Which server to use from `oas.api.servers` when computing `baseURL`.
139
- * - `0` → first server, `1` → second server, etc.
140
- * - When omitted, `baseURL` in the resulting `RootNode.meta` is `undefined`.
46
+ * Index into `oas.api.servers` for computing `baseURL`.
47
+ * `0` → first server, `1` → second server. Omit to leave `baseURL` undefined.
141
48
  */
142
49
  serverIndex?: number;
143
50
  /**
@@ -145,61 +52,77 @@ type OasAdapterOptions = {
145
52
  * Only used when `serverIndex` is set.
146
53
  *
147
54
  * @example
55
+ * ```ts
148
56
  * // spec server: "https://api.{env}.example.com"
149
57
  * serverVariables: { env: 'prod' }
150
58
  * // → baseURL: "https://api.prod.example.com"
59
+ * ```
151
60
  */
152
61
  serverVariables?: Record<string, string>;
153
62
  /**
154
- * How the discriminator field should be interpreted.
155
- * - `'strict'` — uses `oneOf` schemas as defined.
156
- * - `'inherit'` — replaces `oneOf` with the schema from `discriminator.mapping`.
63
+ * How the discriminator field is interpreted.
64
+ * - `'strict'` — uses `oneOf` schemas as written in the spec.
65
+ * - `'inherit'` — propagates discriminator values into child schemas from `discriminator.mapping`.
157
66
  * @default 'strict'
158
67
  */
159
68
  discriminator?: 'strict' | 'inherit';
160
69
  } & Partial<ParserOptions>;
161
- type OasAdapterResolvedOptions = {
70
+ /**
71
+ * Resolved adapter options available at runtime after defaults have been applied.
72
+ */
73
+ type AdapterOasResolvedOptions = {
162
74
  validate: boolean;
163
- oasClass: OasAdapterOptions['oasClass'];
164
- contentType: OasAdapterOptions['contentType'];
165
- serverIndex: OasAdapterOptions['serverIndex'];
166
- serverVariables: OasAdapterOptions['serverVariables'];
167
- discriminator: NonNullable<OasAdapterOptions['discriminator']>;
168
- dateType: NonNullable<OasAdapterOptions['dateType']>;
169
- integerType: NonNullable<OasAdapterOptions['integerType']>;
170
- unknownType: NonNullable<OasAdapterOptions['unknownType']>;
171
- emptySchemaType: NonNullable<OasAdapterOptions['emptySchemaType']>;
172
- enumSuffix: OasAdapterOptions['enumSuffix'];
75
+ contentType: AdapterOasOptions['contentType'];
76
+ serverIndex: AdapterOasOptions['serverIndex'];
77
+ serverVariables: AdapterOasOptions['serverVariables'];
78
+ discriminator: NonNullable<AdapterOasOptions['discriminator']>;
79
+ dateType: NonNullable<AdapterOasOptions['dateType']>;
80
+ integerType: NonNullable<AdapterOasOptions['integerType']>;
81
+ unknownType: NonNullable<AdapterOasOptions['unknownType']>;
82
+ emptySchemaType: NonNullable<AdapterOasOptions['emptySchemaType']>;
83
+ enumSuffix: AdapterOasOptions['enumSuffix'];
173
84
  /**
174
85
  * Map from original `$ref` paths to their collision-resolved schema names.
175
- * Populated by the adapter after each `parse()` call.
176
- * e.g. `'#/components/schemas/Order'` → `'OrderSchema'`
86
+ * Populated after each `parse()` call.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * nameMapping.get('#/components/schemas/Order') // 'Order'
91
+ * nameMapping.get('#/components/responses/Order') // 'OrderResponse'
92
+ * ```
177
93
  */
178
94
  nameMapping: Map<string, string>;
179
95
  };
180
- type OasAdapter = AdapterFactoryOptions<'oas', OasAdapterOptions, OasAdapterResolvedOptions>;
96
+ /**
97
+ * `@kubb/core` adapter factory type for the OpenAPI adapter.
98
+ */
99
+ type AdapterOas = AdapterFactoryOptions<'oas', AdapterOasOptions, AdapterOasResolvedOptions>;
181
100
  //#endregion
182
101
  //#region src/adapter.d.ts
102
+ /**
103
+ * Stable string identifier for the OAS adapter used in Kubb's adapter registry.
104
+ */
183
105
  declare const adapterOasName = "oas";
184
106
  /**
185
- * Creates an OpenAPI / Swagger adapter for Kubb.
107
+ * Creates the default OpenAPI / Swagger adapter for Kubb.
186
108
  *
187
- * This is the default adapter you can omit it from your config when using
188
- * an OpenAPI spec, but supplying it explicitly lets you pass options.
109
+ * Parses the spec, optionally validates it, resolves the base URL, and converts
110
+ * everything into a `RootNode` that downstream plugins consume.
189
111
  *
190
112
  * @example
191
113
  * ```ts
192
114
  * import { defineConfig } from '@kubb/core'
193
115
  * import { adapterOas } from '@kubb/adapter-oas'
116
+ * import { pluginTs } from '@kubb/plugin-ts'
194
117
  *
195
118
  * export default defineConfig({
196
- * adapter: adapterOas({ validate: true, dateType: 'date' }),
197
- * input: { path: './openapi.yaml' },
198
- * plugins: [pluginTs(), pluginZod()],
119
+ * adapter: adapterOas({ dateType: 'date', serverIndex: 0 }),
120
+ * input: { path: './openapi.yaml' },
121
+ * plugins: [pluginTs()],
199
122
  * })
200
123
  * ```
201
124
  */
202
- declare const adapterOas: (options?: OasAdapterOptions | undefined) => _kubb_core0.Adapter<OasAdapter>;
125
+ declare const adapterOas: (options?: AdapterOasOptions | undefined) => _kubb_core0.Adapter<AdapterOas>;
203
126
  //#endregion
204
127
  export { adapterOas, adapterOasName };
205
128
  //# sourceMappingURL=index.d.ts.map