Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

Clients generated from your OpenAPI spec in Java, TypeScript and Kotlin keep breaking: enum additions crash old clients, nullable fields are typed wrongly and model names change between generator versions. How do you make code generation reliable?

Generated clients break when the spec, the generator and the evolution rules are all left loose. We pin generator versions and template changes and upgrade them on purpose with a diff of the generated code, document that enums may grow and configure each client to map unknown values to a default, state required and nullable precisely (in OpenAPI 3.1 with type arrays that include null) and check how each generator maps them, lint the spec with Spectral and run breaking-change detection such as openapi-diff in CI, and give every schema an explicit name so generated model names never change by accident.

Why this question is asked

Generating clients in three languages from one spec sounds like the end of integration bugs, and then the bug reports start: an Android app crashes because a new enum value appeared, a TypeScript client treats a missing field as present, and a Kotlin release renames InlineResponse200 to GetOrders200Response. Each problem has a different cause, but they share one root: nothing in the pipeline treats the spec and the generator as code that must stay stable. Interviewers ask this scenario to see whether we can find those causes and fix the process, not just the latest crash. In this answer, we will take the three symptoms one at a time and then put the checks into CI.

1Why Generated Clients Break

A generated client depends on three things: the spec, the generator version with its templates, and the options we pass. A change to any of them changes the code consumers compile against. When the spec changes in a way that is compatible on the wire but not in generated code, such as a new enum value, old clients break. When the generator is upgraded, its naming or nullability rules may change even though the spec did not. And when the spec is vague, for example about whether a field can be null, each generator guesses differently.

So the fix is not one setting. It is making each of the three inputs explicit, versioned and checked.

2Pinning the Generator and Reviewing Its Upgrades

First, the generator version is pinned in every build, the Maven or Gradle plugin and the npm package alike, and so are any custom templates. Nobody gets a new generator because a build tool resolved 'latest'. When we do want an upgrade, we treat it as a change of its own: generate the clients with the old and the new version from the same spec, diff the output, and read the diff before releasing.

That diff is where we catch renamed models, changed method signatures or different date types before consumers do. If the change is breaking for consumers, the new client is released as a new major version of the client library, with a note explaining what changed and why, even though the API itself did not change.

3Designing Enums That May Grow

A new enum value is compatible on the wire but crashes clients whose generated enum has no matching constant. We fix it at two levels. In the spec and the API guidelines, we state that enums may gain values and clients must handle unknown ones. In the generators, we turn on the option that adds a fallback constant, which OpenAPI Generator offers for many languages as enumUnknownDefaultCase.

XML
<configOptions>
<enumUnknownDefaultCase>true</enumUnknownDefaultCase> <!-- adds UNKNOWN_DEFAULT_OPEN_API -->
</configOptions>
// Generated Java enum, abridged
public enum StatusEnum {
NEW("NEW"), PAID("PAID"), SHIPPED("SHIPPED"),
UNKNOWN_DEFAULT_OPEN_API("unknown_default_open_api");
public static StatusEnum fromValue(String v) { /* ... returns UNKNOWN_DEFAULT_OPEN_API for unknown v */ }
}
// Server adds REFUNDED
StatusEnum s = StatusEnum.fromValue("REFUNDED"); // UNKNOWN_DEFAULT_OPEN_API instead of an exception

Notice that the option is a generator choice per language, so we set it in each client's configuration and verify it with a test that feeds an unknown value. For values that change often, such as product categories, a plain string with documented examples is sometimes better than an enum at all.

4Being Precise About Required and Nullable

Required and nullable are two different questions. Required says whether the property must be present in the JSON object. Nullable says whether its value may be null when present. A generator needs both to choose between a plain type, an optional type and a nullable type, and when the spec is vague, each generator fills the gap with its own default.

In OpenAPI 3.0, nullability is the keyword nullable: true. In OpenAPI 3.1, which aligns with JSON Schema, nullable is gone and we write a type array instead, such as type: [string, 'null']. Generator support for 3.1 has been catching up and differs between languages, so we check how each of our three generators maps each combination, with a small test spec, rather than assuming.

