Safeguard
Supply Chain•

Are custom OpenAPI Generator templates a supply chain risk?

Custom templates decide what code lands in your generated client. How template lookup works, what to review, and how to keep overrides small.

Safeguard Security Team
4 min read

Yes, they can be. A template is code that writes your code, so anything in it, such as an extra import, a logging call or a dependency line, is copied into every generated file. Keep overrides small, store them in version control, and review them like production source.

What a template is

OpenAPI Generator builds a data model from your spec and applies it to templates. Built in templates are written in Mustache and processed by jmustache. The docs also mention experimental Handlebars support and user defined template engines through plugins, starting with version 4.0.0.

You can override templates with a template directory option on the CLI, or the matching setting in the Maven and Gradle plugins. The docs say this approach only overrides existing templates. It cannot create new ones.

Lookup order explains surprises

The templating page lists the order in which the generator looks for a template:

  1. Your custom library path
  2. Your custom generator top level path
  3. The embedded library path
  4. The embedded top level path
  5. The common embedded path

So a file in your folder wins over the built in one. Two consequences follow. A stale override keeps silently winning after you upgrade the generator, and a copied template from an old version can hide fixes made upstream.

What to review in a template change

Look forWhy
New dependency lines in build templatesThey add libraries to every generated project
Added imports or helper callsCode your team did not write, now in every model
Logging of request or response objectsCan leak personal data or tokens into logs
Hard coded URLs, headers or credentialsEnds up in a published SDK
Changes to the HTTP client wrapperAffects TLS, redirects and timeouts for every call

The docs' own example adds an aspect oriented logging library through a template and a new line in a Gradle build template. It is a good illustration of how one template edit adds a third party dependency to every output.

How to keep it manageable

  1. Extract only the templates you must change, using the author template command available since version 5.0. Do not copy the whole directory.
  2. Commit the overrides in a folder next to the spec, with the generator version they were taken from noted in the commit message.
  3. Require review from someone who knows the output language, since a small template edit has a wide effect.
  4. On each generator upgrade, diff your override against the new built in one and re-apply your change deliberately.
  5. Delete overrides you no longer need.

If you load templates from the classpath to share them across projects, the docs describe packaging them in a JAR. Treat that JAR as a dependency: version it, store it in your own registry, and scan it.

Where Safeguard fits

Safeguard's SBOM and dependency scanning will list any libraries your templates add, and policy gates can block a pull request that introduces a risky one. The free scan is at gold.safeguard.sh/scan.

Quick check

Can a template change run code on my build machine?

A Mustache template produces text. The risk is in what that text becomes: code that ships in your product. Running other tools on generated files is a separate feature, covered in our post on file post-processing.

Do I need custom templates at all?

Often not. Config options and additional properties cover many needs without touching templates.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.