refactor(codegen): update code generation to use non-global root #3721
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.
refactor(codegen): eliminate global dependencies and improve code generation architecture
This PR refactors the code generation architecture to remove global dependencies and improve maintainability across the codebase. The changes span three main areas that were causing confusion and making the code harder to maintain.
Changes
Remove Global Root Expression Dependencies
This commit modifies the code generation logic to consistently utilize non-global root expressions across various files. Changes include updating function signatures and internal calls to pass the root expression as a parameter, ensuring that the generated code correctly references the API structure. This refactor removes the need for code generation algorithms to refer to the global root expression variable.
Restructure ServicesData Architecture
The most significant change eliminates the confusing ServicesData global dependencies in both transport and non-transport code generation algorithms. Previously, we had a confusing pattern where ServicesData contained a ServiceData field, making it unclear which layer you were working with.
Key improvements:
This creates clear separation between service layer and transport layer data structures.
Streamline Service File Generation
Impact
These changes enhance the clarity and efficiency of the code generation process while ensuring better maintainability and consistency across service files. The refactor maintains full backward compatibility for generated code - no changes are required for existing Goa applications.
The elimination of global state dependencies makes the codebase more testable and modular, while the improved naming conventions make it much clearer which layer of the system you're working with at any given time.