@kubb/plugin-fetch 5.5.7 → 5.5.9

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.
@@ -0,0 +1,191 @@
1
+ {
2
+ "$schema": "https://kubb.dev/schemas/kubb-extension.json",
3
+ "kind": "plugin",
4
+ "name": "plugin-fetch",
5
+ "export": "pluginFetch",
6
+ "displayName": "Fetch",
7
+ "description": "Generates a type-safe Fetch API client from your OpenAPI spec, one async function per operation, so each call stays in sync with the API.",
8
+ "category": "client",
9
+ "icon": {
10
+ "light": "https://kubb.dev/feature/javascript.svg"
11
+ },
12
+ "tags": ["api-client", "fetch", "http-client", "codegen", "openapi", "validator"],
13
+ "docs": "https://kubb.dev/plugins/plugin-fetch",
14
+ "compatibility": {
15
+ "kubb": ">=5.8.0",
16
+ "node": ">=22"
17
+ },
18
+ "role": "client",
19
+ "options": [
20
+ {
21
+ "key": "outputPath",
22
+ "path": ["output", "path"],
23
+ "label": "Output Path",
24
+ "description": "Output folder for generated files",
25
+ "type": "text",
26
+ "default": "clients"
27
+ },
28
+ {
29
+ "key": "barrel",
30
+ "path": ["output", "barrel"],
31
+ "label": "Barrel",
32
+ "description": "How index.ts barrel files are generated",
33
+ "type": "select",
34
+ "default": {
35
+ "type": "named"
36
+ },
37
+ "choices": [
38
+ {
39
+ "label": "named",
40
+ "value": {
41
+ "type": "named"
42
+ }
43
+ },
44
+ {
45
+ "label": "named (nested)",
46
+ "value": {
47
+ "type": "named",
48
+ "nested": true
49
+ }
50
+ },
51
+ {
52
+ "label": "all",
53
+ "value": {
54
+ "type": "all"
55
+ }
56
+ },
57
+ {
58
+ "label": "all (nested)",
59
+ "value": {
60
+ "type": "all",
61
+ "nested": true
62
+ }
63
+ },
64
+ {
65
+ "label": "false (disabled)",
66
+ "value": false
67
+ }
68
+ ]
69
+ },
70
+ {
71
+ "key": "outputMode",
72
+ "path": ["output", "mode"],
73
+ "label": "Output Mode",
74
+ "description": "How the plugin consolidates its code into files. File mode writes everything into a single file, so the output path must include a file extension and cannot be grouped.",
75
+ "type": "select",
76
+ "default": "directory",
77
+ "choices": [
78
+ {
79
+ "label": "directory (one file per schema)",
80
+ "value": "directory"
81
+ },
82
+ {
83
+ "label": "file (single file)",
84
+ "value": "file"
85
+ }
86
+ ]
87
+ },
88
+ {
89
+ "key": "validator",
90
+ "path": ["validator"],
91
+ "label": "Validator",
92
+ "description": "Validate request and response bodies with schemas from @kubb/plugin-zod",
93
+ "type": "select",
94
+ "default": false,
95
+ "choices": [
96
+ {
97
+ "label": "false (disabled)",
98
+ "value": false
99
+ },
100
+ {
101
+ "label": "zod",
102
+ "value": "zod"
103
+ }
104
+ ]
105
+ },
106
+ {
107
+ "key": "group",
108
+ "path": ["group"],
109
+ "label": "Group",
110
+ "description": "Group generated operations by OpenAPI tag or path",
111
+ "type": "select",
112
+ "default": null,
113
+ "choices": [
114
+ {
115
+ "label": "none",
116
+ "value": null
117
+ },
118
+ {
119
+ "label": "by tag",
120
+ "value": {
121
+ "type": "tag"
122
+ }
123
+ },
124
+ {
125
+ "label": "by path",
126
+ "value": {
127
+ "type": "path"
128
+ }
129
+ }
130
+ ]
131
+ },
132
+ {
133
+ "key": "excludeTags",
134
+ "path": ["exclude"],
135
+ "label": "Exclude Tags",
136
+ "description": "Comma-separated OpenAPI tags to exclude from generation",
137
+ "type": "list",
138
+ "item": {
139
+ "type": "tag",
140
+ "pattern": "$item"
141
+ }
142
+ },
143
+ {
144
+ "key": "includeTags",
145
+ "path": ["include"],
146
+ "label": "Include Tags",
147
+ "description": "Comma-separated OpenAPI tags to include. Only operations with these tags are generated",
148
+ "type": "list",
149
+ "item": {
150
+ "type": "tag",
151
+ "pattern": "$item"
152
+ }
153
+ },
154
+ {
155
+ "key": "baseURL",
156
+ "path": ["baseURL"],
157
+ "label": "Base URL",
158
+ "description": "Custom API base URL",
159
+ "type": "text"
160
+ },
161
+ {
162
+ "key": "sdkMode",
163
+ "path": ["sdk", "mode"],
164
+ "label": "SDK Mode",
165
+ "description": "Group generated operations into an SDK client by tag or flat",
166
+ "type": "select",
167
+ "default": null,
168
+ "choices": [
169
+ {
170
+ "label": "off (standalone functions)",
171
+ "value": null
172
+ },
173
+ {
174
+ "label": "tag",
175
+ "value": "tag"
176
+ },
177
+ {
178
+ "label": "flat",
179
+ "value": "flat"
180
+ }
181
+ ]
182
+ },
183
+ {
184
+ "key": "sdkName",
185
+ "path": ["sdk", "name"],
186
+ "label": "SDK Name",
187
+ "description": "Root client name for the generated SDK",
188
+ "type": "text"
189
+ }
190
+ ]
191
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-fetch",
3
- "version": "5.5.7",
3
+ "version": "5.5.9",
4
4
  "description": "Generate a slim, type-safe HTTP client with Kubb based on the native Fetch api.",
5
5
  "keywords": [
6
6
  "api-client",
@@ -39,6 +39,8 @@
39
39
  "src",
40
40
  "dist",
41
41
  "templates",
42
+ "kubb-extension.json",
43
+ "OVERVIEW.md",
42
44
  "!/**/**.test.**",
43
45
  "!/**/__tests__/**",
44
46
  "!/**/__snapshots__/**"
@@ -58,6 +60,7 @@
58
60
  "require": "./dist/index.cjs"
59
61
  },
60
62
  "./package.json": "./package.json",
63
+ "./kubb-extension.json": "./kubb-extension.json",
61
64
  "./templates/*": "./templates/*"
62
65
  },
63
66
  "publishConfig": {
@@ -65,17 +68,17 @@
65
68
  "registry": "https://registry.npmjs.org/"
66
69
  },
67
70
  "dependencies": {
68
- "@kubb/plugin-ts": "^5.0.6",
69
- "@kubb/plugin-zod": "^5.4.4"
71
+ "@kubb/plugin-ts": "^5.0.8",
72
+ "@kubb/plugin-zod": "^5.4.6"
70
73
  },
71
74
  "devDependencies": {
72
75
  "@internals/client": "0.0.0",
73
76
  "@internals/shared": "0.0.0",
74
- "kubb": "^5.6.3",
77
+ "kubb": "^5.8.1",
75
78
  "typescript": "^6.0.3"
76
79
  },
77
80
  "peerDependencies": {
78
- "kubb": "^5.6.3"
81
+ "kubb": "^5.8.1"
79
82
  },
80
83
  "engines": {
81
84
  "node": ">=22"
package/src/plugin.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import path from 'node:path'
2
2
  import { createSdkGenerator, defaultMacros, resolverClient } from '@internals/client'
3
3
  import { createGroupConfig } from '@internals/shared'
4
- import { definePlugin, Resolver } from 'kubb/kit'
4
+ import { addGenerator, definePlugin, injectFile, Resolver, setMacros, setResolver, useConfig } from 'kubb/kit'
5
+ import { compatibility } from '../kubb-extension.json'
6
+ import { version } from '../package.json'
5
7
  import { pluginTsName } from '@kubb/plugin-ts'
6
8
  import { pluginZodName } from '@kubb/plugin-zod'
7
9
  import { clientGenerator } from './generators/clientGenerator.tsx'
@@ -36,77 +38,72 @@ export const pluginFetchName = 'plugin-fetch' satisfies PluginFetch['name']
36
38
  * })
