refactor(codegen): update code generation to use non-global root#3721
Merged
Conversation
…essions This commit modifies the code generation logic to consistently utilize a non-global root expressions across various files. Changes include updating function signatures and internal calls to pass the root expression, 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.
- Embed service.ServicesData in transport packages to eliminate confusing field names - Rename transport service maps to GRPCServices/HTTPServices for clarity - Add constructor functions to reduce boilerplate initialization - Update variable names from serviceData to services for semantic accuracy - Establish consistent patterns across service, HTTP, and gRPC codegen packages This eliminates the confusing naming where ServicesData contained a ServiceData field, and creates clear separation between service layer and transport layer data structures.
…plate handling - Consolidate file appending in Service function for improved readability. - Simplify section template creation in EndpointFile and ViewsFile functions. - Introduce IsAliased and ServiceTypeRef fields in ServiceData for better type resolution. - Update request initialization template to utilize new fields for aliased types. These changes enhance the clarity and efficiency of the code generation process, ensuring better maintainability and consistency across service files.
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.
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.