S2T
Advanced

How Swagger to TanStack Preserves Your Custom Code

8 min read

One of the biggest fears with code generation is losing your custom modifications. Swagger to TanStack solves this with intelligent preservation markers that protect your changes during regeneration.

The Problem with Traditional Generators

Most code generators completely overwrite files on every run. If you've added custom error handling, logging, or business logic, it gets deleted. This forces you to either avoid customization or maintain parallel code files.

Protection Markers

Swagger to TanStack recognizes specific comments that mark files as customized:

typescript

The update Command

Use the update command instead of generate to safely update existing code:

bash

The update command:

  • Scans all generated files for protection markers
  • Skips files that contain any marker
  • Only updates unchanged, auto-generated files
  • Shows a summary of which files were updated vs preserved

Best Practices for Customization

1. Add Markers Early

As soon as you modify a generated file, add a marker:

typescript

2. Document Your Changes

Use TODO markers to track custom modifications:

typescript

3. Organize Custom Logic

Keep custom code in separate files when possible:

typescript

When to Regenerate vs Update

Use generate when:

  • First-time setup
  • Major API restructuring
  • You want a clean slate

Use update when:

  • Regular API changes
  • You have custom modifications to preserve
  • Incremental updates to existing code

Conclusion

With intelligent preservation markers and the update command, you get the best of both worlds: automatic code generation and the freedom to customize. Your modifications are safe, and your API client stays in sync with your backend.

👋 Hello and welcome!

I'm Armel Dakayao, Front-End Developer & creator of swagger-to-tanstack CLI.

Armel Dakayao

Senior Front-End Developer. I build scalable, user-friendly web & mobile apps with React,React Native, Next.js, and TypeScript.

Swagger to TanStack - Documentation