@kubb/plugin-ts 5.0.0-alpha.25 → 5.0.0-alpha.27
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 +139 -115
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +145 -118
- package/dist/index.js +140 -116
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/Type.tsx +8 -39
- package/src/generators/typeGenerator.tsx +40 -19
- package/src/generators/typeGeneratorLegacy.tsx +36 -18
- package/src/index.ts +1 -0
- package/src/plugin.ts +9 -5
- package/src/presets.ts +5 -2
- package/src/printers/printerTs.ts +33 -4
- package/src/resolvers/resolverTs.ts +11 -15
- package/src/resolvers/resolverTsLegacy.ts +8 -8
- package/src/types.ts +31 -18
package/src/types.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
Resolver,
|
|
14
14
|
UserGroup,
|
|
15
15
|
} from '@kubb/core'
|
|
16
|
+
import type { PrinterTsNodes } from './printers/printerTs.ts'
|
|
16
17
|
/**
|
|
17
18
|
* The concrete resolver type for `@kubb/plugin-ts`.
|
|
18
19
|
* Extends the base `Resolver` (which provides `default` and `resolveOptions`) with
|
|
@@ -27,7 +28,7 @@ export type ResolverTs = Resolver &
|
|
|
27
28
|
* @example
|
|
28
29
|
* resolver.resolveName('list pets status 200') // → 'ListPetsStatus200'
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
|
+
resolveTypeName(name: string): string
|
|
31
32
|
/**
|
|
32
33
|
* Resolves the file/path name for a given identifier using PascalCase.
|
|
33
34
|
*
|
|
@@ -256,35 +257,47 @@ export type Options = {
|
|
|
256
257
|
*/
|
|
257
258
|
compatibilityPreset?: CompatibilityPreset
|
|
258
259
|
/**
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
* Built-in: `resolverTs` (default), `resolverTsLegacy`.
|
|
262
|
-
* @default [resolverTs]
|
|
260
|
+
* Override naming conventions. When a method returns `null` or `undefined`, the preset
|
|
261
|
+
* resolver (`resolverTs` / `resolverTsLegacy`) is used as fallback.
|
|
263
262
|
*/
|
|
264
|
-
|
|
263
|
+
resolver?: Partial<ResolverTs> & ThisType<ResolverTs>
|
|
265
264
|
/**
|
|
266
|
-
*
|
|
267
|
-
*
|
|
265
|
+
* AST visitor applied to each schema/operation node before printing.
|
|
266
|
+
* Returning `null` or `undefined` from a visitor method falls back to the preset transformer.
|
|
268
267
|
*
|
|
269
268
|
* @example Remove writeOnly properties from response types
|
|
270
269
|
* ```ts
|
|
271
|
-
*
|
|
270
|
+
* transformer: {
|
|
272
271
|
* property(node) {
|
|
273
272
|
* if (node.schema.writeOnly) return undefined
|
|
274
273
|
* }
|
|
275
|
-
* }
|
|
274
|
+
* }
|
|
276
275
|
* ```
|
|
276
|
+
*/
|
|
277
|
+
transformer?: Visitor
|
|
278
|
+
/**
|
|
279
|
+
* Override individual printer node handlers to customise rendering of specific schema types.
|
|
280
|
+
*
|
|
281
|
+
* Each key is a `SchemaType` (e.g. `'date'`, `'string'`). The function replaces the
|
|
282
|
+
* built-in handler for that type. Use `this.transform` to recurse into nested schema nodes.
|
|
277
283
|
*
|
|
278
|
-
* @example
|
|
284
|
+
* @example Override the `date` node to use the `Date` object type
|
|
279
285
|
* ```ts
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
286
|
+
* import ts from 'typescript'
|
|
287
|
+
* pluginTs({
|
|
288
|
+
* printer: {
|
|
289
|
+
* nodes: {
|
|
290
|
+
* date(node) {
|
|
291
|
+
* return ts.factory.createTypeReferenceNode('Date', [])
|
|
292
|
+
* },
|
|
293
|
+
* },
|
|
294
|
+
* },
|
|
295
|
+
* })
|
|
285
296
|
* ```
|
|
286
297
|
*/
|
|
287
|
-
|
|
298
|
+
printer?: {
|
|
299
|
+
nodes?: PrinterTsNodes
|
|
300
|
+
}
|
|
288
301
|
} & EnumTypeOptions
|
|
289
302
|
|
|
290
303
|
type ResolvedOptions = {
|
|
@@ -297,7 +310,7 @@ type ResolvedOptions = {
|
|
|
297
310
|
arrayType: NonNullable<Options['arrayType']>
|
|
298
311
|
syntaxType: NonNullable<Options['syntaxType']>
|
|
299
312
|
paramsCasing: Options['paramsCasing']
|
|
300
|
-
|
|
313
|
+
printer: Options['printer']
|
|
301
314
|
}
|
|
302
315
|
|
|
303
316
|
export type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions, ResolverTs>
|