@kubb/swagger-ts 2.13.1 → 2.13.3
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/{chunk-7C2QP7EN.js → chunk-KVSEN6JB.js} +1 -1
- package/dist/chunk-KVSEN6JB.js.map +1 -0
- package/dist/{chunk-TIPBGRIZ.cjs → chunk-ZTEYK3XI.cjs} +1 -1
- package/dist/chunk-ZTEYK3XI.cjs.map +1 -0
- package/dist/components.cjs +2 -2
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/index-DOy9O4ye.d.cts +11 -0
- package/dist/index-DOy9O4ye.d.ts +11 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +2 -6
- package/dist/index.d.ts +2 -6
- package/dist/index.js +1 -1
- package/dist/oas.d.cts +1 -6
- package/dist/oas.d.ts +1 -6
- package/package.json +9 -12
- package/src/OperationGenerator.tsx +1 -1
- package/src/SchemaGenerator.tsx +1 -1
- package/src/components/OasType.tsx +1 -1
- package/src/components/OperationSchema.tsx +1 -1
- package/src/oas/index.ts +1 -7
- package/dist/chunk-7C2QP7EN.js.map +0 -1
- package/dist/chunk-TIPBGRIZ.cjs.map +0 -1
- package/dist/index-_MgWTBjd.d.cts +0 -389
- package/dist/index-_MgWTBjd.d.ts +0 -389
- package/src/oas/infer.ts +0 -51
- package/src/oas/mappers.ts +0 -75
- package/src/oas/model.ts +0 -38
- package/src/oas/requestParams.ts +0 -135
- package/src/oas/response.ts +0 -30
- package/src/oas/security.ts +0 -157
package/src/oas/requestParams.ts
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
import type { OasTypes } from '@kubb/swagger/oas'
|
2
|
-
import type { SplitByDelimiter, TupleToUnion } from '@kubb/types'
|
3
|
-
import type { Pipe, Strings, Tuples } from 'hotscript'
|
4
|
-
import type { FromSchema, JSONSchema } from 'json-schema-to-ts'
|
5
|
-
import type { MethodMap, ParamMap, PathMap } from './mappers.ts'
|
6
|
-
import type { SecurityParamsBySecurityRef } from './security.ts'
|
7
|
-
|
8
|
-
type Checks = {
|
9
|
-
RequestBodyJson: {
|
10
|
-
requestBody: { content: { 'application/json': { schema: JSONSchema } } }
|
11
|
-
}
|
12
|
-
RequestBodyFormData: {
|
13
|
-
requestBody: {
|
14
|
-
content: { 'multipart/form-data': { schema: JSONSchema } }
|
15
|
-
}
|
16
|
-
}
|
17
|
-
RequestBodyFormEncoded: {
|
18
|
-
requestBody: {
|
19
|
-
content: {
|
20
|
-
'application/x-www-form-urlencoded': { schema: JSONSchema }
|
21
|
-
}
|
22
|
-
}
|
23
|
-
}
|
24
|
-
Parameters: {
|
25
|
-
parameters: { name: string; in: string }[]
|
26
|
-
}
|
27
|
-
PathBrackets: `${string}{${string}}${string}`
|
28
|
-
PathPattern: `${string}:${string}${string}`
|
29
|
-
Required: { required: true }
|
30
|
-
}
|
31
|
-
|
32
|
-
type ExtractPathParamsWithPattern<TPath extends string> = Pipe<
|
33
|
-
TPath,
|
34
|
-
[Strings.Split<'/'>, Tuples.Filter<Strings.StartsWith<':'>>, Tuples.Map<Strings.Trim<':'>>, Tuples.ToUnion]
|
35
|
-
>
|
36
|
-
|
37
|
-
type IsPathParameter<T extends string> = T extends `{${infer U}}` ? U : never
|
38
|
-
|
39
|
-
type ExtractPathParameters<T extends any[]> = {
|
40
|
-
[K in keyof T]: IsPathParameter<T[K]>
|
41
|
-
}
|
42
|
-
|
43
|
-
type ExtractSegments<TPath extends string> = SplitByDelimiter<TPath, '/'>
|
44
|
-
|
45
|
-
type ExtractSubSegments<T extends any[]> = {
|
46
|
-
[K in keyof T]: SplitByDelimiter<T[K], ';'>
|
47
|
-
}
|
48
|
-
|
49
|
-
type ExtractPathParamsWithBrackets<TPath extends string> = TupleToUnion<ExtractPathParameters<ExtractSubSegments<ExtractSegments<TPath>>[number]>>
|
50
|
-
|
51
|
-
export type RequestParams<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>, TMethod extends keyof MethodMap<TOAS, TPath>> = (MethodMap<
|
52
|
-
TOAS,
|
53
|
-
TPath
|
54
|
-
>[TMethod] extends Checks['RequestBodyJson']
|
55
|
-
? MethodMap<TOAS, TPath>[TMethod]['requestBody'] extends Checks['Required']
|
56
|
-
? {
|
57
|
-
/**
|
58
|
-
* The request body in JSON is required for this request.
|
59
|
-
*
|
60
|
-
* The value of `json` will be stringified and sent as the request body with `Content-Type: application/json`.
|
61
|
-
*/
|
62
|
-
json: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['application/json']['schema']>
|
63
|
-
}
|
64
|
-
: {
|
65
|
-
/**
|
66
|
-
* The request body in JSON is optional for this request.
|
67
|
-
*
|
68
|
-
* The value of `json` will be stringified and sent as the request body with `Content-Type: application/json`.
|
69
|
-
*/
|
70
|
-
json?: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['application/json']['schema']>
|
71
|
-
}
|
72
|
-
: MethodMap<TOAS, TPath>[TMethod] extends Checks['RequestBodyFormData']
|
73
|
-
? MethodMap<TOAS, TPath>[TMethod]['requestBody'] extends Checks['Required']
|
74
|
-
? {
|
75
|
-
/**
|
76
|
-
* The request body in multipart/form-data is required for this request.
|
77
|
-
*
|
78
|
-
* The value of `formData` will be sent as the request body with `Content-Type: multipart/form-data`.
|
79
|
-
*/
|
80
|
-
formData: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['multipart/form-data']['schema']>
|
81
|
-
}
|
82
|
-
: {
|
83
|
-
/**
|
84
|
-
* The request body in multipart/form-data is optional for this request.
|
85
|
-
*
|
86
|
-
* The value of `formData` will be sent as the request body with `Content-Type: multipart/form-data`.
|
87
|
-
*/
|
88
|
-
formData?: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['multipart/form-data']['schema']>
|
89
|
-
}
|
90
|
-
: MethodMap<TOAS, TPath>[TMethod] extends Checks['RequestBodyFormEncoded']
|
91
|
-
? MethodMap<TOAS, TPath>[TMethod]['requestBody'] extends Checks['Required']
|
92
|
-
? {
|
93
|
-
/**
|
94
|
-
* The request body in application/x-www-form-urlencoded is required for this request.
|
95
|
-
*
|
96
|
-
* The value of `formUrlEncoded` will be sent as the request body with `Content-Type: application/x-www-form-urlencoded`.
|
97
|
-
*/
|
98
|
-
formUrlEncoded: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['application/x-www-form-urlencoded']['schema']>
|
99
|
-
}
|
100
|
-
: {
|
101
|
-
/**
|
102
|
-
* The request body in application/x-www-form-urlencoded is optional for this request.
|
103
|
-
*
|
104
|
-
* The value of `formUrlEncoded` will be sent as the request body with `Content-Type: application/x-www-form-urlencoded`.
|
105
|
-
*/
|
106
|
-
formUrlEncoded?: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['application/x-www-form-urlencoded']['schema']>
|
107
|
-
}
|
108
|
-
: {}) &
|
109
|
-
(MethodMap<TOAS, TPath>[TMethod] extends Checks['Parameters'] ? ParamMap<MethodMap<TOAS, TPath>[TMethod]['parameters']> : {}) & // If there is any parameters defined in path but not in the parameters array, we should add them to the params
|
110
|
-
(TPath extends Checks['PathBrackets']
|
111
|
-
? {
|
112
|
-
/**
|
113
|
-
* Parameters defined in the path are required for this request.
|
114
|
-
*
|
115
|
-
* The value of `params` will be used to replace the path parameters.
|
116
|
-
*
|
117
|
-
* For example if path is `/todos/{id}` and `params` is `{ id: '1' }`, the path will be `/todos/1`
|
118
|
-
*/
|
119
|
-
params: Record<ExtractPathParamsWithBrackets<TPath>, string | number | bigint | boolean>
|
120
|
-
}
|
121
|
-
: {}) &
|
122
|
-
(TPath extends Checks['PathPattern']
|
123
|
-
? {
|
124
|
-
/**
|
125
|
-
* Parameters defined in the path are required for this request.
|
126
|
-
*
|
127
|
-
* The value of `params` will be used to replace the path parameters.
|
128
|
-
*
|
129
|
-
* For example if path is `/todos/:id` and `params` is `{ id: '1' }`, the path will be `/todos/1`.
|
130
|
-
*/
|
131
|
-
params: Record<ExtractPathParamsWithPattern<TPath>, string | number | bigint | boolean>
|
132
|
-
}
|
133
|
-
: {}) & // Respect security definitions in path object
|
134
|
-
SecurityParamsBySecurityRef<TOAS, MethodMap<TOAS, TPath>[TMethod]> & // Respect global security definitions
|
135
|
-
SecurityParamsBySecurityRef<TOAS, TOAS>
|
package/src/oas/response.ts
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
import type { OasTypes } from '@kubb/swagger/oas'
|
2
|
-
import type { FromSchema } from 'json-schema-to-ts'
|
3
|
-
import type { MethodMap, PathMap, StatusMap } from './mappers.ts'
|
4
|
-
|
5
|
-
type Checks = {
|
6
|
-
Content: { content: any }
|
7
|
-
}
|
8
|
-
|
9
|
-
type ResponseSchemas<
|
10
|
-
TOAS extends OasTypes.OASDocument,
|
11
|
-
TPath extends keyof PathMap<TOAS>,
|
12
|
-
TMethod extends keyof MethodMap<TOAS, TPath>,
|
13
|
-
TStatus extends keyof StatusMap<TOAS, TPath, TMethod>,
|
14
|
-
> = StatusMap<TOAS, TPath, TMethod>[TStatus]['content']
|
15
|
-
|
16
|
-
type JSONResponseSchema<
|
17
|
-
TOAS extends OasTypes.OASDocument,
|
18
|
-
TPath extends keyof PathMap<TOAS>,
|
19
|
-
TMethod extends keyof MethodMap<TOAS, TPath>,
|
20
|
-
TStatus extends keyof StatusMap<TOAS, TPath, TMethod>,
|
21
|
-
> = StatusMap<TOAS, TPath, TMethod>[TStatus] extends Checks['Content']
|
22
|
-
? ResponseSchemas<TOAS, TPath, TMethod, TStatus>[keyof ResponseSchemas<TOAS, TPath, TMethod, TStatus>]['schema']
|
23
|
-
: StatusMap<TOAS, TPath, TMethod>[TStatus]['schema']
|
24
|
-
|
25
|
-
export type Response<
|
26
|
-
TOAS extends OasTypes.OASDocument,
|
27
|
-
TPath extends keyof PathMap<TOAS>,
|
28
|
-
TMethod extends keyof MethodMap<TOAS, TPath>,
|
29
|
-
TStatusCode extends keyof StatusMap<TOAS, TPath, TMethod> = 200,
|
30
|
-
> = FromSchema<JSONResponseSchema<TOAS, TPath, TMethod, TStatusCode>>
|
package/src/oas/security.ts
DELETED
@@ -1,157 +0,0 @@
|
|
1
|
-
import type { Call, Objects, Tuples } from 'hotscript'
|
2
|
-
|
3
|
-
type Checks = {
|
4
|
-
Security: { security: { [key: string]: any }[] }
|
5
|
-
|
6
|
-
AuthParams: {
|
7
|
-
Basic:
|
8
|
-
| {
|
9
|
-
type: 'http'
|
10
|
-
scheme: 'basic'
|
11
|
-
}
|
12
|
-
| { type: 'basic' }
|
13
|
-
Bearer:
|
14
|
-
| {
|
15
|
-
type: 'http'
|
16
|
-
scheme: 'bearer'
|
17
|
-
}
|
18
|
-
| { type: 'bearer' }
|
19
|
-
|
20
|
-
OAuth2: {
|
21
|
-
type: 'oauth2'
|
22
|
-
}
|
23
|
-
ApiKey: {
|
24
|
-
type: 'apiKey'
|
25
|
-
in: 'header'
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
AuthName: {
|
30
|
-
Basic: `basic${string}`
|
31
|
-
Bearer: `bearer${string}`
|
32
|
-
OAuth2: `oauth${string}`
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
type SecuritySchemeName<T extends Checks['Security']> = Call<Tuples.Map<Objects.Keys>, T['security']>[number]
|
37
|
-
|
38
|
-
namespace AuthParams {
|
39
|
-
export type Basic<TSecurityScheme> = TSecurityScheme extends Checks['AuthParams']['Basic']
|
40
|
-
? {
|
41
|
-
headers: {
|
42
|
-
/**
|
43
|
-
* `Authorization` header is required for basic authentication
|
44
|
-
* @see https://en.wikipedia.org/wiki/Basic_access_authentication
|
45
|
-
*
|
46
|
-
* It contains the word `Basic` followed by a space and a base64-encoded string `username:password`
|
47
|
-
*
|
48
|
-
* @example
|
49
|
-
* ```
|
50
|
-
* Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
|
51
|
-
* ```
|
52
|
-
*/
|
53
|
-
Authorization: `Basic ${string}`
|
54
|
-
}
|
55
|
-
}
|
56
|
-
: {}
|
57
|
-
|
58
|
-
export type Bearer<TSecurityScheme> = TSecurityScheme extends Checks['AuthParams']['Bearer']
|
59
|
-
? {
|
60
|
-
/**
|
61
|
-
* `Authorization` header is required for bearer authentication
|
62
|
-
* @see https://swagger.io/docs/specification/authentication/bearer-authentication/
|
63
|
-
*/
|
64
|
-
headers: {
|
65
|
-
/**
|
66
|
-
* It contains the word `Bearer` followed by a space and the token
|
67
|
-
*
|
68
|
-
* @example
|
69
|
-
* ```
|
70
|
-
* Authorization: Bearer {token}
|
71
|
-
* ```
|
72
|
-
*/
|
73
|
-
Authorization: `Bearer ${string}`
|
74
|
-
}
|
75
|
-
}
|
76
|
-
: {}
|
77
|
-
|
78
|
-
export type ApiKey<TSecurityScheme> = TSecurityScheme extends Checks['AuthParams']['ApiKey'] & {
|
79
|
-
name: infer TApiKeyHeaderName
|
80
|
-
}
|
81
|
-
? {
|
82
|
-
headers: {
|
83
|
-
/**
|
84
|
-
* Header required for API key authentication
|
85
|
-
*/
|
86
|
-
[THeaderName in TApiKeyHeaderName extends string ? TApiKeyHeaderName : never]: string
|
87
|
-
}
|
88
|
-
}
|
89
|
-
: TSecurityScheme extends {
|
90
|
-
type: 'apiKey'
|
91
|
-
in: 'query'
|
92
|
-
name: infer TApiKeyQueryName
|
93
|
-
}
|
94
|
-
? {
|
95
|
-
query: {
|
96
|
-
/**
|
97
|
-
* Query parameter required for API key authentication
|
98
|
-
*/
|
99
|
-
[TQueryName in TApiKeyQueryName extends string ? TApiKeyQueryName : never]: string
|
100
|
-
}
|
101
|
-
}
|
102
|
-
: {}
|
103
|
-
|
104
|
-
export type OAuth2<TSecurityScheme> = TSecurityScheme extends Checks['AuthParams']['OAuth2']
|
105
|
-
? {
|
106
|
-
/**
|
107
|
-
* `Authorization` header is required for OAuth2.
|
108
|
-
*/
|
109
|
-
headers: {
|
110
|
-
/**
|
111
|
-
* The access token string as issued by the authorization server.
|
112
|
-
* @example `Authorization: Bearer <access_token>`
|
113
|
-
*/
|
114
|
-
Authorization: `Bearer ${string}`
|
115
|
-
}
|
116
|
-
}
|
117
|
-
: {}
|
118
|
-
}
|
119
|
-
|
120
|
-
type OASSecurityParams<TSecurityScheme> = AuthParams.Basic<TSecurityScheme> &
|
121
|
-
AuthParams.Bearer<TSecurityScheme> &
|
122
|
-
AuthParams.ApiKey<TSecurityScheme> &
|
123
|
-
AuthParams.OAuth2<TSecurityScheme>
|
124
|
-
|
125
|
-
export type SecurityParamsBySecurityRef<TOAS, TSecurityObj> = TSecurityObj extends Checks['Security']
|
126
|
-
? TOAS extends
|
127
|
-
| {
|
128
|
-
components: {
|
129
|
-
securitySchemes: {
|
130
|
-
[TSecuritySchemeNameKey in SecuritySchemeName<TSecurityObj> extends string ? SecuritySchemeName<TSecurityObj> : never]: infer TSecurityScheme
|
131
|
-
}
|
132
|
-
}
|
133
|
-
}
|
134
|
-
| {
|
135
|
-
securityDefinitions: {
|
136
|
-
[TSecuritySchemeNameKey in SecuritySchemeName<TSecurityObj> extends string ? SecuritySchemeName<TSecurityObj> : never]: infer TSecurityScheme
|
137
|
-
}
|
138
|
-
}
|
139
|
-
? OASSecurityParams<TSecurityScheme>
|
140
|
-
: // OAS may have a bad reference to a security scheme
|
141
|
-
// So we can assume it
|
142
|
-
SecuritySchemeName<TSecurityObj> extends Checks['AuthName']['Basic']
|
143
|
-
? AuthParams.Basic<{
|
144
|
-
type: 'http'
|
145
|
-
scheme: 'basic'
|
146
|
-
}>
|
147
|
-
: SecuritySchemeName<TSecurityObj> extends Checks['AuthName']['Bearer']
|
148
|
-
? AuthParams.Bearer<{
|
149
|
-
type: 'http'
|
150
|
-
scheme: 'bearer'
|
151
|
-
}>
|
152
|
-
: SecuritySchemeName<TSecurityObj> extends Checks['AuthName']['OAuth2']
|
153
|
-
? AuthParams.OAuth2<{
|
154
|
-
type: 'oauth2'
|
155
|
-
}>
|
156
|
-
: {}
|
157
|
-
: {}
|