@kubb/adapter-oas 5.0.0-alpha.3 → 5.0.0-alpha.31

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,115 +1,54 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import * as _kubb_core0 from "@kubb/core";
2
+ import * as _$_kubb_core0 from "@kubb/core";
3
3
  import { AdapterFactoryOptions } from "@kubb/core";
4
- import { DiscriminatorObject, OASDocument, 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";
9
-
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
- * Resolve name collisions when schemas from different components share the same name (case-insensitive).
59
- * @default false
60
- */
61
- collisionDetection?: boolean;
62
- };
63
- declare class Oas extends BaseOas {
64
- #private;
65
- document: Document;
66
- constructor(document: Document);
67
- setOptions(options: OasOptions): void;
68
- get options(): OasOptions;
69
- get<T = unknown>($ref: string): T | null;
70
- getKey($ref: string): string | undefined;
71
- set($ref: string, value: unknown): false | undefined;
72
- getDiscriminator(schema: SchemaObject$1 | null): DiscriminatorObject$1 | null;
73
- dereferenceWithRef<T = unknown>(schema?: T): T;
74
- getResponseSchema(operation: Operation$1, statusCode: string | number): SchemaObject$1;
75
- getRequestSchema(operation: Operation$1): SchemaObject$1 | undefined;
76
- getParametersSchema(operation: Operation$1, inKey: 'path' | 'query' | 'header'): SchemaObject$1 | null;
77
- validate(): Promise<oas_normalize_lib_types0.ValidationResult>;
78
- flattenSchema(schema: SchemaObject$1 | null): SchemaObject$1 | null;
79
- /**
80
- * Get schemas from OpenAPI components (schemas, responses, requestBodies).
81
- * Returns schemas in dependency order along with name mapping for collision resolution.
82
- */
83
- getSchemas(options?: {
84
- contentType?: contentType;
85
- includes?: Array<'schemas' | 'responses' | 'requestBodies'>;
86
- collisionDetection?: boolean;
87
- }): {
88
- schemas: Record<string, SchemaObject$1>;
89
- nameMapping: Map<string, string>;
90
- };
91
- }
92
- //#endregion
4
+ import { OASDocument } from "oas/types";
5
+ import { ParserOptions } from "@kubb/ast/types";
93
6
  //#region src/types.d.ts
