Scrivio Interview library
LeadershipAdvanced5 min read · updated 12 November 2026

Should your organisation generate server stubs from OpenAPI (design-first) for all teams, or let teams generate the spec from code? Lay out how you would decide and roll it out.

I would not force one approach on everyone. Design-first gives a reviewed contract before any code and consistent clients, but adds tooling and slows small changes; code-first is fast for teams but lets contracts drift and change by accident. So I would make design-first the rule for public and cross-team APIs and allow code-first with automated breaking-change checks for internal ones, give both paths shared generator configuration, templates and CI checks that publish a validated spec to the API catalog, and decide the final rule after a measured pilot with a few teams.

Why this question is asked

Every organisation that takes APIs seriously eventually argues about this. One group wants every API designed in OpenAPI and reviewed before a line of code is written; another says that slows them down and the code is the truth anyway. Interviewers ask it at this level to see whether we can turn a debate about taste into a decision based on where each approach pays off, and roll it out so teams actually follow it. In this answer, we will recap both approaches, weigh what each costs and buys, define a mixed rule, describe the shared tooling that makes both paths safe, and plan a pilot that decides with data.

1A Quick Recap of the Two Approaches

In design-first, the team writes the OpenAPI spec first, gets it reviewed by consumers and API reviewers, and then generates server interfaces from it, for example with OpenAPI Generator's spring generator. The code implements the generated interfaces, so it cannot drift from the spec without failing to compile.

In code-first, the team writes controllers and DTOs in Java, and a tool such as springdoc-openapi produces the spec from the annotations at build or run time. The spec is an output, always in line with the code at that moment, but nobody necessarily looked at it before it changed.

2What Each Approach Costs and Buys

Design-first buys a contract review before implementation, which is the cheapest moment to fix a bad API design, and it gives consistent, high-quality specs from which all clients are generated. Its costs are tooling and skills: engineers must write OpenAPI well, the generator needs configuration, and a small change such as adding a field means editing YAML, regenerating and then coding, which feels slow for a team that owns both sides.

Code-first is fast and natural for Java developers, and the spec can never be out of date with the code. Its risk is the opposite: the contract changes whenever the code changes, sometimes by accident. Renaming a Java field, changing a type or upgrading a library can silently change the published API, and nobody reviews the result unless something forces them to.

Design-first against code-first
AspectDesign-firstCode-first
Contract reviewBefore implementationOnly if a check forces it
Speed of small changesSlower: YAML, generate, codeFast: change the code
Risk of accidental changeLow, compile fails on driftHigh without a diff check
Spec quality and consistencyHigh, written deliberatelyVaries with annotations
Tooling and skills neededGenerator, OpenAPI fluencyspringdoc, few skills

3A Mixed Rule That Matches the Risk

The deciding factor is who pays when the contract is wrong. For public APIs and APIs used by other teams, a bad or accidental change is expensive, because other people's code depends on it and they cannot change it in the same pull request. There, a review before implementation is worth the slower path, so design-first is the rule.

For internal APIs used only by the owning team, the same people control both sides, and speed matters more. Code-first is allowed there, with one condition: the generated spec is diffed against the last published version in CI, and breaking changes fail the build. If an internal API later gains a consumer in another team, it moves to the stricter rule.

Step throughWhich path a team takes
  1. Is the API public, partner-facing or used by another team?
    YesDesign-first: review the spec, generate interfacesNoCode-first is allowed
  2. Code-first with checksspringdoc spec diffed against the published one in CI
  3. Did an internal API gain a consumer outside the team?
    YesMove it to design-firstNoStay code-first
  4. Both pathsvalidated spec published to the API catalog

4 steps in order. Play them, or step through them one at a time.

4Shared Tooling So Both Paths Produce a Validated Spec

The rule only works if following it is easy. A platform team provides, for design-first, a shared generator configuration with pinned versions and standard options such as interfaceOnly and skipDefaultInterface, spec templates with the company's standard error and pagination schemas, and an example repository. For code-first, it provides a starter that configures springdoc consistently and a build step that exports the spec.

Both paths then meet in the same CI checks: Spectral linting against the company rule set, a breaking-change diff against the last published spec, and publishing to the API catalog. So whatever path a team chose, the catalog holds a validated spec for every API, and consumers cannot tell the difference.

5Rolling It Out With a Pilot

Before making the rule mandatory, I would run it with three or four teams for a quarter: at least one with a public API, one with cross-team APIs and one with internal-only services. We measure what the debate is really about. How long does a contract review take from pull request to approval? How many breaking changes were caught in CI, and how many reached consumers? How long does a typical small change take on each path? How do the engineers rate the tooling?

If design-first reviews take days instead of hours, we fix the review process or the tooling before scaling. If code-first teams leak breaking changes despite the diff, we tighten the checks. Then we roll out in waves, new APIs first and existing ones when they next change, with the pilot teams helping others. The data from the pilot also gives the rule its authority: teams follow a rule more readily when they can see the numbers behind it.

6Follow-up questions

Can a team switch an existing code-first API to design-first?

Yes, and it is straightforward: export the current spec with springdoc, clean it up and name its schemas, make it the source, generate the interfaces, and make the existing controllers implement them. The compile errors show where the code and the cleaned-up spec disagree, and each one is a decision to make deliberately.

Does design-first mean a separate design phase that delays projects?

It should not. The spec for a small API can be drafted in an hour and reviewed the same day, and teams can develop consumers against a mock server generated from it while the provider is being built. Done well, design-first lets both sides work in parallel sooner.

7Conclusion

In this answer, we compared design-first and code-first OpenAPI. Design-first gives a reviewed contract before implementation and consistent clients but costs tooling and speed for small changes; code-first is fast but lets contracts drift or change by accident. A mixed rule fits the risk: design-first for public and cross-team APIs, code-first with breaking-change checks for internal ones, supported by shared generator configuration, templates and CI checks that publish a validated spec for every API, and decided after a measured pilot.

What to say in the interviewAbout 90 seconds aloud

Open with

I would not pick one approach for every team, because the cost of a wrong contract is very different across APIs. Design-first gives us a review of the contract before anyone implements it, which is the cheapest time to fix a bad design, and consistent specs for generated clients.

Then, if they want more

The cost is tooling, OpenAPI skills, and slower small changes. Code-first with springdoc is fast and natural, but the contract changes whenever the code does, sometimes by accident, like a renamed field.

So my rule would be: design-first, with generated server interfaces, for anything public, partner-facing or used by another team; code-first allowed for internal APIs owned by one team, but only with a CI step that diffs the generated spec against the published one and fails on breaking changes. If an internal API gets an outside consumer, it moves to design-first.

A platform team would provide pinned generator configuration, spec templates with our standard errors and pagination, a springdoc starter, and shared CI checks, Spectral and a breaking-change diff, so both paths publish a validated spec to the catalog.

Before mandating it, I would pilot with three or four teams for a quarter, measure review time, breaking changes caught versus leaked, and change lead time, fix what hurts, and then roll out to new APIs first.

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 "Should your organisation generate server stubs from OpenAPI (design-first) for all...": https://scrivio-interview-library.netlify.app/spring-boot/rest-api-design/27d170696a/