37
39
  * ```
38
40
  */
39
- export const pluginFetch = definePlugin<PluginFetch>((options) => {
40
- const {
41
- output = { path: 'clients', barrel: { type: 'named' } },
42
- exclude = [],
43
- include,
44
- override = [],
45
- baseURL,
46
- throwOnErrorDefault = true,
47
- validator = false,
48
- returnType = 'full',
49
- group,
50
- sdk,
51
- resolver: userResolver,
52
- } = options
41
+ export const pluginFetch = definePlugin<PluginFetch>({
42
+ meta: { name: pluginFetchName, version, compatibility },
43
+ // Both are ordering hints, skipped when the plugin is not in the pipeline. `plugin-ts` supplies
44
+ // the operation types unless it is absent, in which case `pluginZod({ inferred: true })` does.
45
+ dependencies: { [pluginTsName]: { optional: true }, [pluginZodName]: { optional: true } },
46
+ setup(options) {
47
+ const config = useConfig()
48
+ const {
49
+ output = { path: 'clients', barrel: { type: 'named' } },
50
+ exclude = [],
51
+ include,
52
+ override = [],
53
+ baseURL,
54
+ throwOnErrorDefault = true,
55
+ validator = false,
56
+ returnType = 'full',
57
+ group,
58
+ sdk,
59
+ resolver: userResolver,
60
+ } = options
53
61
 
54
- const resolved: ResolvedOptions = {
55
- output,
56
- exclude,
57
- include,
58
- override,
59
- group: createGroupConfig(group),
60
- baseURL,
61
- throwOnErrorDefault,
62
- validator,
63
- returnType,
64
- sdk: sdk ? { mode: sdk.mode ?? 'tag', name: sdk.name } : undefined,
65
- resolver: userResolver ? Resolver.merge<ResolverClient>(resolverClient, userResolver) : resolverClient,
66
- }
62
+ const resolved: ResolvedOptions = {
63
+ output,
64
+ exclude,
65
+ include,
66
+ override,
67
+ group: createGroupConfig(group),
68
+ baseURL,
69
+ throwOnErrorDefault,
70
+ validator,
71
+ returnType,
72
+ sdk: sdk ? { mode: sdk.mode ?? 'tag', name: sdk.name } : undefined,
73
+ resolver: userResolver ? Resolver.merge<ResolverClient>(resolverClient, userResolver) : resolverClient,
74
+ }
67
75
 
68
- // `sdk` swaps the per-operation functions for the class-based SDK; left unset, the standalone
69
- // functions (which query plugins consume) stay.
70
- const selectedGenerators = resolved.sdk ? [createSdkGenerator<PluginFetch>()] : [clientGenerator]
76
+ setResolver(resolved.resolver)
77
+ setMacros([...defaultMacros, ...(options.macros ?? [])])
71
78
 
72
- return {
73
- name: pluginFetchName,
74
- options,
75
- // Both are ordering hints, dropped when the plugin is not in the pipeline. `plugin-ts` supplies
76
- // the operation types unless it is absent, in which case `pluginZod({ inferred: true })` does.
77
- dependencies: [pluginTsName, pluginZodName],
78
- hooks: {
79
- 'kubb:plugin:setup'(ctx) {
80
- ctx.setOptions(resolved)
81
- ctx.setResolver(resolved.resolver)
82
- ctx.setMacros([...defaultMacros, ...(options.macros ?? [])])
79
+ // `sdk` swaps the per-operation functions for the class-based SDK; left unset, the standalone
80
+ // functions (which query plugins consume) stay.
81
+ addGenerator(resolved.sdk ? createSdkGenerator<PluginFetch>() : clientGenerator)
83
82
 
84
- ctx.addGenerator(...selectedGenerators)
83
+ const root = path.resolve(config.root, config.output.path)
84
+ const baseURLExpression = baseURL ? (baseURL.includes('${') ? `\`${baseURL.replaceAll('`', '\\`')}\`` : JSON.stringify(baseURL)) : undefined
85
85
 
86
- const root = path.resolve(ctx.config.root, ctx.config.output.path)
87
- const baseURLExpression = baseURL ? (baseURL.includes('${') ? `\`${baseURL.replaceAll('`', '\\`')}\`` : JSON.stringify(baseURL)) : undefined
86
+ injectFile({
87
+ baseName: 'serializers.ts',
88
+ path: path.resolve(root, '.kubb/serializers.ts'),
89
+ copy: fetchSerializersTemplatePath,
90
+ })
88
91
 
89
- ctx.injectFile({
90
- baseName: 'serializers.ts',
91
- path: path.resolve(root, '.kubb/serializers.ts'),
92
- copy: fetchSerializersTemplatePath,
93
- })
92
+ injectFile({
93
+ baseName: 'client.ts',
94
+ path: path.resolve(root, '.kubb/client.ts'),
95
+ copy: fetchClientTemplatePath,
96
+ footer: baseURLExpression ? `client.setConfig({ baseURL: ${baseURLExpression} })` : undefined,
97
+ })
94
98
 
95
- ctx.injectFile({
96
- baseName: 'client.ts',
97
- path: path.resolve(root, '.kubb/client.ts'),
98
- copy: fetchClientTemplatePath,
99
- footer: baseURLExpression ? `client.setConfig({ baseURL: ${baseURLExpression} })` : undefined,
100
- })
99
+ injectFile({
100
+ baseName: 'standardSchema.ts',
101
+ path: path.resolve(root, '.kubb/standardSchema.ts'),
102
+ copy: standardSchemaTemplatePath,
103
+ })
101
104
 
102
- ctx.injectFile({
103
- baseName: 'standardSchema.ts',
104
- path: path.resolve(root, '.kubb/standardSchema.ts'),
105
- copy: standardSchemaTemplatePath,
106
- })
107
- },
108
- },
109
- }
105
+ return resolved
106
+ },
110
107
  })
111
108
 
112
109
  export default pluginFetch