@kubb/adapter-oas 5.0.0-alpha.17 → 5.0.0-alpha.19

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