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

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