Skip to content

[core] Add filesDir config option for directory-based template discovery#23884

Draft
aegeiger wants to merge 1 commit into
OpenAPITools:masterfrom
aegeiger:features/filesDir
Draft

[core] Add filesDir config option for directory-based template discovery#23884
aegeiger wants to merge 1 commit into
OpenAPITools:masterfrom
aegeiger:features/filesDir

Conversation

@aegeiger
Copy link
Copy Markdown

@aegeiger aegeiger commented May 27, 2026

Fixes #23877

Adds a new filesDir config option that allows users to point to a directory of additional template files instead of listing each one individually in the files map. Subdirectory names automatically determine the template type.

Example

templateDir: my_custom_templates
filesDir: my_extra_templates/
my_extra_templates/
  README.md              # -> SupportingFiles
  api/
    custom_api.mustache   # -> API
  model/
    validators.mustache   # -> Model
  scripts/
    deploy.sh             # -> SupportingFiles, folder: "scripts"

How to validate

  1. Create a directory structure like above with .mustache template files
  2. Add filesDir: path/to/dir to your generator config YAML
  3. Run generation — files should be discovered and processed according to their subdirectory names
  4. Verify that explicit files entries take precedence when both are specified
  5. Verify that filesDir works when pointing at a symlink to a directory

Files changed

File What
DynamicSettings.java New filesDir field, directory scanning logic (follows symlinks), merge with existing files entries
DynamicSettingsTest.java 5 new tests (nested structure, merge precedence, empty dir, nonexistent dir, case insensitivity)
docs/customization.md Documentation for the new option

Design decisions

  • Convention over configuration: subdirectory names (api/, model/, apiDocs/, etc.) map to TemplateFileType values (case-insensitive). Unrecognized directory names default to SupportingFiles with the path used as the output folder.
  • Merge with files: when both are specified, explicit files entries take precedence over auto-discovered ones.
  • Symlinks are followed: filesDir itself can be a symlink, and symlinks within the tree are followed. No cycle detection is provided — this is documented.
  • Minimal footprint: the change is confined to DynamicSettings.java. No changes to CodegenConfigurator, DefaultGenerator, TemplateDefinition, TemplateFileType, CLI, or any generator — the downstream pipeline already works with List<TemplateDefinition> generically.
  • Fully backward compatible: filesDir is optional; existing behavior is unchanged.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    No sample or doc output changes — this PR adds a new config option (filesDir) that is not used by any existing generator config.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
    Fixes [REQ] Add filesDir config option for directory-based template discovery #23877
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
    N/A — this is a core/config change, not language-specific.

Summary by cubic

Adds a new filesDir config option for directory-based template discovery to reduce config noise. Subfolders map to template types, and explicit files entries still win on conflicts.

  • New Features
    • filesDir scans a directory (follows symlinks) and auto-adds templates.
    • Case-insensitive mapping for api/, model/, apiDocs/, modelDocs/, apiTests/, modelTests/, supportingFiles/.
    • Root files are SupportingFiles; unknown subfolders become SupportingFiles with the folder path preserved.
    • .mustache suffix is stripped from the destination filename.
    • Merges with files; explicit files entries take precedence. Backward compatible.

Written for commit 94f7a0b. Summary will update on new commits. Review in cubic

Add a new `filesDir` config option that allows users to point to a
directory of additional template files instead of listing each one
individually in the `files` map. Subdirectory names are automatically
mapped to template types (api/, model/, apiDocs/, etc.).

This is a natural extension of the existing `files` feature introduced
in v5.0.0, reducing config verbosity when many additional templates are
needed. When both `files` and `filesDir` are specified, explicit
`files` entries take precedence over auto-discovered ones.
@aegeiger
Copy link
Copy Markdown
Author

This PR is complementary to the issue - if maintainers will requests changes on the issue, I'll update this PR.

@aegeiger aegeiger marked this pull request as draft May 27, 2026 12:08
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[REQ] Add filesDir config option for directory-based template discovery

1 participant