@kubb/adapter-oas 5.0.0-beta.75 → 5.0.0-beta.76
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/LICENSE +17 -10
- package/README.md +100 -0
- package/dist/index.cjs +1398 -864
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +845 -126
- package/dist/index.js +1401 -859
- package/dist/index.js.map +1 -1
- package/package.json +14 -10
- package/src/adapter.ts +0 -126
- package/src/constants.ts +0 -122
- package/src/discriminator.ts +0 -108
- package/src/factory.ts +0 -165
- package/src/guards.ts +0 -68
- package/src/index.ts +0 -18
- package/src/parser.ts +0 -1002
- package/src/refs.ts +0 -59
- package/src/resolvers.ts +0 -544
- package/src/types.ts +0 -206
- /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/src/types.ts
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
// external packages
|
|
2
|
-
|
|
3
|
-
import type { AdapterFactoryOptions } from '@kubb/core'
|
|
4
|
-
import { ast } from '@kubb/core'
|
|
5
|
-
import type { Operation as OASOperation } from 'oas/operation'
|
|
6
|
-
import type {
|
|
7
|
-
DiscriminatorObject as OASDiscriminatorObject,
|
|
8
|
-
OASDocument,
|
|
9
|
-
MediaTypeObject as OASMediaTypeObject,
|
|
10
|
-
ResponseObject as OASResponseObject,
|
|
11
|
-
SchemaObject as OASSchemaObject,
|
|
12
|
-
} from 'oas/types'
|
|
13
|
-
import type { OpenAPIV3 } from 'openapi-types'
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Re-exports of `openapi-types` for use by adapter consumers.
|
|
17
|
-
*/
|
|
18
|
-
export type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Content-type string for selecting request/response schemas from an OpenAPI spec.
|
|
22
|
-
* Supports `'application/json'` or any other media type.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* const ct: ContentType = 'application/vnd.api+json'
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export type ContentType = 'application/json' | (string & {})
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Extended OpenAPI 3.0 schema object that includes OpenAPI 3.1 and JSON Schema fields.
|
|
33
|
-
* The parser uses these additional fields to handle newer spec versions.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* const schema: SchemaObject = {
|
|
38
|
-
* type: 'string',
|
|
39
|
-
* const: 'dog',
|
|
40
|
-
* contentMediaType: 'application/octet-stream',
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export type SchemaObject = OASSchemaObject & {
|
|
45
|
-
/**
|
|
46
|
-
* OAS 3.0 vendor extension: marks a schema as nullable without using `type: ['null', ...]`.
|
|
47
|
-
*/
|
|
48
|
-
'x-nullable'?: boolean
|
|
49
|
-
/**
|
|
50
|
-
* OAS 3.1: constrains the schema to a single fixed value (equivalent to a one-item `enum`).
|
|
51
|
-
*/
|
|
52
|
-
const?: string | number | boolean | null
|
|
53
|
-
/**
|
|
54
|
-
* OAS 3.1: media type of the schema content. `'application/octet-stream'` on a `string` schema maps to `blob`.
|
|
55
|
-
*/
|
|
56
|
-
contentMediaType?: string
|
|
57
|
-
$ref?: string
|
|
58
|
-
/**
|
|
59
|
-
* OAS 3.1: positional tuple items, replacing the multi-item `items` array from OAS 3.0.
|
|
60
|
-
*/
|
|
61
|
-
prefixItems?: Array<SchemaObject | ReferenceObject>
|
|
62
|
-
/**
|
|
63
|
-
* JSON Schema: maps regex patterns to sub-schemas for validating additional properties.
|
|
64
|
-
*/
|
|
65
|
-
patternProperties?: Record<string, SchemaObject | boolean>
|
|
66
|
-
/**
|
|
67
|
-
* Single-schema form of `items`. Narrowed from the base type to take precedence over the tuple overload.
|
|
68
|
-
*/
|
|
69
|
-
items?: SchemaObject | ReferenceObject
|
|
70
|
-
/**
|
|
71
|
-
* Enum values for this schema (narrowed from `unknown[]`).
|
|
72
|
-
*/
|
|
73
|
-
enum?: Array<string | number | boolean | null>
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Maps uppercase HTTP method names to lowercase for backwards compatibility.
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```ts
|
|
81
|
-
* HttpMethods['GET'] // 'get'
|
|
82
|
-
* HttpMethods['POST'] // 'post'
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
export const HttpMethods = Object.fromEntries(Object.entries(ast.httpMethods).map(([lower, upper]) => [upper, lower])) as Record<
|
|
86
|
-
Uppercase<ast.HttpMethod>,
|
|
87
|
-
Lowercase<ast.HttpMethod>
|
|
88
|
-
>
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* HTTP method as a lowercase string (`'get' | 'post' | ...`).
|
|
92
|
-
*/
|
|
93
|
-
export type HttpMethod = Lowercase<ast.HttpMethod>
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Normalized OpenAPI document after parsing.
|
|
97
|
-
*/
|
|
98
|
-
export type Document = OASDocument
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* API operation extracted from an OpenAPI document.
|
|
102
|
-
*/
|
|
103
|
-
export type Operation = OASOperation
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Discriminator object for `oneOf`/`anyOf` schemas in OpenAPI.
|
|
107
|
-
*/
|
|
108
|
-
export type DiscriminatorObject = OASDiscriminatorObject
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* OpenAPI reference object pointing to a schema definition via `$ref`.
|
|
112
|
-
*/
|
|
113
|
-
export type ReferenceObject = OpenAPIV3.ReferenceObject
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* OpenAPI response object from a spec that contains schema, status code, and headers.
|
|
117
|
-
*/
|
|
118
|
-
export type ResponseObject = OASResponseObject
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* OpenAPI media type object that maps a content-type string to its schema.
|
|
122
|
-
*/
|
|
123
|
-
export type MediaTypeObject = OASMediaTypeObject
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Configuration options for the OpenAPI adapter.
|
|
127
|
-
* Controls spec validation, content-type selection, and server URL resolution.
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* ```ts
|
|
131
|
-
* adapterOas({
|
|
132
|
-
* validate: false,
|
|
133
|
-
* dateType: 'date',
|
|
134
|
-
* serverIndex: 0,
|
|
135
|
-
* serverVariables: { env: 'prod' },
|
|
136
|
-
* })
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
export type AdapterOasOptions = {
|
|
140
|
-
/**
|
|
141
|
-
* Validate the OpenAPI spec before parsing.
|
|
142
|
-
* @default true
|
|
143
|
-
*/
|
|
144
|
-
validate?: boolean
|
|
145
|
-
/**
|
|
146
|
-
* Preferred content-type used when extracting request/response schemas.
|
|
147
|
-
* Defaults to the first valid JSON media type found in the spec.
|
|
148
|
-
*/
|
|
149
|
-
contentType?: ContentType
|
|
150
|
-
/**
|
|
151
|
-
* Index into `oas.api.servers` for computing `baseURL`.
|
|
152
|
-
* `0` → first server, `1` → second server. Omit to leave `baseURL` undefined.
|
|
153
|
-
*/
|
|
154
|
-
serverIndex?: number
|
|
155
|
-
/**
|
|
156
|
-
* Override values for `{variable}` placeholders in the selected server URL.
|
|
157
|
-
* Only used when `serverIndex` is set.
|
|
158
|
-
*
|
|
159
|
-
* @example
|
|
160
|
-
* ```ts
|
|
161
|
-
* // spec server: "https://api.{env}.example.com"
|
|
162
|
-
* serverVariables: { env: 'prod' }
|
|
163
|
-
* // → baseURL: "https://api.prod.example.com"
|
|
164
|
-
* ```
|
|
165
|
-
*/
|
|
166
|
-
serverVariables?: Record<string, string>
|
|
167
|
-
/**
|
|
168
|
-
* How the discriminator field is interpreted.
|
|
169
|
-
* - `'strict'` — uses `oneOf` schemas as written in the spec.
|
|
170
|
-
* - `'inherit'` — propagates discriminator values into child schemas from `discriminator.mapping`.
|
|
171
|
-
* @default 'strict'
|
|
172
|
-
*/
|
|
173
|
-
discriminator?: 'strict' | 'inherit'
|
|
174
|
-
} & Partial<ast.ParserOptions>
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Adapter options after defaults have been applied and schema name collisions resolved.
|
|
178
|
-
*/
|
|
179
|
-
export type AdapterOasResolvedOptions = {
|
|
180
|
-
validate: boolean
|
|
181
|
-
contentType: AdapterOasOptions['contentType']
|
|
182
|
-
serverIndex: AdapterOasOptions['serverIndex']
|
|
183
|
-
serverVariables: AdapterOasOptions['serverVariables']
|
|
184
|
-
discriminator: NonNullable<AdapterOasOptions['discriminator']>
|
|
185
|
-
dateType: NonNullable<AdapterOasOptions['dateType']>
|
|
186
|
-
integerType: NonNullable<AdapterOasOptions['integerType']>
|
|
187
|
-
unknownType: NonNullable<AdapterOasOptions['unknownType']>
|
|
188
|
-
emptySchemaType: NonNullable<AdapterOasOptions['emptySchemaType']>
|
|
189
|
-
enumSuffix: AdapterOasOptions['enumSuffix']
|
|
190
|
-
/**
|
|
191
|
-
* Map from original `$ref` paths to their collision-resolved schema names.
|
|
192
|
-
* Populated after each `parse()` call.
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* ```ts
|
|
196
|
-
* nameMapping.get('#/components/schemas/Order') // 'Order'
|
|
197
|
-
* nameMapping.get('#/components/responses/Order') // 'OrderResponse'
|
|
198
|
-
* ```
|
|
199
|
-
*/
|
|
200
|
-
nameMapping: Map<string, string>
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* `@kubb/core` adapter factory type for the OpenAPI adapter.
|
|
205
|
-
*/
|
|
206
|
-
export type AdapterOas = AdapterFactoryOptions<'oas', AdapterOasOptions, AdapterOasResolvedOptions, Document>
|
|
File without changes
|