94
- type OasAdapterOptions = {
7
+ /**
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
+ * ```
16
+ */
17
+ type ContentType = 'application/json' | (string & {});
18
+ /**
19
+ * Normalized OpenAPI document type used throughout the adapter.
20
+ */
21
+ type Document = OASDocument;
22
+ /**
23
+ * User-facing options for `adapterOas(...)`.
24
+ *
25
+ * Extends `ParserOptions` from `@kubb/ast` with adapter-specific controls
26
+ * like spec validation and server URL selection.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * adapterOas({
31
+ * validate: false,
32
+ * dateType: 'date',
33
+ * serverIndex: 0,
34
+ * serverVariables: { env: 'prod' },
35
+ * })
36
+ * ```
37
+ */
38
+ type AdapterOasOptions = {
95
39
  /**
96
40
  * Validate the OpenAPI spec before parsing.
97
41
  * @default true
98
42
  */
99
43
  validate?: boolean;
100
44
  /**
101
- * Override the `Oas` class (e.g. for custom subclass behavior).
102
- */
103
- oasClass?: typeof Oas;
104
- /**
105
- * Restrict which content-type is used when extracting request/response schemas.
106
- * By default, the first valid JSON media type is used.
45
+ * Preferred content-type used when extracting request/response schemas.
46
+ * Defaults to the first valid JSON media type found in the spec.
107
47
  */
108
- contentType?: contentType;
48
+ contentType?: ContentType;
109
49
  /**
110
- * Which server to use from `oas.api.servers` when computing `baseURL`.
111
- * - `0` → first server, `1` → second server, etc.
112
- * - When omitted, `baseURL` in the resulting `RootNode.meta` is `undefined`.
50
+ * Index into `oas.api.servers` for computing `baseURL`.
51
+ * `0` → first server, `1` → second server. Omit to leave `baseURL` undefined.
113
52
  */
114
53
  serverIndex?: number;
115
54
  /**
@@ -117,89 +56,77 @@ type OasAdapterOptions = {
117
56
  * Only used when `serverIndex` is set.
118
57
  *
119
58
  * @example
59
+ * ```ts
120
60
  * // spec server: "https://api.{env}.example.com"
121
61
  * serverVariables: { env: 'prod' }
122
62
  * // → baseURL: "https://api.prod.example.com"
63
+ * ```
123
64
  */
124
65
  serverVariables?: Record<string, string>;
125
66
  /**
126
- * How the discriminator field should be interpreted.
127
- * - `'strict'` — uses `oneOf` schemas as defined.
128
- * - `'inherit'` — replaces `oneOf` with the schema from `discriminator.mapping`.
67
+ * How the discriminator field is interpreted.
68
+ * - `'strict'` — uses `oneOf` schemas as written in the spec.
69
+ * - `'inherit'` — propagates discriminator values into child schemas from `discriminator.mapping`.
129
70
  * @default 'strict'
130
71
  */
131
72
  discriminator?: 'strict' | 'inherit';
132
- /**
133
- * Automatically resolve name collisions across schema components.
134
- * @default false
135
- */
136
- collisionDetection?: boolean;
137
- /**
138
- * How `format: 'date-time'` schemas are represented in the AST.
139
- * - `'string'` maps to a `datetime` string node.
140
- * - `'date'` maps to a JavaScript `Date` node.
141
- * - `false` falls through to a plain `string` node.
142
- * @default 'string'
143
- */
144
- dateType?: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
145
- /**
146
- * Whether `type: 'integer'` / `format: 'int64'` produces `number` or `bigint` nodes.
147
- * @default 'number'
148
- */
149
- integerType?: 'number' | 'bigint';
150
- /**
151
- * AST type used when no schema type can be inferred.
152
- * @default 'any'
153
- */
154
- unknownType?: 'any' | 'unknown' | 'void';
155
- /**
156
- * AST type used for completely empty schemas (`{}`).
157
- * @default `unknownType`
158
- */
159
- emptySchemaType?: 'any' | 'unknown' | 'void';
160
- };
161
- type OasAdapterResolvedOptions = {
73
+ } & Partial<ParserOptions>;
74
+ /**
75
+ * Resolved adapter options available at runtime after defaults have been applied.
76
+ */
77
+ type AdapterOasResolvedOptions = {
162
78
  validate: boolean;
163
- oasClass: OasAdapterOptions['oasClass'];
164
- contentType: OasAdapterOptions['contentType'];
165
- serverIndex: OasAdapterOptions['serverIndex'];
166
- serverVariables: OasAdapterOptions['serverVariables'];
167
- discriminator: NonNullable<OasAdapterOptions['discriminator']>;
168
- collisionDetection: boolean;
169
- dateType: NonNullable<OasAdapterOptions['dateType']>;
170
- integerType: NonNullable<OasAdapterOptions['integerType']>;
171
- unknownType: NonNullable<OasAdapterOptions['unknownType']>;
172
- emptySchemaType: NonNullable<OasAdapterOptions['emptySchemaType']>;
79
+ contentType: AdapterOasOptions['contentType'];
80
+ serverIndex: AdapterOasOptions['serverIndex'];
81
+ serverVariables: AdapterOasOptions['serverVariables'];
82
+ discriminator: NonNullable<AdapterOasOptions['discriminator']>;
83
+ dateType: NonNullable<AdapterOasOptions['dateType']>;
84
+ integerType: NonNullable<AdapterOasOptions['integerType']>;
85
+ unknownType: NonNullable<AdapterOasOptions['unknownType']>;
86
+ emptySchemaType: NonNullable<AdapterOasOptions['emptySchemaType']>;
87
+ enumSuffix: AdapterOasOptions['enumSuffix'];
173
88
  /**
174
89
  * 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'`
90
+ * Populated after each `parse()` call.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * nameMapping.get('#/components/schemas/Order') // 'Order'
95
+ * nameMapping.get('#/components/responses/Order') // 'OrderResponse'
96
+ * ```
177
97
  */
178
98
  nameMapping: Map<string, string>;
179
99
  };
180
- type OasAdapter = AdapterFactoryOptions<'oas', OasAdapterOptions, OasAdapterResolvedOptions>;
100
+ /**
101
+ * `@kubb/core` adapter factory type for the OpenAPI adapter.
102
+ */
103
+ type AdapterOas = AdapterFactoryOptions<'oas', AdapterOasOptions, AdapterOasResolvedOptions, Document>;
181
104
  //#endregion
182
105
  //#region src/adapter.d.ts
106
+ /**
107
+ * Stable string identifier for the OAS adapter used in Kubb's adapter registry.
108
+ */
183
109
  declare const adapterOasName = "oas";
184
110
  /**
185
- * Creates an OpenAPI / Swagger adapter for Kubb.
111
+ * Creates the default OpenAPI / Swagger adapter for Kubb.
186
112
  *
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.
113
+ * Parses the spec, optionally validates it, resolves the base URL, and converts
114
+ * everything into a `RootNode` that downstream plugins consume.
189
115
  *
190
116
  * @example
191
117
  * ```ts
192
118
  * import { defineConfig } from '@kubb/core'
193
119
  * import { adapterOas } from '@kubb/adapter-oas'
120
+ * import { pluginTs } from '@kubb/plugin-ts'
194
121
  *
195
122
  * export default defineConfig({
196
- * adapter: adapterOas({ validate: true, dateType: 'date' }),
197
- * input: { path: './openapi.yaml' },
198
- * plugins: [pluginTs(), pluginZod()],
123
+ * adapter: adapterOas({ dateType: 'date', serverIndex: 0 }),
124
+ * input: { path: './openapi.yaml' },
125
+ * plugins: [pluginTs()],
199
126
  * })
200
127
  * ```
201
128
  */
202
- declare const adapterOas: (options?: OasAdapterOptions | undefined) => _kubb_core0.Adapter<OasAdapter>;
129
+ declare const adapterOas: (options?: AdapterOasOptions | undefined) => _$_kubb_core0.Adapter<AdapterOas>;
203
130
  //#endregion
204
- export { adapterOas, adapterOasName };
131
+ export { type AdapterOas, adapterOas, adapterOasName };
205
132
  //# sourceMappingURL=index.d.ts.map