Add option to disable generation of resource collection classes #723
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.
This PR introduces a new configuration option,
generate_resource_collection_classes
, to toggle the generation of resource collection classes in Blueprint.Current behaviour
To return a resource collection, Blueprint creates a resource collection class. These classes allows adding custom metadata that may need to be returned with the collection.
Blueprint uses them in controllers using the
resource
statement, generating code like this:However, as convenient as these dedicated classes are for extending basic functionality, they are not necessary when dealing with simple collections, as all resources provide a
collection
method to generate an "ad-hoc" resource collection on the fly.So given a
PostResource
, the controller can do:Proposed Feature
A new configuration option,
generate_resource_collection_classes
, toggles the generation of resource collection classes in Blueprint.This feature is useful for developers who prefer a leaner approach to resource handling by relying solely on resource classes and their
collection
methods, reducing the number of generated files.'generate_resource_collection_classes' => true,
If this option is true, it will generate resource collection classes (e.g.,
PostResourceCollection
). This is the default value, maintaining existing behavior where dedicated resource collection classes are generated. It also defaults to true if the value is missing from the config (useful for people who already published the configuration file).If this option is false, it will only generate resource classes (e.g.,
PostResource
) and use theircollection
method instead.Testing
Added test cases to verify:
Please let me know if this approach is valid. I would love to see this feature available, happy to make a PR to the docs repo if it does. Thank you!