The API changed. Now what?
A new field, a removed field, a type that flipped. Which changes break your generated code, which break it quietly, and how to find out first.
Your types were right when you made them. The API moved. What happens next depends on the kind of change and on the language, and the quiet failures are the ones to plan for.
The four changes
A new field appears
{ "id": 1, "name": "Ada", "timezone": "Europe/London" }
Open this example in the tool →
Mostly harmless. Your types ignore it.
| Language | What happens |
|---|---|
| TypeScript, Go, Python, Java | Ignored. The field is dropped |
| Rust, serde | Ignored, unless you set deny_unknown_fields |
| Swift, Codable | Ignored |
You lose nothing except the chance to use the new field. The risk is that you never notice a field was added that you needed.
A field disappears
This is the one that breaks, and it should.
| Language | What happens |
|---|---|
| Rust, Swift, Java, C# | The decode fails. Loud, at the edge. Good |
| TypeScript with a check | The check fails. Good |
| TypeScript with no check | undefined flows into your code and throws somewhere else |
| Go | The field is the zero value. Silent |
| Python, dataclass with a reader | Usually throws |
Go deserves attention here. A removed string field becomes "", a removed
number becomes 0, and nothing says a word. If that field drives a decision,
the decision is now made on a zero. This is the argument for pointers on any
field you must be able to miss.
A type changes
"id": 7 becomes "id": "7". Almost everything fails, which is what you
want, except in JavaScript with no check, where the id silently stops matching
anything.
A field's meaning changes
Nothing fails. amount changed from dollars to cents, or a date went from
seconds to milliseconds. No type system in the world catches this. Only a
test with a real expected value does.
How to find out first
Check at the edge. Everything above is better if a decode or a schema
parse happens where the data arrives. In TypeScript that means Zod or the
reader the generator offers, not a bare as User. Read a type is not a
check.
Watch the schema. If the API publishes an OpenAPI or JSON Schema document, fetch it nightly, generate from it, and fail the build when the output differs from what you have committed. You hear about the change on the day it ships.
Keep a recorded answer as a fixture. One real response, saved as a file, parsed by your types in a unit test. It costs nothing and it fails the moment the shape you depend on moves.
Log the unknown fields. A few frameworks can tell you about keys they ignored. Logging those for a week after a release tells you what the API is quietly sending that you do not read.
When you must support both shapes
During a migration you may need to read the old and the new form at once. Do it at the edge, in one place:
const raw = UserWireSchema.parse(json)
const user: User = {
id: String(raw.id),
createdAt: typeof raw.created === 'number'
? new Date(raw.created * 1000)
: new Date(raw.created),
}
Two types: one that describes what comes off the wire, warts and all, and one your program actually uses. The ugly part is confined to the function between them, and it can be deleted on the day the old shape dies.
This is worth doing even with no migration in sight. A generated type is a description of somebody else's API; it is not a good model of your own domain. Keeping them apart means the API can change without your whole code base changing with it.
The checklist
- Check the data where it enters the program.
- Keep a real recorded answer as a test fixture.
- Generate from a schema, in CI, and fail on a difference.
- In Go, use a pointer for any field whose absence means something.
- Keep the wire type and your domain type apart at the boundary.
Do the first two and you will find out about most changes before your users do.
Try it on your own JSON. The generator runs in your browser. Nothing is uploaded, and nothing is stored on a server.
Open JSON to CodeRead next
From a sample, to a schema, to code
The way to use a generator that still works in six months: make the schema once, read it, commit it, and make the code from it every time.
Keep generated code honest — make it again in CI
Generated files rot the moment somebody edits one by hand. One CI step makes that impossible.