YAML
# OpenAPI 3.1
Customer:
type: object
required: [id, email]
properties:
id: { type: integer, format: int64 } # required, never null
email: { type: [string, "null"] } # required, may be null
nickname: { type: string } # optional, never null when present
note: { type: [string, "null"] } # optional, may be null
The four combinations a generator must map
RequiredNullableJSON the client may seeTypical generated type
YesNo"id": 7Plain type, for example long or string
YesYes"email": nullNullable type, for example String? in Kotlin
NoNofield missing, or a valueOptional or nullable, generator-specific
NoYesmissing, null or a valueNullable; some generators distinguish missing
Rows three and four are where generators disagree most; test them for each language.

We then write our guideline down: by default fields are required and not nullable, and every exception is deliberate. That removes most of the guessing.

5Linting and Breaking-Change Detection in CI

Rules only help if a machine enforces them. In the API repository's pipeline we run two checks on every pull request. Spectral lints the spec against our rule set: every schema is named, every enum has a description that says it may grow, every property declares its nullability, operationIds follow our naming. Then a diff tool such as openapi-diff or oasdiff compares the new spec with the last released one and fails the build on breaking changes, such as a removed field, a narrowed type or a new required request property.

Shell
$ spectral lint orders.yaml --ruleset .spectral.yaml
12:9 error schema-must-have-name Inline object schema in response 200 of getOrders
$ oasdiff breaking orders-1.4.0.yaml orders.yaml --fail-on ERR
error [response-property-removed] GET /orders/{orderId}: removed 'totalAmount' from response 200

Finally, the pipeline generates all three clients from the new spec and compiles a small test project against each one. If generation or compilation fails in any language, we find out in the pull request, not from a consumer.

6Giving Every Schema an Explicit Name

Model names change between generator versions mostly because the schemas never had names. An inline object in a response has no name in the spec, so the generator invents one, InlineResponse200 in older versions and something like GetOrders200Response in newer ones. Any consumer code that refers to that class breaks after the upgrade.

The fix is to move every object schema to components/schemas with a deliberate name, and refer to it with $ref. Where a nested inline schema is unavoidable, a title or the generator's inline schema name mappings can fix its name; check your generator version for the exact option. The Spectral rule above keeps new inline objects from creeping back in.

7Follow-up questions

Should we publish generated clients ourselves or let consumers generate them?

For widely used APIs, publishing versioned client libraries is better: we control the generator version and options, run the compile tests, and consumers upgrade by changing a version number. Letting each consumer generate its own client means every team may use a different generator and options, and the same spec produces different bugs everywhere.

Is it worth customising the generator templates?

Sometimes, for example to add a company base class or a header, but each customised template must be maintained across generator upgrades. Keep customisations few, store them with the build, and include them in the generated-code diff when upgrading.

8Conclusion

In this answer, we made client generation reliable by treating the spec and the generator as code. We pinned generator versions and templates and reviewed upgrades by diffing generated output, documented that enums may grow and turned on unknown-value fallbacks in each client, stated required and nullable precisely, using type arrays with null in OpenAPI 3.1, and checked each generator's mapping, ran Spectral and a breaking-change diff in CI, and named every schema explicitly to keep model names stable.

What to say in the interviewAbout 90 seconds aloud

Open with

I would look at the three symptoms separately, because they have three causes. Changing model names usually come from inline schemas the generator has to name itself, plus unpinned generator versions.

Then, if they want more

So I pin the generator and any custom templates in every language, and when we upgrade, I generate with the old and new version from the same spec and review the diff of the generated code before releasing a client.

And I move every object schema into components with an explicit name, using title or name mappings only where inline is unavoidable.

The enum crashes are an evolution rule we never wrote down: I document that enums may grow and turn on the generator option that adds an unknown default constant, enumUnknownDefaultCase in OpenAPI Generator, with a test that feeds an unknown value to each client. The nullable problems come from a vague spec.

Required and nullable are separate questions, and in OpenAPI 3.1 nullable is written as a type array including null. I set a default of required and not nullable, declare every exception, and check how each generator maps the four combinations.

Then I put it all in CI: Spectral lint rules, oasdiff or openapi-diff against the last release to fail on breaking changes, and generating and compiling all three clients on every pull request.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Clients generated from your OpenAPI spec in Java, TypeScript and Kotlin keep breaking...": https://scrivio-interview-library.netlify.app/spring-boot/rest-api-design/dd1a1dd658/