@kubb/plugin-oas 4.12.5 → 4.12.7
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/{SchemaGenerator-Bi6IL-V6.js → SchemaGenerator-D7zYKaxn.js} +2 -2
- package/dist/{SchemaGenerator-Bi6IL-V6.js.map → SchemaGenerator-D7zYKaxn.js.map} +1 -1
- package/dist/{SchemaGenerator-ljGZegre.cjs → SchemaGenerator-DADe_0fV.cjs} +2 -2
- package/dist/{SchemaGenerator-ljGZegre.cjs.map → SchemaGenerator-DADe_0fV.cjs.map} +1 -1
- package/dist/{SchemaMapper-Cjte6oBd.d.cts → SchemaMapper-BkwcB4db.d.ts} +9 -4
- package/dist/{SchemaMapper-DlcrPonN.d.ts → SchemaMapper-C0cW-6bU.d.cts} +9 -4
- package/dist/{createGenerator-B1p6Pl-d.d.ts → createGenerator-C0zcRQF6.d.ts} +6 -3
- package/dist/{createGenerator-DyVUP-Aj.d.cts → createGenerator-DIaC635C.d.cts} +6 -3
- package/dist/generators.d.cts +2 -2
- package/dist/generators.d.ts +2 -2
- package/dist/{getSchemas-BVjyyxPB.cjs → getSchemas-DFlFfjx-.cjs} +9 -9
- package/dist/{getSchemas-BVjyyxPB.cjs.map → getSchemas-DFlFfjx-.cjs.map} +1 -1
- package/dist/{getSchemas-XWPSn2uf.js → getSchemas-DH7Mz7ud.js} +9 -9
- package/dist/{getSchemas-XWPSn2uf.js.map → getSchemas-DH7Mz7ud.js.map} +1 -1
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.d.cts +2 -2
- package/dist/hooks.d.ts +2 -2
- package/dist/hooks.js +1 -1
- package/dist/index.cjs +25 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +25 -10
- package/dist/index.js.map +1 -1
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.d.cts +2 -2
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +1 -1
- package/package.json +5 -6
- package/src/plugin.ts +21 -9
- package/src/types.ts +5 -1
- package/src/utils/getSchemas.ts +8 -8
package/dist/utils.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Output, _ as contentType, b as Config, f as OasTypes, g as SchemaObject, h as Operation, l as isOptional, m as OpenAPIV3_1, p as OpenAPIV3, u as Oas } from "./SchemaMapper-
|
|
2
|
-
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-
|
|
1
|
+
import { S as Output, _ as contentType, b as Config, f as OasTypes, g as SchemaObject, h as Operation, l as isOptional, m as OpenAPIV3_1, p as OpenAPIV3, u as Oas } from "./SchemaMapper-C0cW-6bU.cjs";
|
|
2
|
+
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-DIaC635C.cjs";
|
|
3
3
|
import { Params } from "@kubb/react-fabric/types";
|
|
4
4
|
|
|
5
5
|
//#region src/utils/getBanner.d.ts
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Output, _ as contentType, b as Config, f as OasTypes, g as SchemaObject, h as Operation, l as isOptional, m as OpenAPIV3_1, p as OpenAPIV3, u as Oas } from "./SchemaMapper-
|
|
2
|
-
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-
|
|
1
|
+
import { S as Output, _ as contentType, b as Config, f as OasTypes, g as SchemaObject, h as Operation, l as isOptional, m as OpenAPIV3_1, p as OpenAPIV3, u as Oas } from "./SchemaMapper-BkwcB4db.js";
|
|
2
|
+
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-C0zcRQF6.js";
|
|
3
3
|
import { Params } from "@kubb/react-fabric/types";
|
|
4
4
|
|
|
5
5
|
//#region src/utils/getBanner.d.ts
|
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as getSchemaFactory, t as getSchemas } from "./getSchemas-
|
|
1
|
+
import { n as getSchemaFactory, t as getSchemas } from "./getSchemas-DH7Mz7ud.js";
|
|
2
2
|
import { n as getBanner, t as getFooter } from "./getFooter-C2vyr3vj.js";
|
|
3
3
|
import transformers, { camelCase, isValidVarName } from "@kubb/core/transformers";
|
|
4
4
|
import { URLPath } from "@kubb/core/utils";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-oas",
|
|
3
|
-
"version": "4.12.
|
|
3
|
+
"version": "4.12.7",
|
|
4
4
|
"description": "OpenAPI Specification (OAS) plugin for Kubb, providing core functionality for parsing and processing OpenAPI/Swagger schemas for code generation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openapi",
|
|
@@ -79,15 +79,14 @@
|
|
|
79
79
|
}
|
|
80
80
|
],
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@kubb/react-fabric": "0.7.
|
|
83
|
-
"@stoplight/yaml": "^4.3.0",
|
|
82
|
+
"@kubb/react-fabric": "0.7.2",
|
|
84
83
|
"p-limit": "^7.2.0",
|
|
85
84
|
"remeda": "^2.32.0",
|
|
86
|
-
"@kubb/core": "4.12.
|
|
87
|
-
"@kubb/oas": "4.12.
|
|
85
|
+
"@kubb/core": "4.12.7",
|
|
86
|
+
"@kubb/oas": "4.12.7"
|
|
88
87
|
},
|
|
89
88
|
"peerDependencies": {
|
|
90
|
-
"@kubb/react-fabric": "0.7.
|
|
89
|
+
"@kubb/react-fabric": "0.7.2"
|
|
91
90
|
},
|
|
92
91
|
"engines": {
|
|
93
92
|
"node": ">=20"
|
package/src/plugin.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import { type Config, definePlugin, type Group, getMode } from '@kubb/core'
|
|
2
|
+
import { type Config, definePlugin, type Group, getMode, type KubbEvents } from '@kubb/core'
|
|
3
3
|
import { camelCase } from '@kubb/core/transformers'
|
|
4
|
+
import type { AsyncEventEmitter } from '@kubb/core/utils'
|
|
4
5
|
import type { Oas } from '@kubb/oas'
|
|
5
6
|
import { parseFromConfig } from '@kubb/oas'
|
|
6
7
|
import { jsonGenerator } from './generators'
|
|
@@ -24,7 +25,7 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
24
25
|
discriminator = 'strict',
|
|
25
26
|
} = options
|
|
26
27
|
|
|
27
|
-
const getOas = async ({ config }: { config: Config }): Promise<Oas> => {
|
|
28
|
+
const getOas = async ({ validate, config, events }: { validate: boolean; config: Config; events: AsyncEventEmitter<KubbEvents> }): Promise<Oas> => {
|
|
28
29
|
// needs to be in a different variable or the catch here will not work(return of a promise instead)
|
|
29
30
|
const oas = await parseFromConfig(config, oasClass)
|
|
30
31
|
|
|
@@ -37,10 +38,18 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
37
38
|
if (validate) {
|
|
38
39
|
await oas.valdiate()
|
|
39
40
|
}
|
|
40
|
-
} catch (
|
|
41
|
-
const
|
|
41
|
+
} catch (er) {
|
|
42
|
+
const caughtError = er as Error
|
|
43
|
+
const errorTimestamp = new Date()
|
|
44
|
+
const error = new Error('OAS Validation failed', {
|
|
45
|
+
cause: caughtError,
|
|
46
|
+
})
|
|
42
47
|
|
|
43
|
-
|
|
48
|
+
events.emit('info', caughtError.message)
|
|
49
|
+
events.emit('debug', {
|
|
50
|
+
date: errorTimestamp,
|
|
51
|
+
logs: [`✗ ${error.message}`, caughtError.message],
|
|
52
|
+
})
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
return oas
|
|
@@ -56,18 +65,20 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
56
65
|
},
|
|
57
66
|
inject() {
|
|
58
67
|
const config = this.config
|
|
68
|
+
const events = this.events
|
|
69
|
+
|
|
59
70
|
let oas: Oas
|
|
60
71
|
|
|
61
72
|
return {
|
|
62
|
-
async getOas() {
|
|
73
|
+
async getOas({ validate = false } = {}) {
|
|
63
74
|
if (!oas) {
|
|
64
|
-
oas = await getOas({ config })
|
|
75
|
+
oas = await getOas({ config, events, validate })
|
|
65
76
|
}
|
|
66
77
|
|
|
67
78
|
return oas
|
|
68
79
|
},
|
|
69
80
|
async getBaseURL() {
|
|
70
|
-
const oas = await getOas({ config })
|
|
81
|
+
const oas = await getOas({ config, events, validate: false })
|
|
71
82
|
if (serverIndex !== undefined) {
|
|
72
83
|
return oas.api.servers?.at(serverIndex)?.url
|
|
73
84
|
}
|
|
@@ -111,11 +122,12 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
111
122
|
return path.resolve(root, output.path, baseName)
|
|
112
123
|
},
|
|
113
124
|
async install() {
|
|
125
|
+
const oas = await this.getOas({ validate })
|
|
126
|
+
|
|
114
127
|
if (!output) {
|
|
115
128
|
return
|
|
116
129
|
}
|
|
117
130
|
|
|
118
|
-
const oas = await this.getOas()
|
|
119
131
|
await oas.dereference()
|
|
120
132
|
|
|
121
133
|
const schemaGenerator = new SchemaGenerator(
|
package/src/types.ts
CHANGED
|
@@ -4,8 +4,12 @@ import type { KubbFile } from '@kubb/fabric-core/types'
|
|
|
4
4
|
import type { contentType, HttpMethod, Oas, Operation, SchemaObject } from '@kubb/oas'
|
|
5
5
|
import type { Generator } from './generators/types.ts'
|
|
6
6
|
|
|
7
|
+
type GetOasOptions = {
|
|
8
|
+
validate?: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
type Context = {
|
|
8
|
-
getOas(): Promise<Oas>
|
|
12
|
+
getOas(options?: GetOasOptions): Promise<Oas>
|
|
9
13
|
getBaseURL(): Promise<string | undefined>
|
|
10
14
|
}
|
|
11
15
|
|
package/src/utils/getSchemas.ts
CHANGED
|
@@ -96,10 +96,10 @@ export function getSchemas({ oas, contentType, includes = ['schemas', 'requestBo
|
|
|
96
96
|
if (includes.includes('responses')) {
|
|
97
97
|
const responses = components?.responses || {}
|
|
98
98
|
for (const [name, response] of Object.entries(responses)) {
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
const firstContentType = Object.keys(
|
|
102
|
-
schemas[name] =
|
|
99
|
+
const responseObject = response as OasTypes.ResponseObject
|
|
100
|
+
if (responseObject.content && !schemas[name]) {
|
|
101
|
+
const firstContentType = Object.keys(responseObject.content)[0] || 'application/json'
|
|
102
|
+
schemas[name] = responseObject.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -107,10 +107,10 @@ export function getSchemas({ oas, contentType, includes = ['schemas', 'requestBo
|
|
|
107
107
|
if (includes.includes('requestBodies')) {
|
|
108
108
|
const requestBodies = components?.requestBodies || {}
|
|
109
109
|
for (const [name, request] of Object.entries(requestBodies)) {
|
|
110
|
-
const
|
|
111
|
-
if (
|
|
112
|
-
const firstContentType = Object.keys(
|
|
113
|
-
schemas[name] =
|
|
110
|
+
const requestObject = request as OasTypes.RequestBodyObject
|
|
111
|
+
if (requestObject.content && !schemas[name]) {
|
|
112
|
+
const firstContentType = Object.keys(requestObject.content)[0] || 'application/json'
|
|
113
|
+
schemas[name] = requestObject.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
}
|