feat: add new option and interface to allow customization of how model names are generated#2679
Open
crtl wants to merge 2 commits into
Open
feat: add new option and interface to allow customization of how model names are generated#2679crtl wants to merge 2 commits into
crtl wants to merge 2 commits into
Conversation
0e0fcfa to
667eb0f
Compare
…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
667eb0f to
45d5a90
Compare
Contributor
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce
ModelNameGeneratorInterfaceand wire it throughApiDocGeneratorandModelRegistryto allow customizing schema/model names.NoopModelNameGeneratoras the default (BC-preserving) implementationGroupAppendingModelNameGeneratorthat appends sanitized, sorted group names to the short namemodels.model_name_generator(default:nelmio_api_doc.model_name_generator.default)config/services.phpand wire viaNelmioApiDocExtensionModelRegistryTestto cover the integrationDescription
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
ModelNameGeneratorInterfacewhich can be passed tomodels.model_name_generatorin 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_appendingis provided too which can be used to include serialization groups in generated Model name, elminiating most of possible conflicts.For example a model
Useris used with groups["public-read"]will produce model nameUser_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)
Checklist
docs/)