OpenAPITools / OpenAPITools/openapi-generator

[REQ] Add an "overridesEmbedded" to Codegen Configs to Allow Extensions

Open
#5,916 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

Currently, the CodegenConfigLoader just returns the first Config for a given name. This limits the ability for users to extend a provided code generator (the ServiceLoader as far as I can tell loads Services in arbitrary order).

Describe the solution you'd like

The name for this method could probably be more descriptive. The basic solution is this:

  1. Add a method Boolean overridesEmbedded() to the CodegenConfig.
  2. Add a method String overridesDir() to the CodegenConfig which defines the root of the set of templates to overlay on top of the embedded-dir.
  3. Update [AbstractGenerator.getFullTemplateFile] to check overridesDir after <template-folder>/*, but before <embedded-folder>/* which should avoid breaking changes for users of the templateDir commandline parameter.
  4. Add a implementations in DefaultCodegenConfig:
@Overrides
public Boolean overridesParent() {
	return false;
}

@Overrides
public String overridesDir() {
	return getTemplateDir();
}
  1. Update documentation to tell users who wish to customize existing Code Generators to override the overridesParent and overridesDir methods in their custom code generator.

Describe alternatives you've considered

An alternative way to do this would be to add a priority field instead. This would let users extend other overrides by setting their priority above the defined priority of their override.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading CodegenConfigLoader.java, AbstractGenerator.getFullTemplateFile, and DefaultCodegenConfig to trace configuration discovery and template lookup. Compare the proposed overridesEmbedded and overridesParent names, then check the surrounding documentation and tests. Done means custom code generators can overlay templates without changing existing templateDir behavior, with the documented configuration methods available.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.