Skip to content

feat: add new option and interface to allow customization of how model names are generated#2679

Open
crtl wants to merge 2 commits into
nelmio:5.xfrom
crtl:feature/model-name-generator
Open

feat: add new option and interface to allow customization of how model names are generated#2679
crtl wants to merge 2 commits into
nelmio:5.xfrom
crtl:feature/model-name-generator

Conversation

@crtl
Copy link
Copy Markdown

@crtl crtl commented Jan 22, 2026

Introduce ModelNameGeneratorInterface and wire it through ApiDocGenerator and ModelRegistry to allow customizing schema/model names.

  • Add NoopModelNameGenerator as the default (BC-preserving) implementation
  • Add GroupAppendingModelNameGenerator that appends sanitized, sorted group names to the short name
  • Add configuration option models.model_name_generator (default: nelmio_api_doc.model_name_generator.default)
  • Register services and aliases in config/services.php and wire via NelmioApiDocExtension
  • Update docs with configuration examples and usage guidance
  • Add tests for generators and update ModelRegistryTest to cover the integration

Description

This is my first PR, feedback is very welcome

Currently when using serialization groups with models the generated model names produce conflicts and are thus numberd.
Aside from being none descriptive the number assigned is just the first processed controller which uses the model.
When refactoring code and thus changing the order the controllers are processed the numbering can change.

This becomes especially problemativ when using the json output to generate sdk clients using various tools.

As a solution i have provided a new interface ModelNameGeneratorInterface which can be passed to models.model_name_generator in configuration to allow customization of how model names are generated.
By default a noop subscriber is used to maintain backwards compatibility but a nelmio_api_doc.model_name_generator.group_appending is provided too which can be used to include serialization groups in generated Model name, elminiating most of possible conflicts.

For example a model User is used with groups ["public-read"] will produce model name User_publicRead.

Should there still be a conflict it will fall back to the default numbering logic.

Closes:

What type of PR is this? (check all applicable)

  • Bug Fix
  • Feature
  • Refactor
  • Deprecation
  • Breaking Change
  • Documentation Update
  • CI

Checklist

  • I have made corresponding changes to the documentation (docs/)

@crtl crtl force-pushed the feature/model-name-generator branch from 0e0fcfa to 667eb0f Compare January 22, 2026 23:51
…l names are generated

Introduce `ModelNameGeneratorInterface` and wire it through `ApiDocGenerator` and `ModelRegistry`
to allow customizing schema/model names.

- Add `NoopModelNameGenerator` as the default (BC-preserving) implementation
- Add `GroupAppendingModelNameGenerator` that appends sanitized, sorted group names to the short name
- Add configuration option `models.model_name_generator` (default: `nelmio_api_doc.model_name_generator.default`)
- Register services and aliases in `config/services.php` and wire via `NelmioApiDocExtension`
- Update docs with configuration examples and usage guidance
- Add tests for generators and update `ModelRegistryTest` to cover the integration
@crtl crtl force-pushed the feature/model-name-generator branch from 667eb0f to 45d5a90 Compare January 26, 2026 19:50
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 6, 2026

This PR has been marked as stale because it has not had any activity for 60 days. Remove stale label or comment to prevent this from being closed in 60 days.

@github-actions github-actions Bot added the stale stale issue/PR label Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale stale issue/PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants