@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.cjs +989 -1070
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +83 -128
- package/dist/index.js +988 -1069
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/adapter.ts +79 -63
- package/src/constants.ts +63 -63
- package/src/discriminator.ts +99 -0
- package/src/factory.ts +151 -0
- package/src/guards.ts +68 -0
- package/src/index.ts +1 -0
- package/src/parser.ts +352 -667
- package/src/refs.ts +57 -0
- package/src/resolvers.ts +490 -0
- package/src/types.ts +178 -56
- package/src/oas/Oas.ts +0 -616
- package/src/oas/resolveServerUrl.ts +0 -47
- package/src/oas/types.ts +0 -52
- package/src/oas/utils.ts +0 -402
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 {
|
|
5
|
-
import
|
|
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/
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
90
|
-
*
|
|
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
|
|
106
|
-
* - `'strict'` — uses `oneOf` schemas as
|
|
107
|
-
* - `'inherit'` —
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
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
|
|
112
|
+
* Creates the default OpenAPI / Swagger adapter for Kubb.
|
|
159
113
|
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
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({
|
|
170
|
-
* input:
|
|
171
|
-
* plugins: [pluginTs()
|
|
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?:
|
|
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
|