@kubb/plugin-ts 5.0.0-alpha.26 → 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/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
- resolveName(name: string): string
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
- * Array of named resolvers that control naming conventions.
260
- * Later entries override earlier ones (last wins).
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
- resolvers?: Array<ResolverTs>
263
+ resolver?: Partial<ResolverTs> & ThisType<ResolverTs>
265
264
  /**
266
- * Array of AST visitors applied to each SchemaNode/OperationNode before printing.
267
- * Uses `transform()` from `@kubb/ast` visitors can modify, replace, or annotate nodes.
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
- * transformers: [{
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 Force all dates to plain strings
284
+ * @example Override the `date` node to use the `Date` object type
279
285
  * ```ts
280
- * transformers: [{
281
- * schema(node) {
282
- * if (node.type === 'date') return { ...node, type: 'string' }
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
- transformers?: Array<Visitor>
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
- transformers: Array<Visitor>
313
+ printer: Options['printer']
301
314
  }
302
315
 
303
316
  export type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions, ResolverTs>