Add support for expanding dot notation in Data objects and TypeScript transformer #1045
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.
Description
This PR adds a new feature that allows dot notation in property names to be expanded into nested objects when using Data objects as resources and in TypeScript definitions. This is particularly useful when working with APIs that require or return nested JSON structures.
When using the
MapOutputName
orMapName
attributes with dot notation (e.g., 'user.name'), the package can now generate nested arrays in the JSON output and nested TypeScript interfaces that match the structure of your JSON.Configuration
The feature is controlled by a new configuration option in
config/data.php
:Benefits
Examples
Basic Example
With
expand_dot_notation
enabled, this generates the following JSON:Instead of the flat structure:
JSON:API Specification Example
When working with JSON:API specification, you often have relationships and attributes in a specific structure:
With
expand_dot_notation
enabled, this generates a JSON structure that perfectly matches the JSON:API specification: